Commit d99c328d authored by Dave Schuyler's avatar Dave Schuyler Committed by Commit Bot

[Omnibox] center rich layout images; change entity images to 32px

This CL changes the rich layout images to be centered in a box to the
left of the text lines. This allows for answer images and entity images
to be different sizes without doing a lot of less readable math.

Bug: 798631
Change-Id: I882305ca09353266f02115446f481bff00b00e12
Reviewed-on: https://chromium-review.googlesource.com/1094263Reviewed-by: default avatarKevin Bailey <krb@chromium.org>
Reviewed-by: default avatarJustin Donnelly <jdonnelly@chromium.org>
Commit-Queue: Dave Schuyler <dschuyler@chromium.org>
Cr-Commit-Position: refs/heads/master@{#567048}
parent ce567f01
...@@ -30,11 +30,11 @@ ...@@ -30,11 +30,11 @@
namespace { namespace {
// The left-hand margin used for rows with the refresh UI. // The left-hand margin used for rows with the refresh UI.
static constexpr int kRefreshMarginLeft = 12; static constexpr int kRefreshMarginLeft = 4;
// In the MD refresh or rich suggestions, x-offset of the content and // In the MD refresh or rich suggestions, x-offset of the content and
// description text. // description text.
static constexpr int kTextIndent = 40; static constexpr int kTextIndent = 48;
// TODO(dschuyler): Perhaps this should be based on the font size // TODO(dschuyler): Perhaps this should be based on the font size
// instead of hardcoded to 2 dp (e.g. by adding a space in an // instead of hardcoded to 2 dp (e.g. by adding a space in an
...@@ -42,9 +42,15 @@ static constexpr int kTextIndent = 40; ...@@ -42,9 +42,15 @@ static constexpr int kTextIndent = 40;
// the additional padding here to zero). // the additional padding here to zero).
static constexpr int kAnswerIconToTextPadding = 2; static constexpr int kAnswerIconToTextPadding = 2;
// The edge length of the rich suggestions images. // The edge length of the refresh layout image area.
static constexpr int kRichImageSize = 24; static constexpr int kRefreshImageBoxSize = 40;
static constexpr int kRichImageCornerRadius = 4;
// The diameter of the new answer layout images.
static constexpr int kNewAnswerImageSize = 24;
// The edge length of the entity suggestions images.
static constexpr int kEntityImageSize = 32;
static constexpr int kEntityImageCornerRadius = 4;
// The minimum vertical margin that should be used above and below each // The minimum vertical margin that should be used above and below each
// suggestion. // suggestion.
...@@ -52,7 +58,6 @@ static constexpr int kMinVerticalMargin = 1; ...@@ -52,7 +58,6 @@ static constexpr int kMinVerticalMargin = 1;
// The margin height of a split row when MD refresh is enabled. // The margin height of a split row when MD refresh is enabled.
static constexpr int kRefreshSplitMarginHeight = 8; static constexpr int kRefreshSplitMarginHeight = 8;
static constexpr int kRefreshSplitAdditionalMargin = 4;
// The margin height of a rich suggestion row. // The margin height of a rich suggestion row.
static constexpr int kRichSuggestionMarginHeight = 4; static constexpr int kRichSuggestionMarginHeight = 4;
...@@ -169,8 +174,8 @@ void PlaceholderImageSource::Draw(gfx::Canvas* canvas) { ...@@ -169,8 +174,8 @@ void PlaceholderImageSource::Draw(gfx::Canvas* canvas) {
flags.setStyle(cc::PaintFlags::kStrokeAndFill_Style); flags.setStyle(cc::PaintFlags::kStrokeAndFill_Style);
flags.setColor(color_); flags.setColor(color_);
canvas->sk_canvas()->drawRoundRect(gfx::RectToSkRect(gfx::Rect(size_)), canvas->sk_canvas()->drawRoundRect(gfx::RectToSkRect(gfx::Rect(size_)),
kRichImageCornerRadius, kEntityImageCornerRadius,
kRichImageCornerRadius, flags); kEntityImageCornerRadius, flags);
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
...@@ -191,8 +196,8 @@ class OmniboxImageView : public views::ImageView { ...@@ -191,8 +196,8 @@ class OmniboxImageView : public views::ImageView {
void OmniboxImageView::OnPaint(gfx::Canvas* canvas) { void OmniboxImageView::OnPaint(gfx::Canvas* canvas) {
gfx::Path mask; gfx::Path mask;
mask.addRoundRect(gfx::RectToSkRect(GetImageBounds()), kRichImageCornerRadius, mask.addRoundRect(gfx::RectToSkRect(GetImageBounds()),
kRichImageCornerRadius); kEntityImageCornerRadius, kEntityImageCornerRadius);
canvas->ClipPath(mask, true); canvas->ClipPath(mask, true);
ImageView::OnPaint(canvas); ImageView::OnPaint(canvas);
} }
...@@ -212,6 +217,13 @@ OmniboxMatchCellView::OmniboxMatchCellView(OmniboxResultView* result_view) ...@@ -212,6 +217,13 @@ OmniboxMatchCellView::OmniboxMatchCellView(OmniboxResultView* result_view)
AddChildView(description_view_ = new OmniboxTextView(result_view)); AddChildView(description_view_ = new OmniboxTextView(result_view));
AddChildView(separator_view_ = new OmniboxTextView(result_view)); AddChildView(separator_view_ = new OmniboxTextView(result_view));
if (ui::MaterialDesignController::IsRefreshUi()) {
icon_view_->SetHorizontalAlignment(views::ImageView::CENTER);
icon_view_->SetVerticalAlignment(views::ImageView::CENTER);
}
image_view_->SetHorizontalAlignment(views::ImageView::CENTER);
image_view_->SetVerticalAlignment(views::ImageView::CENTER);
const base::string16& separator = const base::string16& separator =
l10n_util::GetStringUTF16(IDS_AUTOCOMPLETE_MATCH_DESCRIPTION_SEPARATOR); l10n_util::GetStringUTF16(IDS_AUTOCOMPLETE_MATCH_DESCRIPTION_SEPARATOR);
separator_view_->SetText(separator); separator_view_->SetText(separator);
...@@ -281,7 +293,7 @@ void OmniboxMatchCellView::OnMatchUpdate(const OmniboxResultView* result_view, ...@@ -281,7 +293,7 @@ void OmniboxMatchCellView::OnMatchUpdate(const OmniboxResultView* result_view,
image_view_->SetImage(gfx::ImageSkia()); image_view_->SetImage(gfx::ImageSkia());
image_view_->SetSize(gfx::Size()); image_view_->SetSize(gfx::Size());
} else { } else {
// Set up the larger image. // Determine if we have a local icon (or else it will be downloaded).
const gfx::VectorIcon* vector_icon = nullptr; const gfx::VectorIcon* vector_icon = nullptr;
if (match.answer) { if (match.answer) {
switch (match.answer->type()) { switch (match.answer->type()) {
...@@ -306,16 +318,21 @@ void OmniboxMatchCellView::OnMatchUpdate(const OmniboxResultView* result_view, ...@@ -306,16 +318,21 @@ void OmniboxMatchCellView::OnMatchUpdate(const OmniboxResultView* result_view,
default: default:
break; break;
} }
}
if (vector_icon) { if (vector_icon) {
image_view_->SetImage(gfx::CreateVectorIcon(*vector_icon, kRichImageSize, image_view_->SetImage(gfx::CreateVectorIcon(
gfx::kGoogleBlue600)); *vector_icon, kNewAnswerImageSize, gfx::kGoogleBlue600));
}
// Always set the image size so that downloaded images get the correct
// size (such as Weather answers).
image_view_->SetImageSize(
gfx::Size(kNewAnswerImageSize, kNewAnswerImageSize));
} else { } else {
SkColor color = result_view->GetColor(OmniboxPart::RESULTS_BACKGROUND); SkColor color = result_view->GetColor(OmniboxPart::RESULTS_BACKGROUND);
extensions::image_util::ParseHexColorString(match.image_dominant_color, extensions::image_util::ParseHexColorString(match.image_dominant_color,
&color); &color);
color = SkColorSetA(color, 0x40); // 25% transparency (arbitrary). color = SkColorSetA(color, 0x40); // 25% transparency (arbitrary).
const gfx::Size size = gfx::Size(kRichImageSize, kRichImageSize); const gfx::Size size = gfx::Size(kEntityImageSize, kEntityImageSize);
image_view_->SetImageSize(size);
image_view_->SetImage( image_view_->SetImage(
gfx::CanvasImageSource::MakeImageSkia<PlaceholderImageSource>(size, gfx::CanvasImageSource::MakeImageSkia<PlaceholderImageSource>(size,
color)); color));
...@@ -348,6 +365,8 @@ void OmniboxMatchCellView::Layout() { ...@@ -348,6 +365,8 @@ void OmniboxMatchCellView::Layout() {
} }
void OmniboxMatchCellView::LayoutOldStyleAnswer() { void OmniboxMatchCellView::LayoutOldStyleAnswer() {
// TODO(dschuyler): Remove this layout once rich layouts are enabled by
// default.
gfx::Rect child_area = GetContentsBounds(); gfx::Rect child_area = GetContentsBounds();
const int text_height = content_view_->GetLineHeight(); const int text_height = content_view_->GetLineHeight();
int x = child_area.x(); int x = child_area.x();
...@@ -375,12 +394,9 @@ void OmniboxMatchCellView::LayoutRichSuggestion() { ...@@ -375,12 +394,9 @@ void OmniboxMatchCellView::LayoutRichSuggestion() {
gfx::Rect child_area = GetContentsBounds(); gfx::Rect child_area = GetContentsBounds();
int x = child_area.x(); int x = child_area.x();
int y = child_area.y(); int y = child_area.y();
int row_height = child_area.height(); image_view_->SetBounds(x, y, kRefreshImageBoxSize, child_area.height());
const int text_width = child_area.width() - kTextIndent;
const int text_height = content_view_->GetLineHeight(); const int text_height = content_view_->GetLineHeight();
image_view_->SetImageSize(gfx::Size(kRichImageSize, kRichImageSize));
image_view_->SetBounds(x, y + (row_height - kRichImageSize) / 2,
kRichImageSize, kRichImageSize);
int text_width = child_area.width() - kTextIndent;
content_view_->SetBounds(x + kTextIndent, y, text_width, text_height); content_view_->SetBounds(x + kTextIndent, y, text_width, text_height);
description_view_->SetBounds( description_view_->SetBounds(
x + kTextIndent, y + text_height, text_width, x + kTextIndent, y + text_height, text_width,
...@@ -389,15 +405,16 @@ void OmniboxMatchCellView::LayoutRichSuggestion() { ...@@ -389,15 +405,16 @@ void OmniboxMatchCellView::LayoutRichSuggestion() {
void OmniboxMatchCellView::LayoutSplit(int text_indent) { void OmniboxMatchCellView::LayoutSplit(int text_indent) {
gfx::Rect child_area = GetContentsBounds(); gfx::Rect child_area = GetContentsBounds();
icon_view_->SetSize(icon_view_->CalculatePreferredSize());
int row_height = child_area.height(); int row_height = child_area.height();
int icon_x = child_area.x();
if (ui::MaterialDesignController::IsRefreshUi()) {
icon_x += kRefreshSplitAdditionalMargin;
}
int y = child_area.y(); int y = child_area.y();
if (ui::MaterialDesignController::IsRefreshUi()) {
icon_view_->SetBounds(child_area.x(), y, kRefreshImageBoxSize, row_height);
} else {
int icon_x = child_area.x();
icon_view_->SetSize(icon_view_->CalculatePreferredSize());
icon_view_->SetPosition( icon_view_->SetPosition(
gfx::Point(icon_x, y + (row_height - icon_view_->height()) / 2)); gfx::Point(icon_x, y + (row_height - icon_view_->height()) / 2));
}
int content_width = content_view_->CalculatePreferredSize().width(); int content_width = content_view_->CalculatePreferredSize().width();
int description_width = description_view_->CalculatePreferredSize().width(); int description_width = description_view_->CalculatePreferredSize().width();
gfx::Size separator_size = separator_view_->CalculatePreferredSize(); gfx::Size separator_size = separator_view_->CalculatePreferredSize();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment