| 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 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "build/build_config.h" |
| 11 #include "ui/base/layout.h" | 12 #include "ui/base/layout.h" |
| 12 #include "ui/base/nine_image_painter_factory.h" | 13 #include "ui/base/nine_image_painter_factory.h" |
| 13 #include "ui/base/resource/material_design/material_design_controller.h" | 14 #include "ui/base/resource/material_design/material_design_controller.h" |
| 14 #include "ui/gfx/canvas.h" | 15 #include "ui/gfx/canvas.h" |
| 15 #include "ui/gfx/geometry/rect.h" | 16 #include "ui/gfx/geometry/rect.h" |
| 16 #include "ui/gfx/geometry/size.h" | 17 #include "ui/gfx/geometry/size.h" |
| 17 #include "ui/gfx/image/image_skia.h" | 18 #include "ui/gfx/image/image_skia.h" |
| 18 #include "ui/gfx/nine_image_painter.h" | 19 #include "ui/gfx/nine_image_painter.h" |
| 19 #include "ui/gfx/path.h" | 20 #include "ui/gfx/path.h" |
| 20 #include "ui/gfx/skbitmap_operations.h" | 21 #include "ui/gfx/skbitmap_operations.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 38 IMAGE_GRID(IDR_SCROLLBAR_THUMB_BASE_PRESSED) | 39 IMAGE_GRID(IDR_SCROLLBAR_THUMB_BASE_PRESSED) |
| 39 }; | 40 }; |
| 40 | 41 |
| 41 const int kScrollbarArrowButtonImages[NativeTheme::kNumStates][9] = { | 42 const int kScrollbarArrowButtonImages[NativeTheme::kNumStates][9] = { |
| 42 EMPTY_IMAGE_GRID, | 43 EMPTY_IMAGE_GRID, |
| 43 IMAGE_GRID(IDR_SCROLLBAR_ARROW_BUTTON_BASE_HOVER), | 44 IMAGE_GRID(IDR_SCROLLBAR_ARROW_BUTTON_BASE_HOVER), |
| 44 IMAGE_GRID(IDR_SCROLLBAR_ARROW_BUTTON_BASE_NORMAL), | 45 IMAGE_GRID(IDR_SCROLLBAR_ARROW_BUTTON_BASE_NORMAL), |
| 45 IMAGE_GRID(IDR_SCROLLBAR_ARROW_BUTTON_BASE_PRESSED) | 46 IMAGE_GRID(IDR_SCROLLBAR_ARROW_BUTTON_BASE_PRESSED) |
| 46 }; | 47 }; |
| 47 | 48 |
| 48 const uint8 kScrollbarOverlayThumbFillAlphas[NativeTheme::kNumStates] = { | 49 const uint8_t kScrollbarOverlayThumbFillAlphas[NativeTheme::kNumStates] = { |
| 49 0, // Does not matter, will not paint for disabled state. | 50 0, // Does not matter, will not paint for disabled state. |
| 50 178, // Hover state, opacity 70%, alpha would be 0.7 * 255. | 51 178, // Hover state, opacity 70%, alpha would be 0.7 * 255. |
| 51 140, // Normal state, opacity 55%, alpha would be 0.55 * 255. | 52 140, // Normal state, opacity 55%, alpha would be 0.55 * 255. |
| 52 178 // Pressed state, opacity 70%, alpha would be 0.7 * 255. | 53 178 // Pressed state, opacity 70%, alpha would be 0.7 * 255. |
| 53 }; | 54 }; |
| 54 | 55 |
| 55 const uint8 kScrollbarOverlayThumbStrokeAlphas[NativeTheme::kNumStates] = { | 56 const uint8_t kScrollbarOverlayThumbStrokeAlphas[NativeTheme::kNumStates] = { |
| 56 0, // Does not matter, will not paint for disabled state. | 57 0, // Does not matter, will not paint for disabled state. |
| 57 51, // Hover state, opacity 20%, alpha would be 0.2 * 255. | 58 51, // Hover state, opacity 20%, alpha would be 0.2 * 255. |
| 58 38, // Normal state, opacity 15%, alpha would be 0.15 * 255. | 59 38, // Normal state, opacity 15%, alpha would be 0.15 * 255. |
| 59 51 // Pressed state, opacity 20%, alpha would be 0.2 * 255. | 60 51 // Pressed state, opacity 20%, alpha would be 0.2 * 255. |
| 60 }; | 61 }; |
| 61 | 62 |
| 62 const int kScrollbarOverlayThumbStrokeImages[9] = | 63 const int kScrollbarOverlayThumbStrokeImages[9] = |
| 63 IMAGE_GRID_NO_CENTER(IDR_SCROLLBAR_OVERLAY_THUMB_STROKE); | 64 IMAGE_GRID_NO_CENTER(IDR_SCROLLBAR_OVERLAY_THUMB_STROKE); |
| 64 | 65 |
| 65 const int kScrollbarOverlayThumbFillImages[9] = | 66 const int kScrollbarOverlayThumbFillImages[9] = |
| 66 IMAGE_GRID(IDR_SCROLLBAR_OVERLAY_THUMB_FILL); | 67 IMAGE_GRID(IDR_SCROLLBAR_OVERLAY_THUMB_FILL); |
| 67 | 68 |
| 68 const int kScrollbarTrackImages[9] = IMAGE_GRID(IDR_SCROLLBAR_BASE); | 69 const int kScrollbarTrackImages[9] = IMAGE_GRID(IDR_SCROLLBAR_BASE); |
| 69 | 70 |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 void NativeThemeAura::PaintPainter(NineImagePainter* painter, | 269 void NativeThemeAura::PaintPainter(NineImagePainter* painter, |
| 269 SkCanvas* sk_canvas, | 270 SkCanvas* sk_canvas, |
| 270 const gfx::Rect& rect) const { | 271 const gfx::Rect& rect) const { |
| 271 DCHECK(painter); | 272 DCHECK(painter); |
| 272 scoped_ptr<gfx::Canvas> canvas(CommonThemeCreateCanvas(sk_canvas)); | 273 scoped_ptr<gfx::Canvas> canvas(CommonThemeCreateCanvas(sk_canvas)); |
| 273 painter->Paint(canvas.get(), rect); | 274 painter->Paint(canvas.get(), rect); |
| 274 } | 275 } |
| 275 | 276 |
| 276 scoped_ptr<NativeThemeAura::DualPainter> NativeThemeAura::CreateDualPainter( | 277 scoped_ptr<NativeThemeAura::DualPainter> NativeThemeAura::CreateDualPainter( |
| 277 const int fill_image_ids[9], | 278 const int fill_image_ids[9], |
| 278 const uint8 fill_alphas[kNumStates], | 279 const uint8_t fill_alphas[kNumStates], |
| 279 const int stroke_image_ids[9], | 280 const int stroke_image_ids[9], |
| 280 const uint8 stroke_alphas[kNumStates]) const { | 281 const uint8_t stroke_alphas[kNumStates]) const { |
| 281 scoped_ptr<NativeThemeAura::DualPainter> dual_painter( | 282 scoped_ptr<NativeThemeAura::DualPainter> dual_painter( |
| 282 new NativeThemeAura::DualPainter(CreateNineImagePainter(fill_image_ids), | 283 new NativeThemeAura::DualPainter(CreateNineImagePainter(fill_image_ids), |
| 283 fill_alphas, | 284 fill_alphas, |
| 284 CreateNineImagePainter(stroke_image_ids), | 285 CreateNineImagePainter(stroke_image_ids), |
| 285 stroke_alphas)); | 286 stroke_alphas)); |
| 286 return dual_painter; | 287 return dual_painter; |
| 287 } | 288 } |
| 288 | 289 |
| 289 void NativeThemeAura::PaintDualPainter( | 290 void NativeThemeAura::PaintDualPainter( |
| 290 NativeThemeAura::DualPainter* dual_painter, | 291 NativeThemeAura::DualPainter* dual_painter, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 301 | 302 |
| 302 void NativeThemeAura::PaintDualPainterTransition( | 303 void NativeThemeAura::PaintDualPainterTransition( |
| 303 NativeThemeAura::DualPainter* dual_painter, | 304 NativeThemeAura::DualPainter* dual_painter, |
| 304 SkCanvas* sk_canvas, | 305 SkCanvas* sk_canvas, |
| 305 const gfx::Rect& rect, | 306 const gfx::Rect& rect, |
| 306 State startState, | 307 State startState, |
| 307 State endState, | 308 State endState, |
| 308 double progress) const { | 309 double progress) const { |
| 309 DCHECK(dual_painter); | 310 DCHECK(dual_painter); |
| 310 scoped_ptr<gfx::Canvas> canvas(CommonThemeCreateCanvas(sk_canvas)); | 311 scoped_ptr<gfx::Canvas> canvas(CommonThemeCreateCanvas(sk_canvas)); |
| 311 uint8 fill_alpha = dual_painter->fill_alphas[startState] + | 312 uint8_t fill_alpha = dual_painter->fill_alphas[startState] + |
| 312 (dual_painter->fill_alphas[endState] - | 313 (dual_painter->fill_alphas[endState] - |
| 313 dual_painter->fill_alphas[startState]) * | 314 dual_painter->fill_alphas[startState]) * |
| 314 progress; | |
| 315 uint8 stroke_alpha = dual_painter->stroke_alphas[startState] + | |
| 316 (dual_painter->stroke_alphas[endState] - | |
| 317 dual_painter->stroke_alphas[startState]) * | |
| 318 progress; | 315 progress; |
| 316 uint8_t stroke_alpha = dual_painter->stroke_alphas[startState] + |
| 317 (dual_painter->stroke_alphas[endState] - |
| 318 dual_painter->stroke_alphas[startState]) * |
| 319 progress; |
| 319 | 320 |
| 320 dual_painter->fill_painter->Paint(canvas.get(), rect, fill_alpha); | 321 dual_painter->fill_painter->Paint(canvas.get(), rect, fill_alpha); |
| 321 dual_painter->stroke_painter->Paint(canvas.get(), rect, stroke_alpha); | 322 dual_painter->stroke_painter->Paint(canvas.get(), rect, stroke_alpha); |
| 322 } | 323 } |
| 323 | 324 |
| 324 NativeThemeAura::DualPainter::DualPainter( | 325 NativeThemeAura::DualPainter::DualPainter( |
| 325 scoped_ptr<NineImagePainter> fill_painter, | 326 scoped_ptr<NineImagePainter> fill_painter, |
| 326 const uint8 fill_alphas[kNumStates], | 327 const uint8_t fill_alphas[kNumStates], |
| 327 scoped_ptr<NineImagePainter> stroke_painter, | 328 scoped_ptr<NineImagePainter> stroke_painter, |
| 328 const uint8 stroke_alphas[kNumStates]) | 329 const uint8_t stroke_alphas[kNumStates]) |
| 329 : fill_painter(std::move(fill_painter)), | 330 : fill_painter(std::move(fill_painter)), |
| 330 fill_alphas(fill_alphas), | 331 fill_alphas(fill_alphas), |
| 331 stroke_painter(std::move(stroke_painter)), | 332 stroke_painter(std::move(stroke_painter)), |
| 332 stroke_alphas(stroke_alphas) {} | 333 stroke_alphas(stroke_alphas) {} |
| 333 | 334 |
| 334 NativeThemeAura::DualPainter::~DualPainter() {} | 335 NativeThemeAura::DualPainter::~DualPainter() {} |
| 335 | 336 |
| 336 } // namespace ui | 337 } // namespace ui |
| OLD | NEW |