blob: c19361cbaa17b8145432d6f6e5f8b33a8168090e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/views/controls/resize_area.h"
#include "base/logging.h"
#include "ui/base/accessibility/accessible_view_state.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/views/controls/resize_area_delegate.h"
#if defined(USE_AURA)
#include "ui/aura/cursor.h"
#endif
namespace views {
const char ResizeArea::kViewClassName[] = "views/ResizeArea";
////////////////////////////////////////////////////////////////////////////////
// ResizeArea
ResizeArea::ResizeArea(ResizeAreaDelegate* delegate)
: delegate_(delegate),
initial_position_(0) {
}
ResizeArea::~ResizeArea() {
}
std::string ResizeArea::GetClassName() const {
return kViewClassName;
}
gfx::NativeCursor ResizeArea::GetCursor(const MouseEvent& event) {
if (!enabled())
return gfx::kNullCursor;
#if defined(USE_AURA)
return aura::kCursorEastWestResize;
#elif defined(OS_WIN)
static HCURSOR g_resize_cursor = LoadCursor(NULL, IDC_SIZEWE);
return g_resize_cursor;
#endif
}
bool ResizeArea::OnMousePressed(const views::MouseEvent& event) {
if (!event.IsOnlyLeftMouseButton())
return false;
// The resize area obviously will move once you start dragging so we need to
// convert coordinates to screen coordinates so that we don't lose our
// bearings.
gfx::Point point(event.x(), 0);
View::ConvertPointToScreen(this, &point);
initial_position_ = point.x();
return true;
}
bool ResizeArea::OnMouseDragged(const views::MouseEvent& event) {
if (!event.IsLeftMouseButton())
return false;
ReportResizeAmount(event.x(), false);
return true;
}
void ResizeArea::OnMouseReleased(const views::MouseEvent& event) {
ReportResizeAmount(event.x(), true);
}
void ResizeArea::OnMouseCaptureLost() {
ReportResizeAmount(initial_position_, true);
}
void ResizeArea::GetAccessibleState(ui::AccessibleViewState* state) {
state->role = ui::AccessibilityTypes::ROLE_SEPARATOR;
}
void ResizeArea::ReportResizeAmount(int resize_amount, bool last_update) {
gfx::Point point(resize_amount, 0);
View::ConvertPointToScreen(this, &point);
resize_amount = point.x() - initial_position_;
delegate_->OnResize(base::i18n::IsRTL() ? -resize_amount : resize_amount,
last_update);
}
} // namespace views
|