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

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

Issue 1394763003: Update LocationBarView Background (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
Index: chrome/browser/ui/views/location_bar/background_with_1_px_border.cc
diff --git a/chrome/browser/ui/views/location_bar/background_with_1_px_border.cc b/chrome/browser/ui/views/location_bar/background_with_1_px_border.cc
new file mode 100644
index 0000000000000000000000000000000000000000..35e7f42877f5364b84f9702d8e91ada574701179
--- /dev/null
+++ b/chrome/browser/ui/views/location_bar/background_with_1_px_border.cc
@@ -0,0 +1,62 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/ui/views/location_bar/background_with_1_px_border.h"
+
+#include "third_party/skia/include/core/SkPaint.h"
+#include "third_party/skia/include/core/SkPath.h"
+#include "third_party/skia/include/pathops/SkPathOps.h"
+#include "ui/gfx/canvas.h"
+#include "ui/views/view.h"
+#include "ui/views/widget/widget.h"
+
+BackgroundWith1PxBorder::BackgroundWith1PxBorder(SkColor background,
+ SkColor border,
+ bool round_corners)
+ : border_color_(border), round_corners_(round_corners) {
+ SetNativeControlColor(background);
+}
+
+void BackgroundWith1PxBorder::Paint(gfx::Canvas* canvas,
+ views::View* view) const {
+ const float scale = canvas->SaveAndUnscale();
Peter Kasting 2015/10/30 21:07:14 Note: You'll need to update this to compile agains
jonross 2015/11/02 16:36:23 Done.
+ const float kPreScaleOffset = 1.0f;
Peter Kasting 2015/10/30 21:07:14 Nit: Since you added LOCATION_BAR_EDGE_THICKNESS,
jonross 2015/11/02 16:36:23 Done.
+ const float kPostScaleOffset = -0.5f;
+ gfx::RectF border_rect_f(view->GetContentsBounds());
+ SkPath path;
+ if (round_corners_) {
+ border_rect_f.Inset(kPreScaleOffset, kPreScaleOffset);
+ border_rect_f.Scale(scale);
+ border_rect_f.Inset(kPostScaleOffset, kPostScaleOffset);
+ const SkScalar kCornerRadius = SkDoubleToScalar(2.5f * scale);
+ path.addRoundRect(gfx::RectFToSkRect(border_rect_f), kCornerRadius,
+ kCornerRadius);
+ } else {
+ if (view->GetWidget()->IsMaximized())
Peter Kasting 2015/10/30 21:07:14 Please add comments describing why we're doing thi
jonross 2015/11/02 16:36:22 Switched over the naming to make it more consisten
+ border_rect_f.Inset(0.0f, kPreScaleOffset);
+ else
+ border_rect_f.Inset(kPreScaleOffset, kPreScaleOffset);
Peter Kasting 2015/10/30 21:07:14 Nit: Simpler: border_rect_f.Inset(view->GetWidg
jonross 2015/11/02 16:36:23 Done.
+ border_rect_f.Scale(scale);
+ border_rect_f.Inset(kPostScaleOffset, kPostScaleOffset);
+ path.addRect(gfx::RectFToSkRect(border_rect_f));
+ }
+
+ SkPaint paint;
+ paint.setStyle(SkPaint::kStroke_Style);
+ paint.setStrokeWidth(1);
+ paint.setAntiAlias(true);
+
+ SkPath stroke_path;
+ paint.getFillPath(path, &stroke_path);
+
+ SkPath fill_path;
+ Op(path, stroke_path, kDifference_SkPathOp, &fill_path);
+ paint.setStyle(SkPaint::kFill_Style);
+ paint.setColor(get_color());
+ canvas->sk_canvas()->drawPath(fill_path, paint);
+
+ paint.setColor(border_color_);
+ canvas->sk_canvas()->drawPath(stroke_path, paint);
+ canvas->Restore();
+}

Powered by Google App Engine
This is Rietveld 408576698