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

Side by Side Diff: views/controls/scrollbar/bitmap_scroll_bar.cc

Issue 6685069: Disambiguate OnMouseCaptureLost from OnMouseReleased, etc. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments, fix tests, cleanup, etc. Created 9 years, 9 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
« no previous file with comments | « views/controls/scrollbar/bitmap_scroll_bar.h ('k') | views/controls/single_split_view.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "views/controls/scrollbar/bitmap_scroll_bar.h" 5 #include "views/controls/scrollbar/bitmap_scroll_bar.h"
6 6
7 #if defined(OS_LINUX) 7 #if defined(OS_LINUX)
8 #include "views/screen.h" 8 #include "views/screen.h"
9 #endif 9 #endif
10 10
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 public: 47 public:
48 AutorepeatButton(ButtonListener* listener) 48 AutorepeatButton(ButtonListener* listener)
49 : ImageButton(listener), 49 : ImageButton(listener),
50 ALLOW_THIS_IN_INITIALIZER_LIST(repeater_( 50 ALLOW_THIS_IN_INITIALIZER_LIST(repeater_(
51 NewCallback<AutorepeatButton>(this, 51 NewCallback<AutorepeatButton>(this,
52 &AutorepeatButton::NotifyClick))) { 52 &AutorepeatButton::NotifyClick))) {
53 } 53 }
54 virtual ~AutorepeatButton() {} 54 virtual ~AutorepeatButton() {}
55 55
56 protected: 56 protected:
57 virtual bool OnMousePressed(const MouseEvent& event) { 57 virtual bool OnMousePressed(const MouseEvent& event) OVERRIDE {
58 Button::NotifyClick(event); 58 Button::NotifyClick(event);
59 repeater_.Start(); 59 repeater_.Start();
60 return true; 60 return true;
61 } 61 }
62 62
63 virtual void OnMouseReleased(const MouseEvent& event, bool canceled) { 63 virtual void OnMouseReleased(const MouseEvent& event) OVERRIDE {
64 OnMouseCaptureLost();
65 }
66
67 virtual void OnMouseCaptureLost() OVERRIDE {
64 repeater_.Stop(); 68 repeater_.Stop();
65 View::OnMouseReleased(event, canceled);
66 } 69 }
67 70
68 private: 71 private:
69 void NotifyClick() { 72 void NotifyClick() {
70 #if defined(OS_WIN) 73 #if defined(OS_WIN)
71 DWORD pos = GetMessagePos(); 74 DWORD pos = GetMessagePos();
72 POINTS points = MAKEPOINTS(pos); 75 POINTS points = MAKEPOINTS(pos);
73 gfx::Point cursor_point(points.x, points.y); 76 gfx::Point cursor_point(points.x, points.y);
74 #elif defined(OS_LINUX) 77 #elif defined(OS_LINUX)
75 gfx::Point cursor_point = Screen::GetCursorScreenPoint(); 78 gfx::Point cursor_point = Screen::GetCursorScreenPoint();
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 145
143 // Gets the position of the thumb on the x or y axis. 146 // Gets the position of the thumb on the x or y axis.
144 int GetPosition() const { 147 int GetPosition() const {
145 gfx::Rect track_bounds = scroll_bar_->GetTrackBounds(); 148 gfx::Rect track_bounds = scroll_bar_->GetTrackBounds();
146 if (scroll_bar_->IsHorizontal()) 149 if (scroll_bar_->IsHorizontal())
147 return x() - track_bounds.x(); 150 return x() - track_bounds.x();
148 return y() - track_bounds.y(); 151 return y() - track_bounds.y();
149 } 152 }
150 153
151 // View overrides: 154 // View overrides:
152 virtual gfx::Size GetPreferredSize() { 155 virtual gfx::Size GetPreferredSize() OVERRIDE {
153 return gfx::Size(background_bitmap()->width(), 156 return gfx::Size(background_bitmap()->width(),
154 start_cap_bitmap()->height() + 157 start_cap_bitmap()->height() +
155 end_cap_bitmap()->height() + 158 end_cap_bitmap()->height() +
156 grippy_bitmap()->height()); 159 grippy_bitmap()->height());
157 } 160 }
158 161
159 protected: 162 protected:
160 // View overrides: 163 // View overrides:
161 virtual void Paint(gfx::Canvas* canvas) { 164 virtual void Paint(gfx::Canvas* canvas) OVERRIDE {
162 canvas->DrawBitmapInt(*start_cap_bitmap(), 0, 0); 165 canvas->DrawBitmapInt(*start_cap_bitmap(), 0, 0);
163 int top_cap_height = start_cap_bitmap()->height(); 166 int top_cap_height = start_cap_bitmap()->height();
164 int bottom_cap_height = end_cap_bitmap()->height(); 167 int bottom_cap_height = end_cap_bitmap()->height();
165 int thumb_body_height = height() - top_cap_height - bottom_cap_height; 168 int thumb_body_height = height() - top_cap_height - bottom_cap_height;
166 canvas->TileImageInt(*background_bitmap(), 0, top_cap_height, 169 canvas->TileImageInt(*background_bitmap(), 0, top_cap_height,
167 background_bitmap()->width(), thumb_body_height); 170 background_bitmap()->width(), thumb_body_height);
168 canvas->DrawBitmapInt(*end_cap_bitmap(), 0, 171 canvas->DrawBitmapInt(*end_cap_bitmap(), 0,
169 height() - bottom_cap_height); 172 height() - bottom_cap_height);
170 173
171 // Paint the grippy over the track. 174 // Paint the grippy over the track.
172 int grippy_x = (width() - grippy_bitmap()->width()) / 2; 175 int grippy_x = (width() - grippy_bitmap()->width()) / 2;
173 int grippy_y = (thumb_body_height - grippy_bitmap()->height()) / 2; 176 int grippy_y = (thumb_body_height - grippy_bitmap()->height()) / 2;
174 canvas->DrawBitmapInt(*grippy_bitmap(), grippy_x, grippy_y); 177 canvas->DrawBitmapInt(*grippy_bitmap(), grippy_x, grippy_y);
175 } 178 }
176 179
177 virtual void OnMouseEntered(const MouseEvent& event) { 180 virtual void OnMouseEntered(const MouseEvent& event) OVERRIDE {
178 SetState(CustomButton::BS_HOT); 181 SetState(CustomButton::BS_HOT);
179 } 182 }
180 183
181 virtual void OnMouseExited(const MouseEvent& event) { 184 virtual void OnMouseExited(const MouseEvent& event) OVERRIDE {
182 SetState(CustomButton::BS_NORMAL); 185 SetState(CustomButton::BS_NORMAL);
183 } 186 }
184 187
185 virtual bool OnMousePressed(const MouseEvent& event) { 188 virtual bool OnMousePressed(const MouseEvent& event) OVERRIDE {
186 mouse_offset_ = scroll_bar_->IsHorizontal() ? event.x() : event.y(); 189 mouse_offset_ = scroll_bar_->IsHorizontal() ? event.x() : event.y();
187 drag_start_position_ = GetPosition(); 190 drag_start_position_ = GetPosition();
188 SetState(CustomButton::BS_PUSHED); 191 SetState(CustomButton::BS_PUSHED);
189 return true; 192 return true;
190 } 193 }
191 194
192 virtual bool OnMouseDragged(const MouseEvent& event) { 195 virtual bool OnMouseDragged(const MouseEvent& event) OVERRIDE {
193 // If the user moves the mouse more than |kScrollThumbDragOutSnap| outside 196 // If the user moves the mouse more than |kScrollThumbDragOutSnap| outside
194 // the bounds of the thumb, the scrollbar will snap the scroll back to the 197 // the bounds of the thumb, the scrollbar will snap the scroll back to the
195 // point it was at before the drag began. 198 // point it was at before the drag began.
196 if (scroll_bar_->IsHorizontal()) { 199 if (scroll_bar_->IsHorizontal()) {
197 if ((event.y() < y() - kScrollThumbDragOutSnap) || 200 if ((event.y() < y() - kScrollThumbDragOutSnap) ||
198 (event.y() > (y() + height() + kScrollThumbDragOutSnap))) { 201 (event.y() > (y() + height() + kScrollThumbDragOutSnap))) {
199 scroll_bar_->ScrollToThumbPosition(drag_start_position_, false); 202 scroll_bar_->ScrollToThumbPosition(drag_start_position_, false);
200 return true; 203 return true;
201 } 204 }
202 } else { 205 } else {
203 if ((event.x() < x() - kScrollThumbDragOutSnap) || 206 if ((event.x() < x() - kScrollThumbDragOutSnap) ||
204 (event.x() > (x() + width() + kScrollThumbDragOutSnap))) { 207 (event.x() > (x() + width() + kScrollThumbDragOutSnap))) {
205 scroll_bar_->ScrollToThumbPosition(drag_start_position_, false); 208 scroll_bar_->ScrollToThumbPosition(drag_start_position_, false);
206 return true; 209 return true;
207 } 210 }
208 } 211 }
209 if (scroll_bar_->IsHorizontal()) { 212 if (scroll_bar_->IsHorizontal()) {
210 int thumb_x = event.x() - mouse_offset_; 213 int thumb_x = event.x() - mouse_offset_;
211 scroll_bar_->ScrollToThumbPosition(x() + thumb_x, false); 214 scroll_bar_->ScrollToThumbPosition(x() + thumb_x, false);
212 } else { 215 } else {
213 int thumb_y = event.y() - mouse_offset_; 216 int thumb_y = event.y() - mouse_offset_;
214 scroll_bar_->ScrollToThumbPosition(y() + thumb_y, false); 217 scroll_bar_->ScrollToThumbPosition(y() + thumb_y, false);
215 } 218 }
216 return true; 219 return true;
217 } 220 }
218 221
219 virtual void OnMouseReleased(const MouseEvent& event, 222 virtual void OnMouseReleased(const MouseEvent& event) OVERRIDE {
220 bool canceled) { 223 OnMouseCaptureLost();
224 }
225
226 virtual void OnMouseCaptureLost() OVERRIDE {
221 SetState(CustomButton::BS_HOT); 227 SetState(CustomButton::BS_HOT);
222 View::OnMouseReleased(event, canceled);
223 } 228 }
224 229
225 private: 230 private:
226 // Returns the bitmap rendered at the start of the thumb. 231 // Returns the bitmap rendered at the start of the thumb.
227 SkBitmap* start_cap_bitmap() const { 232 SkBitmap* start_cap_bitmap() const {
228 return scroll_bar_->images_[BitmapScrollBar::THUMB_START_CAP][state_]; 233 return scroll_bar_->images_[BitmapScrollBar::THUMB_START_CAP][state_];
229 } 234 }
230 235
231 // Returns the bitmap rendered at the end of the thumb. 236 // Returns the bitmap rendered at the end of the thumb.
232 SkBitmap* end_cap_bitmap() const { 237 SkBitmap* end_cap_bitmap() const {
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 } else if (event.y() > thumb_bounds.bottom()) { 469 } else if (event.y() > thumb_bounds.bottom()) {
465 last_scroll_amount_ = SCROLL_NEXT_PAGE; 470 last_scroll_amount_ = SCROLL_NEXT_PAGE;
466 } 471 }
467 } 472 }
468 TrackClicked(); 473 TrackClicked();
469 repeater_.Start(); 474 repeater_.Start();
470 } 475 }
471 return true; 476 return true;
472 } 477 }
473 478
474 void BitmapScrollBar::OnMouseReleased(const MouseEvent& event, bool canceled) { 479 void BitmapScrollBar::OnMouseReleased(const MouseEvent& event) {
480 OnMouseCaptureLost();
481 }
482
483 void BitmapScrollBar::OnMouseCaptureLost() {
475 SetThumbTrackState(CustomButton::BS_NORMAL); 484 SetThumbTrackState(CustomButton::BS_NORMAL);
476 repeater_.Stop(); 485 repeater_.Stop();
477 View::OnMouseReleased(event, canceled);
478 } 486 }
479 487
480 bool BitmapScrollBar::OnKeyPressed(const KeyEvent& event) { 488 bool BitmapScrollBar::OnKeyPressed(const KeyEvent& event) {
481 ScrollAmount amount = SCROLL_NONE; 489 ScrollAmount amount = SCROLL_NONE;
482 switch (event.key_code()) { 490 switch (event.key_code()) {
483 case ui::VKEY_UP: 491 case ui::VKEY_UP:
484 if (!IsHorizontal()) 492 if (!IsHorizontal())
485 amount = SCROLL_PREV_LINE; 493 amount = SCROLL_PREV_LINE;
486 break; 494 break;
487 case ui::VKEY_DOWN: 495 case ui::VKEY_DOWN:
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
719 thumb_position = thumb_position - (thumb_->GetSize() / 2); 727 thumb_position = thumb_position - (thumb_->GetSize() / 2);
720 return (thumb_position * contents_size_) / GetTrackSize(); 728 return (thumb_position * contents_size_) / GetTrackSize();
721 } 729 }
722 730
723 void BitmapScrollBar::SetThumbTrackState(CustomButton::ButtonState state) { 731 void BitmapScrollBar::SetThumbTrackState(CustomButton::ButtonState state) {
724 thumb_track_state_ = state; 732 thumb_track_state_ = state;
725 SchedulePaint(); 733 SchedulePaint();
726 } 734 }
727 735
728 } // namespace views 736 } // namespace views
OLDNEW
« no previous file with comments | « views/controls/scrollbar/bitmap_scroll_bar.h ('k') | views/controls/single_split_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698