Chromium Code Reviews| Index: chrome/browser/ui/views/omnibox/omnibox_result_view.cc |
| diff --git a/chrome/browser/ui/views/omnibox/omnibox_result_view.cc b/chrome/browser/ui/views/omnibox/omnibox_result_view.cc |
| index e6f67e2adc2cfc82516f86d75f0553b173b42485..d49994964703adae7774a61b5de203cf3041d1d5 100644 |
| --- a/chrome/browser/ui/views/omnibox/omnibox_result_view.cc |
| +++ b/chrome/browser/ui/views/omnibox/omnibox_result_view.cc |
| @@ -23,10 +23,12 @@ |
| #include "chrome/browser/ui/views/location_bar/location_bar_view.h" |
| #include "chrome/browser/ui/views/omnibox/omnibox_popup_contents_view.h" |
| #include "chrome/grit/generated_resources.h" |
| +#include "components/omnibox/omnibox_field_trial.h" |
| #include "components/omnibox/suggestion_answer.h" |
| #include "grit/components_scaled_resources.h" |
| #include "grit/theme_resources.h" |
| #include "ui/base/l10n/l10n_util.h" |
| +#include "ui/base/resource/resource_bundle.h" |
| #include "ui/base/theme_provider.h" |
| #include "ui/gfx/canvas.h" |
| #include "ui/gfx/color_utils.h" |
| @@ -112,6 +114,109 @@ struct TranslationTable { |
| OmniboxResultView::SELECTED, OmniboxResultView::DIVIDER }, |
| }; |
| +// 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.
|
| +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.
|
| +const SkColor kColorGrey = SkColorSetRGB(0x80, 0x80, 0x80); |
| +const SkColor kColorRed = SkColorSetRGB(0xff, 0x00, 0x00); |
| +const SkColor kColorGreen = SkColorSetRGB(0xff, 0x00, 0x00); |
| +const SkColor kColorBlue = SkColorSetRGB(0x00, 0x00, 0xff); |
| +const SkColor kColorPurple = SkColorSetRGB(0x80, 0x00, 0x80); |
| +const SkColor kColorRedish = SkColorSetRGB(0xdd, 0x4b, 0x39); |
| +const SkColor kColorGreenish = SkColorSetRGB(0x3d, 0x94, 0x00); |
| + |
| +// Styles from the Answers in Suggest UI spec. |
| +struct TextStyles { |
| + ui::ResourceBundle::FontStyle font; |
| + SkColor color; |
| + gfx::BaselineStyle baseline; |
| +} const kTextStyles[]{ |
|
Peter Kasting
2015/03/12 09:46:00
Nit: Missing space
dschuyler
2015/03/13 06:01:22
Done.
|
| + // 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
|
| + // 1 ANSWER_TEXT |
| + { |
| + 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
|
| + kColorBlack, |
| + gfx::NORMAL_BASELINE, |
| + }, |
| + // 2 HEADLINE_TEXT |
| + { |
| + ui::ResourceBundle::LargeFont, |
| + kColorGrey, |
| + gfx::NORMAL_BASELINE, |
| + }, |
| + // 3 TOP_ALIGNED_TEXT |
| + { |
| + ui::ResourceBundle::LargeFont, |
| + kColorGrey, |
| + gfx::SUPERIOR, |
| + }, |
| + // 4 DESCRIPTION_TEXT |
| + { |
| + ui::ResourceBundle::BaseFont, |
| + kColorGrey, |
| + gfx::NORMAL_BASELINE, |
| + }, |
| + // 5 DESCRIPTION_TEXT_NEGATIVE |
| + { |
| + ui::ResourceBundle::LargeFont, |
| + kColorRedish, |
| + gfx::INFERIOR, |
| + }, |
| + // 6 DESCRIPTION_TEXT_POSITIVE |
| + { |
| + ui::ResourceBundle::LargeFont, |
| + kColorGreenish, |
| + gfx::INFERIOR, |
| + }, |
| + // 7 MORE_INFO_TEXT |
| + { |
| + ui::ResourceBundle::SmallFont, |
| + kColorGrey, |
| + gfx::NORMAL_BASELINE, |
| + }, |
| + // 8 SUGGESTION_TEXT |
| + { |
| + ui::ResourceBundle::BaseFont, |
| + kColorBlack, |
| + gfx::NORMAL_BASELINE, |
| + }, |
| + // 9 SUGGESTION_TEXT_POSITIVE |
| + { |
| + ui::ResourceBundle::BaseFont, |
| + kColorGreen, |
| + gfx::NORMAL_BASELINE, |
| + }, |
| + // 10 SUGGESTION_TEXT_NEGATIVE |
| + { |
| + ui::ResourceBundle::BaseFont, |
| + kColorRed, |
| + gfx::NORMAL_BASELINE, |
| + }, |
| + // 11 SUGGESTION_LINK_COLOR |
| + { |
| + ui::ResourceBundle::BaseFont, |
| + kColorBlue, |
| + gfx::NORMAL_BASELINE, |
| + }, |
| + // 12 STATUS_TEXT |
| + { |
| + ui::ResourceBundle::LargeFont, |
| + kColorGrey, |
| + gfx::INFERIOR, |
| + }, |
| + // 13 PERSONALIZED_SUGGESTION_TEXT |
| + { |
| + ui::ResourceBundle::BaseFont, |
| + 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.
|
| + gfx::NORMAL_BASELINE, |
| + }, |
| +}; |
| +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.
|
| + |
| +const TextStyles& GetTextStyle(int type) { |
| + // Subtract one because the types are one based (not zero based). |
| + 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
|
| +} |
| + |
| } // namespace |
| //////////////////////////////////////////////////////////////////////////////// |
| @@ -250,9 +355,14 @@ void OmniboxResultView::Invalidate() { |
| } |
| gfx::Size OmniboxResultView::GetPreferredSize() const { |
| - return gfx::Size(0, std::max( |
| - default_icon_size_ + (kMinimumIconVerticalPadding * 2), |
| - GetTextHeight() + (minimum_text_vertical_padding_ * 2))); |
| + 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.
|
| + // An answer implies a match and a description in a large font. |
| + return gfx::Size(0, GetContentLineHeight() + |
| + ui::ResourceBundle::GetSharedInstance() |
| + .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.
|
| + .GetHeight()); |
| + } |
| + return gfx::Size(0, GetContentLineHeight()); |
| } |
| //////////////////////////////////////////////////////////////////////////////// |
| @@ -293,21 +403,29 @@ void OmniboxResultView::PaintMatch(const AutocompleteMatch& match, |
| &contents_max_width, |
| &description_max_width); |
| - x = DrawRenderText(match, contents, true, canvas, x, y, contents_max_width); |
| + int after_contents_x = |
| + DrawRenderText(match, contents, true, canvas, x, y, contents_max_width); |
| if (description_max_width != 0) { |
| - x = DrawRenderText(match, separator_rendertext_.get(), false, canvas, x, y, |
| - separator_width_); |
| - |
| - if (!answer_image_.isNull()) { |
| - canvas->DrawImageInt(answer_image_, |
| - // Source x, y, w, h. |
| - 0, 0, answer_image_.width(), answer_image_.height(), |
| - // Destination x, y, w, h. |
| - GetMirroredXInView(x), |
| - y + kMinimumIconVerticalPadding, default_icon_size_, |
| - default_icon_size_, true); |
| - x += default_icon_size_ + LocationBarView::kIconInternalPadding; |
| + if (match.answer) { |
| + y += GetContentLineHeight(); |
| + if (!answer_image_.isNull()) { |
| + 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
|
| + ui::ResourceBundle::GetSharedInstance() |
| + .GetFontList(ui::ResourceBundle::LargeFont) |
|
Peter Kasting
2015/03/12 09:46:00
Same question
dschuyler
2015/03/13 06:01:21
Done.
|
| + .GetBaseline(); |
| + canvas->DrawImageInt( |
| + answer_image_, |
| + // Source x, y, w, h. |
| + 0, 0, answer_image_.width(), answer_image_.height(), |
| + // Destination x, y, w, h. |
| + GetMirroredXInView(x), y + kMinimumIconVerticalPadding, |
| + 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
|
| + x += answer_icon_size + LocationBarView::kIconInternalPadding; |
| + } |
| + } else { |
| + x = DrawRenderText(match, separator_rendertext_.get(), false, canvas, |
| + after_contents_x, y, separator_width_); |
| } |
| DrawRenderText(match, description, false, canvas, x, y, |
| @@ -378,17 +496,17 @@ int OmniboxResultView::DrawRenderText( |
| gfx::DIRECTIONALITY_FORCE_RTL : gfx::DIRECTIONALITY_FORCE_LTR); |
| prefix_render_text->SetHorizontalAlignment( |
| is_match_contents_rtl ? gfx::ALIGN_RIGHT : gfx::ALIGN_LEFT); |
| - prefix_render_text->SetDisplayRect(gfx::Rect( |
| - mirroring_context_->mirrored_left_coord( |
| - prefix_x, prefix_x + prefix_width), y, |
| - prefix_width, height())); |
| + prefix_render_text->SetDisplayRect( |
| + gfx::Rect(mirroring_context_->mirrored_left_coord( |
| + prefix_x, prefix_x + prefix_width), |
| + y, prefix_width, GetContentLineHeight())); |
| prefix_render_text->Draw(canvas); |
| } |
| // Set the display rect to trigger eliding. |
| - render_text->SetDisplayRect(gfx::Rect( |
| - mirroring_context_->mirrored_left_coord(x, right_x), y, |
| - right_x - x, height())); |
| + render_text->SetDisplayRect( |
| + gfx::Rect(mirroring_context_->mirrored_left_coord(x, right_x), y, |
| + right_x - x, GetContentLineHeight())); |
| render_text->Draw(canvas); |
| return right_x; |
| } |
| @@ -554,10 +672,12 @@ void OmniboxResultView::InitContentsRenderTextIfNecessary() const { |
| void OmniboxResultView::Layout() { |
| const gfx::ImageSkia icon = GetIcon(); |
| - icon_bounds_.SetRect(edge_item_padding_ + |
| - ((icon.width() == default_icon_size_) ? |
| - 0 : LocationBarView::kIconInternalPadding), |
| - (height() - icon.height()) / 2, icon.width(), icon.height()); |
| + icon_bounds_.SetRect( |
| + edge_item_padding_ + ((icon.width() == default_icon_size_) |
| + ? 0 |
| + : LocationBarView::kIconInternalPadding), |
| + (GetContentLineHeight() - icon.height()) / 2, icon.width(), |
| + icon.height()); |
| int text_x = edge_item_padding_ + default_icon_size_ + item_padding_; |
| int text_width = width() - text_x - edge_item_padding_; |
| @@ -602,9 +722,30 @@ void OmniboxResultView::OnPaint(gfx::Canvas* canvas) { |
| if (!description_rendertext_) { |
| if (match_.answer) { |
| base::string16 text; |
| + 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
|
| for (const auto& textfield : match_.answer->second_line().text_fields()) |
| text += textfield.text(); |
| + if (match_.answer->second_line().additional_text()) { |
| + text += spacer; |
| + text += match_.answer->second_line().additional_text()->text(); |
| + } |
| + if (match_.answer->second_line().status_text()) |
| + text += match_.answer->second_line().status_text()->text(); |
| description_rendertext_ = CreateRenderText(text); |
| + int text_offset = 0; |
| + for (const auto& textfield : |
| + match_.answer->second_line().text_fields()) { |
| + text_offset = StyleAnswerText(description_rendertext_.get(), |
| + text_offset, textfield); |
| + } |
| + if (match_.answer->second_line().additional_text()) |
| + text_offset = StyleAnswerText( |
| + description_rendertext_.get(), text_offset + spacer.length(), |
| + *match_.answer->second_line().additional_text()); |
| + if (match_.answer->second_line().status_text()) |
| + text_offset = |
| + StyleAnswerText(description_rendertext_.get(), text_offset, |
| + *match_.answer->second_line().status_text()); |
| } else if (!match_.description.empty()) { |
| description_rendertext_ = CreateClassifiedRenderText( |
| match_.description, match_.description_class, true); |
| @@ -640,3 +781,27 @@ void OmniboxResultView::AnimationProgressed(const gfx::Animation* animation) { |
| Layout(); |
| SchedulePaint(); |
| } |
| + |
| +int OmniboxResultView::StyleAnswerText( |
| + gfx::RenderText* render_text, |
| + int offset, |
| + const SuggestionAnswer::TextField& text_field) const { |
| + int length = text_field.text().length(); |
| + gfx::Range range(offset, offset + length); |
| + const TextStyles& text_style = GetTextStyle(text_field.type()); |
| + render_text->SetFontList( |
| + ui::ResourceBundle::GetSharedInstance().GetFontList(text_style.font)); |
| + render_text->ApplyColor( |
| + GetState() == SELECTED |
| + ? GetNativeTheme()->GetSystemColor( |
| + 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.
|
| + : text_style.color, |
| + range); |
| + render_text->ApplyBaselineStyle(text_style.baseline, range); |
| + return offset + length; |
| +} |
| + |
| +int OmniboxResultView::GetContentLineHeight() const { |
| + return std::max(default_icon_size_ + (kMinimumIconVerticalPadding * 2), |
| + GetTextHeight() + (minimum_text_vertical_padding_ * 2)); |
| +} |