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

Side by Side Diff: third_party/WebKit/Source/core/layout/LayoutTheme.cpp

Issue 1690493002: Switch to LayoutThemeMobile when emulating mobile device in DevTools. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Invalidate tapHighlightColor only Created 4 years, 10 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
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 24 matching lines...) Expand all
35 #include "core/html/HTMLDataListOptionsCollection.h" 35 #include "core/html/HTMLDataListOptionsCollection.h"
36 #include "core/html/HTMLFormControlElement.h" 36 #include "core/html/HTMLFormControlElement.h"
37 #include "core/html/HTMLInputElement.h" 37 #include "core/html/HTMLInputElement.h"
38 #include "core/html/HTMLMeterElement.h" 38 #include "core/html/HTMLMeterElement.h"
39 #include "core/html/HTMLOptionElement.h" 39 #include "core/html/HTMLOptionElement.h"
40 #include "core/html/parser/HTMLParserIdioms.h" 40 #include "core/html/parser/HTMLParserIdioms.h"
41 #include "core/html/shadow/MediaControlElements.h" 41 #include "core/html/shadow/MediaControlElements.h"
42 #include "core/html/shadow/ShadowElementNames.h" 42 #include "core/html/shadow/ShadowElementNames.h"
43 #include "core/html/shadow/SpinButtonElement.h" 43 #include "core/html/shadow/SpinButtonElement.h"
44 #include "core/html/shadow/TextControlInnerElements.h" 44 #include "core/html/shadow/TextControlInnerElements.h"
45 #include "core/layout/LayoutThemeMobile.h"
45 #include "core/page/FocusController.h" 46 #include "core/page/FocusController.h"
46 #include "core/page/Page.h" 47 #include "core/page/Page.h"
47 #include "core/style/ComputedStyle.h" 48 #include "core/style/ComputedStyle.h"
48 #include "platform/FileMetadata.h" 49 #include "platform/FileMetadata.h"
49 #include "platform/FloatConversion.h" 50 #include "platform/FloatConversion.h"
50 #include "platform/RuntimeEnabledFeatures.h" 51 #include "platform/RuntimeEnabledFeatures.h"
52 #include "platform/Theme.h"
51 #include "platform/fonts/FontSelector.h" 53 #include "platform/fonts/FontSelector.h"
52 #include "platform/text/PlatformLocale.h" 54 #include "platform/text/PlatformLocale.h"
53 #include "platform/text/StringTruncator.h" 55 #include "platform/text/StringTruncator.h"
54 #include "public/platform/Platform.h" 56 #include "public/platform/Platform.h"
55 #include "public/platform/WebFallbackThemeEngine.h" 57 #include "public/platform/WebFallbackThemeEngine.h"
56 #include "public/platform/WebRect.h" 58 #include "public/platform/WebRect.h"
57 #include "wtf/text/StringBuilder.h" 59 #include "wtf/text/StringBuilder.h"
58 60
59 #if USE(NEW_THEME)
60 #include "platform/Theme.h"
61 #endif
62
63 // The methods in this file are shared by all themes on every platform. 61 // The methods in this file are shared by all themes on every platform.
64 62
65 namespace blink { 63 namespace blink {
66 64
67 using namespace HTMLNames; 65 using namespace HTMLNames;
68 66
69 LayoutTheme::LayoutTheme() 67 LayoutTheme& LayoutTheme::theme()
68 {
69 if (RuntimeEnabledFeatures::mobileLayoutThemeEnabled()) {
70 DEFINE_STATIC_REF(LayoutTheme, layoutThemeMobile, (LayoutThemeMobile::cr eate()));
71 return *layoutThemeMobile;
72 }
73 return nativeTheme();
74 }
75
76 LayoutTheme::LayoutTheme(Theme* platformTheme)
70 : m_hasCustomFocusRingColor(false) 77 : m_hasCustomFocusRingColor(false)
71 #if USE(NEW_THEME) 78 , m_platformTheme(platformTheme)
72 , m_platformTheme(platformTheme())
73 #endif
74 { 79 {
75 } 80 }
76 81
77 void LayoutTheme::adjustStyle(ComputedStyle& style, Element* e) 82 void LayoutTheme::adjustStyle(ComputedStyle& style, Element* e)
78 { 83 {
79 ASSERT(style.hasAppearance()); 84 ASSERT(style.hasAppearance());
80 85
81 // Force inline and table display styles to be inline-block (except for tabl e- which is block) 86 // Force inline and table display styles to be inline-block (except for tabl e- which is block)
82 ControlPart part = style.appearance(); 87 ControlPart part = style.appearance();
83 if (style.display() == INLINE || style.display() == INLINE_TABLE || style.di splay() == TABLE_ROW_GROUP 88 if (style.display() == INLINE || style.display() == INLINE_TABLE || style.di splay() == TABLE_ROW_GROUP
(...skipping 12 matching lines...) Expand all
96 style.setAppearance(NoControlPart); 101 style.setAppearance(NoControlPart);
97 return; 102 return;
98 } 103 }
99 } 104 }
100 105
101 if (shouldUseFallbackTheme(style)) { 106 if (shouldUseFallbackTheme(style)) {
102 adjustStyleUsingFallbackTheme(style); 107 adjustStyleUsingFallbackTheme(style);
103 return; 108 return;
104 } 109 }
105 110
106 #if USE(NEW_THEME) 111 if (m_platformTheme) {
107 switch (part) { 112 switch (part) {
108 case CheckboxPart: 113 case CheckboxPart:
109 case InnerSpinButtonPart: 114 case InnerSpinButtonPart:
110 case RadioPart: 115 case RadioPart:
111 case PushButtonPart: 116 case PushButtonPart:
112 case SquareButtonPart: 117 case SquareButtonPart:
113 case ButtonPart: { 118 case ButtonPart: {
114 // Border 119 // Border
115 LengthBox borderBox(style.borderTopWidth(), style.borderRightWidth(), st yle.borderBottomWidth(), style.borderLeftWidth()); 120 LengthBox borderBox(style.borderTopWidth(), style.borderRightWidth() , style.borderBottomWidth(), style.borderLeftWidth());
116 borderBox = m_platformTheme->controlBorder(part, style.font().fontDescri ption(), borderBox, style.effectiveZoom()); 121 borderBox = m_platformTheme->controlBorder(part, style.font().fontDe scription(), borderBox, style.effectiveZoom());
117 if (borderBox.top().value() != static_cast<int>(style.borderTopWidth())) { 122 if (borderBox.top().value() != static_cast<int>(style.borderTopWidth ())) {
118 if (borderBox.top().value()) 123 if (borderBox.top().value())
119 style.setBorderTopWidth(borderBox.top().value()); 124 style.setBorderTopWidth(borderBox.top().value());
120 else 125 else
121 style.resetBorderTop(); 126 style.resetBorderTop();
127 }
128 if (borderBox.right().value() != static_cast<int>(style.borderRightW idth())) {
129 if (borderBox.right().value())
130 style.setBorderRightWidth(borderBox.right().value());
131 else
132 style.resetBorderRight();
133 }
134 if (borderBox.bottom().value() != static_cast<int>(style.borderBotto mWidth())) {
135 style.setBorderBottomWidth(borderBox.bottom().value());
136 if (borderBox.bottom().value())
137 style.setBorderBottomWidth(borderBox.bottom().value());
138 else
139 style.resetBorderBottom();
140 }
141 if (borderBox.left().value() != static_cast<int>(style.borderLeftWid th())) {
142 style.setBorderLeftWidth(borderBox.left().value());
143 if (borderBox.left().value())
144 style.setBorderLeftWidth(borderBox.left().value());
145 else
146 style.resetBorderLeft();
147 }
148
149 // Padding
150 LengthBox paddingBox = m_platformTheme->controlPadding(part, style.f ont().fontDescription(), style.paddingBox(), style.effectiveZoom());
151 if (paddingBox != style.paddingBox())
152 style.setPaddingBox(paddingBox);
153
154 // Whitespace
155 if (m_platformTheme->controlRequiresPreWhiteSpace(part))
156 style.setWhiteSpace(PRE);
157
158 // Width / Height
159 // The width and height here are affected by the zoom.
160 // FIXME: Check is flawed, since it doesn't take min-width/max-width into account.
161 LengthSize controlSize = m_platformTheme->controlSize(part, style.fo nt().fontDescription(), LengthSize(style.width(), style.height()), style.effecti veZoom());
162 if (controlSize.width() != style.width())
163 style.setWidth(controlSize.width());
164 if (controlSize.height() != style.height())
165 style.setHeight(controlSize.height());
166
167 // Min-Width / Min-Height
168 LengthSize minControlSize = m_platformTheme->minimumControlSize(part , style.font().fontDescription(), style.effectiveZoom());
169 if (minControlSize.width() != style.minWidth())
170 style.setMinWidth(minControlSize.width());
171 if (minControlSize.height() != style.minHeight())
172 style.setMinHeight(minControlSize.height());
173
174 // Font
175 FontDescription controlFont = m_platformTheme->controlFont(part, sty le.font().fontDescription(), style.effectiveZoom());
176 if (controlFont != style.font().fontDescription()) {
177 // Reset our line-height
178 style.setLineHeight(ComputedStyle::initialLineHeight());
179
180 // Now update our font.
181 if (style.setFontDescription(controlFont))
182 style.font().update(nullptr);
183 }
122 } 184 }
123 if (borderBox.right().value() != static_cast<int>(style.borderRightWidth ())) { 185 default:
124 if (borderBox.right().value()) 186 break;
125 style.setBorderRightWidth(borderBox.right().value());
126 else
127 style.resetBorderRight();
128 }
129 if (borderBox.bottom().value() != static_cast<int>(style.borderBottomWid th())) {
130 style.setBorderBottomWidth(borderBox.bottom().value());
131 if (borderBox.bottom().value())
132 style.setBorderBottomWidth(borderBox.bottom().value());
133 else
134 style.resetBorderBottom();
135 }
136 if (borderBox.left().value() != static_cast<int>(style.borderLeftWidth() )) {
137 style.setBorderLeftWidth(borderBox.left().value());
138 if (borderBox.left().value())
139 style.setBorderLeftWidth(borderBox.left().value());
140 else
141 style.resetBorderLeft();
142 }
143
144 // Padding
145 LengthBox paddingBox = m_platformTheme->controlPadding(part, style.font( ).fontDescription(), style.paddingBox(), style.effectiveZoom());
146 if (paddingBox != style.paddingBox())
147 style.setPaddingBox(paddingBox);
148
149 // Whitespace
150 if (m_platformTheme->controlRequiresPreWhiteSpace(part))
151 style.setWhiteSpace(PRE);
152
153 // Width / Height
154 // The width and height here are affected by the zoom.
155 // FIXME: Check is flawed, since it doesn't take min-width/max-width int o account.
156 LengthSize controlSize = m_platformTheme->controlSize(part, style.font() .fontDescription(), LengthSize(style.width(), style.height()), style.effectiveZo om());
157 if (controlSize.width() != style.width())
158 style.setWidth(controlSize.width());
159 if (controlSize.height() != style.height())
160 style.setHeight(controlSize.height());
161
162 // Min-Width / Min-Height
163 LengthSize minControlSize = m_platformTheme->minimumControlSize(part, st yle.font().fontDescription(), style.effectiveZoom());
164 if (minControlSize.width() != style.minWidth())
165 style.setMinWidth(minControlSize.width());
166 if (minControlSize.height() != style.minHeight())
167 style.setMinHeight(minControlSize.height());
168
169 // Font
170 FontDescription controlFont = m_platformTheme->controlFont(part, style.f ont().fontDescription(), style.effectiveZoom());
171 if (controlFont != style.font().fontDescription()) {
172 // Reset our line-height
173 style.setLineHeight(ComputedStyle::initialLineHeight());
174
175 // Now update our font.
176 if (style.setFontDescription(controlFont))
177 style.font().update(nullptr);
178 } 187 }
179 } 188 }
180 default: 189
181 break; 190 if (!m_platformTheme) {
191 // Call the appropriate style adjustment method based off the appearance value.
192 switch (style.appearance()) {
193 case CheckboxPart:
194 return adjustCheckboxStyle(style);
195 case RadioPart:
196 return adjustRadioStyle(style);
197 case PushButtonPart:
198 case SquareButtonPart:
199 case ButtonPart:
200 return adjustButtonStyle(style);
201 case InnerSpinButtonPart:
202 return adjustInnerSpinButtonStyle(style);
203 default:
204 break;
205 }
182 } 206 }
183 #endif
184 207
185 // Call the appropriate style adjustment method based off the appearance val ue. 208 // Call the appropriate style adjustment method based off the appearance val ue.
186 switch (style.appearance()) { 209 switch (style.appearance()) {
187 #if !USE(NEW_THEME)
188 case CheckboxPart:
189 return adjustCheckboxStyle(style);
190 case RadioPart:
191 return adjustRadioStyle(style);
192 case PushButtonPart:
193 case SquareButtonPart:
194 case ButtonPart:
195 return adjustButtonStyle(style);
196 case InnerSpinButtonPart:
197 return adjustInnerSpinButtonStyle(style);
198 #endif
199 case MenulistPart: 210 case MenulistPart:
200 return adjustMenuListStyle(style, e); 211 return adjustMenuListStyle(style, e);
201 case MenulistButtonPart: 212 case MenulistButtonPart:
202 return adjustMenuListButtonStyle(style, e); 213 return adjustMenuListButtonStyle(style, e);
203 case SliderThumbHorizontalPart: 214 case SliderThumbHorizontalPart:
204 case SliderThumbVerticalPart: 215 case SliderThumbVerticalPart:
205 return adjustSliderThumbStyle(style); 216 return adjustSliderThumbStyle(style);
206 case SearchFieldPart: 217 case SearchFieldPart:
207 return adjustSearchFieldStyle(style); 218 return adjustSearchFieldStyle(style);
208 case SearchFieldCancelButtonPart: 219 case SearchFieldCancelButtonPart:
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 return platformInactiveSelectionForegroundColor(); 372 return platformInactiveSelectionForegroundColor();
362 } 373 }
363 374
364 int LayoutTheme::baselinePosition(const LayoutObject* o) const 375 int LayoutTheme::baselinePosition(const LayoutObject* o) const
365 { 376 {
366 if (!o->isBox()) 377 if (!o->isBox())
367 return 0; 378 return 0;
368 379
369 const LayoutBox* box = toLayoutBox(o); 380 const LayoutBox* box = toLayoutBox(o);
370 381
371 #if USE(NEW_THEME) 382 if (m_platformTheme)
372 return box->size().height() + box->marginTop() + m_platformTheme->baselinePo sitionAdjustment(o->style()->appearance()) * o->style()->effectiveZoom(); 383 return box->size().height() + box->marginTop() + m_platformTheme->baseli nePositionAdjustment(o->style()->appearance()) * o->style()->effectiveZoom();
373 #else
374 return box->size().height() + box->marginTop(); 384 return box->size().height() + box->marginTop();
375 #endif
376 } 385 }
377 386
378 bool LayoutTheme::isControlContainer(ControlPart appearance) const 387 bool LayoutTheme::isControlContainer(ControlPart appearance) const
379 { 388 {
380 // There are more leaves than this, but we'll patch this function as we add support for 389 // There are more leaves than this, but we'll patch this function as we add support for
381 // more controls. 390 // more controls.
382 return appearance != CheckboxPart && appearance != RadioPart; 391 return appearance != CheckboxPart && appearance != RadioPart;
383 } 392 }
384 393
385 bool LayoutTheme::isControlStyled(const ComputedStyle& style) const 394 bool LayoutTheme::isControlStyled(const ComputedStyle& style) const
(...skipping 20 matching lines...) Expand all
406 case SliderVerticalPart: 415 case SliderVerticalPart:
407 return style.boxShadow(); 416 return style.boxShadow();
408 417
409 default: 418 default:
410 return false; 419 return false;
411 } 420 }
412 } 421 }
413 422
414 void LayoutTheme::addVisualOverflow(const LayoutObject& object, IntRect& borderB ox) 423 void LayoutTheme::addVisualOverflow(const LayoutObject& object, IntRect& borderB ox)
415 { 424 {
416 #if USE(NEW_THEME) 425 if (m_platformTheme)
417 m_platformTheme->addVisualOverflow(object.style()->appearance(), controlStat esForLayoutObject(object), object.style()->effectiveZoom(), borderBox); 426 m_platformTheme->addVisualOverflow(object.style()->appearance(), control StatesForLayoutObject(object), object.style()->effectiveZoom(), borderBox);
418 #endif
419 } 427 }
420 428
421 bool LayoutTheme::shouldDrawDefaultFocusRing(const LayoutObject& layoutObject) c onst 429 bool LayoutTheme::shouldDrawDefaultFocusRing(const LayoutObject& layoutObject) c onst
422 { 430 {
423 if (themeDrawsFocusRing(layoutObject.styleRef())) 431 if (themeDrawsFocusRing(layoutObject.styleRef()))
424 return false; 432 return false;
425 Node* node = layoutObject.node(); 433 Node* node = layoutObject.node();
426 if (!node) 434 if (!node)
427 return true; 435 return true;
428 if (!layoutObject.styleRef().hasAppearance() && !node->isLink()) 436 if (!layoutObject.styleRef().hasAppearance() && !node->isLink())
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
565 573
566 bool LayoutTheme::isSpinUpButtonPartHovered(const LayoutObject& o) 574 bool LayoutTheme::isSpinUpButtonPartHovered(const LayoutObject& o)
567 { 575 {
568 Node* node = o.node(); 576 Node* node = o.node();
569 if (!node || !node->isElementNode() || !toElement(node)->isSpinButtonElement ()) 577 if (!node || !node->isElementNode() || !toElement(node)->isSpinButtonElement ())
570 return false; 578 return false;
571 SpinButtonElement* element = toSpinButtonElement(node); 579 SpinButtonElement* element = toSpinButtonElement(node);
572 return element->upDownState() == SpinButtonElement::Up; 580 return element->upDownState() == SpinButtonElement::Up;
573 } 581 }
574 582
575 #if !USE(NEW_THEME)
576
577 void LayoutTheme::adjustCheckboxStyle(ComputedStyle& style) const 583 void LayoutTheme::adjustCheckboxStyle(ComputedStyle& style) const
578 { 584 {
579 // A summary of the rules for checkbox designed to match WinIE: 585 // A summary of the rules for checkbox designed to match WinIE:
580 // width/height - honored (WinIE actually scales its control for small width s, but lets it overflow for small heights.) 586 // width/height - honored (WinIE actually scales its control for small width s, but lets it overflow for small heights.)
581 // font-size - not honored (control has no text), but we use it to decide wh ich control size to use. 587 // font-size - not honored (control has no text), but we use it to decide wh ich control size to use.
582 setCheckboxSize(style); 588 setCheckboxSize(style);
583 589
584 // padding - not honored by WinIE, needs to be removed. 590 // padding - not honored by WinIE, needs to be removed.
585 style.resetPadding(); 591 style.resetPadding();
586 592
(...skipping 17 matching lines...) Expand all
604 style.resetBorder(); 610 style.resetBorder();
605 } 611 }
606 612
607 void LayoutTheme::adjustButtonStyle(ComputedStyle& style) const 613 void LayoutTheme::adjustButtonStyle(ComputedStyle& style) const
608 { 614 {
609 } 615 }
610 616
611 void LayoutTheme::adjustInnerSpinButtonStyle(ComputedStyle&) const 617 void LayoutTheme::adjustInnerSpinButtonStyle(ComputedStyle&) const
612 { 618 {
613 } 619 }
614 #endif
615 620
616 void LayoutTheme::adjustMenuListStyle(ComputedStyle&, Element*) const 621 void LayoutTheme::adjustMenuListStyle(ComputedStyle&, Element*) const
617 { 622 {
618 } 623 }
619 624
620 IntSize LayoutTheme::meterSizeForBounds(const LayoutMeter&, const IntRect& bound s) const 625 IntSize LayoutTheme::meterSizeForBounds(const LayoutMeter&, const IntRect& bound s) const
621 { 626 {
622 return bounds.size(); 627 return bounds.size();
623 } 628 }
624 629
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
937 942
938 // padding - not honored by WinIE, needs to be removed. 943 // padding - not honored by WinIE, needs to be removed.
939 style.resetPadding(); 944 style.resetPadding();
940 945
941 // border - honored by WinIE, but looks terrible (just paints in the control box and turns off the Windows XP theme) 946 // border - honored by WinIE, but looks terrible (just paints in the control box and turns off the Windows XP theme)
942 // for now, we will not honor it. 947 // for now, we will not honor it.
943 style.resetBorder(); 948 style.resetBorder();
944 } 949 }
945 950
946 } // namespace blink 951 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/layout/LayoutTheme.h ('k') | third_party/WebKit/Source/core/layout/LayoutThemeAndroid.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698