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_default.h"
7 #include "skia/ext/platform_canvas.h"
8 #include "third_party/WebKit/Source/Platform/chromium/public/WebRect.h"
9 #include "third_party/WebKit/Source/Platform/chromium/public/WebSize.h"
10 #include "ui/native_theme/native_theme.h"
12 using WebKit::WebCanvas
;
13 using WebKit::WebColor
;
14 using WebKit::WebRect
;
15 using WebKit::WebThemeEngine
;
17 namespace webkit_glue
{
19 static ui::NativeTheme::Part
NativeThemePart(
20 WebThemeEngine::Part part
) {
22 case WebThemeEngine::PartScrollbarDownArrow
:
23 return ui::NativeTheme::kScrollbarDownArrow
;
24 case WebThemeEngine::PartScrollbarLeftArrow
:
25 return ui::NativeTheme::kScrollbarLeftArrow
;
26 case WebThemeEngine::PartScrollbarRightArrow
:
27 return ui::NativeTheme::kScrollbarRightArrow
;
28 case WebThemeEngine::PartScrollbarUpArrow
:
29 return ui::NativeTheme::kScrollbarUpArrow
;
30 case WebThemeEngine::PartScrollbarHorizontalThumb
:
31 return ui::NativeTheme::kScrollbarHorizontalThumb
;
32 case WebThemeEngine::PartScrollbarVerticalThumb
:
33 return ui::NativeTheme::kScrollbarVerticalThumb
;
34 case WebThemeEngine::PartScrollbarHorizontalTrack
:
35 return ui::NativeTheme::kScrollbarHorizontalTrack
;
36 case WebThemeEngine::PartScrollbarVerticalTrack
:
37 return ui::NativeTheme::kScrollbarVerticalTrack
;
38 case WebThemeEngine::PartCheckbox
:
39 return ui::NativeTheme::kCheckbox
;
40 case WebThemeEngine::PartRadio
:
41 return ui::NativeTheme::kRadio
;
42 case WebThemeEngine::PartButton
:
43 return ui::NativeTheme::kPushButton
;
44 case WebThemeEngine::PartTextField
:
45 return ui::NativeTheme::kTextField
;
46 case WebThemeEngine::PartMenuList
:
47 return ui::NativeTheme::kMenuList
;
48 case WebThemeEngine::PartSliderTrack
:
49 return ui::NativeTheme::kSliderTrack
;
50 case WebThemeEngine::PartSliderThumb
:
51 return ui::NativeTheme::kSliderThumb
;
52 case WebThemeEngine::PartInnerSpinButton
:
53 return ui::NativeTheme::kInnerSpinButton
;
54 case WebThemeEngine::PartProgressBar
:
55 return ui::NativeTheme::kProgressBar
;
57 return ui::NativeTheme::kScrollbarDownArrow
;
61 static ui::NativeTheme::State
NativeThemeState(
62 WebThemeEngine::State state
) {
64 case WebThemeEngine::StateDisabled
:
65 return ui::NativeTheme::kDisabled
;
66 case WebThemeEngine::StateHover
:
67 return ui::NativeTheme::kHovered
;
68 case WebThemeEngine::StateNormal
:
69 return ui::NativeTheme::kNormal
;
70 case WebThemeEngine::StatePressed
:
71 return ui::NativeTheme::kPressed
;
73 return ui::NativeTheme::kDisabled
;
77 static void GetNativeThemeExtraParams(
78 WebThemeEngine::Part part
,
79 WebThemeEngine::State state
,
80 const WebThemeEngine::ExtraParams
* extra_params
,
81 ui::NativeTheme::ExtraParams
* native_theme_extra_params
) {
83 case WebThemeEngine::PartScrollbarHorizontalTrack
:
84 case WebThemeEngine::PartScrollbarVerticalTrack
:
85 native_theme_extra_params
->scrollbar_track
.track_x
=
86 extra_params
->scrollbarTrack
.trackX
;
87 native_theme_extra_params
->scrollbar_track
.track_y
=
88 extra_params
->scrollbarTrack
.trackY
;
89 native_theme_extra_params
->scrollbar_track
.track_width
=
90 extra_params
->scrollbarTrack
.trackWidth
;
91 native_theme_extra_params
->scrollbar_track
.track_height
=
92 extra_params
->scrollbarTrack
.trackHeight
;
94 case WebThemeEngine::PartCheckbox
:
95 native_theme_extra_params
->button
.checked
= extra_params
->button
.checked
;
96 native_theme_extra_params
->button
.indeterminate
=
97 extra_params
->button
.indeterminate
;
99 case WebThemeEngine::PartRadio
:
100 native_theme_extra_params
->button
.checked
= extra_params
->button
.checked
;
102 case WebThemeEngine::PartButton
:
103 native_theme_extra_params
->button
.is_default
=
104 extra_params
->button
.isDefault
;
105 native_theme_extra_params
->button
.has_border
=
106 extra_params
->button
.hasBorder
;
107 // Native buttons have a different focus style.
108 native_theme_extra_params
->button
.is_focused
= false;
109 native_theme_extra_params
->button
.background_color
=
110 extra_params
->button
.backgroundColor
;
112 case WebThemeEngine::PartTextField
:
113 native_theme_extra_params
->text_field
.is_text_area
=
114 extra_params
->textField
.isTextArea
;
115 native_theme_extra_params
->text_field
.is_listbox
=
116 extra_params
->textField
.isListbox
;
117 native_theme_extra_params
->text_field
.background_color
=
118 extra_params
->textField
.backgroundColor
;
120 case WebThemeEngine::PartMenuList
:
121 native_theme_extra_params
->menu_list
.has_border
=
122 extra_params
->menuList
.hasBorder
;
123 native_theme_extra_params
->menu_list
.has_border_radius
=
124 extra_params
->menuList
.hasBorderRadius
;
125 native_theme_extra_params
->menu_list
.arrow_x
=
126 extra_params
->menuList
.arrowX
;
127 native_theme_extra_params
->menu_list
.arrow_y
=
128 extra_params
->menuList
.arrowY
;
129 native_theme_extra_params
->menu_list
.background_color
=
130 extra_params
->menuList
.backgroundColor
;
132 case WebThemeEngine::PartSliderTrack
:
133 case WebThemeEngine::PartSliderThumb
:
134 native_theme_extra_params
->slider
.vertical
=
135 extra_params
->slider
.vertical
;
136 native_theme_extra_params
->slider
.in_drag
= extra_params
->slider
.inDrag
;
138 case WebThemeEngine::PartInnerSpinButton
:
139 native_theme_extra_params
->inner_spin
.spin_up
=
140 extra_params
->innerSpin
.spinUp
;
141 native_theme_extra_params
->inner_spin
.read_only
=
142 extra_params
->innerSpin
.readOnly
;
144 case WebThemeEngine::PartProgressBar
:
145 native_theme_extra_params
->progress_bar
.determinate
=
146 extra_params
->progressBar
.determinate
;
147 native_theme_extra_params
->progress_bar
.value_rect_x
=
148 extra_params
->progressBar
.valueRectX
;
149 native_theme_extra_params
->progress_bar
.value_rect_y
=
150 extra_params
->progressBar
.valueRectY
;
151 native_theme_extra_params
->progress_bar
.value_rect_width
=
152 extra_params
->progressBar
.valueRectWidth
;
153 native_theme_extra_params
->progress_bar
.value_rect_height
=
154 extra_params
->progressBar
.valueRectHeight
;
157 break; // Parts that have no extra params get here.
161 WebKit::WebSize
WebThemeEngineImpl::getSize(WebThemeEngine::Part part
) {
162 ui::NativeTheme::ExtraParams extra
;
163 return ui::NativeTheme::instance()->GetPartSize(NativeThemePart(part
),
164 ui::NativeTheme::kNormal
,
168 void WebThemeEngineImpl::paint(
169 WebKit::WebCanvas
* canvas
,
170 WebThemeEngine::Part part
,
171 WebThemeEngine::State state
,
172 const WebKit::WebRect
& rect
,
173 const WebThemeEngine::ExtraParams
* extra_params
) {
174 ui::NativeTheme::ExtraParams native_theme_extra_params
;
175 GetNativeThemeExtraParams(
176 part
, state
, extra_params
, &native_theme_extra_params
);
177 ui::NativeTheme::instance()->Paint(
179 NativeThemePart(part
),
180 NativeThemeState(state
),
182 native_theme_extra_params
);
185 } // namespace webkit_glue