Source/WebCore/ChangeLog

112012-03-30 Eric Seidel <eric@webkit.org>
22
 3 styleForElement() should use enums instead of bools so we can all understand what it's doing
 4 https://bugs.webkit.org/show_bug.cgi?id=82807
 5
 6 Reviewed by NOBODY (OOPS!).
 7
 8 No change in behavior, thus no tests.
 9
 10 Mostly this is just replacing true/false with the correct new enum value
 11 or removing true/false from the callsites when they would have been default anyway.
 12 I think this makes the code *way* more clear.
 13
 14 The old code was extra confusing because the defaults were "true, false". :)
 15 The new defaults are AllowStyleSharing, MatchAllRules.
 16 It's very uncommon for callers to want to override either of these behaviors.
 17 I think most callers which specify DisallowStyleSharing likely don't actually need to
 18 (our style-sharing code should be smart enough to only share when safe anyway).
 19
 20 * css/CSSStyleSelector.cpp:
 21 (WebCore::CSSStyleSelector::CSSStyleSelector):
 22 - Use enums and remove bogus comment (m_rootDefaultStyle is a RefPtr!)
 23 (WebCore::CSSStyleSelector::collectMatchingRulesForList):
 24 * css/CSSStyleSelector.h:
 25 (CSSStyleSelector):
 26 * css/MediaQueryMatcher.cpp:
 27 (WebCore::MediaQueryMatcher::prepareEvaluator):
 28 * css/StyleMedia.cpp:
 29 (WebCore::StyleMedia::matchMedium):
 30 * dom/Element.cpp:
 31 (WebCore::Element::styleForRenderer):
 32 * rendering/RenderObject.cpp:
 33 (WebCore::RenderObject::getUncachedPseudoStyle):
 34 - Updated to use enums
 35 - Also fixed this to use toElement and modern early-return styles.
 36 * rendering/RenderRegion.cpp:
 37 (WebCore::RenderRegion::computeStyleInRegion):
 38 * svg/SVGElement.cpp:
 39 (WebCore::SVGElement::customStyleForRenderer):
 40
 412012-03-30 Eric Seidel <eric@webkit.org>
 42
343 Add tests for iframe seamless and support for parsing webkitseamless attribute
444 https://bugs.webkit.org/show_bug.cgi?id=82795
545

Source/WebCore/css/CSSStyleSelector.cpp

@@CSSStyleSelector::CSSStyleSelector(Document* document, bool matchAuthorAndUserSt
375375 m_medium = adoptPtr(new MediaQueryEvaluator("all"));
376376
377377 if (root)
378  m_rootDefaultStyle = styleForElement(root, 0, false, true); // don't ref, because the RenderStyle is allocated from global heap
 378 m_rootDefaultStyle = styleForElement(root, 0, DisallowStyleSharing, MatchOnlyUserAgentRules);
379379
380380 if (m_rootDefaultStyle && view)
381381 m_medium = adoptPtr(new MediaQueryEvaluator(view->mediaType(), view->frame(), m_rootDefaultStyle.get()));

@@static inline bool isAtShadowBoundary(Element* element)
15671567 return parentNode && parentNode->isShadowRoot();
15681568}
15691569
1570 // If resolveForRootDefault is true, style based on user agent style sheet only. This is used in media queries, where
1571 // relative units are interpreted according to document root element style, styled only with UA stylesheet
1572 
1573 PassRefPtr<RenderStyle> CSSStyleSelector::styleForElement(Element* element, RenderStyle* defaultParent, bool allowSharing, bool resolveForRootDefault, RenderRegion* regionForStyling)
 1570PassRefPtr<RenderStyle> CSSStyleSelector::styleForElement(Element* element, RenderStyle* defaultParent,
 1571 StyleSharingBehavior sharingBehavior, RuleMatchingBehavior matchingBehavior, RenderRegion* regionForStyling)
15741572{
15751573 // Once an element has a renderer, we don't try to destroy it, since otherwise the renderer
15761574 // will vanish if a style recalc happens during loading.
1577  if (allowSharing && !element->document()->haveStylesheetsLoaded() && !element->renderer()) {
 1575 if (sharingBehavior == AllowStyleSharing && !element->document()->haveStylesheetsLoaded() && !element->renderer()) {
15781576 if (!s_styleNotYetAvailable) {
15791577 s_styleNotYetAvailable = RenderStyle::create().leakRef();
15801578 s_styleNotYetAvailable->setDisplay(NONE);

@@PassRefPtr<RenderStyle> CSSStyleSelector::styleForElement(Element* element, Rend
15871585 initElement(element);
15881586 initForStyleResolve(element, defaultParent);
15891587 m_regionForStyling = regionForStyling;
1590  if (allowSharing) {
 1588 if (sharingBehavior == AllowStyleSharing) {
15911589 RenderStyle* sharedStyle = locateSharedStyle();
15921590 if (sharedStyle)
15931591 return sharedStyle;

@@PassRefPtr<RenderStyle> CSSStyleSelector::styleForElement(Element* element, Rend
16151613 ensureDefaultStyleSheetsForElement(element);
16161614
16171615 MatchResult matchResult;
1618  if (resolveForRootDefault)
 1616 if (matchingBehavior == MatchOnlyUserAgentRules)
16191617 matchUARules(matchResult);
16201618 else
16211619 matchAllRules(matchResult);

Source/WebCore/css/CSSStyleSelector.h

@@public:
100100 bool m_result;
101101};
102102
 103enum StyleSharingBehavior {
 104 AllowStyleSharing,
 105 DisallowStyleSharing,
 106};
 107
 108// MatchOnlyUserAgentRules is used in media queries, where relative units
 109// are interpreted according to the document root element style, and styled only
 110// from the User Agent Stylesheet rules.
 111
 112enum RuleMatchingBehavior {
 113 MatchAllRules,
 114 MatchOnlyUserAgentRules,
 115};
 116
103117// This class selects a RenderStyle for a given element based on a collection of stylesheets.
104118class CSSStyleSelector {
105119 WTF_MAKE_NONCOPYABLE(CSSStyleSelector); WTF_MAKE_FAST_ALLOCATED;

@@public:
113127 void pushParentShadowRoot(const ShadowRoot*);
114128 void popParentShadowRoot(const ShadowRoot*);
115129
116  PassRefPtr<RenderStyle> styleForElement(Element*, RenderStyle* parentStyle = 0, bool allowSharing = true, bool resolveForRootDefault = false, RenderRegion* regionForStyling = 0);
 130 PassRefPtr<RenderStyle> styleForElement(Element*, RenderStyle* parentStyle = 0, StyleSharingBehavior = AllowStyleSharing,
 131 RuleMatchingBehavior = MatchAllRules, RenderRegion* regionForStyling = 0);
117132
118133 void keyframeStylesForAnimation(Element*, const RenderStyle*, KeyframeList&);
119134

Source/WebCore/css/MediaQueryMatcher.cpp

@@PassOwnPtr<MediaQueryEvaluator> MediaQueryMatcher::prepareEvaluator() const
8888 if (!styleSelector)
8989 return nullptr;
9090
91  RefPtr<RenderStyle> rootStyle = styleSelector->styleForElement(documentElement, 0 /*defaultParent*/, false /*allowSharing*/, true /*resolveForRootDefault*/);
 91 RefPtr<RenderStyle> rootStyle = styleSelector->styleForElement(documentElement, 0 /*defaultParent*/, DisallowStyleSharing, MatchOnlyUserAgentRules);
9292
9393 return adoptPtr(new MediaQueryEvaluator(mediaType(), m_document->frame(), rootStyle.get()));
9494}

Source/WebCore/css/StyleMedia.cpp

@@bool StyleMedia::matchMedium(const String& query) const
6464 if (!styleSelector)
6565 return false;
6666
67  RefPtr<RenderStyle> rootStyle = styleSelector->styleForElement(documentElement, 0 /*defaultParent*/, false /*allowSharing*/, true /*resolveForRootDefault*/);
 67 RefPtr<RenderStyle> rootStyle = styleSelector->styleForElement(documentElement, 0 /*defaultParent*/, DisallowStyleSharing, MatchOnlyUserAgentRules);
6868
6969 RefPtr<MediaQuerySet> media = MediaQuerySet::create();
7070 if (!media->parse(query))

Source/WebCore/dom/Element.cpp

@@PassRefPtr<RenderStyle> Element::styleForRenderer()
10381038{
10391039 if (hasCustomStyleForRenderer())
10401040 return customStyleForRenderer();
1041  return document()->styleSelector()->styleForElement(static_cast<Element*>(this), 0, true/*allowSharing*/);
 1041 return document()->styleSelector()->styleForElement(static_cast<Element*>(this));
10421042}
10431043
10441044void Element::recalcStyle(StyleChange change)

Source/WebCore/rendering/RenderObject.cpp

@@PassRefPtr<RenderStyle> RenderObject::getUncachedPseudoStyle(PseudoId pseudo, Re
25452545 parentStyle = style();
25462546 }
25472547
 2548 /// FIXME: This "find nearest element parent" should be a helper function.
25482549 Node* n = node();
25492550 while (n && !n->isElementNode())
25502551 n = n->parentNode();
25512552 if (!n)
25522553 return 0;
 2554 Element* element = toElement(n);
25532555
2554  RefPtr<RenderStyle> result;
25552556 if (pseudo == FIRST_LINE_INHERITED) {
2556  result = document()->styleSelector()->styleForElement(static_cast<Element*>(n), parentStyle, false);
 2557 RefPtr<RenderStyle> result = document()->styleSelector()->styleForElement(element, parentStyle, DisallowStyleSharing);
25572558 result->setStyleType(FIRST_LINE_INHERITED);
2558  } else
2559  result = document()->styleSelector()->pseudoStyleForElement(pseudo, static_cast<Element*>(n), parentStyle);
2560  return result.release();
 2559 return result.release();
 2560 }
 2561 return document()->styleSelector()->pseudoStyleForElement(pseudo, element, parentStyle);
25612562}
25622563
25632564static Color decorationColor(RenderObject* renderer)

Source/WebCore/rendering/RenderRegion.cpp

@@PassRefPtr<RenderStyle> RenderRegion::computeStyleInRegion(const RenderBox* box)
300300 ASSERT(box->node() && box->node()->isElementNode());
301301
302302 Element* element = toElement(box->node());
303  RefPtr<RenderStyle> renderBoxRegionStyle = box->view()->document()->styleSelector()->styleForElement(element, 0, false, false, this);
 303 RefPtr<RenderStyle> renderBoxRegionStyle = box->view()->document()->styleSelector()->styleForElement(element, 0, DisallowStyleSharing, MatchAllRules, this);
304304 m_renderBoxRegionStyle.add(box, renderBoxRegionStyle);
305305
306306 if (!box->hasBoxDecorations()) {

Source/WebCore/svg/SVGElement.cpp

@@void SVGElement::synchronizeSystemLanguage(void* contextElement)
478478PassRefPtr<RenderStyle> SVGElement::customStyleForRenderer()
479479{
480480 if (!correspondingElement())
481  return document()->styleSelector()->styleForElement(static_cast<Element*>(this), 0, true);
 481 return document()->styleSelector()->styleForElement(this);
482482
483483 RenderStyle* style = 0;
484484 if (Element* parent = parentOrHostElement()) {

@@PassRefPtr<RenderStyle> SVGElement::customStyleForRenderer()
486486 style = renderer->style();
487487 }
488488
489  return document()->styleSelector()->styleForElement(correspondingElement(), style, false /*allowSharing*/);
 489 return document()->styleSelector()->styleForElement(correspondingElement(), style, DisallowStyleSharing);
490490}
491491
492492StylePropertySet* SVGElement::animatedSMILStyleProperties() const