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/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" |
| 11 #include "ui/views/controls/button/custom_button.h" | 11 #include "ui/views/controls/button/custom_button.h" |
| 12 #include "ui/views/controls/focusable_border.h" | 12 #include "ui/views/controls/focusable_border.h" |
| 13 #include "ui/views/controls/scrollbar/base_scroll_bar_button.h" | 13 #include "ui/views/controls/scrollbar/base_scroll_bar_button.h" |
| 14 #include "ui/views/controls/scrollbar/base_scroll_bar_thumb.h" | 14 #include "ui/views/controls/scrollbar/base_scroll_bar_thumb.h" |
| 15 #include "ui/views/controls/scrollbar/native_scroll_bar.h" | |
| 16 #include "ui/views/controls/scrollbar/scroll_bar.h" | 15 #include "ui/views/controls/scrollbar/scroll_bar.h" |
| 17 | 16 |
| 18 namespace views { | 17 namespace views { |
| 19 | 18 |
| 20 namespace { | 19 namespace { |
| 21 | 20 |
| 22 // Wrapper for the scroll buttons. | 21 // Wrapper for the scroll buttons. |
| 23 class ScrollBarButton : public BaseScrollBarButton { | 22 class ScrollBarButton : public BaseScrollBarButton { |
| 24 public: | 23 public: |
| 25 enum Type { | 24 enum Type { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 63 ui::NativeTheme::Part GetNativeThemePart() const; | 62 ui::NativeTheme::Part GetNativeThemePart() const; |
| 64 ui::NativeTheme::State GetNativeThemeState() const; | 63 ui::NativeTheme::State GetNativeThemeState() const; |
| 65 | 64 |
| 66 ScrollBar* scroll_bar_; | 65 ScrollBar* scroll_bar_; |
| 67 }; | 66 }; |
| 68 | 67 |
| 69 ///////////////////////////////////////////////////////////////////////////// | 68 ///////////////////////////////////////////////////////////////////////////// |
| 70 // ScrollBarButton | 69 // ScrollBarButton |
| 71 | 70 |
| 72 ScrollBarButton::ScrollBarButton(ButtonListener* listener, Type type) | 71 ScrollBarButton::ScrollBarButton(ButtonListener* listener, Type type) |
| 73 : BaseScrollBarButton(listener), | 72 : BaseScrollBarButton(listener), type_(type) { |
| 74 type_(type) { | |
| 75 SetFocusBehavior(FocusBehavior::NEVER); | 73 SetFocusBehavior(FocusBehavior::NEVER); |
| 76 } | 74 } |
| 77 | 75 |
| 78 ScrollBarButton::~ScrollBarButton() { | 76 ScrollBarButton::~ScrollBarButton() {} |
| 79 } | |
| 80 | 77 |
| 81 gfx::Size ScrollBarButton::GetPreferredSize() const { | 78 gfx::Size ScrollBarButton::GetPreferredSize() const { |
| 82 return GetNativeTheme()->GetPartSize(GetNativeThemePart(), | 79 return GetNativeTheme()->GetPartSize( |
| 83 GetNativeThemeState(), | 80 GetNativeThemePart(), GetNativeThemeState(), GetNativeThemeParams()); |
| 84 GetNativeThemeParams()); | |
| 85 } | 81 } |
| 86 | 82 |
| 87 void ScrollBarButton::OnPaint(gfx::Canvas* canvas) { | 83 void ScrollBarButton::OnPaint(gfx::Canvas* canvas) { |
| 88 gfx::Rect bounds(GetPreferredSize()); | 84 gfx::Rect bounds(GetPreferredSize()); |
| 89 GetNativeTheme()->Paint(canvas->sk_canvas(), GetNativeThemePart(), | 85 GetNativeTheme()->Paint(canvas->sk_canvas(), GetNativeThemePart(), |
| 90 GetNativeThemeState(), bounds, | 86 GetNativeThemeState(), bounds, |
| 91 GetNativeThemeParams()); | 87 GetNativeThemeParams()); |
| 92 } | 88 } |
| 93 | 89 |
| 94 ui::NativeTheme::ExtraParams | 90 ui::NativeTheme::ExtraParams ScrollBarButton::GetNativeThemeParams() const { |
| 95 ScrollBarButton::GetNativeThemeParams() const { | |
| 96 ui::NativeTheme::ExtraParams params; | 91 ui::NativeTheme::ExtraParams params; |
| 97 | 92 |
| 98 switch (state()) { | 93 switch (state()) { |
| 99 case CustomButton::STATE_HOVERED: | 94 case CustomButton::STATE_HOVERED: |
| 100 params.scrollbar_arrow.is_hovering = true; | 95 params.scrollbar_arrow.is_hovering = true; |
| 101 break; | 96 break; |
| 102 default: | 97 default: |
| 103 params.scrollbar_arrow.is_hovering = false; | 98 params.scrollbar_arrow.is_hovering = false; |
| 104 break; | 99 break; |
| 105 } | 100 } |
| 106 | 101 |
| 107 return params; | 102 return params; |
| 108 } | 103 } |
| 109 | 104 |
| 110 ui::NativeTheme::Part | 105 ui::NativeTheme::Part ScrollBarButton::GetNativeThemePart() const { |
| 111 ScrollBarButton::GetNativeThemePart() const { | |
| 112 switch (type_) { | 106 switch (type_) { |
| 113 case UP: | 107 case UP: |
| 114 return ui::NativeTheme::kScrollbarUpArrow; | 108 return ui::NativeTheme::kScrollbarUpArrow; |
| 115 case DOWN: | 109 case DOWN: |
| 116 return ui::NativeTheme::kScrollbarDownArrow; | 110 return ui::NativeTheme::kScrollbarDownArrow; |
| 117 case LEFT: | 111 case LEFT: |
| 118 return ui::NativeTheme::kScrollbarLeftArrow; | 112 return ui::NativeTheme::kScrollbarLeftArrow; |
| 119 case RIGHT: | 113 case RIGHT: |
| 120 return ui::NativeTheme::kScrollbarRightArrow; | 114 return ui::NativeTheme::kScrollbarRightArrow; |
| 121 } | 115 } |
| 122 | 116 |
| 123 NOTREACHED(); | 117 NOTREACHED(); |
| 124 return ui::NativeTheme::kScrollbarUpArrow; | 118 return ui::NativeTheme::kScrollbarUpArrow; |
| 125 } | 119 } |
| 126 | 120 |
| 127 ui::NativeTheme::State | 121 ui::NativeTheme::State ScrollBarButton::GetNativeThemeState() const { |
| 128 ScrollBarButton::GetNativeThemeState() const { | |
| 129 switch (state()) { | 122 switch (state()) { |
| 130 case CustomButton::STATE_HOVERED: | 123 case CustomButton::STATE_HOVERED: |
| 131 return ui::NativeTheme::kHovered; | 124 return ui::NativeTheme::kHovered; |
| 132 case CustomButton::STATE_PRESSED: | 125 case CustomButton::STATE_PRESSED: |
| 133 return ui::NativeTheme::kPressed; | 126 return ui::NativeTheme::kPressed; |
| 134 case CustomButton::STATE_DISABLED: | 127 case CustomButton::STATE_DISABLED: |
| 135 return ui::NativeTheme::kDisabled; | 128 return ui::NativeTheme::kDisabled; |
| 136 case CustomButton::STATE_NORMAL: | 129 case CustomButton::STATE_NORMAL: |
| 137 return ui::NativeTheme::kNormal; | 130 return ui::NativeTheme::kNormal; |
| 138 case CustomButton::STATE_COUNT: | 131 case CustomButton::STATE_COUNT: |
| 139 break; | 132 break; |
| 140 } | 133 } |
| 141 | 134 |
| 142 NOTREACHED(); | 135 NOTREACHED(); |
| 143 return ui::NativeTheme::kNormal; | 136 return ui::NativeTheme::kNormal; |
| 144 } | 137 } |
| 145 | 138 |
| 146 ///////////////////////////////////////////////////////////////////////////// | 139 ///////////////////////////////////////////////////////////////////////////// |
| 147 // ScrollBarThumb | 140 // ScrollBarThumb |
| 148 | 141 |
| 149 ScrollBarThumb::ScrollBarThumb(BaseScrollBar* scroll_bar) | 142 ScrollBarThumb::ScrollBarThumb(BaseScrollBar* scroll_bar) |
| 150 : BaseScrollBarThumb(scroll_bar), | 143 : BaseScrollBarThumb(scroll_bar), scroll_bar_(scroll_bar) {} |
| 151 scroll_bar_(scroll_bar) { | |
| 152 } | |
| 153 | 144 |
| 154 ScrollBarThumb::~ScrollBarThumb() { | 145 ScrollBarThumb::~ScrollBarThumb() {} |
| 155 } | |
| 156 | 146 |
| 157 gfx::Size ScrollBarThumb::GetPreferredSize() const { | 147 gfx::Size ScrollBarThumb::GetPreferredSize() const { |
| 158 return GetNativeTheme()->GetPartSize(GetNativeThemePart(), | 148 return GetNativeTheme()->GetPartSize( |
| 159 GetNativeThemeState(), | 149 GetNativeThemePart(), GetNativeThemeState(), GetNativeThemeParams()); |
| 160 GetNativeThemeParams()); | |
| 161 } | 150 } |
| 162 | 151 |
| 163 void ScrollBarThumb::OnPaint(gfx::Canvas* canvas) { | 152 void ScrollBarThumb::OnPaint(gfx::Canvas* canvas) { |
| 164 const gfx::Rect local_bounds(GetLocalBounds()); | 153 const gfx::Rect local_bounds(GetLocalBounds()); |
| 165 const ui::NativeTheme::State theme_state = GetNativeThemeState(); | 154 const ui::NativeTheme::State theme_state = GetNativeThemeState(); |
| 166 const ui::NativeTheme::ExtraParams extra_params(GetNativeThemeParams()); | 155 const ui::NativeTheme::ExtraParams extra_params(GetNativeThemeParams()); |
| 167 GetNativeTheme()->Paint(canvas->sk_canvas(), | 156 GetNativeTheme()->Paint(canvas->sk_canvas(), GetNativeThemePart(), |
| 168 GetNativeThemePart(), | 157 theme_state, local_bounds, extra_params); |
| 169 theme_state, | 158 const ui::NativeTheme::Part gripper_part = |
| 170 local_bounds, | 159 scroll_bar_->IsHorizontal() ? ui::NativeTheme::kScrollbarHorizontalGripper |
| 171 extra_params); | 160 : ui::NativeTheme::kScrollbarVerticalGripper; |
| 172 const ui::NativeTheme::Part gripper_part = scroll_bar_->IsHorizontal() ? | |
| 173 ui::NativeTheme::kScrollbarHorizontalGripper : | |
| 174 ui::NativeTheme::kScrollbarVerticalGripper; | |
| 175 GetNativeTheme()->Paint(canvas->sk_canvas(), gripper_part, theme_state, | 161 GetNativeTheme()->Paint(canvas->sk_canvas(), gripper_part, theme_state, |
| 176 local_bounds, extra_params); | 162 local_bounds, extra_params); |
| 177 } | 163 } |
| 178 | 164 |
| 179 ui::NativeTheme::ExtraParams ScrollBarThumb::GetNativeThemeParams() const { | 165 ui::NativeTheme::ExtraParams ScrollBarThumb::GetNativeThemeParams() const { |
| 180 // This gives the behavior we want. | 166 // This gives the behavior we want. |
| 181 ui::NativeTheme::ExtraParams params; | 167 ui::NativeTheme::ExtraParams params; |
| 182 params.scrollbar_thumb.is_hovering = | 168 params.scrollbar_thumb.is_hovering = |
| 183 (GetState() != CustomButton::STATE_HOVERED); | 169 (GetState() != CustomButton::STATE_HOVERED); |
| 184 return params; | 170 return params; |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 204 break; | 190 break; |
| 205 } | 191 } |
| 206 | 192 |
| 207 NOTREACHED(); | 193 NOTREACHED(); |
| 208 return ui::NativeTheme::kNormal; | 194 return ui::NativeTheme::kNormal; |
| 209 } | 195 } |
| 210 | 196 |
| 211 } // namespace | 197 } // namespace |
| 212 | 198 |
| 213 //////////////////////////////////////////////////////////////////////////////// | 199 //////////////////////////////////////////////////////////////////////////////// |
| 214 // NativeScrollBarViews, public: | 200 // ScrollBarViews, public: |
| 215 | 201 |
| 216 const char NativeScrollBarViews::kViewClassName[] = "NativeScrollBarViews"; | 202 const char ScrollBarViews::kViewClassName[] = "ScrollBarViews"; |
| 217 | 203 |
| 218 NativeScrollBarViews::NativeScrollBarViews(NativeScrollBar* scroll_bar) | 204 ScrollBarViews::ScrollBarViews(bool horizontal) |
| 219 : BaseScrollBar(scroll_bar->IsHorizontal(), | 205 : BaseScrollBar(horizontal, new ScrollBarThumb(this)) { |
| 220 new ScrollBarThumb(this)), | 206 if (horizontal) { |
| 221 native_scroll_bar_(scroll_bar) { | |
| 222 set_controller(native_scroll_bar_->controller()); | |
| 223 | |
| 224 if (native_scroll_bar_->IsHorizontal()) { | |
| 225 prev_button_ = new ScrollBarButton(this, ScrollBarButton::LEFT); | 207 prev_button_ = new ScrollBarButton(this, ScrollBarButton::LEFT); |
| 226 next_button_ = new ScrollBarButton(this, ScrollBarButton::RIGHT); | 208 next_button_ = new ScrollBarButton(this, ScrollBarButton::RIGHT); |
| 227 | 209 |
| 228 part_ = ui::NativeTheme::kScrollbarHorizontalTrack; | 210 part_ = ui::NativeTheme::kScrollbarHorizontalTrack; |
| 229 } else { | 211 } else { |
| 230 prev_button_ = new ScrollBarButton(this, ScrollBarButton::UP); | 212 prev_button_ = new ScrollBarButton(this, ScrollBarButton::UP); |
| 231 next_button_ = new ScrollBarButton(this, ScrollBarButton::DOWN); | 213 next_button_ = new ScrollBarButton(this, ScrollBarButton::DOWN); |
| 232 | 214 |
| 233 part_ = ui::NativeTheme::kScrollbarVerticalTrack; | 215 part_ = ui::NativeTheme::kScrollbarVerticalTrack; |
| 234 } | 216 } |
| 235 | 217 |
| 236 state_ = ui::NativeTheme::kNormal; | 218 state_ = ui::NativeTheme::kNormal; |
| 237 | 219 |
| 238 AddChildView(prev_button_); | 220 AddChildView(prev_button_); |
| 239 AddChildView(next_button_); | 221 AddChildView(next_button_); |
| 240 | 222 |
| 241 prev_button_->set_context_menu_controller(this); | 223 prev_button_->set_context_menu_controller(this); |
| 242 next_button_->set_context_menu_controller(this); | 224 next_button_->set_context_menu_controller(this); |
| 243 } | 225 } |
| 244 | 226 |
| 245 NativeScrollBarViews::~NativeScrollBarViews() { | 227 ScrollBarViews::~ScrollBarViews() {} |
| 228 | |
| 229 // static | |
| 230 int ScrollBarViews::GetVerticalScrollBarWidth(const ui::NativeTheme* theme) { | |
| 231 ui::NativeTheme::ExtraParams button_params; | |
| 232 button_params.scrollbar_arrow.is_hovering = false; | |
| 233 gfx::Size button_size = | |
| 234 theme->GetPartSize(ui::NativeTheme::kScrollbarUpArrow, | |
| 235 ui::NativeTheme::kNormal, button_params); | |
| 236 | |
| 237 ui::NativeTheme::ExtraParams thumb_params; | |
| 238 thumb_params.scrollbar_thumb.is_hovering = false; | |
| 239 gfx::Size track_size = | |
| 240 theme->GetPartSize(ui::NativeTheme::kScrollbarVerticalThumb, | |
| 241 ui::NativeTheme::kNormal, thumb_params); | |
| 242 | |
| 243 return std::max(track_size.width(), button_size.width()); | |
| 246 } | 244 } |
| 247 | 245 |
| 248 //////////////////////////////////////////////////////////////////////////////// | 246 //////////////////////////////////////////////////////////////////////////////// |
| 249 // NativeScrollBarViews, View overrides: | 247 // ScrollBarViews, View overrides: |
| 250 | 248 |
| 251 void NativeScrollBarViews::Layout() { | 249 void ScrollBarViews::Layout() { |
| 252 gfx::Size size = prev_button_->GetPreferredSize(); | 250 gfx::Size size = prev_button_->GetPreferredSize(); |
| 253 prev_button_->SetBounds(0, 0, size.width(), size.height()); | 251 prev_button_->SetBounds(0, 0, size.width(), size.height()); |
| 254 | 252 |
| 255 if (native_scroll_bar_->IsHorizontal()) { | 253 if (IsHorizontal()) { |
| 256 next_button_->SetBounds(width() - size.width(), 0, | 254 next_button_->SetBounds(width() - size.width(), 0, size.width(), |
| 257 size.width(), size.height()); | 255 size.height()); |
| 258 } else { | 256 } else { |
| 259 next_button_->SetBounds(0, height() - size.height(), | 257 next_button_->SetBounds(0, height() - size.height(), size.width(), |
| 260 size.width(), size.height()); | 258 size.height()); |
| 261 } | 259 } |
| 262 | 260 |
| 263 GetThumb()->SetBoundsRect(GetTrackBounds()); | 261 GetThumb()->SetBoundsRect(GetTrackBounds()); |
| 264 } | 262 } |
| 265 | 263 |
| 266 void NativeScrollBarViews::OnPaint(gfx::Canvas* canvas) { | 264 void ScrollBarViews::OnPaint(gfx::Canvas* canvas) { |
| 267 gfx::Rect bounds = GetTrackBounds(); | 265 gfx::Rect bounds = GetTrackBounds(); |
| 268 | 266 |
| 269 if (bounds.IsEmpty()) | 267 if (bounds.IsEmpty()) |
| 270 return; | 268 return; |
| 271 | 269 |
| 272 params_.scrollbar_track.track_x = bounds.x(); | 270 params_.scrollbar_track.track_x = bounds.x(); |
| 273 params_.scrollbar_track.track_y = bounds.y(); | 271 params_.scrollbar_track.track_y = bounds.y(); |
| 274 params_.scrollbar_track.track_width = bounds.width(); | 272 params_.scrollbar_track.track_width = bounds.width(); |
| 275 params_.scrollbar_track.track_height = bounds.height(); | 273 params_.scrollbar_track.track_height = bounds.height(); |
| 276 params_.scrollbar_track.classic_state = 0; | 274 params_.scrollbar_track.classic_state = 0; |
| 277 | 275 |
| 278 GetNativeTheme()->Paint(canvas->sk_canvas(), part_, state_, bounds, params_); | 276 GetNativeTheme()->Paint(canvas->sk_canvas(), part_, state_, bounds, params_); |
| 279 } | 277 } |
| 280 | 278 |
| 281 gfx::Size NativeScrollBarViews::GetPreferredSize() const { | 279 gfx::Size ScrollBarViews::GetPreferredSize() const { |
| 282 const ui::NativeTheme* theme = native_scroll_bar_->GetNativeTheme(); | 280 return gfx::Size(IsHorizontal() ? 0 : GetLayoutSize(), |
| 283 if (native_scroll_bar_->IsHorizontal()) | 281 IsHorizontal() ? GetLayoutSize() : 0); |
| 284 return gfx::Size(0, GetHorizontalScrollBarHeight(theme)); | |
| 285 return gfx::Size(GetVerticalScrollBarWidth(theme), 0); | |
| 286 } | 282 } |
| 287 | 283 |
| 288 const char* NativeScrollBarViews::GetClassName() const { | 284 const char* ScrollBarViews::GetClassName() const { |
| 289 return kViewClassName; | 285 return kViewClassName; |
| 290 } | 286 } |
| 291 | 287 |
| 292 int NativeScrollBarViews::GetLayoutSize() const { | 288 int ScrollBarViews::GetLayoutSize() const { |
| 293 gfx::Size size = prev_button_->GetPreferredSize(); | 289 const ui::NativeTheme* theme = GetNativeTheme(); |
| 294 return IsHorizontal() ? size.height() : size.width(); | 290 if (IsHorizontal()) { |
|
sky
2016/11/07 16:22:55
optional: for consistency move the horizontal bran
Evan Stade
2016/11/07 17:10:00
done
| |
| 295 } | 291 ui::NativeTheme::ExtraParams button_params; |
| 292 button_params.scrollbar_arrow.is_hovering = false; | |
| 293 gfx::Size button_size = | |
| 294 theme->GetPartSize(ui::NativeTheme::kScrollbarLeftArrow, | |
| 295 ui::NativeTheme::kNormal, button_params); | |
| 296 | 296 |
| 297 void NativeScrollBarViews::ScrollToPosition(int position) { | 297 ui::NativeTheme::ExtraParams thumb_params; |
| 298 controller()->ScrollToPosition(native_scroll_bar_, position); | 298 thumb_params.scrollbar_thumb.is_hovering = false; |
| 299 } | 299 gfx::Size track_size = |
| 300 theme->GetPartSize(ui::NativeTheme::kScrollbarHorizontalThumb, | |
| 301 ui::NativeTheme::kNormal, thumb_params); | |
| 300 | 302 |
| 301 int NativeScrollBarViews::GetScrollIncrement(bool is_page, bool is_positive) { | 303 return std::max(track_size.height(), button_size.height()); |
| 302 return controller()->GetScrollIncrement(native_scroll_bar_, | 304 } |
| 303 is_page, | 305 |
| 304 is_positive); | 306 return GetVerticalScrollBarWidth(theme); |
| 305 } | 307 } |
| 306 | 308 |
| 307 ////////////////////////////////////////////////////////////////////////////// | 309 ////////////////////////////////////////////////////////////////////////////// |
| 308 // BaseButton::ButtonListener overrides: | 310 // BaseButton::ButtonListener overrides: |
| 309 | 311 |
| 310 void NativeScrollBarViews::ButtonPressed(Button* sender, | 312 void ScrollBarViews::ButtonPressed(Button* sender, const ui::Event& event) { |
| 311 const ui::Event& event) { | |
| 312 if (sender == prev_button_) { | 313 if (sender == prev_button_) { |
| 313 ScrollByAmount(SCROLL_PREV_LINE); | 314 ScrollByAmount(SCROLL_PREV_LINE); |
| 314 } else if (sender == next_button_) { | 315 } else if (sender == next_button_) { |
| 315 ScrollByAmount(SCROLL_NEXT_LINE); | 316 ScrollByAmount(SCROLL_NEXT_LINE); |
| 316 } | 317 } |
| 317 } | 318 } |
| 318 | 319 |
| 319 //////////////////////////////////////////////////////////////////////////////// | 320 //////////////////////////////////////////////////////////////////////////////// |
| 320 // NativeScrollBarViews, NativeScrollBarWrapper overrides: | 321 // ScrollBarViews, private: |
| 321 | 322 |
| 322 int NativeScrollBarViews::GetPosition() const { | 323 gfx::Rect ScrollBarViews::GetTrackBounds() const { |
| 323 return BaseScrollBar::GetPosition(); | |
| 324 } | |
| 325 | |
| 326 View* NativeScrollBarViews::GetView() { | |
| 327 return this; | |
| 328 } | |
| 329 | |
| 330 void NativeScrollBarViews::Update(int viewport_size, | |
| 331 int content_size, | |
| 332 int current_pos) { | |
| 333 BaseScrollBar::Update(viewport_size, content_size, current_pos); | |
| 334 } | |
| 335 | |
| 336 //////////////////////////////////////////////////////////////////////////////// | |
| 337 // NativeScrollBarViews, private: | |
| 338 | |
| 339 gfx::Rect NativeScrollBarViews::GetTrackBounds() const { | |
| 340 gfx::Rect bounds = GetLocalBounds(); | 324 gfx::Rect bounds = GetLocalBounds(); |
| 341 gfx::Size size = prev_button_->GetPreferredSize(); | 325 gfx::Size size = prev_button_->GetPreferredSize(); |
| 342 BaseScrollBarThumb* thumb = GetThumb(); | 326 BaseScrollBarThumb* thumb = GetThumb(); |
| 343 | 327 |
| 344 if (native_scroll_bar_->IsHorizontal()) { | 328 if (IsHorizontal()) { |
| 345 bounds.set_x(bounds.x() + size.width()); | 329 bounds.set_x(bounds.x() + size.width()); |
| 346 bounds.set_width(std::max(0, bounds.width() - 2 * size.width())); | 330 bounds.set_width(std::max(0, bounds.width() - 2 * size.width())); |
| 347 bounds.set_height(thumb->GetPreferredSize().height()); | 331 bounds.set_height(thumb->GetPreferredSize().height()); |
| 348 } else { | 332 } else { |
| 349 bounds.set_y(bounds.y() + size.height()); | 333 bounds.set_y(bounds.y() + size.height()); |
| 350 bounds.set_height(std::max(0, bounds.height() - 2 * size.height())); | 334 bounds.set_height(std::max(0, bounds.height() - 2 * size.height())); |
| 351 bounds.set_width(thumb->GetPreferredSize().width()); | 335 bounds.set_width(thumb->GetPreferredSize().width()); |
| 352 } | 336 } |
| 353 | 337 |
| 354 return bounds; | 338 return bounds; |
| 355 } | 339 } |
| 356 | 340 |
| 357 //////////////////////////////////////////////////////////////////////////////// | |
| 358 // NativewScrollBarWrapper, public: | |
| 359 | |
| 360 // static | |
| 361 NativeScrollBarWrapper* NativeScrollBarWrapper::CreateWrapper( | |
| 362 NativeScrollBar* scroll_bar) { | |
| 363 return new NativeScrollBarViews(scroll_bar); | |
| 364 } | |
| 365 | |
| 366 // static | |
| 367 int NativeScrollBarWrapper::GetHorizontalScrollBarHeight( | |
| 368 const ui::NativeTheme* theme) { | |
| 369 ui::NativeTheme::ExtraParams button_params; | |
| 370 button_params.scrollbar_arrow.is_hovering = false; | |
| 371 gfx::Size button_size = theme->GetPartSize( | |
| 372 ui::NativeTheme::kScrollbarLeftArrow, | |
| 373 ui::NativeTheme::kNormal, | |
| 374 button_params); | |
| 375 | |
| 376 ui::NativeTheme::ExtraParams thumb_params; | |
| 377 thumb_params.scrollbar_thumb.is_hovering = false; | |
| 378 gfx::Size track_size = theme->GetPartSize( | |
| 379 ui::NativeTheme::kScrollbarHorizontalThumb, | |
| 380 ui::NativeTheme::kNormal, | |
| 381 thumb_params); | |
| 382 | |
| 383 return std::max(track_size.height(), button_size.height()); | |
| 384 } | |
| 385 | |
| 386 // static | |
| 387 int NativeScrollBarWrapper::GetVerticalScrollBarWidth( | |
| 388 const ui::NativeTheme* theme) { | |
| 389 ui::NativeTheme::ExtraParams button_params; | |
| 390 button_params.scrollbar_arrow.is_hovering = false; | |
| 391 gfx::Size button_size = theme->GetPartSize( | |
| 392 ui::NativeTheme::kScrollbarUpArrow, | |
| 393 ui::NativeTheme::kNormal, | |
| 394 button_params); | |
| 395 | |
| 396 ui::NativeTheme::ExtraParams thumb_params; | |
| 397 thumb_params.scrollbar_thumb.is_hovering = false; | |
| 398 gfx::Size track_size = theme->GetPartSize( | |
| 399 ui::NativeTheme::kScrollbarVerticalThumb, | |
| 400 ui::NativeTheme::kNormal, | |
| 401 thumb_params); | |
| 402 | |
| 403 return std::max(track_size.width(), button_size.width()); | |
| 404 } | |
| 405 | |
| 406 } // namespace views | 341 } // namespace views |
| OLD | NEW |