Commit eb0ced86 authored by Peter Kasting's avatar Peter Kasting Committed by Commit Bot

[omnibox] Move some updates from Invalidate() to SetMatch().

Invalidate() is called more frequently (e.g. on color changes), while SetMatch()
is called only when the match actually changes.  So anything that is tied to the
match's content (e.g. the suggestion or keyword contents/description) can be
updated in SetMatch() instead of Invalidate() to save work without visible
change.

Also tweaks Layout() to check the keyword view's visibility instead of the
underlying state that controls it.

Bug: none
Change-Id: Ia0b7ca2566a621ad9315e54313f584c21f999668
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1857649Reviewed-by: default avatarJustin Donnelly <jdonnelly@chromium.org>
Commit-Queue: Justin Donnelly <jdonnelly@chromium.org>
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#706217}
parent 8202d1f2
...@@ -87,6 +87,12 @@ OmniboxResultView::OmniboxResultView( ...@@ -87,6 +87,12 @@ OmniboxResultView::OmniboxResultView(
omnibox::kKeywordSearchIcon, GetLayoutConstant(LOCATION_BAR_ICON_SIZE), omnibox::kKeywordSearchIcon, GetLayoutConstant(LOCATION_BAR_ICON_SIZE),
GetColor(OmniboxPart::RESULTS_ICON))); GetColor(OmniboxPart::RESULTS_ICON)));
keyword_view_->icon()->SizeToPreferredSize(); keyword_view_->icon()->SizeToPreferredSize();
// Calling SetMatch() will result in the child OmniboxMatchCellViews
// constructing their RenderTexts. Without this, the first time the popup is
// opened, it will call Invalidate() before SetMatch(), which will try to
// apply styles to nonexistent RenderTexts, which will crash.
SetMatch(AutocompleteMatch());
} }
OmniboxResultView::~OmniboxResultView() {} OmniboxResultView::~OmniboxResultView() {}
...@@ -109,6 +115,28 @@ void OmniboxResultView::SetMatch(const AutocompleteMatch& match) { ...@@ -109,6 +115,28 @@ void OmniboxResultView::SetMatch(const AutocompleteMatch& match) {
base::FeatureList::IsEnabled( base::FeatureList::IsEnabled(
omnibox::kOmniboxSuggestionTransparencyOptions)); omnibox::kOmniboxSuggestionTransparencyOptions));
suggestion_view_->content()->SetText(match_.contents, match_.contents_class);
if (match_.answer) {
suggestion_view_->content()->AppendExtraText(match_.answer->first_line());
suggestion_view_->description()->SetText(match_.answer->second_line(),
true);
} else {
const bool deemphasize =
match_.type == AutocompleteMatchType::SEARCH_SUGGEST_ENTITY ||
match_.type == AutocompleteMatchType::PEDAL;
suggestion_view_->description()->SetText(
match_.description, match_.description_class, deemphasize);
}
AutocompleteMatch* keyword_match = match_.associated_keyword.get();
keyword_view_->SetVisible(keyword_match);
if (keyword_match) {
keyword_view_->content()->SetText(keyword_match->contents,
keyword_match->contents_class);
keyword_view_->description()->SetText(keyword_match->description,
keyword_match->description_class);
}
Invalidate(); Invalidate();
Layout(); Layout();
} }
...@@ -147,52 +175,22 @@ void OmniboxResultView::Invalidate(bool force_reapply_styles) { ...@@ -147,52 +175,22 @@ void OmniboxResultView::Invalidate(bool force_reapply_styles) {
omnibox::kKeywordSearchIcon, GetLayoutConstant(LOCATION_BAR_ICON_SIZE), omnibox::kKeywordSearchIcon, GetLayoutConstant(LOCATION_BAR_ICON_SIZE),
GetColor(OmniboxPart::RESULTS_ICON))); GetColor(OmniboxPart::RESULTS_ICON)));
// Answers use their own styling for additional content text and the
// description text, whereas non-answer suggestions use the match text and
// calculated classifications for the description text.
if (match_.answer) { if (match_.answer) {
suggestion_view_->content()->SetText(match_.contents,
match_.contents_class);
suggestion_view_->content()->ApplyTextColor( suggestion_view_->content()->ApplyTextColor(
OmniboxPart::RESULTS_TEXT_DEFAULT); OmniboxPart::RESULTS_TEXT_DEFAULT);
suggestion_view_->content()->AppendExtraText(match_.answer->first_line());
suggestion_view_->description()->SetText(match_.answer->second_line(),
true);
} else if (match_.type == AutocompleteMatchType::SEARCH_SUGGEST_ENTITY || } else if (match_.type == AutocompleteMatchType::SEARCH_SUGGEST_ENTITY ||
match_.type == AutocompleteMatchType::PEDAL) { match_.type == AutocompleteMatchType::PEDAL) {
// Entities use match text and calculated classifications, but with style
// adjustments like answers above. Pedals do likewise.
suggestion_view_->content()->SetText(match_.contents,
match_.contents_class);
suggestion_view_->description()->SetText(match_.description,
match_.description_class, -1);
suggestion_view_->description()->ApplyTextColor( suggestion_view_->description()->ApplyTextColor(
OmniboxPart::RESULTS_TEXT_DIMMED); OmniboxPart::RESULTS_TEXT_DIMMED);
} else { } else if (high_contrast || force_reapply_styles) {
// Content and description use match text and calculated classifications.
suggestion_view_->content()->SetText(match_.contents,
match_.contents_class);
suggestion_view_->description()->SetText(match_.description,
match_.description_class);
// Normally, OmniboxTextView caches its appearance, but in high contrast, // Normally, OmniboxTextView caches its appearance, but in high contrast,
// selected-ness changes the text colors, so the styling of the text part of // selected-ness changes the text colors, so the styling of the text part of
// the results needs to be recomputed. // the results needs to be recomputed.
if (high_contrast || force_reapply_styles) { suggestion_view_->content()->ReapplyStyling();
suggestion_view_->content()->ReapplyStyling(); suggestion_view_->description()->ReapplyStyling();
suggestion_view_->description()->ReapplyStyling();
}
} }
AutocompleteMatch* keyword_match = match_.associated_keyword.get(); if (keyword_view_->GetVisible()) {
// Setting the keyword_view_ invisible is a minor optimization (it avoids
// some OnPaint calls); it is not required.
keyword_view_->SetVisible(keyword_match);
if (keyword_match) {
keyword_view_->content()->SetText(keyword_match->contents,
keyword_match->contents_class);
keyword_view_->description()->SetText(keyword_match->description,
keyword_match->description_class);
keyword_view_->description()->ApplyTextColor( keyword_view_->description()->ApplyTextColor(
OmniboxPart::RESULTS_TEXT_DIMMED); OmniboxPart::RESULTS_TEXT_DIMMED);
} }
...@@ -277,11 +275,12 @@ void OmniboxResultView::Layout() { ...@@ -277,11 +275,12 @@ void OmniboxResultView::Layout() {
views::View::Layout(); views::View::Layout();
// NOTE: While animating the keyword match, both matches may be visible. // NOTE: While animating the keyword match, both matches may be visible.
int suggestion_width = width(); int suggestion_width = width();
AutocompleteMatch* keyword_match = match_.associated_keyword.get(); if (keyword_view_->GetVisible()) {
if (keyword_match) {
const int max_kw_x = const int max_kw_x =
suggestion_width - OmniboxMatchCellView::GetTextIndent(); suggestion_width - OmniboxMatchCellView::GetTextIndent();
suggestion_width = animation_->CurrentValueBetween(max_kw_x, 0); suggestion_width = animation_->CurrentValueBetween(max_kw_x, 0);
keyword_view_->SetBounds(suggestion_width, 0, width() - suggestion_width,
height());
} }
// Add buttons from right to left, shrinking the suggestion width as we go. // Add buttons from right to left, shrinking the suggestion width as we go.
...@@ -320,8 +319,6 @@ void OmniboxResultView::Layout() { ...@@ -320,8 +319,6 @@ void OmniboxResultView::Layout() {
} }
} }
keyword_view_->SetBounds(suggestion_width, 0, width() - suggestion_width,
height());
if (popup_contents_view_->InExplicitExperimentalKeywordMode() || if (popup_contents_view_->InExplicitExperimentalKeywordMode() ||
match_.IsSubMatch()) { match_.IsSubMatch()) {
suggestion_view_->SetBounds(kKeywordSuggestionIndent, 0, suggestion_view_->SetBounds(kKeywordSuggestionIndent, 0,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment