| 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/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 |
| 17 ResizeArea::ResizeArea(ResizeAreaDelegate* delegate) | 20 ResizeArea::ResizeArea(ResizeAreaDelegate* delegate) |
| 18 : delegate_(delegate), | 21 : delegate_(delegate), |
| 19 initial_position_(0) { | 22 initial_position_(0) { |
| 20 } | 23 } |
| 21 | 24 |
| 22 ResizeArea::~ResizeArea() { | 25 ResizeArea::~ResizeArea() { |
| 23 } | 26 } |
| 24 | 27 |
| 25 const char* ResizeArea::GetClassName() const { | 28 const char* ResizeArea::GetClassName() const { |
| 26 return kViewClassName; | 29 return kViewClassName; |
| 27 } | 30 } |
| 28 | 31 |
| 29 gfx::NativeCursor ResizeArea::GetCursor(const ui::MouseEvent& event) { | 32 gfx::NativeCursor ResizeArea::GetCursor(const ui::MouseEvent& event) { |
| 30 return enabled() ? GetNativeEastWestResizeCursor() | 33 return enabled() ? GetNativeEastWestResizeCursor() |
| 31 : gfx::kNullCursor; | 34 : gfx::kNullCursor; |
| 32 } | 35 } |
| 33 | 36 |
| 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 | |
| 48 bool ResizeArea::OnMousePressed(const ui::MouseEvent& event) { | 37 bool ResizeArea::OnMousePressed(const ui::MouseEvent& event) { |
| 49 if (!event.IsOnlyLeftMouseButton()) | 38 if (!event.IsOnlyLeftMouseButton()) |
| 50 return false; | 39 return false; |
| 51 | 40 |
| 52 SetInitialPosition(event.x()); | 41 // The resize area obviously will move once you start dragging so we need to |
| 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 |
| 53 return true; | 48 return true; |
| 54 } | 49 } |
| 55 | 50 |
| 56 bool ResizeArea::OnMouseDragged(const ui::MouseEvent& event) { | 51 bool ResizeArea::OnMouseDragged(const ui::MouseEvent& event) { |
| 57 if (!event.IsLeftMouseButton()) | 52 if (!event.IsLeftMouseButton()) |
| 58 return false; | 53 return false; |
| 59 | 54 |
| 60 ReportResizeAmount(event.x(), false); | 55 ReportResizeAmount(event.x(), false); |
| 61 return true; | 56 return true; |
| 62 } | 57 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 74 } | 69 } |
| 75 | 70 |
| 76 void ResizeArea::ReportResizeAmount(int resize_amount, bool last_update) { | 71 void ResizeArea::ReportResizeAmount(int resize_amount, bool last_update) { |
| 77 gfx::Point point(resize_amount, 0); | 72 gfx::Point point(resize_amount, 0); |
| 78 View::ConvertPointToScreen(this, &point); | 73 View::ConvertPointToScreen(this, &point); |
| 79 resize_amount = point.x() - initial_position_; | 74 resize_amount = point.x() - initial_position_; |
| 80 delegate_->OnResize(base::i18n::IsRTL() ? -resize_amount : resize_amount, | 75 delegate_->OnResize(base::i18n::IsRTL() ? -resize_amount : resize_amount, |
| 81 last_update); | 76 last_update); |
| 82 } | 77 } |
| 83 | 78 |
| 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 | |
| 90 } // namespace views | 79 } // namespace views |
| OLD | NEW |