Use ExtensionRegistry::enabled_extensions instead of deprecated ExtensionService...
[chromium-blink-merge.git] / content / child / webthemeengine_impl_android.cc
blobd00f4fa08199da03994045c9a46337979f49e41b
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_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 blink::WebCanvas;
14 using blink::WebColor;
15 using blink::WebRect;
16 using blink::WebThemeEngine;
18 namespace content {
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 case WebThemeEngine::PartScrollbarVerticalThumb:
33 case WebThemeEngine::PartScrollbarHorizontalTrack:
34 case WebThemeEngine::PartScrollbarVerticalTrack:
35 case WebThemeEngine::PartScrollbarCorner:
36 // Android doesn't draw scrollbars.
37 NOTREACHED();
38 return static_cast<ui::NativeTheme::Part>(0);
39 case WebThemeEngine::PartCheckbox:
40 return ui::NativeTheme::kCheckbox;
41 case WebThemeEngine::PartRadio:
42 return ui::NativeTheme::kRadio;
43 case WebThemeEngine::PartButton:
44 return ui::NativeTheme::kPushButton;
45 case WebThemeEngine::PartTextField:
46 return ui::NativeTheme::kTextField;
47 case WebThemeEngine::PartMenuList:
48 return ui::NativeTheme::kMenuList;
49 case WebThemeEngine::PartSliderTrack:
50 return ui::NativeTheme::kSliderTrack;
51 case WebThemeEngine::PartSliderThumb:
52 return ui::NativeTheme::kSliderThumb;
53 case WebThemeEngine::PartInnerSpinButton:
54 return ui::NativeTheme::kInnerSpinButton;
55 case WebThemeEngine::PartProgressBar:
56 return ui::NativeTheme::kProgressBar;
57 default:
58 return ui::NativeTheme::kScrollbarDownArrow;
62 static ui::NativeTheme::State NativeThemeState(
63 WebThemeEngine::State state) {
64 switch (state) {
65 case WebThemeEngine::StateDisabled:
66 return ui::NativeTheme::kDisabled;
67 case WebThemeEngine::StateHover:
68 return ui::NativeTheme::kHovered;
69 case WebThemeEngine::StateNormal:
70 return ui::NativeTheme::kNormal;
71 case WebThemeEngine::StatePressed:
72 return ui::NativeTheme::kPressed;
73 default:
74 return ui::NativeTheme::kDisabled;
78 static void GetNativeThemeExtraParams(
79 WebThemeEngine::Part part,
80 WebThemeEngine::State state,
81 const WebThemeEngine::ExtraParams* extra_params,
82 ui::NativeTheme::ExtraParams* native_theme_extra_params) {
83 switch (part) {
84 case WebThemeEngine::PartScrollbarHorizontalTrack:
85 case WebThemeEngine::PartScrollbarVerticalTrack:
86 // Android doesn't draw scrollbars.
87 NOTREACHED();
88 break;
89 case WebThemeEngine::PartCheckbox:
90 native_theme_extra_params->button.checked = extra_params->button.checked;
91 native_theme_extra_params->button.indeterminate =
92 extra_params->button.indeterminate;
93 break;
94 case WebThemeEngine::PartRadio:
95 native_theme_extra_params->button.checked = extra_params->button.checked;
96 break;
97 case WebThemeEngine::PartButton:
98 native_theme_extra_params->button.is_default =
99 extra_params->button.isDefault;
100 native_theme_extra_params->button.has_border =
101 extra_params->button.hasBorder;
102 // Native buttons have a different focus style.
103 native_theme_extra_params->button.is_focused = false;
104 native_theme_extra_params->button.background_color =
105 extra_params->button.backgroundColor;
106 break;
107 case WebThemeEngine::PartTextField:
108 native_theme_extra_params->text_field.is_text_area =
109 extra_params->textField.isTextArea;
110 native_theme_extra_params->text_field.is_listbox =
111 extra_params->textField.isListbox;
112 native_theme_extra_params->text_field.background_color =
113 extra_params->textField.backgroundColor;
114 break;
115 case WebThemeEngine::PartMenuList:
116 native_theme_extra_params->menu_list.has_border =
117 extra_params->menuList.hasBorder;
118 native_theme_extra_params->menu_list.has_border_radius =
119 extra_params->menuList.hasBorderRadius;
120 native_theme_extra_params->menu_list.arrow_x =
121 extra_params->menuList.arrowX;
122 native_theme_extra_params->menu_list.arrow_y =
123 extra_params->menuList.arrowY;
124 native_theme_extra_params->menu_list.background_color =
125 extra_params->menuList.backgroundColor;
126 break;
127 case WebThemeEngine::PartSliderTrack:
128 case WebThemeEngine::PartSliderThumb:
129 native_theme_extra_params->slider.vertical =
130 extra_params->slider.vertical;
131 native_theme_extra_params->slider.in_drag = extra_params->slider.inDrag;
132 break;
133 case WebThemeEngine::PartInnerSpinButton:
134 native_theme_extra_params->inner_spin.spin_up =
135 extra_params->innerSpin.spinUp;
136 native_theme_extra_params->inner_spin.read_only =
137 extra_params->innerSpin.readOnly;
138 break;
139 case WebThemeEngine::PartProgressBar:
140 native_theme_extra_params->progress_bar.determinate =
141 extra_params->progressBar.determinate;
142 native_theme_extra_params->progress_bar.value_rect_x =
143 extra_params->progressBar.valueRectX;
144 native_theme_extra_params->progress_bar.value_rect_y =
145 extra_params->progressBar.valueRectY;
146 native_theme_extra_params->progress_bar.value_rect_width =
147 extra_params->progressBar.valueRectWidth;
148 native_theme_extra_params->progress_bar.value_rect_height =
149 extra_params->progressBar.valueRectHeight;
150 break;
151 default:
152 break; // Parts that have no extra params get here.
156 blink::WebSize WebThemeEngineImpl::getSize(WebThemeEngine::Part part) {
157 ui::NativeTheme::ExtraParams extra;
158 return ui::NativeTheme::instance()->GetPartSize(
159 NativeThemePart(part), ui::NativeTheme::kNormal, extra);
162 void WebThemeEngineImpl::paint(
163 blink::WebCanvas* canvas,
164 WebThemeEngine::Part part,
165 WebThemeEngine::State state,
166 const blink::WebRect& rect,
167 const WebThemeEngine::ExtraParams* extra_params) {
168 ui::NativeTheme::ExtraParams native_theme_extra_params;
169 GetNativeThemeExtraParams(
170 part, state, extra_params, &native_theme_extra_params);
171 ui::NativeTheme::instance()->Paint(
172 canvas,
173 NativeThemePart(part),
174 NativeThemeState(state),
175 gfx::Rect(rect),
176 native_theme_extra_params);
178 } // namespace content