| 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/scroll_view.h" | 5 #include "ui/views/controls/scroll_view.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "ui/base/events/event.h" | 8 #include "ui/base/events/event.h" |
| 9 #include "ui/native_theme/native_theme.h" | 9 #include "ui/native_theme/native_theme.h" |
| 10 #include "ui/views/border.h" | 10 #include "ui/views/border.h" |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 | 110 |
| 111 ScrollView::ScrollView() | 111 ScrollView::ScrollView() |
| 112 : contents_(NULL), | 112 : contents_(NULL), |
| 113 contents_viewport_(new Viewport()), | 113 contents_viewport_(new Viewport()), |
| 114 header_(NULL), | 114 header_(NULL), |
| 115 header_viewport_(new Viewport()), | 115 header_viewport_(new Viewport()), |
| 116 horiz_sb_(new NativeScrollBar(true)), | 116 horiz_sb_(new NativeScrollBar(true)), |
| 117 vert_sb_(new NativeScrollBar(false)), | 117 vert_sb_(new NativeScrollBar(false)), |
| 118 resize_corner_(NULL), | 118 resize_corner_(NULL), |
| 119 hide_horizontal_scrollbar_(false) { | 119 hide_horizontal_scrollbar_(false) { |
| 120 set_notify_enter_exit_on_child(true); |
| 121 |
| 120 AddChildView(contents_viewport_); | 122 AddChildView(contents_viewport_); |
| 121 AddChildView(header_viewport_); | 123 AddChildView(header_viewport_); |
| 122 | 124 |
| 123 // Don't add the scrollbars as children until we discover we need them | 125 // Don't add the scrollbars as children until we discover we need them |
| 124 // (ShowOrHideScrollBar). | 126 // (ShowOrHideScrollBar). |
| 125 horiz_sb_->SetVisible(false); | 127 horiz_sb_->SetVisible(false); |
| 126 horiz_sb_->set_controller(this); | 128 horiz_sb_->set_controller(this); |
| 127 vert_sb_->SetVisible(false); | 129 vert_sb_->SetVisible(false); |
| 128 vert_sb_->set_controller(this); | 130 vert_sb_->set_controller(this); |
| 129 if (resize_corner_) | 131 if (resize_corner_) |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 std::max(0, viewport_bounds.height() - horiz_sb_height)); | 247 std::max(0, viewport_bounds.height() - horiz_sb_height)); |
| 246 should_layout_contents = true; | 248 should_layout_contents = true; |
| 247 } | 249 } |
| 248 // Default. | 250 // Default. |
| 249 if (!vert_sb_required) { | 251 if (!vert_sb_required) { |
| 250 viewport_bounds.set_width(viewport_bounds.width() + vert_sb_width); | 252 viewport_bounds.set_width(viewport_bounds.width() + vert_sb_width); |
| 251 should_layout_contents = true; | 253 should_layout_contents = true; |
| 252 } | 254 } |
| 253 | 255 |
| 254 if (horiz_sb_required) { | 256 if (horiz_sb_required) { |
| 257 int horiz_sb_visible_height = horiz_sb_->GetVisibleSize(); |
| 258 int height_offset = horiz_sb_visible_height - horiz_sb_height; |
| 255 horiz_sb_->SetBounds(0, | 259 horiz_sb_->SetBounds(0, |
| 256 viewport_bounds.bottom(), | 260 viewport_bounds.bottom() - height_offset, |
| 257 viewport_bounds.right(), | 261 viewport_bounds.right(), |
| 258 horiz_sb_height); | 262 horiz_sb_visible_height); |
| 259 } | 263 } |
| 260 if (vert_sb_required) { | 264 if (vert_sb_required) { |
| 261 vert_sb_->SetBounds(viewport_bounds.right(), | 265 int vert_sb_visible_width = vert_sb_->GetVisibleSize(); |
| 266 int width_offset = vert_sb_visible_width - vert_sb_width; |
| 267 vert_sb_->SetBounds(viewport_bounds.right() - width_offset, |
| 262 0, | 268 0, |
| 263 vert_sb_width, | 269 vert_sb_visible_width, |
| 264 viewport_bounds.bottom()); | 270 viewport_bounds.bottom()); |
| 265 } | 271 } |
| 266 if (resize_corner_required) { | 272 if (resize_corner_required) { |
| 267 // Show the resize corner. | 273 // Show the resize corner. |
| 268 resize_corner_->SetBounds(viewport_bounds.right(), | 274 resize_corner_->SetBounds(viewport_bounds.right(), |
| 269 viewport_bounds.bottom(), | 275 viewport_bounds.bottom(), |
| 270 vert_sb_width, | 276 vert_sb_width, |
| 271 horiz_sb_height); | 277 horiz_sb_height); |
| 272 } | 278 } |
| 273 | 279 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 // Give vertical scrollbar priority | 311 // Give vertical scrollbar priority |
| 306 if (vert_sb_->visible()) | 312 if (vert_sb_->visible()) |
| 307 processed = vert_sb_->OnMouseWheel(e); | 313 processed = vert_sb_->OnMouseWheel(e); |
| 308 | 314 |
| 309 if (!processed && horiz_sb_->visible()) | 315 if (!processed && horiz_sb_->visible()) |
| 310 processed = horiz_sb_->OnMouseWheel(e); | 316 processed = horiz_sb_->OnMouseWheel(e); |
| 311 | 317 |
| 312 return processed; | 318 return processed; |
| 313 } | 319 } |
| 314 | 320 |
| 321 void ScrollView::OnMouseEntered(const ui::MouseEvent& event) { |
| 322 if (horiz_sb_) |
| 323 horiz_sb_->OnMouseEnteredScrollView(event); |
| 324 if (vert_sb_) |
| 325 vert_sb_->OnMouseEnteredScrollView(event); |
| 326 } |
| 327 |
| 328 void ScrollView::OnMouseExited(const ui::MouseEvent& event) { |
| 329 if (horiz_sb_) |
| 330 horiz_sb_->OnMouseExitedScrollView(event); |
| 331 if (vert_sb_) |
| 332 vert_sb_->OnMouseExitedScrollView(event); |
| 333 } |
| 334 |
| 315 void ScrollView::OnGestureEvent(ui::GestureEvent* event) { | 335 void ScrollView::OnGestureEvent(ui::GestureEvent* event) { |
| 316 // If the event happened on one of the scrollbars, then those events are | 336 // If the event happened on one of the scrollbars, then those events are |
| 317 // sent directly to the scrollbars. Otherwise, only scroll events are sent to | 337 // sent directly to the scrollbars. Otherwise, only scroll events are sent to |
| 318 // the scrollbars. | 338 // the scrollbars. |
| 319 bool scroll_event = event->type() == ui::ET_GESTURE_SCROLL_UPDATE || | 339 bool scroll_event = event->type() == ui::ET_GESTURE_SCROLL_UPDATE || |
| 320 event->type() == ui::ET_GESTURE_SCROLL_BEGIN || | 340 event->type() == ui::ET_GESTURE_SCROLL_BEGIN || |
| 321 event->type() == ui::ET_GESTURE_SCROLL_END || | 341 event->type() == ui::ET_GESTURE_SCROLL_END || |
| 322 event->type() == ui::ET_SCROLL_FLING_START; | 342 event->type() == ui::ET_SCROLL_FLING_START; |
| 323 | 343 |
| 324 if (vert_sb_->visible()) { | 344 if (vert_sb_->visible()) { |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 569 | 589 |
| 570 VariableRowHeightScrollHelper::RowInfo | 590 VariableRowHeightScrollHelper::RowInfo |
| 571 FixedRowHeightScrollHelper::GetRowInfo(int y) { | 591 FixedRowHeightScrollHelper::GetRowInfo(int y) { |
| 572 if (y < top_margin_) | 592 if (y < top_margin_) |
| 573 return RowInfo(0, top_margin_); | 593 return RowInfo(0, top_margin_); |
| 574 return RowInfo((y - top_margin_) / row_height_ * row_height_ + top_margin_, | 594 return RowInfo((y - top_margin_) / row_height_ * row_height_ + top_margin_, |
| 575 row_height_); | 595 row_height_); |
| 576 } | 596 } |
| 577 | 597 |
| 578 } // namespace views | 598 } // namespace views |
| OLD | NEW |