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

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: Adjust answer line size and position. 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,
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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 match.answer != nullptr, 350 match.answer != nullptr,
347 !AutocompleteMatch::IsSearchType(match.type), 351 !AutocompleteMatch::IsSearchType(match.type),
348 &contents_max_width, 352 &contents_max_width,
349 &description_max_width); 353 &description_max_width);
350 354
351 int after_contents_x = DrawRenderText(match, contents, CONTENTS, canvas, 355 int after_contents_x = DrawRenderText(match, contents, CONTENTS, canvas,
352 x, y, contents_max_width); 356 x, y, contents_max_width);
353 357
354 if (description_max_width != 0) { 358 if (description_max_width != 0) {
355 if (match.answer) { 359 if (match.answer) {
356 y += GetContentLineHeight(); 360 const int kTextVerticalAdjustment = 1;
Peter Kasting 2017/02/01 19:37:21 Are you trying to offset for the "1" added in GetA
Justin Donnelly 2017/02/01 20:44:15 No, I'm trying to deal with what I think is an eff
Peter Kasting 2017/02/01 20:50:00 It sounds like what really really need is for both
361 y += GetContentLineHeight() - kTextVerticalAdjustment;
357 if (!answer_image_.isNull()) { 362 if (!answer_image_.isNull()) {
358 int answer_icon_size = GetAnswerLineHeight(); 363 int answer_icon_size = GetAnswerLineHeight();
359 canvas->DrawImageInt( 364 canvas->DrawImageInt(
360 answer_image_, 365 answer_image_,
361 0, 0, answer_image_.width(), answer_image_.height(), 366 0, 0, answer_image_.width(), answer_image_.height(),
362 GetMirroredXInView(x), y, answer_icon_size, answer_icon_size, true); 367 GetMirroredXInView(x), y, answer_icon_size, answer_icon_size, true);
363 // TODO(dschuyler): Perhaps this should be based on the font size 368 // TODO(dschuyler): Perhaps this should be based on the font size
364 // instead of hardcoded to 2 dp (e.g. by adding a space in an 369 // instead of hardcoded to 2 dp (e.g. by adding a space in an
365 // appropriate font to the beginning of the description, then reducing 370 // appropriate font to the beginning of the description, then reducing
366 // the additional padding here to zero). 371 // the additional padding here to zero).
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
640 icon_bounds_.y()); 645 icon_bounds_.y());
641 int x = GetMirroredXForRect(text_bounds_); 646 int x = GetMirroredXForRect(text_bounds_);
642 mirroring_context_->Initialize(x, text_bounds_.width()); 647 mirroring_context_->Initialize(x, text_bounds_.width());
643 InitContentsRenderTextIfNecessary(); 648 InitContentsRenderTextIfNecessary();
644 649
645 if (!description_rendertext_) { 650 if (!description_rendertext_) {
646 if (match_.answer) { 651 if (match_.answer) {
647 contents_rendertext_ = 652 contents_rendertext_ =
648 CreateAnswerLine(match_.answer->first_line(), font_list_); 653 CreateAnswerLine(match_.answer->first_line(), font_list_);
649 description_rendertext_ = 654 description_rendertext_ =
650 CreateAnswerLine(match_.answer->second_line(), font_list_); 655 CreateAnswerLine(match_.answer->second_line(), GetAnswerLineFont());
651 } else if (!match_.description.empty()) { 656 } else if (!match_.description.empty()) {
652 description_rendertext_ = CreateClassifiedRenderText( 657 description_rendertext_ = CreateClassifiedRenderText(
653 match_.description, match_.description_class, true); 658 match_.description, match_.description_class, true);
654 } 659 }
655 } 660 }
656 PaintMatch(match_, contents_rendertext_.get(), 661 PaintMatch(match_, contents_rendertext_.get(),
657 description_rendertext_.get(), canvas, x); 662 description_rendertext_.get(), canvas, x);
658 } 663 }
659 664
660 AutocompleteMatch* keyword_match = match_.associated_keyword.get(); 665 AutocompleteMatch* keyword_match = match_.associated_keyword.get();
(...skipping 16 matching lines...) Expand all
677 PaintMatch(*keyword_match, keyword_contents_rendertext_.get(), 682 PaintMatch(*keyword_match, keyword_contents_rendertext_.get(),
678 keyword_description_rendertext_.get(), canvas, x); 683 keyword_description_rendertext_.get(), canvas, x);
679 } 684 }
680 } 685 }
681 686
682 void OmniboxResultView::AnimationProgressed(const gfx::Animation* animation) { 687 void OmniboxResultView::AnimationProgressed(const gfx::Animation* animation) {
683 Layout(); 688 Layout();
684 SchedulePaint(); 689 SchedulePaint();
685 } 690 }
686 691
692 const gfx::FontList& OmniboxResultView::GetAnswerLineFont() const {
693 // This assumes that the first text type in the second answer line can be used
694 // to specify the font for all the text fields in the line. For now this works
695 // but eventually it will be necessary to get RenderText to support multiple
696 // font sizes or use multiple RenderTexts.
697 int text_type =
698 match_.answer && !match_.answer->second_line().text_fields().empty()
699 ? match_.answer->second_line().text_fields()[0].type()
700 : SuggestionAnswer::SUGGESTION;
701 return ui::ResourceBundle::GetSharedInstance().GetFontList(
702 GetTextStyle(text_type).font);
703 }
704
687 int OmniboxResultView::GetAnswerLineHeight() const { 705 int OmniboxResultView::GetAnswerLineHeight() const {
688 // ANSWER_TEXT_LARGE is the largest font used and so defines the boundary that 706 const int kTextVerticalPad = 1;
Peter Kasting 2017/02/01 19:37:21 Whaaat. Why do you want this? At the very least,
Justin Donnelly 2017/02/01 20:44:15 Here I'm simply doing what GetContentLineHeight()
689 // all the other answer styles fit within. 707 return GetAnswerLineFont().GetHeight() + 2 * kTextVerticalPad;
690 return ui::ResourceBundle::GetSharedInstance()
691 .GetFontList(GetTextStyle(SuggestionAnswer::ANSWER_TEXT_LARGE).font)
692 .GetHeight();
693 } 708 }
694 709
695 int OmniboxResultView::GetContentLineHeight() const { 710 int OmniboxResultView::GetContentLineHeight() const {
696 using Md = ui::MaterialDesignController; 711 using Md = ui::MaterialDesignController;
697 const int kIconVerticalPad = Md::GetMode() == Md::MATERIAL_HYBRID ? 8 : 4; 712 const int kIconVerticalPad = Md::GetMode() == Md::MATERIAL_HYBRID ? 8 : 4;
698 const int kTextVerticalPad = 3; 713 const int kTextVerticalPad = 3;
699 return std::max( 714 return std::max(
700 LocationBarView::kIconWidth + 2 * kIconVerticalPad, 715 LocationBarView::kIconWidth + 2 * kIconVerticalPad,
701 GetTextHeight() + 2 * kTextVerticalPad); 716 GetTextHeight() + 2 * kTextVerticalPad);
702 } 717 }
703 718
704 std::unique_ptr<gfx::RenderText> OmniboxResultView::CreateAnswerLine( 719 std::unique_ptr<gfx::RenderText> OmniboxResultView::CreateAnswerLine(
705 const SuggestionAnswer::ImageLine& line, 720 const SuggestionAnswer::ImageLine& line,
706 gfx::FontList font_list) const { 721 const gfx::FontList& font_list) const {
707 std::unique_ptr<gfx::RenderText> destination = 722 std::unique_ptr<gfx::RenderText> destination =
708 CreateRenderText(base::string16()); 723 CreateRenderText(base::string16());
709 destination->SetFontList(font_list); 724 destination->SetFontList(font_list);
710 725
711 for (const SuggestionAnswer::TextField& text_field : line.text_fields()) 726 for (const SuggestionAnswer::TextField& text_field : line.text_fields())
712 AppendAnswerText(destination.get(), text_field.text(), text_field.type()); 727 AppendAnswerText(destination.get(), text_field.text(), text_field.type());
713 if (!line.text_fields().empty()) { 728 if (!line.text_fields().empty()) {
714 constexpr int kMaxDisplayLines = 3; 729 constexpr int kMaxDisplayLines = 3;
715 const SuggestionAnswer::TextField& first_field = line.text_fields().front(); 730 const SuggestionAnswer::TextField& first_field = line.text_fields().front();
716 if (first_field.has_num_lines() && first_field.num_lines() > 1 && 731 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); 788 destination->AppendText(text);
774 const TextStyle& text_style = GetTextStyle(text_type); 789 const TextStyle& text_style = GetTextStyle(text_type);
775 // TODO(dschuyler): follow up on the problem of different font sizes within 790 // TODO(dschuyler): follow up on the problem of different font sizes within
776 // one RenderText. Maybe with destination->SetFontList(...). 791 // one RenderText. Maybe with destination->SetFontList(...).
777 destination->ApplyWeight( 792 destination->ApplyWeight(
778 is_bold ? gfx::Font::Weight::BOLD : gfx::Font::Weight::NORMAL, range); 793 is_bold ? gfx::Font::Weight::BOLD : gfx::Font::Weight::NORMAL, range);
779 destination->ApplyColor( 794 destination->ApplyColor(
780 GetNativeTheme()->GetSystemColor(text_style.colors[GetState()]), range); 795 GetNativeTheme()->GetSystemColor(text_style.colors[GetState()]), range);
781 destination->ApplyBaselineStyle(text_style.baseline, range); 796 destination->ApplyBaselineStyle(text_style.baseline, range);
782 } 797 }
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