| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "views/controls/resize_area.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 #include "ui/base/accessibility/accessible_view_state.h" | |
| 9 #include "ui/base/resource/resource_bundle.h" | |
| 10 #include "views/controls/resize_area_delegate.h" | |
| 11 | |
| 12 #if defined(OS_LINUX) | |
| 13 #include "ui/gfx/gtk_util.h" | |
| 14 #endif | |
| 15 | |
| 16 #if defined(USE_AURA) | |
| 17 #include "ui/aura/cursor.h" | |
| 18 #endif | |
| 19 | |
| 20 namespace views { | |
| 21 | |
| 22 const char ResizeArea::kViewClassName[] = "views/ResizeArea"; | |
| 23 | |
| 24 //////////////////////////////////////////////////////////////////////////////// | |
| 25 // ResizeArea | |
| 26 | |
| 27 ResizeArea::ResizeArea(ResizeAreaDelegate* delegate) | |
| 28 : delegate_(delegate), | |
| 29 initial_position_(0) { | |
| 30 } | |
| 31 | |
| 32 ResizeArea::~ResizeArea() { | |
| 33 } | |
| 34 | |
| 35 std::string ResizeArea::GetClassName() const { | |
| 36 return kViewClassName; | |
| 37 } | |
| 38 | |
| 39 gfx::NativeCursor ResizeArea::GetCursor(const MouseEvent& event) { | |
| 40 if (!IsEnabled()) | |
| 41 return gfx::kNullCursor; | |
| 42 #if defined(USE_AURA) | |
| 43 return aura::kCursorEastWestResize; | |
| 44 #elif defined(OS_WIN) | |
| 45 static HCURSOR g_resize_cursor = LoadCursor(NULL, IDC_SIZEWE); | |
| 46 return g_resize_cursor; | |
| 47 #elif defined(OS_LINUX) | |
| 48 return gfx::GetCursor(GDK_SB_H_DOUBLE_ARROW); | |
| 49 #endif | |
| 50 } | |
| 51 | |
| 52 bool ResizeArea::OnMousePressed(const views::MouseEvent& event) { | |
| 53 if (!event.IsOnlyLeftMouseButton()) | |
| 54 return false; | |
| 55 | |
| 56 // The resize area obviously will move once you start dragging so we need to | |
| 57 // convert coordinates to screen coordinates so that we don't lose our | |
| 58 // bearings. | |
| 59 gfx::Point point(event.x(), 0); | |
| 60 View::ConvertPointToScreen(this, &point); | |
| 61 initial_position_ = point.x(); | |
| 62 | |
| 63 return true; | |
| 64 } | |
| 65 | |
| 66 bool ResizeArea::OnMouseDragged(const views::MouseEvent& event) { | |
| 67 if (!event.IsLeftMouseButton()) | |
| 68 return false; | |
| 69 | |
| 70 ReportResizeAmount(event.x(), false); | |
| 71 return true; | |
| 72 } | |
| 73 | |
| 74 void ResizeArea::OnMouseReleased(const views::MouseEvent& event) { | |
| 75 ReportResizeAmount(event.x(), true); | |
| 76 } | |
| 77 | |
| 78 void ResizeArea::OnMouseCaptureLost() { | |
| 79 ReportResizeAmount(initial_position_, true); | |
| 80 } | |
| 81 | |
| 82 void ResizeArea::GetAccessibleState(ui::AccessibleViewState* state) { | |
| 83 state->role = ui::AccessibilityTypes::ROLE_SEPARATOR; | |
| 84 } | |
| 85 | |
| 86 void ResizeArea::ReportResizeAmount(int resize_amount, bool last_update) { | |
| 87 gfx::Point point(resize_amount, 0); | |
| 88 View::ConvertPointToScreen(this, &point); | |
| 89 resize_amount = point.x() - initial_position_; | |
| 90 delegate_->OnResize(base::i18n::IsRTL() ? -resize_amount : resize_amount, | |
| 91 last_update); | |
| 92 } | |
| 93 | |
| 94 } // namespace views | |
| OLD | NEW |