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

Unified 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: Increase vertical spacing in suggestions 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 side-by-side diff with in-line comments
Download patch
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..aee4ebf8fceffd7ccde106cf6660ac65ab88898c 100644
--- a/chrome/browser/ui/views/omnibox/omnibox_result_view.cc
+++ b/chrome/browser/ui/views/omnibox/omnibox_result_view.cc
@@ -23,10 +23,13 @@
#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 "third_party/skia/include/core/SkColor.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 +115,86 @@ struct TranslationTable {
OmniboxResultView::SELECTED, OmniboxResultView::DIVIDER },
};
+struct TextStyles {
+ ui::ResourceBundle::FontStyle font;
+ NativeTheme::ColorId color;
+ NativeTheme::ColorId color_selected;
+ gfx::BaselineStyle baseline;
+} const kTextStyles[] = {
+ // 1 ANSWER_TEXT
+ {ui::ResourceBundle::LargeFont,
+ NativeTheme::kColorId_AnswerNormalText,
Justin Donnelly 2015/03/13 21:08:33 You've pushed some knowledge of the Answers spec i
dschuyler 2015/03/13 21:48:23 Seems reasonable.
+ NativeTheme::kColorId_AnswerNormalTextSelected,
+ gfx::NORMAL_BASELINE},
+ // 2 HEADLINE_TEXT
+ {ui::ResourceBundle::LargeFont,
+ NativeTheme::kColorId_AnswerInfoText,
+ NativeTheme::kColorId_AnswerInfoTextSelected,
+ gfx::NORMAL_BASELINE},
+ // 3 TOP_ALIGNED_TEXT
+ {ui::ResourceBundle::LargeFont,
+ NativeTheme::kColorId_AnswerInfoText,
+ NativeTheme::kColorId_AnswerInfoTextSelected,
+ gfx::SUPERIOR},
+ // 4 DESCRIPTION_TEXT
+ {ui::ResourceBundle::BaseFont,
+ NativeTheme::kColorId_AnswerInfoText,
+ NativeTheme::kColorId_AnswerInfoTextSelected,
+ gfx::NORMAL_BASELINE},
+ // 5 DESCRIPTION_TEXT_NEGATIVE
+ {ui::ResourceBundle::LargeFont,
+ NativeTheme::kColorId_AnswerNegativeText,
+ NativeTheme::kColorId_AnswerNegativeTextSelected,
+ gfx::INFERIOR},
+ // 6 DESCRIPTION_TEXT_POSITIVE
+ {ui::ResourceBundle::LargeFont,
+ NativeTheme::kColorId_AnswerPositiveText,
+ NativeTheme::kColorId_AnswerPositiveTextSelected,
+ gfx::INFERIOR},
+ // 7 MORE_INFO_TEXT
+ {ui::ResourceBundle::SmallFont,
+ NativeTheme::kColorId_AnswerInfoText,
+ NativeTheme::kColorId_AnswerInfoTextSelected,
+ gfx::NORMAL_BASELINE},
+ // 8 SUGGESTION_TEXT
+ {ui::ResourceBundle::BaseFont,
+ NativeTheme::kColorId_AnswerNormalText,
+ NativeTheme::kColorId_AnswerNormalTextSelected,
+ gfx::NORMAL_BASELINE},
+ // 9 SUGGESTION_TEXT_POSITIVE
+ {ui::ResourceBundle::BaseFont,
+ NativeTheme::kColorId_AnswerPositiveText,
+ NativeTheme::kColorId_AnswerPositiveTextSelected,
+ gfx::NORMAL_BASELINE},
+ // 10 SUGGESTION_TEXT_NEGATIVE
+ {ui::ResourceBundle::BaseFont,
+ NativeTheme::kColorId_AnswerNegativeText,
+ NativeTheme::kColorId_AnswerNegativeTextSelected,
+ gfx::NORMAL_BASELINE},
+ // 11 SUGGESTION_LINK_COLOR
+ {ui::ResourceBundle::BaseFont,
+ NativeTheme::kColorId_AnswerLinkText,
+ NativeTheme::kColorId_AnswerLinkTextSelected,
+ gfx::NORMAL_BASELINE},
+ // 12 STATUS_TEXT
+ {ui::ResourceBundle::LargeFont,
+ NativeTheme::kColorId_AnswerInfoText,
+ NativeTheme::kColorId_AnswerInfoTextSelected,
+ gfx::INFERIOR},
+ // 13 PERSONALIZED_SUGGESTION_TEXT
+ {ui::ResourceBundle::BaseFont,
+ NativeTheme::kColorId_AnswerInfoText,
+ NativeTheme::kColorId_AnswerInfoTextSelected,
+ gfx::NORMAL_BASELINE},
+};
+
+const TextStyles& GetTextStyle(int type) {
+ if (type > (int)arraysize(kTextStyles))
+ type = 1;
+ // Subtract one because the types are one based (not zero based).
+ return kTextStyles[(type - 1)];
+}
+
} // namespace
////////////////////////////////////////////////////////////////////////////////
@@ -250,9 +333,13 @@ 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)
+ return gfx::Size(0, GetContentLineHeight());
+ // An answer implies a match and a description in a large font.
+ return gfx::Size(0, GetContentLineHeight() +
+ ui::ResourceBundle::GetSharedInstance()
+ .GetFontList(GetTextStyle(1).font)
Justin Donnelly 2015/03/13 21:08:33 An explanation of why 1 would be helpful.
dschuyler 2015/03/13 21:48:23 Done.
+ .GetHeight());
}
////////////////////////////////////////////////////////////////////////////////
@@ -293,21 +380,30 @@ 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()) {
+ // Add one to draw all the way on to the bottom and left pixels.
+ // i.e. make the destination rect <= rather than strictly less than.
+ int answer_icon_size = 1 +
+ ui::ResourceBundle::GetSharedInstance()
+ .GetFontList(GetTextStyle(1).font)
Justin Donnelly 2015/03/13 21:08:33 This is used in a couple places. How about GetAnsw
dschuyler 2015/03/13 21:48:23 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, answer_icon_size, answer_icon_size, true);
+ 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 +474,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 +650,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 +700,30 @@ void OmniboxResultView::OnPaint(gfx::Canvas* canvas) {
if (!description_rendertext_) {
if (match_.answer) {
base::string16 text;
+ const base::string16 spacer(base::UTF8ToUTF16(" "));
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 +759,26 @@ 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(text_style.color_selected)
+ : GetNativeTheme()->GetSystemColor(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));
+}

Powered by Google App Engine
This is Rietveld 408576698