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/base/resource/resource_bundle.h"
11 #include "ui/views/controls/resize_area_delegate.h"
12 #include "ui/views/native_cursor.h"
16 const char ResizeArea::kViewClassName
[] = "ResizeArea";
18 ////////////////////////////////////////////////////////////////////////////////
21 ResizeArea::ResizeArea(ResizeAreaDelegate
* delegate
)
22 : delegate_(delegate
),
23 initial_position_(0) {
26 ResizeArea::~ResizeArea() {
29 const char* ResizeArea::GetClassName() const {
30 return kViewClassName
;
33 gfx::NativeCursor
ResizeArea::GetCursor(const ui::MouseEvent
& event
) {
34 return enabled() ? GetNativeEastWestResizeCursor()
38 bool ResizeArea::OnMousePressed(const ui::MouseEvent
& event
) {
39 if (!event
.IsOnlyLeftMouseButton())
42 // The resize area obviously will move once you start dragging so we need to
43 // convert coordinates to screen coordinates so that we don't lose our
45 gfx::Point
point(event
.x(), 0);
46 View::ConvertPointToScreen(this, &point
);
47 initial_position_
= point
.x();
52 bool ResizeArea::OnMouseDragged(const ui::MouseEvent
& event
) {
53 if (!event
.IsLeftMouseButton())
56 ReportResizeAmount(event
.x(), false);
60 void ResizeArea::OnMouseReleased(const ui::MouseEvent
& event
) {
61 ReportResizeAmount(event
.x(), true);
64 void ResizeArea::OnMouseCaptureLost() {
65 ReportResizeAmount(initial_position_
, true);
68 void ResizeArea::GetAccessibleState(ui::AXViewState
* state
) {
69 state
->role
= ui::AX_ROLE_SPLITTER
;
72 void ResizeArea::ReportResizeAmount(int resize_amount
, bool last_update
) {
73 gfx::Point
point(resize_amount
, 0);
74 View::ConvertPointToScreen(this, &point
);
75 resize_amount
= point
.x() - initial_position_
;
76 delegate_
->OnResize(base::i18n::IsRTL() ? -resize_amount
: resize_amount
,