| OLD | NEW |
| 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 Loading... |
| 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 |
| OLD | NEW |