Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(126)

Side by Side Diff: chrome/browser/ui/views/omnibox/omnibox_result_view.cc

Issue 2654163005: Fix the size of omnibox suggestion answers. (Closed)
Patch Set: Merge. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/ui/views/omnibox/omnibox_result_view.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // For WinDDK ATL compatibility, these ATL headers must come first. 5 // For WinDDK ATL compatibility, these ATL headers must come first.
6 #include "build/build_config.h" 6 #include "build/build_config.h"
7 7
8 #if defined(OS_WIN) 8 #if defined(OS_WIN)
9 #include <atlbase.h> // NOLINT 9 #include <atlbase.h> // NOLINT
10 #include <atlwin.h> // NOLINT 10 #include <atlwin.h> // NOLINT
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 { NativeTheme::kColorId_ResultsTableSelectedUrl, 80 { NativeTheme::kColorId_ResultsTableSelectedUrl,
81 OmniboxResultView::SELECTED, OmniboxResultView::URL }, 81 OmniboxResultView::SELECTED, OmniboxResultView::URL },
82 }; 82 };
83 83
84 struct TextStyle { 84 struct TextStyle {
85 ui::ResourceBundle::FontStyle font; 85 ui::ResourceBundle::FontStyle font;
86 ui::NativeTheme::ColorId colors[OmniboxResultView::NUM_STATES]; 86 ui::NativeTheme::ColorId colors[OmniboxResultView::NUM_STATES];
87 gfx::BaselineStyle baseline; 87 gfx::BaselineStyle baseline;
88 }; 88 };
89 89
90 // Returns the styles that should be applied to the specified answer text type.
91 //
92 // Note that the font value is only consulted for the first text type that
93 // appears on an answer line, because RenderText does not yet support multiple
94 // font sizes. Subsequent text types on the same line will share the text size
95 // of the first type, while the color and baseline styles specified here will
96 // always apply. The gfx::INFERIOR baseline style is used as a workaround to
97 // produce smaller text on the same line. The way this is used in the current
98 // set of answers is that the small types (TOP_ALIGNED, DESCRIPTION_NEGATIVE,
99 // DESCRIPTION_POSITIVE and SUGGESTION_SECONDARY_TEXT_SMALL) only ever appear
100 // following LargeFont text, so for consistency they specify LargeFont for the
101 // first value even though this is not actually used (since they're not the
102 // first value).
90 TextStyle GetTextStyle(int type) { 103 TextStyle GetTextStyle(int type) {
91 switch (type) { 104 switch (type) {
92 case SuggestionAnswer::TOP_ALIGNED: 105 case SuggestionAnswer::TOP_ALIGNED:
93 return {ui::ResourceBundle::LargeFont, 106 return {ui::ResourceBundle::LargeFont,
94 {NativeTheme::kColorId_ResultsTableNormalDimmedText, 107 {NativeTheme::kColorId_ResultsTableNormalDimmedText,
95 NativeTheme::kColorId_ResultsTableHoveredDimmedText, 108 NativeTheme::kColorId_ResultsTableHoveredDimmedText,
96 NativeTheme::kColorId_ResultsTableSelectedDimmedText}, 109 NativeTheme::kColorId_ResultsTableSelectedDimmedText},
97 gfx::SUPERIOR}; 110 gfx::SUPERIOR};
98 case SuggestionAnswer::DESCRIPTION_NEGATIVE: 111 case SuggestionAnswer::DESCRIPTION_NEGATIVE:
99 return {ui::ResourceBundle::LargeFont, 112 return {ui::ResourceBundle::LargeFont,
(...skipping 18 matching lines...) Expand all
118 {NativeTheme::kColorId_ResultsTableNormalText, 131 {NativeTheme::kColorId_ResultsTableNormalText,
119 NativeTheme::kColorId_ResultsTableHoveredText, 132 NativeTheme::kColorId_ResultsTableHoveredText,
120 NativeTheme::kColorId_ResultsTableSelectedText}, 133 NativeTheme::kColorId_ResultsTableSelectedText},
121 gfx::NORMAL_BASELINE}; 134 gfx::NORMAL_BASELINE};
122 case SuggestionAnswer::ANSWER_TEXT_LARGE: 135 case SuggestionAnswer::ANSWER_TEXT_LARGE:
123 return {ui::ResourceBundle::LargeFont, 136 return {ui::ResourceBundle::LargeFont,
124 {NativeTheme::kColorId_ResultsTableNormalText, 137 {NativeTheme::kColorId_ResultsTableNormalText,
125 NativeTheme::kColorId_ResultsTableHoveredText, 138 NativeTheme::kColorId_ResultsTableHoveredText,
126 NativeTheme::kColorId_ResultsTableSelectedText}, 139 NativeTheme::kColorId_ResultsTableSelectedText},
127 gfx::NORMAL_BASELINE}; 140 gfx::NORMAL_BASELINE};
128 case SuggestionAnswer::SUGGESTION_SECONDARY_TEXT_SMALL: // Fall through. 141 case SuggestionAnswer::SUGGESTION_SECONDARY_TEXT_SMALL:
142 return {ui::ResourceBundle::LargeFont,
143 {NativeTheme::kColorId_ResultsTableNormalDimmedText,
144 NativeTheme::kColorId_ResultsTableHoveredDimmedText,
145 NativeTheme::kColorId_ResultsTableSelectedDimmedText},
146 gfx::INFERIOR};
129 case SuggestionAnswer::SUGGESTION_SECONDARY_TEXT_MEDIUM: 147 case SuggestionAnswer::SUGGESTION_SECONDARY_TEXT_MEDIUM:
130 return {ui::ResourceBundle::BaseFont, 148 return {ui::ResourceBundle::BaseFont,
131 {NativeTheme::kColorId_ResultsTableNormalDimmedText, 149 {NativeTheme::kColorId_ResultsTableNormalDimmedText,
132 NativeTheme::kColorId_ResultsTableHoveredDimmedText, 150 NativeTheme::kColorId_ResultsTableHoveredDimmedText,
133 NativeTheme::kColorId_ResultsTableSelectedDimmedText}, 151 NativeTheme::kColorId_ResultsTableSelectedDimmedText},
134 gfx::NORMAL_BASELINE}; 152 gfx::NORMAL_BASELINE};
135 case SuggestionAnswer::SUGGESTION: // Fall through. 153 case SuggestionAnswer::SUGGESTION: // Fall through.
136 default: 154 default:
137 return {ui::ResourceBundle::BaseFont, 155 return {ui::ResourceBundle::BaseFont,
138 {NativeTheme::kColorId_ResultsTableNormalText, 156 {NativeTheme::kColorId_ResultsTableNormalText,
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 // selected. The non-answer text is already accessible as a consequence of 289 // selected. The non-answer text is already accessible as a consequence of
272 // updating the text in the omnibox but this alert and GetAccessibleNodeData 290 // updating the text in the omnibox but this alert and GetAccessibleNodeData
273 // below make the answer contents accessible. 291 // below make the answer contents accessible.
274 if (match_.answer) 292 if (match_.answer)
275 NotifyAccessibilityEvent(ui::AX_EVENT_ALERT, true); 293 NotifyAccessibilityEvent(ui::AX_EVENT_ALERT, true);
276 } 294 }
277 295
278 gfx::Size OmniboxResultView::GetPreferredSize() const { 296 gfx::Size OmniboxResultView::GetPreferredSize() const {
279 if (!match_.answer) 297 if (!match_.answer)
280 return gfx::Size(0, GetContentLineHeight()); 298 return gfx::Size(0, GetContentLineHeight());
281 // An answer implies a match and a description in a large font.
282 if (match_.answer->second_line().num_text_lines() == 1) 299 if (match_.answer->second_line().num_text_lines() == 1)
283 return gfx::Size(0, GetContentLineHeight() + GetAnswerLineHeight()); 300 return gfx::Size(0, GetContentLineHeight() + GetAnswerLineHeight());
284 if (!description_rendertext_) { 301 if (!description_rendertext_) {
285 description_rendertext_ = 302 description_rendertext_ =
286 CreateAnswerLine(match_.answer->second_line(), font_list_); 303 CreateAnswerLine(match_.answer->second_line(), GetAnswerLineFont());
287 } 304 }
288 description_rendertext_->SetDisplayRect( 305 description_rendertext_->SetDisplayRect(
289 gfx::Rect(text_bounds_.width(), 0)); 306 gfx::Rect(text_bounds_.width(), 0));
290 description_rendertext_->GetStringSize(); 307 description_rendertext_->GetStringSize();
291 return gfx::Size( 308 return gfx::Size(
292 0, GetContentLineHeight() + 309 0, GetContentLineHeight() +
293 GetAnswerLineHeight() * description_rendertext_->GetNumLines()); 310 GetAnswerLineHeight() * description_rendertext_->GetNumLines());
294 } 311 }
295 312
296 void OmniboxResultView::GetAccessibleNodeData(ui::AXNodeData* node_data) { 313 void OmniboxResultView::GetAccessibleNodeData(ui::AXNodeData* node_data) {
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
641 if (!ShowOnlyKeywordMatch()) { 658 if (!ShowOnlyKeywordMatch()) {
642 canvas->DrawImageInt(GetIcon(), GetMirroredXForRect(icon_bounds_), 659 canvas->DrawImageInt(GetIcon(), GetMirroredXForRect(icon_bounds_),
643 icon_bounds_.y()); 660 icon_bounds_.y());
644 int x = GetMirroredXForRect(text_bounds_); 661 int x = GetMirroredXForRect(text_bounds_);
645 mirroring_context_->Initialize(x, text_bounds_.width()); 662 mirroring_context_->Initialize(x, text_bounds_.width());
646 InitContentsRenderTextIfNecessary(); 663 InitContentsRenderTextIfNecessary();
647 664
648 if (!description_rendertext_) { 665 if (!description_rendertext_) {
649 if (match_.answer) { 666 if (match_.answer) {
650 description_rendertext_ = 667 description_rendertext_ =
651 CreateAnswerLine(match_.answer->second_line(), font_list_); 668 CreateAnswerLine(match_.answer->second_line(), GetAnswerLineFont());
652 } else if (!match_.description.empty()) { 669 } else if (!match_.description.empty()) {
653 description_rendertext_ = CreateClassifiedRenderText( 670 description_rendertext_ = CreateClassifiedRenderText(
654 match_.description, match_.description_class, true); 671 match_.description, match_.description_class, true);
655 } 672 }
656 } 673 }
657 PaintMatch(match_, contents_rendertext_.get(), 674 PaintMatch(match_, contents_rendertext_.get(),
658 description_rendertext_.get(), canvas, x); 675 description_rendertext_.get(), canvas, x);
659 } 676 }
660 677
661 AutocompleteMatch* keyword_match = match_.associated_keyword.get(); 678 AutocompleteMatch* keyword_match = match_.associated_keyword.get();
(...skipping 12 matching lines...) Expand all
674 PaintMatch(*keyword_match, keyword_contents_rendertext_.get(), 691 PaintMatch(*keyword_match, keyword_contents_rendertext_.get(),
675 keyword_description_rendertext_.get(), canvas, x); 692 keyword_description_rendertext_.get(), canvas, x);
676 } 693 }
677 } 694 }
678 695
679 void OmniboxResultView::AnimationProgressed(const gfx::Animation* animation) { 696 void OmniboxResultView::AnimationProgressed(const gfx::Animation* animation) {
680 Layout(); 697 Layout();
681 SchedulePaint(); 698 SchedulePaint();
682 } 699 }
683 700
701 const gfx::FontList& OmniboxResultView::GetAnswerLineFont() const {
702 // This assumes that the first text type in the second answer line can be used
703 // to specify the font for all the text fields in the line. For now this works
704 // but eventually it will be necessary to get RenderText to support multiple
705 // font sizes or use multiple RenderTexts.
706 int text_type =
707 match_.answer && !match_.answer->second_line().text_fields().empty()
708 ? match_.answer->second_line().text_fields()[0].type()
709 : SuggestionAnswer::SUGGESTION;
710 return ui::ResourceBundle::GetSharedInstance().GetFontList(
711 GetTextStyle(text_type).font);
712 }
713
684 int OmniboxResultView::GetAnswerLineHeight() const { 714 int OmniboxResultView::GetAnswerLineHeight() const {
685 // ANSWER_TEXT_LARGE is the largest font used and so defines the boundary that 715 return GetAnswerLineFont().GetHeight();
686 // all the other answer styles fit within.
687 return ui::ResourceBundle::GetSharedInstance()
688 .GetFontList(GetTextStyle(SuggestionAnswer::ANSWER_TEXT_LARGE).font)
689 .GetHeight();
690 } 716 }
691 717
692 int OmniboxResultView::GetContentLineHeight() const { 718 int OmniboxResultView::GetContentLineHeight() const {
693 using Md = ui::MaterialDesignController; 719 using Md = ui::MaterialDesignController;
694 const int kIconVerticalPad = Md::GetMode() == Md::MATERIAL_HYBRID ? 8 : 4; 720 const int kIconVerticalPad = Md::GetMode() == Md::MATERIAL_HYBRID ? 8 : 4;
695 const int kTextVerticalPad = 3; 721 const int kTextVerticalPad = 3;
696 return std::max( 722 return std::max(
697 LocationBarView::kIconWidth + 2 * kIconVerticalPad, 723 LocationBarView::kIconWidth + 2 * kIconVerticalPad,
698 GetTextHeight() + 2 * kTextVerticalPad); 724 GetTextHeight() + 2 * kTextVerticalPad);
699 } 725 }
700 726
701 std::unique_ptr<gfx::RenderText> OmniboxResultView::CreateAnswerLine( 727 std::unique_ptr<gfx::RenderText> OmniboxResultView::CreateAnswerLine(
702 const SuggestionAnswer::ImageLine& line, 728 const SuggestionAnswer::ImageLine& line,
703 gfx::FontList font_list) const { 729 const gfx::FontList& font_list) const {
704 std::unique_ptr<gfx::RenderText> destination = 730 std::unique_ptr<gfx::RenderText> destination =
705 CreateRenderText(base::string16()); 731 CreateRenderText(base::string16());
706 destination->SetFontList(font_list); 732 destination->SetFontList(font_list);
707 733
708 for (const SuggestionAnswer::TextField& text_field : line.text_fields()) 734 for (const SuggestionAnswer::TextField& text_field : line.text_fields())
709 AppendAnswerText(destination.get(), text_field.text(), text_field.type()); 735 AppendAnswerText(destination.get(), text_field.text(), text_field.type());
710 if (!line.text_fields().empty()) { 736 if (!line.text_fields().empty()) {
711 constexpr int kMaxDisplayLines = 3; 737 constexpr int kMaxDisplayLines = 3;
712 const SuggestionAnswer::TextField& first_field = line.text_fields().front(); 738 const SuggestionAnswer::TextField& first_field = line.text_fields().front();
713 if (first_field.has_num_lines() && first_field.num_lines() > 1 && 739 if (first_field.has_num_lines() && first_field.num_lines() > 1 &&
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
770 destination->AppendText(text); 796 destination->AppendText(text);
771 const TextStyle& text_style = GetTextStyle(text_type); 797 const TextStyle& text_style = GetTextStyle(text_type);
772 // TODO(dschuyler): follow up on the problem of different font sizes within 798 // TODO(dschuyler): follow up on the problem of different font sizes within
773 // one RenderText. Maybe with destination->SetFontList(...). 799 // one RenderText. Maybe with destination->SetFontList(...).
774 destination->ApplyWeight( 800 destination->ApplyWeight(
775 is_bold ? gfx::Font::Weight::BOLD : gfx::Font::Weight::NORMAL, range); 801 is_bold ? gfx::Font::Weight::BOLD : gfx::Font::Weight::NORMAL, range);
776 destination->ApplyColor( 802 destination->ApplyColor(
777 GetNativeTheme()->GetSystemColor(text_style.colors[GetState()]), range); 803 GetNativeTheme()->GetSystemColor(text_style.colors[GetState()]), range);
778 destination->ApplyBaselineStyle(text_style.baseline, range); 804 destination->ApplyBaselineStyle(text_style.baseline, range);
779 } 805 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/omnibox/omnibox_result_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698