Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / ui / views / controls / resize_area.cc
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.
4
5 #include "ui/views/controls/resize_area.h"
6
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"
13
14 namespace views {
15
16 const char ResizeArea::kViewClassName[] = "ResizeArea";
17
18 ////////////////////////////////////////////////////////////////////////////////
19 // ResizeArea
20
21 ResizeArea::ResizeArea(ResizeAreaDelegate* delegate)
22     : delegate_(delegate),
23       initial_position_(0) {
24 }
25
26 ResizeArea::~ResizeArea() {
27 }
28
29 const char* ResizeArea::GetClassName() const {
30   return kViewClassName;
31 }
32
33 gfx::NativeCursor ResizeArea::GetCursor(const ui::MouseEvent& event) {
34   return enabled() ? GetNativeEastWestResizeCursor()
35                    : gfx::kNullCursor;
36 }
37
38 bool ResizeArea::OnMousePressed(const ui::MouseEvent& event) {
39   if (!event.IsOnlyLeftMouseButton())
40     return false;
41
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
44   // bearings.
45   gfx::Point point(event.x(), 0);
46   View::ConvertPointToScreen(this, &point);
47   initial_position_ = point.x();
48
49   return true;
50 }
51
52 bool ResizeArea::OnMouseDragged(const ui::MouseEvent& event) {
53   if (!event.IsLeftMouseButton())
54     return false;
55
56   ReportResizeAmount(event.x(), false);
57   return true;
58 }
59
60 void ResizeArea::OnMouseReleased(const ui::MouseEvent& event) {
61   ReportResizeAmount(event.x(), true);
62 }
63
64 void ResizeArea::OnMouseCaptureLost() {
65   ReportResizeAmount(initial_position_, true);
66 }
67
68 void ResizeArea::GetAccessibleState(ui::AXViewState* state) {
69   state->role = ui::AX_ROLE_SPLITTER;
70 }
71
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,
77                       last_update);
78 }
79
80 }  // namespace views