Don't preload rarely seen large images
[chromium-blink-merge.git] / components / html_viewer / web_theme_engine_impl.cc
blob69518ee1c04ea6caede302a2a2ea2cbaefe79d8d
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 "components/html_viewer/web_theme_engine_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/native_theme.h"
12 using blink::WebCanvas;
13 using blink::WebColor;
14 using blink::WebRect;
15 using blink::WebThemeEngine;
17 namespace html_viewer {
18 namespace {
20 ui::NativeTheme::Part NativeThemePart(WebThemeEngine::Part part) {
21 switch (part) {
22 case WebThemeEngine::PartScrollbarDownArrow:
23 return ui::NativeTheme::kScrollbarDownArrow;
24 case WebThemeEngine::PartScrollbarLeftArrow:
25 return ui::NativeTheme::kScrollbarLeftArrow;
26 case WebThemeEngine::PartScrollbarRightArrow:
27 return ui::NativeTheme::kScrollbarRightArrow;
28 case WebThemeEngine::PartScrollbarUpArrow:
29 return ui::NativeTheme::kScrollbarUpArrow;
30 case WebThemeEngine::PartScrollbarHorizontalThumb:
31 return ui::NativeTheme::kScrollbarHorizontalThumb;
32 case WebThemeEngine::PartScrollbarVerticalThumb:
33 return ui::NativeTheme::kScrollbarVerticalThumb;
34 case WebThemeEngine::PartScrollbarHorizontalTrack:
35 return ui::NativeTheme::kScrollbarHorizontalTrack;
36 case WebThemeEngine::PartScrollbarVerticalTrack:
37 return ui::NativeTheme::kScrollbarVerticalTrack;
38 case WebThemeEngine::PartScrollbarCorner:
39 return ui::NativeTheme::kScrollbarCorner;
40 case WebThemeEngine::PartCheckbox:
41 return ui::NativeTheme::kCheckbox;
42 case WebThemeEngine::PartRadio:
43 return ui::NativeTheme::kRadio;
44 case WebThemeEngine::PartButton:
45 return ui::NativeTheme::kPushButton;
46 case WebThemeEngine::PartTextField:
47 return ui::NativeTheme::kTextField;
48 case WebThemeEngine::PartMenuList:
49 return ui::NativeTheme::kMenuList;
50 case WebThemeEngine::PartSliderTrack:
51 return ui::NativeTheme::kSliderTrack;
52 case WebThemeEngine::PartSliderThumb:
53 return ui::NativeTheme::kSliderThumb;
54 case WebThemeEngine::PartInnerSpinButton:
55 return ui::NativeTheme::kInnerSpinButton;
56 case WebThemeEngine::PartProgressBar:
57 return ui::NativeTheme::kProgressBar;
58 default:
59 return ui::NativeTheme::kScrollbarDownArrow;
63 ui::NativeTheme::State NativeThemeState(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 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 native_theme_extra_params->scrollbar_track.track_x =
87 extra_params->scrollbarTrack.trackX;
88 native_theme_extra_params->scrollbar_track.track_y =
89 extra_params->scrollbarTrack.trackY;
90 native_theme_extra_params->scrollbar_track.track_width =
91 extra_params->scrollbarTrack.trackWidth;
92 native_theme_extra_params->scrollbar_track.track_height =
93 extra_params->scrollbarTrack.trackHeight;
94 break;
95 case WebThemeEngine::PartCheckbox:
96 native_theme_extra_params->button.checked = extra_params->button.checked;
97 native_theme_extra_params->button.indeterminate =
98 extra_params->button.indeterminate;
99 break;
100 case WebThemeEngine::PartRadio:
101 native_theme_extra_params->button.checked = extra_params->button.checked;
102 break;
103 case WebThemeEngine::PartButton:
104 native_theme_extra_params->button.is_default =
105 extra_params->button.isDefault;
106 native_theme_extra_params->button.has_border =
107 extra_params->button.hasBorder;
108 // Native buttons have a different focus style.
109 native_theme_extra_params->button.is_focused = false;
110 native_theme_extra_params->button.background_color =
111 extra_params->button.backgroundColor;
112 break;
113 case WebThemeEngine::PartTextField:
114 native_theme_extra_params->text_field.is_text_area =
115 extra_params->textField.isTextArea;
116 native_theme_extra_params->text_field.is_listbox =
117 extra_params->textField.isListbox;
118 native_theme_extra_params->text_field.background_color =
119 extra_params->textField.backgroundColor;
120 break;
121 case WebThemeEngine::PartMenuList:
122 native_theme_extra_params->menu_list.has_border =
123 extra_params->menuList.hasBorder;
124 native_theme_extra_params->menu_list.has_border_radius =
125 extra_params->menuList.hasBorderRadius;
126 native_theme_extra_params->menu_list.arrow_x =
127 extra_params->menuList.arrowX;
128 native_theme_extra_params->menu_list.arrow_y =
129 extra_params->menuList.arrowY;
130 native_theme_extra_params->menu_list.background_color =
131 extra_params->menuList.backgroundColor;
132 break;
133 case WebThemeEngine::PartSliderTrack:
134 case WebThemeEngine::PartSliderThumb:
135 native_theme_extra_params->slider.vertical =
136 extra_params->slider.vertical;
137 native_theme_extra_params->slider.in_drag = extra_params->slider.inDrag;
138 break;
139 case WebThemeEngine::PartInnerSpinButton:
140 native_theme_extra_params->inner_spin.spin_up =
141 extra_params->innerSpin.spinUp;
142 native_theme_extra_params->inner_spin.read_only =
143 extra_params->innerSpin.readOnly;
144 break;
145 case WebThemeEngine::PartProgressBar:
146 native_theme_extra_params->progress_bar.determinate =
147 extra_params->progressBar.determinate;
148 native_theme_extra_params->progress_bar.value_rect_x =
149 extra_params->progressBar.valueRectX;
150 native_theme_extra_params->progress_bar.value_rect_y =
151 extra_params->progressBar.valueRectY;
152 native_theme_extra_params->progress_bar.value_rect_width =
153 extra_params->progressBar.valueRectWidth;
154 native_theme_extra_params->progress_bar.value_rect_height =
155 extra_params->progressBar.valueRectHeight;
156 break;
157 default:
158 break; // Parts that have no extra params get here.
162 } // namespace
164 blink::WebSize WebThemeEngineImpl::getSize(WebThemeEngine::Part part) {
165 ui::NativeTheme::ExtraParams extra;
166 return ui::NativeTheme::instance()->GetPartSize(NativeThemePart(part),
167 ui::NativeTheme::kNormal,
168 extra);
171 void WebThemeEngineImpl::paint(
172 blink::WebCanvas* canvas,
173 WebThemeEngine::Part part,
174 WebThemeEngine::State state,
175 const blink::WebRect& rect,
176 const WebThemeEngine::ExtraParams* extra_params) {
177 ui::NativeTheme::ExtraParams native_theme_extra_params;
178 GetNativeThemeExtraParams(
179 part, state, extra_params, &native_theme_extra_params);
180 ui::NativeTheme::instance()->Paint(
181 canvas,
182 NativeThemePart(part),
183 NativeThemeState(state),
184 gfx::Rect(rect),
185 native_theme_extra_params);
188 void WebThemeEngineImpl::paintStateTransition(blink::WebCanvas* canvas,
189 WebThemeEngine::Part part,
190 WebThemeEngine::State startState,
191 WebThemeEngine::State endState,
192 double progress,
193 const blink::WebRect& rect) {
194 ui::NativeTheme::instance()->PaintStateTransition(
195 canvas,
196 NativeThemePart(part),
197 NativeThemeState(startState),
198 NativeThemeState(endState),
199 progress,
200 gfx::Rect(rect));
203 } // namespace html_viewer