Chromium Code Reviews| 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/views/controls/scrollbar/native_scroll_bar_views.h" | 5 #include "ui/views/controls/scrollbar/native_scroll_bar_views.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "ui/events/keycodes/keyboard_codes.h" | 8 #include "ui/events/keycodes/keyboard_codes.h" |
| 9 #include "ui/gfx/canvas.h" | 9 #include "ui/gfx/canvas.h" |
| 10 #include "ui/gfx/path.h" | 10 #include "ui/gfx/path.h" |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 22 // Wrapper for the scroll buttons. | 22 // Wrapper for the scroll buttons. |
| 23 class ScrollBarButton : public BaseScrollBarButton { | 23 class ScrollBarButton : public BaseScrollBarButton { |
| 24 public: | 24 public: |
| 25 enum Type { | 25 enum Type { |
| 26 UP, | 26 UP, |
| 27 DOWN, | 27 DOWN, |
| 28 LEFT, | 28 LEFT, |
| 29 RIGHT, | 29 RIGHT, |
| 30 }; | 30 }; |
| 31 | 31 |
| 32 ScrollBarButton(ButtonListener* listener, Type type); | 32 ScrollBarButton(ButtonListener* listener, |
| 33 Type type, | |
| 34 NativeScrollBarWrapper* wrapper); | |
| 33 ~ScrollBarButton() override; | 35 ~ScrollBarButton() override; |
| 34 | 36 |
| 35 gfx::Size GetPreferredSize() const override; | 37 gfx::Size GetPreferredSize() const override; |
| 36 const char* GetClassName() const override { return "ScrollBarButton"; } | 38 const char* GetClassName() const override { return "ScrollBarButton"; } |
| 37 | 39 |
| 38 protected: | 40 protected: |
| 39 void OnPaint(gfx::Canvas* canvas) override; | 41 void OnPaint(gfx::Canvas* canvas) override; |
| 40 | 42 |
| 41 private: | 43 private: |
| 42 ui::NativeTheme::ExtraParams GetNativeThemeParams() const; | 44 ui::NativeTheme::ExtraParams GetNativeThemeParams() const; |
| 43 ui::NativeTheme::Part GetNativeThemePart() const; | 45 ui::NativeTheme::Part GetNativeThemePart() const; |
| 44 ui::NativeTheme::State GetNativeThemeState() const; | 46 ui::NativeTheme::State GetNativeThemeState() const; |
| 45 | 47 |
| 46 Type type_; | 48 Type type_; |
| 49 NativeScrollBarWrapper* wrapper_; | |
| 47 }; | 50 }; |
| 48 | 51 |
| 49 // Wrapper for the scroll thumb | 52 // Wrapper for the scroll thumb |
| 50 class ScrollBarThumb : public BaseScrollBarThumb { | 53 class ScrollBarThumb : public BaseScrollBarThumb { |
| 51 public: | 54 public: |
| 52 explicit ScrollBarThumb(BaseScrollBar* scroll_bar); | 55 explicit ScrollBarThumb(BaseScrollBar* scroll_bar, |
|
tapted
2016/02/08 00:31:15
nit: explicit not needed
spqchan
2016/02/09 21:21:26
Done.
| |
| 56 NativeScrollBarWrapper* wrapper); | |
| 53 ~ScrollBarThumb() override; | 57 ~ScrollBarThumb() override; |
| 54 | 58 |
| 55 gfx::Size GetPreferredSize() const override; | 59 gfx::Size GetPreferredSize() const override; |
| 56 const char* GetClassName() const override { return "ScrollBarThumb"; } | 60 const char* GetClassName() const override { return "ScrollBarThumb"; } |
| 57 | 61 |
| 58 protected: | 62 protected: |
| 59 void OnPaint(gfx::Canvas* canvas) override; | 63 void OnPaint(gfx::Canvas* canvas) override; |
| 60 | 64 |
| 61 private: | 65 private: |
| 62 ui::NativeTheme::ExtraParams GetNativeThemeParams() const; | 66 ui::NativeTheme::ExtraParams GetNativeThemeParams() const; |
| 63 ui::NativeTheme::Part GetNativeThemePart() const; | 67 ui::NativeTheme::Part GetNativeThemePart() const; |
| 64 ui::NativeTheme::State GetNativeThemeState() const; | 68 ui::NativeTheme::State GetNativeThemeState() const; |
| 65 | 69 |
| 66 ScrollBar* scroll_bar_; | 70 ScrollBar* scroll_bar_; |
| 71 NativeScrollBarWrapper* wrapper_; | |
|
tapted
2016/02/08 00:31:15
hm. I wonder if ScrollBar should expose a GetNativ
spqchan
2016/02/09 21:21:26
ScrollBar doesn't contain the native_wrapper so th
| |
| 67 }; | 72 }; |
| 68 | 73 |
| 69 ///////////////////////////////////////////////////////////////////////////// | 74 ///////////////////////////////////////////////////////////////////////////// |
| 70 // ScrollBarButton | 75 // ScrollBarButton |
| 71 | 76 |
| 72 ScrollBarButton::ScrollBarButton(ButtonListener* listener, Type type) | 77 ScrollBarButton::ScrollBarButton(ButtonListener* listener, |
| 73 : BaseScrollBarButton(listener), | 78 Type type, |
| 74 type_(type) { | 79 NativeScrollBarWrapper* wrapper) |
| 80 : BaseScrollBarButton(listener), type_(type), wrapper_(wrapper) { | |
| 75 SetFocusable(false); | 81 SetFocusable(false); |
| 76 SetAccessibilityFocusable(false); | 82 SetAccessibilityFocusable(false); |
| 77 } | 83 } |
| 78 | 84 |
| 79 ScrollBarButton::~ScrollBarButton() { | 85 ScrollBarButton::~ScrollBarButton() { |
| 80 } | 86 } |
| 81 | 87 |
| 82 gfx::Size ScrollBarButton::GetPreferredSize() const { | 88 gfx::Size ScrollBarButton::GetPreferredSize() const { |
| 83 return GetNativeTheme()->GetPartSize(GetNativeThemePart(), | 89 return GetNativeTheme()->GetPartSize(GetNativeThemePart(), |
| 84 GetNativeThemeState(), | 90 GetNativeThemeState(), |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 98 | 104 |
| 99 switch (state()) { | 105 switch (state()) { |
| 100 case CustomButton::STATE_HOVERED: | 106 case CustomButton::STATE_HOVERED: |
| 101 params.scrollbar_arrow.is_hovering = true; | 107 params.scrollbar_arrow.is_hovering = true; |
| 102 break; | 108 break; |
| 103 default: | 109 default: |
| 104 params.scrollbar_arrow.is_hovering = false; | 110 params.scrollbar_arrow.is_hovering = false; |
| 105 break; | 111 break; |
| 106 } | 112 } |
| 107 | 113 |
| 114 params.scrollbar_arrow.overlay = wrapper_->GetOverlayParams(); | |
|
tapted
2016/02/08 00:31:15
check for a null |wrapper_|?
spqchan
2016/02/09 21:21:26
Acknowledged.
| |
| 115 | |
| 108 return params; | 116 return params; |
| 109 } | 117 } |
| 110 | 118 |
| 111 ui::NativeTheme::Part | 119 ui::NativeTheme::Part |
| 112 ScrollBarButton::GetNativeThemePart() const { | 120 ScrollBarButton::GetNativeThemePart() const { |
| 113 switch (type_) { | 121 switch (type_) { |
| 114 case UP: | 122 case UP: |
| 115 return ui::NativeTheme::kScrollbarUpArrow; | 123 return ui::NativeTheme::kScrollbarUpArrow; |
| 116 case DOWN: | 124 case DOWN: |
| 117 return ui::NativeTheme::kScrollbarDownArrow; | 125 return ui::NativeTheme::kScrollbarDownArrow; |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 140 break; | 148 break; |
| 141 } | 149 } |
| 142 | 150 |
| 143 NOTREACHED(); | 151 NOTREACHED(); |
| 144 return ui::NativeTheme::kNormal; | 152 return ui::NativeTheme::kNormal; |
| 145 } | 153 } |
| 146 | 154 |
| 147 ///////////////////////////////////////////////////////////////////////////// | 155 ///////////////////////////////////////////////////////////////////////////// |
| 148 // ScrollBarThumb | 156 // ScrollBarThumb |
| 149 | 157 |
| 150 ScrollBarThumb::ScrollBarThumb(BaseScrollBar* scroll_bar) | 158 ScrollBarThumb::ScrollBarThumb(BaseScrollBar* scroll_bar, |
| 159 NativeScrollBarWrapper* wrapper) | |
| 151 : BaseScrollBarThumb(scroll_bar), | 160 : BaseScrollBarThumb(scroll_bar), |
| 152 scroll_bar_(scroll_bar) { | 161 scroll_bar_(scroll_bar), |
| 162 wrapper_(wrapper) { | |
| 153 SetFocusable(false); | 163 SetFocusable(false); |
| 154 SetAccessibilityFocusable(false); | 164 SetAccessibilityFocusable(false); |
| 155 } | 165 } |
| 156 | 166 |
| 157 ScrollBarThumb::~ScrollBarThumb() { | 167 ScrollBarThumb::~ScrollBarThumb() { |
| 158 } | 168 } |
| 159 | 169 |
| 160 gfx::Size ScrollBarThumb::GetPreferredSize() const { | 170 gfx::Size ScrollBarThumb::GetPreferredSize() const { |
| 161 return GetNativeTheme()->GetPartSize(GetNativeThemePart(), | 171 return GetNativeTheme()->GetPartSize(GetNativeThemePart(), |
| 162 GetNativeThemeState(), | 172 GetNativeThemeState(), |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 177 ui::NativeTheme::kScrollbarVerticalGripper; | 187 ui::NativeTheme::kScrollbarVerticalGripper; |
| 178 GetNativeTheme()->Paint(canvas->sk_canvas(), gripper_part, theme_state, | 188 GetNativeTheme()->Paint(canvas->sk_canvas(), gripper_part, theme_state, |
| 179 local_bounds, extra_params); | 189 local_bounds, extra_params); |
| 180 } | 190 } |
| 181 | 191 |
| 182 ui::NativeTheme::ExtraParams ScrollBarThumb::GetNativeThemeParams() const { | 192 ui::NativeTheme::ExtraParams ScrollBarThumb::GetNativeThemeParams() const { |
| 183 // This gives the behavior we want. | 193 // This gives the behavior we want. |
| 184 ui::NativeTheme::ExtraParams params; | 194 ui::NativeTheme::ExtraParams params; |
| 185 params.scrollbar_thumb.is_hovering = | 195 params.scrollbar_thumb.is_hovering = |
| 186 (GetState() != CustomButton::STATE_HOVERED); | 196 (GetState() != CustomButton::STATE_HOVERED); |
| 197 params.scrollbar_thumb.overlay = wrapper_->GetOverlayParams(); | |
|
tapted
2016/02/08 00:31:15
null check?
spqchan
2016/02/09 21:21:26
Acknowledged.
| |
| 187 return params; | 198 return params; |
| 188 } | 199 } |
| 189 | 200 |
| 190 ui::NativeTheme::Part ScrollBarThumb::GetNativeThemePart() const { | 201 ui::NativeTheme::Part ScrollBarThumb::GetNativeThemePart() const { |
| 191 if (scroll_bar_->IsHorizontal()) | 202 if (scroll_bar_->IsHorizontal()) |
| 192 return ui::NativeTheme::kScrollbarHorizontalThumb; | 203 return ui::NativeTheme::kScrollbarHorizontalThumb; |
| 193 return ui::NativeTheme::kScrollbarVerticalThumb; | 204 return ui::NativeTheme::kScrollbarVerticalThumb; |
| 194 } | 205 } |
| 195 | 206 |
| 196 ui::NativeTheme::State ScrollBarThumb::GetNativeThemeState() const { | 207 ui::NativeTheme::State ScrollBarThumb::GetNativeThemeState() const { |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 212 } | 223 } |
| 213 | 224 |
| 214 } // namespace | 225 } // namespace |
| 215 | 226 |
| 216 //////////////////////////////////////////////////////////////////////////////// | 227 //////////////////////////////////////////////////////////////////////////////// |
| 217 // NativeScrollBarViews, public: | 228 // NativeScrollBarViews, public: |
| 218 | 229 |
| 219 const char NativeScrollBarViews::kViewClassName[] = "NativeScrollBarViews"; | 230 const char NativeScrollBarViews::kViewClassName[] = "NativeScrollBarViews"; |
| 220 | 231 |
| 221 NativeScrollBarViews::NativeScrollBarViews(NativeScrollBar* scroll_bar) | 232 NativeScrollBarViews::NativeScrollBarViews(NativeScrollBar* scroll_bar) |
| 222 : BaseScrollBar(scroll_bar->IsHorizontal(), | 233 : BaseScrollBar(scroll_bar->IsHorizontal(), new ScrollBarThumb(this, this)), |
| 223 new ScrollBarThumb(this)), | |
| 224 native_scroll_bar_(scroll_bar) { | 234 native_scroll_bar_(scroll_bar) { |
| 225 set_controller(native_scroll_bar_->controller()); | 235 set_controller(native_scroll_bar_->controller()); |
| 226 | 236 |
| 227 if (native_scroll_bar_->IsHorizontal()) { | 237 if (native_scroll_bar_->IsHorizontal()) { |
| 228 prev_button_ = new ScrollBarButton(this, ScrollBarButton::LEFT); | 238 prev_button_ = new ScrollBarButton(this, ScrollBarButton::LEFT, this); |
| 229 next_button_ = new ScrollBarButton(this, ScrollBarButton::RIGHT); | 239 next_button_ = new ScrollBarButton(this, ScrollBarButton::RIGHT, this); |
| 230 | 240 |
| 231 part_ = ui::NativeTheme::kScrollbarHorizontalTrack; | 241 part_ = ui::NativeTheme::kScrollbarHorizontalTrack; |
| 232 } else { | 242 } else { |
| 233 prev_button_ = new ScrollBarButton(this, ScrollBarButton::UP); | 243 prev_button_ = new ScrollBarButton(this, ScrollBarButton::UP, this); |
| 234 next_button_ = new ScrollBarButton(this, ScrollBarButton::DOWN); | 244 next_button_ = new ScrollBarButton(this, ScrollBarButton::DOWN, this); |
| 235 | 245 |
| 236 part_ = ui::NativeTheme::kScrollbarVerticalTrack; | 246 part_ = ui::NativeTheme::kScrollbarVerticalTrack; |
| 237 } | 247 } |
| 238 | 248 |
| 239 state_ = ui::NativeTheme::kNormal; | 249 state_ = ui::NativeTheme::kNormal; |
| 240 | 250 |
| 241 AddChildView(prev_button_); | 251 AddChildView(prev_button_); |
| 242 AddChildView(next_button_); | 252 AddChildView(next_button_); |
| 243 | 253 |
| 244 prev_button_->set_context_menu_controller(this); | 254 prev_button_->set_context_menu_controller(this); |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 399 ui::NativeTheme::ExtraParams thumb_params; | 409 ui::NativeTheme::ExtraParams thumb_params; |
| 400 thumb_params.scrollbar_thumb.is_hovering = false; | 410 thumb_params.scrollbar_thumb.is_hovering = false; |
| 401 gfx::Size track_size = theme->GetPartSize( | 411 gfx::Size track_size = theme->GetPartSize( |
| 402 ui::NativeTheme::kScrollbarVerticalThumb, | 412 ui::NativeTheme::kScrollbarVerticalThumb, |
| 403 ui::NativeTheme::kNormal, | 413 ui::NativeTheme::kNormal, |
| 404 thumb_params); | 414 thumb_params); |
| 405 | 415 |
| 406 return std::max(track_size.width(), button_size.width()); | 416 return std::max(track_size.width(), button_size.width()); |
| 407 } | 417 } |
| 408 | 418 |
| 419 ui::NativeTheme::OverlayParams NativeScrollBarWrapper::GetOverlayParams() { | |
| 420 ui::NativeTheme::OverlayParams params; | |
| 421 params.is_overlay = false; | |
| 422 params.alpha = 1.0; | |
| 423 return params; | |
| 424 } | |
| 425 | |
| 409 } // namespace views | 426 } // namespace views |
| OLD | NEW |