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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
// Copyright (c) 2010 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 "views/controls/slider/slider.h"
#include <string>
#include "views/controls/slider/native_slider_wrapper.h"
#include "views/controls/native/native_view_host.h"
#include "views/widget/widget.h"
namespace views {
// static
const char Slider::kViewClassName[] = "views/Slider";
/////////////////////////////////////////////////////////////////////////////
// Slider
Slider::Slider()
: native_wrapper_(NULL),
listener_(NULL),
style_(STYLE_HORIZONTAL) {
SetFocusable(true);
}
Slider::Slider(double min, double max, double step, StyleFlags style,
SliderListener* listener)
: native_wrapper_(NULL),
listener_(listener),
style_(style),
min_(min),
max_(max),
step_(step) {
SetFocusable(true);
}
Slider::~Slider() {
}
void Slider::NotifyValueChanged() {
if (native_wrapper_)
value_ = native_wrapper_->GetValue();
if (listener_)
listener_->SliderValueChanged(this);
}
void Slider::SetValue(double value) {
value_ = value;
if (native_wrapper_)
native_wrapper_->SetValue(value);
}
////////////////////////////////////////////////////////////////////////////////
// Slider, View overrides:
void Slider::Layout() {
if (native_wrapper_) {
native_wrapper_->GetView()->SetBoundsRect(GetContentsBounds());
native_wrapper_->GetView()->Layout();
}
}
gfx::Size Slider::GetPreferredSize() {
if (native_wrapper_)
return native_wrapper_->GetPreferredSize();
return gfx::Size();
}
void Slider::SetEnabled(bool enabled) {
View::SetEnabled(enabled);
if (native_wrapper_)
native_wrapper_->UpdateEnabled();
}
void Slider::Focus() {
if (native_wrapper_) {
// Forward the focus to the wrapper if it exists.
native_wrapper_->SetFocus();
} else {
// If there is no wrapper, cause the RootView to be focused so that we still
// get keyboard messages.
View::Focus();
}
}
void Slider::PaintFocusBorder(gfx::Canvas* canvas) {
if (NativeViewHost::kRenderNativeControlFocus)
View::PaintFocusBorder(canvas);
}
void Slider::ViewHierarchyChanged(bool is_add, View* parent, View* child) {
if (is_add && !native_wrapper_ && GetWidget()) {
// The native wrapper's lifetime will be managed by the view hierarchy after
// we call AddChildView.
native_wrapper_ = NativeSliderWrapper::CreateWrapper(this);
AddChildView(native_wrapper_->GetView());
native_wrapper_->UpdateEnabled();
}
}
std::string Slider::GetClassName() const {
return kViewClassName;
}
NativeSliderWrapper* Slider::CreateWrapper() {
NativeSliderWrapper* native_wrapper =
NativeSliderWrapper::CreateWrapper(this);
native_wrapper->UpdateEnabled();
return native_wrapper;
}
} // namespace views
|