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

Unified Diff: ui/native_theme/native_theme_mac.mm

Issue 1819443002: MacViews: draw combobox arrow backgrounds (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixes! Created 4 years, 9 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: ui/native_theme/native_theme_mac.mm
diff --git a/ui/native_theme/native_theme_mac.mm b/ui/native_theme/native_theme_mac.mm
index f9627ff3cb75d417b719cf57873b6a7a6b481501..fc06074089c0aa71cba6bf186e3b02e43b9886d3 100644
--- a/ui/native_theme/native_theme_mac.mm
+++ b/ui/native_theme/native_theme_mac.mm
@@ -12,7 +12,9 @@
#include "base/mac/sdk_forward_declarations.h"
#include "base/macros.h"
#import "skia/ext/skia_utils_mac.h"
+#include "third_party/skia/include/core/SkRRect.h"
#include "third_party/skia/include/effects/SkGradientShader.h"
+#include "ui/gfx/color_palette.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/skia_util.h"
#include "ui/native_theme/common_theme.h"
@@ -266,6 +268,69 @@ void NativeThemeMac::PaintMenuItemBackground(
}
}
+skia::RefPtr<SkShader> NativeThemeMac::GetButtonBackgroundShader(
+ NativeTheme::State state, int height) const {
+ typedef SkColor ColorByState[NativeTheme::State::kNumStates];
tapted 2016/03/22 11:20:26 nit: typedef const? or const below for start/end c
Elly Fong-Jones 2016/03/22 22:05:10 Acknowledged.
+ SkPoint gradient_points[2];
+ gradient_points[0].iset(0, 0);
+ gradient_points[1].iset(0, height);
+
+ // TODO(ellyjones): These colors are not exactly right, and the gradient
+ // probably needs more stops.
+ SkScalar gradient_positions[] = { 0.0, 0.38, 1.0 };
+
+ // TODO(ellyjones): Does this need to handle states other than kHovered and
+ // kNormal?
tapted 2016/03/22 11:20:26 I think this can be removed, or replaced with a co
Elly Fong-Jones 2016/03/22 22:05:10 I can only do this by stripping off the const, sin
+ ColorByState start_colors = { gfx::kMaterialGrey300,
+ gfx::kMaterialBlue300,
tapted 2016/03/22 11:20:26 I'm pretty sure we don't want hover states - this
Elly Fong-Jones 2016/03/22 22:05:10 Done.
+ SK_ColorWHITE,
+ gfx::kMaterialBlue300
+ };
+ ColorByState end_colors = { gfx::kMaterialGrey300,
+ gfx::kMaterialBlue700,
+ SK_ColorWHITE,
+ gfx::kMaterialBlue700
+ };
+
+ SkColor gradient_colors[] = {
+ start_colors[state], start_colors[state], end_colors[state]
+ };
+
+ skia::RefPtr<SkShader> gradient_shader = skia::AdoptRef(
+ SkGradientShader::CreateLinear(
+ gradient_points, gradient_colors, gradient_positions, 3,
+ SkShader::kClamp_TileMode));
+ return gradient_shader;
+}
+
+void NativeThemeMac::PaintComboboxArrowBackground(SkCanvas* canvas,
+ State state,
+ const gfx::Rect& rect) const {
+ // TODO(ellyjones): This constant is duplicated in FocusableRoundedBorder at
+ // the moment. Maybe this function should take this as a parameter instead.
+ const int kComboboxBorderRadius = 5;
tapted 2016/03/22 11:20:26 I think we want a constant in native_theme_mac.h o
Elly Fong-Jones 2016/03/22 22:05:10 Done.
+
+ // The combobox arrow is a logical button, so it has a button background
+ // gradient.
+ skia::RefPtr<SkShader> shader =
+ GetButtonBackgroundShader(state, rect.height());
+
+ SkPaint paint;
+ paint.setShader(shader.get());
+ paint.setStyle(SkPaint::kFill_Style);
+ paint.setAntiAlias(true);
+
+ SkPoint no_curve = SkPoint::Make(0, 0);
+ SkPoint curve = SkPoint::Make(kComboboxBorderRadius, kComboboxBorderRadius);
+ // Curve upper-right and lower-right corners of the background only.
+ SkVector curves[4] = { no_curve, curve, curve, no_curve };
+
+ SkRRect fill_rect;
+ fill_rect.setRectRadii(gfx::RectToSkRect(rect), curves);
+
+ canvas->drawRRect(fill_rect, paint);
+}
+
NativeThemeMac::NativeThemeMac() {
}

Powered by Google App Engine
This is Rietveld 408576698