Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / content / child / webfallbackthemeengine_impl.cc
blobd720e35e17585bef089493e499fc5daef188a142
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/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;
14 using blink::WebRect;
15 using blink::WebFallbackThemeEngine;
17 namespace content {
19 static ui::NativeTheme::Part NativeThemePart(
20 WebFallbackThemeEngine::Part part) {
21 switch (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::PartScrollbarCorner:
39 return ui::NativeTheme::kScrollbarCorner;
40 case WebFallbackThemeEngine::PartCheckbox:
41 return ui::NativeTheme::kCheckbox;
42 case WebFallbackThemeEngine::PartRadio:
43 return ui::NativeTheme::kRadio;
44 case WebFallbackThemeEngine::PartButton:
45 return ui::NativeTheme::kPushButton;
46 case WebFallbackThemeEngine::PartTextField:
47 return ui::NativeTheme::kTextField;
48 case WebFallbackThemeEngine::PartMenuList:
49 return ui::NativeTheme::kMenuList;
50 case WebFallbackThemeEngine::PartSliderTrack:
51 return ui::NativeTheme::kSliderTrack;
52 case WebFallbackThemeEngine::PartSliderThumb:
53 return ui::NativeTheme::kSliderThumb;
54 case WebFallbackThemeEngine::PartInnerSpinButton:
55 return ui::NativeTheme::kInnerSpinButton;
56 case WebFallbackThemeEngine::PartProgressBar:
57 return ui::NativeTheme::kProgressBar;
58 default:
59 return ui::NativeTheme::kScrollbarDownArrow;
63 static ui::NativeTheme::State NativeThemeState(
64 WebFallbackThemeEngine::State state) {
65 switch (state) {
66 case WebFallbackThemeEngine::StateDisabled:
67 return ui::NativeTheme::kDisabled;
68 case WebFallbackThemeEngine::StateHover:
69 return ui::NativeTheme::kHovered;
70 case WebFallbackThemeEngine::StateNormal:
71 return ui::NativeTheme::kNormal;
72 case WebFallbackThemeEngine::StatePressed:
73 return ui::NativeTheme::kPressed;
74 default:
75 return ui::NativeTheme::kDisabled;
79 static void GetNativeThemeExtraParams(
80 WebFallbackThemeEngine::Part part,
81 WebFallbackThemeEngine::State state,
82 const WebFallbackThemeEngine::ExtraParams* extra_params,
83 ui::NativeTheme::ExtraParams* native_theme_extra_params) {
84 switch (part) {
85 case WebFallbackThemeEngine::PartScrollbarHorizontalTrack:
86 case WebFallbackThemeEngine::PartScrollbarVerticalTrack:
87 native_theme_extra_params->scrollbar_track.track_x =
88 extra_params->scrollbarTrack.trackX;
89 native_theme_extra_params->scrollbar_track.track_y =
90 extra_params->scrollbarTrack.trackY;
91 native_theme_extra_params->scrollbar_track.track_width =
92 extra_params->scrollbarTrack.trackWidth;
93 native_theme_extra_params->scrollbar_track.track_height =
94 extra_params->scrollbarTrack.trackHeight;
95 break;
96 case WebFallbackThemeEngine::PartCheckbox:
97 native_theme_extra_params->button.checked = extra_params->button.checked;
98 native_theme_extra_params->button.indeterminate =
99 extra_params->button.indeterminate;
100 break;
101 case WebFallbackThemeEngine::PartRadio:
102 native_theme_extra_params->button.checked = extra_params->button.checked;
103 break;
104 case WebFallbackThemeEngine::PartButton:
105 native_theme_extra_params->button.is_default =
106 extra_params->button.isDefault;
107 native_theme_extra_params->button.has_border =
108 extra_params->button.hasBorder;
109 // Native buttons have a different focus style.
110 native_theme_extra_params->button.is_focused = false;
111 native_theme_extra_params->button.background_color =
112 extra_params->button.backgroundColor;
113 break;
114 case WebFallbackThemeEngine::PartTextField:
115 native_theme_extra_params->text_field.is_text_area =
116 extra_params->textField.isTextArea;
117 native_theme_extra_params->text_field.is_listbox =
118 extra_params->textField.isListbox;
119 native_theme_extra_params->text_field.background_color =
120 extra_params->textField.backgroundColor;
121 break;
122 case WebFallbackThemeEngine::PartMenuList:
123 native_theme_extra_params->menu_list.has_border =
124 extra_params->menuList.hasBorder;
125 native_theme_extra_params->menu_list.has_border_radius =
126 extra_params->menuList.hasBorderRadius;
127 native_theme_extra_params->menu_list.arrow_x =
128 extra_params->menuList.arrowX;
129 native_theme_extra_params->menu_list.arrow_y =
130 extra_params->menuList.arrowY;
131 native_theme_extra_params->menu_list.background_color =
132 extra_params->menuList.backgroundColor;
133 break;
134 case WebFallbackThemeEngine::PartSliderTrack:
135 case WebFallbackThemeEngine::PartSliderThumb:
136 native_theme_extra_params->slider.vertical =
137 extra_params->slider.vertical;
138 native_theme_extra_params->slider.in_drag = extra_params->slider.inDrag;
139 break;
140 case WebFallbackThemeEngine::PartInnerSpinButton:
141 native_theme_extra_params->inner_spin.spin_up =
142 extra_params->innerSpin.spinUp;
143 native_theme_extra_params->inner_spin.read_only =
144 extra_params->innerSpin.readOnly;
145 break;
146 case WebFallbackThemeEngine::PartProgressBar:
147 native_theme_extra_params->progress_bar.determinate =
148 extra_params->progressBar.determinate;
149 native_theme_extra_params->progress_bar.value_rect_x =
150 extra_params->progressBar.valueRectX;
151 native_theme_extra_params->progress_bar.value_rect_y =
152 extra_params->progressBar.valueRectY;
153 native_theme_extra_params->progress_bar.value_rect_width =
154 extra_params->progressBar.valueRectWidth;
155 native_theme_extra_params->progress_bar.value_rect_height =
156 extra_params->progressBar.valueRectHeight;
157 break;
158 default:
159 break; // Parts that have no extra params get here.
163 WebFallbackThemeEngineImpl::WebFallbackThemeEngineImpl()
164 : theme_(new ui::FallbackTheme()) {
167 WebFallbackThemeEngineImpl::~WebFallbackThemeEngineImpl() {}
169 blink::WebSize WebFallbackThemeEngineImpl::getSize(
170 WebFallbackThemeEngine::Part part) {
171 ui::NativeTheme::ExtraParams extra;
172 return theme_->GetPartSize(NativeThemePart(part),
173 ui::NativeTheme::kNormal,
174 extra);
177 void WebFallbackThemeEngineImpl::paint(
178 blink::WebCanvas* canvas,
179 WebFallbackThemeEngine::Part part,
180 WebFallbackThemeEngine::State state,
181 const blink::WebRect& rect,
182 const WebFallbackThemeEngine::ExtraParams* extra_params) {
183 ui::NativeTheme::ExtraParams native_theme_extra_params;
184 GetNativeThemeExtraParams(
185 part, state, extra_params, &native_theme_extra_params);
186 theme_->Paint(canvas,
187 NativeThemePart(part),
188 NativeThemeState(state),
189 gfx::Rect(rect),
190 native_theme_extra_params);
193 } // namespace content