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

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

Issue 795933009: [AiS] for desktop, two lines and font sytles (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed unnecessary include Created 5 years, 9 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 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <atlbase.h> // NOLINT 8 #include <atlbase.h> // NOLINT
9 #include <atlwin.h> // NOLINT 9 #include <atlwin.h> // NOLINT
10 #endif 10 #endif
11 11
12 #include "chrome/browser/ui/views/omnibox/omnibox_result_view.h" 12 #include "chrome/browser/ui/views/omnibox/omnibox_result_view.h"
13 13
14 #include <algorithm> // NOLINT 14 #include <algorithm> // NOLINT
15 15
16 #include "base/i18n/bidi_line_iterator.h" 16 #include "base/i18n/bidi_line_iterator.h"
17 #include "base/memory/scoped_vector.h" 17 #include "base/memory/scoped_vector.h"
18 #include "base/strings/string_number_conversions.h" 18 #include "base/strings/string_number_conversions.h"
19 #include "base/strings/string_util.h" 19 #include "base/strings/string_util.h"
20 #include "chrome/browser/bitmap_fetcher/bitmap_fetcher_service_factory.h" 20 #include "chrome/browser/bitmap_fetcher/bitmap_fetcher_service_factory.h"
21 #include "chrome/browser/profiles/profile.h" 21 #include "chrome/browser/profiles/profile.h"
22 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h" 22 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h"
23 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" 23 #include "chrome/browser/ui/views/location_bar/location_bar_view.h"
24 #include "chrome/browser/ui/views/omnibox/omnibox_popup_contents_view.h" 24 #include "chrome/browser/ui/views/omnibox/omnibox_popup_contents_view.h"
25 #include "chrome/grit/generated_resources.h" 25 #include "chrome/grit/generated_resources.h"
26 #include "components/omnibox/suggestion_answer.h" 26 #include "components/omnibox/suggestion_answer.h"
27 #include "grit/components_scaled_resources.h" 27 #include "grit/components_scaled_resources.h"
28 #include "grit/theme_resources.h" 28 #include "grit/theme_resources.h"
29 #include "third_party/skia/include/core/SkColor.h"
29 #include "ui/base/l10n/l10n_util.h" 30 #include "ui/base/l10n/l10n_util.h"
30 #include "ui/base/resource/resource_bundle.h" 31 #include "ui/base/resource/resource_bundle.h"
31 #include "ui/base/theme_provider.h" 32 #include "ui/base/theme_provider.h"
32 #include "ui/gfx/canvas.h" 33 #include "ui/gfx/canvas.h"
33 #include "ui/gfx/color_utils.h" 34 #include "ui/gfx/color_utils.h"
34 #include "ui/gfx/image/image.h" 35 #include "ui/gfx/image/image.h"
35 #include "ui/gfx/range/range.h" 36 #include "ui/gfx/range/range.h"
36 #include "ui/gfx/render_text.h" 37 #include "ui/gfx/render_text.h"
37 #include "ui/gfx/text_utils.h" 38 #include "ui/gfx/text_utils.h"
38 39
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 { NativeTheme::kColorId_ResultsTableSelectedUrl, 105 { NativeTheme::kColorId_ResultsTableSelectedUrl,
105 OmniboxResultView::SELECTED, OmniboxResultView::URL }, 106 OmniboxResultView::SELECTED, OmniboxResultView::URL },
106 { NativeTheme::kColorId_ResultsTableNormalDivider, 107 { NativeTheme::kColorId_ResultsTableNormalDivider,
107 OmniboxResultView::NORMAL, OmniboxResultView::DIVIDER }, 108 OmniboxResultView::NORMAL, OmniboxResultView::DIVIDER },
108 { NativeTheme::kColorId_ResultsTableHoveredDivider, 109 { NativeTheme::kColorId_ResultsTableHoveredDivider,
109 OmniboxResultView::HOVERED, OmniboxResultView::DIVIDER }, 110 OmniboxResultView::HOVERED, OmniboxResultView::DIVIDER },
110 { NativeTheme::kColorId_ResultsTableSelectedDivider, 111 { NativeTheme::kColorId_ResultsTableSelectedDivider,
111 OmniboxResultView::SELECTED, OmniboxResultView::DIVIDER }, 112 OmniboxResultView::SELECTED, OmniboxResultView::DIVIDER },
112 }; 113 };
113 114
115 struct TextStyle {
116 ui::ResourceBundle::FontStyle font;
117 ui::NativeTheme::ColorId colors[OmniboxResultView::NUM_STATES];
118 gfx::BaselineStyle baseline;
119 } const kTextStyles[] = {
120 // 1 ANSWER_TEXT
121 {ui::ResourceBundle::LargeFont,
122 {NativeTheme::kColorId_ResultsTableNormalText,
123 NativeTheme::kColorId_ResultsTableHoveredText,
124 NativeTheme::kColorId_ResultsTableSelectedText},
125 gfx::NORMAL_BASELINE},
126 // 2 HEADLINE_TEXT
127 {ui::ResourceBundle::LargeFont,
128 {NativeTheme::kColorId_ResultsTableNormalDimmedText,
129 NativeTheme::kColorId_ResultsTableHoveredDimmedText,
130 NativeTheme::kColorId_ResultsTableSelectedDimmedText},
131 gfx::NORMAL_BASELINE},
132 // 3 TOP_ALIGNED_TEXT
133 {ui::ResourceBundle::LargeFont,
134 {NativeTheme::kColorId_ResultsTableNormalDimmedText,
135 NativeTheme::kColorId_ResultsTableHoveredDimmedText,
136 NativeTheme::kColorId_ResultsTableSelectedDimmedText},
137 gfx::SUPERIOR},
138 // 4 DESCRIPTION_TEXT
139 {ui::ResourceBundle::BaseFont,
140 {NativeTheme::kColorId_ResultsTableNormalDimmedText,
141 NativeTheme::kColorId_ResultsTableHoveredDimmedText,
142 NativeTheme::kColorId_ResultsTableSelectedDimmedText},
143 gfx::NORMAL_BASELINE},
144 // 5 DESCRIPTION_TEXT_NEGATIVE
145 {ui::ResourceBundle::LargeFont,
146 {NativeTheme::kColorId_ResultsTableNegativeText,
147 NativeTheme::kColorId_ResultsTableNegativeHoveredText,
148 NativeTheme::kColorId_ResultsTableNegativeSelectedText},
149 gfx::INFERIOR},
150 // 6 DESCRIPTION_TEXT_POSITIVE
151 {ui::ResourceBundle::LargeFont,
152 {NativeTheme::kColorId_ResultsTablePositiveText,
153 NativeTheme::kColorId_ResultsTablePositiveHoveredText,
154 NativeTheme::kColorId_ResultsTablePositiveSelectedText},
155 gfx::INFERIOR},
156 // 7 MORE_INFO_TEXT
157 {ui::ResourceBundle::SmallFont,
158 {NativeTheme::kColorId_ResultsTableNormalDimmedText,
159 NativeTheme::kColorId_ResultsTableHoveredDimmedText,
160 NativeTheme::kColorId_ResultsTableSelectedDimmedText},
161 gfx::NORMAL_BASELINE},
162 // 8 SUGGESTION_TEXT
163 {ui::ResourceBundle::BaseFont,
164 {NativeTheme::kColorId_ResultsTableNormalText,
165 NativeTheme::kColorId_ResultsTableHoveredText,
166 NativeTheme::kColorId_ResultsTableSelectedText},
167 gfx::NORMAL_BASELINE},
168 // 9 SUGGESTION_TEXT_POSITIVE
169 {ui::ResourceBundle::BaseFont,
170 {NativeTheme::kColorId_ResultsTablePositiveText,
171 NativeTheme::kColorId_ResultsTablePositiveHoveredText,
172 NativeTheme::kColorId_ResultsTablePositiveSelectedText},
173 gfx::NORMAL_BASELINE},
174 // 10 SUGGESTION_TEXT_NEGATIVE
175 {ui::ResourceBundle::BaseFont,
176 {NativeTheme::kColorId_ResultsTableNegativeText,
177 NativeTheme::kColorId_ResultsTableNegativeHoveredText,
178 NativeTheme::kColorId_ResultsTableNegativeSelectedText},
179 gfx::NORMAL_BASELINE},
180 // 11 SUGGESTION_LINK_COLOR
181 {ui::ResourceBundle::BaseFont,
182 {NativeTheme::kColorId_ResultsTableNormalUrl,
183 NativeTheme::kColorId_ResultsTableHoveredUrl,
184 NativeTheme::kColorId_ResultsTableSelectedUrl},
185 gfx::NORMAL_BASELINE},
186 // 12 STATUS_TEXT
187 {ui::ResourceBundle::LargeFont,
188 {NativeTheme::kColorId_ResultsTableNormalDimmedText,
189 NativeTheme::kColorId_ResultsTableHoveredDimmedText,
190 NativeTheme::kColorId_ResultsTableSelectedDimmedText},
191 gfx::INFERIOR},
192 // 13 PERSONALIZED_SUGGESTION_TEXT
193 {ui::ResourceBundle::BaseFont,
194 {NativeTheme::kColorId_ResultsTableNormalText,
195 NativeTheme::kColorId_ResultsTableHoveredText,
196 NativeTheme::kColorId_ResultsTableSelectedText},
197 gfx::NORMAL_BASELINE},
198 };
199
200 const TextStyle& GetTextStyle(size_t type) {
201 if (type > arraysize(kTextStyles))
202 type = 1;
203 // Subtract one because the types are one based (not zero based).
204 return kTextStyles[type - 1];
205 }
206
114 } // namespace 207 } // namespace
115 208
116 //////////////////////////////////////////////////////////////////////////////// 209 ////////////////////////////////////////////////////////////////////////////////
117 // OmniboxResultView, public: 210 // OmniboxResultView, public:
118 211
119 // This class is a utility class for calculations affected by whether the result 212 // This class is a utility class for calculations affected by whether the result
120 // view is horizontally mirrored. The drawing functions can be written as if 213 // view is horizontally mirrored. The drawing functions can be written as if
121 // all drawing occurs left-to-right, and then use this class to get the actual 214 // all drawing occurs left-to-right, and then use this class to get the actual
122 // coordinates to begin drawing onscreen. 215 // coordinates to begin drawing onscreen.
123 class OmniboxResultView::MirroringContext { 216 class OmniboxResultView::MirroringContext {
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after
598 if (!ShowOnlyKeywordMatch()) { 691 if (!ShowOnlyKeywordMatch()) {
599 canvas->DrawImageInt(GetIcon(), GetMirroredXForRect(icon_bounds_), 692 canvas->DrawImageInt(GetIcon(), GetMirroredXForRect(icon_bounds_),
600 icon_bounds_.y()); 693 icon_bounds_.y());
601 int x = GetMirroredXForRect(text_bounds_); 694 int x = GetMirroredXForRect(text_bounds_);
602 mirroring_context_->Initialize(x, text_bounds_.width()); 695 mirroring_context_->Initialize(x, text_bounds_.width());
603 InitContentsRenderTextIfNecessary(); 696 InitContentsRenderTextIfNecessary();
604 697
605 if (!description_rendertext_) { 698 if (!description_rendertext_) {
606 if (match_.answer) { 699 if (match_.answer) {
607 base::string16 text; 700 base::string16 text;
608 for (const auto& textfield : match_.answer->second_line().text_fields())
609 text += textfield.text();
610 description_rendertext_ = CreateRenderText(text); 701 description_rendertext_ = CreateRenderText(text);
611 description_rendertext_->SetFontList( 702 for (const SuggestionAnswer::TextField& textfield :
612 ui::ResourceBundle::GetSharedInstance().GetFontList( 703 match_.answer->second_line().text_fields())
613 ui::ResourceBundle::LargeFont)); 704 AppendAnswerText(textfield);
705 if (match_.answer->second_line().additional_text())
706 AppendAnswerText(*match_.answer->second_line().additional_text());
707 if (match_.answer->second_line().status_text())
708 AppendAnswerText(*match_.answer->second_line().status_text());
614 } else if (!match_.description.empty()) { 709 } else if (!match_.description.empty()) {
615 description_rendertext_ = CreateClassifiedRenderText( 710 description_rendertext_ = CreateClassifiedRenderText(
616 match_.description, match_.description_class, true); 711 match_.description, match_.description_class, true);
617 } 712 }
618 } 713 }
619 PaintMatch(match_, contents_rendertext_.get(), 714 PaintMatch(match_, contents_rendertext_.get(),
620 description_rendertext_.get(), canvas, x); 715 description_rendertext_.get(), canvas, x);
621 } 716 }
622 717
623 AutocompleteMatch* keyword_match = match_.associated_keyword.get(); 718 AutocompleteMatch* keyword_match = match_.associated_keyword.get();
(...skipping 17 matching lines...) Expand all
641 keyword_description_rendertext_.get(), canvas, x); 736 keyword_description_rendertext_.get(), canvas, x);
642 } 737 }
643 } 738 }
644 739
645 void OmniboxResultView::AnimationProgressed(const gfx::Animation* animation) { 740 void OmniboxResultView::AnimationProgressed(const gfx::Animation* animation) {
646 Layout(); 741 Layout();
647 SchedulePaint(); 742 SchedulePaint();
648 } 743 }
649 744
650 int OmniboxResultView::GetAnswerLineHeight() const { 745 int OmniboxResultView::GetAnswerLineHeight() const {
651 // LargeFont is the largest font used and so defines the boundary that 746 // GetTextStyle(1) is the largest font used and so defines the boundary that
652 // all the other answer styles fit within. 747 // all the other answer styles fit within.
653 return ui::ResourceBundle::GetSharedInstance() 748 return ui::ResourceBundle::GetSharedInstance()
654 .GetFontList(ui::ResourceBundle::LargeFont) 749 .GetFontList(GetTextStyle(1).font)
655 .GetHeight(); 750 .GetHeight();
656 } 751 }
657 752
658 int OmniboxResultView::GetContentLineHeight() const { 753 int OmniboxResultView::GetContentLineHeight() const {
659 return std::max(default_icon_size_ + (kMinimumIconVerticalPadding * 2), 754 return std::max(default_icon_size_ + (kMinimumIconVerticalPadding * 2),
660 GetTextHeight() + (kMinimumTextVerticalPadding * 2)); 755 GetTextHeight() + (kMinimumTextVerticalPadding * 2));
661 } 756 }
757
758 void OmniboxResultView::AppendAnswerText(
759 const SuggestionAnswer::TextField& text_field) {
760 int offset = description_rendertext_->text().length();
761 gfx::Range range(offset, offset + text_field.text().length());
762 description_rendertext_->AppendText(text_field.text());
763 const TextStyle& text_style = GetTextStyle(text_field.type());
764 // TODO(dschuyler): follow up on the problem of different font sizes within
765 // one RenderText.
766 description_rendertext_->SetFontList(
767 ui::ResourceBundle::GetSharedInstance().GetFontList(text_style.font));
768 description_rendertext_->ApplyColor(
769 GetNativeTheme()->GetSystemColor(text_style.colors[GetState()]), range);
770 description_rendertext_->ApplyBaselineStyle(text_style.baseline, range);
771 }
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