Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(315)

Side by Side Diff: ui/views/controls/scrollbar/base_scroll_bar_thumb.cc

Issue 10832282: Replace views::MouseEvent with ui::MouseEvent (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/base_scroll_bar_thumb.h" 5 #include "ui/views/controls/scrollbar/base_scroll_bar_thumb.h"
6 6
7 #include "ui/gfx/canvas.h" 7 #include "ui/gfx/canvas.h"
8 #include "ui/gfx/rect.h" 8 #include "ui/gfx/rect.h"
9 #include "ui/views/controls/scrollbar/base_scroll_bar.h" 9 #include "ui/views/controls/scrollbar/base_scroll_bar.h"
10 10
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 SetBoundsRect(thumb_bounds); 58 SetBoundsRect(thumb_bounds);
59 } 59 }
60 60
61 int BaseScrollBarThumb::GetPosition() const { 61 int BaseScrollBarThumb::GetPosition() const {
62 gfx::Rect track_bounds = scroll_bar_->GetTrackBounds(); 62 gfx::Rect track_bounds = scroll_bar_->GetTrackBounds();
63 if (scroll_bar_->IsHorizontal()) 63 if (scroll_bar_->IsHorizontal())
64 return x() - track_bounds.x(); 64 return x() - track_bounds.x();
65 return y() - track_bounds.y(); 65 return y() - track_bounds.y();
66 } 66 }
67 67
68 void BaseScrollBarThumb::OnMouseEntered(const MouseEvent& event) { 68 void BaseScrollBarThumb::OnMouseEntered(const ui::MouseEvent& event) {
69 SetState(CustomButton::BS_HOT); 69 SetState(CustomButton::BS_HOT);
70 } 70 }
71 71
72 void BaseScrollBarThumb::OnMouseExited(const MouseEvent& event) { 72 void BaseScrollBarThumb::OnMouseExited(const ui::MouseEvent& event) {
73 SetState(CustomButton::BS_NORMAL); 73 SetState(CustomButton::BS_NORMAL);
74 } 74 }
75 75
76 bool BaseScrollBarThumb::OnMousePressed(const MouseEvent& event) { 76 bool BaseScrollBarThumb::OnMousePressed(const ui::MouseEvent& event) {
77 mouse_offset_ = scroll_bar_->IsHorizontal() ? event.x() : event.y(); 77 mouse_offset_ = scroll_bar_->IsHorizontal() ? event.x() : event.y();
78 drag_start_position_ = GetPosition(); 78 drag_start_position_ = GetPosition();
79 SetState(CustomButton::BS_PUSHED); 79 SetState(CustomButton::BS_PUSHED);
80 return true; 80 return true;
81 } 81 }
82 82
83 bool BaseScrollBarThumb::OnMouseDragged(const MouseEvent& event) { 83 bool BaseScrollBarThumb::OnMouseDragged(const ui::MouseEvent& event) {
84 // If the user moves the mouse more than |kScrollThumbDragOutSnap| outside 84 // If the user moves the mouse more than |kScrollThumbDragOutSnap| outside
85 // the bounds of the thumb, the scrollbar will snap the scroll back to the 85 // the bounds of the thumb, the scrollbar will snap the scroll back to the
86 // point it was at before the drag began. 86 // point it was at before the drag began.
87 if (scroll_bar_->IsHorizontal()) { 87 if (scroll_bar_->IsHorizontal()) {
88 if ((event.y() < y() - kScrollThumbDragOutSnap) || 88 if ((event.y() < y() - kScrollThumbDragOutSnap) ||
89 (event.y() > (y() + height() + kScrollThumbDragOutSnap))) { 89 (event.y() > (y() + height() + kScrollThumbDragOutSnap))) {
90 scroll_bar_->ScrollToThumbPosition(drag_start_position_, false); 90 scroll_bar_->ScrollToThumbPosition(drag_start_position_, false);
91 return true; 91 return true;
92 } 92 }
93 } else { 93 } else {
94 if ((event.x() < x() - kScrollThumbDragOutSnap) || 94 if ((event.x() < x() - kScrollThumbDragOutSnap) ||
95 (event.x() > (x() + width() + kScrollThumbDragOutSnap))) { 95 (event.x() > (x() + width() + kScrollThumbDragOutSnap))) {
96 scroll_bar_->ScrollToThumbPosition(drag_start_position_, false); 96 scroll_bar_->ScrollToThumbPosition(drag_start_position_, false);
97 return true; 97 return true;
98 } 98 }
99 } 99 }
100 if (scroll_bar_->IsHorizontal()) { 100 if (scroll_bar_->IsHorizontal()) {
101 int thumb_x = event.x() - mouse_offset_; 101 int thumb_x = event.x() - mouse_offset_;
102 scroll_bar_->ScrollToThumbPosition(GetPosition() + thumb_x, false); 102 scroll_bar_->ScrollToThumbPosition(GetPosition() + thumb_x, false);
103 } else { 103 } else {
104 int thumb_y = event.y() - mouse_offset_; 104 int thumb_y = event.y() - mouse_offset_;
105 scroll_bar_->ScrollToThumbPosition(GetPosition() + thumb_y, false); 105 scroll_bar_->ScrollToThumbPosition(GetPosition() + thumb_y, false);
106 } 106 }
107 return true; 107 return true;
108 } 108 }
109 109
110 void BaseScrollBarThumb::OnMouseReleased(const MouseEvent& event) { 110 void BaseScrollBarThumb::OnMouseReleased(const ui::MouseEvent& event) {
111 OnMouseCaptureLost(); 111 OnMouseCaptureLost();
112 } 112 }
113 113
114 void BaseScrollBarThumb::OnMouseCaptureLost() { 114 void BaseScrollBarThumb::OnMouseCaptureLost() {
115 SetState(CustomButton::BS_HOT); 115 SetState(CustomButton::BS_HOT);
116 } 116 }
117 117
118 CustomButton::ButtonState BaseScrollBarThumb::GetState() const { 118 CustomButton::ButtonState BaseScrollBarThumb::GetState() const {
119 return state_; 119 return state_;
120 } 120 }
121 121
122 void BaseScrollBarThumb::SetState(CustomButton::ButtonState state) { 122 void BaseScrollBarThumb::SetState(CustomButton::ButtonState state) {
123 state_ = state; 123 state_ = state;
124 SchedulePaint(); 124 SchedulePaint();
125 } 125 }
126 126
127 } // namespace views 127 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/scrollbar/base_scroll_bar_thumb.h ('k') | ui/views/controls/scrollbar/bitmap_scroll_bar.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698