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

Unified Diff: chrome/browser/ui/views/omnibox/omnibox_result_view.cc

Issue 2671323003: Fix the size of omnibox suggestion answers. (Closed)
Patch Set: 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 a91113692703a538094cd399bf96c4a9f21c8028..3bcde2435dc5c02a8381ee01a13170cc74c221a7 100644
--- a/chrome/browser/ui/views/omnibox/omnibox_result_view.cc
+++ b/chrome/browser/ui/views/omnibox/omnibox_result_view.cc
@@ -86,6 +86,19 @@ struct TextStyle {
gfx::BaselineStyle baseline;
};
+// Returns the styles that should be applied to the specified answer text type.
+//
+// Note that the font value is only consulted for the first text type that
+// appears on an answer line, because RenderText does not yet support multiple
+// font sizes. Subsequent text types on the same line will share the text size
+// of the first type, while the color and baseline styles specified here will
+// always apply. The gfx::INFERIOR baseline style is used as a workaround to
+// produce smaller text on the same line. The way this is used in the current
+// set of answers is that the small types (TOP_ALIGNED, DESCRIPTION_NEGATIVE,
+// DESCRIPTION_POSITIVE and SUGGESTION_SECONDARY_TEXT_SMALL) only ever appear
+// following LargeFont text, so for consistency they specify LargeFont for the
+// first value even though this is not actually used (since they're not the
+// first value).
TextStyle GetTextStyle(int type) {
switch (type) {
case SuggestionAnswer::TOP_ALIGNED:
@@ -124,7 +137,12 @@ TextStyle GetTextStyle(int type) {
NativeTheme::kColorId_ResultsTableHoveredText,
NativeTheme::kColorId_ResultsTableSelectedText},
gfx::NORMAL_BASELINE};
- case SuggestionAnswer::SUGGESTION_SECONDARY_TEXT_SMALL: // Fall through.
+ case SuggestionAnswer::SUGGESTION_SECONDARY_TEXT_SMALL:
+ return {ui::ResourceBundle::LargeFont,
+ {NativeTheme::kColorId_ResultsTableNormalDimmedText,
+ NativeTheme::kColorId_ResultsTableHoveredDimmedText,
+ NativeTheme::kColorId_ResultsTableSelectedDimmedText},
+ gfx::INFERIOR};
case SuggestionAnswer::SUGGESTION_SECONDARY_TEXT_MEDIUM:
return {ui::ResourceBundle::BaseFont,
{NativeTheme::kColorId_ResultsTableNormalDimmedText,
@@ -278,12 +296,11 @@ void OmniboxResultView::OnSelected() {
gfx::Size OmniboxResultView::GetPreferredSize() const {
if (!match_.answer)
return gfx::Size(0, GetContentLineHeight());
- // An answer implies a match and a description in a large font.
if (match_.answer->second_line().num_text_lines() == 1)
return gfx::Size(0, GetContentLineHeight() + GetAnswerLineHeight());
if (!description_rendertext_) {
description_rendertext_ =
- CreateAnswerLine(match_.answer->second_line(), font_list_);
+ CreateAnswerLine(match_.answer->second_line(), GetAnswerLineFont());
}
description_rendertext_->SetDisplayRect(
gfx::Rect(text_bounds_.width(), 0));
@@ -647,7 +664,7 @@ void OmniboxResultView::OnPaint(gfx::Canvas* canvas) {
contents_rendertext_ =
CreateAnswerLine(match_.answer->first_line(), font_list_);
description_rendertext_ =
- CreateAnswerLine(match_.answer->second_line(), font_list_);
+ CreateAnswerLine(match_.answer->second_line(), GetAnswerLineFont());
} else if (!match_.description.empty()) {
description_rendertext_ = CreateClassifiedRenderText(
match_.description, match_.description_class, true);
@@ -684,12 +701,21 @@ void OmniboxResultView::AnimationProgressed(const gfx::Animation* animation) {
SchedulePaint();
}
+const gfx::FontList& OmniboxResultView::GetAnswerLineFont() const {
+ // This assumes that the first text type in the second answer line can be used
+ // to specify the font for all the text fields in the line. For now this works
+ // but eventually it will be necessary to get RenderText to support multiple
+ // font sizes or use multiple RenderTexts.
+ int text_type =
+ match_.answer && !match_.answer->second_line().text_fields().empty()
+ ? match_.answer->second_line().text_fields()[0].type()
+ : SuggestionAnswer::SUGGESTION;
+ return ui::ResourceBundle::GetSharedInstance().GetFontList(
+ GetTextStyle(text_type).font);
+}
+
int OmniboxResultView::GetAnswerLineHeight() const {
- // ANSWER_TEXT_LARGE is the largest font used and so defines the boundary that
- // all the other answer styles fit within.
- return ui::ResourceBundle::GetSharedInstance()
- .GetFontList(GetTextStyle(SuggestionAnswer::ANSWER_TEXT_LARGE).font)
- .GetHeight();
+ return GetAnswerLineFont().GetHeight();
}
int OmniboxResultView::GetContentLineHeight() const {
@@ -703,7 +729,7 @@ int OmniboxResultView::GetContentLineHeight() const {
std::unique_ptr<gfx::RenderText> OmniboxResultView::CreateAnswerLine(
const SuggestionAnswer::ImageLine& line,
- gfx::FontList font_list) const {
+ const gfx::FontList& font_list) const {
std::unique_ptr<gfx::RenderText> destination =
CreateRenderText(base::string16());
destination->SetFontList(font_list);
« 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