Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(595)

Side by Side Diff: Source/core/rendering/RenderTheme.cpp

Issue 14866009: Enable proper zooming of checkbox and radio button on Win and Mac. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/rendering/RenderTheme.h ('k') | Source/core/rendering/RenderThemeChromiumMac.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /** 1 /**
2 * This file is part of the theme implementation for form controls in WebCore. 2 * This file is part of the theme implementation for form controls in WebCore.
3 * 3 *
4 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2012 Apple Computer, Inc. 4 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2012 Apple Computer, Inc.
5 * 5 *
6 * This library is free software; you can redistribute it and/or 6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public 7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either 8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version. 9 * version 2 of the License, or (at your option) any later version.
10 * 10 *
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 #include "core/platform/FileSystem.h" 46 #include "core/platform/FileSystem.h"
47 #include "core/platform/FloatConversion.h" 47 #include "core/platform/FloatConversion.h"
48 #include "core/platform/LocalizedStrings.h" 48 #include "core/platform/LocalizedStrings.h"
49 #include "core/platform/graphics/FontSelector.h" 49 #include "core/platform/graphics/FontSelector.h"
50 #include "core/platform/graphics/GraphicsContextStateSaver.h" 50 #include "core/platform/graphics/GraphicsContextStateSaver.h"
51 #include "core/platform/graphics/StringTruncator.h" 51 #include "core/platform/graphics/StringTruncator.h"
52 #include "core/rendering/PaintInfo.h" 52 #include "core/rendering/PaintInfo.h"
53 #include "core/rendering/RenderMeter.h" 53 #include "core/rendering/RenderMeter.h"
54 #include "core/rendering/RenderView.h" 54 #include "core/rendering/RenderView.h"
55 #include "core/rendering/style/RenderStyle.h" 55 #include "core/rendering/style/RenderStyle.h"
56 #include <public/Platform.h>
57 #include <public/WebFallbackThemeEngine.h>
58 #include <public/WebRect.h>
56 59
57 #if ENABLE(INPUT_SPEECH) 60 #if ENABLE(INPUT_SPEECH)
58 #include "core/rendering/RenderInputSpeech.h" 61 #include "core/rendering/RenderInputSpeech.h"
59 #endif 62 #endif
60 63
61 // The methods in this file are shared by all themes on every platform. 64 // The methods in this file are shared by all themes on every platform.
62 65
63 namespace WebCore { 66 namespace WebCore {
64 67
65 using namespace HTMLNames; 68 using namespace HTMLNames;
66 69
67 static Color& customFocusRingColor() 70 static Color& customFocusRingColor()
68 { 71 {
69 DEFINE_STATIC_LOCAL(Color, color, ()); 72 DEFINE_STATIC_LOCAL(Color, color, ());
70 return color; 73 return color;
71 } 74 }
72 75
76 static WebKit::WebFallbackThemeEngine::State getWebFallbackThemeState(const Rend erTheme* theme, const RenderObject* o)
77 {
78 if (!theme->isEnabled(o))
79 return WebKit::WebFallbackThemeEngine::StateDisabled;
80 if (theme->isPressed(o))
81 return WebKit::WebFallbackThemeEngine::StatePressed;
82 if (theme->isHovered(o))
83 return WebKit::WebFallbackThemeEngine::StateHover;
84
85 return WebKit::WebFallbackThemeEngine::StateNormal;
86 }
87
73 RenderTheme::RenderTheme() 88 RenderTheme::RenderTheme()
74 #if USE(NEW_THEME) 89 #if USE(NEW_THEME)
75 : m_theme(platformTheme()) 90 : m_theme(platformTheme())
76 #endif 91 #endif
77 { 92 {
78 } 93 }
79 94
80 void RenderTheme::adjustStyle(StyleResolver* styleResolver, RenderStyle* style, Element* e, bool UAHasAppearance, const BorderData& border, const FillLayer& bac kground, const Color& backgroundColor) 95 void RenderTheme::adjustStyle(StyleResolver* styleResolver, RenderStyle* style, Element* e, bool UAHasAppearance, const BorderData& border, const FillLayer& bac kground, const Color& backgroundColor)
81 { 96 {
82 // Force inline and table display styles to be inline-block (except for tabl e- which is block) 97 // Force inline and table display styles to be inline-block (except for tabl e- which is block)
(...skipping 10 matching lines...) Expand all
93 if (part == MenulistPart) { 108 if (part == MenulistPart) {
94 style->setAppearance(MenulistButtonPart); 109 style->setAppearance(MenulistButtonPart);
95 part = MenulistButtonPart; 110 part = MenulistButtonPart;
96 } else 111 } else
97 style->setAppearance(NoControlPart); 112 style->setAppearance(NoControlPart);
98 } 113 }
99 114
100 if (!style->hasAppearance()) 115 if (!style->hasAppearance())
101 return; 116 return;
102 117
118 if (shouldUseFallbackTheme(style)) {
119 adjustStyleUsingFallbackTheme(styleResolver, style, e);
120 return;
121 }
122
103 #if USE(NEW_THEME) 123 #if USE(NEW_THEME)
104 switch (part) { 124 switch (part) {
105 case CheckboxPart: 125 case CheckboxPart:
106 case InnerSpinButtonPart: 126 case InnerSpinButtonPart:
107 case RadioPart: 127 case RadioPart:
108 case PushButtonPart: 128 case PushButtonPart:
109 case SquareButtonPart: 129 case SquareButtonPart:
110 case ButtonPart: { 130 case ButtonPart: {
111 // Border 131 // Border
112 LengthBox borderBox(style->borderTopWidth(), style->borderRightWidth(), style->borderBottomWidth(), style->borderLeftWidth()); 132 LengthBox borderBox(style->borderTopWidth(), style->borderRightWidth(), style->borderBottomWidth(), style->borderLeftWidth());
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 if (paintInfo.context->updatingControlTints()) { 271 if (paintInfo.context->updatingControlTints()) {
252 if (controlSupportsTints(o)) 272 if (controlSupportsTints(o))
253 o->repaint(); 273 o->repaint();
254 return false; 274 return false;
255 } 275 }
256 if (paintInfo.context->paintingDisabled()) 276 if (paintInfo.context->paintingDisabled())
257 return false; 277 return false;
258 278
259 ControlPart part = o->style()->appearance(); 279 ControlPart part = o->style()->appearance();
260 280
281 if (shouldUseFallbackTheme(o->style()))
282 return paintUsingFallbackTheme(o, paintInfo, r);
283
261 #if USE(NEW_THEME) 284 #if USE(NEW_THEME)
262 switch (part) { 285 switch (part) {
263 case CheckboxPart: 286 case CheckboxPart:
264 case RadioPart: 287 case RadioPart:
265 case PushButtonPart: 288 case PushButtonPart:
266 case SquareButtonPart: 289 case SquareButtonPart:
267 case ButtonPart: 290 case ButtonPart:
268 case InnerSpinButtonPart: 291 case InnerSpinButtonPart:
269 m_theme->paint(part, controlStatesForRenderer(o), const_cast<GraphicsCon text*>(paintInfo.context), r, o->style()->effectiveZoom(), o->view()->frameView( )); 292 m_theme->paint(part, controlStatesForRenderer(o), const_cast<GraphicsCon text*>(paintInfo.context), r, o->style()->effectiveZoom(), o->view()->frameView( ));
270 return false; 293 return false;
(...skipping 960 matching lines...) Expand 10 before | Expand all | Expand 10 after
1231 bool RenderTheme::supportsCalendarPicker(const AtomicString& type) const 1254 bool RenderTheme::supportsCalendarPicker(const AtomicString& type) const
1232 { 1255 {
1233 return type == InputTypeNames::date() 1256 return type == InputTypeNames::date()
1234 || type == InputTypeNames::datetime() 1257 || type == InputTypeNames::datetime()
1235 || type == InputTypeNames::datetimelocal() 1258 || type == InputTypeNames::datetimelocal()
1236 || type == InputTypeNames::month() 1259 || type == InputTypeNames::month()
1237 || type == InputTypeNames::week(); 1260 || type == InputTypeNames::week();
1238 } 1261 }
1239 #endif 1262 #endif
1240 1263
1264 bool RenderTheme::shouldUseFallbackTheme(RenderStyle*) const
1265 {
1266 return false;
1267 }
1268
1269 void RenderTheme::adjustStyleUsingFallbackTheme(StyleResolver* styleResolver, Re nderStyle* style, Element* e)
1270 {
1271 ControlPart part = style->appearance();
1272 switch (part) {
1273 case CheckboxPart:
1274 return adjustCheckboxStyleUsingFallbackTheme(styleResolver, style, e);
1275 case RadioPart:
1276 return adjustRadioStyleUsingFallbackTheme(styleResolver, style, e);
1277 default:
1278 break;
1279 }
1280 }
1281
1282 bool RenderTheme::paintUsingFallbackTheme(RenderObject* o, const PaintInfo& i, c onst IntRect& r)
1283 {
1284 ControlPart part = o->style()->appearance();
1285 switch (part) {
1286 case CheckboxPart:
1287 return paintCheckboxUsingFallbackTheme(o, i, r);
1288 case RadioPart:
1289 return paintRadioUsingFallbackTheme(o, i, r);
1290 default:
1291 break;
1292 }
1293 return true;
1294 }
1295
1296 // static
1297 void RenderTheme::setSizeIfAuto(RenderStyle* style, const IntSize& size)
1298 {
1299 if (style->width().isIntrinsicOrAuto())
1300 style->setWidth(Length(size.width(), Fixed));
1301 if (style->height().isAuto())
1302 style->setHeight(Length(size.height(), Fixed));
1303 }
1304
1305 bool RenderTheme::paintCheckboxUsingFallbackTheme(RenderObject* o, const PaintIn fo& i, const IntRect& r)
1306 {
1307 WebKit::WebFallbackThemeEngine::ExtraParams extraParams;
1308 WebKit::WebCanvas* canvas = i.context->canvas();
1309 extraParams.button.checked = isChecked(o);
1310 extraParams.button.indeterminate = isIndeterminate(o);
1311
1312 float zoomLevel = o->style()->effectiveZoom();
1313 GraphicsContextStateSaver stateSaver(*i.context);
1314 IntRect unzoomedRect = r;
1315 if (zoomLevel != 1) {
1316 unzoomedRect.setWidth(unzoomedRect.width() / zoomLevel);
1317 unzoomedRect.setHeight(unzoomedRect.height() / zoomLevel);
1318 i.context->translate(unzoomedRect.x(), unzoomedRect.y());
1319 i.context->scale(FloatSize(zoomLevel, zoomLevel));
1320 i.context->translate(-unzoomedRect.x(), -unzoomedRect.y());
1321 }
1322
1323 WebKit::Platform::current()->fallbackThemeEngine()->paint(canvas, WebKit::We bFallbackThemeEngine::PartCheckbox, getWebFallbackThemeState(this, o), WebKit::W ebRect(unzoomedRect), &extraParams);
1324 return false;
1325 }
1326
1327 void RenderTheme::adjustCheckboxStyleUsingFallbackTheme(StyleResolver*, RenderSt yle* style, Element*) const
1328 {
1329 // If the width and height are both specified, then we have nothing to do.
1330 if (!style->width().isIntrinsicOrAuto() && !style->height().isAuto())
1331 return;
1332
1333 IntSize size = WebKit::Platform::current()->fallbackThemeEngine()->getSize(W ebKit::WebFallbackThemeEngine::PartCheckbox);
1334 float zoomLevel = style->effectiveZoom();
1335 size.setWidth(size.width() * zoomLevel);
1336 size.setHeight(size.height() * zoomLevel);
1337 setSizeIfAuto(style, size);
1338
1339 // padding - not honored by WinIE, needs to be removed.
1340 style->resetPadding();
1341
1342 // border - honored by WinIE, but looks terrible (just paints in the control box and turns off the Windows XP theme)
1343 // for now, we will not honor it.
1344 style->resetBorder();
1345 }
1346
1347 bool RenderTheme::paintRadioUsingFallbackTheme(RenderObject* o, const PaintInfo& i, const IntRect& r)
1348 {
1349 WebKit::WebFallbackThemeEngine::ExtraParams extraParams;
1350 WebKit::WebCanvas* canvas = i.context->canvas();
1351 extraParams.button.checked = isChecked(o);
1352 extraParams.button.indeterminate = isIndeterminate(o);
1353
1354 float zoomLevel = o->style()->effectiveZoom();
1355 GraphicsContextStateSaver stateSaver(*i.context);
1356 IntRect unzoomedRect = r;
1357 if (zoomLevel != 1) {
1358 unzoomedRect.setWidth(unzoomedRect.width() / zoomLevel);
1359 unzoomedRect.setHeight(unzoomedRect.height() / zoomLevel);
1360 i.context->translate(unzoomedRect.x(), unzoomedRect.y());
1361 i.context->scale(FloatSize(zoomLevel, zoomLevel));
1362 i.context->translate(-unzoomedRect.x(), -unzoomedRect.y());
1363 }
1364
1365 WebKit::Platform::current()->fallbackThemeEngine()->paint(canvas, WebKit::We bFallbackThemeEngine::PartRadio, getWebFallbackThemeState(this, o), WebKit::WebR ect(unzoomedRect), &extraParams);
1366 return false;
1367 }
1368
1369 void RenderTheme::adjustRadioStyleUsingFallbackTheme(StyleResolver*, RenderStyle * style, Element*) const
1370 {
1371 // If the width and height are both specified, then we have nothing to do.
1372 if (!style->width().isIntrinsicOrAuto() && !style->height().isAuto())
1373 return;
1374
1375 IntSize size = WebKit::Platform::current()->fallbackThemeEngine()->getSize(W ebKit::WebFallbackThemeEngine::PartRadio);
1376 float zoomLevel = style->effectiveZoom();
1377 size.setWidth(size.width() * zoomLevel);
1378 size.setHeight(size.height() * zoomLevel);
1379 setSizeIfAuto(style, size);
1380
1381 // padding - not honored by WinIE, needs to be removed.
1382 style->resetPadding();
1383
1384 // border - honored by WinIE, but looks terrible (just paints in the control box and turns off the Windows XP theme)
1385 // for now, we will not honor it.
1386 style->resetBorder();
1387 }
1388
1241 } // namespace WebCore 1389 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/rendering/RenderTheme.h ('k') | Source/core/rendering/RenderThemeChromiumMac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698