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

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: fix linux build 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/effects/SkGradientShader.h" 15 #include "third_party/skia/include/effects/SkGradientShader.h"
16 #include "ui/gfx/color_palette.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
25 // value between 0.0 and 1.0 (i.e. divide by 255.0). Then, 26 // value between 0.0 and 1.0 (i.e. divide by 255.0). Then,
(...skipping 233 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 // static
271 skia::RefPtr<SkShader> NativeThemeMac::GetButtonBackgroundShader(
272 NativeTheme::State state, int height) {
273 typedef SkColor ColorByState[NativeTheme::State::kNumStates];
274 SkPoint gradient_points[2];
275 gradient_points[0].iset(0, 0);
276 gradient_points[1].iset(0, height);
277
278 SkScalar gradient_positions[] = { 0.0, 0.38, 1.0 };
279
280 ColorByState start_colors;
281 start_colors[NativeTheme::State::kDisabled] = gfx::kMaterialGrey300;
282 start_colors[NativeTheme::State::kHovered] = gfx::kMaterialBlue300;
283 start_colors[NativeTheme::State::kNormal] = gfx::kMaterialBlue300;
284 start_colors[NativeTheme::State::kPressed] = gfx::kMaterialBlue300;
285 ColorByState end_colors;
286 end_colors[NativeTheme::State::kDisabled] = gfx::kMaterialGrey300;
287 end_colors[NativeTheme::State::kHovered] = gfx::kMaterialBlue700;
288 end_colors[NativeTheme::State::kNormal] = gfx::kMaterialBlue700;
289 end_colors[NativeTheme::State::kPressed] = gfx::kMaterialBlue700;
290
291 SkColor gradient_colors[] = {
292 start_colors[state], start_colors[state], end_colors[state]
293 };
294
295 skia::RefPtr<SkShader> gradient_shader = skia::AdoptRef(
296 SkGradientShader::CreateLinear(
297 gradient_points, gradient_colors, gradient_positions, 3,
298 SkShader::kClamp_TileMode));
299 return gradient_shader;
300 }
301
269 NativeThemeMac::NativeThemeMac() { 302 NativeThemeMac::NativeThemeMac() {
270 } 303 }
271 304
272 NativeThemeMac::~NativeThemeMac() { 305 NativeThemeMac::~NativeThemeMac() {
273 } 306 }
274 307
275 } // namespace ui 308 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698