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

Side by Side 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 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"
59 #include "core/dom/Fullscreen.h" 60 #include "core/dom/Fullscreen.h"
60 #include "core/dom/MutationObserverInterestGroup.h" 61 #include "core/dom/MutationObserverInterestGroup.h"
61 #include "core/dom/MutationRecord.h" 62 #include "core/dom/MutationRecord.h"
62 #include "core/dom/NamedNodeMap.h" 63 #include "core/dom/NamedNodeMap.h"
63 #include "core/dom/NodeRenderStyle.h" 64 #include "core/dom/NodeRenderStyle.h"
64 #include "core/dom/PresentationAttributeStyle.h" 65 #include "core/dom/PresentationAttributeStyle.h"
65 #include "core/dom/PseudoElement.h" 66 #include "core/dom/PseudoElement.h"
66 #include "core/dom/RenderTreeBuilder.h" 67 #include "core/dom/RenderTreeBuilder.h"
67 #include "core/dom/ScriptableDocumentParser.h" 68 #include "core/dom/ScriptableDocumentParser.h"
68 #include "core/dom/SelectorQuery.h" 69 #include "core/dom/SelectorQuery.h"
70 #include "core/dom/StyleChangeReason.h"
69 #include "core/dom/StyleEngine.h" 71 #include "core/dom/StyleEngine.h"
70 #include "core/dom/Text.h" 72 #include "core/dom/Text.h"
71 #include "core/dom/custom/CustomElement.h" 73 #include "core/dom/custom/CustomElement.h"
72 #include "core/dom/custom/CustomElementRegistrationContext.h" 74 #include "core/dom/custom/CustomElementRegistrationContext.h"
73 #include "core/dom/shadow/InsertionPoint.h" 75 #include "core/dom/shadow/InsertionPoint.h"
74 #include "core/dom/shadow/ShadowRoot.h" 76 #include "core/dom/shadow/ShadowRoot.h"
75 #include "core/editing/FrameSelection.h" 77 #include "core/editing/FrameSelection.h"
76 #include "core/editing/TextIterator.h" 78 #include "core/editing/TextIterator.h"
77 #include "core/editing/htmlediting.h" 79 #include "core/editing/htmlediting.h"
78 #include "core/editing/markup.h" 80 #include "core/editing/markup.h"
(...skipping 17 matching lines...) Expand all
96 #include "core/html/HTMLTableRowsCollection.h" 98 #include "core/html/HTMLTableRowsCollection.h"
97 #include "core/html/HTMLTemplateElement.h" 99 #include "core/html/HTMLTemplateElement.h"
98 #include "core/html/parser/HTMLParserIdioms.h" 100 #include "core/html/parser/HTMLParserIdioms.h"
99 #include "core/inspector/InspectorInstrumentation.h" 101 #include "core/inspector/InspectorInstrumentation.h"
100 #include "core/page/Chrome.h" 102 #include "core/page/Chrome.h"
101 #include "core/page/ChromeClient.h" 103 #include "core/page/ChromeClient.h"
102 #include "core/page/FocusController.h" 104 #include "core/page/FocusController.h"
103 #include "core/page/Page.h" 105 #include "core/page/Page.h"
104 #include "core/page/PointerLockController.h" 106 #include "core/page/PointerLockController.h"
105 #include "core/rendering/RenderLayer.h" 107 #include "core/rendering/RenderLayer.h"
108 #include "core/rendering/RenderTextFragment.h"
106 #include "core/rendering/RenderView.h" 109 #include "core/rendering/RenderView.h"
107 #include "core/rendering/compositing/RenderLayerCompositor.h" 110 #include "core/rendering/compositing/RenderLayerCompositor.h"
108 #include "core/svg/SVGDocumentExtensions.h" 111 #include "core/svg/SVGDocumentExtensions.h"
109 #include "core/svg/SVGElement.h" 112 #include "core/svg/SVGElement.h"
110 #include "platform/EventDispatchForbiddenScope.h" 113 #include "platform/EventDispatchForbiddenScope.h"
111 #include "platform/RuntimeEnabledFeatures.h" 114 #include "platform/RuntimeEnabledFeatures.h"
112 #include "platform/UserGestureIndicator.h" 115 #include "platform/UserGestureIndicator.h"
113 #include "platform/scroll/ScrollableArea.h" 116 #include "platform/scroll/ScrollableArea.h"
114 #include "wtf/BitVector.h" 117 #include "wtf/BitVector.h"
115 #include "wtf/HashFunctions.h" 118 #include "wtf/HashFunctions.h"
(...skipping 1225 matching lines...) Expand 10 before | Expand all | Expand 10 after
1341 1344
1342 // When a shadow root exists, it does the work of attaching the children. 1345 // When a shadow root exists, it does the work of attaching the children.
1343 if (ElementShadow* shadow = this->shadow()) 1346 if (ElementShadow* shadow = this->shadow())
1344 shadow->attach(context); 1347 shadow->attach(context);
1345 1348
1346 ContainerNode::attach(context); 1349 ContainerNode::attach(context);
1347 1350
1348 createPseudoElementIfNeeded(AFTER); 1351 createPseudoElementIfNeeded(AFTER);
1349 createPseudoElementIfNeeded(BACKDROP); 1352 createPseudoElementIfNeeded(BACKDROP);
1350 1353
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
1351 if (hasRareData() && !renderer()) { 1359 if (hasRareData() && !renderer()) {
1352 if (ActiveAnimations* activeAnimations = elementRareData()->activeAnimat ions()) { 1360 if (ActiveAnimations* activeAnimations = elementRareData()->activeAnimat ions()) {
1353 activeAnimations->cssAnimations().cancel(); 1361 activeAnimations->cssAnimations().cancel();
1354 activeAnimations->setAnimationStyleChange(false); 1362 activeAnimations->setAnimationStyleChange(false);
1355 } 1363 }
1356 } 1364 }
1357 } 1365 }
1358 1366
1359 void Element::detach(const AttachContext& context) 1367 void Element::detach(const AttachContext& context)
1360 { 1368 {
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
1500 for (ShadowRoot* root = youngestShadowRoot(); root; root = root->old erShadowRoot()) { 1508 for (ShadowRoot* root = youngestShadowRoot(); root; root = root->old erShadowRoot()) {
1501 if (root->shouldCallRecalcStyle(change)) 1509 if (root->shouldCallRecalcStyle(change))
1502 root->recalcStyle(change); 1510 root->recalcStyle(change);
1503 } 1511 }
1504 recalcChildStyle(change); 1512 recalcChildStyle(change);
1505 } 1513 }
1506 1514
1507 updatePseudoElement(AFTER, change); 1515 updatePseudoElement(AFTER, change);
1508 updatePseudoElement(BACKDROP, change); 1516 updatePseudoElement(BACKDROP, change);
1509 1517
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
1510 clearChildNeedsStyleRecalc(); 1524 clearChildNeedsStyleRecalc();
1511 } 1525 }
1512 1526
1513 if (hasCustomStyleCallbacks()) 1527 if (hasCustomStyleCallbacks())
1514 didRecalcStyle(change); 1528 didRecalcStyle(change);
1515 1529
1516 if (change == Reattach) 1530 if (change == Reattach)
1517 reattachWhitespaceSiblings(nextTextSibling); 1531 reattachWhitespaceSiblings(nextTextSibling);
1518 } 1532 }
1519 1533
(...skipping 961 matching lines...) Expand 10 before | Expand all | Expand 10 after
2481 // attributes while we are iterating. 2495 // attributes while we are iterating.
2482 WillBeHeapVector<RefPtrWillBeMember<Attr> > attrNodesCopy(*attrNodes); 2496 WillBeHeapVector<RefPtrWillBeMember<Attr> > attrNodesCopy(*attrNodes);
2483 for (size_t i = 0; i < attrNodesCopy.size(); ++i) 2497 for (size_t i = 0; i < attrNodesCopy.size(); ++i)
2484 attrNodesCopy[i]->normalize(); 2498 attrNodesCopy[i]->normalize();
2485 } 2499 }
2486 2500
2487 void Element::updatePseudoElement(PseudoId pseudoId, StyleRecalcChange change) 2501 void Element::updatePseudoElement(PseudoId pseudoId, StyleRecalcChange change)
2488 { 2502 {
2489 ASSERT(!needsStyleRecalc()); 2503 ASSERT(!needsStyleRecalc());
2490 PseudoElement* element = pseudoElement(pseudoId); 2504 PseudoElement* element = pseudoElement(pseudoId);
2505
2491 if (element && (change == UpdatePseudoElements || element->shouldCallRecalcS tyle(change))) { 2506 if (element && (change == UpdatePseudoElements || element->shouldCallRecalcS tyle(change))) {
2507 if (pseudoId == FIRST_LETTER && updateFirstLetter(element))
2508 return;
2492 2509
2493 // Need to clear the cached style if the PseudoElement wants a recalc so it 2510 // Need to clear the cached style if the PseudoElement wants a recalc so it
2494 // computes a new style. 2511 // computes a new style.
2495 if (element->needsStyleRecalc()) 2512 if (element->needsStyleRecalc())
2496 renderer()->style()->removeCachedPseudoStyle(pseudoId); 2513 renderer()->style()->removeCachedPseudoStyle(pseudoId);
2497 2514
2498 // PseudoElement styles hang off their parent element's style so if we n eeded 2515 // PseudoElement styles hang off their parent element's style so if we n eeded
2499 // a style recalc we should Force one on the pseudo. 2516 // a style recalc we should Force one on the pseudo.
2500 // FIXME: We should figure out the right text sibling to pass. 2517 // FIXME: We should figure out the right text sibling to pass.
2501 element->recalcStyle(change == UpdatePseudoElements ? Force : change); 2518 element->recalcStyle(change == UpdatePseudoElements ? Force : change);
2502 2519
2503 // Wait until our parent is not displayed or pseudoElementRendererIsNeed ed 2520 // Wait until our parent is not displayed or pseudoElementRendererIsNeed ed
2504 // is false, otherwise we could continously create and destroy PseudoEle ments 2521 // is false, otherwise we could continuously create and destroy PseudoEl ements
2505 // when RenderObject::isChildAllowed on our parent returns false for the 2522 // when RenderObject::isChildAllowed on our parent returns false for the
2506 // PseudoElement's renderer for each style recalc. 2523 // PseudoElement's renderer for each style recalc.
2507 if (!renderer() || !pseudoElementRendererIsNeeded(renderer()->getCachedP seudoStyle(pseudoId))) 2524 if (!renderer() || !pseudoElementRendererIsNeeded(renderer()->getCachedP seudoStyle(pseudoId)))
2508 elementRareData()->setPseudoElement(pseudoId, nullptr); 2525 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);
2509 } else if (change >= UpdatePseudoElements) { 2532 } else if (change >= UpdatePseudoElements) {
2510 createPseudoElementIfNeeded(pseudoId); 2533 createPseudoElementIfNeeded(pseudoId);
2511 } 2534 }
2512 } 2535 }
2513 2536
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
2514 void Element::createPseudoElementIfNeeded(PseudoId pseudoId) 2558 void Element::createPseudoElementIfNeeded(PseudoId pseudoId)
2515 { 2559 {
2516 if (isPseudoElement()) 2560 if (isPseudoElement())
2517 return; 2561 return;
2518 2562
2519 // Document::ensureStyleResolver is not inlined and shows up on profiles, av oid it here. 2563 // Document::ensureStyleResolver is not inlined and shows up on profiles, av oid it here.
2520 StyleEngine* engine = document().styleEngine(); 2564 StyleEngine* engine = document().styleEngine();
2521 RefPtrWillBeRawPtr<PseudoElement> element = engine->ensureResolver().createP seudoElementIfNeeded(*this, pseudoId); 2565 RefPtrWillBeRawPtr<PseudoElement> element = engine->ensureResolver().createP seudoElementIfNeeded(*this, pseudoId);
2522 if (!element) 2566 if (!element)
2523 return; 2567 return;
(...skipping 740 matching lines...) Expand 10 before | Expand all | Expand 10 after
3264 return wrapper; 3308 return wrapper;
3265 3309
3266 CustomElementBinding* binding = perContextData->customElementBinding(customE lementDefinition()); 3310 CustomElementBinding* binding = perContextData->customElementBinding(customE lementDefinition());
3267 3311
3268 wrapper->SetPrototype(binding->prototype()); 3312 wrapper->SetPrototype(binding->prototype());
3269 3313
3270 return V8DOMWrapper::associateObjectWithWrapperNonTemplate(this, wrapperType , wrapper, isolate); 3314 return V8DOMWrapper::associateObjectWithWrapperNonTemplate(this, wrapperType , wrapper, isolate);
3271 } 3315 }
3272 3316
3273 } // namespace blink 3317 } // 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