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

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

Issue 10387121: Revert 136996 - ui: Move NativeTheme files into ui/base/native_theme/ directory. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: 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 ui::NativeTheme::ExtraParams GetNativeThemeParams() const; 44 gfx::NativeTheme::ExtraParams GetNativeThemeParams() const;
45 ui::NativeTheme::Part GetNativeThemePart() const; 45 gfx::NativeTheme::Part GetNativeThemePart() const;
46 ui::NativeTheme::State GetNativeThemeState() const; 46 gfx::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 ui::NativeTheme::ExtraParams GetNativeThemeParams() const; 66 gfx::NativeTheme::ExtraParams GetNativeThemeParams() const;
67 ui::NativeTheme::Part GetNativeThemePart() const; 67 gfx::NativeTheme::Part GetNativeThemePart() const;
68 ui::NativeTheme::State GetNativeThemeState() const; 68 gfx::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 ui::NativeTheme* native_theme = ui::NativeTheme::instance(); 89 const gfx::NativeTheme* native_theme = gfx::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 ui::NativeTheme* native_theme = ui::NativeTheme::instance(); 96 const gfx::NativeTheme* native_theme = gfx::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 ui::NativeTheme::ExtraParams ScrollBarButton::GetNativeThemeParams() const { 102 gfx::NativeTheme::ExtraParams
103 ui::NativeTheme::ExtraParams params; 103 ScrollBarButton::GetNativeThemeParams() const {
104 gfx::NativeTheme::ExtraParams params;
104 105
105 switch (state_) { 106 switch (state_) {
106 case CustomButton::BS_HOT: 107 case CustomButton::BS_HOT:
107 params.scrollbar_arrow.is_hovering = true; 108 params.scrollbar_arrow.is_hovering = true;
108 break; 109 break;
109 default: 110 default:
110 params.scrollbar_arrow.is_hovering = false; 111 params.scrollbar_arrow.is_hovering = false;
111 break; 112 break;
112 } 113 }
113 114
114 return params; 115 return params;
115 } 116 }
116 117
117 ui::NativeTheme::Part ScrollBarButton::GetNativeThemePart() const { 118 gfx::NativeTheme::Part
119 ScrollBarButton::GetNativeThemePart() const {
118 switch (type_) { 120 switch (type_) {
119 case UP: 121 case UP:
120 return ui::NativeTheme::kScrollbarUpArrow; 122 return gfx::NativeTheme::kScrollbarUpArrow;
121 case DOWN: 123 case DOWN:
122 return ui::NativeTheme::kScrollbarDownArrow; 124 return gfx::NativeTheme::kScrollbarDownArrow;
123 case LEFT: 125 case LEFT:
124 return ui::NativeTheme::kScrollbarLeftArrow; 126 return gfx::NativeTheme::kScrollbarLeftArrow;
125 case RIGHT: 127 case RIGHT:
126 return ui::NativeTheme::kScrollbarRightArrow; 128 return gfx::NativeTheme::kScrollbarRightArrow;
127 default: 129 default:
128 return ui::NativeTheme::kScrollbarUpArrow; 130 return gfx::NativeTheme::kScrollbarUpArrow;
129 } 131 }
130 } 132 }
131 133
132 ui::NativeTheme::State ScrollBarButton::GetNativeThemeState() const { 134 gfx::NativeTheme::State
133 ui::NativeTheme::State state; 135 ScrollBarButton::GetNativeThemeState() const {
136 gfx::NativeTheme::State state;
134 137
135 switch (state_) { 138 switch (state_) {
136 case CustomButton::BS_HOT: 139 case CustomButton::BS_HOT:
137 state = ui::NativeTheme::kHovered; 140 state = gfx::NativeTheme::kHovered;
138 break; 141 break;
139 case CustomButton::BS_PUSHED: 142 case CustomButton::BS_PUSHED:
140 state = ui::NativeTheme::kPressed; 143 state = gfx::NativeTheme::kPressed;
141 break; 144 break;
142 case CustomButton::BS_DISABLED: 145 case CustomButton::BS_DISABLED:
143 state = ui::NativeTheme::kDisabled; 146 state = gfx::NativeTheme::kDisabled;
144 break; 147 break;
145 case CustomButton::BS_NORMAL: 148 case CustomButton::BS_NORMAL:
146 default: 149 default:
147 state = ui::NativeTheme::kNormal; 150 state = gfx::NativeTheme::kNormal;
148 break; 151 break;
149 } 152 }
150 153
151 return state; 154 return state;
152 } 155 }
153 156
154 ///////////////////////////////////////////////////////////////////////////// 157 /////////////////////////////////////////////////////////////////////////////
155 // ScrollBarThumb 158 // ScrollBarThumb
156 159
157 ScrollBarThumb::ScrollBarThumb(BaseScrollBar* scroll_bar) 160 ScrollBarThumb::ScrollBarThumb(BaseScrollBar* scroll_bar)
158 : BaseScrollBarThumb(scroll_bar), 161 : BaseScrollBarThumb(scroll_bar),
159 scroll_bar_(scroll_bar) { 162 scroll_bar_(scroll_bar) {
160 set_focusable(false); 163 set_focusable(false);
161 set_accessibility_focusable(false); 164 set_accessibility_focusable(false);
162 } 165 }
163 166
164 ScrollBarThumb::~ScrollBarThumb() { 167 ScrollBarThumb::~ScrollBarThumb() {
165 } 168 }
166 169
167 gfx::Size ScrollBarThumb::GetPreferredSize() { 170 gfx::Size ScrollBarThumb::GetPreferredSize() {
168 const ui::NativeTheme* native_theme = ui::NativeTheme::instance(); 171 const gfx::NativeTheme* native_theme = gfx::NativeTheme::instance();
169 return native_theme->GetPartSize(GetNativeThemePart(), 172 return native_theme->GetPartSize(GetNativeThemePart(),
170 GetNativeThemeState(), 173 GetNativeThemeState(),
171 GetNativeThemeParams()); 174 GetNativeThemeParams());
172 } 175 }
173 176
174 void ScrollBarThumb::OnPaint(gfx::Canvas* canvas) { 177 void ScrollBarThumb::OnPaint(gfx::Canvas* canvas) {
175 const ui::NativeTheme* native_theme = ui::NativeTheme::instance(); 178 const gfx::NativeTheme* native_theme = gfx::NativeTheme::instance();
176 179
177 native_theme->Paint(canvas->sk_canvas(), 180 native_theme->Paint(canvas->sk_canvas(),
178 GetNativeThemePart(), 181 GetNativeThemePart(),
179 GetNativeThemeState(), 182 GetNativeThemeState(),
180 GetLocalBounds(), 183 GetLocalBounds(),
181 GetNativeThemeParams()); 184 GetNativeThemeParams());
182 } 185 }
183 186
184 ui::NativeTheme::ExtraParams ScrollBarThumb::GetNativeThemeParams() const { 187 gfx::NativeTheme::ExtraParams
185 ui::NativeTheme::ExtraParams params; 188 ScrollBarThumb::GetNativeThemeParams() const {
189 gfx::NativeTheme::ExtraParams params;
186 190
187 switch (GetState()) { 191 switch (GetState()) {
188 case CustomButton::BS_HOT: 192 case CustomButton::BS_HOT:
189 params.scrollbar_thumb.is_hovering = true; 193 params.scrollbar_thumb.is_hovering = true;
190 break; 194 break;
191 default: 195 default:
192 params.scrollbar_thumb.is_hovering = false; 196 params.scrollbar_thumb.is_hovering = false;
193 break; 197 break;
194 } 198 }
195 199
196 return params; 200 return params;
197 } 201 }
198 202
199 ui::NativeTheme::Part ScrollBarThumb::GetNativeThemePart() const { 203 gfx::NativeTheme::Part ScrollBarThumb::GetNativeThemePart() const {
200 if (scroll_bar_->IsHorizontal()) 204 if (scroll_bar_->IsHorizontal())
201 return ui::NativeTheme::kScrollbarHorizontalThumb; 205 return gfx::NativeTheme::kScrollbarHorizontalThumb;
202 return ui::NativeTheme::kScrollbarVerticalThumb; 206 return gfx::NativeTheme::kScrollbarVerticalThumb;
203 } 207 }
204 208
205 ui::NativeTheme::State ScrollBarThumb::GetNativeThemeState() const { 209 gfx::NativeTheme::State ScrollBarThumb::GetNativeThemeState() const {
206 ui::NativeTheme::State state; 210 gfx::NativeTheme::State state;
207 211
208 switch (GetState()) { 212 switch (GetState()) {
209 case CustomButton::BS_HOT: 213 case CustomButton::BS_HOT:
210 state = ui::NativeTheme::kHovered; 214 state = gfx::NativeTheme::kHovered;
211 break; 215 break;
212 case CustomButton::BS_PUSHED: 216 case CustomButton::BS_PUSHED:
213 state = ui::NativeTheme::kPressed; 217 state = gfx::NativeTheme::kPressed;
214 break; 218 break;
215 case CustomButton::BS_DISABLED: 219 case CustomButton::BS_DISABLED:
216 state = ui::NativeTheme::kDisabled; 220 state = gfx::NativeTheme::kDisabled;
217 break; 221 break;
218 case CustomButton::BS_NORMAL: 222 case CustomButton::BS_NORMAL:
219 default: 223 default:
220 state = ui::NativeTheme::kNormal; 224 state = gfx::NativeTheme::kNormal;
221 break; 225 break;
222 } 226 }
223 227
224 return state; 228 return state;
225 } 229 }
226 230
227 } // namespace 231 } // namespace
228 232
229 //////////////////////////////////////////////////////////////////////////////// 233 ////////////////////////////////////////////////////////////////////////////////
230 // NativeScrollBarViews, public: 234 // NativeScrollBarViews, public:
231 235
232 const char NativeScrollBarViews::kViewClassName[] = 236 const char NativeScrollBarViews::kViewClassName[] =
233 "views/NativeScrollBarViews"; 237 "views/NativeScrollBarViews";
234 238
235 NativeScrollBarViews::NativeScrollBarViews(NativeScrollBar* scroll_bar) 239 NativeScrollBarViews::NativeScrollBarViews(NativeScrollBar* scroll_bar)
236 : BaseScrollBar(scroll_bar->IsHorizontal(), 240 : BaseScrollBar(scroll_bar->IsHorizontal(),
237 new ScrollBarThumb(this)), 241 new ScrollBarThumb(this)),
238 native_scroll_bar_(scroll_bar) { 242 native_scroll_bar_(scroll_bar) {
239 set_controller(native_scroll_bar_->controller()); 243 set_controller(native_scroll_bar_->controller());
240 244
241 if (native_scroll_bar_->IsHorizontal()) { 245 if (native_scroll_bar_->IsHorizontal()) {
242 prev_button_ = new ScrollBarButton(this, ScrollBarButton::LEFT); 246 prev_button_ = new ScrollBarButton(this, ScrollBarButton::LEFT);
243 next_button_ = new ScrollBarButton(this, ScrollBarButton::RIGHT); 247 next_button_ = new ScrollBarButton(this, ScrollBarButton::RIGHT);
244 248
245 part_ = ui::NativeTheme::kScrollbarHorizontalTrack; 249 part_ = gfx::NativeTheme::kScrollbarHorizontalTrack;
246 } else { 250 } else {
247 prev_button_ = new ScrollBarButton(this, ScrollBarButton::UP); 251 prev_button_ = new ScrollBarButton(this, ScrollBarButton::UP);
248 next_button_ = new ScrollBarButton(this, ScrollBarButton::DOWN); 252 next_button_ = new ScrollBarButton(this, ScrollBarButton::DOWN);
249 253
250 part_ = ui::NativeTheme::kScrollbarVerticalTrack; 254 part_ = gfx::NativeTheme::kScrollbarVerticalTrack;
251 } 255 }
252 256
253 state_ = ui::NativeTheme::kNormal; 257 state_ = gfx::NativeTheme::kNormal;
254 258
255 AddChildView(prev_button_); 259 AddChildView(prev_button_);
256 AddChildView(next_button_); 260 AddChildView(next_button_);
257 261
258 prev_button_->set_context_menu_controller(this); 262 prev_button_->set_context_menu_controller(this);
259 next_button_->set_context_menu_controller(this); 263 next_button_->set_context_menu_controller(this);
260 } 264 }
261 265
262 NativeScrollBarViews::~NativeScrollBarViews() { 266 NativeScrollBarViews::~NativeScrollBarViews() {
263 } 267 }
(...skipping 10 matching lines...) Expand all
274 size.width(), size.height()); 278 size.width(), size.height());
275 } else { 279 } else {
276 next_button_->SetBounds(0, height() - size.height(), 280 next_button_->SetBounds(0, height() - size.height(),
277 size.width(), size.height()); 281 size.width(), size.height());
278 } 282 }
279 283
280 GetThumb()->SetBoundsRect(GetTrackBounds()); 284 GetThumb()->SetBoundsRect(GetTrackBounds());
281 } 285 }
282 286
283 void NativeScrollBarViews::OnPaint(gfx::Canvas* canvas) { 287 void NativeScrollBarViews::OnPaint(gfx::Canvas* canvas) {
284 const ui::NativeTheme* native_theme = ui::NativeTheme::instance(); 288 const gfx::NativeTheme* native_theme = gfx::NativeTheme::instance();
285 gfx::Rect bounds = GetTrackBounds(); 289 gfx::Rect bounds = GetTrackBounds();
286 290
287 if (bounds.IsEmpty()) 291 if (bounds.IsEmpty())
288 return; 292 return;
289 293
290 params_.scrollbar_track.track_x = bounds.x(); 294 params_.scrollbar_track.track_x = bounds.x();
291 params_.scrollbar_track.track_y = bounds.y(); 295 params_.scrollbar_track.track_y = bounds.y();
292 params_.scrollbar_track.track_width = bounds.width(); 296 params_.scrollbar_track.track_width = bounds.width();
293 params_.scrollbar_track.track_height = bounds.height(); 297 params_.scrollbar_track.track_height = bounds.height();
294 298
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 // NativewScrollBarWrapper, public: 379 // NativewScrollBarWrapper, public:
376 380
377 // static 381 // static
378 NativeScrollBarWrapper* NativeScrollBarWrapper::CreateWrapper( 382 NativeScrollBarWrapper* NativeScrollBarWrapper::CreateWrapper(
379 NativeScrollBar* scroll_bar) { 383 NativeScrollBar* scroll_bar) {
380 return new NativeScrollBarViews(scroll_bar); 384 return new NativeScrollBarViews(scroll_bar);
381 } 385 }
382 386
383 // static 387 // static
384 int NativeScrollBarWrapper::GetHorizontalScrollBarHeight() { 388 int NativeScrollBarWrapper::GetHorizontalScrollBarHeight() {
385 const ui::NativeTheme* native_theme = ui::NativeTheme::instance(); 389 const gfx::NativeTheme* native_theme = gfx::NativeTheme::instance();
386 390
387 ui::NativeTheme::ExtraParams button_params; 391 gfx::NativeTheme::ExtraParams button_params;
388 button_params.scrollbar_arrow.is_hovering = false; 392 button_params.scrollbar_arrow.is_hovering = false;
389 gfx::Size button_size = native_theme->GetPartSize( 393 gfx::Size button_size = native_theme->GetPartSize(
390 ui::NativeTheme::kScrollbarLeftArrow, 394 gfx::NativeTheme::kScrollbarLeftArrow,
391 ui::NativeTheme::kNormal, 395 gfx::NativeTheme::kNormal,
392 button_params); 396 button_params);
393 397
394 ui::NativeTheme::ExtraParams thumb_params; 398 gfx::NativeTheme::ExtraParams thumb_params;
395 thumb_params.scrollbar_thumb.is_hovering = false; 399 thumb_params.scrollbar_thumb.is_hovering = false;
396 gfx::Size track_size = native_theme->GetPartSize( 400 gfx::Size track_size = native_theme->GetPartSize(
397 ui::NativeTheme::kScrollbarHorizontalThumb, 401 gfx::NativeTheme::kScrollbarHorizontalThumb,
398 ui::NativeTheme::kNormal, 402 gfx::NativeTheme::kNormal,
399 thumb_params); 403 thumb_params);
400 404
401 return std::max(track_size.height(), button_size.height()); 405 return std::max(track_size.height(), button_size.height());
402 } 406 }
403 407
404 // static 408 // static
405 int NativeScrollBarWrapper::GetVerticalScrollBarWidth() { 409 int NativeScrollBarWrapper::GetVerticalScrollBarWidth() {
406 const ui::NativeTheme* native_theme = ui::NativeTheme::instance(); 410 const gfx::NativeTheme* native_theme = gfx::NativeTheme::instance();
407 411
408 ui::NativeTheme::ExtraParams button_params; 412 gfx::NativeTheme::ExtraParams button_params;
409 button_params.scrollbar_arrow.is_hovering = false; 413 button_params.scrollbar_arrow.is_hovering = false;
410 gfx::Size button_size = native_theme->GetPartSize( 414 gfx::Size button_size = native_theme->GetPartSize(
411 ui::NativeTheme::kScrollbarUpArrow, 415 gfx::NativeTheme::kScrollbarUpArrow,
412 ui::NativeTheme::kNormal, 416 gfx::NativeTheme::kNormal,
413 button_params); 417 button_params);
414 418
415 ui::NativeTheme::ExtraParams thumb_params; 419 gfx::NativeTheme::ExtraParams thumb_params;
416 thumb_params.scrollbar_thumb.is_hovering = false; 420 thumb_params.scrollbar_thumb.is_hovering = false;
417 gfx::Size track_size = native_theme->GetPartSize( 421 gfx::Size track_size = native_theme->GetPartSize(
418 ui::NativeTheme::kScrollbarVerticalThumb, 422 gfx::NativeTheme::kScrollbarVerticalThumb,
419 ui::NativeTheme::kNormal, 423 gfx::NativeTheme::kNormal,
420 thumb_params); 424 thumb_params);
421 425
422 return std::max(track_size.width(), button_size.width()); 426 return std::max(track_size.width(), button_size.width());
423 } 427 }
424 #endif 428 #endif
425 429
426 } // 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