2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com)
4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com)
5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights reserved.
6 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org>
7 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org>
8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
9 * Copyright (c) 2011, Code Aurora Forum. All rights reserved.
10 * Copyright (C) Research In Motion Limited 2011. All rights reserved.
11 * Copyright (C) 2012 Google Inc. All rights reserved.
13 * This library is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU Library General Public
15 * License as published by the Free Software Foundation; either
16 * version 2 of the License, or (at your option) any later version.
18 * This library is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 * Library General Public License for more details.
23 * You should have received a copy of the GNU Library General Public License
24 * along with this library; see the file COPYING.LIB. If not, write to
25 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
26 * Boston, MA 02110-1301, USA.
30 #include "StyleResolver.h"
32 #include "Attribute.h"
33 #include "CSSBorderImage.h"
34 #include "CSSCalculationValue.h"
35 #include "CSSCursorImageValue.h"
36 #include "CSSDefaultStyleSheets.h"
37 #include "CSSFilterImageValue.h"
38 #include "CSSFontFaceRule.h"
39 #include "CSSFontSelector.h"
40 #include "CSSLineBoxContainValue.h"
41 #include "CSSPageRule.h"
42 #include "CSSParser.h"
43 #include "CSSPrimitiveValueMappings.h"
44 #include "CSSPropertyNames.h"
45 #include "CSSReflectValue.h"
46 #include "CSSSelector.h"
47 #include "CSSSelectorList.h"
48 #include "CSSStyleRule.h"
49 #include "CSSSupportsRule.h"
50 #include "CSSTimingFunctionValue.h"
51 #include "CSSValueList.h"
52 #include "CachedImage.h"
53 #include "CalculationValue.h"
54 #include "ContentData.h"
56 #include "CounterContent.h"
57 #include "CursorList.h"
58 #include "DeprecatedStyleBuilder.h"
59 #include "DocumentStyleSheetCollection.h"
60 #include "ElementRuleCollector.h"
61 #include "FontFeatureValue.h"
62 #include "FontValue.h"
64 #include "FrameSelection.h"
65 #include "FrameView.h"
66 #include "HTMLDocument.h"
67 #include "HTMLIFrameElement.h"
68 #include "HTMLInputElement.h"
69 #include "HTMLNames.h"
70 #include "HTMLOptGroupElement.h"
71 #include "HTMLOptionElement.h"
72 #include "HTMLProgressElement.h"
73 #include "HTMLStyleElement.h"
74 #include "HTMLTableElement.h"
75 #include "HTMLTextAreaElement.h"
76 #include "InsertionPoint.h"
77 #include "InspectorInstrumentation.h"
78 #include "KeyframeList.h"
80 #include "LocaleToScriptMapping.h"
81 #include "MathMLNames.h"
82 #include "MediaList.h"
83 #include "MediaQueryEvaluator.h"
84 #include "NodeRenderStyle.h"
85 #include "NodeRenderingTraversal.h"
87 #include "PageRuleCollector.h"
89 #include "QuotesData.h"
91 #include "RenderRegion.h"
92 #include "RenderScrollbar.h"
93 #include "RenderScrollbarTheme.h"
94 #include "RenderStyleConstants.h"
95 #include "RenderTheme.h"
96 #include "RenderView.h"
98 #include "SVGDocumentExtensions.h"
99 #include "SVGFontFaceElement.h"
100 #include "SecurityOrigin.h"
101 #include "SelectorCheckerFastPath.h"
102 #include "Settings.h"
103 #include "ShadowData.h"
104 #include "ShadowRoot.h"
105 #include "ShadowValue.h"
106 #include "StyleCachedImage.h"
107 #include "StyleFontSizeFunctions.h"
108 #include "StyleGeneratedImage.h"
109 #include "StylePendingImage.h"
110 #include "StylePropertySet.h"
111 #include "StylePropertyShorthand.h"
112 #include "StyleRule.h"
113 #include "StyleRuleImport.h"
114 #include "StyleSheetContents.h"
115 #include "StyleSheetList.h"
117 #include "TransformFunctions.h"
118 #include "TransformOperations.h"
119 #include "UserAgentStyleSheets.h"
120 #include "ViewportStyleResolver.h"
121 #include "VisitedLinkState.h"
122 #include "WebKitCSSKeyframeRule.h"
123 #include "WebKitCSSKeyframesRule.h"
124 #include "WebKitCSSRegionRule.h"
125 #include "WebKitCSSTransformValue.h"
126 #include "WebKitFontFamilyNames.h"
127 #include "XMLNames.h"
128 #include <wtf/StdLibExtras.h>
129 #include <wtf/Vector.h>
131 #if ENABLE(CSS_FILTERS)
132 #include "FilterOperation.h"
133 #include "WebKitCSSFilterValue.h"
136 #if ENABLE(CSS_IMAGE_SET)
137 #include "CSSImageSetValue.h"
138 #include "StyleCachedImageSet.h"
141 #if ENABLE(CSS_SHADERS)
142 #include "CustomFilterArrayParameter.h"
143 #include "CustomFilterColorParameter.h"
144 #include "CustomFilterConstants.h"
145 #include "CustomFilterNumberParameter.h"
146 #include "CustomFilterOperation.h"
147 #include "CustomFilterParameter.h"
148 #include "CustomFilterProgramInfo.h"
149 #include "CustomFilterTransformParameter.h"
150 #include "StyleCachedShader.h"
151 #include "StyleCustomFilterProgram.h"
152 #include "StyleCustomFilterProgramCache.h"
153 #include "StylePendingShader.h"
154 #include "StyleShader.h"
155 #include "WebKitCSSMixFunctionValue.h"
156 #include "WebKitCSSShaderValue.h"
159 #if ENABLE(CSS_SHAPES)
160 #include "CachedResourceLoader.h"
163 #if ENABLE(CSS_VARIABLES)
164 #include "CSSVariableValue.h"
167 #if ENABLE(DASHBOARD_SUPPORT)
168 #include "DashboardRegion.h"
171 #if ENABLE(PLUGIN_PROXY_FOR_VIDEO)
172 #include "HTMLAudioElement.h"
176 #include "CachedSVGDocument.h"
177 #include "CachedSVGDocumentReference.h"
178 #include "SVGDocument.h"
179 #include "SVGElement.h"
180 #include "SVGNames.h"
181 #include "SVGURIReference.h"
182 #include "WebKitCSSSVGDocumentValue.h"
185 #if ENABLE(VIDEO_TRACK)
186 #include "WebVTTElement.h"
193 using namespace HTMLNames;
195 #define HANDLE_INHERIT(prop, Prop) \
197 m_state.style()->set##Prop(m_state.parentStyle()->prop()); \
201 #define HANDLE_INHERIT_AND_INITIAL(prop, Prop) \
202 HANDLE_INHERIT(prop, Prop) \
204 m_state.style()->set##Prop(RenderStyle::initial##Prop()); \
208 RenderStyle* StyleResolver::s_styleNotYetAvailable;
210 inline void StyleResolver::State::cacheBorderAndBackground()
212 m_hasUAAppearance = m_style->hasAppearance();
213 if (m_hasUAAppearance) {
214 m_borderData = m_style->border();
215 m_backgroundData = *m_style->backgroundLayers();
216 m_backgroundColor = m_style->backgroundColor();
220 inline void StyleResolver::State::clear()
226 m_regionForStyling = 0;
227 m_pendingImageProperties.clear();
228 #if ENABLE(CSS_SHADERS)
229 m_hasPendingShaders = false;
231 #if ENABLE(CSS_FILTERS) && ENABLE(SVG)
232 m_pendingSVGDocuments.clear();
236 void StyleResolver::MatchResult::addMatchedProperties(const StylePropertySet& properties, StyleRule* rule, unsigned linkMatchType, PropertyWhitelistType propertyWhitelistType)
238 matchedProperties.grow(matchedProperties.size() + 1);
239 StyleResolver::MatchedProperties& newProperties = matchedProperties.last();
240 newProperties.properties = const_cast<StylePropertySet*>(&properties);
241 newProperties.linkMatchType = linkMatchType;
242 newProperties.whitelistType = propertyWhitelistType;
243 matchedRules.append(rule);
246 StyleResolver::StyleResolver(Document& document, bool matchAuthorAndUserStyles)
247 : m_matchedPropertiesCacheAdditionsSinceLastSweep(0)
248 , m_matchedPropertiesCacheSweepTimer(this, &StyleResolver::sweepMatchedPropertiesCache)
249 , m_document(document)
250 , m_matchAuthorAndUserStyles(matchAuthorAndUserStyles)
251 , m_fontSelector(CSSFontSelector::create(&m_document))
252 #if ENABLE(CSS_DEVICE_ADAPTATION)
253 , m_viewportStyleResolver(ViewportStyleResolver::create(&document))
255 , m_deprecatedStyleBuilder(DeprecatedStyleBuilder::sharedStyleBuilder())
258 Element* root = m_document.documentElement();
260 CSSDefaultStyleSheets::initDefaultStyle(root);
262 // construct document root element default style. this is needed
263 // to evaluate media queries that contain relative constraints, like "screen and (max-width: 10em)"
264 // This is here instead of constructor, because when constructor is run,
265 // document doesn't have documentElement
266 // NOTE: this assumes that element that gets passed to styleForElement -call
267 // is always from the document that owns the style selector
268 FrameView* view = m_document.view();
270 m_medium = adoptPtr(new MediaQueryEvaluator(view->mediaType()));
272 m_medium = adoptPtr(new MediaQueryEvaluator("all"));
275 m_rootDefaultStyle = styleForElement(root, 0, DisallowStyleSharing, MatchOnlyUserAgentRules);
277 if (m_rootDefaultStyle && view)
278 m_medium = adoptPtr(new MediaQueryEvaluator(view->mediaType(), &view->frame(), m_rootDefaultStyle.get()));
280 m_ruleSets.resetAuthorStyle();
282 DocumentStyleSheetCollection& styleSheetCollection = m_document.styleSheetCollection();
283 m_ruleSets.initUserStyle(styleSheetCollection, *m_medium, *this);
285 #if ENABLE(SVG_FONTS)
286 if (m_document.svgExtensions()) {
287 const HashSet<SVGFontFaceElement*>& svgFontFaceElements = m_document.svgExtensions()->svgFontFaceElements();
288 HashSet<SVGFontFaceElement*>::const_iterator end = svgFontFaceElements.end();
289 for (HashSet<SVGFontFaceElement*>::const_iterator it = svgFontFaceElements.begin(); it != end; ++it)
290 fontSelector()->addFontFaceRule((*it)->fontFaceRule());
294 appendAuthorStyleSheets(0, styleSheetCollection.activeAuthorStyleSheets());
297 void StyleResolver::appendAuthorStyleSheets(unsigned firstNew, const Vector<RefPtr<CSSStyleSheet> >& styleSheets)
299 m_ruleSets.appendAuthorStyleSheets(firstNew, styleSheets, m_medium.get(), m_inspectorCSSOMWrappers, document().isViewSource(), this);
300 if (document().renderView() && document().renderView()->style())
301 document().renderView()->style()->font().update(fontSelector());
303 #if ENABLE(CSS_DEVICE_ADAPTATION)
304 viewportStyleResolver()->resolve();
308 void StyleResolver::pushParentElement(Element* parent)
310 const ContainerNode* parentsParent = parent->parentOrShadowHostElement();
312 // We are not always invoked consistently. For example, script execution can cause us to enter
313 // style recalc in the middle of tree building. We may also be invoked from somewhere within the tree.
314 // Reset the stack in this case, or if we see a new root element.
315 // Otherwise just push the new parent.
316 if (!parentsParent || m_selectorFilter.parentStackIsEmpty())
317 m_selectorFilter.setupParentStack(parent);
319 m_selectorFilter.pushParent(parent);
321 // Note: We mustn't skip ShadowRoot nodes for the scope stack.
323 m_scopeResolver->push(parent, parent->parentOrShadowHostNode());
326 void StyleResolver::popParentElement(Element* parent)
328 // Note that we may get invoked for some random elements in some wacky cases during style resolve.
329 // Pause maintaining the stack in this case.
330 if (m_selectorFilter.parentStackIsConsistent(parent))
331 m_selectorFilter.popParent();
333 m_scopeResolver->pop(parent);
336 void StyleResolver::pushParentShadowRoot(const ShadowRoot* shadowRoot)
338 ASSERT(shadowRoot->hostElement());
340 m_scopeResolver->push(shadowRoot, shadowRoot->hostElement());
343 void StyleResolver::popParentShadowRoot(const ShadowRoot* shadowRoot)
345 ASSERT(shadowRoot->hostElement());
347 m_scopeResolver->pop(shadowRoot);
350 // This is a simplified style setting function for keyframe styles
351 void StyleResolver::addKeyframeStyle(PassRefPtr<StyleRuleKeyframes> rule)
353 AtomicString s(rule->name());
354 m_keyframesRuleMap.set(s.impl(), rule);
357 StyleResolver::~StyleResolver()
359 m_fontSelector->clearDocument();
361 #if ENABLE(CSS_DEVICE_ADAPTATION)
362 m_viewportStyleResolver->clearDocument();
366 void StyleResolver::sweepMatchedPropertiesCache(Timer<StyleResolver>*)
368 // Look for cache entries containing a style declaration with a single ref and remove them.
369 // This may happen when an element attribute mutation causes it to generate a new inlineStyle()
370 // or presentationAttributeStyle(), potentially leaving this cache with the last ref on the old one.
371 Vector<unsigned, 16> toRemove;
372 MatchedPropertiesCache::iterator it = m_matchedPropertiesCache.begin();
373 MatchedPropertiesCache::iterator end = m_matchedPropertiesCache.end();
374 for (; it != end; ++it) {
375 Vector<MatchedProperties>& matchedProperties = it->value.matchedProperties;
376 for (size_t i = 0; i < matchedProperties.size(); ++i) {
377 if (matchedProperties[i].properties->hasOneRef()) {
378 toRemove.append(it->key);
383 for (size_t i = 0; i < toRemove.size(); ++i)
384 m_matchedPropertiesCache.remove(toRemove[i]);
386 m_matchedPropertiesCacheAdditionsSinceLastSweep = 0;
389 inline bool StyleResolver::styleSharingCandidateMatchesHostRules()
391 #if ENABLE(SHADOW_DOM)
392 return m_scopeResolver && m_scopeResolver->styleSharingCandidateMatchesHostRules(m_state.element());
398 bool StyleResolver::classNamesAffectedByRules(const SpaceSplitString& classNames) const
400 for (unsigned i = 0; i < classNames.size(); ++i) {
401 if (m_ruleSets.features().classesInRules.contains(classNames[i].impl()))
407 inline void StyleResolver::State::initElement(Element* e)
410 m_styledElement = e && e->isStyledElement() ? static_cast<StyledElement*>(e) : 0;
411 m_elementLinkState = e ? e->document().visitedLinkState().determineLinkState(e) : NotInsideLink;
414 inline void StyleResolver::initElement(Element* e)
416 if (m_state.element() != e) {
417 m_state.initElement(e);
418 if (e && e == e->document().documentElement()) {
419 e->document().setDirectionSetOnDocumentElement(false);
420 e->document().setWritingModeSetOnDocumentElement(false);
425 inline void StyleResolver::State::initForStyleResolve(Document& document, Element* e, RenderStyle* parentStyle, RenderRegion* regionForStyling)
427 m_regionForStyling = regionForStyling;
430 m_parentNode = NodeRenderingTraversal::parent(e);
431 bool resetStyleInheritance = hasShadowRootParent(e) && toShadowRoot(e->parentNode())->resetStyleInheritance();
432 m_parentStyle = resetStyleInheritance ? 0 :
433 parentStyle ? parentStyle :
434 m_parentNode ? m_parentNode->renderStyle() : 0;
437 m_parentStyle = parentStyle;
440 Node* docElement = e ? e->document().documentElement() : 0;
441 RenderStyle* docStyle = document.renderStyle();
442 m_rootElementStyle = docElement && e != docElement ? docElement->renderStyle() : docStyle;
445 m_pendingImageProperties.clear();
449 static const unsigned cStyleSearchThreshold = 10;
450 static const unsigned cStyleSearchLevelThreshold = 10;
452 static inline bool parentElementPreventsSharing(const Element* parentElement)
456 return parentElement->hasFlagsSetDuringStylingOfChildren();
459 Node* StyleResolver::locateCousinList(Element* parent, unsigned& visitedNodeCount) const
461 if (visitedNodeCount >= cStyleSearchThreshold * cStyleSearchLevelThreshold)
463 if (!parent || !parent->isStyledElement())
465 #if ENABLE(STYLE_SCOPED)
466 if (parent->hasScopedHTMLStyleChild())
469 StyledElement* p = static_cast<StyledElement*>(parent);
470 if (p->inlineStyle())
473 if (p->isSVGElement() && toSVGElement(p)->animatedSMILStyleProperties())
476 if (p->hasID() && m_ruleSets.features().idsInRules.contains(p->idForStyleResolution().impl()))
479 RenderStyle* parentStyle = p->renderStyle();
480 unsigned subcount = 0;
481 Node* thisCousin = p;
482 Node* currentNode = p->previousSibling();
484 // Reserve the tries for this level. This effectively makes sure that the algorithm
485 // will never go deeper than cStyleSearchLevelThreshold levels into recursion.
486 visitedNodeCount += cStyleSearchThreshold;
488 while (currentNode) {
490 if (currentNode->renderStyle() == parentStyle && currentNode->lastChild()
491 && currentNode->isElementNode() && !parentElementPreventsSharing(toElement(currentNode))
492 #if ENABLE(SHADOW_DOM)
493 && !toElement(currentNode)->authorShadowRoot()
496 // Adjust for unused reserved tries.
497 visitedNodeCount -= cStyleSearchThreshold - subcount;
498 return currentNode->lastChild();
500 if (subcount >= cStyleSearchThreshold)
502 currentNode = currentNode->previousSibling();
504 currentNode = locateCousinList(thisCousin->parentElement(), visitedNodeCount);
505 thisCousin = currentNode;
511 bool StyleResolver::styleSharingCandidateMatchesRuleSet(RuleSet* ruleSet)
516 ElementRuleCollector collector(this, m_state);
517 return collector.hasAnyMatchingRules(ruleSet);
520 bool StyleResolver::canShareStyleWithControl(StyledElement* element) const
522 const State& state = m_state;
523 HTMLInputElement* thisInputElement = element->toInputElement();
524 HTMLInputElement* otherInputElement = state.element()->toInputElement();
526 if (!thisInputElement || !otherInputElement)
529 if (thisInputElement->elementData() != otherInputElement->elementData()) {
530 if (thisInputElement->fastGetAttribute(typeAttr) != otherInputElement->fastGetAttribute(typeAttr))
532 if (thisInputElement->fastGetAttribute(readonlyAttr) != otherInputElement->fastGetAttribute(readonlyAttr))
536 if (thisInputElement->isAutofilled() != otherInputElement->isAutofilled())
538 if (thisInputElement->shouldAppearChecked() != otherInputElement->shouldAppearChecked())
540 if (thisInputElement->shouldAppearIndeterminate() != otherInputElement->shouldAppearIndeterminate())
542 if (thisInputElement->isRequired() != otherInputElement->isRequired())
545 if (element->isDisabledFormControl() != state.element()->isDisabledFormControl())
548 if (element->isDefaultButtonForForm() != state.element()->isDefaultButtonForForm())
551 if (state.document().containsValidityStyleRules()) {
552 bool willValidate = element->willValidate();
554 if (willValidate != state.element()->willValidate())
557 if (willValidate && (element->isValidFormControlElement() != state.element()->isValidFormControlElement()))
560 if (element->isInRange() != state.element()->isInRange())
563 if (element->isOutOfRange() != state.element()->isOutOfRange())
570 static inline bool elementHasDirectionAuto(Element* element)
572 // FIXME: This line is surprisingly hot, we may wish to inline hasDirectionAuto into StyleResolver.
573 return element->isHTMLElement() && toHTMLElement(element)->hasDirectionAuto();
576 bool StyleResolver::sharingCandidateHasIdenticalStyleAffectingAttributes(StyledElement* sharingCandidate) const
578 const State& state = m_state;
579 if (state.element()->elementData() == sharingCandidate->elementData())
581 if (state.element()->fastGetAttribute(XMLNames::langAttr) != sharingCandidate->fastGetAttribute(XMLNames::langAttr))
583 if (state.element()->fastGetAttribute(langAttr) != sharingCandidate->fastGetAttribute(langAttr))
586 if (!state.elementAffectedByClassRules()) {
587 if (sharingCandidate->hasClass() && classNamesAffectedByRules(sharingCandidate->classNames()))
589 } else if (sharingCandidate->hasClass()) {
591 // SVG elements require a (slow!) getAttribute comparision because "class" is an animatable attribute for SVG.
592 if (state.element()->isSVGElement()) {
593 if (state.element()->getAttribute(classAttr) != sharingCandidate->getAttribute(classAttr))
597 if (state.element()->classNames() != sharingCandidate->classNames())
605 if (state.styledElement()->presentationAttributeStyle() != sharingCandidate->presentationAttributeStyle())
608 #if ENABLE(PROGRESS_ELEMENT)
609 if (state.element()->hasTagName(progressTag)) {
610 if (state.element()->shouldAppearIndeterminate() != sharingCandidate->shouldAppearIndeterminate())
618 bool StyleResolver::canShareStyleWithElement(StyledElement* element) const
620 RenderStyle* style = element->renderStyle();
621 const State& state = m_state;
627 if (style->hasUniquePseudoStyle())
629 if (element->tagQName() != state.element()->tagQName())
631 if (element->inlineStyle())
633 if (element->needsStyleRecalc())
636 if (element->isSVGElement() && toSVGElement(element)->animatedSMILStyleProperties())
639 if (element->isLink() != state.element()->isLink())
641 if (element->hovered() != state.element()->hovered())
643 if (element->active() != state.element()->active())
645 if (element->focused() != state.element()->focused())
647 if (element->shadowPseudoId() != state.element()->shadowPseudoId())
649 if (element == element->document().cssTarget())
651 if (!sharingCandidateHasIdenticalStyleAffectingAttributes(element))
653 if (element->additionalPresentationAttributeStyle() != state.styledElement()->additionalPresentationAttributeStyle())
656 if (element->hasID() && m_ruleSets.features().idsInRules.contains(element->idForStyleResolution().impl()))
658 #if ENABLE(STYLE_SCOPED)
659 if (element->hasScopedHTMLStyleChild())
663 // FIXME: We should share style for option and optgroup whenever possible.
664 // Before doing so, we need to resolve issues in HTMLSelectElement::recalcListItems
665 // and RenderMenuList::setText. See also https://bugs.webkit.org/show_bug.cgi?id=88405
666 if (isHTMLOptionElement(element) || isHTMLOptGroupElement(element))
669 bool isControl = element->isFormControlElement();
671 if (isControl != state.element()->isFormControlElement())
674 if (isControl && !canShareStyleWithControl(element))
677 if (style->transitions() || style->animations())
680 #if USE(ACCELERATED_COMPOSITING)
681 // Turn off style sharing for elements that can gain layers for reasons outside of the style system.
682 // See comments in RenderObject::setStyle().
683 if (element->hasTagName(iframeTag) || element->hasTagName(frameTag) || element->hasTagName(embedTag) || element->hasTagName(objectTag) || element->hasTagName(appletTag) || element->hasTagName(canvasTag)
684 #if ENABLE(PLUGIN_PROXY_FOR_VIDEO)
685 // With proxying, the media elements are backed by a RenderEmbeddedObject.
686 || element->hasTagName(videoTag) || isHTMLAudioElement(element)
692 if (elementHasDirectionAuto(element))
695 if (element->isLink() && state.elementLinkState() != style->insideLink())
698 #if ENABLE(VIDEO_TRACK)
699 // Deny sharing styles between WebVTT and non-WebVTT nodes.
700 if (element->isWebVTTElement() != state.element()->isWebVTTElement())
703 if (element->isWebVTTElement() && state.element()->isWebVTTElement() && toWebVTTElement(element)->isPastNode() != toWebVTTElement(state.element())->isPastNode())
707 #if ENABLE(FULLSCREEN_API)
708 if (element == element->document().webkitCurrentFullScreenElement() || state.element() == state.document().webkitCurrentFullScreenElement())
714 inline StyledElement* StyleResolver::findSiblingForStyleSharing(Node* node, unsigned& count) const
716 for (; node; node = node->previousSibling()) {
717 if (!node->isStyledElement())
719 if (canShareStyleWithElement(static_cast<StyledElement*>(node)))
721 if (count++ == cStyleSearchThreshold)
724 return static_cast<StyledElement*>(node);
727 RenderStyle* StyleResolver::locateSharedStyle()
729 State& state = m_state;
730 if (!state.styledElement() || !state.parentStyle())
733 // If the element has inline style it is probably unique.
734 if (state.styledElement()->inlineStyle())
737 if (state.styledElement()->isSVGElement() && toSVGElement(state.styledElement())->animatedSMILStyleProperties())
740 // Ids stop style sharing if they show up in the stylesheets.
741 if (state.styledElement()->hasID() && m_ruleSets.features().idsInRules.contains(state.styledElement()->idForStyleResolution().impl()))
743 if (parentElementPreventsSharing(state.element()->parentElement()))
745 #if ENABLE(STYLE_SCOPED)
746 if (state.styledElement()->hasScopedHTMLStyleChild())
749 if (state.element() == state.document().cssTarget())
751 if (elementHasDirectionAuto(state.element()))
754 // Cache whether state.element is affected by any known class selectors.
755 // FIXME: This shouldn't be a member variable. The style sharing code could be factored out of StyleResolver.
756 state.setElementAffectedByClassRules(state.element() && state.element()->hasClass() && classNamesAffectedByRules(state.element()->classNames()));
758 // Check previous siblings and their cousins.
760 unsigned visitedNodeCount = 0;
761 StyledElement* shareElement = 0;
762 Node* cousinList = state.styledElement()->previousSibling();
764 shareElement = findSiblingForStyleSharing(cousinList, count);
767 cousinList = locateCousinList(cousinList->parentElement(), visitedNodeCount);
770 // If we have exhausted all our budget or our cousins.
774 // Can't share if sibling rules apply. This is checked at the end as it should rarely fail.
775 if (styleSharingCandidateMatchesRuleSet(m_ruleSets.sibling()))
777 // Can't share if attribute rules apply.
778 if (styleSharingCandidateMatchesRuleSet(m_ruleSets.uncommonAttribute()))
780 // Can't share if @host @-rules apply.
781 if (styleSharingCandidateMatchesHostRules())
783 // Tracking child index requires unique style for each node. This may get set by the sibling rule match above.
784 if (parentElementPreventsSharing(state.element()->parentElement()))
786 return shareElement->renderStyle();
789 static inline bool isAtShadowBoundary(const Element* element)
793 ContainerNode* parentNode = element->parentNode();
794 return parentNode && parentNode->isShadowRoot();
797 PassRefPtr<RenderStyle> StyleResolver::styleForElement(Element* element, RenderStyle* defaultParent,
798 StyleSharingBehavior sharingBehavior, RuleMatchingBehavior matchingBehavior, RenderRegion* regionForStyling)
800 // Once an element has a renderer, we don't try to destroy it, since otherwise the renderer
801 // will vanish if a style recalc happens during loading.
802 if (sharingBehavior == AllowStyleSharing && !element->document().haveStylesheetsLoaded() && !element->renderer()) {
803 if (!s_styleNotYetAvailable) {
804 s_styleNotYetAvailable = RenderStyle::create().leakRef();
805 s_styleNotYetAvailable->setDisplay(NONE);
806 s_styleNotYetAvailable->font().update(m_fontSelector);
808 element->document().setHasNodesWithPlaceholderStyle();
809 return s_styleNotYetAvailable;
812 State& state = m_state;
813 initElement(element);
814 state.initForStyleResolve(document(), element, defaultParent, regionForStyling);
815 if (sharingBehavior == AllowStyleSharing) {
816 RenderStyle* sharedStyle = locateSharedStyle();
823 if (state.parentStyle()) {
824 state.setStyle(RenderStyle::create());
825 state.style()->inheritFrom(state.parentStyle(), isAtShadowBoundary(element) ? RenderStyle::AtShadowBoundary : RenderStyle::NotAtShadowBoundary);
827 state.setStyle(defaultStyleForElement());
828 state.setParentStyle(RenderStyle::clone(state.style()));
831 if (element->isLink()) {
832 state.style()->setIsLink(true);
833 EInsideLink linkState = state.elementLinkState();
834 if (linkState != NotInsideLink) {
835 bool forceVisited = InspectorInstrumentation::forcePseudoState(element, CSSSelector::PseudoVisited);
837 linkState = InsideVisitedLink;
839 state.style()->setInsideLink(linkState);
842 bool needsCollection = false;
843 CSSDefaultStyleSheets::ensureDefaultStyleSheetsForElement(element, needsCollection);
845 m_ruleSets.collectFeatures(document().isViewSource(), m_scopeResolver.get());
847 ElementRuleCollector collector(this, state);
848 collector.setRegionForStyling(regionForStyling);
849 collector.setMedium(m_medium.get());
851 if (matchingBehavior == MatchOnlyUserAgentRules)
852 collector.matchUARules();
854 collector.matchAllRules(m_matchAuthorAndUserStyles, matchingBehavior != MatchAllRulesExcludingSMIL);
856 applyMatchedProperties(collector.matchedResult(), element);
858 // Clean up our style object's display and text decorations (among other fixups).
859 adjustRenderStyle(state.style(), state.parentStyle(), element);
861 state.clear(); // Clear out for the next resolve.
863 document().didAccessStyleResolver();
865 // Now return the style.
866 return state.takeStyle();
869 PassRefPtr<RenderStyle> StyleResolver::styleForKeyframe(const RenderStyle* elementStyle, const StyleKeyframe* keyframe, KeyframeValue& keyframeValue)
872 result.addMatchedProperties(keyframe->properties());
874 ASSERT(!m_state.style());
876 State& state = m_state;
879 state.setStyle(RenderStyle::clone(elementStyle));
880 state.setLineHeightValue(0);
882 // We don't need to bother with !important. Since there is only ever one
883 // decl, there's nothing to override. So just add the first properties.
884 bool inheritedOnly = false;
885 applyMatchedProperties<HighPriorityProperties>(result, false, 0, result.matchedProperties.size() - 1, inheritedOnly);
887 // If our font got dirtied, go ahead and update it now.
890 // Line-height is set when we are sure we decided on the font-size
891 if (state.lineHeightValue())
892 applyProperty(CSSPropertyLineHeight, state.lineHeightValue());
894 // Now do rest of the properties.
895 applyMatchedProperties<LowPriorityProperties>(result, false, 0, result.matchedProperties.size() - 1, inheritedOnly);
897 // If our font got dirtied by one of the non-essential font props,
898 // go ahead and update it a second time.
901 // Start loading resources referenced by this style.
902 loadPendingResources();
904 // Add all the animating properties to the keyframe.
905 unsigned propertyCount = keyframe->properties().propertyCount();
906 for (unsigned i = 0; i < propertyCount; ++i) {
907 CSSPropertyID property = keyframe->properties().propertyAt(i).id();
908 // Timing-function within keyframes is special, because it is not animated; it just
909 // describes the timing function between this keyframe and the next.
910 if (property != CSSPropertyWebkitAnimationTimingFunction)
911 keyframeValue.addProperty(property);
914 document().didAccessStyleResolver();
916 return state.takeStyle();
919 void StyleResolver::keyframeStylesForAnimation(Element* e, const RenderStyle* elementStyle, KeyframeList& list)
923 // Get the keyframesRule for this name
924 if (!e || list.animationName().isEmpty())
927 m_keyframesRuleMap.checkConsistency();
929 KeyframesRuleMap::iterator it = m_keyframesRuleMap.find(list.animationName().impl());
930 if (it == m_keyframesRuleMap.end())
933 const StyleRuleKeyframes* keyframesRule = it->value.get();
935 // Construct and populate the style for each keyframe
936 const Vector<RefPtr<StyleKeyframe> >& keyframes = keyframesRule->keyframes();
937 for (unsigned i = 0; i < keyframes.size(); ++i) {
938 // Apply the declaration to the style. This is a simplified version of the logic in styleForElement
940 m_state.initForStyleResolve(document(), e);
942 const StyleKeyframe* keyframe = keyframes[i].get();
944 KeyframeValue keyframeValue(0, 0);
945 keyframeValue.setStyle(styleForKeyframe(elementStyle, keyframe, keyframeValue));
947 // Add this keyframe style to all the indicated key times
949 keyframe->getKeys(keys);
950 for (size_t keyIndex = 0; keyIndex < keys.size(); ++keyIndex) {
951 keyframeValue.setKey(keys[keyIndex]);
952 list.insert(keyframeValue);
956 // If the 0% keyframe is missing, create it (but only if there is at least one other keyframe)
957 int initialListSize = list.size();
958 if (initialListSize > 0 && list[0].key()) {
959 static StyleKeyframe* zeroPercentKeyframe;
960 if (!zeroPercentKeyframe) {
961 zeroPercentKeyframe = StyleKeyframe::create(MutableStylePropertySet::create()).leakRef();
962 zeroPercentKeyframe->setKeyText("0%");
964 KeyframeValue keyframeValue(0, 0);
965 keyframeValue.setStyle(styleForKeyframe(elementStyle, zeroPercentKeyframe, keyframeValue));
966 list.insert(keyframeValue);
969 // If the 100% keyframe is missing, create it (but only if there is at least one other keyframe)
970 if (initialListSize > 0 && (list[list.size() - 1].key() != 1)) {
971 static StyleKeyframe* hundredPercentKeyframe;
972 if (!hundredPercentKeyframe) {
973 hundredPercentKeyframe = StyleKeyframe::create(MutableStylePropertySet::create()).leakRef();
974 hundredPercentKeyframe->setKeyText("100%");
976 KeyframeValue keyframeValue(1, 0);
977 keyframeValue.setStyle(styleForKeyframe(elementStyle, hundredPercentKeyframe, keyframeValue));
978 list.insert(keyframeValue);
982 PassRefPtr<RenderStyle> StyleResolver::pseudoStyleForElement(Element* e, const PseudoStyleRequest& pseudoStyleRequest, RenderStyle* parentStyle)
988 State& state = m_state;
992 state.initForStyleResolve(document(), e, parentStyle);
994 if (m_state.parentStyle()) {
995 state.setStyle(RenderStyle::create());
996 state.style()->inheritFrom(m_state.parentStyle());
998 state.setStyle(defaultStyleForElement());
999 state.setParentStyle(RenderStyle::clone(state.style()));
1002 // Since we don't use pseudo-elements in any of our quirk/print user agent rules, don't waste time walking
1005 // Check UA, user and author rules.
1006 ElementRuleCollector collector(this, state);
1007 collector.setPseudoStyleRequest(pseudoStyleRequest);
1008 collector.setMedium(m_medium.get());
1009 collector.matchUARules();
1011 if (m_matchAuthorAndUserStyles) {
1012 collector.matchUserRules(false);
1013 collector.matchAuthorRules(false);
1016 if (collector.matchedResult().matchedProperties.isEmpty())
1019 state.style()->setStyleType(pseudoStyleRequest.pseudoId);
1021 applyMatchedProperties(collector.matchedResult(), e);
1023 // Clean up our style object's display and text decorations (among other fixups).
1024 adjustRenderStyle(state.style(), m_state.parentStyle(), 0);
1026 // Start loading resources referenced by this style.
1027 loadPendingResources();
1029 document().didAccessStyleResolver();
1031 // Now return the style.
1032 return state.takeStyle();
1035 PassRefPtr<RenderStyle> StyleResolver::styleForPage(int pageIndex)
1037 m_state.initForStyleResolve(document(), document().documentElement()); // m_rootElementStyle will be set to the document style.
1039 m_state.setStyle(RenderStyle::create());
1040 m_state.style()->inheritFrom(m_state.rootElementStyle());
1042 PageRuleCollector collector(m_state, m_ruleSets);
1043 collector.matchAllPageRules(pageIndex);
1044 m_state.setLineHeightValue(0);
1045 bool inheritedOnly = false;
1047 MatchResult& result = collector.matchedResult();
1048 #if ENABLE(CSS_VARIABLES)
1049 applyMatchedProperties<VariableDefinitions>(result, false, 0, result.matchedProperties.size() - 1, inheritedOnly);
1051 applyMatchedProperties<HighPriorityProperties>(result, false, 0, result.matchedProperties.size() - 1, inheritedOnly);
1053 // If our font got dirtied, go ahead and update it now.
1056 // Line-height is set when we are sure we decided on the font-size.
1057 if (m_state.lineHeightValue())
1058 applyProperty(CSSPropertyLineHeight, m_state.lineHeightValue());
1060 applyMatchedProperties<LowPriorityProperties>(result, false, 0, result.matchedProperties.size() - 1, inheritedOnly);
1062 // Start loading resources referenced by this style.
1063 loadPendingResources();
1065 document().didAccessStyleResolver();
1067 // Now return the style.
1068 return m_state.takeStyle();
1071 PassRefPtr<RenderStyle> StyleResolver::defaultStyleForElement()
1073 m_state.setStyle(RenderStyle::create());
1074 // Make sure our fonts are initialized if we don't inherit them from our parent style.
1075 if (Settings* settings = documentSettings()) {
1076 initializeFontStyle(settings);
1077 m_state.style()->font().update(fontSelector());
1079 m_state.style()->font().update(0);
1081 return m_state.takeStyle();
1084 static void addIntrinsicMargins(RenderStyle* style)
1086 // Intrinsic margin value.
1087 const int intrinsicMargin = 2 * style->effectiveZoom();
1089 // FIXME: Using width/height alone and not also dealing with min-width/max-width is flawed.
1090 // FIXME: Using "quirk" to decide the margin wasn't set is kind of lame.
1091 if (style->width().isIntrinsicOrAuto()) {
1092 if (style->marginLeft().quirk())
1093 style->setMarginLeft(Length(intrinsicMargin, Fixed));
1094 if (style->marginRight().quirk())
1095 style->setMarginRight(Length(intrinsicMargin, Fixed));
1098 if (style->height().isAuto()) {
1099 if (style->marginTop().quirk())
1100 style->setMarginTop(Length(intrinsicMargin, Fixed));
1101 if (style->marginBottom().quirk())
1102 style->setMarginBottom(Length(intrinsicMargin, Fixed));
1106 static EDisplay equivalentBlockDisplay(EDisplay display, bool isFloating, bool strictParsing)
1117 // It is a WinIE bug that floated list items lose their bullets, so we'll emulate the quirk, but only in quirks mode.
1118 if (!strictParsing && isFloating)
1134 case TABLE_ROW_GROUP:
1135 case TABLE_HEADER_GROUP:
1136 case TABLE_FOOTER_GROUP:
1138 case TABLE_COLUMN_GROUP:
1144 ASSERT_NOT_REACHED();
1147 ASSERT_NOT_REACHED();
1151 // CSS requires text-decoration to be reset at each DOM element for tables,
1152 // inline blocks, inline tables, run-ins, shadow DOM crossings, floating elements,
1153 // and absolute or relatively positioned elements.
1154 static bool doesNotInheritTextDecoration(RenderStyle* style, Element* e)
1156 return style->display() == TABLE || style->display() == INLINE_TABLE || style->display() == RUN_IN
1157 || style->display() == INLINE_BLOCK || style->display() == INLINE_BOX || isAtShadowBoundary(e)
1158 || style->isFloating() || style->hasOutOfFlowPosition();
1161 static bool isDisplayFlexibleBox(EDisplay display)
1163 return display == FLEX || display == INLINE_FLEX;
1166 #if ENABLE(ACCELERATED_OVERFLOW_SCROLLING)
1167 static bool isScrollableOverflow(EOverflow overflow)
1169 return overflow == OSCROLL || overflow == OAUTO || overflow == OOVERLAY;
1173 void StyleResolver::adjustRenderStyle(RenderStyle* style, RenderStyle* parentStyle, Element *e)
1175 ASSERT(parentStyle);
1177 // Cache our original display.
1178 style->setOriginalDisplay(style->display());
1180 if (style->display() != NONE) {
1181 // If we have a <td> that specifies a float property, in quirks mode we just drop the float
1183 // Sites also commonly use display:inline/block on <td>s and <table>s. In quirks mode we force
1184 // these tags to retain their display types.
1185 if (document().inQuirksMode() && e) {
1186 if (e->hasTagName(tdTag)) {
1187 style->setDisplay(TABLE_CELL);
1188 style->setFloating(NoFloat);
1189 } else if (isHTMLTableElement(e))
1190 style->setDisplay(style->isDisplayInlineType() ? INLINE_TABLE : TABLE);
1193 if (e && (e->hasTagName(tdTag) || e->hasTagName(thTag))) {
1194 if (style->whiteSpace() == KHTML_NOWRAP) {
1195 // Figure out if we are really nowrapping or if we should just
1196 // use normal instead. If the width of the cell is fixed, then
1197 // we don't actually use NOWRAP.
1198 if (style->width().isFixed())
1199 style->setWhiteSpace(NORMAL);
1201 style->setWhiteSpace(NOWRAP);
1205 // Tables never support the -webkit-* values for text-align and will reset back to the default.
1206 if (e && isHTMLTableElement(e) && (style->textAlign() == WEBKIT_LEFT || style->textAlign() == WEBKIT_CENTER || style->textAlign() == WEBKIT_RIGHT))
1207 style->setTextAlign(TASTART);
1209 // Frames and framesets never honor position:relative or position:absolute. This is necessary to
1210 // fix a crash where a site tries to position these objects. They also never honor display.
1211 if (e && (e->hasTagName(frameTag) || e->hasTagName(framesetTag))) {
1212 style->setPosition(StaticPosition);
1213 style->setDisplay(BLOCK);
1216 // Ruby text does not support float or position. This might change with evolution of the specification.
1217 if (e && e->hasTagName(rtTag)) {
1218 style->setPosition(StaticPosition);
1219 style->setFloating(NoFloat);
1222 // FIXME: We shouldn't be overriding start/-webkit-auto like this. Do it in html.css instead.
1223 // Table headers with a text-align of -webkit-auto will change the text-align to center.
1224 if (e && e->hasTagName(thTag) && style->textAlign() == TASTART)
1225 style->setTextAlign(CENTER);
1227 if (e && e->hasTagName(legendTag))
1228 style->setDisplay(BLOCK);
1230 // Absolute/fixed positioned elements, floating elements and the document element need block-like outside display.
1231 if (style->hasOutOfFlowPosition() || style->isFloating() || (e && e->document().documentElement() == e))
1232 style->setDisplay(equivalentBlockDisplay(style->display(), style->isFloating(), !document().inQuirksMode()));
1234 // FIXME: Don't support this mutation for pseudo styles like first-letter or first-line, since it's not completely
1235 // clear how that should work.
1236 if (style->display() == INLINE && style->styleType() == NOPSEUDO && style->writingMode() != parentStyle->writingMode())
1237 style->setDisplay(INLINE_BLOCK);
1239 // After performing the display mutation, check table rows. We do not honor position:relative or position:sticky on
1240 // table rows or cells. This has been established for position:relative in CSS2.1 (and caused a crash in containingBlock()
1242 if ((style->display() == TABLE_HEADER_GROUP || style->display() == TABLE_ROW_GROUP
1243 || style->display() == TABLE_FOOTER_GROUP || style->display() == TABLE_ROW)
1244 && style->hasInFlowPosition())
1245 style->setPosition(StaticPosition);
1247 // writing-mode does not apply to table row groups, table column groups, table rows, and table columns.
1248 // FIXME: Table cells should be allowed to be perpendicular or flipped with respect to the table, though.
1249 if (style->display() == TABLE_COLUMN || style->display() == TABLE_COLUMN_GROUP || style->display() == TABLE_FOOTER_GROUP
1250 || style->display() == TABLE_HEADER_GROUP || style->display() == TABLE_ROW || style->display() == TABLE_ROW_GROUP
1251 || style->display() == TABLE_CELL)
1252 style->setWritingMode(parentStyle->writingMode());
1254 // FIXME: Since we don't support block-flow on flexible boxes yet, disallow setting
1255 // of block-flow to anything other than TopToBottomWritingMode.
1256 // https://bugs.webkit.org/show_bug.cgi?id=46418 - Flexible box support.
1257 if (style->writingMode() != TopToBottomWritingMode && (style->display() == BOX || style->display() == INLINE_BOX))
1258 style->setWritingMode(TopToBottomWritingMode);
1260 if (isDisplayFlexibleBox(parentStyle->display())) {
1261 style->setFloating(NoFloat);
1262 style->setDisplay(equivalentBlockDisplay(style->display(), style->isFloating(), !document().inQuirksMode()));
1266 // Make sure our z-index value is only applied if the object is positioned.
1267 if (style->position() == StaticPosition && !isDisplayFlexibleBox(parentStyle->display()))
1268 style->setHasAutoZIndex();
1270 // Auto z-index becomes 0 for the root element and transparent objects. This prevents
1271 // cases where objects that should be blended as a single unit end up with a non-transparent
1272 // object wedged in between them. Auto z-index also becomes 0 for objects that specify transforms/masks/reflections.
1273 if (style->hasAutoZIndex() && ((e && e->document().documentElement() == e)
1274 || style->opacity() < 1.0f
1275 || style->hasTransformRelatedProperty()
1277 || style->clipPath()
1278 || style->boxReflect()
1279 || style->hasFilter()
1280 || style->hasBlendMode()
1281 || style->position() == StickyPosition
1282 || (style->position() == FixedPosition && e && e->document().page() && e->document().page()->settings().fixedPositionCreatesStackingContext())
1284 style->setZIndex(0);
1286 // Textarea considers overflow visible as auto.
1287 if (e && isHTMLTextAreaElement(e)) {
1288 style->setOverflowX(style->overflowX() == OVISIBLE ? OAUTO : style->overflowX());
1289 style->setOverflowY(style->overflowY() == OVISIBLE ? OAUTO : style->overflowY());
1292 if (doesNotInheritTextDecoration(style, e))
1293 style->setTextDecorationsInEffect(style->textDecoration());
1295 style->addToTextDecorationsInEffect(style->textDecoration());
1297 // If either overflow value is not visible, change to auto.
1298 if (style->overflowX() == OMARQUEE && style->overflowY() != OMARQUEE)
1299 style->setOverflowY(OMARQUEE);
1300 else if (style->overflowY() == OMARQUEE && style->overflowX() != OMARQUEE)
1301 style->setOverflowX(OMARQUEE);
1302 else if (style->overflowX() == OVISIBLE && style->overflowY() != OVISIBLE) {
1303 // FIXME: Once we implement pagination controls, overflow-x should default to hidden
1304 // if overflow-y is set to -webkit-paged-x or -webkit-page-y. For now, we'll let it
1305 // default to auto so we can at least scroll through the pages.
1306 style->setOverflowX(OAUTO);
1307 } else if (style->overflowY() == OVISIBLE && style->overflowX() != OVISIBLE)
1308 style->setOverflowY(OAUTO);
1310 // Call setStylesForPaginationMode() if a pagination mode is set for any non-root elements. If these
1311 // styles are specified on a root element, then they will be incorporated in
1312 // Style::createForDocument().
1313 if ((style->overflowY() == OPAGEDX || style->overflowY() == OPAGEDY) && !(e && (e->hasTagName(htmlTag) || e->hasTagName(bodyTag))))
1314 style->setColumnStylesFromPaginationMode(WebCore::paginationModeForRenderStyle(style));
1316 // Table rows, sections and the table itself will support overflow:hidden and will ignore scroll/auto.
1317 // FIXME: Eventually table sections will support auto and scroll.
1318 if (style->display() == TABLE || style->display() == INLINE_TABLE
1319 || style->display() == TABLE_ROW_GROUP || style->display() == TABLE_ROW) {
1320 if (style->overflowX() != OVISIBLE && style->overflowX() != OHIDDEN)
1321 style->setOverflowX(OVISIBLE);
1322 if (style->overflowY() != OVISIBLE && style->overflowY() != OHIDDEN)
1323 style->setOverflowY(OVISIBLE);
1326 // Menulists should have visible overflow
1327 if (style->appearance() == MenulistPart) {
1328 style->setOverflowX(OVISIBLE);
1329 style->setOverflowY(OVISIBLE);
1332 #if ENABLE(ACCELERATED_OVERFLOW_SCROLLING)
1333 // Touch overflow scrolling creates a stacking context.
1334 if (style->hasAutoZIndex() && style->useTouchOverflowScrolling() && (isScrollableOverflow(style->overflowX()) || isScrollableOverflow(style->overflowY())))
1335 style->setZIndex(0);
1338 // Cull out any useless layers and also repeat patterns into additional layers.
1339 style->adjustBackgroundLayers();
1340 style->adjustMaskLayers();
1342 // Do the same for animations and transitions.
1343 style->adjustAnimations();
1344 style->adjustTransitions();
1346 // Important: Intrinsic margins get added to controls before the theme has adjusted the style, since the theme will
1347 // alter fonts and heights/widths.
1348 if (e && e->isFormControlElement() && style->fontSize() >= 11) {
1349 // Don't apply intrinsic margins to image buttons. The designer knows how big the images are,
1350 // so we have to treat all image buttons as though they were explicitly sized.
1351 if (!isHTMLInputElement(e) || !toHTMLInputElement(e)->isImageButton())
1352 addIntrinsicMargins(style);
1355 // Let the theme also have a crack at adjusting the style.
1356 if (style->hasAppearance())
1357 RenderTheme::defaultTheme()->adjustStyle(this, style, e, m_state.hasUAAppearance(), m_state.borderData(), m_state.backgroundData(), m_state.backgroundColor());
1359 // If we have first-letter pseudo style, do not share this style.
1360 if (style->hasPseudoStyle(FIRST_LETTER))
1363 // FIXME: when dropping the -webkit prefix on transform-style, we should also have opacity < 1 cause flattening.
1364 if (style->preserves3D() && (style->overflowX() != OVISIBLE
1365 || style->overflowY() != OVISIBLE
1366 || style->hasFilter()))
1367 style->setTransformStyle3D(TransformStyle3DFlat);
1369 // Seamless iframes behave like blocks. Map their display to inline-block when marked inline.
1370 if (e && e->hasTagName(iframeTag) && style->display() == INLINE && toHTMLIFrameElement(e)->shouldDisplaySeamlessly())
1371 style->setDisplay(INLINE_BLOCK);
1373 adjustGridItemPosition(style);
1376 if (e && e->isSVGElement()) {
1377 // Spec: http://www.w3.org/TR/SVG/masking.html#OverflowProperty
1378 if (style->overflowY() == OSCROLL)
1379 style->setOverflowY(OHIDDEN);
1380 else if (style->overflowY() == OAUTO)
1381 style->setOverflowY(OVISIBLE);
1383 if (style->overflowX() == OSCROLL)
1384 style->setOverflowX(OHIDDEN);
1385 else if (style->overflowX() == OAUTO)
1386 style->setOverflowX(OVISIBLE);
1388 // Only the root <svg> element in an SVG document fragment tree honors css position
1389 if (!(e->hasTagName(SVGNames::svgTag) && e->parentNode() && !e->parentNode()->isSVGElement()))
1390 style->setPosition(RenderStyle::initialPosition());
1392 // RenderSVGRoot handles zooming for the whole SVG subtree, so foreignObject content should
1393 // not be scaled again.
1394 if (e->hasTagName(SVGNames::foreignObjectTag))
1395 style->setEffectiveZoom(RenderStyle::initialZoom());
1400 void StyleResolver::adjustGridItemPosition(RenderStyle* style) const
1402 // If opposing grid-placement properties both specify a grid span, they both compute to ‘auto’.
1403 if (style->gridItemColumnStart().isSpan() && style->gridItemColumnEnd().isSpan()) {
1404 style->setGridItemColumnStart(GridPosition());
1405 style->setGridItemColumnEnd(GridPosition());
1408 if (style->gridItemRowStart().isSpan() && style->gridItemRowEnd().isSpan()) {
1409 style->setGridItemRowStart(GridPosition());
1410 style->setGridItemRowEnd(GridPosition());
1414 bool StyleResolver::checkRegionStyle(Element* regionElement)
1416 // FIXME (BUG 72472): We don't add @-webkit-region rules of scoped style sheets for the moment,
1417 // so all region rules are global by default. Verify whether that can stand or needs changing.
1419 unsigned rulesSize = m_ruleSets.authorStyle()->regionSelectorsAndRuleSets().size();
1420 for (unsigned i = 0; i < rulesSize; ++i) {
1421 ASSERT(m_ruleSets.authorStyle()->regionSelectorsAndRuleSets().at(i).ruleSet.get());
1422 if (checkRegionSelector(m_ruleSets.authorStyle()->regionSelectorsAndRuleSets().at(i).selector, regionElement))
1426 if (m_ruleSets.userStyle()) {
1427 rulesSize = m_ruleSets.userStyle()->regionSelectorsAndRuleSets().size();
1428 for (unsigned i = 0; i < rulesSize; ++i) {
1429 ASSERT(m_ruleSets.userStyle()->regionSelectorsAndRuleSets().at(i).ruleSet.get());
1430 if (checkRegionSelector(m_ruleSets.userStyle()->regionSelectorsAndRuleSets().at(i).selector, regionElement))
1438 static void checkForOrientationChange(RenderStyle* style)
1440 FontOrientation fontOrientation;
1441 NonCJKGlyphOrientation glyphOrientation;
1442 style->getFontAndGlyphOrientation(fontOrientation, glyphOrientation);
1444 const FontDescription& fontDescription = style->fontDescription();
1445 if (fontDescription.orientation() == fontOrientation && fontDescription.nonCJKGlyphOrientation() == glyphOrientation)
1448 FontDescription newFontDescription(fontDescription);
1449 newFontDescription.setNonCJKGlyphOrientation(glyphOrientation);
1450 newFontDescription.setOrientation(fontOrientation);
1451 style->setFontDescription(newFontDescription);
1454 void StyleResolver::updateFont()
1456 if (!m_state.fontDirty())
1459 RenderStyle* style = m_state.style();
1460 #if ENABLE(IOS_TEXT_AUTOSIZING)
1461 checkForTextSizeAdjust(style);
1463 checkForGenericFamilyChange(style, m_state.parentStyle());
1464 checkForZoomChange(style, m_state.parentStyle());
1465 checkForOrientationChange(style);
1466 style->font().update(m_fontSelector);
1467 m_state.setFontDirty(false);
1470 Vector<RefPtr<StyleRuleBase> > StyleResolver::styleRulesForElement(Element* e, unsigned rulesToInclude)
1472 return pseudoStyleRulesForElement(e, NOPSEUDO, rulesToInclude);
1475 Vector<RefPtr<StyleRuleBase> > StyleResolver::pseudoStyleRulesForElement(Element* e, PseudoId pseudoId, unsigned rulesToInclude)
1477 if (!e || !e->document().haveStylesheetsLoaded())
1478 return Vector<RefPtr<StyleRuleBase> >();
1481 m_state.initForStyleResolve(document(), e, 0);
1483 ElementRuleCollector collector(this, m_state);
1484 collector.setMode(SelectorChecker::CollectingRules);
1485 collector.setPseudoStyleRequest(PseudoStyleRequest(pseudoId));
1486 collector.setMedium(m_medium.get());
1488 if (rulesToInclude & UAAndUserCSSRules) {
1489 // First we match rules from the user agent sheet.
1490 collector.matchUARules();
1492 // Now we check user sheet rules.
1493 if (m_matchAuthorAndUserStyles)
1494 collector.matchUserRules(rulesToInclude & EmptyCSSRules);
1497 if (m_matchAuthorAndUserStyles && (rulesToInclude & AuthorCSSRules)) {
1498 collector.setSameOriginOnly(!(rulesToInclude & CrossOriginCSSRules));
1500 // Check the rules in author sheets.
1501 collector.matchAuthorRules(rulesToInclude & EmptyCSSRules);
1504 return collector.matchedRuleList();
1507 // -------------------------------------------------------------------------------------
1508 // this is mostly boring stuff on how to apply a certain rule to the renderstyle...
1510 Length StyleResolver::convertToIntLength(const CSSPrimitiveValue* primitiveValue, const RenderStyle* style, const RenderStyle* rootStyle, double multiplier)
1512 return primitiveValue ? primitiveValue->convertToLength<FixedIntegerConversion | PercentConversion | CalculatedConversion | FractionConversion | ViewportPercentageConversion>(style, rootStyle, multiplier) : Length(Undefined);
1515 Length StyleResolver::convertToFloatLength(const CSSPrimitiveValue* primitiveValue, const RenderStyle* style, const RenderStyle* rootStyle, double multiplier)
1517 return primitiveValue ? primitiveValue->convertToLength<FixedFloatConversion | PercentConversion | CalculatedConversion | FractionConversion | ViewportPercentageConversion>(style, rootStyle, multiplier) : Length(Undefined);
1520 template <StyleResolver::StyleApplicationPass pass>
1521 void StyleResolver::applyProperties(const StylePropertySet* properties, StyleRule* rule, bool isImportant, bool inheritedOnly, PropertyWhitelistType propertyWhitelistType)
1523 ASSERT((propertyWhitelistType != PropertyWhitelistRegion) || m_state.regionForStyling());
1524 InspectorInstrumentationCookie cookie = InspectorInstrumentation::willProcessRule(&document(), rule, *this);
1526 unsigned propertyCount = properties->propertyCount();
1527 for (unsigned i = 0; i < propertyCount; ++i) {
1528 StylePropertySet::PropertyReference current = properties->propertyAt(i);
1529 if (isImportant != current.isImportant())
1531 if (inheritedOnly && !current.isInherited()) {
1532 // If the property value is explicitly inherited, we need to apply further non-inherited properties
1533 // as they might override the value inherited here. For this reason we don't allow declarations with
1534 // explicitly inherited properties to be cached.
1535 ASSERT(!current.value()->isInheritedValue());
1538 CSSPropertyID property = current.id();
1540 if (propertyWhitelistType == PropertyWhitelistRegion && !StyleResolver::isValidRegionStyleProperty(property))
1542 #if ENABLE(VIDEO_TRACK)
1543 if (propertyWhitelistType == PropertyWhitelistCue && !StyleResolver::isValidCueStyleProperty(property))
1547 #if ENABLE(CSS_VARIABLES)
1548 case VariableDefinitions:
1549 COMPILE_ASSERT(CSSPropertyVariable < firstCSSProperty, CSS_variable_is_before_first_property);
1550 if (property == CSSPropertyVariable)
1551 applyProperty(current.id(), current.value());
1554 case HighPriorityProperties:
1555 COMPILE_ASSERT(firstCSSProperty == CSSPropertyColor, CSS_color_is_first_property);
1556 #if ENABLE(IOS_TEXT_AUTOSIZING)
1557 COMPILE_ASSERT(CSSPropertyZoom == CSSPropertyColor + 18, CSS_zoom_is_end_of_first_prop_range);
1559 COMPILE_ASSERT(CSSPropertyZoom == CSSPropertyColor + 17, CSS_zoom_is_end_of_first_prop_range);
1561 COMPILE_ASSERT(CSSPropertyLineHeight == CSSPropertyZoom + 1, CSS_line_height_is_after_zoom);
1562 #if ENABLE(CSS_VARIABLES)
1563 if (property == CSSPropertyVariable)
1566 // give special priority to font-xxx, color properties, etc
1567 if (property < CSSPropertyLineHeight)
1568 applyProperty(current.id(), current.value());
1569 // we apply line-height later
1570 else if (property == CSSPropertyLineHeight)
1571 m_state.setLineHeightValue(current.value());
1573 case LowPriorityProperties:
1574 if (property > CSSPropertyLineHeight)
1575 applyProperty(current.id(), current.value());
1578 InspectorInstrumentation::didProcessRule(cookie);
1581 template <StyleResolver::StyleApplicationPass pass>
1582 void StyleResolver::applyMatchedProperties(const MatchResult& matchResult, bool isImportant, int startIndex, int endIndex, bool inheritedOnly)
1584 if (startIndex == -1)
1587 State& state = m_state;
1588 if (state.style()->insideLink() != NotInsideLink) {
1589 for (int i = startIndex; i <= endIndex; ++i) {
1590 const MatchedProperties& matchedProperties = matchResult.matchedProperties[i];
1591 unsigned linkMatchType = matchedProperties.linkMatchType;
1592 // FIXME: It would be nicer to pass these as arguments but that requires changes in many places.
1593 state.setApplyPropertyToRegularStyle(linkMatchType & SelectorChecker::MatchLink);
1594 state.setApplyPropertyToVisitedLinkStyle(linkMatchType & SelectorChecker::MatchVisited);
1596 applyProperties<pass>(matchedProperties.properties.get(), matchResult.matchedRules[i], isImportant, inheritedOnly, static_cast<PropertyWhitelistType>(matchedProperties.whitelistType));
1598 state.setApplyPropertyToRegularStyle(true);
1599 state.setApplyPropertyToVisitedLinkStyle(false);
1602 for (int i = startIndex; i <= endIndex; ++i) {
1603 const MatchedProperties& matchedProperties = matchResult.matchedProperties[i];
1604 applyProperties<pass>(matchedProperties.properties.get(), matchResult.matchedRules[i], isImportant, inheritedOnly, static_cast<PropertyWhitelistType>(matchedProperties.whitelistType));
1608 unsigned StyleResolver::computeMatchedPropertiesHash(const MatchedProperties* properties, unsigned size)
1611 return StringHasher::hashMemory(properties, sizeof(MatchedProperties) * size);
1614 bool operator==(const StyleResolver::MatchRanges& a, const StyleResolver::MatchRanges& b)
1616 return a.firstUARule == b.firstUARule
1617 && a.lastUARule == b.lastUARule
1618 && a.firstAuthorRule == b.firstAuthorRule
1619 && a.lastAuthorRule == b.lastAuthorRule
1620 && a.firstUserRule == b.firstUserRule
1621 && a.lastUserRule == b.lastUserRule;
1624 bool operator!=(const StyleResolver::MatchRanges& a, const StyleResolver::MatchRanges& b)
1629 bool operator==(const StyleResolver::MatchedProperties& a, const StyleResolver::MatchedProperties& b)
1631 return a.properties == b.properties && a.linkMatchType == b.linkMatchType;
1634 bool operator!=(const StyleResolver::MatchedProperties& a, const StyleResolver::MatchedProperties& b)
1639 const StyleResolver::MatchedPropertiesCacheItem* StyleResolver::findFromMatchedPropertiesCache(unsigned hash, const MatchResult& matchResult)
1643 MatchedPropertiesCache::iterator it = m_matchedPropertiesCache.find(hash);
1644 if (it == m_matchedPropertiesCache.end())
1646 MatchedPropertiesCacheItem& cacheItem = it->value;
1648 size_t size = matchResult.matchedProperties.size();
1649 if (size != cacheItem.matchedProperties.size())
1651 for (size_t i = 0; i < size; ++i) {
1652 if (matchResult.matchedProperties[i] != cacheItem.matchedProperties[i])
1655 if (cacheItem.ranges != matchResult.ranges)
1660 void StyleResolver::addToMatchedPropertiesCache(const RenderStyle* style, const RenderStyle* parentStyle, unsigned hash, const MatchResult& matchResult)
1662 static const unsigned matchedDeclarationCacheAdditionsBetweenSweeps = 100;
1663 if (++m_matchedPropertiesCacheAdditionsSinceLastSweep >= matchedDeclarationCacheAdditionsBetweenSweeps
1664 && !m_matchedPropertiesCacheSweepTimer.isActive()) {
1665 static const unsigned matchedDeclarationCacheSweepTimeInSeconds = 60;
1666 m_matchedPropertiesCacheSweepTimer.startOneShot(matchedDeclarationCacheSweepTimeInSeconds);
1670 MatchedPropertiesCacheItem cacheItem;
1671 cacheItem.matchedProperties.appendVector(matchResult.matchedProperties);
1672 cacheItem.ranges = matchResult.ranges;
1673 // Note that we don't cache the original RenderStyle instance. It may be further modified.
1674 // The RenderStyle in the cache is really just a holder for the substructures and never used as-is.
1675 cacheItem.renderStyle = RenderStyle::clone(style);
1676 cacheItem.parentRenderStyle = RenderStyle::clone(parentStyle);
1677 m_matchedPropertiesCache.add(hash, cacheItem);
1680 void StyleResolver::invalidateMatchedPropertiesCache()
1682 m_matchedPropertiesCache.clear();
1685 static bool isCacheableInMatchedPropertiesCache(const Element* element, const RenderStyle* style, const RenderStyle* parentStyle)
1687 // FIXME: CSSPropertyWebkitWritingMode modifies state when applying to document element. We can't skip the applying by caching.
1688 if (element == element->document().documentElement() && element->document().writingModeSetOnDocumentElement())
1690 if (style->unique() || (style->styleType() != NOPSEUDO && parentStyle->unique()))
1692 if (style->hasAppearance())
1694 if (style->zoom() != RenderStyle::initialZoom())
1696 if (style->writingMode() != RenderStyle::initialWritingMode())
1698 // The cache assumes static knowledge about which properties are inherited.
1699 if (parentStyle->hasExplicitlyInheritedProperties())
1704 void StyleResolver::applyMatchedProperties(const MatchResult& matchResult, const Element* element)
1707 State& state = m_state;
1708 unsigned cacheHash = matchResult.isCacheable ? computeMatchedPropertiesHash(matchResult.matchedProperties.data(), matchResult.matchedProperties.size()) : 0;
1709 bool applyInheritedOnly = false;
1710 const MatchedPropertiesCacheItem* cacheItem = 0;
1711 if (cacheHash && (cacheItem = findFromMatchedPropertiesCache(cacheHash, matchResult))) {
1712 // We can build up the style by copying non-inherited properties from an earlier style object built using the same exact
1713 // style declarations. We then only need to apply the inherited properties, if any, as their values can depend on the
1714 // element context. This is fast and saves memory by reusing the style data structures.
1715 state.style()->copyNonInheritedFrom(cacheItem->renderStyle.get());
1716 if (state.parentStyle()->inheritedDataShared(cacheItem->parentRenderStyle.get()) && !isAtShadowBoundary(element)) {
1717 EInsideLink linkStatus = state.style()->insideLink();
1718 // If the cache item parent style has identical inherited properties to the current parent style then the
1719 // resulting style will be identical too. We copy the inherited properties over from the cache and are done.
1720 state.style()->inheritFrom(cacheItem->renderStyle.get());
1722 // Unfortunately the link status is treated like an inherited property. We need to explicitly restore it.
1723 state.style()->setInsideLink(linkStatus);
1726 applyInheritedOnly = true;
1729 #if ENABLE(CSS_VARIABLES)
1730 // First apply all variable definitions, as they may be used during application of later properties.
1731 applyMatchedProperties<VariableDefinitions>(matchResult, false, 0, matchResult.matchedProperties.size() - 1, applyInheritedOnly);
1732 applyMatchedProperties<VariableDefinitions>(matchResult, true, matchResult.ranges.firstAuthorRule, matchResult.ranges.lastAuthorRule, applyInheritedOnly);
1733 applyMatchedProperties<VariableDefinitions>(matchResult, true, matchResult.ranges.firstUserRule, matchResult.ranges.lastUserRule, applyInheritedOnly);
1734 applyMatchedProperties<VariableDefinitions>(matchResult, true, matchResult.ranges.firstUARule, matchResult.ranges.lastUARule, applyInheritedOnly);
1737 // Now we have all of the matched rules in the appropriate order. Walk the rules and apply
1738 // high-priority properties first, i.e., those properties that other properties depend on.
1739 // The order is (1) high-priority not important, (2) high-priority important, (3) normal not important
1740 // and (4) normal important.
1741 state.setLineHeightValue(0);
1742 applyMatchedProperties<HighPriorityProperties>(matchResult, false, 0, matchResult.matchedProperties.size() - 1, applyInheritedOnly);
1743 applyMatchedProperties<HighPriorityProperties>(matchResult, true, matchResult.ranges.firstAuthorRule, matchResult.ranges.lastAuthorRule, applyInheritedOnly);
1744 applyMatchedProperties<HighPriorityProperties>(matchResult, true, matchResult.ranges.firstUserRule, matchResult.ranges.lastUserRule, applyInheritedOnly);
1745 applyMatchedProperties<HighPriorityProperties>(matchResult, true, matchResult.ranges.firstUARule, matchResult.ranges.lastUARule, applyInheritedOnly);
1747 if (cacheItem && cacheItem->renderStyle->effectiveZoom() != state.style()->effectiveZoom()) {
1748 state.setFontDirty(true);
1749 applyInheritedOnly = false;
1752 // If our font got dirtied, go ahead and update it now.
1755 // Line-height is set when we are sure we decided on the font-size.
1756 if (state.lineHeightValue())
1757 applyProperty(CSSPropertyLineHeight, state.lineHeightValue());
1759 // Many properties depend on the font. If it changes we just apply all properties.
1760 if (cacheItem && cacheItem->renderStyle->fontDescription() != state.style()->fontDescription())
1761 applyInheritedOnly = false;
1763 // Now do the normal priority UA properties.
1764 applyMatchedProperties<LowPriorityProperties>(matchResult, false, matchResult.ranges.firstUARule, matchResult.ranges.lastUARule, applyInheritedOnly);
1766 // Cache our border and background so that we can examine them later.
1767 state.cacheBorderAndBackground();
1769 // Now do the author and user normal priority properties and all the !important properties.
1770 applyMatchedProperties<LowPriorityProperties>(matchResult, false, matchResult.ranges.lastUARule + 1, matchResult.matchedProperties.size() - 1, applyInheritedOnly);
1771 applyMatchedProperties<LowPriorityProperties>(matchResult, true, matchResult.ranges.firstAuthorRule, matchResult.ranges.lastAuthorRule, applyInheritedOnly);
1772 applyMatchedProperties<LowPriorityProperties>(matchResult, true, matchResult.ranges.firstUserRule, matchResult.ranges.lastUserRule, applyInheritedOnly);
1773 applyMatchedProperties<LowPriorityProperties>(matchResult, true, matchResult.ranges.firstUARule, matchResult.ranges.lastUARule, applyInheritedOnly);
1775 // Start loading resources referenced by this style.
1776 loadPendingResources();
1778 ASSERT(!state.fontDirty());
1780 if (cacheItem || !cacheHash)
1782 if (!isCacheableInMatchedPropertiesCache(state.element(), state.style(), state.parentStyle()))
1784 addToMatchedPropertiesCache(state.style(), state.parentStyle(), cacheHash, matchResult);
1787 void StyleResolver::applyPropertyToStyle(CSSPropertyID id, CSSValue* value, RenderStyle* style)
1790 m_state.initForStyleResolve(document(), 0, style);
1791 m_state.setStyle(style);
1792 applyPropertyToCurrentStyle(id, value);
1795 void StyleResolver::applyPropertyToCurrentStyle(CSSPropertyID id, CSSValue* value)
1798 applyProperty(id, value);
1801 inline bool isValidVisitedLinkProperty(CSSPropertyID id)
1804 case CSSPropertyBackgroundColor:
1805 case CSSPropertyBorderLeftColor:
1806 case CSSPropertyBorderRightColor:
1807 case CSSPropertyBorderTopColor:
1808 case CSSPropertyBorderBottomColor:
1809 case CSSPropertyColor:
1810 case CSSPropertyOutlineColor:
1811 case CSSPropertyWebkitColumnRuleColor:
1812 #if ENABLE(CSS3_TEXT)
1813 case CSSPropertyWebkitTextDecorationColor:
1815 case CSSPropertyWebkitTextEmphasisColor:
1816 case CSSPropertyWebkitTextFillColor:
1817 case CSSPropertyWebkitTextStrokeColor:
1819 case CSSPropertyFill:
1820 case CSSPropertyStroke:
1830 // http://dev.w3.org/csswg/css3-regions/#the-at-region-style-rule
1831 // FIXME: add incremental support for other region styling properties.
1832 inline bool StyleResolver::isValidRegionStyleProperty(CSSPropertyID id)
1835 case CSSPropertyBackgroundColor:
1836 case CSSPropertyColor:
1845 #if ENABLE(VIDEO_TRACK)
1846 inline bool StyleResolver::isValidCueStyleProperty(CSSPropertyID id)
1849 case CSSPropertyBackground:
1850 case CSSPropertyBackgroundAttachment:
1851 case CSSPropertyBackgroundClip:
1852 case CSSPropertyBackgroundColor:
1853 case CSSPropertyBackgroundImage:
1854 case CSSPropertyBackgroundOrigin:
1855 case CSSPropertyBackgroundPosition:
1856 case CSSPropertyBackgroundPositionX:
1857 case CSSPropertyBackgroundPositionY:
1858 case CSSPropertyBackgroundRepeat:
1859 case CSSPropertyBackgroundRepeatX:
1860 case CSSPropertyBackgroundRepeatY:
1861 case CSSPropertyBackgroundSize:
1862 case CSSPropertyColor:
1863 case CSSPropertyFont:
1864 case CSSPropertyFontFamily:
1865 case CSSPropertyFontSize:
1866 case CSSPropertyFontStyle:
1867 case CSSPropertyFontVariant:
1868 case CSSPropertyFontWeight:
1869 case CSSPropertyLineHeight:
1870 case CSSPropertyOpacity:
1871 case CSSPropertyOutline:
1872 case CSSPropertyOutlineColor:
1873 case CSSPropertyOutlineOffset:
1874 case CSSPropertyOutlineStyle:
1875 case CSSPropertyOutlineWidth:
1876 case CSSPropertyVisibility:
1877 case CSSPropertyWhiteSpace:
1878 case CSSPropertyTextDecoration:
1879 case CSSPropertyTextShadow:
1880 case CSSPropertyBorderStyle:
1888 // SVG handles zooming in a different way compared to CSS. The whole document is scaled instead
1889 // of each individual length value in the render style / tree. CSSPrimitiveValue::computeLength*()
1890 // multiplies each resolved length with the zoom multiplier - so for SVG we need to disable that.
1891 // Though all CSS values that can be applied to outermost <svg> elements (width/height/border/padding...)
1892 // need to respect the scaling. RenderBox (the parent class of RenderSVGRoot) grabs values like
1893 // width/height/border/padding/... from the RenderStyle -> for SVG these values would never scale,
1894 // if we'd pass a 1.0 zoom factor everyhwere. So we only pass a zoom factor of 1.0 for specific
1895 // properties that are NOT allowed to scale within a zoomed SVG document (letter/word-spacing/font-size).
1896 bool StyleResolver::useSVGZoomRules()
1898 return m_state.element() && m_state.element()->isSVGElement();
1901 static bool createGridTrackBreadth(CSSPrimitiveValue* primitiveValue, const StyleResolver::State& state, Length& workingLength)
1903 if (primitiveValue->getValueID() == CSSValueWebkitMinContent) {
1904 workingLength = Length(MinContent);
1908 if (primitiveValue->getValueID() == CSSValueWebkitMaxContent) {
1909 workingLength = Length(MaxContent);
1913 workingLength = primitiveValue->convertToLength<FixedIntegerConversion | PercentConversion | ViewportPercentageConversion | AutoConversion>(state.style(), state.rootElementStyle(), state.style()->effectiveZoom());
1914 if (workingLength.isUndefined())
1917 if (primitiveValue->isLength())
1918 workingLength.setQuirk(primitiveValue->isQuirkValue());
1923 static bool createGridTrackSize(CSSValue* value, GridTrackSize& trackSize, const StyleResolver::State& state)
1925 if (!value->isPrimitiveValue())
1928 CSSPrimitiveValue* primitiveValue = static_cast<CSSPrimitiveValue*>(value);
1929 Pair* minMaxTrackBreadth = primitiveValue->getPairValue();
1930 if (!minMaxTrackBreadth) {
1931 Length workingLength;
1932 if (!createGridTrackBreadth(primitiveValue, state, workingLength))
1935 trackSize.setLength(workingLength);
1939 Length minTrackBreadth;
1940 Length maxTrackBreadth;
1941 if (!createGridTrackBreadth(minMaxTrackBreadth->first(), state, minTrackBreadth) || !createGridTrackBreadth(minMaxTrackBreadth->second(), state, maxTrackBreadth))
1944 trackSize.setMinMax(minTrackBreadth, maxTrackBreadth);
1948 static bool createGridTrackList(CSSValue* value, Vector<GridTrackSize>& trackSizes, NamedGridLinesMap& namedGridLines, const StyleResolver::State& state)
1951 if (value->isPrimitiveValue()) {
1952 CSSPrimitiveValue* primitiveValue = static_cast<CSSPrimitiveValue*>(value);
1953 return primitiveValue->getValueID() == CSSValueNone;
1956 if (!value->isValueList())
1959 size_t currentNamedGridLine = 0;
1960 for (CSSValueListIterator i = value; i.hasMore(); i.advance()) {
1961 CSSValue* currValue = i.value();
1962 if (currValue->isPrimitiveValue()) {
1963 CSSPrimitiveValue* primitiveValue = static_cast<CSSPrimitiveValue*>(currValue);
1964 if (primitiveValue->isString()) {
1965 NamedGridLinesMap::AddResult result = namedGridLines.add(primitiveValue->getStringValue(), Vector<size_t>());
1966 result.iterator->value.append(currentNamedGridLine);
1971 ++currentNamedGridLine;
1972 GridTrackSize trackSize;
1973 if (!createGridTrackSize(currValue, trackSize, state))
1976 trackSizes.append(trackSize);
1979 if (trackSizes.isEmpty())
1986 static bool createGridPosition(CSSValue* value, GridPosition& position)
1988 // For now, we only accept: 'auto' | [ <integer> || <string> ] | span && <integer>?
1989 if (value->isPrimitiveValue()) {
1990 #if !ASSERT_DISABLED
1991 CSSPrimitiveValue* primitiveValue = static_cast<CSSPrimitiveValue*>(value);
1992 ASSERT(primitiveValue->getValueID() == CSSValueAuto);
1997 ASSERT_WITH_SECURITY_IMPLICATION(value->isValueList());
1998 CSSValueList* values = static_cast<CSSValueList*>(value);
1999 ASSERT(values->length());
2001 bool isSpanPosition = false;
2002 // The specification makes the <integer> optional, in which case it default to '1'.
2003 int gridLineNumber = 1;
2004 String gridLineName;
2006 CSSValueListIterator it = values;
2007 CSSPrimitiveValue* currentValue = static_cast<CSSPrimitiveValue*>(it.value());
2008 if (currentValue->getValueID() == CSSValueSpan) {
2009 isSpanPosition = true;
2011 currentValue = it.hasMore() ? static_cast<CSSPrimitiveValue*>(it.value()) : 0;
2014 if (currentValue && currentValue->isNumber()) {
2015 gridLineNumber = currentValue->getIntValue();
2017 currentValue = it.hasMore() ? static_cast<CSSPrimitiveValue*>(it.value()) : 0;
2020 if (currentValue && currentValue->isString()) {
2021 gridLineName = currentValue->getStringValue();
2025 ASSERT(!it.hasMore());
2027 position.setSpanPosition(gridLineNumber, gridLineName);
2029 position.setExplicitPosition(gridLineNumber, gridLineName);
2034 #if ENABLE(CSS_VARIABLES)
2035 static bool hasVariableReference(CSSValue* value)
2037 if (value->isPrimitiveValue()) {
2038 CSSPrimitiveValue* primitiveValue = static_cast<CSSPrimitiveValue*>(value);
2039 return primitiveValue->hasVariableReference();
2042 if (value->isCalculationValue())
2043 return static_cast<CSSCalcValue*>(value)->hasVariableReference();
2045 if (value->isReflectValue()) {
2046 CSSReflectValue* reflectValue = toCSSReflectValue(value);
2047 CSSPrimitiveValue* direction = reflectValue->direction();
2048 CSSPrimitiveValue* offset = reflectValue->offset();
2049 CSSValue* mask = reflectValue->mask();
2050 return (direction && hasVariableReference(direction)) || (offset && hasVariableReference(offset)) || (mask && hasVariableReference(mask));
2053 for (CSSValueListIterator i = value; i.hasMore(); i.advance()) {
2054 if (hasVariableReference(i.value()))
2061 void StyleResolver::resolveVariables(CSSPropertyID id, CSSValue* value, Vector<std::pair<CSSPropertyID, String> >& knownExpressions)
2063 std::pair<CSSPropertyID, String> expression(id, value->serializeResolvingVariables(*m_state.style()->variables()));
2065 if (knownExpressions.contains(expression))
2066 return; // cycle detected.
2068 knownExpressions.append(expression);
2070 // FIXME: It would be faster not to re-parse from strings, but for now CSS property validation lives inside the parser so we do it there.
2071 RefPtr<MutableStylePropertySet> resultSet = MutableStylePropertySet::create();
2072 if (!CSSParser::parseValue(resultSet.get(), id, expression.second, false, document()))
2073 return; // expression failed to parse.
2075 for (unsigned i = 0; i < resultSet->propertyCount(); i++) {
2076 StylePropertySet::PropertyReference property = resultSet->propertyAt(i);
2077 if (property.id() != CSSPropertyVariable && hasVariableReference(property.value()))
2078 resolveVariables(property.id(), property.value(), knownExpressions);
2080 applyProperty(property.id(), property.value());
2085 void StyleResolver::applyProperty(CSSPropertyID id, CSSValue* value)
2087 #if ENABLE(CSS_VARIABLES)
2088 if (id != CSSPropertyVariable && hasVariableReference(value)) {
2089 Vector<std::pair<CSSPropertyID, String> > knownExpressions;
2090 resolveVariables(id, value, knownExpressions);
2095 // CSS variables don't resolve shorthands at parsing time, so this should be *after* handling variables.
2096 ASSERT_WITH_MESSAGE(!isExpandedShorthand(id), "Shorthand property id = %d wasn't expanded at parsing time", id);
2098 State& state = m_state;
2099 bool isInherit = state.parentNode() && value->isInheritedValue();
2100 bool isInitial = value->isInitialValue() || (!state.parentNode() && value->isInheritedValue());
2102 ASSERT(!isInherit || !isInitial); // isInherit -> !isInitial && isInitial -> !isInherit
2103 ASSERT(!isInherit || (state.parentNode() && state.parentStyle())); // isInherit -> (state.parentNode() && state.parentStyle())
2105 if (!state.applyPropertyToRegularStyle() && (!state.applyPropertyToVisitedLinkStyle() || !isValidVisitedLinkProperty(id))) {
2106 // Limit the properties that can be applied to only the ones honored by :visited.
2110 if (isInherit && !state.parentStyle()->hasExplicitlyInheritedProperties() && !CSSProperty::isInheritedProperty(id))
2111 state.parentStyle()->setHasExplicitlyInheritedProperties();
2113 #if ENABLE(CSS_VARIABLES)
2114 if (id == CSSPropertyVariable) {
2115 ASSERT_WITH_SECURITY_IMPLICATION(value->isVariableValue());
2116 CSSVariableValue* variable = static_cast<CSSVariableValue*>(value);
2117 ASSERT(!variable->name().isEmpty());
2118 ASSERT(!variable->value().isEmpty());
2119 state.style()->setVariable(variable->name(), variable->value());
2124 // Check lookup table for implementations and use when available.
2125 const PropertyHandler& handler = m_deprecatedStyleBuilder.propertyHandler(id);
2126 if (handler.isValid()) {
2128 handler.applyInheritValue(id, this);
2130 handler.applyInitialValue(id, this);
2132 handler.applyValue(id, this, value);
2136 CSSPrimitiveValue* primitiveValue = value->isPrimitiveValue() ? static_cast<CSSPrimitiveValue*>(value) : 0;
2138 float zoomFactor = state.style()->effectiveZoom();
2140 // What follows is a list that maps the CSS properties into their corresponding front-end
2141 // RenderStyle values.
2144 case CSSPropertyContent:
2145 // list of string, uri, counter, attr, i
2147 // FIXME: In CSS3, it will be possible to inherit content. In CSS2 it is not. This
2148 // note is a reminder that eventually "inherit" needs to be supported.
2151 state.style()->clearContent();
2155 if (!value->isValueList())
2158 bool didSet = false;
2159 for (CSSValueListIterator i = value; i.hasMore(); i.advance()) {
2160 CSSValue* item = i.value();
2161 if (item->isImageGeneratorValue()) {
2162 if (item->isGradientValue())
2163 state.style()->setContent(StyleGeneratedImage::create(static_cast<CSSGradientValue*>(item)->gradientWithStylesResolved(this).get()), didSet);
2165 state.style()->setContent(StyleGeneratedImage::create(static_cast<CSSImageGeneratorValue*>(item)), didSet);
2167 #if ENABLE(CSS_IMAGE_SET)
2168 } else if (item->isImageSetValue()) {
2169 state.style()->setContent(setOrPendingFromValue(CSSPropertyContent, toCSSImageSetValue(item)), didSet);
2174 if (item->isImageValue()) {
2175 state.style()->setContent(cachedOrPendingFromValue(CSSPropertyContent, static_cast<CSSImageValue*>(item)), didSet);
2180 if (!item->isPrimitiveValue())
2183 CSSPrimitiveValue* contentValue = static_cast<CSSPrimitiveValue*>(item);
2185 if (contentValue->isString()) {
2186 state.style()->setContent(contentValue->getStringValue().impl(), didSet);
2188 } else if (contentValue->isAttr()) {
2189 // FIXME: Can a namespace be specified for an attr(foo)?
2190 if (state.style()->styleType() == NOPSEUDO)
2191 state.style()->setUnique();
2193 state.parentStyle()->setUnique();
2194 QualifiedName attr(nullAtom, contentValue->getStringValue().impl(), nullAtom);
2195 const AtomicString& value = state.element()->getAttribute(attr);
2196 state.style()->setContent(value.isNull() ? emptyAtom : value.impl(), didSet);
2198 // register the fact that the attribute value affects the style
2199 m_ruleSets.features().attrsInRules.add(attr.localName().impl());
2200 } else if (contentValue->isCounter()) {
2201 Counter* counterValue = contentValue->getCounterValue();
2202 EListStyleType listStyleType = NoneListStyle;
2203 CSSValueID listStyleIdent = counterValue->listStyleIdent();
2204 if (listStyleIdent != CSSValueNone)
2205 listStyleType = static_cast<EListStyleType>(listStyleIdent - CSSValueDisc);
2206 OwnPtr<CounterContent> counter = adoptPtr(new CounterContent(counterValue->identifier(), listStyleType, counterValue->separator()));
2207 state.style()->setContent(counter.release(), didSet);
2210 switch (contentValue->getValueID()) {
2211 case CSSValueOpenQuote:
2212 state.style()->setContent(OPEN_QUOTE, didSet);
2215 case CSSValueCloseQuote:
2216 state.style()->setContent(CLOSE_QUOTE, didSet);
2219 case CSSValueNoOpenQuote:
2220 state.style()->setContent(NO_OPEN_QUOTE, didSet);
2223 case CSSValueNoCloseQuote:
2224 state.style()->setContent(NO_CLOSE_QUOTE, didSet);
2228 // normal and none do not have any effect.
2234 state.style()->clearContent();
2237 case CSSPropertyQuotes:
2239 state.style()->setQuotes(state.parentStyle()->quotes());
2243 state.style()->setQuotes(0);
2246 if (value->isValueList()) {
2247 CSSValueList* list = static_cast<CSSValueList*>(value);
2248 Vector<std::pair<String, String> > quotes;
2249 for (size_t i = 0; i < list->length(); i += 2) {
2250 CSSValue* first = list->itemWithoutBoundsCheck(i);
2251 // item() returns null if out of bounds so this is safe.
2252 CSSValue* second = list->item(i + 1);
2255 ASSERT_WITH_SECURITY_IMPLICATION(first->isPrimitiveValue());
2256 ASSERT_WITH_SECURITY_IMPLICATION(second->isPrimitiveValue());
2257 String startQuote = static_cast<CSSPrimitiveValue*>(first)->getStringValue();
2258 String endQuote = static_cast<CSSPrimitiveValue*>(second)->getStringValue();
2259 quotes.append(std::make_pair(startQuote, endQuote));
2261 state.style()->setQuotes(QuotesData::create(quotes));
2264 if (primitiveValue) {
2265 if (primitiveValue->getValueID() == CSSValueNone)
2266 state.style()->setQuotes(QuotesData::create(Vector<std::pair<String, String> >()));
2269 // Shorthand properties.
2270 case CSSPropertyFont:
2272 FontDescription fontDescription = state.parentStyle()->fontDescription();
2273 state.style()->setLineHeight(state.parentStyle()->specifiedLineHeight());
2274 state.setLineHeightValue(0);
2275 setFontDescription(fontDescription);
2276 } else if (isInitial) {
2277 Settings* settings = documentSettings();
2278 ASSERT(settings); // If we're doing style resolution, this document should always be in a frame and thus have settings
2281 initializeFontStyle(settings);
2282 } else if (primitiveValue) {
2283 state.style()->setLineHeight(RenderStyle::initialLineHeight());
2284 state.setLineHeightValue(0);
2286 FontDescription fontDescription;
2287 RenderTheme::defaultTheme()->systemFont(primitiveValue->getValueID(), fontDescription);
2289 // Double-check and see if the theme did anything. If not, don't bother updating the font.
2290 if (fontDescription.isAbsoluteSize()) {
2291 // Make sure the rendering mode and printer font settings are updated.
2292 Settings* settings = documentSettings();
2293 ASSERT(settings); // If we're doing style resolution, this document should always be in a frame and thus have settings
2296 fontDescription.setRenderingMode(settings->fontRenderingMode());
2297 fontDescription.setUsePrinterFont(document().printing() || !settings->screenFontSubstitutionEnabled());
2299 // Handle the zoom factor.
2300 fontDescription.setComputedSize(Style::computedFontSizeFromSpecifiedSize(fontDescription.specifiedSize(), fontDescription.isAbsoluteSize(), useSVGZoomRules(), state.style(), document()));
2301 setFontDescription(fontDescription);
2303 } else if (value->isFontValue()) {
2304 FontValue* font = static_cast<FontValue*>(value);
2305 if (!font->style || !font->variant || !font->weight
2306 || !font->size || !font->lineHeight || !font->family)
2308 applyProperty(CSSPropertyFontStyle, font->style.get());
2309 applyProperty(CSSPropertyFontVariant, font->variant.get());
2310 applyProperty(CSSPropertyFontWeight, font->weight.get());
2311 // The previous properties can dirty our font but they don't try to read the font's
2312 // properties back, which is safe. However if font-size is using the 'ex' unit, it will
2313 // need query the dirtied font's x-height to get the computed size. To be safe in this
2314 // case, let's just update the font now.
2316 applyProperty(CSSPropertyFontSize, font->size.get());
2318 state.setLineHeightValue(font->lineHeight.get());
2320 applyProperty(CSSPropertyFontFamily, font->family.get());
2324 case CSSPropertyBackground:
2325 case CSSPropertyBackgroundPosition:
2326 case CSSPropertyBackgroundRepeat:
2327 case CSSPropertyBorder:
2328 case CSSPropertyBorderBottom:
2329 case CSSPropertyBorderColor:
2330 case CSSPropertyBorderImage:
2331 case CSSPropertyBorderLeft:
2332 case CSSPropertyBorderRadius:
2333 case CSSPropertyBorderRight:
2334 case CSSPropertyBorderSpacing:
2335 case CSSPropertyBorderStyle:
2336 case CSSPropertyBorderTop:
2337 case CSSPropertyBorderWidth:
2338 case CSSPropertyListStyle:
2339 case CSSPropertyMargin:
2340 case CSSPropertyOutline:
2341 case CSSPropertyOverflow:
2342 case CSSPropertyPadding:
2343 case CSSPropertyTransition:
2344 case CSSPropertyWebkitAnimation:
2345 case CSSPropertyWebkitBorderAfter:
2346 case CSSPropertyWebkitBorderBefore:
2347 case CSSPropertyWebkitBorderEnd:
2348 case CSSPropertyWebkitBorderStart:
2349 case CSSPropertyWebkitBorderRadius:
2350 case CSSPropertyWebkitColumns:
2351 case CSSPropertyWebkitColumnRule:
2352 case CSSPropertyWebkitFlex:
2353 case CSSPropertyWebkitFlexFlow:
2354 case CSSPropertyWebkitGridColumn:
2355 case CSSPropertyWebkitGridRow:
2356 case CSSPropertyWebkitMarginCollapse:
2357 case CSSPropertyWebkitMarquee:
2358 case CSSPropertyWebkitMask:
2359 case CSSPropertyWebkitMaskPosition:
2360 case CSSPropertyWebkitMaskRepeat:
2361 case CSSPropertyWebkitTextEmphasis:
2362 case CSSPropertyWebkitTextStroke:
2363 case CSSPropertyWebkitTransition:
2364 case CSSPropertyWebkitTransformOrigin:
2365 ASSERT(isExpandedShorthand(id));
2366 ASSERT_NOT_REACHED();
2370 case CSSPropertyTextShadow:
2371 case CSSPropertyBoxShadow:
2372 case CSSPropertyWebkitBoxShadow: {
2374 if (id == CSSPropertyTextShadow)
2375 return state.style()->setTextShadow(state.parentStyle()->textShadow() ? adoptPtr(new ShadowData(*state.parentStyle()->textShadow())) : nullptr);
2376 return state.style()->setBoxShadow(state.parentStyle()->boxShadow() ? adoptPtr(new ShadowData(*state.parentStyle()->boxShadow())) : nullptr);
2378 if (isInitial || primitiveValue) // initial | none
2379 return id == CSSPropertyTextShadow ? state.style()->setTextShadow(nullptr) : state.style()->setBoxShadow(nullptr);
2381 if (!value->isValueList())
2384 for (CSSValueListIterator i = value; i.hasMore(); i.advance()) {
2385 CSSValue* currValue = i.value();
2386 if (!currValue->isShadowValue())
2388 ShadowValue* item = static_cast<ShadowValue*>(currValue);
2389 int x = item->x->computeLength<int>(state.style(), state.rootElementStyle(), zoomFactor);
2390 if (item->x->isViewportPercentageLength())
2391 x = viewportPercentageValue(*item->x, x);
2392 int y = item->y->computeLength<int>(state.style(), state.rootElementStyle(), zoomFactor);
2393 if (item->y->isViewportPercentageLength())
2394 y = viewportPercentageValue(*item->y, y);
2395 int blur = item->blur ? item->blur->computeLength<int>(state.style(), state.rootElementStyle(), zoomFactor) : 0;
2396 if (item->blur && item->blur->isViewportPercentageLength())
2397 blur = viewportPercentageValue(*item->blur, blur);
2398 int spread = item->spread ? item->spread->computeLength<int>(state.style(), state.rootElementStyle(), zoomFactor) : 0;
2399 if (item->spread && item->spread->isViewportPercentageLength())
2400 spread = viewportPercentageValue(*item->spread, spread);
2401 ShadowStyle shadowStyle = item->style && item->style->getValueID() == CSSValueInset ? Inset : Normal;
2404 color = colorFromPrimitiveValue(item->color.get());
2405 else if (state.style())
2406 color = state.style()->color();
2408 OwnPtr<ShadowData> shadowData = adoptPtr(new ShadowData(IntPoint(x, y), blur, spread, shadowStyle, id == CSSPropertyWebkitBoxShadow, color.isValid() ? color : Color::transparent));
2409 if (id == CSSPropertyTextShadow)
2410 state.style()->setTextShadow(shadowData.release(), i.index()); // add to the list if this is not the first entry
2412 state.style()->setBoxShadow(shadowData.release(), i.index()); // add to the list if this is not the first entry
2416 case CSSPropertyWebkitBoxReflect: {
2417 HANDLE_INHERIT_AND_INITIAL(boxReflect, BoxReflect)
2418 if (primitiveValue) {
2419 state.style()->setBoxReflect(RenderStyle::initialBoxReflect());
2423 if (!value->isReflectValue())
2426 CSSReflectValue* reflectValue = toCSSReflectValue(value);
2427 RefPtr<StyleReflection> reflection = StyleReflection::create();
2428 reflection->setDirection(*reflectValue->direction());
2429 if (reflectValue->offset())
2430 reflection->setOffset(reflectValue->offset()->convertToLength<FixedIntegerConversion | PercentConversion | CalculatedConversion>(state.style(), state.rootElementStyle(), zoomFactor));
2431 NinePieceImage mask;
2432 mask.setMaskDefaults();
2433 m_styleMap.mapNinePieceImage(id, reflectValue->mask(), mask);
2434 reflection->setMask(mask);
2436 state.style()->setBoxReflect(reflection.release());
2439 case CSSPropertySrc: // Only used in @font-face rules.
2441 case CSSPropertyUnicodeRange: // Only used in @font-face rules.
2443 case CSSPropertyWebkitLocale: {
2444 HANDLE_INHERIT_AND_INITIAL(locale, Locale);
2445 if (!primitiveValue)
2447 if (primitiveValue->getValueID() == CSSValueAuto)
2448 state.style()->setLocale(nullAtom);
2450 state.style()->setLocale(primitiveValue->getStringValue());
2451 FontDescription fontDescription = state.style()->fontDescription();
2452 fontDescription.setScript(localeToScriptCodeForFontSelection(state.style()->locale()));
2453 setFontDescription(fontDescription);
2456 #if ENABLE(IOS_TEXT_AUTOSIZING)
2457 case CSSPropertyWebkitTextSizeAdjust: {
2458 HANDLE_INHERIT_AND_INITIAL(textSizeAdjust, TextSizeAdjust)
2459 if (!primitiveValue)
2462 if (primitiveValue->getValueID() == CSSValueAuto)
2463 state.style()->setTextSizeAdjust(TextSizeAdjustment(AutoTextSizeAdjustment));
2464 else if (primitiveValue->getValueID() == CSSValueNone)
2465 state.style()->setTextSizeAdjust(TextSizeAdjustment(NoTextSizeAdjustment));
2467 state.style()->setTextSizeAdjust(TextSizeAdjustment(primitiveValue->getFloatValue()));
2469 state.setFontDirty(true);
2473 #if ENABLE(DASHBOARD_SUPPORT)
2474 case CSSPropertyWebkitDashboardRegion:
2476 HANDLE_INHERIT_AND_INITIAL(dashboardRegions, DashboardRegions)
2477 if (!primitiveValue)
2480 if (primitiveValue->getValueID() == CSSValueNone) {
2481 state.style()->setDashboardRegions(RenderStyle::noneDashboardRegions());
2485 DashboardRegion* region = primitiveValue->getDashboardRegionValue();
2489 DashboardRegion* first = region;
2491 Length top = convertToIntLength(region->top(), state.style(), state.rootElementStyle());
2492 Length right = convertToIntLength(region->right(), state.style(), state.rootElementStyle());
2493 Length bottom = convertToIntLength(region->bottom(), state.style(), state.rootElementStyle());
2494 Length left = convertToIntLength(region->left(), state.style(), state.rootElementStyle());
2496 if (top.isUndefined())
2498 if (right.isUndefined())
2500 if (bottom.isUndefined())
2502 if (left.isUndefined())
2505 if (region->m_isCircle)
2506 state.style()->setDashboardRegion(StyleDashboardRegion::Circle, region->m_label, top, right, bottom, left, region == first ? false : true);
2507 else if (region->m_isRectangle)
2508 state.style()->setDashboardRegion(StyleDashboardRegion::Rectangle, region->m_label, top, right, bottom, left, region == first ? false : true);
2509 region = region->m_next.get();
2512 state.document().setHasAnnotatedRegions(true);
2517 #if ENABLE(DRAGGABLE_REGION)
2518 case CSSPropertyWebkitAppRegion: {
2519 if (!primitiveValue || !primitiveValue->getValueID())
2521 state.style()->setDraggableRegionMode(primitiveValue->getValueID() == CSSValueDrag ? DraggableRegionDrag : DraggableRegionNoDrag);
2522 state.document().setHasAnnotatedRegions(true);
2526 case CSSPropertyWebkitTextStrokeWidth: {
2527 HANDLE_INHERIT_AND_INITIAL(textStrokeWidth, TextStrokeWidth)
2529 switch (primitiveValue->getValueID()) {
2531 case CSSValueMedium:
2532 case CSSValueThick: {
2533 double result = 1.0 / 48;
2534 if (primitiveValue->getValueID() == CSSValueMedium)
2536 else if (primitiveValue->getValueID() == CSSValueThick)
2538 width = CSSPrimitiveValue::create(result, CSSPrimitiveValue::CSS_EMS)->computeLength<float>(state.style(), state.rootElementStyle(), zoomFactor);
2542 width = primitiveValue->computeLength<float>(state.style(), state.rootElementStyle(), zoomFactor);
2545 state.style()->setTextStrokeWidth(width);
2548 case CSSPropertyWebkitTransform: {
2549 HANDLE_INHERIT_AND_INITIAL(transform, Transform);
2550 TransformOperations operations;
2551 transformsForValue(state.style(), state.rootElementStyle(), value, operations);
2552 state.style()->setTransform(operations);
2555 case CSSPropertyWebkitPerspective: {
2556 HANDLE_INHERIT_AND_INITIAL(perspective, Perspective)
2558 if (!primitiveValue)
2561 if (primitiveValue->getValueID() == CSSValueNone) {
2562 state.style()->setPerspective(0);
2566 float perspectiveValue;
2567 if (primitiveValue->isLength())
2568 perspectiveValue = primitiveValue->computeLength<float>(state.style(), state.rootElementStyle(), zoomFactor);
2569 else if (primitiveValue->isNumber()) {
2570 // For backward compatibility, treat valueless numbers as px.
2571 perspectiveValue = CSSPrimitiveValue::create(primitiveValue->getDoubleValue(), CSSPrimitiveValue::CSS_PX)->computeLength<float>(state.style(), state.rootElementStyle(), zoomFactor);
2575 if (perspectiveValue >= 0.0f)
2576 state.style()->setPerspective(perspectiveValue);
2580 case CSSPropertyWebkitTouchCallout: {
2581 HANDLE_INHERIT_AND_INITIAL(touchCalloutEnabled, TouchCalloutEnabled);
2582 if (!primitiveValue)
2585 state.style()->setTouchCalloutEnabled(primitiveValue->getStringValue().lower() != "none");
2589 #if ENABLE(TOUCH_EVENTS)
2590 case CSSPropertyWebkitTapHighlightColor: {
2591 HANDLE_INHERIT_AND_INITIAL(tapHighlightColor, TapHighlightColor);
2592 if (!primitiveValue)
2595 Color col = colorFromPrimitiveValue(primitiveValue);
2596 state.style()->setTapHighlightColor(col);
2600 #if ENABLE(ACCELERATED_OVERFLOW_SCROLLING)
2601 case CSSPropertyWebkitOverflowScrolling: {
2602 HANDLE_INHERIT_AND_INITIAL(useTouchOverflowScrolling, UseTouchOverflowScrolling);
2603 if (!primitiveValue)
2605 state.style()->setUseTouchOverflowScrolling(primitiveValue->getValueID() == CSSValueTouch);
2609 case CSSPropertyInvalid:
2611 // Directional properties are resolved by resolveDirectionAwareProperty() before the switch.
2612 case CSSPropertyWebkitBorderEndColor:
2613 case CSSPropertyWebkitBorderEndStyle:
2614 case CSSPropertyWebkitBorderEndWidth:
2615 case CSSPropertyWebkitBorderStartColor:
2616 case CSSPropertyWebkitBorderStartStyle:
2617 case CSSPropertyWebkitBorderStartWidth:
2618 case CSSPropertyWebkitBorderBeforeColor:
2619 case CSSPropertyWebkitBorderBeforeStyle:
2620 case CSSPropertyWebkitBorderBeforeWidth:
2621 case CSSPropertyWebkitBorderAfterColor:
2622 case CSSPropertyWebkitBorderAfterStyle:
2623 case CSSPropertyWebkitBorderAfterWidth:
2624 case CSSPropertyWebkitMarginEnd:
2625 case CSSPropertyWebkitMarginStart:
2626 case CSSPropertyWebkitMarginBefore:
2627 case CSSPropertyWebkitMarginAfter:
2628 case CSSPropertyWebkitMarginBeforeCollapse:
2629 case CSSPropertyWebkitMarginTopCollapse:
2630 case CSSPropertyWebkitMarginAfterCollapse:
2631 case CSSPropertyWebkitMarginBottomCollapse:
2632 case CSSPropertyWebkitPaddingEnd:
2633 case CSSPropertyWebkitPaddingStart:
2634 case CSSPropertyWebkitPaddingBefore:
2635 case CSSPropertyWebkitPaddingAfter:
2636 case CSSPropertyWebkitLogicalWidth:
2637 case CSSPropertyWebkitLogicalHeight:
2638 case CSSPropertyWebkitMinLogicalWidth:
2639 case CSSPropertyWebkitMinLogicalHeight:
2640 case CSSPropertyWebkitMaxLogicalWidth:
2641 case CSSPropertyWebkitMaxLogicalHeight:
2643 CSSPropertyID newId = CSSProperty::resolveDirectionAwareProperty(id, state.style()->direction(), state.style()->writingMode());
2644 ASSERT(newId != id);
2645 return applyProperty(newId, value);
2647 case CSSPropertyFontStretch:
2648 case CSSPropertyPage:
2649 case CSSPropertyTextLineThrough:
2650 case CSSPropertyTextLineThroughColor:
2651 case CSSPropertyTextLineThroughMode:
2652 case CSSPropertyTextLineThroughStyle:
2653 case CSSPropertyTextLineThroughWidth:
2654 case CSSPropertyTextOverline:
2655 case CSSPropertyTextOverlineColor:
2656 case CSSPropertyTextOverlineMode:
2657 case CSSPropertyTextOverlineStyle:
2658 case CSSPropertyTextOverlineWidth:
2659 case CSSPropertyTextUnderline:
2660 case CSSPropertyTextUnderlineColor:
2661 case CSSPropertyTextUnderlineMode:
2662 case CSSPropertyTextUnderlineStyle:
2663 case CSSPropertyTextUnderlineWidth:
2664 case CSSPropertyWebkitFontSizeDelta:
2665 case CSSPropertyWebkitTextDecorationsInEffect:
2668 // CSS Text Layout Module Level 3: Vertical writing support
2669 case CSSPropertyWebkitWritingMode: {
2670 HANDLE_INHERIT_AND_INITIAL(writingMode, WritingMode);
2673 setWritingMode(*primitiveValue);
2675 // FIXME: It is not ok to modify document state while applying style.
2676 if (state.element() && state.element() == state.document().documentElement())
2677 state.document().setWritingModeSetOnDocumentElement(true);
2681 case CSSPropertyWebkitTextOrientation: {
2682 HANDLE_INHERIT_AND_INITIAL(textOrientation, TextOrientation);
2685 setTextOrientation(*primitiveValue);
2690 case CSSPropertyWebkitLineBoxContain: {
2691 HANDLE_INHERIT_AND_INITIAL(lineBoxContain, LineBoxContain)
2692 if (primitiveValue && primitiveValue->getValueID() == CSSValueNone) {
2693 state.style()->setLineBoxContain(LineBoxContainNone);
2697 if (!value->isCSSLineBoxContainValue())
2700 CSSLineBoxContainValue* lineBoxContainValue = static_cast<CSSLineBoxContainValue*>(value);
2701 state.style()->setLineBoxContain(lineBoxContainValue->value());
2705 // CSS Fonts Module Level 3
2706 case CSSPropertyWebkitFontFeatureSettings: {
2707 if (primitiveValue && primitiveValue->getValueID() == CSSValueNormal) {
2708 setFontDescription(state.style()->fontDescription().makeNormalFeatureSettings());
2712 if (!value->isValueList())
2715 FontDescription fontDescription = state.style()->fontDescription();
2716 CSSValueList* list = static_cast<CSSValueList*>(value);
2717 RefPtr<FontFeatureSettings> settings = FontFeatureSettings::create();
2718 int len = list->length();
2719 for (int i = 0; i < len; ++i) {
2720 CSSValue* item = list->itemWithoutBoundsCheck(i);
2721 if (!item->isFontFeatureValue())
2723 FontFeatureValue* feature = static_cast<FontFeatureValue*>(item);
2724 settings->append(FontFeature(feature->tag(), feature->value()));
2726 fontDescription.setFeatureSettings(settings.release());
2727 setFontDescription(fontDescription);
2731 #if ENABLE(CSS_FILTERS)
2732 case CSSPropertyWebkitFilter: {
2733 HANDLE_INHERIT_AND_INITIAL(filter, Filter);
2734 FilterOperations operations;
2735 if (createFilterOperations(value, operations))
2736 state.style()->setFilter(operations);
2740 case CSSPropertyWebkitGridAutoColumns: {
2741 GridTrackSize trackSize;
2742 if (!createGridTrackSize(value, trackSize, state))
2744 state.style()->setGridAutoColumns(trackSize);
2747 case CSSPropertyWebkitGridAutoRows: {
2748 GridTrackSize trackSize;
2749 if (!createGridTrackSize(value, trackSize, state))
2751 state.style()->setGridAutoRows(trackSize);
2754 case CSSPropertyWebkitGridDefinitionColumns: {
2755 Vector<GridTrackSize> trackSizes;
2756 NamedGridLinesMap namedGridLines;
2757 if (!createGridTrackList(value, trackSizes, namedGridLines, state))
2759 state.style()->setGridColumns(trackSizes);
2760 state.style()->setNamedGridColumnLines(namedGridLines);
2763 case CSSPropertyWebkitGridDefinitionRows: {
2764 Vector<GridTrackSize> trackSizes;
2765 NamedGridLinesMap namedGridLines;
2766 if (!createGridTrackList(value, trackSizes, namedGridLines, state))
2768 state.style()->setGridRows(trackSizes);
2769 state.style()->setNamedGridRowLines(namedGridLines);
2773 case CSSPropertyWebkitGridColumnStart: {
2774 GridPosition columnStartPosition;
2775 if (!createGridPosition(value, columnStartPosition))
2777 state.style()->setGridItemColumnStart(columnStartPosition);
2780 case CSSPropertyWebkitGridColumnEnd: {
2781 GridPosition columnEndPosition;
2782 if (!createGridPosition(value, columnEndPosition))
2784 state.style()->setGridItemColumnEnd(columnEndPosition);
2788 case CSSPropertyWebkitGridRowStart: {
2789 GridPosition rowStartPosition;
2790 if (!createGridPosition(value, rowStartPosition))
2792 state.style()->setGridItemRowStart(rowStartPosition);
2795 case CSSPropertyWebkitGridRowEnd: {
2796 GridPosition rowEndPosition;
2797 if (!createGridPosition(value, rowEndPosition))
2799 state.style()->setGridItemRowEnd(rowEndPosition);
2803 // These properties are aliased and DeprecatedStyleBuilder already applied the property on the prefixed version.
2804 case CSSPropertyTransitionDelay:
2805 case CSSPropertyTransitionDuration:
2806 case CSSPropertyTransitionProperty:
2807 case CSSPropertyTransitionTimingFunction:
2809 // These properties are implemented in the DeprecatedStyleBuilder lookup table.
2810 case CSSPropertyBackgroundAttachment:
2811 case CSSPropertyBackgroundClip:
2812 case CSSPropertyBackgroundColor:
2813 case CSSPropertyBackgroundImage:
2814 case CSSPropertyBackgroundOrigin:
2815 case CSSPropertyBackgroundPositionX:
2816 case CSSPropertyBackgroundPositionY:
2817 case CSSPropertyBackgroundRepeatX:
2818 case CSSPropertyBackgroundRepeatY:
2819 case CSSPropertyBackgroundSize:
2820 case CSSPropertyBorderBottomColor:
2821 case CSSPropertyBorderBottomLeftRadius:
2822 case CSSPropertyBorderBottomRightRadius:
2823 case CSSPropertyBorderBottomStyle:
2824 case CSSPropertyBorderBottomWidth:
2825 case CSSPropertyBorderCollapse:
2826 case CSSPropertyBorderImageOutset:
2827 case CSSPropertyBorderImageRepeat:
2828 case CSSPropertyBorderImageSlice:
2829 case CSSPropertyBorderImageSource:
2830 case CSSPropertyBorderImageWidth:
2831 case CSSPropertyBorderLeftColor:
2832 case CSSPropertyBorderLeftStyle:
2833 case CSSPropertyBorderLeftWidth:
2834 case CSSPropertyBorderRightColor:
2835 case CSSPropertyBorderRightStyle:
2836 case CSSPropertyBorderRightWidth:
2837 case CSSPropertyBorderTopColor:
2838 case CSSPropertyBorderTopLeftRadius:
2839 case CSSPropertyBorderTopRightRadius:
2840 case CSSPropertyBorderTopStyle:
2841 case CSSPropertyBorderTopWidth:
2842 case CSSPropertyBottom:
2843 case CSSPropertyBoxSizing:
2844 case CSSPropertyCaptionSide:
2845 case CSSPropertyClear:
2846 case CSSPropertyClip:
2847 case CSSPropertyColor:
2848 case CSSPropertyCounterIncrement:
2849 case CSSPropertyCounterReset:
2850 case CSSPropertyCursor:
2851 case CSSPropertyDirection:
2852 case CSSPropertyDisplay:
2853 case CSSPropertyEmptyCells:
2854 case CSSPropertyFloat:
2855 case CSSPropertyFontSize:
2856 case CSSPropertyFontStyle:
2857 case CSSPropertyFontVariant:
2858 case CSSPropertyFontWeight:
2859 case CSSPropertyHeight:
2860 #if ENABLE(CSS_IMAGE_ORIENTATION)
2861 case CSSPropertyImageOrientation:
2863 case CSSPropertyImageRendering:
2864 #if ENABLE(CSS_IMAGE_RESOLUTION)
2865 case CSSPropertyImageResolution:
2867 case CSSPropertyLeft:
2868 case CSSPropertyLetterSpacing:
2869 case CSSPropertyLineHeight:
2870 case CSSPropertyListStyleImage:
2871 case CSSPropertyListStylePosition:
2872 case CSSPropertyListStyleType:
2873 case CSSPropertyMarginBottom:
2874 case CSSPropertyMarginLeft:
2875 case CSSPropertyMarginRight:
2876 case CSSPropertyMarginTop:
2877 case CSSPropertyMaxHeight:
2878 case CSSPropertyMaxWidth:
2879 case CSSPropertyMinHeight:
2880 case CSSPropertyMinWidth:
2881 case CSSPropertyObjectFit:
2882 case CSSPropertyOpacity:
2883 case CSSPropertyOrphans:
2884 case CSSPropertyOutlineColor:
2885 case CSSPropertyOutlineOffset:
2886 case CSSPropertyOutlineStyle:
2887 case CSSPropertyOutlineWidth:
2888 case CSSPropertyOverflowWrap:
2889 case CSSPropertyOverflowX:
2890 case CSSPropertyOverflowY:
2891 case CSSPropertyPaddingBottom:
2892 case CSSPropertyPaddingLeft:
2893 case CSSPropertyPaddingRight:
2894 case CSSPropertyPaddingTop:
2895 case CSSPropertyPageBreakAfter:
2896 case CSSPropertyPageBreakBefore:
2897 case CSSPropertyPageBreakInside:
2898 case CSSPropertyPointerEvents:
2899 case CSSPropertyPosition:
2900 case CSSPropertyResize:
2901 case CSSPropertyRight:
2902 case CSSPropertySize:
2903 case CSSPropertySpeak:
2904 case CSSPropertyTabSize:
2905 case CSSPropertyTableLayout:
2906 case CSSPropertyTextAlign:
2907 case CSSPropertyTextDecoration:
2908 case CSSPropertyTextIndent:
2909 case CSSPropertyTextOverflow:
2910 case CSSPropertyTextRendering:
2911 case CSSPropertyTextTransform:
2912 case CSSPropertyTop:
2913 case CSSPropertyUnicodeBidi:
2914 #if ENABLE(CSS_VARIABLES)
2915 case CSSPropertyVariable:
2917 case CSSPropertyVerticalAlign:
2918 case CSSPropertyVisibility:
2919 case CSSPropertyWebkitAnimationDelay:
2920 case CSSPropertyWebkitAnimationDirection:
2921 case CSSPropertyWebkitAnimationDuration:
2922 case CSSPropertyWebkitAnimationFillMode:
2923 case CSSPropertyWebkitAnimationIterationCount:
2924 case CSSPropertyWebkitAnimationName:
2925 case CSSPropertyWebkitAnimationPlayState:
2926 case CSSPropertyWebkitAnimationTimingFunction:
2927 case CSSPropertyWebkitAppearance:
2928 case CSSPropertyWebkitAspectRatio:
2929 case CSSPropertyWebkitBackfaceVisibility:
2930 case CSSPropertyWebkitBackgroundClip:
2931 case CSSPropertyWebkitBackgroundComposite:
2932 case CSSPropertyWebkitBackgroundOrigin:
2933 case CSSPropertyWebkitBackgroundSize:
2934 case CSSPropertyWebkitBorderFit:
2935 case CSSPropertyWebkitBorderHorizontalSpacing:
2936 case CSSPropertyWebkitBorderImage:
2937 case CSSPropertyWebkitBorderVerticalSpacing:
2938 case CSSPropertyWebkitBoxAlign:
2939 #if ENABLE(CSS_BOX_DECORATION_BREAK)
2940 case CSSPropertyWebkitBoxDecorationBreak:
2942 case CSSPropertyWebkitBoxDirection:
2943 case CSSPropertyWebkitBoxFlex:
2944 case CSSPropertyWebkitBoxFlexGroup:
2945 case CSSPropertyWebkitBoxLines:
2946 case CSSPropertyWebkitBoxOrdinalGroup:
2947 case CSSPropertyWebkitBoxOrient:
2948 case CSSPropertyWebkitBoxPack:
2949 case CSSPropertyWebkitColorCorrection:
2950 case CSSPropertyWebkitColumnAxis:
2951 case CSSPropertyWebkitColumnBreakAfter:
2952 case CSSPropertyWebkitColumnBreakBefore:
2953 case CSSPropertyWebkitColumnBreakInside:
2954 case CSSPropertyWebkitColumnCount:
2955 case CSSPropertyWebkitColumnGap:
2956 case CSSPropertyWebkitColumnProgression:
2957 case CSSPropertyWebkitColumnRuleColor:
2958 case CSSPropertyWebkitColumnRuleStyle:
2959 case CSSPropertyWebkitColumnRuleWidth:
2960 case CSSPropertyWebkitColumnSpan:
2961 case CSSPropertyWebkitColumnWidth:
2962 #if ENABLE(CURSOR_VISIBILITY)
2963 case CSSPropertyWebkitCursorVisibility:
2965 case CSSPropertyWebkitAlignContent:
2966 case CSSPropertyWebkitAlignItems:
2967 case CSSPropertyWebkitAlignSelf:
2968 case CSSPropertyWebkitFlexBasis:
2969 case CSSPropertyWebkitFlexDirection:
2970 case CSSPropertyWebkitFlexGrow:
2971 case CSSPropertyWebkitFlexShrink:
2972 case CSSPropertyWebkitFlexWrap:
2973 case CSSPropertyWebkitJustifyContent:
2974 case CSSPropertyWebkitOrder:
2975 #if ENABLE(CSS_REGIONS)
2976 case CSSPropertyWebkitFlowFrom:
2977 case CSSPropertyWebkitFlowInto:
2979 case CSSPropertyWebkitFontKerning:
2980 case CSSPropertyWebkitFontSmoothing:
2981 case CSSPropertyWebkitFontVariantLigatures:
2982 case CSSPropertyWebkitHighlight:
2983 case CSSPropertyWebkitHyphenateCharacter:
2984 case CSSPropertyWebkitHyphenateLimitAfter:
2985 case CSSPropertyWebkitHyphenateLimitBefore:
2986 case CSSPropertyWebkitHyphenateLimitLines:
2987 case CSSPropertyWebkitHyphens:
2988 case CSSPropertyWebkitLineAlign:
2989 case CSSPropertyWebkitLineBreak:
2990 case CSSPropertyWebkitLineClamp:
2991 case CSSPropertyWebkitLineGrid:
2992 case CSSPropertyWebkitLineSnap:
2993 case CSSPropertyWebkitMarqueeDirection:
2994 case CSSPropertyWebkitMarqueeIncrement:
2995 case CSSPropertyWebkitMarqueeRepetition:
2996 case CSSPropertyWebkitMarqueeSpeed:
2997 case CSSPropertyWebkitMarqueeStyle:
2998 case CSSPropertyWebkitMaskBoxImage:
2999 case CSSPropertyWebkitMaskBoxImageOutset:
3000 case CSSPropertyWebkitMaskBoxImageRepeat:
3001 case CSSPropertyWebkitMaskBoxImageSlice:
3002 case CSSPropertyWebkitMaskBoxImageSource:
3003 case CSSPropertyWebkitMaskBoxImageWidth:
3004 case CSSPropertyWebkitMaskClip:
3005 case CSSPropertyWebkitMaskComposite:
3006 case CSSPropertyWebkitMaskImage:
3007 case CSSPropertyWebkitMaskOrigin:
3008 case CSSPropertyWebkitMaskPositionX:
3009 case CSSPropertyWebkitMaskPositionY:
3010 case CSSPropertyWebkitMaskRepeatX:
3011 case CSSPropertyWebkitMaskRepeatY:
3012 case CSSPropertyWebkitMaskSize:
3013 case CSSPropertyWebkitMaskSourceType:
3014 case CSSPropertyWebkitNbspMode:
3015 case CSSPropertyWebkitPerspectiveOrigin:
3016 case CSSPropertyWebkitPerspectiveOriginX:
3017 case CSSPropertyWebkitPerspectiveOriginY:
3018 case CSSPropertyWebkitPrintColorAdjust:
3019 #if ENABLE(CSS_REGIONS)
3020 case CSSPropertyWebkitRegionBreakAfter:
3021 case CSSPropertyWebkitRegionBreakBefore:
3022 case CSSPropertyWebkitRegionBreakInside:
3023 case CSSPropertyWebkitRegionFragment:
3025 case CSSPropertyWebkitRtlOrdering:
3026 case CSSPropertyWebkitRubyPosition:
3027 case CSSPropertyWebkitTextCombine:
3028 #if ENABLE(CSS3_TEXT)
3029 case CSSPropertyWebkitTextDecorationLine:
3030 case CSSPropertyWebkitTextDecorationStyle:
3031 case CSSPropertyWebkitTextDecorationColor:
3032 case CSSPropertyWebkitTextAlignLast:
3033 case CSSPropertyWebkitTextJustify:
3034 case CSSPropertyWebkitTextUnderlinePosition:
3036 case CSSPropertyWebkitTextEmphasisColor:
3037 case CSSPropertyWebkitTextEmphasisPosition:
3038 case CSSPropertyWebkitTextEmphasisStyle:
3039 case CSSPropertyWebkitTextFillColor:
3040 case CSSPropertyWebkitTextSecurity:
3041 case CSSPropertyWebkitTextStrokeColor:
3042 case CSSPropertyWebkitTransformOriginX:
3043 case CSSPropertyWebkitTransformOriginY:
3044 case CSSPropertyWebkitTransformOriginZ:
3045 case CSSPropertyWebkitTransformStyle:
3046 case CSSPropertyWebkitTransitionDelay:
3047 case CSSPropertyWebkitTransitionDuration:
3048 case CSSPropertyWebkitTransitionProperty:
3049 case CSSPropertyWebkitTransitionTimingFunction:
3050 case CSSPropertyWebkitUserDrag:
3051 case CSSPropertyWebkitUserModify:
3052 case CSSPropertyWebkitUserSelect:
3053 case CSSPropertyWebkitClipPath:
3054 #if ENABLE(CSS_SHAPES)
3055 case CSSPropertyWebkitShapeMargin:
3056 case CSSPropertyWebkitShapePadding:
3057 case CSSPropertyWebkitShapeInside:
3058 case CSSPropertyWebkitShapeOutside:
3060 #if ENABLE(CSS_EXCLUSIONS)
3061 case CSSPropertyWebkitWrapFlow:
3062 case CSSPropertyWebkitWrapThrough:
3064 #if ENABLE(CSS_SHADERS)
3065 case CSSPropertyMix:
3066 case CSSPropertyParameters:
3068 case CSSPropertyWhiteSpace:
3069 case CSSPropertyWidows:
3070 case CSSPropertyWidth:
3071 case CSSPropertyWordBreak:
3072 case CSSPropertyWordSpacing:
3073 case CSSPropertyWordWrap:
3074 case CSSPropertyZIndex:
3075 case CSSPropertyZoom:
3076 #if ENABLE(CSS_DEVICE_ADAPTATION)
3077 case CSSPropertyMaxZoom:
3078 case CSSPropertyMinZoom:
3079 case CSSPropertyOrientation:
3080 case CSSPropertyUserZoom:
3082 ASSERT_NOT_REACHED();
3086 // Try the SVG properties
3087 applySVGProperty(id, value);
3093 PassRefPtr<StyleImage> StyleResolver::styleImage(CSSPropertyID property, CSSValue* value)
3095 if (value->isImageValue())
3096 return cachedOrPendingFromValue(property, static_cast<CSSImageValue*>(value));
3098 if (value->isImageGeneratorValue()) {
3099 if (value->isGradientValue())
3100 return generatedOrPendingFromValue(property, static_cast<CSSGradientValue*>(value)->gradientWithStylesResolved(this).get());
3101 return generatedOrPendingFromValue(property, static_cast<CSSImageGeneratorValue*>(value));
3104 #if ENABLE(CSS_IMAGE_SET)
3105 if (value->isImageSetValue())
3106 return setOrPendingFromValue(property, toCSSImageSetValue(value));
3109 if (value->isCursorImageValue())
3110 return cursorOrPendingFromValue(property, static_cast<CSSCursorImageValue*>(value));
3115 PassRefPtr<StyleImage> StyleResolver::cachedOrPendingFromValue(CSSPropertyID property, CSSImageValue* value)
3117 RefPtr<StyleImage> image = value->cachedOrPendingImage();
3118 if (image && image->isPendingImage())
3119 m_state.pendingImageProperties().set(property, value);
3120 return image.release();
3123 PassRefPtr<StyleImage> StyleResolver::generatedOrPendingFromValue(CSSPropertyID property, CSSImageGeneratorValue* value)
3125 #if ENABLE(CSS_FILTERS)
3126 if (value->isFilterImageValue()) {
3127 // FilterImage needs to calculate FilterOperations.
3128 static_cast<CSSFilterImageValue*>(value)->createFilterOperations(this);
3131 if (value->isPending()) {
3132 m_state.pendingImageProperties().set(property, value);
3133 return StylePendingImage::create(value);
3135 return StyleGeneratedImage::create(value);
3138 #if ENABLE(CSS_IMAGE_SET)
3139 PassRefPtr<StyleImage> StyleResolver::setOrPendingFromValue(CSSPropertyID property, CSSImageSetValue* value)
3141 RefPtr<StyleImage> image = value->cachedOrPendingImageSet(document());
3142 if (image && image->isPendingImage())
3143 m_state.pendingImageProperties().set(property, value);
3144 return image.release();
3148 PassRefPtr<StyleImage> StyleResolver::cursorOrPendingFromValue(CSSPropertyID property, CSSCursorImageValue* value)
3150 RefPtr<StyleImage> image = value->cachedOrPendingImage(document());
3151 if (image && image->isPendingImage())
3152 m_state.pendingImageProperties().set(property, value);
3153 return image.release();
3156 #if ENABLE(IOS_TEXT_AUTOSIZING)
3157 void StyleResolver::checkForTextSizeAdjust(RenderStyle* style)
3159 if (style->textSizeAdjust().isAuto())
3162 FontDescription newFontDescription(style->fontDescription());
3163 if (!style->textSizeAdjust().isNone())
3164 newFontDescription.setComputedSize(newFontDescription.specifiedSize() * style->textSizeAdjust().multiplier());
3166 newFontDescription.setComputedSize(newFontDescription.specifiedSize());
3167 style->setFontDescription(newFontDescription);
3171 void StyleResolver::checkForZoomChange(RenderStyle* style, RenderStyle* parentStyle)
3173 if (style->effectiveZoom() == parentStyle->effectiveZoom())
3176 const FontDescription& childFont = style->fontDescription();
3177 FontDescription newFontDescription(childFont);
3178 setFontSize(newFontDescription, childFont.specifiedSize());
3179 style->setFontDescription(newFontDescription);
3182 void StyleResolver::checkForGenericFamilyChange(RenderStyle* style, RenderStyle* parentStyle)
3184 const FontDescription& childFont = style->fontDescription();
3186 if (childFont.isAbsoluteSize() || !parentStyle)
3189 const FontDescription& parentFont = parentStyle->fontDescription();
3190 if (childFont.useFixedDefaultSize() == parentFont.useFixedDefaultSize())
3193 // For now, lump all families but monospace together.
3194 if (childFont.genericFamily() != FontDescription::MonospaceFamily
3195 && parentFont.genericFamily() != FontDescription::MonospaceFamily)
3198 // We know the parent is monospace or the child is monospace, and that font
3199 // size was unspecified. We want to scale our font size as appropriate.
3200 // If the font uses a keyword size, then we refetch from the table rather than
3201 // multiplying by our scale factor.
3203 if (childFont.keywordSize())
3204 size = Style::fontSizeForKeyword(CSSValueXxSmall + childFont.keywordSize() - 1, childFont.useFixedDefaultSize(), document());
3206 Settings* settings = documentSettings();
3207 float fixedScaleFactor = (settings && settings->defaultFixedFontSize() && settings->defaultFontSize())
3208 ? static_cast<float>(settings->defaultFixedFontSize()) / settings->defaultFontSize()
3210 size = parentFont.useFixedDefaultSize() ?
3211 childFont.specifiedSize() / fixedScaleFactor :
3212 childFont.specifiedSize() * fixedScaleFactor;
3215 FontDescription newFontDescription(childFont);
3216 setFontSize(newFontDescription, size);
3217 style->setFontDescription(newFontDescription);
3220 void StyleResolver::initializeFontStyle(Settings* settings)
3222 FontDescription fontDescription;
3223 fontDescription.setGenericFamily(FontDescription::StandardFamily);
3224 fontDescription.setRenderingMode(settings->fontRenderingMode());
3225 fontDescription.setUsePrinterFont(document().printing() || !settings->screenFontSubstitutionEnabled());
3226 const AtomicString& standardFontFamily = documentSettings()->standardFontFamily();
3227 if (!standardFontFamily.isEmpty())
3228 fontDescription.setOneFamily(standardFontFamily);
3229 fontDescription.setKeywordSize(CSSValueMedium - CSSValueXxSmall + 1);
3230 setFontSize(fontDescription, Style::fontSizeForKeyword(CSSValueMedium, false, document()));
3231 m_state.style()->setLineHeight(RenderStyle::initialLineHeight());
3232 m_state.setLineHeightValue(0);
3233 setFontDescription(fontDescription);
3236 void StyleResolver::setFontSize(FontDescription& fontDescription, float size)
3238 fontDescription.setSpecifiedSize(size);
3239 fontDescription.setComputedSize(Style::computedFontSizeFromSpecifiedSize(size, fontDescription.isAbsoluteSize(), useSVGZoomRules(), m_state.style(), document()));
3242 static Color colorForCSSValue(CSSValueID cssValueId)
3245 CSSValueID cssValueId;
3249 static const ColorValue colorValues[] = {
3250 { CSSValueAqua, 0xFF00FFFF },
3251 { CSSValueBlack, 0xFF000000 },
3252 { CSSValueBlue, 0xFF0000FF },
3253 { CSSValueFuchsia, 0xFFFF00FF },
3254 { CSSValueGray, 0xFF808080 },
3255 { CSSValueGreen, 0xFF008000 },
3256 { CSSValueGrey, 0xFF808080 },
3257 { CSSValueLime, 0xFF00FF00 },
3258 { CSSValueMaroon, 0xFF800000 },
3259 { CSSValueNavy, 0xFF000080 },
3260 { CSSValueOlive, 0xFF808000 },
3261 { CSSValueOrange, 0xFFFFA500 },
3262 { CSSValuePurple, 0xFF800080 },
3263 { CSSValueRed, 0xFFFF0000 },
3264 { CSSValueSilver, 0xFFC0C0C0 },
3265 { CSSValueTeal, 0xFF008080 },
3266 { CSSValueTransparent, 0x00000000 },
3267 { CSSValueWhite, 0xFFFFFFFF },
3268 { CSSValueYellow, 0xFFFFFF00 },
3269 { CSSValueInvalid, CSSValueInvalid }
3272 for (const ColorValue* col = colorValues; col->cssValueId; ++col) {
3273 if (col->cssValueId == cssValueId)
3276 return RenderTheme::defaultTheme()->systemColor(cssValueId);
3279 bool StyleResolver::colorFromPrimitiveValueIsDerivedFromElement(CSSPrimitiveValue* value)
3281 int ident = value->getValueID();
3283 case CSSValueWebkitText:
3284 case CSSValueWebkitLink:
3285 case CSSValueWebkitActivelink:
3286 case CSSValueCurrentcolor:
3293 Color StyleResolver::colorFromPrimitiveValue(CSSPrimitiveValue* value, bool forVisitedLink) const
3295 if (value->isRGBColor())
3296 return Color(value->getRGBA32Value());
3298 const State& state = m_state;
3299 CSSValueID ident = value->getValueID();
3303 case CSSValueWebkitText:
3304 return state.document().textColor();
3305 case CSSValueWebkitLink:
3306 return (state.element()->isLink() && forVisitedLink) ? state.document().visitedLinkColor() : state.document().linkColor();
3307 case CSSValueWebkitActivelink:
3308 return state.document().activeLinkColor();
3309 case CSSValueWebkitFocusRingColor:
3310 return RenderTheme::focusRingColor();
3311 case CSSValueCurrentcolor:
3312 return state.style()->color();
3314 return colorForCSSValue(ident);
3318 void StyleResolver::addViewportDependentMediaQueryResult(const MediaQueryExp* expr, bool result)
3320 m_viewportDependentMediaQueryResults.append(adoptPtr(new MediaQueryResult(*expr, result)));
3323 bool StyleResolver::affectedByViewportChange() const
3325 unsigned s = m_viewportDependentMediaQueryResults.size();
3326 for (unsigned i = 0; i < s; i++) {
3327 if (m_medium->eval(&m_viewportDependentMediaQueryResults[i]->m_expression) != m_viewportDependentMediaQueryResults[i]->m_result)
3333 #if ENABLE(CSS_FILTERS)
3334 static FilterOperation::OperationType filterOperationForType(WebKitCSSFilterValue::FilterOperationType type)
3337 case WebKitCSSFilterValue::ReferenceFilterOperation:
3338 return FilterOperation::REFERENCE;
3339 case WebKitCSSFilterValue::GrayscaleFilterOperation:
3340 return FilterOperation::GRAYSCALE;
3341 case WebKitCSSFilterValue::SepiaFilterOperation:
3342 return FilterOperation::SEPIA;
3343 case WebKitCSSFilterValue::SaturateFilterOperation:
3344 return FilterOperation::SATURATE;
3345 case WebKitCSSFilterValue::HueRotateFilterOperation:
3346 return FilterOperation::HUE_ROTATE;
3347 case WebKitCSSFilterValue::InvertFilterOperation:
3348 return FilterOperation::INVERT;
3349 case WebKitCSSFilterValue::OpacityFilterOperation:
3350 return FilterOperation::OPACITY;
3351 case WebKitCSSFilterValue::BrightnessFilterOperation:
3352 return FilterOperation::BRIGHTNESS;
3353 case WebKitCSSFilterValue::ContrastFilterOperation:
3354 return FilterOperation::CONTRAST;
3355 case WebKitCSSFilterValue::BlurFilterOperation:
3356 return FilterOperation::BLUR;
3357 case WebKitCSSFilterValue::DropShadowFilterOperation:
3358 return FilterOperation::DROP_SHADOW;
3359 #if ENABLE(CSS_SHADERS)
3360 case WebKitCSSFilterValue::CustomFilterOperation:
3361 return FilterOperation::CUSTOM;
3363 case WebKitCSSFilterValue::UnknownFilterOperation:
3364 return FilterOperation::NONE;
3366 return FilterOperation::NONE;
3369 #if ENABLE(CSS_FILTERS) && ENABLE(SVG)
3370 void StyleResolver::loadPendingSVGDocuments()
3372 State& state = m_state;
3374 // Crash reports indicate that we've seen calls to this function when our
3375 // style is NULL. We don't know exactly why this happens. Our guess is
3376 // reentering styleForElement().
3377 ASSERT(state.style());
3378 if (!state.style() || !state.style()->hasFilter() || state.pendingSVGDocuments().isEmpty())
3381 CachedResourceLoader* cachedResourceLoader = state.document().cachedResourceLoader();
3382 Vector<RefPtr<FilterOperation> >& filterOperations = state.style()->mutableFilter().operations();
3383 for (unsigned i = 0; i < filterOperations.size(); ++i) {
3384 RefPtr<FilterOperation> filterOperation = filterOperations.at(i);
3385 if (filterOperation->getOperationType() == FilterOperation::REFERENCE) {
3386 ReferenceFilterOperation* referenceFilter = static_cast<ReferenceFilterOperation*>(filterOperation.get());
3388 WebKitCSSSVGDocumentValue* value = state.pendingSVGDocuments().get(referenceFilter);
3391 CachedSVGDocument* cachedDocument = value->load(cachedResourceLoader);
3392 if (!cachedDocument)
3395 // Stash the CachedSVGDocument on the reference filter.
3396 referenceFilter->setCachedSVGDocumentReference(adoptPtr(new CachedSVGDocumentReference(cachedDocument)));
3399 state.pendingSVGDocuments().clear();
3403 #if ENABLE(CSS_SHADERS)
3404 StyleShader* StyleResolver::styleShader(CSSValue* value)
3406 if (value->isWebKitCSSShaderValue())
3407 return cachedOrPendingStyleShaderFromValue(static_cast<WebKitCSSShaderValue*>(value));
3411 StyleShader* StyleResolver::cachedOrPendingStyleShaderFromValue(WebKitCSSShaderValue* value)
3413 StyleShader* shader = value->cachedOrPendingShader();
3414 if (shader && shader->isPendingShader())
3415 m_state.setHasPendingShaders(true);
3419 PassRefPtr<CustomFilterProgram> StyleResolver::lookupCustomFilterProgram(WebKitCSSShaderValue* vertexShader, WebKitCSSShaderValue* fragmentShader,
3420 CustomFilterProgramType programType, const CustomFilterProgramMixSettings& mixSettings, CustomFilterMeshType meshType)
3422 CachedResourceLoader* cachedResourceLoader = m_state.document().cachedResourceLoader();
3423 KURL vertexShaderURL = vertexShader ? vertexShader->completeURL(cachedResourceLoader) : KURL();
3424 KURL fragmentShaderURL = fragmentShader ? fragmentShader->completeURL(cachedResourceLoader) : KURL();
3425 RefPtr<StyleCustomFilterProgram> program;
3426 if (m_customFilterProgramCache)
3427 program = m_customFilterProgramCache->lookup(CustomFilterProgramInfo(vertexShaderURL, fragmentShaderURL, programType, mixSettings, meshType));
3429 // Create a new StyleCustomFilterProgram that will be resolved during the loadPendingShaders and added to the cache.
3430 program = StyleCustomFilterProgram::create(vertexShaderURL, vertexShader ? styleShader(vertexShader) : 0,
3431 fragmentShaderURL, fragm