Make castv2 performance test work.
[chromium-blink-merge.git] / ui / views / controls / resize_area.cc
blob66759106dfadf47b52714ffcd0381b1e4c2c06f8
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"
13 namespace views {
15 const char ResizeArea::kViewClassName[] = "ResizeArea";
17 ////////////////////////////////////////////////////////////////////////////////
18 // ResizeArea
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()
34 : gfx::kNullCursor;
37 bool ResizeArea::OnMousePressed(const ui::MouseEvent& event) {
38 if (!event.IsOnlyLeftMouseButton())
39 return false;
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();
48 return true;
51 bool ResizeArea::OnMouseDragged(const ui::MouseEvent& event) {
52 if (!event.IsLeftMouseButton())
53 return false;
55 ReportResizeAmount(event.x(), false);
56 return true;
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,
76 last_update);
79 } // namespace views