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

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

Issue 2834073004: Refine the layout of omnibox answer suggestions. (Closed)
Patch Set: Created 3 years, 8 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 bc71cdf4d05f2003db63b53907d6dd64e74b89d9..a841b1ef4ddcbccc7e449f5d7b44ca780e39651e 100644
--- a/chrome/browser/ui/views/omnibox/omnibox_result_view.cc
+++ b/chrome/browser/ui/views/omnibox/omnibox_result_view.cc
@@ -48,6 +48,9 @@ using ui::NativeTheme;
namespace {
+// The padding that should be placed between lines in a top and bottom layout.
Peter Kasting 2017/04/24 22:16:05 What is "a top and bottom layout"? Do you mean "W
Justin Donnelly 2017/04/25 16:52:30 "Top and bottom" is meant to distinguish a layout
+static const int kVerticalPadding = 3;
+
// A mapping from OmniboxResultView's ResultViewState/ColorKind types to
// NativeTheme colors.
struct TranslationTable {
@@ -294,20 +297,10 @@ void OmniboxResultView::OnSelected() {
}
gfx::Size OmniboxResultView::GetPreferredSize() const {
- if (!match_.answer)
- return gfx::Size(0, GetContentLineHeight());
- 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(), GetAnswerLineFont());
- }
- description_rendertext_->SetDisplayRect(
- gfx::Rect(text_bounds_.width(), 0));
- description_rendertext_->GetStringSize();
- return gfx::Size(
- 0, GetContentLineHeight() +
- GetAnswerLineHeight() * description_rendertext_->GetNumLines());
+ int height = GetTextHeight() + (2 * GetVerticalMargin());
+ if (match_.answer)
+ height += GetAnswerLineHeight() + kVerticalPadding;
+ return gfx::Size(0, height);
}
void OmniboxResultView::GetAccessibleNodeData(ui::AXNodeData* node_data) {
@@ -341,7 +334,7 @@ void OmniboxResultView::PaintMatch(const AutocompleteMatch& match,
gfx::RenderText* description,
gfx::Canvas* canvas,
int x) const {
- int y = text_bounds_.y();
+ int y = text_bounds_.y() + GetVerticalMargin();
if (!separator_rendertext_) {
const base::string16& separator =
@@ -370,7 +363,7 @@ void OmniboxResultView::PaintMatch(const AutocompleteMatch& match,
if (description_max_width != 0) {
if (match.answer) {
- y += GetContentLineHeight();
+ y += GetTextHeight() + kVerticalPadding;
if (!answer_image_.isNull()) {
int answer_icon_size = GetAnswerLineHeight();
Peter Kasting 2017/04/24 22:16:05 This will vertically center the icon against (howe
Justin Donnelly 2017/04/25 16:52:30 Yes, that's what I want. With multiple lines of te
canvas->DrawImageInt(
@@ -460,21 +453,17 @@ int OmniboxResultView::DrawRenderText(
prefix_render_text->SetDisplayRect(
gfx::Rect(mirroring_context_->mirrored_left_coord(
prefix_x, prefix_x + prefix_width),
- y, prefix_width, GetContentLineHeight()));
+ y, prefix_width, GetTextHeight()));
prefix_render_text->Draw(canvas);
}
// Set the display rect to trigger elision.
- const int final_width = right_x - x;
- int height = GetContentLineHeight();
- if (render_text_type == DESCRIPTION && match.answer) {
- render_text->SetDisplayRect(gfx::Rect(gfx::Size(final_width, 0)));
- render_text->GetStringSize();
- height = GetAnswerLineHeight() * render_text->GetNumLines();
- }
+ int height = (render_text_type == DESCRIPTION && match.answer)
+ ? GetAnswerLineHeight()
+ : GetTextHeight();
render_text->SetDisplayRect(
gfx::Rect(mirroring_context_->mirrored_left_coord(x, right_x), y,
- final_width, height));
+ right_x - x, height));
render_text->Draw(canvas);
return right_x;
}
@@ -625,8 +614,9 @@ void OmniboxResultView::Layout() {
const int end_x = width() - start_x;
const gfx::ImageSkia icon = GetIcon();
- icon_bounds_.SetRect(start_x, (GetContentLineHeight() - icon.height()) / 2,
- icon.width(), icon.height());
+ const int icon_y =
+ GetVerticalMargin() + (GetTextHeight() - icon.height()) / 2;
+ icon_bounds_.SetRect(start_x, icon_y, icon.width(), icon.height());
const int text_x = start_x + LocationBarView::kIconWidth + horizontal_padding;
int text_width = end_x - text_x;
@@ -665,7 +655,7 @@ void OmniboxResultView::OnPaint(gfx::Canvas* canvas) {
if (!description_rendertext_) {
if (match_.answer) {
description_rendertext_ =
- CreateAnswerLine(match_.answer->second_line(), GetAnswerLineFont());
+ CreateAnswerLine(match_.answer->second_line(), GetAnswerFont());
} else if (!match_.description.empty()) {
description_rendertext_ = CreateClassifiedRenderText(
match_.description, match_.description_class, true);
@@ -698,7 +688,7 @@ void OmniboxResultView::AnimationProgressed(const gfx::Animation* animation) {
SchedulePaint();
}
-const gfx::FontList& OmniboxResultView::GetAnswerLineFont() const {
+const gfx::FontList& OmniboxResultView::GetAnswerFont() 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
@@ -712,16 +702,31 @@ const gfx::FontList& OmniboxResultView::GetAnswerLineFont() const {
}
int OmniboxResultView::GetAnswerLineHeight() const {
Peter Kasting 2017/04/24 22:16:05 Nit: Seems like GetAnswerHeight() would be better
Justin Donnelly 2017/04/25 16:52:30 Good point, done. Also changed CreateAnswerLine()
- return GetAnswerLineFont().GetHeight();
+ // If the answer specifies a maximum of 1 line we can simply return the answer
+ // font height.
+ if (match_.answer->second_line().num_text_lines() == 1)
+ return GetAnswerFont().GetHeight();
+
+ // Multi-line answers require layout in order to determine the number of lines
+ // the RenderText will use.
+ if (!description_rendertext_) {
+ description_rendertext_ =
+ CreateAnswerLine(match_.answer->second_line(), GetAnswerFont());
+ }
+ description_rendertext_->SetDisplayRect(gfx::Rect(text_bounds_.width(), 0));
+ description_rendertext_->GetStringSize();
+ return GetAnswerFont().GetHeight() * description_rendertext_->GetNumLines();
}
-int OmniboxResultView::GetContentLineHeight() const {
+int OmniboxResultView::GetVerticalMargin() const {
+ // Regardless of the text size, we ensure a minimum size for the content line
Justin Donnelly 2017/04/21 16:57:08 This is my understanding of what this logic is try
+ // here. This minimum is larger for hybrid mouse/touch devices to ensure an
+ // adequately sized touch target.
using Md = ui::MaterialDesignController;
const int kIconVerticalPad = Md::GetMode() == Md::MATERIAL_HYBRID ? 8 : 4;
- const int kTextVerticalPad = 3;
- return std::max(
- LocationBarView::kIconWidth + 2 * kIconVerticalPad,
- GetTextHeight() + 2 * kTextVerticalPad);
+ const int min_height = LocationBarView::kIconWidth + 2 * kIconVerticalPad;
+
+ return std::max(kVerticalPadding, (min_height - GetTextHeight()) / 2);
}
std::unique_ptr<gfx::RenderText> OmniboxResultView::CreateAnswerLine(
« 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