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

Side by Side Diff: ui/views/controls/resize_area.cc

Issue 2796303006: Add gesture support in views::ResizeArea (Closed)
Patch Set: skip OSX Created 3 years, 8 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
« no previous file with comments | « ui/views/controls/resize_area.h ('k') | ui/views/controls/resize_area_delegate.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) 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/resize_area.h" 5 #include "ui/views/controls/resize_area.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "ui/accessibility/ax_node_data.h" 8 #include "ui/accessibility/ax_node_data.h"
9 #include "ui/base/cursor/cursor.h" 9 #include "ui/base/cursor/cursor.h"
10 #include "ui/views/controls/resize_area_delegate.h" 10 #include "ui/views/controls/resize_area_delegate.h"
11 #include "ui/views/native_cursor.h" 11 #include "ui/views/native_cursor.h"
12 12
13 namespace views { 13 namespace views {
14 14
15 const char ResizeArea::kViewClassName[] = "ResizeArea"; 15 const char ResizeArea::kViewClassName[] = "ResizeArea";
16 16
17 ////////////////////////////////////////////////////////////////////////////////
18 // ResizeArea
19
20 ResizeArea::ResizeArea(ResizeAreaDelegate* delegate) 17 ResizeArea::ResizeArea(ResizeAreaDelegate* delegate)
21 : delegate_(delegate), 18 : delegate_(delegate),
22 initial_position_(0) { 19 initial_position_(0) {
23 } 20 }
24 21
25 ResizeArea::~ResizeArea() { 22 ResizeArea::~ResizeArea() {
26 } 23 }
27 24
28 const char* ResizeArea::GetClassName() const { 25 const char* ResizeArea::GetClassName() const {
29 return kViewClassName; 26 return kViewClassName;
30 } 27 }
31 28
32 gfx::NativeCursor ResizeArea::GetCursor(const ui::MouseEvent& event) { 29 gfx::NativeCursor ResizeArea::GetCursor(const ui::MouseEvent& event) {
33 return enabled() ? GetNativeEastWestResizeCursor() 30 return enabled() ? GetNativeEastWestResizeCursor()
34 : gfx::kNullCursor; 31 : gfx::kNullCursor;
35 } 32 }
36 33
34 void ResizeArea::OnGestureEvent(ui::GestureEvent* event) {
35 if (event->type() == ui::ET_GESTURE_TAP_DOWN) {
36 SetInitialPosition(event->x());
37 event->SetHandled();
38 } else if (event->type() == ui::ET_GESTURE_SCROLL_BEGIN ||
39 event->type() == ui::ET_GESTURE_SCROLL_UPDATE) {
40 ReportResizeAmount(event->x(), false);
41 event->SetHandled();
42 } else if (event->type() == ui::ET_GESTURE_END) {
43 ReportResizeAmount(event->x(), true);
44 event->SetHandled();
45 }
46 }
47
37 bool ResizeArea::OnMousePressed(const ui::MouseEvent& event) { 48 bool ResizeArea::OnMousePressed(const ui::MouseEvent& event) {
38 if (!event.IsOnlyLeftMouseButton()) 49 if (!event.IsOnlyLeftMouseButton())
39 return false; 50 return false;
40 51
41 // The resize area obviously will move once you start dragging so we need to 52 SetInitialPosition(event.x());
42 // convert coordinates to screen coordinates so that we don't lose our
43 // bearings.
44 gfx::Point point(event.x(), 0);
45 View::ConvertPointToScreen(this, &point);
46 initial_position_ = point.x();
47
48 return true; 53 return true;
49 } 54 }
50 55
51 bool ResizeArea::OnMouseDragged(const ui::MouseEvent& event) { 56 bool ResizeArea::OnMouseDragged(const ui::MouseEvent& event) {
52 if (!event.IsLeftMouseButton()) 57 if (!event.IsLeftMouseButton())
53 return false; 58 return false;
54 59
55 ReportResizeAmount(event.x(), false); 60 ReportResizeAmount(event.x(), false);
56 return true; 61 return true;
57 } 62 }
(...skipping 11 matching lines...) Expand all
69 } 74 }
70 75
71 void ResizeArea::ReportResizeAmount(int resize_amount, bool last_update) { 76 void ResizeArea::ReportResizeAmount(int resize_amount, bool last_update) {
72 gfx::Point point(resize_amount, 0); 77 gfx::Point point(resize_amount, 0);
73 View::ConvertPointToScreen(this, &point); 78 View::ConvertPointToScreen(this, &point);
74 resize_amount = point.x() - initial_position_; 79 resize_amount = point.x() - initial_position_;
75 delegate_->OnResize(base::i18n::IsRTL() ? -resize_amount : resize_amount, 80 delegate_->OnResize(base::i18n::IsRTL() ? -resize_amount : resize_amount,
76 last_update); 81 last_update);
77 } 82 }
78 83
84 void ResizeArea::SetInitialPosition(int event_x) {
85 gfx::Point point(event_x, 0);
86 View::ConvertPointToScreen(this, &point);
87 initial_position_ = point.x();
88 }
89
79 } // namespace views 90 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/resize_area.h ('k') | ui/views/controls/resize_area_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698