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

Side by Side Diff: ui/views/controls/scrollbar/native_scroll_bar_views.cc

Issue 10310136: ui: Move NativeTheme files into ui/base/native_theme/ directory. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix win Created 8 years, 7 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/views/controls/scrollbar/native_scroll_bar_views.h" 5 #include "ui/views/controls/scrollbar/native_scroll_bar_views.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "ui/base/keycodes/keyboard_codes.h" 8 #include "ui/base/keycodes/keyboard_codes.h"
9 #include "ui/gfx/canvas.h" 9 #include "ui/gfx/canvas.h"
10 #include "ui/gfx/path.h" 10 #include "ui/gfx/path.h"
(...skipping 23 matching lines...) Expand all
34 34
35 virtual gfx::Size GetPreferredSize() OVERRIDE; 35 virtual gfx::Size GetPreferredSize() OVERRIDE;
36 virtual std::string GetClassName() const OVERRIDE { 36 virtual std::string GetClassName() const OVERRIDE {
37 return "views/ScrollBarButton"; 37 return "views/ScrollBarButton";
38 } 38 }
39 39
40 protected: 40 protected:
41 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; 41 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
42 42
43 private: 43 private:
44 gfx::NativeTheme::ExtraParams GetNativeThemeParams() const; 44 ui::NativeTheme::ExtraParams GetNativeThemeParams() const;
45 gfx::NativeTheme::Part GetNativeThemePart() const; 45 ui::NativeTheme::Part GetNativeThemePart() const;
46 gfx::NativeTheme::State GetNativeThemeState() const; 46 ui::NativeTheme::State GetNativeThemeState() const;
47 47
48 Type type_; 48 Type type_;
49 }; 49 };
50 50
51 // Wrapper for the scroll thumb 51 // Wrapper for the scroll thumb
52 class ScrollBarThumb : public BaseScrollBarThumb { 52 class ScrollBarThumb : public BaseScrollBarThumb {
53 public: 53 public:
54 explicit ScrollBarThumb(BaseScrollBar* scroll_bar); 54 explicit ScrollBarThumb(BaseScrollBar* scroll_bar);
55 virtual ~ScrollBarThumb(); 55 virtual ~ScrollBarThumb();
56 56
57 virtual gfx::Size GetPreferredSize() OVERRIDE; 57 virtual gfx::Size GetPreferredSize() OVERRIDE;
58 virtual std::string GetClassName() const OVERRIDE { 58 virtual std::string GetClassName() const OVERRIDE {
59 return "views/ScrollBarThumb"; 59 return "views/ScrollBarThumb";
60 } 60 }
61 61
62 protected: 62 protected:
63 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; 63 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
64 64
65 private: 65 private:
66 gfx::NativeTheme::ExtraParams GetNativeThemeParams() const; 66 ui::NativeTheme::ExtraParams GetNativeThemeParams() const;
67 gfx::NativeTheme::Part GetNativeThemePart() const; 67 ui::NativeTheme::Part GetNativeThemePart() const;
68 gfx::NativeTheme::State GetNativeThemeState() const; 68 ui::NativeTheme::State GetNativeThemeState() const;
69 69
70 ScrollBar* scroll_bar_; 70 ScrollBar* scroll_bar_;
71 }; 71 };
72 72
73 ///////////////////////////////////////////////////////////////////////////// 73 /////////////////////////////////////////////////////////////////////////////
74 // ScrollBarButton 74 // ScrollBarButton
75 75
76 ScrollBarButton::ScrollBarButton( 76 ScrollBarButton::ScrollBarButton(
77 ButtonListener* listener, 77 ButtonListener* listener,
78 Type type) 78 Type type)
79 : BaseScrollBarButton(listener), 79 : BaseScrollBarButton(listener),
80 type_(type) { 80 type_(type) {
81 set_focusable(false); 81 set_focusable(false);
82 set_accessibility_focusable(false); 82 set_accessibility_focusable(false);
83 } 83 }
84 84
85 ScrollBarButton::~ScrollBarButton() { 85 ScrollBarButton::~ScrollBarButton() {
86 } 86 }
87 87
88 gfx::Size ScrollBarButton::GetPreferredSize() { 88 gfx::Size ScrollBarButton::GetPreferredSize() {
89 const gfx::NativeTheme* native_theme = gfx::NativeTheme::instance(); 89 const ui::NativeTheme* native_theme = ui::NativeTheme::instance();
90 return native_theme->GetPartSize(GetNativeThemePart(), 90 return native_theme->GetPartSize(GetNativeThemePart(),
91 GetNativeThemeState(), 91 GetNativeThemeState(),
92 GetNativeThemeParams()); 92 GetNativeThemeParams());
93 } 93 }
94 94
95 void ScrollBarButton::OnPaint(gfx::Canvas* canvas) { 95 void ScrollBarButton::OnPaint(gfx::Canvas* canvas) {
96 const gfx::NativeTheme* native_theme = gfx::NativeTheme::instance(); 96 const ui::NativeTheme* native_theme = ui::NativeTheme::instance();
97 gfx::Rect bounds(GetPreferredSize()); 97 gfx::Rect bounds(GetPreferredSize());
98 native_theme->Paint(canvas->sk_canvas(), GetNativeThemePart(), 98 native_theme->Paint(canvas->sk_canvas(), GetNativeThemePart(),
99 GetNativeThemeState(), bounds, GetNativeThemeParams()); 99 GetNativeThemeState(), bounds, GetNativeThemeParams());
100 } 100 }
101 101
102 gfx::NativeTheme::ExtraParams 102 ui::NativeTheme::ExtraParams
103 ScrollBarButton::GetNativeThemeParams() const { 103 ScrollBarButton::GetNativeThemeParams() const {
104 gfx::NativeTheme::ExtraParams params; 104 ui::NativeTheme::ExtraParams params;
105 105
106 switch (state_) { 106 switch (state_) {
107 case CustomButton::BS_HOT: 107 case CustomButton::BS_HOT:
108 params.scrollbar_arrow.is_hovering = true; 108 params.scrollbar_arrow.is_hovering = true;
109 break; 109 break;
110 default: 110 default:
111 params.scrollbar_arrow.is_hovering = false; 111 params.scrollbar_arrow.is_hovering = false;
112 break; 112 break;
113 } 113 }
114 114
115 return params; 115 return params;
116 } 116 }
117 117
118 gfx::NativeTheme::Part 118 ui::NativeTheme::Part
119 ScrollBarButton::GetNativeThemePart() const { 119 ScrollBarButton::GetNativeThemePart() const {
120 switch (type_) { 120 switch (type_) {
121 case UP: 121 case UP:
122 return gfx::NativeTheme::kScrollbarUpArrow; 122 return ui::NativeTheme::kScrollbarUpArrow;
123 case DOWN: 123 case DOWN:
124 return gfx::NativeTheme::kScrollbarDownArrow; 124 return ui::NativeTheme::kScrollbarDownArrow;
125 case LEFT: 125 case LEFT:
126 return gfx::NativeTheme::kScrollbarLeftArrow; 126 return ui::NativeTheme::kScrollbarLeftArrow;
127 case RIGHT: 127 case RIGHT:
128 return gfx::NativeTheme::kScrollbarRightArrow; 128 return ui::NativeTheme::kScrollbarRightArrow;
129 default: 129 default:
130 return gfx::NativeTheme::kScrollbarUpArrow; 130 return ui::NativeTheme::kScrollbarUpArrow;
131 } 131 }
132 } 132 }
133 133
134 gfx::NativeTheme::State 134 ui::NativeTheme::State
135 ScrollBarButton::GetNativeThemeState() const { 135 ScrollBarButton::GetNativeThemeState() const {
136 gfx::NativeTheme::State state; 136 ui::NativeTheme::State state;
137 137
138 switch (state_) { 138 switch (state_) {
139 case CustomButton::BS_HOT: 139 case CustomButton::BS_HOT:
140 state = gfx::NativeTheme::kHovered; 140 state = ui::NativeTheme::kHovered;
141 break; 141 break;
142 case CustomButton::BS_PUSHED: 142 case CustomButton::BS_PUSHED:
143 state = gfx::NativeTheme::kPressed; 143 state = ui::NativeTheme::kPressed;
144 break; 144 break;
145 case CustomButton::BS_DISABLED: 145 case CustomButton::BS_DISABLED:
146 state = gfx::NativeTheme::kDisabled; 146 state = ui::NativeTheme::kDisabled;
147 break; 147 break;
148 case CustomButton::BS_NORMAL: 148 case CustomButton::BS_NORMAL:
149 default: 149 default:
150 state = gfx::NativeTheme::kNormal; 150 state = ui::NativeTheme::kNormal;
151 break; 151 break;
152 } 152 }
153 153
154 return state; 154 return state;
155 } 155 }
156 156
157 ///////////////////////////////////////////////////////////////////////////// 157 /////////////////////////////////////////////////////////////////////////////
158 // ScrollBarThumb 158 // ScrollBarThumb
159 159
160 ScrollBarThumb::ScrollBarThumb(BaseScrollBar* scroll_bar) 160 ScrollBarThumb::ScrollBarThumb(BaseScrollBar* scroll_bar)
161 : BaseScrollBarThumb(scroll_bar), 161 : BaseScrollBarThumb(scroll_bar),
162 scroll_bar_(scroll_bar) { 162 scroll_bar_(scroll_bar) {
163 set_focusable(false); 163 set_focusable(false);
164 set_accessibility_focusable(false); 164 set_accessibility_focusable(false);
165 } 165 }
166 166
167 ScrollBarThumb::~ScrollBarThumb() { 167 ScrollBarThumb::~ScrollBarThumb() {
168 } 168 }
169 169
170 gfx::Size ScrollBarThumb::GetPreferredSize() { 170 gfx::Size ScrollBarThumb::GetPreferredSize() {
171 const gfx::NativeTheme* native_theme = gfx::NativeTheme::instance(); 171 const ui::NativeTheme* native_theme = ui::NativeTheme::instance();
172 return native_theme->GetPartSize(GetNativeThemePart(), 172 return native_theme->GetPartSize(GetNativeThemePart(),
173 GetNativeThemeState(), 173 GetNativeThemeState(),
174 GetNativeThemeParams()); 174 GetNativeThemeParams());
175 } 175 }
176 176
177 void ScrollBarThumb::OnPaint(gfx::Canvas* canvas) { 177 void ScrollBarThumb::OnPaint(gfx::Canvas* canvas) {
178 const gfx::NativeTheme* native_theme = gfx::NativeTheme::instance(); 178 const ui::NativeTheme* native_theme = ui::NativeTheme::instance();
179 179
180 native_theme->Paint(canvas->sk_canvas(), 180 native_theme->Paint(canvas->sk_canvas(),
181 GetNativeThemePart(), 181 GetNativeThemePart(),
182 GetNativeThemeState(), 182 GetNativeThemeState(),
183 GetLocalBounds(), 183 GetLocalBounds(),
184 GetNativeThemeParams()); 184 GetNativeThemeParams());
185 } 185 }
186 186
187 gfx::NativeTheme::ExtraParams 187 ui::NativeTheme::ExtraParams
188 ScrollBarThumb::GetNativeThemeParams() const { 188 ScrollBarThumb::GetNativeThemeParams() const {
189 gfx::NativeTheme::ExtraParams params; 189 ui::NativeTheme::ExtraParams params;
190 190
191 switch (GetState()) { 191 switch (GetState()) {
192 case CustomButton::BS_HOT: 192 case CustomButton::BS_HOT:
193 params.scrollbar_thumb.is_hovering = true; 193 params.scrollbar_thumb.is_hovering = true;
194 break; 194 break;
195 default: 195 default:
196 params.scrollbar_thumb.is_hovering = false; 196 params.scrollbar_thumb.is_hovering = false;
197 break; 197 break;
198 } 198 }
199 199
200 return params; 200 return params;
201 } 201 }
202 202
203 gfx::NativeTheme::Part ScrollBarThumb::GetNativeThemePart() const { 203 ui::NativeTheme::Part ScrollBarThumb::GetNativeThemePart() const {
204 if (scroll_bar_->IsHorizontal()) 204 if (scroll_bar_->IsHorizontal())
205 return gfx::NativeTheme::kScrollbarHorizontalThumb; 205 return ui::NativeTheme::kScrollbarHorizontalThumb;
206 return gfx::NativeTheme::kScrollbarVerticalThumb; 206 return ui::NativeTheme::kScrollbarVerticalThumb;
207 } 207 }
208 208
209 gfx::NativeTheme::State ScrollBarThumb::GetNativeThemeState() const { 209 ui::NativeTheme::State ScrollBarThumb::GetNativeThemeState() const {
210 gfx::NativeTheme::State state; 210 ui::NativeTheme::State state;
211 211
212 switch (GetState()) { 212 switch (GetState()) {
213 case CustomButton::BS_HOT: 213 case CustomButton::BS_HOT:
214 state = gfx::NativeTheme::kHovered; 214 state = ui::NativeTheme::kHovered;
215 break; 215 break;
216 case CustomButton::BS_PUSHED: 216 case CustomButton::BS_PUSHED:
217 state = gfx::NativeTheme::kPressed; 217 state = ui::NativeTheme::kPressed;
218 break; 218 break;
219 case CustomButton::BS_DISABLED: 219 case CustomButton::BS_DISABLED:
220 state = gfx::NativeTheme::kDisabled; 220 state = ui::NativeTheme::kDisabled;
221 break; 221 break;
222 case CustomButton::BS_NORMAL: 222 case CustomButton::BS_NORMAL:
223 default: 223 default:
224 state = gfx::NativeTheme::kNormal; 224 state = ui::NativeTheme::kNormal;
225 break; 225 break;
226 } 226 }
227 227
228 return state; 228 return state;
229 } 229 }
230 230
231 } // namespace 231 } // namespace
232 232
233 //////////////////////////////////////////////////////////////////////////////// 233 ////////////////////////////////////////////////////////////////////////////////
234 // NativeScrollBarViews, public: 234 // NativeScrollBarViews, public:
235 235
236 const char NativeScrollBarViews::kViewClassName[] = 236 const char NativeScrollBarViews::kViewClassName[] =
237 "views/NativeScrollBarViews"; 237 "views/NativeScrollBarViews";
238 238
239 NativeScrollBarViews::NativeScrollBarViews(NativeScrollBar* scroll_bar) 239 NativeScrollBarViews::NativeScrollBarViews(NativeScrollBar* scroll_bar)
240 : BaseScrollBar(scroll_bar->IsHorizontal(), 240 : BaseScrollBar(scroll_bar->IsHorizontal(),
241 new ScrollBarThumb(this)), 241 new ScrollBarThumb(this)),
242 native_scroll_bar_(scroll_bar) { 242 native_scroll_bar_(scroll_bar) {
243 set_controller(native_scroll_bar_->controller()); 243 set_controller(native_scroll_bar_->controller());
244 244
245 if (native_scroll_bar_->IsHorizontal()) { 245 if (native_scroll_bar_->IsHorizontal()) {
246 prev_button_ = new ScrollBarButton(this, ScrollBarButton::LEFT); 246 prev_button_ = new ScrollBarButton(this, ScrollBarButton::LEFT);
247 next_button_ = new ScrollBarButton(this, ScrollBarButton::RIGHT); 247 next_button_ = new ScrollBarButton(this, ScrollBarButton::RIGHT);
248 248
249 part_ = gfx::NativeTheme::kScrollbarHorizontalTrack; 249 part_ = ui::NativeTheme::kScrollbarHorizontalTrack;
250 } else { 250 } else {
251 prev_button_ = new ScrollBarButton(this, ScrollBarButton::UP); 251 prev_button_ = new ScrollBarButton(this, ScrollBarButton::UP);
252 next_button_ = new ScrollBarButton(this, ScrollBarButton::DOWN); 252 next_button_ = new ScrollBarButton(this, ScrollBarButton::DOWN);
253 253
254 part_ = gfx::NativeTheme::kScrollbarVerticalTrack; 254 part_ = ui::NativeTheme::kScrollbarVerticalTrack;
255 } 255 }
256 256
257 state_ = gfx::NativeTheme::kNormal; 257 state_ = ui::NativeTheme::kNormal;
258 258
259 AddChildView(prev_button_); 259 AddChildView(prev_button_);
260 AddChildView(next_button_); 260 AddChildView(next_button_);
261 261
262 prev_button_->set_context_menu_controller(this); 262 prev_button_->set_context_menu_controller(this);
263 next_button_->set_context_menu_controller(this); 263 next_button_->set_context_menu_controller(this);
264 } 264 }
265 265
266 NativeScrollBarViews::~NativeScrollBarViews() { 266 NativeScrollBarViews::~NativeScrollBarViews() {
267 } 267 }
(...skipping 10 matching lines...) Expand all
278 size.width(), size.height()); 278 size.width(), size.height());
279 } else { 279 } else {
280 next_button_->SetBounds(0, height() - size.height(), 280 next_button_->SetBounds(0, height() - size.height(),
281 size.width(), size.height()); 281 size.width(), size.height());
282 } 282 }
283 283
284 GetThumb()->SetBoundsRect(GetTrackBounds()); 284 GetThumb()->SetBoundsRect(GetTrackBounds());
285 } 285 }
286 286
287 void NativeScrollBarViews::OnPaint(gfx::Canvas* canvas) { 287 void NativeScrollBarViews::OnPaint(gfx::Canvas* canvas) {
288 const gfx::NativeTheme* native_theme = gfx::NativeTheme::instance(); 288 const ui::NativeTheme* native_theme = ui::NativeTheme::instance();
289 gfx::Rect bounds = GetTrackBounds(); 289 gfx::Rect bounds = GetTrackBounds();
290 290
291 if (bounds.IsEmpty()) 291 if (bounds.IsEmpty())
292 return; 292 return;
293 293
294 params_.scrollbar_track.track_x = bounds.x(); 294 params_.scrollbar_track.track_x = bounds.x();
295 params_.scrollbar_track.track_y = bounds.y(); 295 params_.scrollbar_track.track_y = bounds.y();
296 params_.scrollbar_track.track_width = bounds.width(); 296 params_.scrollbar_track.track_width = bounds.width();
297 params_.scrollbar_track.track_height = bounds.height(); 297 params_.scrollbar_track.track_height = bounds.height();
298 298
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 // NativewScrollBarWrapper, public: 379 // NativewScrollBarWrapper, public:
380 380
381 // static 381 // static
382 NativeScrollBarWrapper* NativeScrollBarWrapper::CreateWrapper( 382 NativeScrollBarWrapper* NativeScrollBarWrapper::CreateWrapper(
383 NativeScrollBar* scroll_bar) { 383 NativeScrollBar* scroll_bar) {
384 return new NativeScrollBarViews(scroll_bar); 384 return new NativeScrollBarViews(scroll_bar);
385 } 385 }
386 386
387 // static 387 // static
388 int NativeScrollBarWrapper::GetHorizontalScrollBarHeight() { 388 int NativeScrollBarWrapper::GetHorizontalScrollBarHeight() {
389 const gfx::NativeTheme* native_theme = gfx::NativeTheme::instance(); 389 const ui::NativeTheme* native_theme = ui::NativeTheme::instance();
390 390
391 gfx::NativeTheme::ExtraParams button_params; 391 ui::NativeTheme::ExtraParams button_params;
392 button_params.scrollbar_arrow.is_hovering = false; 392 button_params.scrollbar_arrow.is_hovering = false;
393 gfx::Size button_size = native_theme->GetPartSize( 393 gfx::Size button_size = native_theme->GetPartSize(
394 gfx::NativeTheme::kScrollbarLeftArrow, 394 ui::NativeTheme::kScrollbarLeftArrow,
395 gfx::NativeTheme::kNormal, 395 ui::NativeTheme::kNormal,
396 button_params); 396 button_params);
397 397
398 gfx::NativeTheme::ExtraParams thumb_params; 398 ui::NativeTheme::ExtraParams thumb_params;
399 thumb_params.scrollbar_thumb.is_hovering = false; 399 thumb_params.scrollbar_thumb.is_hovering = false;
400 gfx::Size track_size = native_theme->GetPartSize( 400 gfx::Size track_size = native_theme->GetPartSize(
401 gfx::NativeTheme::kScrollbarHorizontalThumb, 401 ui::NativeTheme::kScrollbarHorizontalThumb,
402 gfx::NativeTheme::kNormal, 402 ui::NativeTheme::kNormal,
403 thumb_params); 403 thumb_params);
404 404
405 return std::max(track_size.height(), button_size.height()); 405 return std::max(track_size.height(), button_size.height());
406 } 406 }
407 407
408 // static 408 // static
409 int NativeScrollBarWrapper::GetVerticalScrollBarWidth() { 409 int NativeScrollBarWrapper::GetVerticalScrollBarWidth() {
410 const gfx::NativeTheme* native_theme = gfx::NativeTheme::instance(); 410 const ui::NativeTheme* native_theme = ui::NativeTheme::instance();
411 411
412 gfx::NativeTheme::ExtraParams button_params; 412 ui::NativeTheme::ExtraParams button_params;
413 button_params.scrollbar_arrow.is_hovering = false; 413 button_params.scrollbar_arrow.is_hovering = false;
414 gfx::Size button_size = native_theme->GetPartSize( 414 gfx::Size button_size = native_theme->GetPartSize(
415 gfx::NativeTheme::kScrollbarUpArrow, 415 ui::NativeTheme::kScrollbarUpArrow,
416 gfx::NativeTheme::kNormal, 416 ui::NativeTheme::kNormal,
417 button_params); 417 button_params);
418 418
419 gfx::NativeTheme::ExtraParams thumb_params; 419 ui::NativeTheme::ExtraParams thumb_params;
420 thumb_params.scrollbar_thumb.is_hovering = false; 420 thumb_params.scrollbar_thumb.is_hovering = false;
421 gfx::Size track_size = native_theme->GetPartSize( 421 gfx::Size track_size = native_theme->GetPartSize(
422 gfx::NativeTheme::kScrollbarVerticalThumb, 422 ui::NativeTheme::kScrollbarVerticalThumb,
423 gfx::NativeTheme::kNormal, 423 ui::NativeTheme::kNormal,
424 thumb_params); 424 thumb_params);
425 425
426 return std::max(track_size.width(), button_size.width()); 426 return std::max(track_size.width(), button_size.width());
427 } 427 }
428 #endif 428 #endif
429 429
430 } // namespace views 430 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/scrollbar/native_scroll_bar_views.h ('k') | ui/views/controls/tabbed_pane/native_tabbed_pane_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698