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 "third_party/skia/include/effects/SkGradientShader.h" | |
16 #include "ui/gfx/geometry/rect.h" | |
15 #include "ui/gfx/skia_util.h" | 17 #include "ui/gfx/skia_util.h" |
16 | 18 |
17 namespace { | 19 namespace { |
18 | 20 |
21 const SkColor kScrollerTrackGradientColors[] = { | |
22 SkColorSetRGB(0xF0, 0xF0, 0xF0), | |
23 SkColorSetRGB(0xFA, 0xFA, 0xFA), | |
24 SkColorSetRGB(0xFD, 0xFD, 0xFD), | |
25 SkColorSetRGB(0xF5, 0xF5, 0xF5) }; | |
26 const SkColor kScrollerTrackBorderColor = SkColorSetRGB(0xE4, 0xE4, 0xE4); | |
27 const SkColor kScrollerThumbColor = SkColorSetARGB(0x38, 0, 0, 0); | |
28 const SkColor kScrollerThumbHoverColor = SkColorSetARGB(0x80, 0, 0, 0); | |
29 const int kScrollerTrackBorderWidth = 1; | |
30 const int kScrollerThumbInset = 3; | |
tapted
2014/08/13 01:13:29
nit: this one probably needs a comment - it's a bi
Andre
2014/08/13 20:04:21
Done.
| |
31 | |
19 // Values calculated by reading pixels and solving simultaneous equations | 32 // Values calculated by reading pixels and solving simultaneous equations |
20 // derived from "A over B" alpha compositing. Steps: Sample the semi-transparent | 33 // 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 | 34 // 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, | 35 // value between 0.0 and 1.0 (i.e. divide by 255.0). Then, |
23 // alpha = (P2 - P1 + B1 - B2) / (B1 - B2) | 36 // alpha = (P2 - P1 + B1 - B2) / (B1 - B2) |
24 // color = (P1 - B1 + alpha * B1) / alpha. | 37 // color = (P1 - B1 + alpha * B1) / alpha. |
25 const SkColor kMenuPopupBackgroundColor = SkColorSetARGB(251, 255, 255, 255); | 38 const SkColor kMenuPopupBackgroundColor = SkColorSetARGB(251, 255, 255, 255); |
26 const SkColor kMenuSeparatorColor = SkColorSetARGB(243, 228, 228, 228); | 39 const SkColor kMenuSeparatorColor = SkColorSetARGB(243, 228, 228, 228); |
27 const SkColor kMenuBorderColor = SkColorSetARGB(60, 0, 0, 0); | 40 const SkColor kMenuBorderColor = SkColorSetARGB(60, 0, 0, 0); |
28 | 41 |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
177 } | 190 } |
178 | 191 |
179 SkColor color; | 192 SkColor color; |
180 if (CommonThemeGetSystemColor(color_id, &color)) | 193 if (CommonThemeGetSystemColor(color_id, &color)) |
181 return color; | 194 return color; |
182 | 195 |
183 NOTIMPLEMENTED() << " Invalid color_id: " << color_id; | 196 NOTIMPLEMENTED() << " Invalid color_id: " << color_id; |
184 return FallbackTheme::GetSystemColor(color_id); | 197 return FallbackTheme::GetSystemColor(color_id); |
185 } | 198 } |
186 | 199 |
200 void NativeThemeMac::PaintScrollbarTrack( | |
201 SkCanvas* canvas, | |
202 Part part, | |
203 State state, | |
204 const ScrollbarTrackExtraParams& extra_params, | |
205 const gfx::Rect& rect) const { | |
206 SkPoint gradient_bounds[2]; | |
tapted
2014/08/13 01:13:29
nit: perhaps a comment in here saying which style
Andre
2014/08/13 20:04:22
Done.
| |
207 if (part == kScrollbarVerticalTrack) { | |
208 gradient_bounds[0].set(rect.x() + kScrollerTrackBorderWidth, rect.y()); | |
209 gradient_bounds[1].set(rect.right(), rect.y()); | |
210 } else { | |
211 gradient_bounds[0].set(rect.x(), rect.y() + kScrollerTrackBorderWidth); | |
tapted
2014/08/13 01:13:29
nit: DCHECK_EQ(part, kScrollbarHorizontalTrack);
Andre
2014/08/13 20:04:22
Done.
| |
212 gradient_bounds[1].set(rect.x(), rect.bottom()); | |
213 } | |
214 skia::RefPtr<SkShader> shader = skia::AdoptRef( | |
215 SkGradientShader::CreateLinear(gradient_bounds, | |
216 kScrollerTrackGradientColors, | |
217 NULL, | |
218 4, | |
tapted
2014/08/13 01:13:29
nit: 4 -> arraysize(kScrollerTrackGradientColors)
Andre
2014/08/13 20:04:22
Done.
| |
219 SkShader::kClamp_TileMode)); | |
220 SkPaint gradient; | |
221 gradient.setShader(shader.get()); | |
222 | |
223 SkIRect track_rect; | |
224 track_rect.set(rect.x(), rect.y(), rect.right(), rect.bottom()); | |
225 canvas->drawIRect(track_rect, gradient); | |
226 | |
227 // Draw line border next to content area. | |
228 SkPaint paint; | |
229 paint.setColor(kScrollerTrackBorderColor); | |
230 if (part == kScrollbarVerticalTrack) { | |
231 canvas->drawRectCoords(track_rect.left(), | |
232 track_rect.top(), | |
233 track_rect.left() + kScrollerTrackBorderWidth, | |
234 track_rect.bottom(), | |
235 paint); | |
236 } else { | |
237 canvas->drawRectCoords(track_rect.left(), | |
238 track_rect.top(), | |
239 track_rect.right(), | |
240 track_rect.top() + kScrollerTrackBorderWidth, | |
241 paint); | |
242 } | |
243 } | |
244 | |
245 void NativeThemeMac::PaintScrollbarThumb(SkCanvas* canvas, | |
246 Part part, | |
247 State state, | |
248 const gfx::Rect& rect) const { | |
249 gfx::Rect thumb_rect(rect); | |
250 switch (part) { | |
251 case kScrollbarHorizontalThumb: | |
252 thumb_rect.Inset(0, kScrollerTrackBorderWidth, 0, 0); | |
253 break; | |
254 case kScrollbarVerticalThumb: | |
255 thumb_rect.Inset(kScrollerTrackBorderWidth, 0, 0, 0); | |
256 break; | |
257 default: | |
258 NOTREACHED(); | |
259 break; | |
260 } | |
261 | |
262 thumb_rect.Inset(kScrollerThumbInset, kScrollerThumbInset); | |
263 | |
264 SkPaint paint; | |
tapted
2014/08/13 01:13:29
Looking at the screenshots.. I think we want paint
Andre
2014/08/13 20:04:22
Done.
| |
265 paint.setColor(state == kHovered ? thumb_active_color_ | |
tapted
2014/08/13 01:13:29
hm - it's odd there are protected data members in
Andre
2014/08/13 20:04:22
Acknowledged.
| |
266 : thumb_inactive_color_); | |
267 SkRect skrect; | |
268 skrect.set( | |
269 thumb_rect.x(), thumb_rect.y(), thumb_rect.right(), thumb_rect.bottom()); | |
270 const SkScalar radius = std::min(skrect.width(), skrect.height()); | |
271 canvas->drawRoundRect(skrect, radius, radius, paint); | |
272 } | |
273 | |
187 void NativeThemeMac::PaintMenuPopupBackground( | 274 void NativeThemeMac::PaintMenuPopupBackground( |
188 SkCanvas* canvas, | 275 SkCanvas* canvas, |
189 const gfx::Size& size, | 276 const gfx::Size& size, |
190 const MenuBackgroundExtraParams& menu_background) const { | 277 const MenuBackgroundExtraParams& menu_background) const { |
191 canvas->drawColor(kMenuPopupBackgroundColor, SkXfermode::kSrc_Mode); | 278 canvas->drawColor(kMenuPopupBackgroundColor, SkXfermode::kSrc_Mode); |
192 } | 279 } |
193 | 280 |
194 void NativeThemeMac::PaintMenuItemBackground( | 281 void NativeThemeMac::PaintMenuItemBackground( |
195 SkCanvas* canvas, | 282 SkCanvas* canvas, |
196 State state, | 283 State state, |
(...skipping 13 matching lines...) Expand all Loading... | |
210 paint.setColor(GetSystemColor(kColorId_HoverMenuItemBackgroundColor)); | 297 paint.setColor(GetSystemColor(kColorId_HoverMenuItemBackgroundColor)); |
211 canvas->drawRect(gfx::RectToSkRect(rect), paint); | 298 canvas->drawRect(gfx::RectToSkRect(rect), paint); |
212 break; | 299 break; |
213 default: | 300 default: |
214 NOTREACHED(); | 301 NOTREACHED(); |
215 break; | 302 break; |
216 } | 303 } |
217 } | 304 } |
218 | 305 |
219 NativeThemeMac::NativeThemeMac() { | 306 NativeThemeMac::NativeThemeMac() { |
307 set_scrollbar_button_length(0); | |
308 SetScrollbarColors(kScrollerThumbColor, | |
309 kScrollerThumbHoverColor, | |
310 kScrollerTrackGradientColors[0]); | |
220 } | 311 } |
221 | 312 |
222 NativeThemeMac::~NativeThemeMac() { | 313 NativeThemeMac::~NativeThemeMac() { |
223 } | 314 } |
224 | 315 |
225 } // namespace ui | 316 } // namespace ui |
OLD | NEW |