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

Side by Side Diff: views/controls/slider/native_slider_gtk.cc

Issue 211002: Add touchpad speed factor setting to Chrome OS touchpad settings page... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 3 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 | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2009 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 <gtk/gtk.h>
6
7 #include "views/controls/slider/native_slider_gtk.h"
8
9 #include "base/gfx/gtk_util.h"
10 #include "views/controls/slider/slider.h"
11
12 namespace views {
13
14 ////////////////////////////////////////////////////////////////////////////////
15 // NativeSliderGtk, public:
16
17 NativeSliderGtk::NativeSliderGtk(Slider* slider)
18 : slider_(slider) {
19 }
20
21 NativeSliderGtk::~NativeSliderGtk() {
22 }
23
24 ////////////////////////////////////////////////////////////////////////////////
25 // NativeSliderGtk, NativeSliderWrapper implementation:
26
27 void NativeSliderGtk::UpdateEnabled() {
28 if (!native_view())
29 return;
30 SetEnabled(slider_->IsEnabled());
31 }
32
33 double NativeSliderGtk::GetValue() {
34 if (!native_view())
35 return 0;
36 return gtk_range_get_value(GTK_RANGE(native_view()));
37 }
38
39 void NativeSliderGtk::SetValue(double value) {
40 if (!native_view())
41 return;
42 gtk_range_set_value(GTK_RANGE(native_view()), value);
43 }
44
45 void NativeSliderGtk::SetFocus() {
46 Focus();
47 }
48
49 gfx::Size NativeSliderGtk::GetPreferredSize() {
50 if (!native_view())
51 return gfx::Size();
52
53 if (preferred_size_.IsEmpty()) {
54 GtkRequisition size_request = { 0, 0 };
55 gtk_widget_size_request(native_view(), &size_request);
56 preferred_size_.SetSize(size_request.width, size_request.height);
57 }
58 return preferred_size_;
59 }
60
61 View* NativeSliderGtk::GetView() {
62 return this;
63 }
64
65 gfx::NativeView NativeSliderGtk::GetTestingHandle() const {
66 return native_view();
67 }
68
69 // static
70 gboolean NativeSliderGtk::OnValueChangedHandler(GtkWidget* entry,
71 NativeSliderGtk* slider) {
72 return slider->OnValueChanged();
73 }
74
75 gboolean NativeSliderGtk::OnValueChanged() {
76 slider_->NotifyValueChanged();
77 return false;
78 }
79 ////////////////////////////////////////////////////////////////////////////////
80 // NativeSliderGtk, NativeControlGtk overrides:
81
82 void NativeSliderGtk::CreateNativeControl() {
83 GtkWidget* widget;
84 if (slider_->style() & Slider::STYLE_VERTICAL)
85 widget = gtk_vscale_new_with_range(slider_->min(),
86 slider_->max(),
87 slider_->step());
88 else
89 widget = gtk_hscale_new_with_range(slider_->min(),
90 slider_->max(),
91 slider_->step());
92 NativeControlCreated(widget);
93
94 bool drawvalue = slider_->style() & Slider::STYLE_DRAW_VALUE;
95 gtk_scale_set_draw_value(GTK_SCALE(native_view()), drawvalue);
96
97 int digits = 0;
98 if (slider_->style() & Slider::STYLE_ONE_DIGIT)
99 digits = 1;
100 else if (slider_->style() & Slider::STYLE_TWO_DIGITS)
101 digits = 2;
102 gtk_scale_set_digits(GTK_SCALE(native_view()), digits);
103
104 if (slider_->style() & Slider::STYLE_UPDATE_ON_RELEASE)
105 gtk_range_set_update_policy(GTK_RANGE(native_view()),
106 GTK_UPDATE_DISCONTINUOUS);
107 }
108
109 void NativeSliderGtk::NativeControlCreated(GtkWidget* widget) {
110 NativeControlGtk::NativeControlCreated(widget);
111 g_signal_connect(widget, "value_changed",
112 G_CALLBACK(OnValueChangedHandler), this);
113 }
114
115 ////////////////////////////////////////////////////////////////////////////////
116 // NativeSliderWrapper, public:
117
118 // static
119 NativeSliderWrapper* NativeSliderWrapper::CreateWrapper(Slider* field) {
120 return new NativeSliderGtk(field);
121 }
122
123 } // namespace views
OLDNEW
« no previous file with comments | « views/controls/slider/native_slider_gtk.h ('k') | views/controls/slider/native_slider_wrapper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698