Chromium Code Reviews| 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/core/SkRRect.h" | |
| 15 #include "third_party/skia/include/effects/SkGradientShader.h" | 16 #include "third_party/skia/include/effects/SkGradientShader.h" |
| 17 #include "ui/gfx/color_palette.h" | |
| 16 #include "ui/gfx/geometry/rect.h" | 18 #include "ui/gfx/geometry/rect.h" |
| 17 #include "ui/gfx/skia_util.h" | 19 #include "ui/gfx/skia_util.h" |
| 18 #include "ui/native_theme/common_theme.h" | 20 #include "ui/native_theme/common_theme.h" |
| 19 | 21 |
| 20 namespace { | 22 namespace { |
| 21 | 23 |
| 22 // Values calculated by reading pixels and solving simultaneous equations | 24 // Values calculated by reading pixels and solving simultaneous equations |
| 23 // derived from "A over B" alpha compositing. Steps: Sample the semi-transparent | 25 // 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 | 26 // 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, | 27 // 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. | 261 // and is a good shade of gray, it's not blue enough for the Blue theme. |
| 260 paint.setColor(GetSystemColor(kColorId_HoverMenuItemBackgroundColor)); | 262 paint.setColor(GetSystemColor(kColorId_HoverMenuItemBackgroundColor)); |
| 261 canvas->drawRect(gfx::RectToSkRect(rect), paint); | 263 canvas->drawRect(gfx::RectToSkRect(rect), paint); |
| 262 break; | 264 break; |
| 263 default: | 265 default: |
| 264 NOTREACHED(); | 266 NOTREACHED(); |
| 265 break; | 267 break; |
| 266 } | 268 } |
| 267 } | 269 } |
| 268 | 270 |
| 271 skia::RefPtr<SkShader> NativeThemeMac::GetButtonBackgroundShader( | |
| 272 NativeTheme::State state, int height) const { | |
| 273 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.
| |
| 274 SkPoint gradient_points[2]; | |
| 275 gradient_points[0].iset(0, 0); | |
| 276 gradient_points[1].iset(0, height); | |
| 277 | |
| 278 // TODO(ellyjones): These colors are not exactly right, and the gradient | |
| 279 // probably needs more stops. | |
| 280 SkScalar gradient_positions[] = { 0.0, 0.38, 1.0 }; | |
| 281 | |
| 282 // TODO(ellyjones): Does this need to handle states other than kHovered and | |
| 283 // 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
| |
| 284 ColorByState start_colors = { gfx::kMaterialGrey300, | |
| 285 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.
| |
| 286 SK_ColorWHITE, | |
| 287 gfx::kMaterialBlue300 | |
| 288 }; | |
| 289 ColorByState end_colors = { gfx::kMaterialGrey300, | |
| 290 gfx::kMaterialBlue700, | |
| 291 SK_ColorWHITE, | |
| 292 gfx::kMaterialBlue700 | |
| 293 }; | |
| 294 | |
| 295 SkColor gradient_colors[] = { | |
| 296 start_colors[state], start_colors[state], end_colors[state] | |
| 297 }; | |
| 298 | |
| 299 skia::RefPtr<SkShader> gradient_shader = skia::AdoptRef( | |
| 300 SkGradientShader::CreateLinear( | |
| 301 gradient_points, gradient_colors, gradient_positions, 3, | |
| 302 SkShader::kClamp_TileMode)); | |
| 303 return gradient_shader; | |
| 304 } | |
| 305 | |
| 306 void NativeThemeMac::PaintComboboxArrowBackground(SkCanvas* canvas, | |
| 307 State state, | |
| 308 const gfx::Rect& rect) const { | |
| 309 // TODO(ellyjones): This constant is duplicated in FocusableRoundedBorder at | |
| 310 // the moment. Maybe this function should take this as a parameter instead. | |
| 311 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.
| |
| 312 | |
| 313 // The combobox arrow is a logical button, so it has a button background | |
| 314 // gradient. | |
| 315 skia::RefPtr<SkShader> shader = | |
| 316 GetButtonBackgroundShader(state, rect.height()); | |
| 317 | |
| 318 SkPaint paint; | |
| 319 paint.setShader(shader.get()); | |
| 320 paint.setStyle(SkPaint::kFill_Style); | |
| 321 paint.setAntiAlias(true); | |
| 322 | |
| 323 SkPoint no_curve = SkPoint::Make(0, 0); | |
| 324 SkPoint curve = SkPoint::Make(kComboboxBorderRadius, kComboboxBorderRadius); | |
| 325 // Curve upper-right and lower-right corners of the background only. | |
| 326 SkVector curves[4] = { no_curve, curve, curve, no_curve }; | |
| 327 | |
| 328 SkRRect fill_rect; | |
| 329 fill_rect.setRectRadii(gfx::RectToSkRect(rect), curves); | |
| 330 | |
| 331 canvas->drawRRect(fill_rect, paint); | |
| 332 } | |
| 333 | |
| 269 NativeThemeMac::NativeThemeMac() { | 334 NativeThemeMac::NativeThemeMac() { |
| 270 } | 335 } |
| 271 | 336 |
| 272 NativeThemeMac::~NativeThemeMac() { | 337 NativeThemeMac::~NativeThemeMac() { |
| 273 } | 338 } |
| 274 | 339 |
| 275 } // namespace ui | 340 } // namespace ui |
| OLD | NEW |