Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(966)

Side by Side Diff: ui/views/controls/resize_area.cc

Issue 851853002: It is time. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Trying to reup because the last upload failed. Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/views/controls/resize_area.h ('k') | ui/views/controls/resize_area_delegate.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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/views/controls/resize_area_delegate.h"
11 #include "ui/views/native_cursor.h"
12
13 namespace views {
14
15 const char ResizeArea::kViewClassName[] = "ResizeArea";
16
17 ////////////////////////////////////////////////////////////////////////////////
18 // ResizeArea
19
20 ResizeArea::ResizeArea(ResizeAreaDelegate* delegate)
21 : delegate_(delegate),
22 initial_position_(0) {
23 }
24
25 ResizeArea::~ResizeArea() {
26 }
27
28 const char* ResizeArea::GetClassName() const {
29 return kViewClassName;
30 }
31
32 gfx::NativeCursor ResizeArea::GetCursor(const ui::MouseEvent& event) {
33 return enabled() ? GetNativeEastWestResizeCursor()
34 : gfx::kNullCursor;
35 }
36
37 bool ResizeArea::OnMousePressed(const ui::MouseEvent& event) {
38 if (!event.IsOnlyLeftMouseButton())
39 return false;
40
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();
47
48 return true;
49 }
50
51 bool ResizeArea::OnMouseDragged(const ui::MouseEvent& event) {
52 if (!event.IsLeftMouseButton())
53 return false;
54
55 ReportResizeAmount(event.x(), false);
56 return true;
57 }
58
59 void ResizeArea::OnMouseReleased(const ui::MouseEvent& event) {
60 ReportResizeAmount(event.x(), true);
61 }
62
63 void ResizeArea::OnMouseCaptureLost() {
64 ReportResizeAmount(initial_position_, true);
65 }
66
67 void ResizeArea::GetAccessibleState(ui::AXViewState* state) {
68 state->role = ui::AX_ROLE_SPLITTER;
69 }
70
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);
77 }
78
79 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/resize_area.h ('k') | ui/views/controls/resize_area_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698