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

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

Issue 2070733002: Update omnibox dropdown selection/hover background drawing for MD. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@scaled_radius
Patch Set: Created 4 years, 6 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 b81569068cb18c9c2d21c90c3fa62efeb9a80eb8..db32db044b1df1eb2b072d9b94c93fdb98a5f809 100644
--- a/chrome/browser/ui/views/omnibox/omnibox_result_view.cc
+++ b/chrome/browser/ui/views/omnibox/omnibox_result_view.cc
@@ -21,6 +21,8 @@
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "chrome/browser/ui/layout_constants.h"
+#include "chrome/browser/ui/views/location_bar/background_with_1_px_border.h"
+#include "chrome/browser/ui/views/location_bar/icon_label_bubble_view.h"
#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"
@@ -40,6 +42,7 @@
#include "ui/gfx/paint_vector_icon.h"
#include "ui/gfx/range/range.h"
#include "ui/gfx/render_text.h"
+#include "ui/gfx/scoped_canvas.h"
#include "ui/gfx/text_utils.h"
#include "ui/gfx/vector_icons_public.h"
#include "ui/native_theme/native_theme.h"
@@ -638,10 +641,16 @@ void OmniboxResultView::InitContentsRenderTextIfNecessary() const {
}
void OmniboxResultView::Layout() {
- const int horizontal_padding =
+ int horizontal_padding =
GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING);
- const int start_x = StartMargin() + horizontal_padding;
- const int end_x = width() - EndMargin() - horizontal_padding;
+ // In non-material, the horizontal bounds we're given are indented inside the
+ // omnibox border. In material, we're given the outside bounds, so we can
+ // match the omnibox border outline shape exactly in OnPaint(). So we have to
+ // inset here to keep the icons lined up.
+ const int border_padding = ui::MaterialDesignController::IsModeMaterial() ?
+ GetLayoutConstant(LOCATION_BAR_BORDER_THICKNESS) : 0;
+ const int start_x = border_padding + horizontal_padding;
+ const int end_x = width() - border_padding - horizontal_padding;
const gfx::ImageSkia icon = GetIcon();
// Pre-MD, normal icons are 19 px wide, while extension icons are 16 px wide.
@@ -677,13 +686,34 @@ void OmniboxResultView::Layout() {
}
void OmniboxResultView::OnBoundsChanged(const gfx::Rect& previous_bounds) {
- animation_->SetSlideDuration((width() - StartMargin() - EndMargin()) / 4);
+ animation_->SetSlideDuration(width() / 4);
}
void OmniboxResultView::OnPaint(gfx::Canvas* canvas) {
const ResultViewState state = GetState();
- if (state != NORMAL)
- canvas->DrawColor(GetColor(state, BACKGROUND));
+ if (state != NORMAL) {
+ const SkColor background_color = GetColor(state, BACKGROUND);
+ if (ui::MaterialDesignController::IsModeMaterial()) {
+ SkPaint paint;
+ paint.setAntiAlias(true);
+ paint.setColor(background_color);
+
+ // This is similar to the code in BackgroundWith1PxBorder, except that
+ // instead of stroking along a path offset by 0.5 px, we're filling to
+ // where the edge of that stroke would be (i.e. on a whole-pixel
+ // boundary).
+ gfx::RectF rect(GetLocalBounds());
+ gfx::ScopedCanvas scoped_canvas(canvas);
+ const float scale = canvas->UndoDeviceScaleFactor();
+ rect.Scale(scale);
+ rect.Inset(GetLayoutConstant(LOCATION_BAR_BORDER_THICKNESS) * scale - 1,
+ 0);
+ canvas->DrawRoundRect(
+ rect, BackgroundWith1PxBorder::kCornerRadius * scale + 1, paint);
Evan Stade 2016/06/16 16:11:32 Would it be possible to set a bgwith1pxborder on |
Peter Kasting 2016/06/16 17:57:13 Yes, although doing it right took more effort than
+ } else {
+ canvas->DrawColor(background_color);
+ }
+ }
// NOTE: While animating the keyword match, both matches may be visible.
@@ -829,13 +859,3 @@ void OmniboxResultView::AppendAnswerTextHelper(gfx::RenderText* destination,
GetNativeTheme()->GetSystemColor(text_style.colors[GetState()]), range);
destination->ApplyBaselineStyle(text_style.baseline, range);
}
-
-int OmniboxResultView::StartMargin() const {
- return ui::MaterialDesignController::IsModeMaterial() ?
- model_->start_margin() : 0;
-}
-
-int OmniboxResultView::EndMargin() const {
- return ui::MaterialDesignController::IsModeMaterial() ?
- model_->end_margin() : 0;
-}
« 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