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" |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 case kColorId_TableGroupingIndicatorColor: | 245 case kColorId_TableGroupingIndicatorColor: |
246 return SkColorSetRGB(140, 140, 140); | 246 return SkColorSetRGB(140, 140, 140); |
247 | 247 |
248 default: | 248 default: |
249 // TODO(tapted): Handle all values and remove the default case. | 249 // TODO(tapted): Handle all values and remove the default case. |
250 return GetAuraColor(color_id, this); | 250 return GetAuraColor(color_id, this); |
251 } | 251 } |
252 } | 252 } |
253 | 253 |
254 void NativeThemeMac::PaintMenuPopupBackground( | 254 void NativeThemeMac::PaintMenuPopupBackground( |
255 SkCanvas* canvas, | 255 cc::PaintCanvas* canvas, |
256 const gfx::Size& size, | 256 const gfx::Size& size, |
257 const MenuBackgroundExtraParams& menu_background) const { | 257 const MenuBackgroundExtraParams& menu_background) const { |
258 SkPaint paint; | 258 cc::PaintFlags paint; |
259 paint.setAntiAlias(true); | 259 paint.setAntiAlias(true); |
260 if (base::mac::IsOS10_9()) | 260 if (base::mac::IsOS10_9()) |
261 paint.setColor(kMenuPopupBackgroundColorMavericks); | 261 paint.setColor(kMenuPopupBackgroundColorMavericks); |
262 else | 262 else |
263 paint.setColor(kMenuPopupBackgroundColor); | 263 paint.setColor(kMenuPopupBackgroundColor); |
264 const SkScalar radius = SkIntToScalar(menu_background.corner_radius); | 264 const SkScalar radius = SkIntToScalar(menu_background.corner_radius); |
265 SkRect rect = gfx::RectToSkRect(gfx::Rect(size)); | 265 SkRect rect = gfx::RectToSkRect(gfx::Rect(size)); |
266 canvas->drawRoundRect(rect, radius, radius, paint); | 266 canvas->drawRoundRect(rect, radius, radius, paint); |
267 } | 267 } |
268 | 268 |
269 void NativeThemeMac::PaintMenuItemBackground( | 269 void NativeThemeMac::PaintMenuItemBackground( |
270 SkCanvas* canvas, | 270 cc::PaintCanvas* canvas, |
271 State state, | 271 State state, |
272 const gfx::Rect& rect, | 272 const gfx::Rect& rect, |
273 const MenuItemExtraParams& menu_item) const { | 273 const MenuItemExtraParams& menu_item) const { |
274 SkPaint paint; | 274 cc::PaintFlags paint; |
275 switch (state) { | 275 switch (state) { |
276 case NativeTheme::kNormal: | 276 case NativeTheme::kNormal: |
277 case NativeTheme::kDisabled: | 277 case NativeTheme::kDisabled: |
278 // Draw nothing over the regular background. | 278 // Draw nothing over the regular background. |
279 break; | 279 break; |
280 case NativeTheme::kHovered: | 280 case NativeTheme::kHovered: |
281 // TODO(tapted): Draw a gradient, and use [NSColor currentControlTint] to | 281 // TODO(tapted): Draw a gradient, and use [NSColor currentControlTint] to |
282 // pick colors. The System color "selectedMenuItemColor" is actually still | 282 // pick colors. The System color "selectedMenuItemColor" is actually still |
283 // blue for Graphite. And while "keyboardFocusIndicatorColor" does change, | 283 // blue for Graphite. And while "keyboardFocusIndicatorColor" does change, |
284 // and is a good shade of gray, it's not blue enough for the Blue theme. | 284 // and is a good shade of gray, it's not blue enough for the Blue theme. |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 | 362 |
363 for (size_t i = 0; i < arraysize(gradient_colors); ++i) | 363 for (size_t i = 0; i < arraysize(gradient_colors); ++i) |
364 gradient_colors[i] = ApplySystemControlTint(gradient_colors[i]); | 364 gradient_colors[i] = ApplySystemControlTint(gradient_colors[i]); |
365 | 365 |
366 return SkGradientShader::MakeLinear( | 366 return SkGradientShader::MakeLinear( |
367 gradient_points, gradient_colors, gradient_positions, | 367 gradient_points, gradient_colors, gradient_positions, |
368 arraysize(gradient_positions), SkShader::kClamp_TileMode); | 368 arraysize(gradient_positions), SkShader::kClamp_TileMode); |
369 } | 369 } |
370 | 370 |
371 // static | 371 // static |
372 void NativeThemeMac::PaintStyledGradientButton(SkCanvas* canvas, | 372 void NativeThemeMac::PaintStyledGradientButton(cc::PaintCanvas* canvas, |
373 const gfx::Rect& integer_bounds, | 373 const gfx::Rect& integer_bounds, |
374 ButtonBackgroundType type, | 374 ButtonBackgroundType type, |
375 bool round_left, | 375 bool round_left, |
376 bool round_right, | 376 bool round_right, |
377 bool focus) { | 377 bool focus) { |
378 const SkScalar kBorderThickness = 1; | 378 const SkScalar kBorderThickness = 1; |
379 const SkScalar kFocusRingThickness = 4; | 379 const SkScalar kFocusRingThickness = 4; |
380 const SkColor kFocusRingColor = ApplySystemControlTint( | 380 const SkColor kFocusRingColor = ApplySystemControlTint( |
381 SkColorSetARGB(0x94, 0x79, 0xa7, 0xe9)); | 381 SkColorSetARGB(0x94, 0x79, 0xa7, 0xe9)); |
382 | 382 |
(...skipping 18 matching lines...) Expand all Loading... |
401 SkRRect shape; | 401 SkRRect shape; |
402 if (round_left && round_right) | 402 if (round_left && round_right) |
403 shape.setRectXY(bounds, kButtonCornerRadius, kButtonCornerRadius); | 403 shape.setRectXY(bounds, kButtonCornerRadius, kButtonCornerRadius); |
404 else if (round_left) | 404 else if (round_left) |
405 shape.setRectRadii(bounds, kLeftCurves); | 405 shape.setRectRadii(bounds, kLeftCurves); |
406 else if (round_right) | 406 else if (round_right) |
407 shape.setRectRadii(bounds, kRightCurves); | 407 shape.setRectRadii(bounds, kRightCurves); |
408 else | 408 else |
409 shape.setRect(bounds); | 409 shape.setRect(bounds); |
410 | 410 |
411 SkPaint paint; | 411 cc::PaintFlags paint; |
412 paint.setStyle(SkPaint::kFill_Style); | 412 paint.setStyle(cc::PaintFlags::kFill_Style); |
413 paint.setAntiAlias(true); | 413 paint.setAntiAlias(true); |
414 | 414 |
415 // First draw the darker "outer" border, with its gradient and shadow. Inside | 415 // First draw the darker "outer" border, with its gradient and shadow. Inside |
416 // a tab strip, this will draw over the outer border and inner separator. | 416 // a tab strip, this will draw over the outer border and inner separator. |
417 paint.setLooper(gfx::CreateShadowDrawLooper(shadows)); | 417 paint.setLooper(gfx::CreateShadowDrawLooper(shadows)); |
418 paint.setShader(GetButtonBorderShader(type, shape.height())); | 418 paint.setShader( |
| 419 cc::WrapSkShader(GetButtonBorderShader(type, shape.height()))); |
419 canvas->drawRRect(shape, paint); | 420 canvas->drawRRect(shape, paint); |
420 | 421 |
421 // Then, inset the rounded rect and draw over that with the inner gradient. | 422 // Then, inset the rounded rect and draw over that with the inner gradient. |
422 shape.inset(kBorderThickness, kBorderThickness); | 423 shape.inset(kBorderThickness, kBorderThickness); |
423 paint.setLooper(nullptr); | 424 paint.setLooper(nullptr); |
424 paint.setShader(GetButtonBackgroundShader(type, shape.height())); | 425 paint.setShader( |
| 426 cc::WrapSkShader(GetButtonBackgroundShader(type, shape.height()))); |
425 canvas->drawRRect(shape, paint); | 427 canvas->drawRRect(shape, paint); |
426 | 428 |
427 if (!focus) | 429 if (!focus) |
428 return; | 430 return; |
429 | 431 |
430 SkRRect outer_shape; | 432 SkRRect outer_shape; |
431 shape.outset(kFocusRingThickness, kFocusRingThickness, &outer_shape); | 433 shape.outset(kFocusRingThickness, kFocusRingThickness, &outer_shape); |
432 paint.setShader(nullptr); | 434 paint.setShader(nullptr); |
433 paint.setColor(kFocusRingColor); | 435 paint.setColor(kFocusRingColor); |
434 canvas->drawDRRect(outer_shape, shape, paint); | 436 canvas->drawDRRect(outer_shape, shape, paint); |
435 } | 437 } |
436 | 438 |
437 NativeThemeMac::NativeThemeMac() { | 439 NativeThemeMac::NativeThemeMac() { |
438 } | 440 } |
439 | 441 |
440 NativeThemeMac::~NativeThemeMac() { | 442 NativeThemeMac::~NativeThemeMac() { |
441 } | 443 } |
442 | 444 |
443 } // namespace ui | 445 } // namespace ui |
OLD | NEW |