Remove unnecessary casts for WebContentsImpl::GetRenderViewHost.
[chromium-blink-merge.git] / content / child / webthemeengine_impl_default.cc
blob1235494d6ff2ff56e0beffd5be64c791ffbfa9ac
1 // Copyright 2014 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 "content/child/webthemeengine_impl_default.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/native_theme.h"
12 using blink::WebCanvas;
13 using blink::WebColor;
14 using blink::WebRect;
15 using blink::WebThemeEngine;
17 namespace content {
18 namespace {
20 #if defined(OS_WIN)
21 // The scrollbar metrics default to 17 dips which is the default value on
22 // Windows in most cases.
23 int32 g_vertical_scroll_bar_width = 17;
25 // The height of a horizontal scroll bar in dips.
26 int32 g_horizontal_scroll_bar_height = 17;
28 // The height of the arrow bitmap on a vertical scroll bar in dips.
29 int32 g_vertical_arrow_bitmap_height = 17;
31 // The width of the arrow bitmap on a horizontal scroll bar in dips.
32 int32 g_horizontal_arrow_bitmap_width = 17;
33 #endif
35 } // namespace
37 static ui::NativeTheme::Part NativeThemePart(
38 WebThemeEngine::Part part) {
39 switch (part) {
40 case WebThemeEngine::PartScrollbarDownArrow:
41 return ui::NativeTheme::kScrollbarDownArrow;
42 case WebThemeEngine::PartScrollbarLeftArrow:
43 return ui::NativeTheme::kScrollbarLeftArrow;
44 case WebThemeEngine::PartScrollbarRightArrow:
45 return ui::NativeTheme::kScrollbarRightArrow;
46 case WebThemeEngine::PartScrollbarUpArrow:
47 return ui::NativeTheme::kScrollbarUpArrow;
48 case WebThemeEngine::PartScrollbarHorizontalThumb:
49 return ui::NativeTheme::kScrollbarHorizontalThumb;
50 case WebThemeEngine::PartScrollbarVerticalThumb:
51 return ui::NativeTheme::kScrollbarVerticalThumb;
52 case WebThemeEngine::PartScrollbarHorizontalTrack:
53 return ui::NativeTheme::kScrollbarHorizontalTrack;
54 case WebThemeEngine::PartScrollbarVerticalTrack:
55 return ui::NativeTheme::kScrollbarVerticalTrack;
56 case WebThemeEngine::PartScrollbarCorner:
57 return ui::NativeTheme::kScrollbarCorner;
58 case WebThemeEngine::PartCheckbox:
59 return ui::NativeTheme::kCheckbox;
60 case WebThemeEngine::PartRadio:
61 return ui::NativeTheme::kRadio;
62 case WebThemeEngine::PartButton:
63 return ui::NativeTheme::kPushButton;
64 case WebThemeEngine::PartTextField:
65 return ui::NativeTheme::kTextField;
66 case WebThemeEngine::PartMenuList:
67 return ui::NativeTheme::kMenuList;
68 case WebThemeEngine::PartSliderTrack:
69 return ui::NativeTheme::kSliderTrack;
70 case WebThemeEngine::PartSliderThumb:
71 return ui::NativeTheme::kSliderThumb;
72 case WebThemeEngine::PartInnerSpinButton:
73 return ui::NativeTheme::kInnerSpinButton;
74 case WebThemeEngine::PartProgressBar:
75 return ui::NativeTheme::kProgressBar;
76 default:
77 return ui::NativeTheme::kScrollbarDownArrow;
81 static ui::NativeTheme::State NativeThemeState(
82 WebThemeEngine::State state) {
83 switch (state) {
84 case WebThemeEngine::StateDisabled:
85 return ui::NativeTheme::kDisabled;
86 case WebThemeEngine::StateHover:
87 return ui::NativeTheme::kHovered;
88 case WebThemeEngine::StateNormal:
89 return ui::NativeTheme::kNormal;
90 case WebThemeEngine::StatePressed:
91 return ui::NativeTheme::kPressed;
92 default:
93 return ui::NativeTheme::kDisabled;
97 static void GetNativeThemeExtraParams(
98 WebThemeEngine::Part part,
99 WebThemeEngine::State state,
100 const WebThemeEngine::ExtraParams* extra_params,
101 ui::NativeTheme::ExtraParams* native_theme_extra_params) {
102 switch (part) {
103 case WebThemeEngine::PartScrollbarHorizontalTrack:
104 case WebThemeEngine::PartScrollbarVerticalTrack:
105 native_theme_extra_params->scrollbar_track.track_x =
106 extra_params->scrollbarTrack.trackX;
107 native_theme_extra_params->scrollbar_track.track_y =
108 extra_params->scrollbarTrack.trackY;
109 native_theme_extra_params->scrollbar_track.track_width =
110 extra_params->scrollbarTrack.trackWidth;
111 native_theme_extra_params->scrollbar_track.track_height =
112 extra_params->scrollbarTrack.trackHeight;
113 break;
114 case WebThemeEngine::PartCheckbox:
115 native_theme_extra_params->button.checked = extra_params->button.checked;
116 native_theme_extra_params->button.indeterminate =
117 extra_params->button.indeterminate;
118 break;
119 case WebThemeEngine::PartRadio:
120 native_theme_extra_params->button.checked = extra_params->button.checked;
121 break;
122 case WebThemeEngine::PartButton:
123 native_theme_extra_params->button.is_default =
124 extra_params->button.isDefault;
125 native_theme_extra_params->button.has_border =
126 extra_params->button.hasBorder;
127 // Native buttons have a different focus style.
128 native_theme_extra_params->button.is_focused = false;
129 native_theme_extra_params->button.background_color =
130 extra_params->button.backgroundColor;
131 break;
132 case WebThemeEngine::PartTextField:
133 native_theme_extra_params->text_field.is_text_area =
134 extra_params->textField.isTextArea;
135 native_theme_extra_params->text_field.is_listbox =
136 extra_params->textField.isListbox;
137 native_theme_extra_params->text_field.background_color =
138 extra_params->textField.backgroundColor;
139 break;
140 case WebThemeEngine::PartMenuList:
141 native_theme_extra_params->menu_list.has_border =
142 extra_params->menuList.hasBorder;
143 native_theme_extra_params->menu_list.has_border_radius =
144 extra_params->menuList.hasBorderRadius;
145 native_theme_extra_params->menu_list.arrow_x =
146 extra_params->menuList.arrowX;
147 native_theme_extra_params->menu_list.arrow_y =
148 extra_params->menuList.arrowY;
149 native_theme_extra_params->menu_list.background_color =
150 extra_params->menuList.backgroundColor;
151 break;
152 case WebThemeEngine::PartSliderTrack:
153 case WebThemeEngine::PartSliderThumb:
154 native_theme_extra_params->slider.vertical =
155 extra_params->slider.vertical;
156 native_theme_extra_params->slider.in_drag = extra_params->slider.inDrag;
157 break;
158 case WebThemeEngine::PartInnerSpinButton:
159 native_theme_extra_params->inner_spin.spin_up =
160 extra_params->innerSpin.spinUp;
161 native_theme_extra_params->inner_spin.read_only =
162 extra_params->innerSpin.readOnly;
163 break;
164 case WebThemeEngine::PartProgressBar:
165 native_theme_extra_params->progress_bar.determinate =
166 extra_params->progressBar.determinate;
167 native_theme_extra_params->progress_bar.value_rect_x =
168 extra_params->progressBar.valueRectX;
169 native_theme_extra_params->progress_bar.value_rect_y =
170 extra_params->progressBar.valueRectY;
171 native_theme_extra_params->progress_bar.value_rect_width =
172 extra_params->progressBar.valueRectWidth;
173 native_theme_extra_params->progress_bar.value_rect_height =
174 extra_params->progressBar.valueRectHeight;
175 break;
176 default:
177 break; // Parts that have no extra params get here.
181 blink::WebSize WebThemeEngineImpl::getSize(WebThemeEngine::Part part) {
182 ui::NativeTheme::ExtraParams extra;
183 ui::NativeTheme::Part native_theme_part = NativeThemePart(part);
184 #if defined(OS_WIN)
185 switch (native_theme_part) {
186 case ui::NativeTheme::kScrollbarDownArrow:
187 case ui::NativeTheme::kScrollbarLeftArrow:
188 case ui::NativeTheme::kScrollbarRightArrow:
189 case ui::NativeTheme::kScrollbarUpArrow:
190 case ui::NativeTheme::kScrollbarHorizontalThumb:
191 case ui::NativeTheme::kScrollbarVerticalThumb:
192 case ui::NativeTheme::kScrollbarHorizontalTrack:
193 case ui::NativeTheme::kScrollbarVerticalTrack: {
194 return gfx::Size(g_vertical_scroll_bar_width,
195 g_vertical_scroll_bar_width);
198 default:
199 break;
201 #endif
202 return ui::NativeTheme::instance()->GetPartSize(native_theme_part,
203 ui::NativeTheme::kNormal,
204 extra);
207 void WebThemeEngineImpl::paint(
208 blink::WebCanvas* canvas,
209 WebThemeEngine::Part part,
210 WebThemeEngine::State state,
211 const blink::WebRect& rect,
212 const WebThemeEngine::ExtraParams* extra_params) {
213 ui::NativeTheme::ExtraParams native_theme_extra_params;
214 GetNativeThemeExtraParams(
215 part, state, extra_params, &native_theme_extra_params);
216 ui::NativeTheme::instance()->Paint(
217 canvas,
218 NativeThemePart(part),
219 NativeThemeState(state),
220 gfx::Rect(rect),
221 native_theme_extra_params);
224 void WebThemeEngineImpl::paintStateTransition(blink::WebCanvas* canvas,
225 WebThemeEngine::Part part,
226 WebThemeEngine::State startState,
227 WebThemeEngine::State endState,
228 double progress,
229 const blink::WebRect& rect) {
230 ui::NativeTheme::instance()->PaintStateTransition(
231 canvas,
232 NativeThemePart(part),
233 NativeThemeState(startState),
234 NativeThemeState(endState),
235 progress,
236 gfx::Rect(rect));
239 #if defined(OS_WIN)
240 // static
241 void WebThemeEngineImpl::cacheScrollBarMetrics(
242 int32 vertical_scroll_bar_width,
243 int32 horizontal_scroll_bar_height,
244 int32 vertical_arrow_bitmap_height,
245 int32 horizontal_arrow_bitmap_width) {
246 g_vertical_scroll_bar_width = vertical_scroll_bar_width;
247 g_horizontal_scroll_bar_height = horizontal_scroll_bar_height;
248 g_vertical_arrow_bitmap_height = vertical_arrow_bitmap_height;
249 g_horizontal_arrow_bitmap_width = horizontal_arrow_bitmap_width;
251 #endif
253 } // namespace content