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

Side by Side 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: 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/native_theme/native_theme_mac.h" 5 #include "ui/native_theme/native_theme_mac.h"
6 6
7 #import <Cocoa/Cocoa.h> 7 #import <Cocoa/Cocoa.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include "base/mac/mac_util.h" 10 #include "base/mac/mac_util.h"
11 #include "base/mac/scoped_cftyperef.h" 11 #include "base/mac/scoped_cftyperef.h"
12 #include "base/mac/sdk_forward_declarations.h" 12 #include "base/mac/sdk_forward_declarations.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #import "skia/ext/skia_utils_mac.h" 14 #import "skia/ext/skia_utils_mac.h"
15 #include "third_party/skia/include/core/SkRRect.h"
15 #include "third_party/skia/include/effects/SkGradientShader.h" 16 #include "third_party/skia/include/effects/SkGradientShader.h"
16 #include "ui/gfx/geometry/rect.h" 17 #include "ui/gfx/geometry/rect.h"
17 #include "ui/gfx/skia_util.h" 18 #include "ui/gfx/skia_util.h"
18 #include "ui/native_theme/common_theme.h" 19 #include "ui/native_theme/common_theme.h"
19 20
20 namespace { 21 namespace {
21 22
22 // Values calculated by reading pixels and solving simultaneous equations 23 // Values calculated by reading pixels and solving simultaneous equations
23 // derived from "A over B" alpha compositing. Steps: Sample the semi-transparent 24 // derived from "A over B" alpha compositing. Steps: Sample the semi-transparent
24 // pixel over two backgrounds; P1, P2 over backgrounds B1, B2. Use the color 25 // pixel over two backgrounds; P1, P2 over backgrounds B1, B2. Use the color
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 // and is a good shade of gray, it's not blue enough for the Blue theme. 260 // and is a good shade of gray, it's not blue enough for the Blue theme.
260 paint.setColor(GetSystemColor(kColorId_HoverMenuItemBackgroundColor)); 261 paint.setColor(GetSystemColor(kColorId_HoverMenuItemBackgroundColor));
261 canvas->drawRect(gfx::RectToSkRect(rect), paint); 262 canvas->drawRect(gfx::RectToSkRect(rect), paint);
262 break; 263 break;
263 default: 264 default:
264 NOTREACHED(); 265 NOTREACHED();
265 break; 266 break;
266 } 267 }
267 } 268 }
268 269
270 skia::RefPtr<SkShader>
271 GetComboboxArrowBackgroundShader(NativeTheme::State state, int height) {
272 SkPoint gradient_points[2];
273 gradient_points[0].iset(0, 0);
274 gradient_points[1].iset(0, height);
275
276 // TODO(ellyjones): These colors are not exactly right, and the gradient
277 // probably needs more stops.
278 SkScalar gradient_positions[] = { 0.0, 0.38, 1.0 };
279
280 SkColor light_blue = SkColorSetRGB(0x4e, 0x97, 0xfd);
tapted 2016/03/21 07:09:04 Are there things we can pick from ui/gfx/color_pal
Elly Fong-Jones 2016/03/21 18:53:56 Done. kGoogleBlue300 and kGoogleBlue700 turn out t
281 SkColor dark_blue = SkColorSetRGB(0x3f, 0x68, 0xe5);
282
283 // TODO(ellyjones): Does this need to handle states other than kHovered and
284 // kNormal?
tapted 2016/03/21 07:09:04 kDisabled. There's also "invalid"
Elly Fong-Jones 2016/03/21 18:53:56 Done.
285 SkColor hovered_colors[] = { light_blue, light_blue, dark_blue };
286 SkColor normal_colors[] = { SK_ColorWHITE, SK_ColorWHITE, SK_ColorWHITE };
287 SkColor* gradient_colors = state == NativeTheme::kHovered ?
288 hovered_colors :
289 normal_colors;
290
291 skia::RefPtr<SkShader> gradient_shader = skia::AdoptRef(
292 SkGradientShader::CreateLinear(
293 gradient_points, gradient_colors, gradient_positions, 3,
294 SkShader::kClamp_TileMode));
295 return gradient_shader;
296 }
297
298 void NativeThemeMac::PaintComboboxArrowBackground(SkCanvas* canvas,
299 State state,
300 const gfx::Rect& rect) const {
301 // TODO(ellyjones): This constant is duplicated in FocusableRoundedBorder at
302 // the moment. Maybe this function should take this as a parameter instead.
303 const int kComboboxBorderRadius = 5;
304
305 skia::RefPtr<SkShader> shader =
306 GetComboboxArrowBackgroundShader(state, rect.height());
307
308 SkPaint paint;
309 paint.setShader(shader.get());
310 paint.setStyle(SkPaint::kFill_Style);
311 paint.setAntiAlias(true);
312
313 SkPoint no_curve = SkPoint::Make(0, 0);
314 SkPoint curve = SkPoint::Make(kComboboxBorderRadius, kComboboxBorderRadius);
315 // Curve upper-right and lower-right corners of the background only.
316 SkVector curves[4] = { no_curve, curve, curve, no_curve };
317
318 SkRRect fill_rect;
319 fill_rect.setRectRadii(gfx::RectToSkRect(rect), curves);
320
321 canvas->drawRRect(fill_rect, paint);
322 }
323
269 NativeThemeMac::NativeThemeMac() { 324 NativeThemeMac::NativeThemeMac() {
270 } 325 }
271 326
272 NativeThemeMac::~NativeThemeMac() { 327 NativeThemeMac::~NativeThemeMac() {
273 } 328 }
274 329
275 } // namespace ui 330 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698