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
3 // found in the LICENSE file.
5 #include "ui/views/controls/resize_area.h"
7 #include "base/logging.h"
8 #include "ui/accessibility/ax_view_state.h"
9 #include "ui/base/cursor/cursor.h"
10 #include "ui/views/controls/resize_area_delegate.h"
11 #include "ui/views/native_cursor.h"
15 const char ResizeArea::kViewClassName
[] = "ResizeArea";
17 ////////////////////////////////////////////////////////////////////////////////
20 ResizeArea::ResizeArea(ResizeAreaDelegate
* delegate
)
21 : delegate_(delegate
),
22 initial_position_(0) {
25 ResizeArea::~ResizeArea() {
28 const char* ResizeArea::GetClassName() const {
29 return kViewClassName
;
32 gfx::NativeCursor
ResizeArea::GetCursor(const ui::MouseEvent
& event
) {
33 return enabled() ? GetNativeEastWestResizeCursor()
37 bool ResizeArea::OnMousePressed(const ui::MouseEvent
& event
) {
38 if (!event
.IsOnlyLeftMouseButton())
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
44 gfx::Point
point(event
.x(), 0);
45 View::ConvertPointToScreen(this, &point
);
46 initial_position_
= point
.x();
51 bool ResizeArea::OnMouseDragged(const ui::MouseEvent
& event
) {
52 if (!event
.IsLeftMouseButton())
55 ReportResizeAmount(event
.x(), false);
59 void ResizeArea::OnMouseReleased(const ui::MouseEvent
& event
) {
60 ReportResizeAmount(event
.x(), true);
63 void ResizeArea::OnMouseCaptureLost() {
64 ReportResizeAmount(initial_position_
, true);
67 void ResizeArea::GetAccessibleState(ui::AXViewState
* state
) {
68 state
->role
= ui::AX_ROLE_SPLITTER
;
71 void ResizeArea::ReportResizeAmount(int resize_amount
, bool last_update
) {
72 gfx::Point
point(resize_amount
, 0);
73 View::ConvertPointToScreen(this, &point
);
74 resize_amount
= point
.x() - initial_position_
;
75 delegate_
->OnResize(base::i18n::IsRTL() ? -resize_amount
: resize_amount
,