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/child/webfallbackthemeengine_impl.h"
7 #include "skia/ext/platform_canvas.h"
8 #include "third_party/WebKit/public/platform/WebRect.h"
9 #include "third_party/WebKit/public/platform/WebSize.h"
10 #include "ui/native_theme/fallback_theme.h"
12 using blink::WebCanvas
;
13 using blink::WebColor
;
15 using blink::WebFallbackThemeEngine
;
17 namespace webkit_glue
{
19 static ui::NativeTheme::Part
NativeThemePart(
20 WebFallbackThemeEngine::Part part
) {
22 case WebFallbackThemeEngine::PartScrollbarDownArrow
:
23 return ui::NativeTheme::kScrollbarDownArrow
;
24 case WebFallbackThemeEngine::PartScrollbarLeftArrow
:
25 return ui::NativeTheme::kScrollbarLeftArrow
;
26 case WebFallbackThemeEngine::PartScrollbarRightArrow
:
27 return ui::NativeTheme::kScrollbarRightArrow
;
28 case WebFallbackThemeEngine::PartScrollbarUpArrow
:
29 return ui::NativeTheme::kScrollbarUpArrow
;
30 case WebFallbackThemeEngine::PartScrollbarHorizontalThumb
:
31 return ui::NativeTheme::kScrollbarHorizontalThumb
;
32 case WebFallbackThemeEngine::PartScrollbarVerticalThumb
:
33 return ui::NativeTheme::kScrollbarVerticalThumb
;
34 case WebFallbackThemeEngine::PartScrollbarHorizontalTrack
:
35 return ui::NativeTheme::kScrollbarHorizontalTrack
;
36 case WebFallbackThemeEngine::PartScrollbarVerticalTrack
:
37 return ui::NativeTheme::kScrollbarVerticalTrack
;
38 case WebFallbackThemeEngine::PartCheckbox
:
39 return ui::NativeTheme::kCheckbox
;
40 case WebFallbackThemeEngine::PartRadio
:
41 return ui::NativeTheme::kRadio
;
42 case WebFallbackThemeEngine::PartButton
:
43 return ui::NativeTheme::kPushButton
;
44 case WebFallbackThemeEngine::PartTextField
:
45 return ui::NativeTheme::kTextField
;
46 case WebFallbackThemeEngine::PartMenuList
:
47 return ui::NativeTheme::kMenuList
;
48 case WebFallbackThemeEngine::PartSliderTrack
:
49 return ui::NativeTheme::kSliderTrack
;
50 case WebFallbackThemeEngine::PartSliderThumb
:
51 return ui::NativeTheme::kSliderThumb
;
52 case WebFallbackThemeEngine::PartInnerSpinButton
:
53 return ui::NativeTheme::kInnerSpinButton
;
54 case WebFallbackThemeEngine::PartProgressBar
:
55 return ui::NativeTheme::kProgressBar
;
57 return ui::NativeTheme::kScrollbarDownArrow
;
61 static ui::NativeTheme::State
NativeThemeState(
62 WebFallbackThemeEngine::State state
) {
64 case WebFallbackThemeEngine::StateDisabled
:
65 return ui::NativeTheme::kDisabled
;
66 case WebFallbackThemeEngine::StateHover
:
67 return ui::NativeTheme::kHovered
;
68 case WebFallbackThemeEngine::StateNormal
:
69 return ui::NativeTheme::kNormal
;
70 case WebFallbackThemeEngine::StatePressed
:
71 return ui::NativeTheme::kPressed
;
73 return ui::NativeTheme::kDisabled
;
77 static void GetNativeThemeExtraParams(
78 WebFallbackThemeEngine::Part part
,
79 WebFallbackThemeEngine::State state
,
80 const WebFallbackThemeEngine::ExtraParams
* extra_params
,
81 ui::NativeTheme::ExtraParams
* native_theme_extra_params
) {
83 case WebFallbackThemeEngine::PartScrollbarHorizontalTrack
:
84 case WebFallbackThemeEngine::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 WebFallbackThemeEngine::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 WebFallbackThemeEngine::PartRadio
:
100 native_theme_extra_params
->button
.checked
= extra_params
->button
.checked
;
102 case WebFallbackThemeEngine::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 WebFallbackThemeEngine::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 WebFallbackThemeEngine::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 WebFallbackThemeEngine::PartSliderTrack
:
133 case WebFallbackThemeEngine::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 WebFallbackThemeEngine::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 WebFallbackThemeEngine::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 WebFallbackThemeEngineImpl::WebFallbackThemeEngineImpl()
162 : theme_(new ui::FallbackTheme()) {
165 WebFallbackThemeEngineImpl::~WebFallbackThemeEngineImpl() {}
167 blink::WebSize
WebFallbackThemeEngineImpl::getSize(
168 WebFallbackThemeEngine::Part part
) {
169 ui::NativeTheme::ExtraParams extra
;
170 return theme_
->GetPartSize(NativeThemePart(part
),
171 ui::NativeTheme::kNormal
,
175 void WebFallbackThemeEngineImpl::paint(
176 blink::WebCanvas
* canvas
,
177 WebFallbackThemeEngine::Part part
,
178 WebFallbackThemeEngine::State state
,
179 const blink::WebRect
& rect
,
180 const WebFallbackThemeEngine::ExtraParams
* extra_params
) {
181 ui::NativeTheme::ExtraParams native_theme_extra_params
;
182 GetNativeThemeExtraParams(
183 part
, state
, extra_params
, &native_theme_extra_params
);
184 theme_
->Paint(canvas
,
185 NativeThemePart(part
),
186 NativeThemeState(state
),
188 native_theme_extra_params
);
191 } // namespace webkit_glue