<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[160138] trunk/Source/WebCore</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/160138">160138</a></dd>
<dt>Author</dt> <dd>antti@apple.com</dd>
<dt>Date</dt> <dd>2013-12-04 16:03:00 -0800 (Wed, 04 Dec 2013)</dd>
</dl>

<h3>Log Message</h3>
<pre>Move pseudo element construction out from Element
https://bugs.webkit.org/show_bug.cgi?id=125257

Reviewed by Anders Carlsson.

This is logically part of the style resolve/render tree construction. This will make future
refactoring easier.

* dom/Element.cpp:
* dom/Element.h:
* style/StyleResolveTree.cpp:
(WebCore::Style::beforeOrAfterPseudoElement):
(WebCore::Style::setBeforeOrAfterPseudoElement):
(WebCore::Style::clearBeforeOrAfterPseudoElement):
(WebCore::Style::needsPseudeElement):
(WebCore::Style::attachBeforeOrAfterPseudoElementIfNeeded):
(WebCore::Style::attachRenderTree):
(WebCore::Style::updateBeforeOrAfterPseudoElement):
(WebCore::Style::resolveTree):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoredomElementcpp">trunk/Source/WebCore/dom/Element.cpp</a></li>
<li><a href="#trunkSourceWebCoredomElementh">trunk/Source/WebCore/dom/Element.h</a></li>
<li><a href="#trunkSourceWebCorestyleStyleResolveTreecpp">trunk/Source/WebCore/style/StyleResolveTree.cpp</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (160137 => 160138)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2013-12-04 23:43:37 UTC (rev 160137)
+++ trunk/Source/WebCore/ChangeLog        2013-12-05 00:03:00 UTC (rev 160138)
</span><span class="lines">@@ -1,3 +1,25 @@
</span><ins>+2013-12-04  Antti Koivisto  &lt;antti@apple.com&gt;
+
+        Move pseudo element construction out from Element
+        https://bugs.webkit.org/show_bug.cgi?id=125257
+
+        Reviewed by Anders Carlsson.
+
+        This is logically part of the style resolve/render tree construction. This will make future
+        refactoring easier.
+
+        * dom/Element.cpp:
+        * dom/Element.h:
+        * style/StyleResolveTree.cpp:
+        (WebCore::Style::beforeOrAfterPseudoElement):
+        (WebCore::Style::setBeforeOrAfterPseudoElement):
+        (WebCore::Style::clearBeforeOrAfterPseudoElement):
+        (WebCore::Style::needsPseudeElement):
+        (WebCore::Style::attachBeforeOrAfterPseudoElementIfNeeded):
+        (WebCore::Style::attachRenderTree):
+        (WebCore::Style::updateBeforeOrAfterPseudoElement):
+        (WebCore::Style::resolveTree):
+
</ins><span class="cx"> 2013-12-04  Zoltan Horvath  &lt;zoltan@webkit.org&gt;
</span><span class="cx"> 
</span><span class="cx">         Move TrailingObjects class into its own h/cpp
</span></span></pre></div>
<a id="trunkSourceWebCoredomElementcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/Element.cpp (160137 => 160138)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/Element.cpp        2013-12-04 23:43:37 UTC (rev 160137)
+++ trunk/Source/WebCore/dom/Element.cpp        2013-12-05 00:03:00 UTC (rev 160138)
</span><span class="lines">@@ -2334,57 +2334,6 @@
</span><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-bool Element::updateExistingPseudoElement(PseudoElement* existingPseudoElement, Style::Change change)
-{
-    // PseudoElement styles hang off their parent element's style so if we needed
-    // a style recalc we should Force one on the pseudo.
-    Style::resolveTree(*existingPseudoElement, needsStyleRecalc() ? Style::Force : change);
-
-    // FIXME: This is silly.
-    // Wait until our parent is not displayed or pseudoElementRendererIsNeeded
-    // is false, otherwise we could continously create and destroy PseudoElements
-    // when RenderElement::isChildAllowed on our parent returns false for the
-    // PseudoElement's renderer for each style recalc.
-    return renderer() &amp;&amp; pseudoElementRendererIsNeeded(existingPseudoElement-&gt;renderStyle());
-}
-
-PassRefPtr&lt;PseudoElement&gt; Element::createPseudoElementIfNeeded(PseudoId pseudoId)
-{
-    if (!document().styleSheetCollection().usesBeforeAfterRules())
-        return 0;
-    if (!renderer() || !renderer()-&gt;canHaveGeneratedChildren())
-        return 0;
-    if (isPseudoElement())
-        return 0;
-    if (!pseudoElementRendererIsNeeded(renderer()-&gt;getCachedPseudoStyle(pseudoId)))
-        return 0;
-    RefPtr&lt;PseudoElement&gt; pseudoElement = PseudoElement::create(*this, pseudoId);
-    Style::attachRenderTree(*pseudoElement);
-    return pseudoElement.release();
-}
-
-void Element::updateBeforePseudoElement(Style::Change change)
-{
-    if (PseudoElement* existingPseudoElement = beforePseudoElement()) {
-        if (!updateExistingPseudoElement(existingPseudoElement, change))
-            clearBeforePseudoElement();
-        return;
-    }
-    if (RefPtr&lt;PseudoElement&gt; pseudo = createPseudoElementIfNeeded(BEFORE))
-        setBeforePseudoElement(pseudo.release());
-}
-
-void Element::updateAfterPseudoElement(Style::Change change)
-{
-    if (PseudoElement* existingPseudoElement = afterPseudoElement()) {
-        if (!updateExistingPseudoElement(existingPseudoElement, change))
-            clearAfterPseudoElement();
-        return;
-    }
-    if (RefPtr&lt;PseudoElement&gt; pseudo = createPseudoElementIfNeeded(AFTER))
-        setAfterPseudoElement(pseudo.release());
-}
-
</del><span class="cx"> PseudoElement* Element::beforePseudoElement() const
</span><span class="cx"> {
</span><span class="cx">     return hasRareData() ? elementRareData()-&gt;beforePseudoElement() : 0;
</span></span></pre></div>
<a id="trunkSourceWebCoredomElementh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/Element.h (160137 => 160138)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/Element.h        2013-12-04 23:43:37 UTC (rev 160137)
+++ trunk/Source/WebCore/dom/Element.h        2013-12-05 00:03:00 UTC (rev 160138)
</span><span class="lines">@@ -551,8 +551,10 @@
</span><span class="cx">     virtual void willDetachRenderers();
</span><span class="cx">     virtual void didDetachRenderers();
</span><span class="cx"> 
</span><del>-    void updateBeforePseudoElement(Style::Change);
-    void updateAfterPseudoElement(Style::Change);
</del><ins>+    void setBeforePseudoElement(PassRefPtr&lt;PseudoElement&gt;);
+    void setAfterPseudoElement(PassRefPtr&lt;PseudoElement&gt;);
+    void clearBeforePseudoElement();
+    void clearAfterPseudoElement();
</ins><span class="cx">     void resetComputedStyle();
</span><span class="cx">     void clearStyleDerivedDataBeforeDetachingRenderer();
</span><span class="cx">     void clearHoverAndActiveStatusBeforeDetachingRenderer();
</span><span class="lines">@@ -590,13 +592,6 @@
</span><span class="cx">     bool isUserActionElementFocused() const;
</span><span class="cx">     bool isUserActionElementHovered() const;
</span><span class="cx"> 
</span><del>-    PassRefPtr&lt;PseudoElement&gt; createPseudoElementIfNeeded(PseudoId);
-    bool updateExistingPseudoElement(PseudoElement* existing, Style::Change);
-
-    void setBeforePseudoElement(PassRefPtr&lt;PseudoElement&gt;);
-    void setAfterPseudoElement(PassRefPtr&lt;PseudoElement&gt;);
-    void clearBeforePseudoElement();
-    void clearAfterPseudoElement();
</del><span class="cx">     void resetNeedsNodeRenderingTraversalSlowPath();
</span><span class="cx"> 
</span><span class="cx">     virtual bool areAuthorShadowsAllowed() const { return true; }
</span></span></pre></div>
<a id="trunkSourceWebCorestyleStyleResolveTreecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/style/StyleResolveTree.cpp (160137 => 160138)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/style/StyleResolveTree.cpp        2013-12-04 23:43:37 UTC (rev 160137)
+++ trunk/Source/WebCore/style/StyleResolveTree.cpp        2013-12-05 00:03:00 UTC (rev 160138)
</span><span class="lines">@@ -467,6 +467,56 @@
</span><span class="cx">     shadowRoot.setAttached(true);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+static PseudoElement* beforeOrAfterPseudoElement(Element&amp; current, PseudoId pseudoId)
+{
+    ASSERT(pseudoId == BEFORE || pseudoId == AFTER);
+    if (pseudoId == BEFORE)
+        return current.beforePseudoElement();
+    return current.afterPseudoElement();
+}
+
+static void setBeforeOrAfterPseudoElement(Element&amp; current, PassRefPtr&lt;PseudoElement&gt; pseudoElement, PseudoId pseudoId)
+{
+    ASSERT(pseudoId == BEFORE || pseudoId == AFTER);
+    if (pseudoId == BEFORE) {
+        current.setBeforePseudoElement(pseudoElement);
+        return;
+    }
+    current.setAfterPseudoElement(pseudoElement);
+}
+
+static void clearBeforeOrAfterPseudoElement(Element&amp; current, PseudoId pseudoId)
+{
+    ASSERT(pseudoId == BEFORE || pseudoId == AFTER);
+    if (pseudoId == BEFORE) {
+        current.clearBeforePseudoElement();
+        return;
+    }
+    current.clearAfterPseudoElement();
+}
+
+static bool needsPseudeElement(Element&amp; current, PseudoId pseudoId)
+{
+    if (!current.document().styleSheetCollection().usesBeforeAfterRules())
+        return false;
+    if (!current.renderer() || !current.renderer()-&gt;canHaveGeneratedChildren())
+        return false;
+    if (current.isPseudoElement())
+        return false;
+    if (!pseudoElementRendererIsNeeded(current.renderer()-&gt;getCachedPseudoStyle(pseudoId)))
+        return false;
+    return true;
+}
+
+static void attachBeforeOrAfterPseudoElementIfNeeded(Element&amp; current, PseudoId pseudoId)
+{
+    if (!needsPseudeElement(current, pseudoId))
+        return;
+    RefPtr&lt;PseudoElement&gt; pseudoElement = PseudoElement::create(current, pseudoId);
+    setBeforeOrAfterPseudoElement(current, pseudoElement, pseudoId);
+    attachRenderTree(*pseudoElement, nullptr);
+}
+
</ins><span class="cx"> static void attachRenderTree(Element&amp; current, PassRefPtr&lt;RenderStyle&gt; resolvedStyle)
</span><span class="cx"> {
</span><span class="cx">     PostAttachCallbackDisabler callbackDisabler(current);
</span><span class="lines">@@ -480,7 +530,7 @@
</span><span class="cx">     if (current.parentElement() &amp;&amp; current.parentElement()-&gt;isInCanvasSubtree())
</span><span class="cx">         current.setIsInCanvasSubtree(true);
</span><span class="cx"> 
</span><del>-    current.updateBeforePseudoElement(NoChange);
</del><ins>+    attachBeforeOrAfterPseudoElementIfNeeded(current, BEFORE);
</ins><span class="cx"> 
</span><span class="cx">     StyleResolverParentPusher parentPusher(&amp;current);
</span><span class="cx"> 
</span><span class="lines">@@ -499,7 +549,7 @@
</span><span class="cx">     if (AXObjectCache* cache = current.document().axObjectCache())
</span><span class="cx">         cache-&gt;updateCacheAfterNodeIsAttached(&amp;current);
</span><span class="cx"> 
</span><del>-    current.updateAfterPseudoElement(NoChange);
</del><ins>+    attachBeforeOrAfterPseudoElementIfNeeded(current, AFTER);
</ins><span class="cx"> 
</span><span class="cx">     current.updateFocusAppearanceAfterAttachIfNeeded();
</span><span class="cx">     
</span><span class="lines">@@ -674,6 +724,18 @@
</span><span class="cx">     shadowRoot-&gt;clearChildNeedsStyleRecalc();
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+static void updateBeforeOrAfterPseudoElement(Element&amp; current, Change change, PseudoId pseudoId)
+{
+    if (PseudoElement* existingPseudoElement = beforeOrAfterPseudoElement(current, pseudoId)) {
+        if (needsPseudeElement(current, pseudoId))
+            resolveTree(*existingPseudoElement, current.needsStyleRecalc() ? Force : change);
+        else
+            clearBeforeOrAfterPseudoElement(current, pseudoId);
+        return;
+    }
+    attachBeforeOrAfterPseudoElementIfNeeded(current, pseudoId);
+}
+
</ins><span class="cx"> #if PLATFORM(IOS)
</span><span class="cx"> static EVisibility elementImplicitVisibility(const Element* element)
</span><span class="cx"> {
</span><span class="lines">@@ -762,7 +824,7 @@
</span><span class="cx">             }
</span><span class="cx">         }
</span><span class="cx"> 
</span><del>-        current.updateBeforePseudoElement(change);
</del><ins>+        updateBeforeOrAfterPseudoElement(current, change, BEFORE);
</ins><span class="cx"> 
</span><span class="cx">         // FIXME: This check is good enough for :hover + foo, but it is not good enough for :hover + foo + bar.
</span><span class="cx">         // For now we will just worry about the common case, since it's a lot trickier to get the second case right
</span><span class="lines">@@ -788,7 +850,7 @@
</span><span class="cx">             forceCheckOfAnyElementSibling = forceCheckOfAnyElementSibling || (childRulesChanged &amp;&amp; hasIndirectAdjacentRules);
</span><span class="cx">         }
</span><span class="cx"> 
</span><del>-        current.updateAfterPseudoElement(change);
</del><ins>+        updateBeforeOrAfterPseudoElement(current, change, AFTER);
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     current.clearNeedsStyleRecalc();
</span></span></pre>
</div>
</div>

</body>
</html>