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 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 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 "ui/native_theme/common_theme.h" | 13 #include "ui/native_theme/common_theme.h" |
| 14 #import "skia/ext/skia_utils_mac.h" | 14 #import "skia/ext/skia_utils_mac.h" |
| 15 #include "ui/gfx/geometry/rect.h" | |
| 15 #include "ui/gfx/skia_util.h" | 16 #include "ui/gfx/skia_util.h" |
| 16 | 17 |
| 17 namespace { | 18 namespace { |
| 18 | 19 |
| 20 const SkColor kScrollerTrackColor = SkColorSetRGB(0xF8, 0xF8, 0xF8); | |
|
tapted
2014/08/11 01:00:58
Can we make this a horizontal 3-stage gradient, to
Andre
2014/08/12 21:42:38
Done.
| |
| 21 const SkColor kScrollerTrackBorderColor = SkColorSetRGB(0xE4, 0xE4, 0xE4); | |
| 22 const SkColor kScrollerThumbColor = SkColorSetRGB(0xC3, 0xC3, 0xC3); | |
|
tapted
2014/08/11 01:00:58
These should have an alpha component, so the track
Andre
2014/08/12 21:42:37
Added alpha component, although the effect is very
| |
| 23 const SkColor kScrollerThumbHoverColor = SkColorSetRGB(0x7E, 0x7E, 0x7E); | |
| 24 const int kScrollerTrackBorderWidth = 1; | |
| 25 const int kScrollerThumbInset = 3; | |
| 26 | |
| 19 // Values calculated by reading pixels and solving simultaneous equations | 27 // Values calculated by reading pixels and solving simultaneous equations |
| 20 // derived from "A over B" alpha compositing. Steps: Sample the semi-transparent | 28 // derived from "A over B" alpha compositing. Steps: Sample the semi-transparent |
| 21 // pixel over two backgrounds; P1, P2 over backgrounds B1, B2. Use the color | 29 // pixel over two backgrounds; P1, P2 over backgrounds B1, B2. Use the color |
| 22 // value between 0.0 and 1.0 (i.e. divide by 255.0). Then, | 30 // value between 0.0 and 1.0 (i.e. divide by 255.0). Then, |
| 23 // alpha = (P2 - P1 + B1 - B2) / (B1 - B2) | 31 // alpha = (P2 - P1 + B1 - B2) / (B1 - B2) |
| 24 // color = (P1 - B1 + alpha * B1) / alpha. | 32 // color = (P1 - B1 + alpha * B1) / alpha. |
| 25 const SkColor kMenuPopupBackgroundColor = SkColorSetARGB(251, 255, 255, 255); | 33 const SkColor kMenuPopupBackgroundColor = SkColorSetARGB(251, 255, 255, 255); |
| 26 const SkColor kMenuSeparatorColor = SkColorSetARGB(243, 228, 228, 228); | 34 const SkColor kMenuSeparatorColor = SkColorSetARGB(243, 228, 228, 228); |
| 27 const SkColor kMenuBorderColor = SkColorSetARGB(60, 0, 0, 0); | 35 const SkColor kMenuBorderColor = SkColorSetARGB(60, 0, 0, 0); |
| 28 | 36 |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 209 // and is a good shade of gray, it's not blue enough for the Blue theme. | 217 // and is a good shade of gray, it's not blue enough for the Blue theme. |
| 210 paint.setColor(GetSystemColor(kColorId_HoverMenuItemBackgroundColor)); | 218 paint.setColor(GetSystemColor(kColorId_HoverMenuItemBackgroundColor)); |
| 211 canvas->drawRect(gfx::RectToSkRect(rect), paint); | 219 canvas->drawRect(gfx::RectToSkRect(rect), paint); |
| 212 break; | 220 break; |
| 213 default: | 221 default: |
| 214 NOTREACHED(); | 222 NOTREACHED(); |
| 215 break; | 223 break; |
| 216 } | 224 } |
| 217 } | 225 } |
| 218 | 226 |
| 227 void NativeThemeMac::PaintScrollbarTrack( | |
|
tapted
2014/08/11 01:00:58
(nit: move up in the .mm file too)
Andre
2014/08/12 21:42:37
Done.
| |
| 228 SkCanvas* canvas, | |
| 229 Part part, | |
| 230 State state, | |
| 231 const ScrollbarTrackExtraParams& extra_params, | |
| 232 const gfx::Rect& rect) const { | |
| 233 SkPaint paint; | |
| 234 paint.setColor(track_color_); | |
|
tapted
2014/08/11 01:00:58
probably something like paint.setShader(SkGradient
Andre
2014/08/12 21:42:38
Done.
| |
| 235 SkIRect track_rect; | |
| 236 track_rect.set(rect.x(), rect.y(), rect.right(), rect.bottom()); | |
| 237 canvas->drawIRect(track_rect, paint); | |
| 238 | |
| 239 // Draw line border next to content area. | |
| 240 paint.setColor(kScrollerTrackBorderColor); | |
| 241 if (part == kScrollbarVerticalTrack) { | |
| 242 canvas->drawRectCoords(track_rect.left(), | |
| 243 track_rect.top(), | |
| 244 track_rect.left() + kScrollerTrackBorderWidth, | |
| 245 track_rect.bottom(), | |
| 246 paint); | |
| 247 } else { | |
| 248 canvas->drawRectCoords(track_rect.left(), | |
| 249 track_rect.top(), | |
| 250 track_rect.right(), | |
| 251 track_rect.top() + kScrollerTrackBorderWidth, | |
| 252 paint); | |
| 253 } | |
| 254 } | |
| 255 | |
| 256 void NativeThemeMac::PaintScrollbarThumb(SkCanvas* canvas, | |
| 257 Part part, | |
| 258 State state, | |
| 259 const gfx::Rect& rect) const { | |
| 260 gfx::Rect thumb_rect(rect); | |
| 261 if (part == kScrollbarVerticalThumb) | |
|
tapted
2014/08/11 01:00:58
Maybe a switch statement here, with NOTREACHED().
Andre
2014/08/12 21:42:38
Done.
| |
| 262 thumb_rect.Inset(kScrollerTrackBorderWidth, 0, 0, 0); | |
| 263 else | |
| 264 thumb_rect.Inset(0, kScrollerTrackBorderWidth, 0, 0); | |
| 265 | |
| 266 thumb_rect.Inset(kScrollerThumbInset, kScrollerThumbInset); | |
| 267 | |
| 268 SkPaint paint; | |
| 269 paint.setColor(state == kHovered ? thumb_active_color_ | |
| 270 : thumb_inactive_color_); | |
| 271 SkRect skrect; | |
| 272 skrect.set( | |
| 273 thumb_rect.x(), thumb_rect.y(), thumb_rect.right(), thumb_rect.bottom()); | |
| 274 const SkScalar radius = std::min(skrect.width(), skrect.height()); | |
| 275 canvas->drawRoundRect(skrect, radius, radius, paint); | |
| 276 } | |
| 277 | |
| 219 NativeThemeMac::NativeThemeMac() { | 278 NativeThemeMac::NativeThemeMac() { |
| 279 set_scrollbar_button_length(0); | |
|
tapted
2014/08/11 01:00:58
Perhaps also override PaintArrowButton to be a no-
Andre
2014/08/12 21:42:38
I've added a scrollbar_button_length_ check in Nat
tapted
2014/08/13 01:13:29
lg
| |
| 280 SetScrollbarColors( | |
| 281 kScrollerThumbColor, kScrollerThumbHoverColor, kScrollerTrackColor); | |
| 220 } | 282 } |
| 221 | 283 |
| 222 NativeThemeMac::~NativeThemeMac() { | 284 NativeThemeMac::~NativeThemeMac() { |
| 223 } | 285 } |
| 224 | 286 |
| 225 } // namespace ui | 287 } // namespace ui |
| OLD | NEW |