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

Unified Diff: chrome/browser/ui/views/location_bar/location_bar_view.cc

Issue 1394763003: Update LocationBarView Background (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Subtractive Path Painting Created 5 years, 2 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/views/location_bar/location_bar_view.cc
diff --git a/chrome/browser/ui/views/location_bar/location_bar_view.cc b/chrome/browser/ui/views/location_bar/location_bar_view.cc
index c39d2fca8b57c5ccc74d5a93ffc65eb87a2dfdf6..b2bc2fae7eb4675d0390c6dadcbaccac0fc2cbd9 100644
--- a/chrome/browser/ui/views/location_bar/location_bar_view.cc
+++ b/chrome/browser/ui/views/location_bar/location_bar_view.cc
@@ -70,6 +70,8 @@
#include "extensions/common/feature_switch.h"
#include "grit/components_scaled_resources.h"
#include "grit/theme_resources.h"
+#include "third_party/skia/include/core/SkPath.h"
+#include "third_party/skia/include/pathops/SkPathOps.h"
#include "ui/accessibility/ax_view_state.h"
#include "ui/base/dragdrop/drag_drop_types.h"
#include "ui/base/l10n/l10n_util.h"
@@ -103,6 +105,82 @@ using views::View;
namespace {
+// Removes the current image scaling on |canvas|, returning the scale value.
+// Also adjusts |rect| based on the scaling. Call canvas->Restore() to return
+// to default scaling.
+float SetupScaledPainting(gfx::Canvas* canvas, gfx::RectF* rect) {
+ const float display_scale = canvas->image_scale();
+ canvas->Save();
+ SkScalar scale_factor = 1.0f / display_scale;
+ canvas->sk_canvas()->scale(scale_factor, scale_factor);
+
+ const float kOffset = 0.5f;
+ rect->Scale(display_scale);
+ gfx::InsetsF insets(kOffset, kOffset, kOffset, kOffset);
+ rect->Inset(insets);
Evan Stade 2015/10/09 20:00:24 you can just do rect->Inset(kOffset, kOffset)
jonross 2015/10/19 20:29:02 Done.
+
+ return display_scale;
+}
+
+// Draws a filled rect in the native coordinates of the display. Where |bounds|
+// is in the coordinate space of LocationBarView. The actual rect drawn will be
+// reduced by the region of |bounds| required to render a one pixel thick
+// border.
+void DrawScaledBackgroundRect(gfx::Canvas* canvas,
+ SkColor color,
+ gfx::Rect bounds) {
+ gfx::RectF border_rect_f(bounds);
+ const float display_scale = SetupScaledPainting(canvas, &border_rect_f);
+ const SkScalar kCornerRadius = SkDoubleToScalar(2.5f * display_scale);
+
+ SkPath path;
+ path.addRoundRect(gfx::RectFToSkRect(border_rect_f), kCornerRadius,
+ kCornerRadius);
+
+ SkPaint stroke_paint;
+ stroke_paint.setStyle(SkPaint::Style::kStroke_Style);
+ stroke_paint.setStrokeWidth(1);
+
+ SkPath stroke_path;
+ stroke_paint.getFillPath(path, &stroke_path);
+
+ SkPath fill_path;
+ Op(path, stroke_path, kDifference_SkPathOp, &fill_path);
+
+ SkPaint paint;
+ paint.setStyle(SkPaint::kFill_Style);
+ paint.setColor(color);
+ paint.setAntiAlias(true);
+
+ canvas->sk_canvas()->drawPath(fill_path, paint);
+ canvas->Restore();
+}
+
+// Draws a one pixel thick border in the native coordinates of the display.
+// Where |bounds| is in the coordinate space of LocationBarView. If |round| the
+// drawn rect will have rounded corners.
+void DrawScaledBorderRect(gfx::Canvas* canvas,
+ SkColor color,
+ gfx::Rect bounds,
+ bool round) {
+ gfx::RectF border_rect_f(bounds);
+ const float display_scale = SetupScaledPainting(canvas, &border_rect_f);
+
+ SkPaint paint;
+ paint.setStyle(SkPaint::Style::kStroke_Style);
+ paint.setColor(color);
+ paint.setAntiAlias(true);
+
+ const SkScalar kCornerRadius = SkDoubleToScalar(2.5f * display_scale);
+ if (round) {
+ canvas->sk_canvas()->drawRoundRect(gfx::RectFToSkRect(border_rect_f),
+ kCornerRadius, kCornerRadius, paint);
+ } else {
+ canvas->sk_canvas()->drawRect(gfx::RectFToSkRect(border_rect_f), paint);
+ }
+ canvas->Restore();
+}
+
int GetEditLeadingInternalSpace() {
// The textfield has 1 px of whitespace before the text in the RTL case only.
return base::i18n::IsRTL() ? 1 : 0;
@@ -1259,6 +1337,8 @@ void LocationBarView::OnPaint(gfx::Canvas* canvas) {
SkColor color(GetColor(SecurityStateModel::NONE, BACKGROUND));
if (is_popup_mode_) {
canvas->FillRect(bounds, color);
+ } else if (ui::MaterialDesignController::IsModeMaterial()) {
+ DrawScaledBackgroundRect(canvas, color, bounds);
} else {
SkPaint paint;
paint.setStyle(SkPaint::kFill_Style);
@@ -1290,28 +1370,9 @@ void LocationBarView::PaintChildren(const ui::PaintContext& context) {
border_rect.Inset(-kPopupEdgeThickness, 0);
if (ui::MaterialDesignController::IsModeMaterial()) {
- gfx::Canvas* canvas = recorder.canvas();
- const float display_scale = canvas->image_scale();
- canvas->Save();
- SkScalar scale_factor = 1.0f / display_scale;
- canvas->sk_canvas()->scale(scale_factor, scale_factor);
-
- SkPaint paint;
- paint.setStyle(SkPaint::Style::kStroke_Style);
- paint.setColor(SkColorSetARGB(0x40, 0x00, 0x00, 0x00));
- paint.setStrokeWidth(1);
- paint.setAntiAlias(true);
-
- const float kOffset = 0.5f;
- gfx::RectF border_rect_f(border_rect);
- border_rect_f.Scale(display_scale);
- gfx::InsetsF insets(kOffset, kOffset, kOffset, kOffset);
- border_rect_f.Inset(insets);
-
- const SkScalar kCornerRadius = SkDoubleToScalar(2.5f * display_scale);
- canvas->sk_canvas()->drawRoundRect(gfx::RectFToSkRect(border_rect_f),
- kCornerRadius, kCornerRadius, paint);
- recorder.canvas()->Restore();
+ DrawScaledBorderRect(recorder.canvas(),
+ SkColorSetARGB(0x4D, 0x00, 0x00, 0x00), border_rect,
+ !is_popup_mode_);
Peter Kasting 2015/10/12 23:45:44 In the MD world, I don't think we actually need to
jonross 2015/10/19 20:29:02 Done.
} else {
views::Painter::PaintPainterAt(recorder.canvas(), border_painter_.get(),
border_rect);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698