Revert 224458 "Enabling MediaStreamInfoBarTest.DenyingCameraDoes..."
[chromium-blink-merge.git] / webkit / child / webthemeengine_impl_android.cc
blobda139e5d5b12b42be2501803f531837169bf03a9
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/webthemeengine_impl_android.h"
7 #include "base/logging.h"
8 #include "skia/ext/platform_canvas.h"
9 #include "third_party/WebKit/public/platform/WebRect.h"
10 #include "third_party/WebKit/public/platform/WebSize.h"
11 #include "ui/native_theme/native_theme.h"
13 using WebKit::WebCanvas;
14 using WebKit::WebColor;
15 using WebKit::WebRect;
16 using WebKit::WebThemeEngine;
18 namespace webkit_glue {
20 static ui::NativeTheme::Part NativeThemePart(
21 WebThemeEngine::Part part) {
22 switch (part) {
23 case WebThemeEngine::PartScrollbarDownArrow:
24 return ui::NativeTheme::kScrollbarDownArrow;
25 case WebThemeEngine::PartScrollbarLeftArrow:
26 return ui::NativeTheme::kScrollbarLeftArrow;
27 case WebThemeEngine::PartScrollbarRightArrow:
28 return ui::NativeTheme::kScrollbarRightArrow;
29 case WebThemeEngine::PartScrollbarUpArrow:
30 return ui::NativeTheme::kScrollbarUpArrow;
31 case WebThemeEngine::PartScrollbarHorizontalThumb:
32 // Android doesn't draw scrollbars.
33 NOTREACHED();
34 return static_cast<ui::NativeTheme::Part>(0);
35 case WebThemeEngine::PartScrollbarVerticalThumb:
36 // Android doesn't draw scrollbars.
37 NOTREACHED();
38 return static_cast<ui::NativeTheme::Part>(0);
39 case WebThemeEngine::PartScrollbarHorizontalTrack:
40 // Android doesn't draw scrollbars.
41 NOTREACHED();
42 return static_cast<ui::NativeTheme::Part>(0);
43 case WebThemeEngine::PartScrollbarVerticalTrack:
44 // Android doesn't draw scrollbars.
45 NOTREACHED();
46 return static_cast<ui::NativeTheme::Part>(0);
47 case WebThemeEngine::PartCheckbox:
48 return ui::NativeTheme::kCheckbox;
49 case WebThemeEngine::PartRadio:
50 return ui::NativeTheme::kRadio;
51 case WebThemeEngine::PartButton:
52 return ui::NativeTheme::kPushButton;
53 case WebThemeEngine::PartTextField:
54 return ui::NativeTheme::kTextField;
55 case WebThemeEngine::PartMenuList:
56 return ui::NativeTheme::kMenuList;
57 case WebThemeEngine::PartSliderTrack:
58 return ui::NativeTheme::kSliderTrack;
59 case WebThemeEngine::PartSliderThumb:
60 return ui::NativeTheme::kSliderThumb;
61 case WebThemeEngine::PartInnerSpinButton:
62 return ui::NativeTheme::kInnerSpinButton;
63 case WebThemeEngine::PartProgressBar:
64 return ui::NativeTheme::kProgressBar;
65 default:
66 return ui::NativeTheme::kScrollbarDownArrow;
70 static ui::NativeTheme::State NativeThemeState(
71 WebThemeEngine::State state) {
72 switch (state) {
73 case WebThemeEngine::StateDisabled:
74 return ui::NativeTheme::kDisabled;
75 case WebThemeEngine::StateHover:
76 return ui::NativeTheme::kHovered;
77 case WebThemeEngine::StateNormal:
78 return ui::NativeTheme::kNormal;
79 case WebThemeEngine::StatePressed:
80 return ui::NativeTheme::kPressed;
81 default:
82 return ui::NativeTheme::kDisabled;
86 static void GetNativeThemeExtraParams(
87 WebThemeEngine::Part part,
88 WebThemeEngine::State state,
89 const WebThemeEngine::ExtraParams* extra_params,
90 ui::NativeTheme::ExtraParams* native_theme_extra_params) {
91 switch (part) {
92 case WebThemeEngine::PartScrollbarHorizontalTrack:
93 case WebThemeEngine::PartScrollbarVerticalTrack:
94 // Android doesn't draw scrollbars.
95 NOTREACHED();
96 break;
97 case WebThemeEngine::PartCheckbox:
98 native_theme_extra_params->button.checked = extra_params->button.checked;
99 native_theme_extra_params->button.indeterminate =
100 extra_params->button.indeterminate;
101 break;
102 case WebThemeEngine::PartRadio:
103 native_theme_extra_params->button.checked = extra_params->button.checked;
104 break;
105 case WebThemeEngine::PartButton:
106 native_theme_extra_params->button.is_default =
107 extra_params->button.isDefault;
108 native_theme_extra_params->button.has_border =
109 extra_params->button.hasBorder;
110 // Native buttons have a different focus style.
111 native_theme_extra_params->button.is_focused = false;
112 native_theme_extra_params->button.background_color =
113 extra_params->button.backgroundColor;
114 break;
115 case WebThemeEngine::PartTextField:
116 native_theme_extra_params->text_field.is_text_area =
117 extra_params->textField.isTextArea;
118 native_theme_extra_params->text_field.is_listbox =
119 extra_params->textField.isListbox;
120 native_theme_extra_params->text_field.background_color =
121 extra_params->textField.backgroundColor;
122 break;
123 case WebThemeEngine::PartMenuList:
124 native_theme_extra_params->menu_list.has_border =
125 extra_params->menuList.hasBorder;
126 native_theme_extra_params->menu_list.has_border_radius =
127 extra_params->menuList.hasBorderRadius;
128 native_theme_extra_params->menu_list.arrow_x =
129 extra_params->menuList.arrowX;
130 native_theme_extra_params->menu_list.arrow_y =
131 extra_params->menuList.arrowY;
132 native_theme_extra_params->menu_list.background_color =
133 extra_params->menuList.backgroundColor;
134 break;
135 case WebThemeEngine::PartSliderTrack:
136 case WebThemeEngine::PartSliderThumb:
137 native_theme_extra_params->slider.vertical =
138 extra_params->slider.vertical;
139 native_theme_extra_params->slider.in_drag = extra_params->slider.inDrag;
140 break;
141 case WebThemeEngine::PartInnerSpinButton:
142 native_theme_extra_params->inner_spin.spin_up =
143 extra_params->innerSpin.spinUp;
144 native_theme_extra_params->inner_spin.read_only =
145 extra_params->innerSpin.readOnly;
146 break;
147 case WebThemeEngine::PartProgressBar:
148 native_theme_extra_params->progress_bar.determinate =
149 extra_params->progressBar.determinate;
150 native_theme_extra_params->progress_bar.value_rect_x =
151 extra_params->progressBar.valueRectX;
152 native_theme_extra_params->progress_bar.value_rect_y =
153 extra_params->progressBar.valueRectY;
154 native_theme_extra_params->progress_bar.value_rect_width =
155 extra_params->progressBar.valueRectWidth;
156 native_theme_extra_params->progress_bar.value_rect_height =
157 extra_params->progressBar.valueRectHeight;
158 break;
159 default:
160 break; // Parts that have no extra params get here.
164 WebKit::WebSize WebThemeEngineImpl::getSize(WebThemeEngine::Part part) {
165 ui::NativeTheme::ExtraParams extra;
166 return ui::NativeTheme::instance()->GetPartSize(
167 NativeThemePart(part), ui::NativeTheme::kNormal, extra);
170 void WebThemeEngineImpl::paint(
171 WebKit::WebCanvas* canvas,
172 WebThemeEngine::Part part,
173 WebThemeEngine::State state,
174 const WebKit::WebRect& rect,
175 const WebThemeEngine::ExtraParams* extra_params) {
176 ui::NativeTheme::ExtraParams native_theme_extra_params;
177 GetNativeThemeExtraParams(
178 part, state, extra_params, &native_theme_extra_params);
179 ui::NativeTheme::instance()->Paint(
180 canvas,
181 NativeThemePart(part),
182 NativeThemeState(state),
183 gfx::Rect(rect),
184 native_theme_extra_params);
186 } // namespace webkit_glue