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

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: Positive/Negative font change 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
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/omnibox_field_trial.h"
26 #include "components/omnibox/suggestion_answer.h" 27 #include "components/omnibox/suggestion_answer.h"
27 #include "grit/components_scaled_resources.h" 28 #include "grit/components_scaled_resources.h"
28 #include "grit/theme_resources.h" 29 #include "grit/theme_resources.h"
29 #include "ui/base/l10n/l10n_util.h" 30 #include "ui/base/l10n/l10n_util.h"
31 #include "ui/base/resource/resource_bundle.h"
30 #include "ui/base/theme_provider.h" 32 #include "ui/base/theme_provider.h"
31 #include "ui/gfx/canvas.h" 33 #include "ui/gfx/canvas.h"
32 #include "ui/gfx/color_utils.h" 34 #include "ui/gfx/color_utils.h"
33 #include "ui/gfx/image/image.h" 35 #include "ui/gfx/image/image.h"
34 #include "ui/gfx/range/range.h" 36 #include "ui/gfx/range/range.h"
35 #include "ui/gfx/render_text.h" 37 #include "ui/gfx/render_text.h"
36 #include "ui/gfx/text_utils.h" 38 #include "ui/gfx/text_utils.h"
37 #include "ui/native_theme/native_theme.h" 39 #include "ui/native_theme/native_theme.h"
38 40
39 using ui::NativeTheme; 41 using ui::NativeTheme;
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 { NativeTheme::kColorId_ResultsTableSelectedUrl, 107 { NativeTheme::kColorId_ResultsTableSelectedUrl,
106 OmniboxResultView::SELECTED, OmniboxResultView::URL }, 108 OmniboxResultView::SELECTED, OmniboxResultView::URL },
107 { NativeTheme::kColorId_ResultsTableNormalDivider, 109 { NativeTheme::kColorId_ResultsTableNormalDivider,
108 OmniboxResultView::NORMAL, OmniboxResultView::DIVIDER }, 110 OmniboxResultView::NORMAL, OmniboxResultView::DIVIDER },
109 { NativeTheme::kColorId_ResultsTableHoveredDivider, 111 { NativeTheme::kColorId_ResultsTableHoveredDivider,
110 OmniboxResultView::HOVERED, OmniboxResultView::DIVIDER }, 112 OmniboxResultView::HOVERED, OmniboxResultView::DIVIDER },
111 { NativeTheme::kColorId_ResultsTableSelectedDivider, 113 { NativeTheme::kColorId_ResultsTableSelectedDivider,
112 OmniboxResultView::SELECTED, OmniboxResultView::DIVIDER }, 114 OmniboxResultView::SELECTED, OmniboxResultView::DIVIDER },
113 }; 115 };
114 116
117 // Colors from the Answers in Suggest UI spec.
Peter Kasting 2015/03/12 09:46:00 This comment doesn't seem to tell the reader anyth
dschuyler 2015/03/13 06:01:22 Done.
118 const SkColor kColorBlack = SkColorSetRGB(0x00, 0x00, 0x00);
Peter Kasting 2015/03/12 09:46:00 Don't define new constants for anything that's alr
dschuyler 2015/03/13 06:01:21 Done.
119 const SkColor kColorGrey = SkColorSetRGB(0x80, 0x80, 0x80);
120 const SkColor kColorRed = SkColorSetRGB(0xff, 0x00, 0x00);
121 const SkColor kColorGreen = SkColorSetRGB(0xff, 0x00, 0x00);
122 const SkColor kColorBlue = SkColorSetRGB(0x00, 0x00, 0xff);
123 const SkColor kColorPurple = SkColorSetRGB(0x80, 0x00, 0x80);
124 const SkColor kColorRedish = SkColorSetRGB(0xdd, 0x4b, 0x39);
125 const SkColor kColorGreenish = SkColorSetRGB(0x3d, 0x94, 0x00);
126
127 // Styles from the Answers in Suggest UI spec.
128 struct TextStyles {
129 ui::ResourceBundle::FontStyle font;
130 SkColor color;
131 gfx::BaselineStyle baseline;
132 } const kTextStyles[]{
Peter Kasting 2015/03/12 09:46:00 Nit: Missing space
dschuyler 2015/03/13 06:01:22 Done.
133 // 0 Zero is not used as a style type.
Peter Kasting 2015/03/12 09:46:00 Nit: Remove this comment, all it does is imply the
dschuyler 2015/03/13 06:01:22 This is cl format. Should I report a bug in cl fo
134 // 1 ANSWER_TEXT
135 {
136 ui::ResourceBundle::LargeFont,
Peter Kasting 2015/03/12 09:45:59 Nit: Indent 2 more, not 1
dschuyler 2015/03/13 06:01:21 I can adjust this by hand. This should be already
137 kColorBlack,
138 gfx::NORMAL_BASELINE,
139 },
140 // 2 HEADLINE_TEXT
141 {
142 ui::ResourceBundle::LargeFont,
143 kColorGrey,
144 gfx::NORMAL_BASELINE,
145 },
146 // 3 TOP_ALIGNED_TEXT
147 {
148 ui::ResourceBundle::LargeFont,
149 kColorGrey,
150 gfx::SUPERIOR,
151 },
152 // 4 DESCRIPTION_TEXT
153 {
154 ui::ResourceBundle::BaseFont,
155 kColorGrey,
156 gfx::NORMAL_BASELINE,
157 },
158 // 5 DESCRIPTION_TEXT_NEGATIVE
159 {
160 ui::ResourceBundle::LargeFont,
161 kColorRedish,
162 gfx::INFERIOR,
163 },
164 // 6 DESCRIPTION_TEXT_POSITIVE
165 {
166 ui::ResourceBundle::LargeFont,
167 kColorGreenish,
168 gfx::INFERIOR,
169 },
170 // 7 MORE_INFO_TEXT
171 {
172 ui::ResourceBundle::SmallFont,
173 kColorGrey,
174 gfx::NORMAL_BASELINE,
175 },
176 // 8 SUGGESTION_TEXT
177 {
178 ui::ResourceBundle::BaseFont,
179 kColorBlack,
180 gfx::NORMAL_BASELINE,
181 },
182 // 9 SUGGESTION_TEXT_POSITIVE
183 {
184 ui::ResourceBundle::BaseFont,
185 kColorGreen,
186 gfx::NORMAL_BASELINE,
187 },
188 // 10 SUGGESTION_TEXT_NEGATIVE
189 {
190 ui::ResourceBundle::BaseFont,
191 kColorRed,
192 gfx::NORMAL_BASELINE,
193 },
194 // 11 SUGGESTION_LINK_COLOR
195 {
196 ui::ResourceBundle::BaseFont,
197 kColorBlue,
198 gfx::NORMAL_BASELINE,
199 },
200 // 12 STATUS_TEXT
201 {
202 ui::ResourceBundle::LargeFont,
203 kColorGrey,
204 gfx::INFERIOR,
205 },
206 // 13 PERSONALIZED_SUGGESTION_TEXT
207 {
208 ui::ResourceBundle::BaseFont,
209 kColorPurple,
Peter Kasting 2015/03/12 09:46:00 While google.com uses purple for personalized sugg
Justin Donnelly 2015/03/12 14:34:18 Yes, I used normal suggestion color for these on m
dschuyler 2015/03/13 06:01:21 Done.
dschuyler 2015/03/13 06:01:22 Done.
210 gfx::NORMAL_BASELINE,
211 },
212 };
213 const int kTextStyleCount = sizeof(kTextStyles) / sizeof(kTextStyles[0]);
Peter Kasting 2015/03/12 09:46:00 Don't do this; use arraysize(kTextStyles) below wh
dschuyler 2015/03/13 06:01:22 Done.
214
215 const TextStyles& GetTextStyle(int type) {
216 // Subtract one because the types are one based (not zero based).
217 return kTextStyles[(type - 1) % kTextStyleCount];
Peter Kasting 2015/03/12 09:46:00 Using % here seems questionable; if the server giv
dschuyler 2015/03/13 06:01:21 :) too much time focusing on performance. The mod
218 }
219
115 } // namespace 220 } // namespace
116 221
117 //////////////////////////////////////////////////////////////////////////////// 222 ////////////////////////////////////////////////////////////////////////////////
118 // OmniboxResultView, public: 223 // OmniboxResultView, public:
119 224
120 // This class is a utility class for calculations affected by whether the result 225 // This class is a utility class for calculations affected by whether the result
121 // view is horizontally mirrored. The drawing functions can be written as if 226 // view is horizontally mirrored. The drawing functions can be written as if
122 // all drawing occurs left-to-right, and then use this class to get the actual 227 // all drawing occurs left-to-right, and then use this class to get the actual
123 // coordinates to begin drawing onscreen. 228 // coordinates to begin drawing onscreen.
124 class OmniboxResultView::MirroringContext { 229 class OmniboxResultView::MirroringContext {
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 void OmniboxResultView::Invalidate() { 348 void OmniboxResultView::Invalidate() {
244 keyword_icon_->SetImage(GetKeywordIcon()); 349 keyword_icon_->SetImage(GetKeywordIcon());
245 // While the text in the RenderTexts may not have changed, the styling 350 // While the text in the RenderTexts may not have changed, the styling
246 // (color/bold) may need to change. So we reset them to cause them to be 351 // (color/bold) may need to change. So we reset them to cause them to be
247 // recomputed in OnPaint(). 352 // recomputed in OnPaint().
248 ResetRenderTexts(); 353 ResetRenderTexts();
249 SchedulePaint(); 354 SchedulePaint();
250 } 355 }
251 356
252 gfx::Size OmniboxResultView::GetPreferredSize() const { 357 gfx::Size OmniboxResultView::GetPreferredSize() const {
253 return gfx::Size(0, std::max( 358 if (match_.answer) {
Peter Kasting 2015/03/12 09:45:59 Nit: If you reverse this conditional, you can omit
dschuyler 2015/03/13 06:01:20 Done.
254 default_icon_size_ + (kMinimumIconVerticalPadding * 2), 359 // An answer implies a match and a description in a large font.
255 GetTextHeight() + (minimum_text_vertical_padding_ * 2))); 360 return gfx::Size(0, GetContentLineHeight() +
361 ui::ResourceBundle::GetSharedInstance()
362 .GetFontList(ui::ResourceBundle::LargeFont)
Peter Kasting 2015/03/12 09:45:59 Hmm, technically rather than hardcoding LargeFont
dschuyler 2015/03/13 06:01:22 Done.
363 .GetHeight());
364 }
365 return gfx::Size(0, GetContentLineHeight());
256 } 366 }
257 367
258 //////////////////////////////////////////////////////////////////////////////// 368 ////////////////////////////////////////////////////////////////////////////////
259 // OmniboxResultView, protected: 369 // OmniboxResultView, protected:
260 370
261 OmniboxResultView::ResultViewState OmniboxResultView::GetState() const { 371 OmniboxResultView::ResultViewState OmniboxResultView::GetState() const {
262 if (model_->IsSelectedIndex(model_index_)) 372 if (model_->IsSelectedIndex(model_index_))
263 return SELECTED; 373 return SELECTED;
264 return model_->IsHoveredIndex(model_index_) ? HOVERED : NORMAL; 374 return model_->IsHoveredIndex(model_index_) ? HOVERED : NORMAL;
265 } 375 }
(...skipping 20 matching lines...) Expand all
286 int contents_max_width, description_max_width; 396 int contents_max_width, description_max_width;
287 OmniboxPopupModel::ComputeMatchMaxWidths( 397 OmniboxPopupModel::ComputeMatchMaxWidths(
288 contents->GetContentWidth(), 398 contents->GetContentWidth(),
289 separator_width_, 399 separator_width_,
290 description ? description->GetContentWidth() : 0, 400 description ? description->GetContentWidth() : 0,
291 mirroring_context_->remaining_width(x), 401 mirroring_context_->remaining_width(x),
292 !AutocompleteMatch::IsSearchType(match.type), 402 !AutocompleteMatch::IsSearchType(match.type),
293 &contents_max_width, 403 &contents_max_width,
294 &description_max_width); 404 &description_max_width);
295 405
296 x = DrawRenderText(match, contents, true, canvas, x, y, contents_max_width); 406 int after_contents_x =
407 DrawRenderText(match, contents, true, canvas, x, y, contents_max_width);
297 408
298 if (description_max_width != 0) { 409 if (description_max_width != 0) {
299 x = DrawRenderText(match, separator_rendertext_.get(), false, canvas, x, y, 410 if (match.answer) {
300 separator_width_); 411 y += GetContentLineHeight();
301 412 if (!answer_image_.isNull()) {
302 if (!answer_image_.isNull()) { 413 int answer_icon_size = 1 +
Peter Kasting 2015/03/12 09:46:00 Why 1?
dschuyler 2015/03/13 06:01:21 I've added a comment. While it's hard to tell fro
303 canvas->DrawImageInt(answer_image_, 414 ui::ResourceBundle::GetSharedInstance()
304 // Source x, y, w, h. 415 .GetFontList(ui::ResourceBundle::LargeFont)
Peter Kasting 2015/03/12 09:46:00 Same question
dschuyler 2015/03/13 06:01:21 Done.
305 0, 0, answer_image_.width(), answer_image_.height(), 416 .GetBaseline();
306 // Destination x, y, w, h. 417 canvas->DrawImageInt(
307 GetMirroredXInView(x), 418 answer_image_,
308 y + kMinimumIconVerticalPadding, default_icon_size_, 419 // Source x, y, w, h.
309 default_icon_size_, true); 420 0, 0, answer_image_.width(), answer_image_.height(),
310 x += default_icon_size_ + LocationBarView::kIconInternalPadding; 421 // Destination x, y, w, h.
422 GetMirroredXInView(x), y + kMinimumIconVerticalPadding,
423 answer_icon_size, answer_icon_size, true);
Peter Kasting 2015/03/12 09:45:59 Do we really want to scale the icon to the text he
Justin Donnelly 2015/03/12 14:34:18 The provided size is not in any way adjusted for t
Peter Kasting 2015/03/12 15:55:44 I'm just concerned that this can probably take eve
dschuyler 2015/03/13 06:01:21 For now at least, I think it's what we have to wor
424 x += answer_icon_size + LocationBarView::kIconInternalPadding;
425 }
426 } else {
427 x = DrawRenderText(match, separator_rendertext_.get(), false, canvas,
428 after_contents_x, y, separator_width_);
311 } 429 }
312 430
313 DrawRenderText(match, description, false, canvas, x, y, 431 DrawRenderText(match, description, false, canvas, x, y,
314 description_max_width); 432 description_max_width);
315 } 433 }
316 } 434 }
317 435
318 int OmniboxResultView::DrawRenderText( 436 int OmniboxResultView::DrawRenderText(
319 const AutocompleteMatch& match, 437 const AutocompleteMatch& match,
320 gfx::RenderText* render_text, 438 gfx::RenderText* render_text,
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 const int start_offset = std::max(prefix_width, 489 const int start_offset = std::max(prefix_width,
372 std::min(remaining_width - max_match_contents_width, offset)); 490 std::min(remaining_width - max_match_contents_width, offset));
373 right_x = x + std::min(remaining_width, start_offset + max_width); 491 right_x = x + std::min(remaining_width, start_offset + max_width);
374 x += start_offset; 492 x += start_offset;
375 prefix_x = x - prefix_width; 493 prefix_x = x - prefix_width;
376 } 494 }
377 prefix_render_text->SetDirectionalityMode(is_match_contents_rtl ? 495 prefix_render_text->SetDirectionalityMode(is_match_contents_rtl ?
378 gfx::DIRECTIONALITY_FORCE_RTL : gfx::DIRECTIONALITY_FORCE_LTR); 496 gfx::DIRECTIONALITY_FORCE_RTL : gfx::DIRECTIONALITY_FORCE_LTR);
379 prefix_render_text->SetHorizontalAlignment( 497 prefix_render_text->SetHorizontalAlignment(
380 is_match_contents_rtl ? gfx::ALIGN_RIGHT : gfx::ALIGN_LEFT); 498 is_match_contents_rtl ? gfx::ALIGN_RIGHT : gfx::ALIGN_LEFT);
381 prefix_render_text->SetDisplayRect(gfx::Rect( 499 prefix_render_text->SetDisplayRect(
382 mirroring_context_->mirrored_left_coord( 500 gfx::Rect(mirroring_context_->mirrored_left_coord(
383 prefix_x, prefix_x + prefix_width), y, 501 prefix_x, prefix_x + prefix_width),
384 prefix_width, height())); 502 y, prefix_width, GetContentLineHeight()));
385 prefix_render_text->Draw(canvas); 503 prefix_render_text->Draw(canvas);
386 } 504 }
387 505
388 // Set the display rect to trigger eliding. 506 // Set the display rect to trigger eliding.
389 render_text->SetDisplayRect(gfx::Rect( 507 render_text->SetDisplayRect(
390 mirroring_context_->mirrored_left_coord(x, right_x), y, 508 gfx::Rect(mirroring_context_->mirrored_left_coord(x, right_x), y,
391 right_x - x, height())); 509 right_x - x, GetContentLineHeight()));
392 render_text->Draw(canvas); 510 render_text->Draw(canvas);
393 return right_x; 511 return right_x;
394 } 512 }
395 513
396 scoped_ptr<gfx::RenderText> OmniboxResultView::CreateRenderText( 514 scoped_ptr<gfx::RenderText> OmniboxResultView::CreateRenderText(
397 const base::string16& text) const { 515 const base::string16& text) const {
398 scoped_ptr<gfx::RenderText> render_text(gfx::RenderText::CreateInstance()); 516 scoped_ptr<gfx::RenderText> render_text(gfx::RenderText::CreateInstance());
399 render_text->SetDisplayRect(gfx::Rect(gfx::Size(INT_MAX, 0))); 517 render_text->SetDisplayRect(gfx::Rect(gfx::Size(INT_MAX, 0)));
400 render_text->SetCursorEnabled(false); 518 render_text->SetCursorEnabled(false);
401 render_text->SetElideBehavior(gfx::ELIDE_TAIL); 519 render_text->SetElideBehavior(gfx::ELIDE_TAIL);
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
547 if (!contents_rendertext_) { 665 if (!contents_rendertext_) {
548 contents_rendertext_.reset( 666 contents_rendertext_.reset(
549 CreateClassifiedRenderText( 667 CreateClassifiedRenderText(
550 match_.contents, match_.contents_class, false).release()); 668 match_.contents, match_.contents_class, false).release());
551 } 669 }
552 } 670 }
553 671
554 void OmniboxResultView::Layout() { 672 void OmniboxResultView::Layout() {
555 const gfx::ImageSkia icon = GetIcon(); 673 const gfx::ImageSkia icon = GetIcon();
556 674
557 icon_bounds_.SetRect(edge_item_padding_ + 675 icon_bounds_.SetRect(
558 ((icon.width() == default_icon_size_) ? 676 edge_item_padding_ + ((icon.width() == default_icon_size_)
559 0 : LocationBarView::kIconInternalPadding), 677 ? 0
560 (height() - icon.height()) / 2, icon.width(), icon.height()); 678 : LocationBarView::kIconInternalPadding),
679 (GetContentLineHeight() - icon.height()) / 2, icon.width(),
680 icon.height());
561 681
562 int text_x = edge_item_padding_ + default_icon_size_ + item_padding_; 682 int text_x = edge_item_padding_ + default_icon_size_ + item_padding_;
563 int text_width = width() - text_x - edge_item_padding_; 683 int text_width = width() - text_x - edge_item_padding_;
564 684
565 if (match_.associated_keyword.get()) { 685 if (match_.associated_keyword.get()) {
566 const int kw_collapsed_size = 686 const int kw_collapsed_size =
567 keyword_icon_->width() + edge_item_padding_; 687 keyword_icon_->width() + edge_item_padding_;
568 const int max_kw_x = width() - kw_collapsed_size; 688 const int max_kw_x = width() - kw_collapsed_size;
569 const int kw_x = 689 const int kw_x =
570 animation_->CurrentValueBetween(max_kw_x, edge_item_padding_); 690 animation_->CurrentValueBetween(max_kw_x, edge_item_padding_);
(...skipping 24 matching lines...) Expand all
595 if (!ShowOnlyKeywordMatch()) { 715 if (!ShowOnlyKeywordMatch()) {
596 canvas->DrawImageInt(GetIcon(), GetMirroredXForRect(icon_bounds_), 716 canvas->DrawImageInt(GetIcon(), GetMirroredXForRect(icon_bounds_),
597 icon_bounds_.y()); 717 icon_bounds_.y());
598 int x = GetMirroredXForRect(text_bounds_); 718 int x = GetMirroredXForRect(text_bounds_);
599 mirroring_context_->Initialize(x, text_bounds_.width()); 719 mirroring_context_->Initialize(x, text_bounds_.width());
600 InitContentsRenderTextIfNecessary(); 720 InitContentsRenderTextIfNecessary();
601 721
602 if (!description_rendertext_) { 722 if (!description_rendertext_) {
603 if (match_.answer) { 723 if (match_.answer) {
604 base::string16 text; 724 base::string16 text;
725 const base::string16 spacer(base::UTF8ToUTF16(" "));
Peter Kasting 2015/03/12 09:46:00 You can't concatenate strings this way; this doesn
Justin Donnelly 2015/03/12 14:34:18 I'm not quite sure what you're proposing here, Pet
Peter Kasting 2015/03/12 15:55:44 Yes.
dschuyler 2015/03/13 06:01:22 I agree that it's weird. Justin and I have discus
Justin Donnelly 2015/03/13 21:08:32 For sure, you're right to be wary of a simplistic
Peter Kasting 2015/03/14 01:54:13 At the least, I think you can make this code clean
dschuyler 2015/03/16 21:49:09 How about AppendText, so as to be a bit more gener
605 for (const auto& textfield : match_.answer->second_line().text_fields()) 726 for (const auto& textfield : match_.answer->second_line().text_fields())
606 text += textfield.text(); 727 text += textfield.text();
728 if (match_.answer->second_line().additional_text()) {
729 text += spacer;
730 text += match_.answer->second_line().additional_text()->text();
731 }
732 if (match_.answer->second_line().status_text())
733 text += match_.answer->second_line().status_text()->text();
607 description_rendertext_ = CreateRenderText(text); 734 description_rendertext_ = CreateRenderText(text);
735 int text_offset = 0;
736 for (const auto& textfield :
737 match_.answer->second_line().text_fields()) {
738 text_offset = StyleAnswerText(description_rendertext_.get(),
739 text_offset, textfield);
740 }
741 if (match_.answer->second_line().additional_text())
742 text_offset = StyleAnswerText(
743 description_rendertext_.get(), text_offset + spacer.length(),
744 *match_.answer->second_line().additional_text());
745 if (match_.answer->second_line().status_text())
746 text_offset =
747 StyleAnswerText(description_rendertext_.get(), text_offset,
748 *match_.answer->second_line().status_text());
608 } else if (!match_.description.empty()) { 749 } else if (!match_.description.empty()) {
609 description_rendertext_ = CreateClassifiedRenderText( 750 description_rendertext_ = CreateClassifiedRenderText(
610 match_.description, match_.description_class, true); 751 match_.description, match_.description_class, true);
611 } 752 }
612 } 753 }
613 PaintMatch(match_, contents_rendertext_.get(), 754 PaintMatch(match_, contents_rendertext_.get(),
614 description_rendertext_.get(), canvas, x); 755 description_rendertext_.get(), canvas, x);
615 } 756 }
616 757
617 AutocompleteMatch* keyword_match = match_.associated_keyword.get(); 758 AutocompleteMatch* keyword_match = match_.associated_keyword.get();
(...skipping 15 matching lines...) Expand all
633 } 774 }
634 PaintMatch(*keyword_match, keyword_contents_rendertext_.get(), 775 PaintMatch(*keyword_match, keyword_contents_rendertext_.get(),
635 keyword_description_rendertext_.get(), canvas, x); 776 keyword_description_rendertext_.get(), canvas, x);
636 } 777 }
637 } 778 }
638 779
639 void OmniboxResultView::AnimationProgressed(const gfx::Animation* animation) { 780 void OmniboxResultView::AnimationProgressed(const gfx::Animation* animation) {
640 Layout(); 781 Layout();
641 SchedulePaint(); 782 SchedulePaint();
642 } 783 }
784
785 int OmniboxResultView::StyleAnswerText(
786 gfx::RenderText* render_text,
787 int offset,
788 const SuggestionAnswer::TextField& text_field) const {
789 int length = text_field.text().length();
790 gfx::Range range(offset, offset + length);
791 const TextStyles& text_style = GetTextStyle(text_field.type());
792 render_text->SetFontList(
793 ui::ResourceBundle::GetSharedInstance().GetFontList(text_style.font));
794 render_text->ApplyColor(
795 GetState() == SELECTED
796 ? GetNativeTheme()->GetSystemColor(
797 NativeTheme::kColorId_ResultsTableSelectedText)
Peter Kasting 2015/03/12 09:46:00 This turns all the text the same color when the an
dschuyler 2015/03/16 21:49:09 Done.
798 : text_style.color,
799 range);
800 render_text->ApplyBaselineStyle(text_style.baseline, range);
801 return offset + length;
802 }
803
804 int OmniboxResultView::GetContentLineHeight() const {
805 return std::max(default_icon_size_ + (kMinimumIconVerticalPadding * 2),
806 GetTextHeight() + (minimum_text_vertical_padding_ * 2));
807 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698