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

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: 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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 {NativeTheme::kColorId_ResultsTableNormalText, 117 {NativeTheme::kColorId_ResultsTableNormalText,
118 NativeTheme::kColorId_ResultsTableHoveredText, 118 NativeTheme::kColorId_ResultsTableHoveredText,
119 NativeTheme::kColorId_ResultsTableSelectedText}, 119 NativeTheme::kColorId_ResultsTableSelectedText},
120 gfx::NORMAL_BASELINE}; 120 gfx::NORMAL_BASELINE};
121 case SuggestionAnswer::ANSWER_TEXT_LARGE: 121 case SuggestionAnswer::ANSWER_TEXT_LARGE:
122 return {ui::ResourceBundle::LargeFont, 122 return {ui::ResourceBundle::LargeFont,
123 {NativeTheme::kColorId_ResultsTableNormalText, 123 {NativeTheme::kColorId_ResultsTableNormalText,
124 NativeTheme::kColorId_ResultsTableHoveredText, 124 NativeTheme::kColorId_ResultsTableHoveredText,
125 NativeTheme::kColorId_ResultsTableSelectedText}, 125 NativeTheme::kColorId_ResultsTableSelectedText},
126 gfx::NORMAL_BASELINE}; 126 gfx::NORMAL_BASELINE};
127 case SuggestionAnswer::SUGGESTION_SECONDARY_TEXT_SMALL: // Fall through. 127 case SuggestionAnswer::SUGGESTION_SECONDARY_TEXT_SMALL:
128 return {ui::ResourceBundle::LargeFont,
Peter Kasting 2017/02/01 02:00:58 LargeFont? Shouldn't this be BaseFont?
Justin Donnelly 2017/02/01 16:58:45 Unfortunately, no, LargeFont is "correct". The way
Peter Kasting 2017/02/01 19:37:21 I wonder if any of this deserves a comment in the
Justin Donnelly 2017/02/01 20:44:15 sgtm, done.
129 {NativeTheme::kColorId_ResultsTableNormalDimmedText,
130 NativeTheme::kColorId_ResultsTableHoveredDimmedText,
131 NativeTheme::kColorId_ResultsTableSelectedDimmedText},
132 gfx::INFERIOR};
128 case SuggestionAnswer::SUGGESTION_SECONDARY_TEXT_MEDIUM: 133 case SuggestionAnswer::SUGGESTION_SECONDARY_TEXT_MEDIUM:
129 return {ui::ResourceBundle::BaseFont, 134 return {ui::ResourceBundle::BaseFont,
130 {NativeTheme::kColorId_ResultsTableNormalDimmedText, 135 {NativeTheme::kColorId_ResultsTableNormalDimmedText,
131 NativeTheme::kColorId_ResultsTableHoveredDimmedText, 136 NativeTheme::kColorId_ResultsTableHoveredDimmedText,
132 NativeTheme::kColorId_ResultsTableSelectedDimmedText}, 137 NativeTheme::kColorId_ResultsTableSelectedDimmedText},
133 gfx::NORMAL_BASELINE}; 138 gfx::NORMAL_BASELINE};
134 case SuggestionAnswer::SUGGESTION: // Fall through. 139 case SuggestionAnswer::SUGGESTION: // Fall through.
135 default: 140 default:
136 return {ui::ResourceBundle::BaseFont, 141 return {ui::ResourceBundle::BaseFont,
137 {NativeTheme::kColorId_ResultsTableNormalText, 142 {NativeTheme::kColorId_ResultsTableNormalText,
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 // selected. The non-answer text is already accessible as a consequence of 276 // selected. The non-answer text is already accessible as a consequence of
272 // updating the text in the omnibox but this alert and GetAccessibleNodeData 277 // updating the text in the omnibox but this alert and GetAccessibleNodeData
273 // below make the answer contents accessible. 278 // below make the answer contents accessible.
274 if (match_.answer) 279 if (match_.answer)
275 NotifyAccessibilityEvent(ui::AX_EVENT_ALERT, true); 280 NotifyAccessibilityEvent(ui::AX_EVENT_ALERT, true);
276 } 281 }
277 282
278 gfx::Size OmniboxResultView::GetPreferredSize() const { 283 gfx::Size OmniboxResultView::GetPreferredSize() const {
279 if (!match_.answer) 284 if (!match_.answer)
280 return gfx::Size(0, GetContentLineHeight()); 285 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) 286 if (match_.answer->second_line().num_text_lines() == 1)
283 return gfx::Size(0, GetContentLineHeight() + GetAnswerLineHeight()); 287 return gfx::Size(0, GetContentLineHeight() + GetAnswerLineHeight());
284 if (!description_rendertext_) { 288 if (!description_rendertext_) {
285 description_rendertext_ = 289 description_rendertext_ =
286 CreateAnswerLine(match_.answer->second_line(), font_list_); 290 CreateAnswerLine(match_.answer->second_line(), GetAnswerLineFont());
287 } 291 }
288 description_rendertext_->SetDisplayRect( 292 description_rendertext_->SetDisplayRect(
289 gfx::Rect(text_bounds_.width(), 0)); 293 gfx::Rect(text_bounds_.width(), 0));
290 description_rendertext_->GetStringSize(); 294 description_rendertext_->GetStringSize();
291 return gfx::Size( 295 return gfx::Size(
292 0, GetContentLineHeight() + 296 0, GetContentLineHeight() +
293 GetAnswerLineHeight() * description_rendertext_->GetNumLines()); 297 GetAnswerLineHeight() * description_rendertext_->GetNumLines());
294 } 298 }
295 299
296 void OmniboxResultView::GetAccessibleNodeData(ui::AXNodeData* node_data) { 300 void OmniboxResultView::GetAccessibleNodeData(ui::AXNodeData* node_data) {
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
640 icon_bounds_.y()); 644 icon_bounds_.y());
641 int x = GetMirroredXForRect(text_bounds_); 645 int x = GetMirroredXForRect(text_bounds_);
642 mirroring_context_->Initialize(x, text_bounds_.width()); 646 mirroring_context_->Initialize(x, text_bounds_.width());
643 InitContentsRenderTextIfNecessary(); 647 InitContentsRenderTextIfNecessary();
644 648
645 if (!description_rendertext_) { 649 if (!description_rendertext_) {
646 if (match_.answer) { 650 if (match_.answer) {
647 contents_rendertext_ = 651 contents_rendertext_ =
648 CreateAnswerLine(match_.answer->first_line(), font_list_); 652 CreateAnswerLine(match_.answer->first_line(), font_list_);
649 description_rendertext_ = 653 description_rendertext_ =
650 CreateAnswerLine(match_.answer->second_line(), font_list_); 654 CreateAnswerLine(match_.answer->second_line(), GetAnswerLineFont());
651 } else if (!match_.description.empty()) { 655 } else if (!match_.description.empty()) {
652 description_rendertext_ = CreateClassifiedRenderText( 656 description_rendertext_ = CreateClassifiedRenderText(
653 match_.description, match_.description_class, true); 657 match_.description, match_.description_class, true);
654 } 658 }
655 } 659 }
656 PaintMatch(match_, contents_rendertext_.get(), 660 PaintMatch(match_, contents_rendertext_.get(),
657 description_rendertext_.get(), canvas, x); 661 description_rendertext_.get(), canvas, x);
658 } 662 }
659 663
660 AutocompleteMatch* keyword_match = match_.associated_keyword.get(); 664 AutocompleteMatch* keyword_match = match_.associated_keyword.get();
(...skipping 16 matching lines...) Expand all
677 PaintMatch(*keyword_match, keyword_contents_rendertext_.get(), 681 PaintMatch(*keyword_match, keyword_contents_rendertext_.get(),
678 keyword_description_rendertext_.get(), canvas, x); 682 keyword_description_rendertext_.get(), canvas, x);
679 } 683 }
680 } 684 }
681 685
682 void OmniboxResultView::AnimationProgressed(const gfx::Animation* animation) { 686 void OmniboxResultView::AnimationProgressed(const gfx::Animation* animation) {
683 Layout(); 687 Layout();
684 SchedulePaint(); 688 SchedulePaint();
685 } 689 }
686 690
691 const gfx::FontList& OmniboxResultView::GetAnswerLineFont() const {
692 // This assumes that the first text type in the second answer line can be used
693 // to specify the font for all the text fields in the line. For now this works
694 // but eventually it will be necessary to get RenderText to support multiple
695 // font sizes or use multiple RenderTexts.
696 int text_type =
697 match_.answer && !match_.answer->second_line().text_fields().empty()
698 ? match_.answer->second_line().text_fields()[0].type()
699 : SuggestionAnswer::SUGGESTION;
700 return ui::ResourceBundle::GetSharedInstance().GetFontList(
701 GetTextStyle(text_type).font);
702 }
703
687 int OmniboxResultView::GetAnswerLineHeight() const { 704 int OmniboxResultView::GetAnswerLineHeight() const {
688 // ANSWER_TEXT_LARGE is the largest font used and so defines the boundary that 705 return GetAnswerLineFont().GetHeight();
Peter Kasting 2017/02/01 02:00:58 Should we just inline this into callers now? I di
Justin Donnelly 2017/02/01 16:58:45 I started doing this but then began playing around
689 // all the other answer styles fit within.
690 return ui::ResourceBundle::GetSharedInstance()
691 .GetFontList(GetTextStyle(SuggestionAnswer::ANSWER_TEXT_LARGE).font)
692 .GetHeight();
693 } 706 }
694 707
695 int OmniboxResultView::GetContentLineHeight() const { 708 int OmniboxResultView::GetContentLineHeight() const {
696 using Md = ui::MaterialDesignController; 709 using Md = ui::MaterialDesignController;
697 const int kIconVerticalPad = Md::GetMode() == Md::MATERIAL_HYBRID ? 8 : 4; 710 const int kIconVerticalPad = Md::GetMode() == Md::MATERIAL_HYBRID ? 8 : 4;
698 const int kTextVerticalPad = 3; 711 const int kTextVerticalPad = 3;
699 return std::max( 712 return std::max(
700 LocationBarView::kIconWidth + 2 * kIconVerticalPad, 713 LocationBarView::kIconWidth + 2 * kIconVerticalPad,
701 GetTextHeight() + 2 * kTextVerticalPad); 714 GetTextHeight() + 2 * kTextVerticalPad);
702 } 715 }
703 716
704 std::unique_ptr<gfx::RenderText> OmniboxResultView::CreateAnswerLine( 717 std::unique_ptr<gfx::RenderText> OmniboxResultView::CreateAnswerLine(
705 const SuggestionAnswer::ImageLine& line, 718 const SuggestionAnswer::ImageLine& line,
706 gfx::FontList font_list) const { 719 const gfx::FontList& font_list) const {
707 std::unique_ptr<gfx::RenderText> destination = 720 std::unique_ptr<gfx::RenderText> destination =
708 CreateRenderText(base::string16()); 721 CreateRenderText(base::string16());
709 destination->SetFontList(font_list); 722 destination->SetFontList(font_list);
710 723
711 for (const SuggestionAnswer::TextField& text_field : line.text_fields()) 724 for (const SuggestionAnswer::TextField& text_field : line.text_fields())
712 AppendAnswerText(destination.get(), text_field.text(), text_field.type()); 725 AppendAnswerText(destination.get(), text_field.text(), text_field.type());
713 if (!line.text_fields().empty()) { 726 if (!line.text_fields().empty()) {
714 constexpr int kMaxDisplayLines = 3; 727 constexpr int kMaxDisplayLines = 3;
715 const SuggestionAnswer::TextField& first_field = line.text_fields().front(); 728 const SuggestionAnswer::TextField& first_field = line.text_fields().front();
716 if (first_field.has_num_lines() && first_field.num_lines() > 1 && 729 if (first_field.has_num_lines() && first_field.num_lines() > 1 &&
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
773 destination->AppendText(text); 786 destination->AppendText(text);
774 const TextStyle& text_style = GetTextStyle(text_type); 787 const TextStyle& text_style = GetTextStyle(text_type);
775 // TODO(dschuyler): follow up on the problem of different font sizes within 788 // TODO(dschuyler): follow up on the problem of different font sizes within
776 // one RenderText. Maybe with destination->SetFontList(...). 789 // one RenderText. Maybe with destination->SetFontList(...).
777 destination->ApplyWeight( 790 destination->ApplyWeight(
778 is_bold ? gfx::Font::Weight::BOLD : gfx::Font::Weight::NORMAL, range); 791 is_bold ? gfx::Font::Weight::BOLD : gfx::Font::Weight::NORMAL, range);
779 destination->ApplyColor( 792 destination->ApplyColor(
780 GetNativeTheme()->GetSystemColor(text_style.colors[GetState()]), range); 793 GetNativeTheme()->GetSystemColor(text_style.colors[GetState()]), range);
781 destination->ApplyBaselineStyle(text_style.baseline, range); 794 destination->ApplyBaselineStyle(text_style.baseline, range);
782 } 795 }
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