Display new Autofill UI Contents in Views
[chromium-blink-merge.git] / webkit / glue / webthemeengine_impl_win.cc
blob7e60501664819408c5bb177f8718dea67986b8fc
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
3 // found in the LICENSE file.
5 #include "webkit/glue/webthemeengine_impl_win.h"
7 #include <vsstyle.h> // To convert to ui::NativeTheme::State
9 #include "base/logging.h"
10 #include "skia/ext/platform_canvas.h"
11 #include "skia/ext/skia_utils_win.h"
12 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h"
13 #include "ui/base/native_theme/native_theme.h"
15 using WebKit::WebCanvas;
16 using WebKit::WebColor;
17 using WebKit::WebRect;
18 using WebKit::WebSize;
20 namespace webkit_glue {
22 static RECT WebRectToRECT(const WebRect& rect) {
23 RECT result;
24 result.left = rect.x;
25 result.top = rect.y;
26 result.right = rect.x + rect.width;
27 result.bottom = rect.y + rect.height;
28 return result;
31 static ui::NativeTheme::State WebButtonStateToGfx(
32 int part, int state, ui::NativeTheme::ButtonExtraParams* extra) {
33 ui::NativeTheme::State gfx_state = ui::NativeTheme::kNormal;
34 // Native buttons have a different focus style.
35 extra->is_focused = false;
37 if (part == BP_PUSHBUTTON) {
38 switch (state) {
39 case PBS_NORMAL:
40 gfx_state = ui::NativeTheme::kNormal;
41 extra->checked = false;
42 extra->indeterminate = false;
43 extra->is_default = false;
44 break;
45 case PBS_HOT:
46 gfx_state = ui::NativeTheme::kHovered;
47 extra->checked = false;
48 extra->indeterminate = false;
49 extra->is_default = false;
50 break;
51 case PBS_PRESSED:
52 gfx_state = ui::NativeTheme::kPressed;
53 extra->checked = false;
54 extra->indeterminate = false;
55 extra->is_default = false;
56 break;
57 case PBS_DISABLED:
58 gfx_state = ui::NativeTheme::kDisabled;
59 extra->checked = false;
60 extra->indeterminate = false;
61 extra->is_default = false;
62 break;
63 case PBS_DEFAULTED:
64 gfx_state = ui::NativeTheme::kNormal;
65 extra->checked = false;
66 extra->indeterminate = false;
67 extra->is_default = true;
68 break;
69 case PBS_DEFAULTED_ANIMATING:
70 gfx_state = ui::NativeTheme::kNormal;
71 extra->checked = false;
72 extra->indeterminate = false;
73 extra->is_default = true;
74 break;
75 default:
76 NOTREACHED() << "Invalid state: " << state;
78 } else if (part == BP_RADIOBUTTON) {
79 switch (state) {
80 case RBS_UNCHECKEDNORMAL:
81 gfx_state = ui::NativeTheme::kNormal;
82 extra->checked = false;
83 extra->indeterminate = false;
84 extra->is_default = false;
85 break;
86 case RBS_UNCHECKEDHOT:
87 gfx_state = ui::NativeTheme::kHovered;
88 extra->checked = false;
89 extra->indeterminate = false;
90 extra->is_default = false;
91 break;
92 case RBS_UNCHECKEDPRESSED:
93 gfx_state = ui::NativeTheme::kPressed;
94 extra->checked = false;
95 extra->indeterminate = false;
96 extra->is_default = false;
97 break;
98 case RBS_UNCHECKEDDISABLED:
99 gfx_state = ui::NativeTheme::kDisabled;
100 extra->checked = false;
101 extra->indeterminate = false;
102 extra->is_default = false;
103 break;
104 case RBS_CHECKEDNORMAL:
105 gfx_state = ui::NativeTheme::kNormal;
106 extra->checked = true;
107 extra->indeterminate = false;
108 extra->is_default = false;
109 break;
110 case RBS_CHECKEDHOT:
111 gfx_state = ui::NativeTheme::kHovered;
112 extra->checked = true;
113 extra->indeterminate = false;
114 extra->is_default = false;
115 break;
116 case RBS_CHECKEDPRESSED:
117 gfx_state = ui::NativeTheme::kPressed;
118 extra->checked = true;
119 extra->indeterminate = false;
120 extra->is_default = false;
121 break;
122 case RBS_CHECKEDDISABLED:
123 gfx_state = ui::NativeTheme::kDisabled;
124 extra->checked = true;
125 extra->indeterminate = false;
126 extra->is_default = false;
127 break;
128 default:
129 NOTREACHED() << "Invalid state: " << state;
130 break;
132 } else if (part == BP_CHECKBOX) {
133 switch (state) {
134 case CBS_UNCHECKEDNORMAL:
135 gfx_state = ui::NativeTheme::kNormal;
136 extra->checked = false;
137 extra->indeterminate = false;
138 extra->is_default = false;
139 break;
140 case CBS_UNCHECKEDHOT:
141 gfx_state = ui::NativeTheme::kHovered;
142 extra->checked = false;
143 extra->indeterminate = false;
144 extra->is_default = false;
145 break;
146 case CBS_UNCHECKEDPRESSED:
147 gfx_state = ui::NativeTheme::kPressed;
148 extra->checked = false;
149 extra->indeterminate = false;
150 extra->is_default = false;
151 break;
152 case CBS_UNCHECKEDDISABLED:
153 gfx_state = ui::NativeTheme::kDisabled;
154 extra->checked = false;
155 extra->indeterminate = false;
156 extra->is_default = false;
157 break;
158 case CBS_CHECKEDNORMAL:
159 gfx_state = ui::NativeTheme::kNormal;
160 extra->checked = true;
161 extra->indeterminate = false;
162 extra->is_default = false;
163 break;
164 case CBS_CHECKEDHOT:
165 gfx_state = ui::NativeTheme::kHovered;
166 extra->checked = true;
167 extra->indeterminate = false;
168 extra->is_default = false;
169 break;
170 case CBS_CHECKEDPRESSED:
171 gfx_state = ui::NativeTheme::kPressed;
172 extra->checked = true;
173 extra->indeterminate = false;
174 extra->is_default = false;
175 break;
176 case CBS_CHECKEDDISABLED:
177 gfx_state = ui::NativeTheme::kDisabled;
178 extra->checked = true;
179 extra->indeterminate = false;
180 extra->is_default = false;
181 break;
182 case CBS_MIXEDNORMAL:
183 gfx_state = ui::NativeTheme::kNormal;
184 extra->checked = false;
185 extra->indeterminate = true;
186 extra->is_default = false;
187 break;
188 case CBS_MIXEDHOT:
189 gfx_state = ui::NativeTheme::kHovered;
190 extra->checked = false;
191 extra->indeterminate = true;
192 extra->is_default = false;
193 break;
194 case CBS_MIXEDPRESSED:
195 gfx_state = ui::NativeTheme::kPressed;
196 extra->checked = false;
197 extra->indeterminate = true;
198 extra->is_default = false;
199 break;
200 case CBS_MIXEDDISABLED:
201 gfx_state = ui::NativeTheme::kDisabled;
202 extra->checked = false;
203 extra->indeterminate = true;
204 extra->is_default = false;
205 break;
206 case CBS_IMPLICITNORMAL:
207 gfx_state = ui::NativeTheme::kNormal;
208 extra->checked = false;
209 extra->indeterminate = false;
210 extra->is_default = false;
211 break;
212 case CBS_IMPLICITHOT:
213 gfx_state = ui::NativeTheme::kHovered;
214 extra->checked = false;
215 extra->indeterminate = false;
216 extra->is_default = false;
217 break;
218 case CBS_IMPLICITPRESSED:
219 gfx_state = ui::NativeTheme::kPressed;
220 extra->checked = false;
221 extra->indeterminate = false;
222 extra->is_default = false;
223 break;
224 case CBS_IMPLICITDISABLED:
225 gfx_state = ui::NativeTheme::kDisabled;
226 extra->checked = false;
227 extra->indeterminate = false;
228 extra->is_default = false;
229 break;
230 case CBS_EXCLUDEDNORMAL:
231 gfx_state = ui::NativeTheme::kNormal;
232 extra->checked = false;
233 extra->indeterminate = false;
234 extra->is_default = false;
235 break;
236 case CBS_EXCLUDEDHOT:
237 gfx_state = ui::NativeTheme::kHovered;
238 extra->checked = false;
239 extra->indeterminate = false;
240 extra->is_default = false;
241 break;
242 case CBS_EXCLUDEDPRESSED:
243 gfx_state = ui::NativeTheme::kPressed;
244 extra->checked = false;
245 extra->indeterminate = false;
246 extra->is_default = false;
247 break;
248 case CBS_EXCLUDEDDISABLED:
249 gfx_state = ui::NativeTheme::kDisabled;
250 extra->checked = false;
251 extra->indeterminate = false;
252 extra->is_default = false;
253 break;
254 default:
255 NOTREACHED() << "Invalid state: " << state;
256 break;
258 } else if (part == BP_GROUPBOX) {
259 switch (state) {
260 case GBS_NORMAL:
261 gfx_state = ui::NativeTheme::kNormal;
262 extra->checked = false;
263 extra->indeterminate = false;
264 extra->is_default = false;
265 break;
266 case GBS_DISABLED:
267 gfx_state = ui::NativeTheme::kDisabled;
268 extra->checked = false;
269 extra->indeterminate = false;
270 extra->is_default = false;
271 break;
272 default:
273 NOTREACHED() << "Invalid state: " << state;
274 break;
276 } else if (part == BP_COMMANDLINK) {
277 switch (state) {
278 case CMDLS_NORMAL:
279 gfx_state = ui::NativeTheme::kNormal;
280 extra->checked = false;
281 extra->indeterminate = false;
282 extra->is_default = false;
283 break;
284 case CMDLS_HOT:
285 gfx_state = ui::NativeTheme::kHovered;
286 extra->checked = false;
287 extra->indeterminate = false;
288 extra->is_default = false;
289 break;
290 case CMDLS_PRESSED:
291 gfx_state = ui::NativeTheme::kPressed;
292 extra->checked = false;
293 extra->indeterminate = false;
294 extra->is_default = false;
295 break;
296 case CMDLS_DISABLED:
297 gfx_state = ui::NativeTheme::kDisabled;
298 extra->checked = false;
299 extra->indeterminate = false;
300 extra->is_default = false;
301 break;
302 case CMDLS_DEFAULTED:
303 gfx_state = ui::NativeTheme::kNormal;
304 extra->checked = false;
305 extra->indeterminate = false;
306 extra->is_default = true;
307 break;
308 case CMDLS_DEFAULTED_ANIMATING:
309 gfx_state = ui::NativeTheme::kNormal;
310 extra->checked = false;
311 extra->indeterminate = false;
312 extra->is_default = true;
313 break;
314 default:
315 NOTREACHED() << "Invalid state: " << state;
316 break;
318 } else if (part == BP_COMMANDLINKGLYPH) {
319 switch (state) {
320 case CMDLGS_NORMAL:
321 gfx_state = ui::NativeTheme::kNormal;
322 extra->checked = false;
323 extra->indeterminate = false;
324 extra->is_default = false;
325 break;
326 case CMDLGS_HOT:
327 gfx_state = ui::NativeTheme::kHovered;
328 extra->checked = false;
329 extra->indeterminate = false;
330 extra->is_default = false;
331 break;
332 case CMDLGS_PRESSED:
333 gfx_state = ui::NativeTheme::kPressed;
334 extra->checked = false;
335 extra->indeterminate = false;
336 extra->is_default = false;
337 break;
338 case CMDLGS_DISABLED:
339 gfx_state = ui::NativeTheme::kDisabled;
340 extra->checked = false;
341 extra->indeterminate = false;
342 extra->is_default = false;
343 break;
344 case CMDLGS_DEFAULTED:
345 gfx_state = ui::NativeTheme::kNormal;
346 extra->checked = false;
347 extra->indeterminate = false;
348 extra->is_default = true;
349 break;
350 default:
351 NOTREACHED() << "Invalid state: " << state;
352 break;
355 return gfx_state;
358 void WebThemeEngineImpl::paintButton(
359 WebCanvas* canvas, int part, int state, int classic_state,
360 const WebRect& rect) {
361 ui::NativeTheme::Part native_part = ui::NativeTheme::kPushButton;
362 switch (part) {
363 case BP_PUSHBUTTON:
364 native_part = ui::NativeTheme::kPushButton;
365 break;
366 case BP_CHECKBOX:
367 native_part = ui::NativeTheme::kCheckbox;
368 break;
369 case BP_RADIOBUTTON:
370 native_part = ui::NativeTheme::kRadio;
371 break;
372 default:
373 NOTREACHED() << "Invalid part: " << part;
374 break;
376 ui::NativeTheme::ExtraParams extra;
377 ui::NativeTheme::State native_state = WebButtonStateToGfx(part, state,
378 &extra.button);
379 extra.button.classic_state = classic_state;
380 gfx::Rect gfx_rect(rect.x, rect.y, rect.width, rect.height);
381 ui::NativeTheme::instance()->Paint(canvas, native_part,
382 native_state, gfx_rect, extra);
385 static ui::NativeTheme::State WebListMenuStateToGfx(int part, int state) {
386 ui::NativeTheme::State gfx_state = ui::NativeTheme::kNormal;
388 switch (part) {
389 case CP_DROPDOWNBUTTON:
390 switch (state) {
391 case CBXS_NORMAL:
392 gfx_state = ui::NativeTheme::kNormal;
393 break;
394 case CBXS_HOT:
395 gfx_state = ui::NativeTheme::kHovered;
396 break;
397 case CBXS_PRESSED:
398 gfx_state = ui::NativeTheme::kPressed;
399 break;
400 case CBXS_DISABLED:
401 gfx_state = ui::NativeTheme::kDisabled;
402 break;
403 default:
404 NOTREACHED() << "Invalid state: " << state;
405 break;
407 break;
408 default:
409 NOTREACHED() << "Invalid part: " << part;
410 break;
412 return gfx_state;
415 void WebThemeEngineImpl::paintMenuList(
416 WebCanvas* canvas, int part, int state, int classic_state,
417 const WebRect& rect) {
418 ui::NativeTheme::Part native_part = ui::NativeTheme::kMenuList;
419 switch (part) {
420 case CP_DROPDOWNBUTTON:
421 native_part = ui::NativeTheme::kMenuList;
422 break;
423 default:
424 NOTREACHED() << "Invalid part: " << part;
425 break;
427 ui::NativeTheme::State native_state = WebListMenuStateToGfx(part, state);
428 gfx::Rect gfx_rect(rect.x, rect.y, rect.width, rect.height);
429 ui::NativeTheme::ExtraParams extra;
430 extra.menu_list.classic_state = classic_state;
431 ui::NativeTheme::instance()->Paint(canvas, native_part,
432 native_state, gfx_rect, extra);
435 static ui::NativeTheme::State WebScrollbarArrowStateToGfx(
436 int state, ui::NativeTheme::Part* part,
437 ui::NativeTheme::ScrollbarArrowExtraParams* extra) {
438 ui::NativeTheme::State gfx_state = ui::NativeTheme::kNormal;
439 switch (state) {
440 case ABS_UPNORMAL:
441 gfx_state = ui::NativeTheme::kNormal;
442 *part = ui::NativeTheme::kScrollbarUpArrow;
443 extra->is_hovering = false;
444 break;
445 case ABS_UPHOT:
446 gfx_state = ui::NativeTheme::kHovered;
447 *part = ui::NativeTheme::kScrollbarUpArrow;
448 extra->is_hovering = false;
449 break;
450 case ABS_UPPRESSED:
451 gfx_state = ui::NativeTheme::kPressed;
452 *part = ui::NativeTheme::kScrollbarUpArrow;
453 extra->is_hovering = false;
454 break;
455 case ABS_UPDISABLED:
456 gfx_state = ui::NativeTheme::kDisabled;
457 *part = ui::NativeTheme::kScrollbarUpArrow;
458 extra->is_hovering = false;
459 break;
460 case ABS_DOWNNORMAL:
461 gfx_state = ui::NativeTheme::kNormal;
462 *part = ui::NativeTheme::kScrollbarDownArrow;
463 extra->is_hovering = false;
464 break;
465 case ABS_DOWNHOT:
466 gfx_state = ui::NativeTheme::kHovered;
467 *part = ui::NativeTheme::kScrollbarDownArrow;
468 extra->is_hovering = false;
469 break;
470 case ABS_DOWNPRESSED:
471 gfx_state = ui::NativeTheme::kPressed;
472 *part = ui::NativeTheme::kScrollbarDownArrow;
473 extra->is_hovering = false;
474 break;
475 case ABS_DOWNDISABLED:
476 gfx_state = ui::NativeTheme::kDisabled;
477 *part = ui::NativeTheme::kScrollbarDownArrow;
478 extra->is_hovering = false;
479 break;
480 case ABS_LEFTNORMAL:
481 gfx_state = ui::NativeTheme::kNormal;
482 *part = ui::NativeTheme::kScrollbarLeftArrow;
483 extra->is_hovering = false;
484 break;
485 case ABS_LEFTHOT:
486 gfx_state = ui::NativeTheme::kHovered;
487 *part = ui::NativeTheme::kScrollbarLeftArrow;
488 extra->is_hovering = false;
489 break;
490 case ABS_LEFTPRESSED:
491 gfx_state = ui::NativeTheme::kPressed;
492 *part = ui::NativeTheme::kScrollbarLeftArrow;
493 extra->is_hovering = false;
494 break;
495 case ABS_LEFTDISABLED:
496 gfx_state = ui::NativeTheme::kDisabled;
497 *part = ui::NativeTheme::kScrollbarLeftArrow;
498 extra->is_hovering = false;
499 break;
500 case ABS_RIGHTNORMAL:
501 gfx_state = ui::NativeTheme::kNormal;
502 *part = ui::NativeTheme::kScrollbarRightArrow;
503 extra->is_hovering = false;
504 break;
505 case ABS_RIGHTHOT:
506 gfx_state = ui::NativeTheme::kHovered;
507 *part = ui::NativeTheme::kScrollbarRightArrow;
508 extra->is_hovering = false;
509 break;
510 case ABS_RIGHTPRESSED:
511 gfx_state = ui::NativeTheme::kPressed;
512 *part = ui::NativeTheme::kScrollbarRightArrow;
513 extra->is_hovering = false;
514 break;
515 case ABS_RIGHTDISABLED:
516 gfx_state = ui::NativeTheme::kDisabled;
517 *part = ui::NativeTheme::kScrollbarRightArrow;
518 extra->is_hovering = false;
519 break;
520 case ABS_UPHOVER:
521 gfx_state = ui::NativeTheme::kHovered;
522 *part = ui::NativeTheme::kScrollbarUpArrow;
523 extra->is_hovering = true;
524 break;
525 case ABS_DOWNHOVER:
526 gfx_state = ui::NativeTheme::kHovered;
527 *part = ui::NativeTheme::kScrollbarDownArrow;
528 extra->is_hovering = true;
529 break;
530 case ABS_LEFTHOVER:
531 gfx_state = ui::NativeTheme::kHovered;
532 *part = ui::NativeTheme::kScrollbarLeftArrow;
533 extra->is_hovering = true;
534 break;
535 case ABS_RIGHTHOVER:
536 gfx_state = ui::NativeTheme::kHovered;
537 *part = ui::NativeTheme::kScrollbarRightArrow;
538 extra->is_hovering = true;
539 break;
540 default:
541 NOTREACHED() << "Invalid state: " << state;
542 break;
544 return gfx_state;
547 void WebThemeEngineImpl::paintScrollbarArrow(
548 WebCanvas* canvas, int state, int classic_state, const WebRect& rect) {
549 ui::NativeTheme::Part native_part;
550 ui::NativeTheme::ExtraParams extra;
551 ui::NativeTheme::State native_state = WebScrollbarArrowStateToGfx(
552 state, &native_part, &extra.scrollbar_arrow);
553 gfx::Rect gfx_rect(rect.x, rect.y, rect.width, rect.height);
554 ui::NativeTheme::instance()->Paint(canvas, native_part,
555 native_state, gfx_rect, extra);
558 static ui::NativeTheme::State WebScrollbarThumbStateToGfx(
559 int state, ui::NativeTheme::ScrollbarThumbExtraParams* extra) {
560 ui::NativeTheme::State gfx_state = ui::NativeTheme::kNormal;
561 switch (state) {
562 case SCRBS_NORMAL:
563 gfx_state = ui::NativeTheme::kNormal;
564 extra->is_hovering = false;
565 break;
566 case SCRBS_HOVER:
567 gfx_state = ui::NativeTheme::kHovered;
568 extra->is_hovering = true;
569 break;
570 case SCRBS_HOT:
571 gfx_state = ui::NativeTheme::kHovered;
572 extra->is_hovering = false;
573 break;
574 case SCRBS_PRESSED:
575 gfx_state = ui::NativeTheme::kPressed;
576 extra->is_hovering = false;
577 break;
578 case SCRBS_DISABLED:
579 gfx_state = ui::NativeTheme::kDisabled;
580 extra->is_hovering = false;
581 break;
582 default:
583 NOTREACHED() << "Invalid state: " << state;
584 break;
586 return gfx_state;
589 void WebThemeEngineImpl::paintScrollbarThumb(
590 WebCanvas* canvas, int part, int state, int classic_state,
591 const WebRect& rect) {
592 ui::NativeTheme::Part native_part;
593 if (part == SBP_THUMBBTNHORZ) {
594 native_part = ui::NativeTheme::kScrollbarHorizontalThumb;
595 } else if (part == SBP_THUMBBTNVERT) {
596 native_part = ui::NativeTheme::kScrollbarVerticalThumb;
597 } else if (part == SBP_GRIPPERHORZ) {
598 native_part = ui::NativeTheme::kScrollbarHorizontalGripper;
599 } else if (part == SBP_GRIPPERVERT) {
600 native_part = ui::NativeTheme::kScrollbarVerticalGripper;
601 } else {
602 NOTREACHED() << "Invalid part: " << part;
605 ui::NativeTheme::ExtraParams extra;
606 ui::NativeTheme::State native_state = WebScrollbarThumbStateToGfx(
607 state, &extra.scrollbar_thumb);
609 gfx::Rect gfx_rect(rect.x, rect.y, rect.width, rect.height);
610 ui::NativeTheme::instance()->Paint(canvas, native_part,
611 native_state, gfx_rect, extra);
614 static ui::NativeTheme::State WebScrollbarTrackStateToGfx(
615 int part, int state, ui::NativeTheme::Part* gfx_part,
616 ui::NativeTheme::ScrollbarTrackExtraParams* extra) {
617 ui::NativeTheme::State gfx_state = ui::NativeTheme::kNormal;
618 switch (part) {
619 case SBP_LOWERTRACKHORZ:
620 switch (state) {
621 case SCRBS_NORMAL:
622 gfx_state = ui::NativeTheme::kNormal;
623 *gfx_part = ui::NativeTheme::kScrollbarHorizontalTrack;
624 extra->is_upper = false;
625 break;
626 case SCRBS_HOVER:
627 case SCRBS_HOT:
628 gfx_state = ui::NativeTheme::kHovered;
629 *gfx_part = ui::NativeTheme::kScrollbarHorizontalTrack;
630 extra->is_upper = false;
631 break;
632 case SCRBS_PRESSED:
633 gfx_state = ui::NativeTheme::kPressed;
634 *gfx_part = ui::NativeTheme::kScrollbarHorizontalTrack;
635 extra->is_upper = false;
636 break;
637 case SCRBS_DISABLED:
638 gfx_state = ui::NativeTheme::kDisabled;
639 *gfx_part = ui::NativeTheme::kScrollbarHorizontalTrack;
640 extra->is_upper = false;
641 break;
642 default:
643 NOTREACHED() << "Invalid state: " << state;
644 break;
646 break;
647 case SBP_UPPERTRACKHORZ:
648 switch (state) {
649 case SCRBS_NORMAL:
650 gfx_state = ui::NativeTheme::kNormal;
651 *gfx_part = ui::NativeTheme::kScrollbarHorizontalTrack;
652 extra->is_upper = true;
653 break;
654 case SCRBS_HOVER:
655 case SCRBS_HOT:
656 gfx_state = ui::NativeTheme::kHovered;
657 *gfx_part = ui::NativeTheme::kScrollbarHorizontalTrack;
658 extra->is_upper = true;
659 break;
660 case SCRBS_PRESSED:
661 gfx_state = ui::NativeTheme::kPressed;
662 *gfx_part = ui::NativeTheme::kScrollbarHorizontalTrack;
663 extra->is_upper = true;
664 break;
665 case SCRBS_DISABLED:
666 gfx_state = ui::NativeTheme::kDisabled;
667 *gfx_part = ui::NativeTheme::kScrollbarHorizontalTrack;
668 extra->is_upper = true;
669 break;
670 default:
671 NOTREACHED() << "Invalid state: " << state;
672 break;
674 break;
675 case SBP_LOWERTRACKVERT:
676 switch (state) {
677 case SCRBS_NORMAL:
678 gfx_state = ui::NativeTheme::kNormal;
679 *gfx_part = ui::NativeTheme::kScrollbarVerticalTrack;
680 extra->is_upper = false;
681 break;
682 case SCRBS_HOVER:
683 case SCRBS_HOT:
684 gfx_state = ui::NativeTheme::kHovered;
685 *gfx_part = ui::NativeTheme::kScrollbarVerticalTrack;
686 extra->is_upper = false;
687 break;
688 case SCRBS_PRESSED:
689 gfx_state = ui::NativeTheme::kPressed;
690 *gfx_part = ui::NativeTheme::kScrollbarVerticalTrack;
691 extra->is_upper = false;
692 break;
693 case SCRBS_DISABLED:
694 gfx_state = ui::NativeTheme::kDisabled;
695 *gfx_part = ui::NativeTheme::kScrollbarVerticalTrack;
696 extra->is_upper = false;
697 break;
698 default:
699 NOTREACHED() << "Invalid state: " << state;
700 break;
702 break;
703 case SBP_UPPERTRACKVERT:
704 switch (state) {
705 case SCRBS_NORMAL:
706 gfx_state = ui::NativeTheme::kNormal;
707 *gfx_part = ui::NativeTheme::kScrollbarVerticalTrack;
708 extra->is_upper = true;
709 break;
710 case SCRBS_HOVER:
711 case SCRBS_HOT:
712 gfx_state = ui::NativeTheme::kHovered;
713 *gfx_part = ui::NativeTheme::kScrollbarVerticalTrack;
714 extra->is_upper = true;
715 break;
716 case SCRBS_PRESSED:
717 gfx_state = ui::NativeTheme::kPressed;
718 *gfx_part = ui::NativeTheme::kScrollbarVerticalTrack;
719 extra->is_upper = true;
720 break;
721 case SCRBS_DISABLED:
722 gfx_state = ui::NativeTheme::kDisabled;
723 *gfx_part = ui::NativeTheme::kScrollbarVerticalTrack;
724 extra->is_upper = true;
725 break;
726 default:
727 NOTREACHED() << "Invalid state: " << state;
728 break;
730 break;
731 default:
732 NOTREACHED() << "Invalid part: " << part;
733 break;
735 return gfx_state;
738 void WebThemeEngineImpl::paintScrollbarTrack(
739 WebCanvas* canvas, int part, int state, int classic_state,
740 const WebRect& rect, const WebRect& align_rect) {
741 ui::NativeTheme::Part native_part;
742 ui::NativeTheme::ExtraParams extra;
743 ui::NativeTheme::State native_state = WebScrollbarTrackStateToGfx(
744 part, state, &native_part, &extra.scrollbar_track);
745 extra.scrollbar_track.classic_state = classic_state;
746 extra.scrollbar_track.track_x = align_rect.x;
747 extra.scrollbar_track.track_y = align_rect.y;
748 extra.scrollbar_track.track_width = align_rect.width;
749 extra.scrollbar_track.track_height = align_rect.height;
751 gfx::Rect gfx_rect(rect.x, rect.y, rect.width, rect.height);
752 ui::NativeTheme::instance()->Paint(canvas, native_part,
753 native_state, gfx_rect, extra);
756 static ui::NativeTheme::State WebSpinButtonStateToGfx(
757 int part, int state, ui::NativeTheme::InnerSpinButtonExtraParams* extra) {
758 ui::NativeTheme::State gfx_state = ui::NativeTheme::kNormal;
759 switch (part) {
760 case SPNP_UP:
761 switch (state) {
762 case UPS_NORMAL:
763 gfx_state = ui::NativeTheme::kNormal;
764 extra->spin_up = true;
765 extra->read_only = false;
766 break;
767 case UPS_HOT:
768 gfx_state = ui::NativeTheme::kHovered;
769 extra->spin_up = true;
770 extra->read_only = false;
771 break;
772 case UPS_PRESSED:
773 gfx_state = ui::NativeTheme::kPressed;
774 extra->spin_up = true;
775 extra->read_only = false;
776 break;
777 case UPS_DISABLED:
778 gfx_state = ui::NativeTheme::kDisabled;
779 extra->spin_up = true;
780 extra->read_only = false;
781 break;
782 default:
783 NOTREACHED() << "Invalid state: " << state;
784 break;
786 break;
787 case SPNP_DOWN:
788 switch (state) {
789 case DNS_NORMAL:
790 gfx_state = ui::NativeTheme::kNormal;
791 extra->spin_up = false;
792 extra->read_only = false;
793 break;
794 case DNS_HOT:
795 gfx_state = ui::NativeTheme::kHovered;
796 extra->spin_up = false;
797 extra->read_only = false;
798 break;
799 case DNS_PRESSED:
800 gfx_state = ui::NativeTheme::kPressed;
801 extra->spin_up = false;
802 extra->read_only = false;
803 break;
804 case DNS_DISABLED:
805 gfx_state = ui::NativeTheme::kDisabled;
806 extra->spin_up = false;
807 extra->read_only = false;
808 break;
809 default:
810 NOTREACHED() << "Invalid state: " << state;
811 break;
813 break;
814 default:
815 NOTREACHED() << "Invalid part: " << part;
816 break;
818 return gfx_state;
821 void WebThemeEngineImpl::paintSpinButton(
822 WebCanvas* canvas, int part, int state, int classic_state,
823 const WebRect& rect) {
824 ui::NativeTheme::ExtraParams extra;
825 ui::NativeTheme::State native_state = WebSpinButtonStateToGfx(
826 part, state, &extra.inner_spin);
827 extra.inner_spin.classic_state = classic_state;
828 gfx::Rect gfx_rect(rect.x, rect.y, rect.width, rect.height);
829 ui::NativeTheme::instance()->Paint(canvas,
830 ui::NativeTheme::kInnerSpinButton,
831 native_state,
832 gfx_rect,
833 extra);
836 static ui::NativeTheme::State WebTextFieldStateToGfx(
837 int part, int state, ui::NativeTheme::TextFieldExtraParams* extra) {
838 ui::NativeTheme::State gfx_state = ui::NativeTheme::kNormal;
839 switch (part) {
840 case EP_EDITTEXT:
841 switch (state) {
842 case ETS_NORMAL:
843 gfx_state = ui::NativeTheme::kNormal;
844 extra->is_read_only = false;
845 extra->is_focused = false;
846 break;
847 case ETS_HOT:
848 gfx_state = ui::NativeTheme::kHovered;
849 extra->is_read_only = false;
850 extra->is_focused = false;
851 break;
852 case ETS_SELECTED:
853 gfx_state = ui::NativeTheme::kPressed;
854 extra->is_read_only = false;
855 extra->is_focused = false;
856 break;
857 case ETS_DISABLED:
858 gfx_state = ui::NativeTheme::kDisabled;
859 extra->is_read_only = false;
860 extra->is_focused = false;
861 break;
862 case ETS_FOCUSED:
863 gfx_state = ui::NativeTheme::kNormal;
864 extra->is_read_only = false;
865 extra->is_focused = true;
866 break;
867 case ETS_READONLY:
868 gfx_state = ui::NativeTheme::kNormal;
869 extra->is_read_only = true;
870 extra->is_focused = false;
871 break;
872 default:
873 NOTREACHED() << "Invalid state: " << state;
874 break;
876 break;
877 default:
878 NOTREACHED() << "Invalid part: " << part;
879 break;
881 return gfx_state;
884 void WebThemeEngineImpl::paintTextField(
885 WebCanvas* canvas, int part, int state, int classic_state,
886 const WebRect& rect, WebColor color, bool fill_content_area,
887 bool draw_edges) {
888 ui::NativeTheme::ExtraParams extra;
889 ui::NativeTheme::State native_state = WebTextFieldStateToGfx(
890 part, state, &extra.text_field);
891 extra.text_field.fill_content_area = fill_content_area;
892 extra.text_field.draw_edges = draw_edges;
893 extra.text_field.background_color = color;
894 extra.text_field.classic_state = classic_state;
895 gfx::Rect gfx_rect(rect.x, rect.y, rect.width, rect.height);
897 ui::NativeTheme::instance()->Paint(canvas,
898 ui::NativeTheme::kTextField, native_state, gfx_rect, extra);
901 static ui::NativeTheme::State WebTrackbarStateToGfx(
902 int part,
903 int state,
904 ui::NativeTheme::TrackbarExtraParams* extra) {
905 ui::NativeTheme::State gfx_state = ui::NativeTheme::kNormal;
906 switch (state) {
907 case TUS_NORMAL:
908 gfx_state = ui::NativeTheme::kNormal;
909 break;
910 case TUS_HOT:
911 gfx_state = ui::NativeTheme::kHovered;
912 break;
913 case TUS_PRESSED:
914 gfx_state = ui::NativeTheme::kPressed;
915 break;
916 case TUS_DISABLED:
917 gfx_state = ui::NativeTheme::kDisabled;
918 break;
919 default:
920 NOTREACHED() << "Invalid state: " << state;
921 break;
924 switch (part) {
925 case TKP_TRACK:
926 case TKP_THUMBBOTTOM:
927 extra->vertical = false;
928 break;
929 case TKP_TRACKVERT:
930 case TKP_THUMBVERT:
931 extra->vertical = true;
932 break;
933 default:
934 NOTREACHED() << "Invalid part: " << part;
935 break;
938 return gfx_state;
941 void WebThemeEngineImpl::paintTrackbar(
942 WebCanvas* canvas, int part, int state, int classic_state,
943 const WebRect& rect) {
944 ui::NativeTheme::Part native_part = ui::NativeTheme::kTrackbarTrack;
945 switch (part) {
946 case TKP_TRACK:
947 case TKP_TRACKVERT:
948 native_part = ui::NativeTheme::kTrackbarTrack;
949 break;
950 case TKP_THUMBBOTTOM:
951 case TKP_THUMBVERT:
952 native_part = ui::NativeTheme::kTrackbarThumb;
953 break;
954 default:
955 NOTREACHED() << "Invalid part: " << part;
956 break;
959 ui::NativeTheme::ExtraParams extra;
960 ui::NativeTheme::State native_state = WebTrackbarStateToGfx(part, state,
961 &extra.trackbar);
962 gfx::Rect gfx_rect(rect.x, rect.y, rect.width, rect.height);
963 extra.trackbar.classic_state = classic_state;
964 ui::NativeTheme::instance()->Paint(canvas, native_part,
965 native_state, gfx_rect, extra);
968 void WebThemeEngineImpl::paintProgressBar(
969 WebCanvas* canvas, const WebRect& barRect, const WebRect& valueRect,
970 bool determinate, double animatedSeconds)
972 gfx::Rect gfx_rect(barRect.x, barRect.y, barRect.width, barRect.height);
973 ui::NativeTheme::ExtraParams extra;
974 extra.progress_bar.animated_seconds = animatedSeconds;
975 extra.progress_bar.determinate = determinate;
976 extra.progress_bar.value_rect_x = valueRect.x;
977 extra.progress_bar.value_rect_y = valueRect.y;
978 extra.progress_bar.value_rect_width = valueRect.width;
979 extra.progress_bar.value_rect_height = valueRect.height;
980 ui::NativeTheme::instance()->Paint(canvas, ui::NativeTheme::kProgressBar,
981 ui::NativeTheme::kNormal, gfx_rect,
982 extra);
985 WebSize WebThemeEngineImpl::getSize(int part) {
986 switch (part) {
987 case SBP_ARROWBTN: {
988 gfx::Size size = ui::NativeTheme::instance()->GetPartSize(
989 ui::NativeTheme::kScrollbarUpArrow,
990 ui::NativeTheme::kNormal,
991 ui::NativeTheme::ExtraParams());
992 return WebSize(size.width(), size.height());
994 default:
995 NOTREACHED() << "Unhandled part: " << part;
997 return WebSize();
1000 } // namespace webkit_glue