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

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

Issue 23890025: WIP (Introduce WTF::NonNullPtr<T>.) (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 3 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/EventContext.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 1219 matching lines...) Expand 10 before | Expand all | Expand 10 after
1230 1230
1231 if (!insertionPoint->isInTreeScope()) 1231 if (!insertionPoint->isInTreeScope())
1232 return InsertionDone; 1232 return InsertionDone;
1233 1233
1234 if (hasRareData()) 1234 if (hasRareData())
1235 elementRareData()->clearClassListValueForQuirksMode(); 1235 elementRareData()->clearClassListValueForQuirksMode();
1236 1236
1237 if (isUpgradedCustomElement() && inDocument()) 1237 if (isUpgradedCustomElement() && inDocument())
1238 CustomElement::didEnterDocument(this, document()); 1238 CustomElement::didEnterDocument(this, document());
1239 1239
1240 TreeScope& scope = insertionPoint->treeScope(); 1240 NonNullPtr<TreeScope> scope = insertionPoint->treeScope();
1241 if (&scope != &treeScope()) 1241 if (scope != treeScope())
1242 return InsertionDone; 1242 return InsertionDone;
1243 1243
1244 const AtomicString& idValue = getIdAttribute(); 1244 const AtomicString& idValue = getIdAttribute();
1245 if (!idValue.isNull()) 1245 if (!idValue.isNull())
1246 updateId(scope, nullAtom, idValue); 1246 updateId(scope, nullAtom, idValue);
1247 1247
1248 const AtomicString& nameValue = getNameAttribute(); 1248 const AtomicString& nameValue = getNameAttribute();
1249 if (!nameValue.isNull()) 1249 if (!nameValue.isNull())
1250 updateName(nullAtom, nameValue); 1250 updateName(nullAtom, nameValue);
1251 1251
1252 if (hasTagName(labelTag)) { 1252 if (hasTagName(labelTag)) {
1253 if (scope.shouldCacheLabelsByForAttribute()) 1253 if (scope->shouldCacheLabelsByForAttribute())
1254 updateLabel(scope, nullAtom, fastGetAttribute(forAttr)); 1254 updateLabel(scope, nullAtom, fastGetAttribute(forAttr));
1255 } 1255 }
1256 1256
1257 if (parentElement() && parentElement()->isInCanvasSubtree()) 1257 if (parentElement() && parentElement()->isInCanvasSubtree())
1258 setIsInCanvasSubtree(true); 1258 setIsInCanvasSubtree(true);
1259 1259
1260 return InsertionDone; 1260 return InsertionDone;
1261 } 1261 }
1262 1262
1263 void Element::removedFrom(ContainerNode* insertionPoint) 1263 void Element::removedFrom(ContainerNode* insertionPoint)
(...skipping 11 matching lines...) Expand all
1275 document().removeFromTopLayer(this); 1275 document().removeFromTopLayer(this);
1276 1276
1277 if (containsFullScreenElement()) 1277 if (containsFullScreenElement())
1278 setContainsFullScreenElementOnAncestorsCrossingFrameBoundaries(false); 1278 setContainsFullScreenElementOnAncestorsCrossingFrameBoundaries(false);
1279 1279
1280 if (document().page()) 1280 if (document().page())
1281 document().page()->pointerLockController().elementRemoved(this); 1281 document().page()->pointerLockController().elementRemoved(this);
1282 1282
1283 setSavedLayerScrollOffset(IntSize()); 1283 setSavedLayerScrollOffset(IntSize());
1284 1284
1285 if (insertionPoint->isInTreeScope() && &treeScope() == &document()) { 1285 if (insertionPoint->isInTreeScope() && treeScope() == &document()) {
1286 const AtomicString& idValue = getIdAttribute(); 1286 const AtomicString& idValue = getIdAttribute();
1287 if (!idValue.isNull()) 1287 if (!idValue.isNull())
1288 updateId(insertionPoint->treeScope(), idValue, nullAtom); 1288 updateId(insertionPoint->treeScope(), idValue, nullAtom);
1289 1289
1290 const AtomicString& nameValue = getNameAttribute(); 1290 const AtomicString& nameValue = getNameAttribute();
1291 if (!nameValue.isNull()) 1291 if (!nameValue.isNull())
1292 updateName(nameValue, nullAtom); 1292 updateName(nameValue, nullAtom);
1293 1293
1294 if (hasTagName(labelTag)) { 1294 if (hasTagName(labelTag)) {
1295 TreeScope& treeScope = insertionPoint->treeScope(); 1295 NonNullPtr<TreeScope> treeScope = insertionPoint->treeScope();
1296 if (treeScope.shouldCacheLabelsByForAttribute()) 1296 if (treeScope->shouldCacheLabelsByForAttribute())
1297 updateLabel(treeScope, fastGetAttribute(forAttr), nullAtom); 1297 updateLabel(treeScope, fastGetAttribute(forAttr), nullAtom);
1298 } 1298 }
1299 } 1299 }
1300 1300
1301 ContainerNode::removedFrom(insertionPoint); 1301 ContainerNode::removedFrom(insertionPoint);
1302 if (wasInDocument) { 1302 if (wasInDocument) {
1303 if (hasPendingResources()) 1303 if (hasPendingResources())
1304 document().accessSVGExtensions()->removeElementFromPendingResources( this); 1304 document().accessSVGExtensions()->removeElementFromPendingResources( this);
1305 1305
1306 if (isUpgradedCustomElement()) 1306 if (isUpgradedCustomElement())
(...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after
1836 if (index != notFound) { 1836 if (index != notFound) {
1837 if (oldAttrNode) 1837 if (oldAttrNode)
1838 detachAttrNodeFromElementWithValue(oldAttrNode.get(), elementData->a ttributeItem(index)->value()); 1838 detachAttrNodeFromElementWithValue(oldAttrNode.get(), elementData->a ttributeItem(index)->value());
1839 else 1839 else
1840 oldAttrNode = Attr::create(document(), attrNode->qualifiedName(), el ementData->attributeItem(index)->value()); 1840 oldAttrNode = Attr::create(document(), attrNode->qualifiedName(), el ementData->attributeItem(index)->value());
1841 } 1841 }
1842 1842
1843 setAttributeInternal(index, attrNode->qualifiedName(), attrNode->value(), No tInSynchronizationOfLazyAttribute); 1843 setAttributeInternal(index, attrNode->qualifiedName(), attrNode->value(), No tInSynchronizationOfLazyAttribute);
1844 1844
1845 attrNode->attachToElement(this); 1845 attrNode->attachToElement(this);
1846 treeScope().adoptIfNeeded(attrNode); 1846 treeScope()->adoptIfNeeded(attrNode);
1847 ensureAttrNodeListForElement(this)->append(attrNode); 1847 ensureAttrNodeListForElement(this)->append(attrNode);
1848 1848
1849 return oldAttrNode.release(); 1849 return oldAttrNode.release();
1850 } 1850 }
1851 1851
1852 PassRefPtr<Attr> Element::setAttributeNodeNS(Attr* attr, ExceptionState& es) 1852 PassRefPtr<Attr> Element::setAttributeNodeNS(Attr* attr, ExceptionState& es)
1853 { 1853 {
1854 return setAttributeNode(attr, es); 1854 return setAttributeNode(attr, es);
1855 } 1855 }
1856 1856
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
2060 frame->selection().setSelection(newSelection); 2060 frame->selection().setSelection(newSelection);
2061 frame->selection().revealSelection(); 2061 frame->selection().revealSelection();
2062 } 2062 }
2063 } else if (renderer() && !renderer()->isWidget()) 2063 } else if (renderer() && !renderer()->isWidget())
2064 renderer()->scrollRectToVisible(boundingBox()); 2064 renderer()->scrollRectToVisible(boundingBox());
2065 } 2065 }
2066 2066
2067 void Element::blur() 2067 void Element::blur()
2068 { 2068 {
2069 cancelFocusAppearanceUpdate(); 2069 cancelFocusAppearanceUpdate();
2070 if (treeScope().adjustedFocusedElement() == this) { 2070 if (treeScope()->adjustedFocusedElement() == this) {
2071 Document& doc = document(); 2071 Document& doc = document();
2072 if (doc.page()) 2072 if (doc.page())
2073 doc.page()->focusController().setFocusedElement(0, doc.frame()); 2073 doc.page()->focusController().setFocusedElement(0, doc.frame());
2074 else 2074 else
2075 doc.setFocusedElement(0); 2075 doc.setFocusedElement(0);
2076 } 2076 }
2077 } 2077 }
2078 2078
2079 bool Element::isFocusable() const 2079 bool Element::isFocusable() const
2080 { 2080 {
(...skipping 686 matching lines...) Expand 10 before | Expand all | Expand 10 after
2767 { 2767 {
2768 if (!isInTreeScope()) 2768 if (!isInTreeScope())
2769 return; 2769 return;
2770 2770
2771 if (oldId == newId) 2771 if (oldId == newId)
2772 return; 2772 return;
2773 2773
2774 updateId(treeScope(), oldId, newId); 2774 updateId(treeScope(), oldId, newId);
2775 } 2775 }
2776 2776
2777 inline void Element::updateId(TreeScope& scope, const AtomicString& oldId, const AtomicString& newId) 2777 inline void Element::updateId(NonNullPtr<TreeScope> scope, const AtomicString& o ldId, const AtomicString& newId)
2778 { 2778 {
2779 ASSERT(isInTreeScope()); 2779 ASSERT(isInTreeScope());
2780 ASSERT(oldId != newId); 2780 ASSERT(oldId != newId);
2781 2781
2782 if (!oldId.isEmpty()) 2782 if (!oldId.isEmpty())
2783 scope.removeElementById(oldId, this); 2783 scope->removeElementById(oldId, this);
2784 if (!newId.isEmpty()) 2784 if (!newId.isEmpty())
2785 scope.addElementById(newId, this); 2785 scope->addElementById(newId, this);
2786 2786
2787 if (shouldRegisterAsExtraNamedItem()) 2787 if (shouldRegisterAsExtraNamedItem())
2788 updateExtraNamedItemRegistration(oldId, newId); 2788 updateExtraNamedItemRegistration(oldId, newId);
2789 } 2789 }
2790 2790
2791 void Element::updateLabel(TreeScope& scope, const AtomicString& oldForAttributeV alue, const AtomicString& newForAttributeValue) 2791 void Element::updateLabel(NonNullPtr<TreeScope> scope, const AtomicString& oldFo rAttributeValue, const AtomicString& newForAttributeValue)
2792 { 2792 {
2793 ASSERT(hasTagName(labelTag)); 2793 ASSERT(hasTagName(labelTag));
2794 2794
2795 if (!inDocument()) 2795 if (!inDocument())
2796 return; 2796 return;
2797 2797
2798 if (oldForAttributeValue == newForAttributeValue) 2798 if (oldForAttributeValue == newForAttributeValue)
2799 return; 2799 return;
2800 2800
2801 if (!oldForAttributeValue.isEmpty()) 2801 if (!oldForAttributeValue.isEmpty())
2802 scope.removeLabel(oldForAttributeValue, toHTMLLabelElement(this)); 2802 scope->removeLabel(oldForAttributeValue, toHTMLLabelElement(this));
2803 if (!newForAttributeValue.isEmpty()) 2803 if (!newForAttributeValue.isEmpty())
2804 scope.addLabel(newForAttributeValue, toHTMLLabelElement(this)); 2804 scope->addLabel(newForAttributeValue, toHTMLLabelElement(this));
2805 } 2805 }
2806 2806
2807 static bool hasSelectorForAttribute(Document* document, const AtomicString& loca lName) 2807 static bool hasSelectorForAttribute(Document* document, const AtomicString& loca lName)
2808 { 2808 {
2809 return document->styleResolver() && document->styleResolver()->ruleFeatureSe t().hasSelectorForAttribute(localName); 2809 return document->styleResolver() && document->styleResolver()->ruleFeatureSe t().hasSelectorForAttribute(localName);
2810 } 2810 }
2811 2811
2812 void Element::willModifyAttribute(const QualifiedName& name, const AtomicString& oldValue, const AtomicString& newValue) 2812 void Element::willModifyAttribute(const QualifiedName& name, const AtomicString& oldValue, const AtomicString& newValue)
2813 { 2813 {
2814 if (isIdAttributeName(name)) 2814 if (isIdAttributeName(name))
2815 updateId(oldValue, newValue); 2815 updateId(oldValue, newValue);
2816 else if (name == HTMLNames::nameAttr) 2816 else if (name == HTMLNames::nameAttr)
2817 updateName(oldValue, newValue); 2817 updateName(oldValue, newValue);
2818 else if (name == HTMLNames::forAttr && hasTagName(labelTag)) { 2818 else if (name == HTMLNames::forAttr && hasTagName(labelTag)) {
2819 TreeScope& scope = treeScope(); 2819 NonNullPtr<TreeScope> scope = treeScope();
2820 if (scope.shouldCacheLabelsByForAttribute()) 2820 if (scope->shouldCacheLabelsByForAttribute())
2821 updateLabel(scope, oldValue, newValue); 2821 updateLabel(scope, oldValue, newValue);
2822 } 2822 }
2823 2823
2824 if (oldValue != newValue) { 2824 if (oldValue != newValue) {
2825 if (attached() && hasSelectorForAttribute(&document(), name.localName()) ) 2825 if (attached() && hasSelectorForAttribute(&document(), name.localName()) )
2826 setNeedsStyleRecalc(); 2826 setNeedsStyleRecalc();
2827 2827
2828 if (isUpgradedCustomElement()) 2828 if (isUpgradedCustomElement())
2829 CustomElement::attributeDidChange(this, name.localName(), oldValue, newValue); 2829 CustomElement::attributeDidChange(this, name.localName(), oldValue, newValue);
2830 } 2830 }
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
2952 return findAttrNodeInList(attrNodeList, name); 2952 return findAttrNodeInList(attrNodeList, name);
2953 return 0; 2953 return 0;
2954 } 2954 }
2955 2955
2956 PassRefPtr<Attr> Element::ensureAttr(const QualifiedName& name) 2956 PassRefPtr<Attr> Element::ensureAttr(const QualifiedName& name)
2957 { 2957 {
2958 AttrNodeList* attrNodeList = ensureAttrNodeListForElement(this); 2958 AttrNodeList* attrNodeList = ensureAttrNodeListForElement(this);
2959 RefPtr<Attr> attrNode = findAttrNodeInList(attrNodeList, name); 2959 RefPtr<Attr> attrNode = findAttrNodeInList(attrNodeList, name);
2960 if (!attrNode) { 2960 if (!attrNode) {
2961 attrNode = Attr::create(*this, name); 2961 attrNode = Attr::create(*this, name);
2962 treeScope().adoptIfNeeded(attrNode.get()); 2962 treeScope()->adoptIfNeeded(attrNode.get());
2963 attrNodeList->append(attrNode); 2963 attrNodeList->append(attrNode);
2964 } 2964 }
2965 return attrNode.release(); 2965 return attrNode.release();
2966 } 2966 }
2967 2967
2968 void Element::detachAttrNodeFromElementWithValue(Attr* attrNode, const AtomicStr ing& value) 2968 void Element::detachAttrNodeFromElementWithValue(Attr* attrNode, const AtomicStr ing& value)
2969 { 2969 {
2970 ASSERT(hasSyntheticAttrChildNodes()); 2970 ASSERT(hasSyntheticAttrChildNodes());
2971 attrNode->detachFromElementWithValue(value); 2971 attrNode->detachFromElementWithValue(value);
2972 2972
(...skipping 660 matching lines...) Expand 10 before | Expand all | Expand 10 after
3633 return 0; 3633 return 0;
3634 } 3634 }
3635 3635
3636 Attribute* UniqueElementData::attributeItem(unsigned index) 3636 Attribute* UniqueElementData::attributeItem(unsigned index)
3637 { 3637 {
3638 ASSERT_WITH_SECURITY_IMPLICATION(index < length()); 3638 ASSERT_WITH_SECURITY_IMPLICATION(index < length());
3639 return &m_attributeVector.at(index); 3639 return &m_attributeVector.at(index);
3640 } 3640 }
3641 3641
3642 } // namespace WebCore 3642 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/dom/Element.h ('k') | Source/core/dom/EventContext.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698