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

Unified Diff: Source/core/dom/Element.cpp

Issue 571603003: Convert first letter into a pseudo element. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/core/dom/Element.cpp
diff --git a/Source/core/dom/Element.cpp b/Source/core/dom/Element.cpp
index 008fb9055e6258dde22c6474eb0809919eb8d8ec..83ca020c22c1891b25ea384a991b89b934b700b4 100644
--- a/Source/core/dom/Element.cpp
+++ b/Source/core/dom/Element.cpp
@@ -56,6 +56,7 @@
#include "core/dom/ElementRareData.h"
#include "core/dom/ElementTraversal.h"
#include "core/dom/ExceptionCode.h"
+#include "core/dom/FirstLetterPseudoElement.h"
#include "core/dom/Fullscreen.h"
#include "core/dom/MutationObserverInterestGroup.h"
#include "core/dom/MutationRecord.h"
@@ -66,6 +67,7 @@
#include "core/dom/RenderTreeBuilder.h"
#include "core/dom/ScriptableDocumentParser.h"
#include "core/dom/SelectorQuery.h"
+#include "core/dom/StyleChangeReason.h"
#include "core/dom/StyleEngine.h"
#include "core/dom/Text.h"
#include "core/dom/custom/CustomElement.h"
@@ -103,6 +105,7 @@
#include "core/page/Page.h"
#include "core/page/PointerLockController.h"
#include "core/rendering/RenderLayer.h"
+#include "core/rendering/RenderTextFragment.h"
#include "core/rendering/RenderView.h"
#include "core/rendering/compositing/RenderLayerCompositor.h"
#include "core/svg/SVGDocumentExtensions.h"
@@ -1348,6 +1351,11 @@ void Element::attach(const AttachContext& context)
createPseudoElementIfNeeded(AFTER);
createPseudoElementIfNeeded(BACKDROP);
+ // We create the first-letter element after the :before, :after and
+ // children are attached because the first letter text could come
+ // from any of them.
+ createPseudoElementIfNeeded(FIRST_LETTER);
+
if (hasRareData() && !renderer()) {
if (ActiveAnimations* activeAnimations = elementRareData()->activeAnimations()) {
activeAnimations->cssAnimations().cancel();
@@ -1507,6 +1515,12 @@ void Element::recalcStyle(StyleRecalcChange change, Text* nextTextSibling)
updatePseudoElement(AFTER, change);
updatePseudoElement(BACKDROP, change);
+ // If our children have changed then we need to force the first-letter
+ // checks as we don't know if they effected the first letter or not.
+ // This can be seen when a child transitions from floating to
+ // non-floating we have to take it into account for the first letter.
+ updatePseudoElement(FIRST_LETTER, childNeedsStyleRecalc() ? Force : change);
+
clearChildNeedsStyleRecalc();
}
@@ -2488,7 +2502,24 @@ void Element::updatePseudoElement(PseudoId pseudoId, StyleRecalcChange change)
{
ASSERT(!needsStyleRecalc());
PseudoElement* element = pseudoElement(pseudoId);
+
if (element && (change == UpdatePseudoElements || element->shouldCallRecalcStyle(change))) {
+ // If we're updating first letter, and the current first letter renderer
+ // is not the same as the one we're currently using we need to re-create
+ // the first letter renderer.
+ if (pseudoId == FIRST_LETTER) {
+ RenderObject* remainingTextRenderer = FirstLetterPseudoElement::firstLetterTextRenderer(*element);
+ if (!remainingTextRenderer || remainingTextRenderer != toFirstLetterPseudoElement(element)->remainingTextRenderer()
Julien - ping for review 2014/10/06 17:47:32 Wouldn't |element| be an arbitrary Element and not
Julien - ping for review 2014/10/06 20:11:45 Actually nevermind, I thought |element| == this.
dsinclair 2014/10/07 19:36:20 Right, it has to be otherwise something has gone v
+ || toFirstLetterPseudoElement(element)->isStale()) {
+ // We have to clear out the old first letter here because when it is
+ // disposed it will set the original text back on the remaining text
+ // renderer. If we dispose after creating the new one we will get
+ // incorrect results due to setting the first letter back.
+ elementRareData()->setPseudoElement(FIRST_LETTER, nullptr);
+ createPseudoElementIfNeeded(pseudoId);
esprehn 2014/10/07 00:17:40 You should just reattach the first letter PseudoEl
dsinclair 2014/10/07 19:36:20 Done. I was using FirstLetterPseudoElement::dispo
+ return;
+ }
+ }
// Need to clear the cached style if the PseudoElement wants a recalc so it
// computes a new style.
@@ -2501,13 +2532,21 @@ void Element::updatePseudoElement(PseudoId pseudoId, StyleRecalcChange change)
element->recalcStyle(change == UpdatePseudoElements ? Force : change);
// Wait until our parent is not displayed or pseudoElementRendererIsNeeded
- // is false, otherwise we could continously create and destroy PseudoElements
+ // is false, otherwise we could continuously create and destroy PseudoElements
// when RenderObject::isChildAllowed on our parent returns false for the
// PseudoElement's renderer for each style recalc.
if (!renderer() || !pseudoElementRendererIsNeeded(renderer()->getCachedPseudoStyle(pseudoId)))
elementRareData()->setPseudoElement(pseudoId, nullptr);
} else if (change >= UpdatePseudoElements) {
- createPseudoElementIfNeeded(pseudoId);
+ // We have a first-letter pseudoElement, but we no longer should have one.
+ // This can happen if we change to a float, for example. We need to cleanup the
+ // first-letter pseudoElement and then fix the text of the original remaining
+ // text renderer.
+ // This can be seen in Test 7 of fast/css/first-letter-removed-added.html
+ if (pseudoId == FIRST_LETTER && element && !FirstLetterPseudoElement::firstLetterTextRenderer(*element))
+ elementRareData()->setPseudoElement(pseudoId, nullptr);
esprehn 2014/10/07 00:17:40 This is in the wrong side of the branch. You shoul
dsinclair 2014/10/07 19:36:20 Done? I wasn't quite sure what you meant with the
+ else
+ createPseudoElementIfNeeded(pseudoId);
}
}

Powered by Google App Engine
This is Rietveld 408576698