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

Side by Side Diff: Source/core/dom/Element.cpp

Issue 639863006: Revert of 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/dom/Element.h ('k') | Source/core/dom/ElementRareData.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Peter Kelly (pmk@post.com) 4 * (C) 2001 Peter Kelly (pmk@post.com)
5 * (C) 2001 Dirk Mueller (mueller@kde.org) 5 * (C) 2001 Dirk Mueller (mueller@kde.org)
6 * (C) 2007 David Smith (catfish.man@gmail.com) 6 * (C) 2007 David Smith (catfish.man@gmail.com)
7 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012, 2013 Apple Inc. All rights reserved. 7 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012, 2013 Apple Inc. All rights reserved.
8 * (C) 2007 Eric Seidel (eric@webkit.org) 8 * (C) 2007 Eric Seidel (eric@webkit.org)
9 * 9 *
10 * This library is free software; you can redistribute it and/or 10 * This library is free software; you can redistribute it and/or
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 #include "core/css/resolver/StyleResolverParentScope.h" 49 #include "core/css/resolver/StyleResolverParentScope.h"
50 #include "core/dom/Attr.h" 50 #include "core/dom/Attr.h"
51 #include "core/dom/CSSSelectorWatch.h" 51 #include "core/dom/CSSSelectorWatch.h"
52 #include "core/dom/ClientRect.h" 52 #include "core/dom/ClientRect.h"
53 #include "core/dom/ClientRectList.h" 53 #include "core/dom/ClientRectList.h"
54 #include "core/dom/DatasetDOMStringMap.h" 54 #include "core/dom/DatasetDOMStringMap.h"
55 #include "core/dom/ElementDataCache.h" 55 #include "core/dom/ElementDataCache.h"
56 #include "core/dom/ElementRareData.h" 56 #include "core/dom/ElementRareData.h"
57 #include "core/dom/ElementTraversal.h" 57 #include "core/dom/ElementTraversal.h"
58 #include "core/dom/ExceptionCode.h" 58 #include "core/dom/ExceptionCode.h"
59 #include "core/dom/FirstLetterPseudoElement.h"
60 #include "core/dom/Fullscreen.h" 59 #include "core/dom/Fullscreen.h"
61 #include "core/dom/MutationObserverInterestGroup.h" 60 #include "core/dom/MutationObserverInterestGroup.h"
62 #include "core/dom/MutationRecord.h" 61 #include "core/dom/MutationRecord.h"
63 #include "core/dom/NamedNodeMap.h" 62 #include "core/dom/NamedNodeMap.h"
64 #include "core/dom/NodeRenderStyle.h" 63 #include "core/dom/NodeRenderStyle.h"
65 #include "core/dom/PresentationAttributeStyle.h" 64 #include "core/dom/PresentationAttributeStyle.h"
66 #include "core/dom/PseudoElement.h" 65 #include "core/dom/PseudoElement.h"
67 #include "core/dom/RenderTreeBuilder.h" 66 #include "core/dom/RenderTreeBuilder.h"
68 #include "core/dom/ScriptableDocumentParser.h" 67 #include "core/dom/ScriptableDocumentParser.h"
69 #include "core/dom/SelectorQuery.h" 68 #include "core/dom/SelectorQuery.h"
70 #include "core/dom/StyleChangeReason.h"
71 #include "core/dom/StyleEngine.h" 69 #include "core/dom/StyleEngine.h"
72 #include "core/dom/Text.h" 70 #include "core/dom/Text.h"
73 #include "core/dom/custom/CustomElement.h" 71 #include "core/dom/custom/CustomElement.h"
74 #include "core/dom/custom/CustomElementRegistrationContext.h" 72 #include "core/dom/custom/CustomElementRegistrationContext.h"
75 #include "core/dom/shadow/InsertionPoint.h" 73 #include "core/dom/shadow/InsertionPoint.h"
76 #include "core/dom/shadow/ShadowRoot.h" 74 #include "core/dom/shadow/ShadowRoot.h"
77 #include "core/editing/FrameSelection.h" 75 #include "core/editing/FrameSelection.h"
78 #include "core/editing/TextIterator.h" 76 #include "core/editing/TextIterator.h"
79 #include "core/editing/htmlediting.h" 77 #include "core/editing/htmlediting.h"
80 #include "core/editing/markup.h" 78 #include "core/editing/markup.h"
(...skipping 17 matching lines...) Expand all
98 #include "core/html/HTMLTableRowsCollection.h" 96 #include "core/html/HTMLTableRowsCollection.h"
99 #include "core/html/HTMLTemplateElement.h" 97 #include "core/html/HTMLTemplateElement.h"
100 #include "core/html/parser/HTMLParserIdioms.h" 98 #include "core/html/parser/HTMLParserIdioms.h"
101 #include "core/inspector/InspectorInstrumentation.h" 99 #include "core/inspector/InspectorInstrumentation.h"
102 #include "core/page/Chrome.h" 100 #include "core/page/Chrome.h"
103 #include "core/page/ChromeClient.h" 101 #include "core/page/ChromeClient.h"
104 #include "core/page/FocusController.h" 102 #include "core/page/FocusController.h"
105 #include "core/page/Page.h" 103 #include "core/page/Page.h"
106 #include "core/page/PointerLockController.h" 104 #include "core/page/PointerLockController.h"
107 #include "core/rendering/RenderLayer.h" 105 #include "core/rendering/RenderLayer.h"
108 #include "core/rendering/RenderTextFragment.h"
109 #include "core/rendering/RenderView.h" 106 #include "core/rendering/RenderView.h"
110 #include "core/rendering/compositing/RenderLayerCompositor.h" 107 #include "core/rendering/compositing/RenderLayerCompositor.h"
111 #include "core/svg/SVGDocumentExtensions.h" 108 #include "core/svg/SVGDocumentExtensions.h"
112 #include "core/svg/SVGElement.h" 109 #include "core/svg/SVGElement.h"
113 #include "platform/EventDispatchForbiddenScope.h" 110 #include "platform/EventDispatchForbiddenScope.h"
114 #include "platform/RuntimeEnabledFeatures.h" 111 #include "platform/RuntimeEnabledFeatures.h"
115 #include "platform/UserGestureIndicator.h" 112 #include "platform/UserGestureIndicator.h"
116 #include "platform/scroll/ScrollableArea.h" 113 #include "platform/scroll/ScrollableArea.h"
117 #include "wtf/BitVector.h" 114 #include "wtf/BitVector.h"
118 #include "wtf/HashFunctions.h" 115 #include "wtf/HashFunctions.h"
(...skipping 1225 matching lines...) Expand 10 before | Expand all | Expand 10 after
1344 1341
1345 // When a shadow root exists, it does the work of attaching the children. 1342 // When a shadow root exists, it does the work of attaching the children.
1346 if (ElementShadow* shadow = this->shadow()) 1343 if (ElementShadow* shadow = this->shadow())
1347 shadow->attach(context); 1344 shadow->attach(context);
1348 1345
1349 ContainerNode::attach(context); 1346 ContainerNode::attach(context);
1350 1347
1351 createPseudoElementIfNeeded(AFTER); 1348 createPseudoElementIfNeeded(AFTER);
1352 createPseudoElementIfNeeded(BACKDROP); 1349 createPseudoElementIfNeeded(BACKDROP);
1353 1350
1354 // We create the first-letter element after the :before, :after and
1355 // children are attached because the first letter text could come
1356 // from any of them.
1357 createPseudoElementIfNeeded(FIRST_LETTER);
1358
1359 if (hasRareData() && !renderer()) { 1351 if (hasRareData() && !renderer()) {
1360 if (ActiveAnimations* activeAnimations = elementRareData()->activeAnimat ions()) { 1352 if (ActiveAnimations* activeAnimations = elementRareData()->activeAnimat ions()) {
1361 activeAnimations->cssAnimations().cancel(); 1353 activeAnimations->cssAnimations().cancel();
1362 activeAnimations->setAnimationStyleChange(false); 1354 activeAnimations->setAnimationStyleChange(false);
1363 } 1355 }
1364 } 1356 }
1365 } 1357 }
1366 1358
1367 void Element::detach(const AttachContext& context) 1359 void Element::detach(const AttachContext& context)
1368 { 1360 {
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
1508 for (ShadowRoot* root = youngestShadowRoot(); root; root = root->old erShadowRoot()) { 1500 for (ShadowRoot* root = youngestShadowRoot(); root; root = root->old erShadowRoot()) {
1509 if (root->shouldCallRecalcStyle(change)) 1501 if (root->shouldCallRecalcStyle(change))
1510 root->recalcStyle(change); 1502 root->recalcStyle(change);
1511 } 1503 }
1512 recalcChildStyle(change); 1504 recalcChildStyle(change);
1513 } 1505 }
1514 1506
1515 updatePseudoElement(AFTER, change); 1507 updatePseudoElement(AFTER, change);
1516 updatePseudoElement(BACKDROP, change); 1508 updatePseudoElement(BACKDROP, change);
1517 1509
1518 // If our children have changed then we need to force the first-letter
1519 // checks as we don't know if they effected the first letter or not.
1520 // This can be seen when a child transitions from floating to
1521 // non-floating we have to take it into account for the first letter.
1522 updatePseudoElement(FIRST_LETTER, childNeedsStyleRecalc() ? Force : chan ge);
1523
1524 clearChildNeedsStyleRecalc(); 1510 clearChildNeedsStyleRecalc();
1525 } 1511 }
1526 1512
1527 if (hasCustomStyleCallbacks()) 1513 if (hasCustomStyleCallbacks())
1528 didRecalcStyle(change); 1514 didRecalcStyle(change);
1529 1515
1530 if (change == Reattach) 1516 if (change == Reattach)
1531 reattachWhitespaceSiblings(nextTextSibling); 1517 reattachWhitespaceSiblings(nextTextSibling);
1532 } 1518 }
1533 1519
(...skipping 961 matching lines...) Expand 10 before | Expand all | Expand 10 after
2495 // attributes while we are iterating. 2481 // attributes while we are iterating.
2496 WillBeHeapVector<RefPtrWillBeMember<Attr> > attrNodesCopy(*attrNodes); 2482 WillBeHeapVector<RefPtrWillBeMember<Attr> > attrNodesCopy(*attrNodes);
2497 for (size_t i = 0; i < attrNodesCopy.size(); ++i) 2483 for (size_t i = 0; i < attrNodesCopy.size(); ++i)
2498 attrNodesCopy[i]->normalize(); 2484 attrNodesCopy[i]->normalize();
2499 } 2485 }
2500 2486
2501 void Element::updatePseudoElement(PseudoId pseudoId, StyleRecalcChange change) 2487 void Element::updatePseudoElement(PseudoId pseudoId, StyleRecalcChange change)
2502 { 2488 {
2503 ASSERT(!needsStyleRecalc()); 2489 ASSERT(!needsStyleRecalc());
2504 PseudoElement* element = pseudoElement(pseudoId); 2490 PseudoElement* element = pseudoElement(pseudoId);
2505
2506 if (element && (change == UpdatePseudoElements || element->shouldCallRecalcS tyle(change))) { 2491 if (element && (change == UpdatePseudoElements || element->shouldCallRecalcS tyle(change))) {
2507 if (pseudoId == FIRST_LETTER && updateFirstLetter(element))
2508 return;
2509 2492
2510 // Need to clear the cached style if the PseudoElement wants a recalc so it 2493 // Need to clear the cached style if the PseudoElement wants a recalc so it
2511 // computes a new style. 2494 // computes a new style.
2512 if (element->needsStyleRecalc()) 2495 if (element->needsStyleRecalc())
2513 renderer()->style()->removeCachedPseudoStyle(pseudoId); 2496 renderer()->style()->removeCachedPseudoStyle(pseudoId);
2514 2497
2515 // PseudoElement styles hang off their parent element's style so if we n eeded 2498 // PseudoElement styles hang off their parent element's style so if we n eeded
2516 // a style recalc we should Force one on the pseudo. 2499 // a style recalc we should Force one on the pseudo.
2517 // FIXME: We should figure out the right text sibling to pass. 2500 // FIXME: We should figure out the right text sibling to pass.
2518 element->recalcStyle(change == UpdatePseudoElements ? Force : change); 2501 element->recalcStyle(change == UpdatePseudoElements ? Force : change);
2519 2502
2520 // Wait until our parent is not displayed or pseudoElementRendererIsNeed ed 2503 // Wait until our parent is not displayed or pseudoElementRendererIsNeed ed
2521 // is false, otherwise we could continuously create and destroy PseudoEl ements 2504 // is false, otherwise we could continously create and destroy PseudoEle ments
2522 // when RenderObject::isChildAllowed on our parent returns false for the 2505 // when RenderObject::isChildAllowed on our parent returns false for the
2523 // PseudoElement's renderer for each style recalc. 2506 // PseudoElement's renderer for each style recalc.
2524 if (!renderer() || !pseudoElementRendererIsNeeded(renderer()->getCachedP seudoStyle(pseudoId))) 2507 if (!renderer() || !pseudoElementRendererIsNeeded(renderer()->getCachedP seudoStyle(pseudoId)))
2525 elementRareData()->setPseudoElement(pseudoId, nullptr); 2508 elementRareData()->setPseudoElement(pseudoId, nullptr);
2526 } else if (pseudoId == FIRST_LETTER && element && change >= UpdatePseudoElem ents && !FirstLetterPseudoElement::firstLetterTextRenderer(*element)) {
2527 // This can happen if we change to a float, for example. We need to clea nup the
2528 // first-letter pseudoElement and then fix the text of the original rema ining
2529 // text renderer.
2530 // This can be seen in Test 7 of fast/css/first-letter-removed-added.htm l
2531 elementRareData()->setPseudoElement(pseudoId, nullptr);
2532 } else if (change >= UpdatePseudoElements) { 2509 } else if (change >= UpdatePseudoElements) {
2533 createPseudoElementIfNeeded(pseudoId); 2510 createPseudoElementIfNeeded(pseudoId);
2534 } 2511 }
2535 } 2512 }
2536 2513
2537 // If we're updating first letter, and the current first letter renderer
2538 // is not the same as the one we're currently using we need to re-create
2539 // the first letter renderer.
2540 bool Element::updateFirstLetter(Element* element)
2541 {
2542 RenderObject* remainingTextRenderer = FirstLetterPseudoElement::firstLetterT extRenderer(*element);
2543 if (!remainingTextRenderer || remainingTextRenderer != toFirstLetterPseudoEl ement(element)->remainingTextRenderer()
2544 || toFirstLetterPseudoElement(element)->needsUpdate()) {
2545 // We have to clear out the old first letter here because when it is
2546 // disposed it will set the original text back on the remaining text
2547 // renderer. If we dispose after creating the new one we will get
2548 // incorrect results due to setting the first letter back.
2549 if (remainingTextRenderer)
2550 element->reattach();
2551 else
2552 elementRareData()->setPseudoElement(FIRST_LETTER, nullptr);
2553 return true;
2554 }
2555 return false;
2556 }
2557
2558 void Element::createPseudoElementIfNeeded(PseudoId pseudoId) 2514 void Element::createPseudoElementIfNeeded(PseudoId pseudoId)
2559 { 2515 {
2560 if (isPseudoElement()) 2516 if (isPseudoElement())
2561 return; 2517 return;
2562 2518
2563 // Document::ensureStyleResolver is not inlined and shows up on profiles, av oid it here. 2519 // Document::ensureStyleResolver is not inlined and shows up on profiles, av oid it here.
2564 StyleEngine* engine = document().styleEngine(); 2520 StyleEngine* engine = document().styleEngine();
2565 RefPtrWillBeRawPtr<PseudoElement> element = engine->ensureResolver().createP seudoElementIfNeeded(*this, pseudoId); 2521 RefPtrWillBeRawPtr<PseudoElement> element = engine->ensureResolver().createP seudoElementIfNeeded(*this, pseudoId);
2566 if (!element) 2522 if (!element)
2567 return; 2523 return;
(...skipping 740 matching lines...) Expand 10 before | Expand all | Expand 10 after
3308 return wrapper; 3264 return wrapper;
3309 3265
3310 CustomElementBinding* binding = perContextData->customElementBinding(customE lementDefinition()); 3266 CustomElementBinding* binding = perContextData->customElementBinding(customE lementDefinition());
3311 3267
3312 wrapper->SetPrototype(binding->prototype()); 3268 wrapper->SetPrototype(binding->prototype());
3313 3269
3314 return V8DOMWrapper::associateObjectWithWrapperNonTemplate(this, wrapperType , wrapper, isolate); 3270 return V8DOMWrapper::associateObjectWithWrapperNonTemplate(this, wrapperType , wrapper, isolate);
3315 } 3271 }
3316 3272
3317 } // namespace blink 3273 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/dom/Element.h ('k') | Source/core/dom/ElementRareData.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698