Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef UI_NATIVE_THEME_NATIVE_THEME_AURA_H_ |
| 6 | #define UI_NATIVE_THEME_NATIVE_THEME_AURA_H_ |
| 7 | |
| 8 | #include "base/basictypes.h" |
| 9 | #include "base/compiler_specific.h" |
Torne (Richard Coles) | 90dce4d | 2013-05-29 14:40:03 +0100 | [diff] [blame] | 10 | #include "ui/native_theme/fallback_theme.h" |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 11 | |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 12 | namespace gfx { |
| 13 | class NineImagePainter; |
| 14 | } |
| 15 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 16 | namespace ui { |
| 17 | |
| 18 | // Aura implementation of native theme support. |
Torne (Richard Coles) | 90dce4d | 2013-05-29 14:40:03 +0100 | [diff] [blame] | 19 | class NATIVE_THEME_EXPORT NativeThemeAura : public FallbackTheme { |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 20 | public: |
| 21 | static NativeThemeAura* instance(); |
| 22 | |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 23 | protected: |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 24 | NativeThemeAura(); |
Torne (Richard Coles) | 31cddfd | 2014-11-06 11:12:11 +0000 | [diff] [blame] | 25 | ~NativeThemeAura() override; |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 26 | |
| 27 | // Overridden from NativeThemeBase: |
Torne (Richard Coles) | 31cddfd | 2014-11-06 11:12:11 +0000 | [diff] [blame] | 28 | void PaintMenuPopupBackground( |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 29 | SkCanvas* canvas, |
| 30 | const gfx::Size& size, |
Torne (Richard Coles) | 0b0f963 | 2014-10-27 14:56:43 +0000 | [diff] [blame] | 31 | const MenuBackgroundExtraParams& menu_background) const override; |
Torne (Richard Coles) | 31cddfd | 2014-11-06 11:12:11 +0000 | [diff] [blame] | 32 | void PaintMenuItemBackground( |
Torne (Richard Coles) | b2df76e | 2013-05-13 16:52:09 +0100 | [diff] [blame] | 33 | SkCanvas* canvas, |
| 34 | State state, |
| 35 | const gfx::Rect& rect, |
Torne (Richard Coles) | 0b0f963 | 2014-10-27 14:56:43 +0000 | [diff] [blame] | 36 | const MenuListExtraParams& menu_list) const override; |
Torne (Richard Coles) | 31cddfd | 2014-11-06 11:12:11 +0000 | [diff] [blame] | 37 | void PaintArrowButton(SkCanvas* gc, |
| 38 | const gfx::Rect& rect, |
| 39 | Part direction, |
| 40 | State state) const override; |
| 41 | void PaintScrollbarTrack(SkCanvas* sk_canvas, |
| 42 | Part part, |
| 43 | State state, |
| 44 | const ScrollbarTrackExtraParams& extra_params, |
| 45 | const gfx::Rect& rect) const override; |
| 46 | void PaintScrollbarThumb(SkCanvas* sk_canvas, |
| 47 | Part part, |
| 48 | State state, |
| 49 | const gfx::Rect& rect) const override; |
| 50 | void PaintScrollbarCorner(SkCanvas* canvas, |
| 51 | State state, |
| 52 | const gfx::Rect& rect) const override; |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 53 | |
Torne (Richard Coles) | 31cddfd | 2014-11-06 11:12:11 +0000 | [diff] [blame] | 54 | void PaintScrollbarThumbStateTransition(SkCanvas* canvas, |
| 55 | State startState, |
| 56 | State endState, |
| 57 | double progress, |
| 58 | const gfx::Rect& rect) const override; |
Torne (Richard Coles) | f8ee788 | 2014-06-20 14:52:04 +0100 | [diff] [blame] | 59 | |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 60 | // Returns the NineImagePainter used to paint the specified state, creating if |
| 61 | // necessary. If no image is provided for the specified state the normal state |
| 62 | // images are used. |
| 63 | gfx::NineImagePainter* GetOrCreatePainter( |
Ben Murdoch | 116680a | 2014-07-20 18:25:52 -0700 | [diff] [blame] | 64 | const int image_ids[kNumStates][9], |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 65 | State state, |
Ben Murdoch | 116680a | 2014-07-20 18:25:52 -0700 | [diff] [blame] | 66 | scoped_ptr<gfx::NineImagePainter> painters[kNumStates]) const; |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 67 | |
| 68 | // Paints |painter| into the canvas using |rect|. |
| 69 | void PaintPainter(gfx::NineImagePainter* painter, |
| 70 | SkCanvas* sk_canvas, |
| 71 | const gfx::Rect& rect) const; |
| 72 | |
| 73 | mutable scoped_ptr<gfx::NineImagePainter> scrollbar_track_painter_; |
| 74 | |
| 75 | mutable scoped_ptr<gfx::NineImagePainter> |
Ben Murdoch | 116680a | 2014-07-20 18:25:52 -0700 | [diff] [blame] | 76 | scrollbar_thumb_painters_[kNumStates]; |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 77 | |
| 78 | mutable scoped_ptr<gfx::NineImagePainter> |
Ben Murdoch | 116680a | 2014-07-20 18:25:52 -0700 | [diff] [blame] | 79 | scrollbar_arrow_button_painters_[kNumStates]; |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 80 | |
Torne (Richard Coles) | 23730a6 | 2014-03-21 14:25:57 +0000 | [diff] [blame] | 81 | private: |
| 82 | struct DualPainter { |
| 83 | // For overlay scrollbar thumbs, fill and stroke are controlled separately, |
| 84 | // and each state is achieved by painting with different opacity. This |
| 85 | // struct bundles information of painter generated using assets and alpha |
| 86 | // value associated with each state, so that a DualPainter for overlay |
| 87 | // scrollbar thumb would only need state as input to paint correctly. |
| 88 | DualPainter(scoped_ptr<gfx::NineImagePainter> fill_painter, |
Ben Murdoch | 116680a | 2014-07-20 18:25:52 -0700 | [diff] [blame] | 89 | const uint8 fill_alphas[kNumStates], |
Torne (Richard Coles) | 23730a6 | 2014-03-21 14:25:57 +0000 | [diff] [blame] | 90 | scoped_ptr<gfx::NineImagePainter> stroke_painter, |
Ben Murdoch | 116680a | 2014-07-20 18:25:52 -0700 | [diff] [blame] | 91 | const uint8 stroke_alphas[kNumStates]); |
Torne (Richard Coles) | 23730a6 | 2014-03-21 14:25:57 +0000 | [diff] [blame] | 92 | ~DualPainter(); |
| 93 | |
| 94 | scoped_ptr<gfx::NineImagePainter> fill_painter; |
| 95 | const uint8* const fill_alphas; |
| 96 | scoped_ptr<gfx::NineImagePainter> stroke_painter; |
| 97 | const uint8* const stroke_alphas; |
| 98 | }; |
| 99 | |
| 100 | // Returns DualPainter from specific fill and stroke, creating if necessary. |
| 101 | scoped_ptr<DualPainter> CreateDualPainter( |
| 102 | const int fill_image_ids[9], |
Ben Murdoch | 116680a | 2014-07-20 18:25:52 -0700 | [diff] [blame] | 103 | const uint8 fill_alphas[kNumStates], |
Torne (Richard Coles) | 23730a6 | 2014-03-21 14:25:57 +0000 | [diff] [blame] | 104 | const int stroke_image_ids[9], |
Ben Murdoch | 116680a | 2014-07-20 18:25:52 -0700 | [diff] [blame] | 105 | const uint8 stroke_alphas[kNumStates]) const; |
Torne (Richard Coles) | 23730a6 | 2014-03-21 14:25:57 +0000 | [diff] [blame] | 106 | |
| 107 | // Paints |dualPainter| into the canvas using |rect| and specific alpha. |
| 108 | void PaintDualPainter(DualPainter* dual_painter, |
| 109 | SkCanvas* sk_canvas, |
| 110 | const gfx::Rect& rect, |
| 111 | State state) const; |
| 112 | |
Torne (Richard Coles) | f8ee788 | 2014-06-20 14:52:04 +0100 | [diff] [blame] | 113 | void PaintDualPainterTransition(DualPainter* dual_painter, |
| 114 | SkCanvas* sk_canvas, |
| 115 | const gfx::Rect& rect, |
| 116 | State startState, |
| 117 | State endState, |
| 118 | double progress) const; |
| 119 | |
Torne (Richard Coles) | 23730a6 | 2014-03-21 14:25:57 +0000 | [diff] [blame] | 120 | mutable scoped_ptr<DualPainter> scrollbar_overlay_thumb_painter_; |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 121 | |
| 122 | DISALLOW_COPY_AND_ASSIGN(NativeThemeAura); |
| 123 | }; |
| 124 | |
| 125 | } // namespace ui |
| 126 | |
| 127 | #endif // UI_NATIVE_THEME_NATIVE_THEME_AURA_H_ |