| 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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 // CGColorRefToSkColor will not like. But RGB is additive, so the conversion | 115 // CGColorRefToSkColor will not like. But RGB is additive, so the conversion |
| 116 // is easy (RGB to grayscale is less easy). | 116 // is easy (RGB to grayscale is less easy). |
| 117 const CGFloat* components = CGColorGetComponents(cg_color); | 117 const CGFloat* components = CGColorGetComponents(cg_color); |
| 118 CGFloat alpha = component_count == 2 ? components[1] : 1.0; | 118 CGFloat alpha = component_count == 2 ? components[1] : 1.0; |
| 119 return SkColorSetARGB(SkScalarRoundToInt(255.0 * alpha), | 119 return SkColorSetARGB(SkScalarRoundToInt(255.0 * alpha), |
| 120 SkScalarRoundToInt(255.0 * components[0]), | 120 SkScalarRoundToInt(255.0 * components[0]), |
| 121 SkScalarRoundToInt(255.0 * components[0]), | 121 SkScalarRoundToInt(255.0 * components[0]), |
| 122 SkScalarRoundToInt(255.0 * components[0])); | 122 SkScalarRoundToInt(255.0 * components[0])); |
| 123 } | 123 } |
| 124 | 124 |
| 125 SkColor GetColorFromOverlayParams( |
| 126 SkColor color, |
| 127 ui::NativeTheme::OverlayParams overlay_params) { |
| 128 return overlay_params.is_overlay |
| 129 ? SkColorSetA(color, SkColorGetA(color) * overlay_params.alpha) |
| 130 : color; |
| 131 } |
| 132 |
| 125 } // namespace | 133 } // namespace |
| 126 | 134 |
| 127 namespace ui { | 135 namespace ui { |
| 128 | 136 |
| 129 // static | 137 // static |
| 130 NativeTheme* NativeTheme::GetInstanceForWeb() { | 138 NativeTheme* NativeTheme::GetInstanceForWeb() { |
| 131 return NativeThemeMac::instance(); | 139 return NativeThemeMac::instance(); |
| 132 } | 140 } |
| 133 | 141 |
| 134 // static | 142 // static |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 // Emulate the non-overlay scroller style from OSX 10.7 and later. | 257 // Emulate the non-overlay scroller style from OSX 10.7 and later. |
| 250 SkPoint gradient_bounds[2]; | 258 SkPoint gradient_bounds[2]; |
| 251 if (part == kScrollbarVerticalTrack) { | 259 if (part == kScrollbarVerticalTrack) { |
| 252 gradient_bounds[0].set(rect.x(), rect.y()); | 260 gradient_bounds[0].set(rect.x(), rect.y()); |
| 253 gradient_bounds[1].set(rect.right(), rect.y()); | 261 gradient_bounds[1].set(rect.right(), rect.y()); |
| 254 } else { | 262 } else { |
| 255 DCHECK_EQ(part, kScrollbarHorizontalTrack); | 263 DCHECK_EQ(part, kScrollbarHorizontalTrack); |
| 256 gradient_bounds[0].set(rect.x(), rect.y()); | 264 gradient_bounds[0].set(rect.x(), rect.y()); |
| 257 gradient_bounds[1].set(rect.x(), rect.bottom()); | 265 gradient_bounds[1].set(rect.x(), rect.bottom()); |
| 258 } | 266 } |
| 267 |
| 268 // TODO(spqchan): Change the opacity of the track when it's overlayed. |
| 259 skia::RefPtr<SkShader> shader = skia::AdoptRef( | 269 skia::RefPtr<SkShader> shader = skia::AdoptRef( |
| 260 SkGradientShader::CreateLinear(gradient_bounds, | 270 SkGradientShader::CreateLinear(gradient_bounds, |
| 261 kScrollerTrackGradientColors, | 271 kScrollerTrackGradientColors, |
| 262 NULL, | 272 NULL, |
| 263 arraysize(kScrollerTrackGradientColors), | 273 arraysize(kScrollerTrackGradientColors), |
| 264 SkShader::kClamp_TileMode)); | 274 SkShader::kClamp_TileMode)); |
| 265 SkPaint gradient; | 275 SkPaint gradient; |
| 266 gradient.setShader(shader.get()); | 276 gradient.setShader(shader.get()); |
| 267 | 277 |
| 268 SkIRect track_rect = gfx::RectToSkIRect(rect); | 278 SkIRect track_rect = gfx::RectToSkIRect(rect); |
| 269 canvas->drawIRect(track_rect, gradient); | 279 canvas->drawIRect(track_rect, gradient); |
| 270 | 280 |
| 271 // Draw inner and outer line borders. | 281 // Draw inner and outer line borders. |
| 272 if (part == kScrollbarVerticalTrack) { | 282 if (part == kScrollbarVerticalTrack) { |
| 273 SkPaint paint; | 283 SkPaint paint; |
| 274 paint.setColor(kScrollerTrackInnerBorderColor); | 284 paint.setColor(GetColorFromOverlayParams(kScrollerTrackInnerBorderColor, |
| 285 extra_params.overlay)); |
| 275 canvas->drawRectCoords(track_rect.left(), | 286 canvas->drawRectCoords(track_rect.left(), |
| 276 track_rect.top(), | 287 track_rect.top(), |
| 277 track_rect.left() + kScrollerTrackBorderWidth, | 288 track_rect.left() + kScrollerTrackBorderWidth, |
| 278 track_rect.bottom(), | 289 track_rect.bottom(), |
| 279 paint); | 290 paint); |
| 280 paint.setColor(kScrollerTrackOuterBorderColor); | 291 paint.setColor(GetColorFromOverlayParams(kScrollerTrackOuterBorderColor, |
| 292 extra_params.overlay)); |
| 281 canvas->drawRectCoords(track_rect.right() - kScrollerTrackBorderWidth, | 293 canvas->drawRectCoords(track_rect.right() - kScrollerTrackBorderWidth, |
| 282 track_rect.top(), | 294 track_rect.top(), |
| 283 track_rect.right(), | 295 track_rect.right(), |
| 284 track_rect.bottom(), | 296 track_rect.bottom(), |
| 285 paint); | 297 paint); |
| 286 } else { | 298 } else { |
| 287 SkPaint paint; | 299 SkPaint paint; |
| 288 paint.setColor(kScrollerTrackInnerBorderColor); | 300 paint.setColor(GetColorFromOverlayParams(kScrollerTrackInnerBorderColor, |
| 301 extra_params.overlay)); |
| 289 canvas->drawRectCoords(track_rect.left(), | 302 canvas->drawRectCoords(track_rect.left(), |
| 290 track_rect.top(), | 303 track_rect.top(), |
| 291 track_rect.right(), | 304 track_rect.right(), |
| 292 track_rect.top() + kScrollerTrackBorderWidth, | 305 track_rect.top() + kScrollerTrackBorderWidth, |
| 293 paint); | 306 paint); |
| 294 paint.setColor(kScrollerTrackOuterBorderColor); | 307 paint.setColor(GetColorFromOverlayParams(kScrollerTrackOuterBorderColor, |
| 308 extra_params.overlay)); |
| 295 canvas->drawRectCoords(track_rect.left(), | 309 canvas->drawRectCoords(track_rect.left(), |
| 296 track_rect.bottom() - kScrollerTrackBorderWidth, | 310 track_rect.bottom() - kScrollerTrackBorderWidth, |
| 297 track_rect.right(), | 311 track_rect.right(), |
| 298 track_rect.bottom(), | 312 track_rect.bottom(), |
| 299 paint); | 313 paint); |
| 300 } | 314 } |
| 301 } | 315 } |
| 302 | 316 |
| 303 void NativeThemeMac::PaintScrollbarThumb(SkCanvas* canvas, | 317 void NativeThemeMac::PaintScrollbarThumb( |
| 304 Part part, | 318 SkCanvas* canvas, |
| 305 State state, | 319 Part part, |
| 306 const gfx::Rect& rect) const { | 320 State state, |
| 321 const ScrollbarThumbExtraParams& extra_params, |
| 322 const gfx::Rect& rect) const { |
| 307 gfx::Rect thumb_rect(rect); | 323 gfx::Rect thumb_rect(rect); |
| 308 switch (part) { | 324 switch (part) { |
| 309 case kScrollbarHorizontalThumb: | 325 case kScrollbarHorizontalThumb: |
| 310 thumb_rect.Inset(0, kScrollerTrackBorderWidth, 0, 0); | 326 thumb_rect.Inset(0, kScrollerTrackBorderWidth, 0, 0); |
| 311 break; | 327 break; |
| 312 case kScrollbarVerticalThumb: | 328 case kScrollbarVerticalThumb: |
| 313 thumb_rect.Inset(kScrollerTrackBorderWidth, 0, 0, 0); | 329 thumb_rect.Inset(kScrollerTrackBorderWidth, 0, 0, 0); |
| 314 break; | 330 break; |
| 315 default: | 331 default: |
| 316 NOTREACHED(); | 332 NOTREACHED(); |
| 317 break; | 333 break; |
| 318 } | 334 } |
| 319 | 335 |
| 320 thumb_rect.Inset(kScrollerThumbInset, kScrollerThumbInset); | 336 thumb_rect.Inset(kScrollerThumbInset, kScrollerThumbInset); |
| 321 | 337 |
| 322 SkPaint paint; | 338 SkPaint paint; |
| 323 paint.setAntiAlias(true); | 339 paint.setAntiAlias(true); |
| 324 paint.setColor(state == kHovered ? thumb_active_color_ | 340 |
| 325 : thumb_inactive_color_); | 341 SkColor thumb_color = |
| 342 state == kHovered ? thumb_active_color_ : thumb_inactive_color_; |
| 343 paint.setColor(GetColorFromOverlayParams(thumb_color, extra_params.overlay)); |
| 344 |
| 326 const SkScalar radius = std::min(rect.width(), rect.height()); | 345 const SkScalar radius = std::min(rect.width(), rect.height()); |
| 327 canvas->drawRoundRect(gfx::RectToSkRect(thumb_rect), radius, radius, paint); | 346 canvas->drawRoundRect(gfx::RectToSkRect(thumb_rect), radius, radius, paint); |
| 328 } | 347 } |
| 329 | 348 |
| 330 void NativeThemeMac::PaintScrollbarCorner(SkCanvas* canvas, | 349 void NativeThemeMac::PaintScrollbarCorner(SkCanvas* canvas, |
| 331 State state, | 350 State state, |
| 332 const gfx::Rect& rect) const { | 351 const gfx::Rect& rect) const { |
| 333 DCHECK_GT(rect.width(), 0); | 352 DCHECK_GT(rect.width(), 0); |
| 334 DCHECK_GT(rect.height(), 0); | 353 DCHECK_GT(rect.height(), 0); |
| 335 | 354 |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 409 set_scrollbar_button_length(0); | 428 set_scrollbar_button_length(0); |
| 410 SetScrollbarColors(kScrollerThumbColor, | 429 SetScrollbarColors(kScrollerThumbColor, |
| 411 kScrollerThumbHoverColor, | 430 kScrollerThumbHoverColor, |
| 412 kScrollerTrackGradientColors[0]); | 431 kScrollerTrackGradientColors[0]); |
| 413 } | 432 } |
| 414 | 433 |
| 415 NativeThemeMac::~NativeThemeMac() { | 434 NativeThemeMac::~NativeThemeMac() { |
| 416 } | 435 } |
| 417 | 436 |
| 418 } // namespace ui | 437 } // namespace ui |
| OLD | NEW |