OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_aura.h" | 5 #include "ui/native_theme/native_theme_aura.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "grit/ui_resources.h" | 10 #include "grit/ui_resources.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include "ui/native_theme/native_theme_switches.h" | 22 #include "ui/native_theme/native_theme_switches.h" |
23 | 23 |
24 using gfx::NineImagePainter; | 24 using gfx::NineImagePainter; |
25 | 25 |
26 #define EMPTY_IMAGE_GRID { 0, 0, 0, 0, 0, 0, 0, 0, 0 } | 26 #define EMPTY_IMAGE_GRID { 0, 0, 0, 0, 0, 0, 0, 0, 0 } |
27 | 27 |
28 namespace ui { | 28 namespace ui { |
29 | 29 |
30 namespace { | 30 namespace { |
31 | 31 |
32 const int kScrollbarThumbImages[NativeTheme::kMaxState][9] = { | 32 const int kScrollbarThumbImages[NativeTheme::kNumStates][9] = { |
33 EMPTY_IMAGE_GRID, | 33 EMPTY_IMAGE_GRID, |
34 IMAGE_GRID(IDR_SCROLLBAR_THUMB_BASE_HOVER), | 34 IMAGE_GRID(IDR_SCROLLBAR_THUMB_BASE_HOVER), |
35 IMAGE_GRID(IDR_SCROLLBAR_THUMB_BASE_NORMAL), | 35 IMAGE_GRID(IDR_SCROLLBAR_THUMB_BASE_NORMAL), |
36 IMAGE_GRID(IDR_SCROLLBAR_THUMB_BASE_PRESSED) | 36 IMAGE_GRID(IDR_SCROLLBAR_THUMB_BASE_PRESSED) |
37 }; | 37 }; |
38 | 38 |
39 const int kScrollbarArrowButtonImages[NativeTheme::kMaxState][9] = { | 39 const int kScrollbarArrowButtonImages[NativeTheme::kNumStates][9] = { |
40 EMPTY_IMAGE_GRID, | 40 EMPTY_IMAGE_GRID, |
41 IMAGE_GRID(IDR_SCROLLBAR_ARROW_BUTTON_BASE_HOVER), | 41 IMAGE_GRID(IDR_SCROLLBAR_ARROW_BUTTON_BASE_HOVER), |
42 IMAGE_GRID(IDR_SCROLLBAR_ARROW_BUTTON_BASE_NORMAL), | 42 IMAGE_GRID(IDR_SCROLLBAR_ARROW_BUTTON_BASE_NORMAL), |
43 IMAGE_GRID(IDR_SCROLLBAR_ARROW_BUTTON_BASE_PRESSED) | 43 IMAGE_GRID(IDR_SCROLLBAR_ARROW_BUTTON_BASE_PRESSED) |
44 }; | 44 }; |
45 | 45 |
46 const uint8 kScrollbarOverlayThumbFillAlphas[NativeTheme::kMaxState] = { | 46 const uint8 kScrollbarOverlayThumbFillAlphas[NativeTheme::kNumStates] = { |
47 0, // Does not matter, will not paint for disabled state. | 47 0, // Does not matter, will not paint for disabled state. |
48 178, // Hover state, opacity 70%, alpha would be 0.7 * 255. | 48 178, // Hover state, opacity 70%, alpha would be 0.7 * 255. |
49 140, // Normal state, opacity 55%, alpha would be 0.55 * 255. | 49 140, // Normal state, opacity 55%, alpha would be 0.55 * 255. |
50 178 // Pressed state, opacity 70%, alpha would be 0.7 * 255. | 50 178 // Pressed state, opacity 70%, alpha would be 0.7 * 255. |
51 }; | 51 }; |
52 | 52 |
53 const uint8 kScrollbarOverlayThumbStrokeAlphas[NativeTheme::kMaxState] = { | 53 const uint8 kScrollbarOverlayThumbStrokeAlphas[NativeTheme::kNumStates] = { |
54 0, // Does not matter, will not paint for disabled state. | 54 0, // Does not matter, will not paint for disabled state. |
55 51, // Hover state, opacity 20%, alpha would be 0.2 * 255. | 55 51, // Hover state, opacity 20%, alpha would be 0.2 * 255. |
56 38, // Normal state, opacity 15%, alpha would be 0.15 * 255. | 56 38, // Normal state, opacity 15%, alpha would be 0.15 * 255. |
57 51 // Pressed state, opacity 20%, alpha would be 0.2 * 255. | 57 51 // Pressed state, opacity 20%, alpha would be 0.2 * 255. |
58 }; | 58 }; |
59 | 59 |
60 const int kScrollbarOverlayThumbStrokeImages[9] = | 60 const int kScrollbarOverlayThumbStrokeImages[9] = |
61 IMAGE_GRID_NO_CENTER(IDR_SCROLLBAR_OVERLAY_THUMB_STROKE); | 61 IMAGE_GRID_NO_CENTER(IDR_SCROLLBAR_OVERLAY_THUMB_STROKE); |
62 | 62 |
63 const int kScrollbarOverlayThumbFillImages[9] = | 63 const int kScrollbarOverlayThumbFillImages[9] = |
(...skipping 16 matching lines...) Expand all Loading... |
80 } | 80 } |
81 #endif | 81 #endif |
82 | 82 |
83 NativeThemeAura::NativeThemeAura() { | 83 NativeThemeAura::NativeThemeAura() { |
84 // We don't draw scrollbar buttons. | 84 // We don't draw scrollbar buttons. |
85 #if defined(OS_CHROMEOS) | 85 #if defined(OS_CHROMEOS) |
86 set_scrollbar_button_length(0); | 86 set_scrollbar_button_length(0); |
87 #endif | 87 #endif |
88 | 88 |
89 // Images and alphas declarations assume the following order. | 89 // Images and alphas declarations assume the following order. |
90 COMPILE_ASSERT(kDisabled == 0, states_unexepctedly_changed); | 90 COMPILE_ASSERT(kDisabled == 0, states_unexpectedly_changed); |
91 COMPILE_ASSERT(kHovered == 1, states_unexepctedly_changed); | 91 COMPILE_ASSERT(kHovered == 1, states_unexpectedly_changed); |
92 COMPILE_ASSERT(kNormal == 2, states_unexepctedly_changed); | 92 COMPILE_ASSERT(kNormal == 2, states_unexpectedly_changed); |
93 COMPILE_ASSERT(kPressed == 3, states_unexepctedly_changed); | 93 COMPILE_ASSERT(kPressed == 3, states_unexpectedly_changed); |
94 COMPILE_ASSERT(kMaxState == 4, states_unexepctedly_changed); | |
95 } | 94 } |
96 | 95 |
97 NativeThemeAura::~NativeThemeAura() { | 96 NativeThemeAura::~NativeThemeAura() { |
98 } | 97 } |
99 | 98 |
100 void NativeThemeAura::PaintMenuPopupBackground( | 99 void NativeThemeAura::PaintMenuPopupBackground( |
101 SkCanvas* canvas, | 100 SkCanvas* canvas, |
102 const gfx::Size& size, | 101 const gfx::Size& size, |
103 const MenuBackgroundExtraParams& menu_background) const { | 102 const MenuBackgroundExtraParams& menu_background) const { |
104 SkColor color = GetSystemColor(NativeTheme::kColorId_MenuBackgroundColor); | 103 SkColor color = GetSystemColor(NativeTheme::kColorId_MenuBackgroundColor); |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 // Overlay Scrollbar should never paint a scrollbar corner. | 237 // Overlay Scrollbar should never paint a scrollbar corner. |
239 DCHECK(!IsOverlayScrollbarEnabled()); | 238 DCHECK(!IsOverlayScrollbarEnabled()); |
240 SkPaint paint; | 239 SkPaint paint; |
241 paint.setColor(SkColorSetRGB(0xF1, 0xF1, 0xF1)); | 240 paint.setColor(SkColorSetRGB(0xF1, 0xF1, 0xF1)); |
242 paint.setStyle(SkPaint::kFill_Style); | 241 paint.setStyle(SkPaint::kFill_Style); |
243 paint.setXfermodeMode(SkXfermode::kSrc_Mode); | 242 paint.setXfermodeMode(SkXfermode::kSrc_Mode); |
244 canvas->drawIRect(RectToSkIRect(rect), paint); | 243 canvas->drawIRect(RectToSkIRect(rect), paint); |
245 } | 244 } |
246 | 245 |
247 NineImagePainter* NativeThemeAura::GetOrCreatePainter( | 246 NineImagePainter* NativeThemeAura::GetOrCreatePainter( |
248 const int images[kMaxState][9], | 247 const int images[kNumStates][9], |
249 State state, | 248 State state, |
250 scoped_ptr<NineImagePainter> painters[kMaxState]) const { | 249 scoped_ptr<NineImagePainter> painters[kNumStates]) const { |
251 if (painters[state]) | 250 if (painters[state]) |
252 return painters[state].get(); | 251 return painters[state].get(); |
253 if (images[state][0] == 0) { | 252 if (images[state][0] == 0) { |
254 // Must always provide normal state images. | 253 // Must always provide normal state images. |
255 DCHECK_NE(kNormal, state); | 254 DCHECK_NE(kNormal, state); |
256 return GetOrCreatePainter(images, kNormal, painters); | 255 return GetOrCreatePainter(images, kNormal, painters); |
257 } | 256 } |
258 painters[state] = CreateNineImagePainter(images[state]); | 257 painters[state] = CreateNineImagePainter(images[state]); |
259 return painters[state].get(); | 258 return painters[state].get(); |
260 } | 259 } |
261 | 260 |
262 void NativeThemeAura::PaintPainter(NineImagePainter* painter, | 261 void NativeThemeAura::PaintPainter(NineImagePainter* painter, |
263 SkCanvas* sk_canvas, | 262 SkCanvas* sk_canvas, |
264 const gfx::Rect& rect) const { | 263 const gfx::Rect& rect) const { |
265 DCHECK(painter); | 264 DCHECK(painter); |
266 scoped_ptr<gfx::Canvas> canvas(CommonThemeCreateCanvas(sk_canvas)); | 265 scoped_ptr<gfx::Canvas> canvas(CommonThemeCreateCanvas(sk_canvas)); |
267 painter->Paint(canvas.get(), rect); | 266 painter->Paint(canvas.get(), rect); |
268 } | 267 } |
269 | 268 |
270 scoped_ptr<NativeThemeAura::DualPainter> NativeThemeAura::CreateDualPainter( | 269 scoped_ptr<NativeThemeAura::DualPainter> NativeThemeAura::CreateDualPainter( |
271 const int fill_image_ids[9], | 270 const int fill_image_ids[9], |
272 const uint8 fill_alphas[kMaxState], | 271 const uint8 fill_alphas[kNumStates], |
273 const int stroke_image_ids[9], | 272 const int stroke_image_ids[9], |
274 const uint8 stroke_alphas[kMaxState]) const { | 273 const uint8 stroke_alphas[kNumStates]) const { |
275 scoped_ptr<NativeThemeAura::DualPainter> dual_painter( | 274 scoped_ptr<NativeThemeAura::DualPainter> dual_painter( |
276 new NativeThemeAura::DualPainter(CreateNineImagePainter(fill_image_ids), | 275 new NativeThemeAura::DualPainter(CreateNineImagePainter(fill_image_ids), |
277 fill_alphas, | 276 fill_alphas, |
278 CreateNineImagePainter(stroke_image_ids), | 277 CreateNineImagePainter(stroke_image_ids), |
279 stroke_alphas)); | 278 stroke_alphas)); |
280 return dual_painter.Pass(); | 279 return dual_painter.Pass(); |
281 } | 280 } |
282 | 281 |
283 void NativeThemeAura::PaintDualPainter( | 282 void NativeThemeAura::PaintDualPainter( |
284 NativeThemeAura::DualPainter* dual_painter, | 283 NativeThemeAura::DualPainter* dual_painter, |
(...skipping 25 matching lines...) Expand all Loading... |
310 (dual_painter->stroke_alphas[endState] - | 309 (dual_painter->stroke_alphas[endState] - |
311 dual_painter->stroke_alphas[startState]) * | 310 dual_painter->stroke_alphas[startState]) * |
312 progress; | 311 progress; |
313 | 312 |
314 dual_painter->fill_painter->Paint(canvas.get(), rect, fill_alpha); | 313 dual_painter->fill_painter->Paint(canvas.get(), rect, fill_alpha); |
315 dual_painter->stroke_painter->Paint(canvas.get(), rect, stroke_alpha); | 314 dual_painter->stroke_painter->Paint(canvas.get(), rect, stroke_alpha); |
316 } | 315 } |
317 | 316 |
318 NativeThemeAura::DualPainter::DualPainter( | 317 NativeThemeAura::DualPainter::DualPainter( |
319 scoped_ptr<NineImagePainter> fill_painter, | 318 scoped_ptr<NineImagePainter> fill_painter, |
320 const uint8 fill_alphas[kMaxState], | 319 const uint8 fill_alphas[kNumStates], |
321 scoped_ptr<NineImagePainter> stroke_painter, | 320 scoped_ptr<NineImagePainter> stroke_painter, |
322 const uint8 stroke_alphas[kMaxState]) | 321 const uint8 stroke_alphas[kNumStates]) |
323 : fill_painter(fill_painter.Pass()), | 322 : fill_painter(fill_painter.Pass()), |
324 fill_alphas(fill_alphas), | 323 fill_alphas(fill_alphas), |
325 stroke_painter(stroke_painter.Pass()), | 324 stroke_painter(stroke_painter.Pass()), |
326 stroke_alphas(stroke_alphas) {} | 325 stroke_alphas(stroke_alphas) {} |
327 | 326 |
328 NativeThemeAura::DualPainter::~DualPainter() {} | 327 NativeThemeAura::DualPainter::~DualPainter() {} |
329 | 328 |
330 } // namespace ui | 329 } // namespace ui |
OLD | NEW |