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

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

Issue 192293002: Use new is*Element() helper functions in DOM code (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 9 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
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 1313 matching lines...) Expand 10 before | Expand all | Expand 10 after
1324 return InsertionDone; 1324 return InsertionDone;
1325 1325
1326 const AtomicString& idValue = getIdAttribute(); 1326 const AtomicString& idValue = getIdAttribute();
1327 if (!idValue.isNull()) 1327 if (!idValue.isNull())
1328 updateId(scope, nullAtom, idValue); 1328 updateId(scope, nullAtom, idValue);
1329 1329
1330 const AtomicString& nameValue = getNameAttribute(); 1330 const AtomicString& nameValue = getNameAttribute();
1331 if (!nameValue.isNull()) 1331 if (!nameValue.isNull())
1332 updateName(nullAtom, nameValue); 1332 updateName(nullAtom, nameValue);
1333 1333
1334 if (hasTagName(labelTag)) { 1334 if (isHTMLLabelElement(*this)) {
1335 if (scope.shouldCacheLabelsByForAttribute()) 1335 if (scope.shouldCacheLabelsByForAttribute())
1336 updateLabel(scope, nullAtom, fastGetAttribute(forAttr)); 1336 updateLabel(scope, nullAtom, fastGetAttribute(forAttr));
1337 } 1337 }
1338 1338
1339 if (parentElement() && parentElement()->isInCanvasSubtree()) 1339 if (parentElement() && parentElement()->isInCanvasSubtree())
1340 setIsInCanvasSubtree(true); 1340 setIsInCanvasSubtree(true);
1341 1341
1342 return InsertionDone; 1342 return InsertionDone;
1343 } 1343 }
1344 1344
(...skipping 13 matching lines...) Expand all
1358 1358
1359 if (insertionPoint->isInTreeScope() && treeScope() == document()) { 1359 if (insertionPoint->isInTreeScope() && treeScope() == document()) {
1360 const AtomicString& idValue = getIdAttribute(); 1360 const AtomicString& idValue = getIdAttribute();
1361 if (!idValue.isNull()) 1361 if (!idValue.isNull())
1362 updateId(insertionPoint->treeScope(), idValue, nullAtom); 1362 updateId(insertionPoint->treeScope(), idValue, nullAtom);
1363 1363
1364 const AtomicString& nameValue = getNameAttribute(); 1364 const AtomicString& nameValue = getNameAttribute();
1365 if (!nameValue.isNull()) 1365 if (!nameValue.isNull())
1366 updateName(nameValue, nullAtom); 1366 updateName(nameValue, nullAtom);
1367 1367
1368 if (hasTagName(labelTag)) { 1368 if (isHTMLLabelElement(*this)) {
1369 TreeScope& treeScope = insertionPoint->treeScope(); 1369 TreeScope& treeScope = insertionPoint->treeScope();
1370 if (treeScope.shouldCacheLabelsByForAttribute()) 1370 if (treeScope.shouldCacheLabelsByForAttribute())
1371 updateLabel(treeScope, fastGetAttribute(forAttr), nullAtom); 1371 updateLabel(treeScope, fastGetAttribute(forAttr), nullAtom);
1372 } 1372 }
1373 } 1373 }
1374 1374
1375 ContainerNode::removedFrom(insertionPoint); 1375 ContainerNode::removedFrom(insertionPoint);
1376 if (wasInDocument) { 1376 if (wasInDocument) {
1377 if (hasPendingResources()) 1377 if (hasPendingResources())
1378 document().accessSVGExtensions().removeElementFromPendingResources(t his); 1378 document().accessSVGExtensions().removeElementFromPendingResources(t his);
(...skipping 875 matching lines...) Expand 10 before | Expand all | Expand 10 after
2254 2254
2255 String Element::outerHTML() const 2255 String Element::outerHTML() const
2256 { 2256 {
2257 return createMarkup(this); 2257 return createMarkup(this);
2258 } 2258 }
2259 2259
2260 void Element::setInnerHTML(const String& html, ExceptionState& exceptionState) 2260 void Element::setInnerHTML(const String& html, ExceptionState& exceptionState)
2261 { 2261 {
2262 if (RefPtr<DocumentFragment> fragment = createFragmentForInnerOuterHTML(html , this, AllowScriptingContent, "innerHTML", exceptionState)) { 2262 if (RefPtr<DocumentFragment> fragment = createFragmentForInnerOuterHTML(html , this, AllowScriptingContent, "innerHTML", exceptionState)) {
2263 ContainerNode* container = this; 2263 ContainerNode* container = this;
2264 if (hasTagName(templateTag)) 2264 if (isHTMLTemplateElement(*this))
2265 container = toHTMLTemplateElement(this)->content(); 2265 container = toHTMLTemplateElement(this)->content();
2266 replaceChildrenWithFragment(container, fragment.release(), exceptionStat e); 2266 replaceChildrenWithFragment(container, fragment.release(), exceptionStat e);
2267 } 2267 }
2268 } 2268 }
2269 2269
2270 void Element::setOuterHTML(const String& html, ExceptionState& exceptionState) 2270 void Element::setOuterHTML(const String& html, ExceptionState& exceptionState)
2271 { 2271 {
2272 Node* p = parentNode(); 2272 Node* p = parentNode();
2273 if (!p) { 2273 if (!p) {
2274 exceptionState.throwDOMException(NoModificationAllowedError, "This eleme nt has no parent node."); 2274 exceptionState.throwDOMException(NoModificationAllowedError, "This eleme nt has no parent node.");
(...skipping 705 matching lines...) Expand 10 before | Expand all | Expand 10 after
2980 scope.removeElementById(oldId, this); 2980 scope.removeElementById(oldId, this);
2981 if (!newId.isEmpty()) 2981 if (!newId.isEmpty())
2982 scope.addElementById(newId, this); 2982 scope.addElementById(newId, this);
2983 2983
2984 if (shouldRegisterAsExtraNamedItem()) 2984 if (shouldRegisterAsExtraNamedItem())
2985 updateExtraNamedItemRegistration(oldId, newId); 2985 updateExtraNamedItemRegistration(oldId, newId);
2986 } 2986 }
2987 2987
2988 void Element::updateLabel(TreeScope& scope, const AtomicString& oldForAttributeV alue, const AtomicString& newForAttributeValue) 2988 void Element::updateLabel(TreeScope& scope, const AtomicString& oldForAttributeV alue, const AtomicString& newForAttributeValue)
2989 { 2989 {
2990 ASSERT(hasTagName(labelTag)); 2990 ASSERT(isHTMLLabelElement(this));
adamk 2014/03/10 18:23:24 Why do you sometimes use "*this" and sometimes "th
adamk 2014/03/11 21:40:26 Still curious for an answer to this (maybe for ASS
2991 2991
2992 if (!inDocument()) 2992 if (!inDocument())
2993 return; 2993 return;
2994 2994
2995 if (oldForAttributeValue == newForAttributeValue) 2995 if (oldForAttributeValue == newForAttributeValue)
2996 return; 2996 return;
2997 2997
2998 if (!oldForAttributeValue.isEmpty()) 2998 if (!oldForAttributeValue.isEmpty())
2999 scope.removeLabel(oldForAttributeValue, toHTMLLabelElement(this)); 2999 scope.removeLabel(oldForAttributeValue, toHTMLLabelElement(this));
3000 if (!newForAttributeValue.isEmpty()) 3000 if (!newForAttributeValue.isEmpty())
3001 scope.addLabel(newForAttributeValue, toHTMLLabelElement(this)); 3001 scope.addLabel(newForAttributeValue, toHTMLLabelElement(this));
3002 } 3002 }
3003 3003
3004 static bool hasSelectorForAttribute(Document* document, const AtomicString& loca lName) 3004 static bool hasSelectorForAttribute(Document* document, const AtomicString& loca lName)
3005 { 3005 {
3006 return document->ensureStyleResolver().ensureRuleFeatureSet().hasSelectorFor Attribute(localName); 3006 return document->ensureStyleResolver().ensureRuleFeatureSet().hasSelectorFor Attribute(localName);
3007 } 3007 }
3008 3008
3009 void Element::willModifyAttribute(const QualifiedName& name, const AtomicString& oldValue, const AtomicString& newValue) 3009 void Element::willModifyAttribute(const QualifiedName& name, const AtomicString& oldValue, const AtomicString& newValue)
3010 { 3010 {
3011 if (isIdAttributeName(name)) 3011 if (isIdAttributeName(name)) {
3012 updateId(oldValue, newValue); 3012 updateId(oldValue, newValue);
3013 else if (name == HTMLNames::nameAttr) 3013 } else if (name == HTMLNames::nameAttr) {
3014 updateName(oldValue, newValue); 3014 updateName(oldValue, newValue);
3015 else if (name == HTMLNames::forAttr && hasTagName(labelTag)) { 3015 } else if (name == HTMLNames::forAttr && isHTMLLabelElement(*this)) {
3016 TreeScope& scope = treeScope(); 3016 TreeScope& scope = treeScope();
3017 if (scope.shouldCacheLabelsByForAttribute()) 3017 if (scope.shouldCacheLabelsByForAttribute())
3018 updateLabel(scope, oldValue, newValue); 3018 updateLabel(scope, oldValue, newValue);
3019 } 3019 }
3020 3020
3021 if (oldValue != newValue) { 3021 if (oldValue != newValue) {
3022 if (inActiveDocument() && hasSelectorForAttribute(&document(), name.loca lName())) 3022 if (inActiveDocument() && hasSelectorForAttribute(&document(), name.loca lName()))
3023 setNeedsStyleRecalc(SubtreeStyleChange); 3023 setNeedsStyleRecalc(SubtreeStyleChange);
3024 3024
3025 if (isUpgradedCustomElement()) 3025 if (isUpgradedCustomElement())
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
3121 if (!newId.isEmpty()) 3121 if (!newId.isEmpty())
3122 toHTMLDocument(document()).addExtraNamedItem(newId); 3122 toHTMLDocument(document()).addExtraNamedItem(newId);
3123 } 3123 }
3124 3124
3125 PassRefPtr<HTMLCollection> Element::ensureCachedHTMLCollection(CollectionType ty pe) 3125 PassRefPtr<HTMLCollection> Element::ensureCachedHTMLCollection(CollectionType ty pe)
3126 { 3126 {
3127 if (HTMLCollection* collection = cachedHTMLCollection(type)) 3127 if (HTMLCollection* collection = cachedHTMLCollection(type))
3128 return collection; 3128 return collection;
3129 3129
3130 if (type == TableRows) { 3130 if (type == TableRows) {
3131 ASSERT(hasTagName(tableTag)); 3131 ASSERT(isHTMLTableElement(this));
3132 return ensureRareData().ensureNodeLists().addCache<HTMLTableRowsCollecti on>(*this, type); 3132 return ensureRareData().ensureNodeLists().addCache<HTMLTableRowsCollecti on>(*this, type);
3133 } else if (type == SelectOptions) { 3133 } else if (type == SelectOptions) {
3134 ASSERT(hasTagName(selectTag)); 3134 ASSERT(isHTMLSelectElement(this));
3135 return ensureRareData().ensureNodeLists().addCache<HTMLOptionsCollection >(*this, type); 3135 return ensureRareData().ensureNodeLists().addCache<HTMLOptionsCollection >(*this, type);
3136 } else if (type == FormControls) { 3136 } else if (type == FormControls) {
3137 ASSERT(hasTagName(formTag) || hasTagName(fieldsetTag)); 3137 ASSERT(isHTMLFormElement(this) || isHTMLFieldSetElement(this));
3138 return ensureRareData().ensureNodeLists().addCache<HTMLFormControlsColle ction>(*this, type); 3138 return ensureRareData().ensureNodeLists().addCache<HTMLFormControlsColle ction>(*this, type);
3139 } 3139 }
3140 return ensureRareData().ensureNodeLists().addCache<HTMLCollection>(*this, ty pe); 3140 return ensureRareData().ensureNodeLists().addCache<HTMLCollection>(*this, ty pe);
3141 } 3141 }
3142 3142
3143 static void scheduleLayerUpdateCallback(Node* node) 3143 static void scheduleLayerUpdateCallback(Node* node)
3144 { 3144 {
3145 // Notify the renderer even is the styles are identical since it may need to 3145 // Notify the renderer even is the styles are identical since it may need to
3146 // create or destroy a RenderLayer. 3146 // create or destroy a RenderLayer.
3147 node->setNeedsStyleRecalc(LocalStyleChange, StyleChangeFromRenderer); 3147 node->setNeedsStyleRecalc(LocalStyleChange, StyleChangeFromRenderer);
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after
3522 return false; 3522 return false;
3523 if (this == document().cssTarget()) 3523 if (this == document().cssTarget())
3524 return false; 3524 return false;
3525 if (isHTMLElement() && toHTMLElement(this)->hasDirectionAuto()) 3525 if (isHTMLElement() && toHTMLElement(this)->hasDirectionAuto())
3526 return false; 3526 return false;
3527 if (hasActiveAnimations()) 3527 if (hasActiveAnimations())
3528 return false; 3528 return false;
3529 // Turn off style sharing for elements that can gain layers for reasons outs ide of the style system. 3529 // Turn off style sharing for elements that can gain layers for reasons outs ide of the style system.
3530 // See comments in RenderObject::setStyle(). 3530 // See comments in RenderObject::setStyle().
3531 // FIXME: Why does gaining a layer from outside the style system require dis abling sharing? 3531 // FIXME: Why does gaining a layer from outside the style system require dis abling sharing?
3532 if (hasTagName(iframeTag) 3532 if (isHTMLIFrameElement(*this)
3533 || hasTagName(frameTag) 3533 || isHTMLFrameElement(*this)
3534 || hasTagName(embedTag) 3534 || isHTMLEmbedElement(*this)
3535 || hasTagName(objectTag) 3535 || isHTMLObjectElement(*this)
3536 || hasTagName(appletTag) 3536 || isHTMLAppletElement(*this)
3537 || hasTagName(canvasTag)) 3537 || isHTMLCanvasElement(*this))
3538 return false; 3538 return false;
3539 // FIXME: We should share style for option and optgroup whenever possible. 3539 // FIXME: We should share style for option and optgroup whenever possible.
3540 // Before doing so, we need to resolve issues in HTMLSelectElement::recalcLi stItems 3540 // Before doing so, we need to resolve issues in HTMLSelectElement::recalcLi stItems
3541 // and RenderMenuList::setText. See also https://bugs.webkit.org/show_bug.cg i?id=88405 3541 // and RenderMenuList::setText. See also https://bugs.webkit.org/show_bug.cg i?id=88405
3542 if (hasTagName(optionTag) || hasTagName(optgroupTag)) 3542 if (isHTMLOptionElement(*this) || isHTMLOptGroupElement(*this))
3543 return false; 3543 return false;
3544 if (FullscreenElementStack::isActiveFullScreenElement(this)) 3544 if (FullscreenElementStack::isActiveFullScreenElement(this))
3545 return false; 3545 return false;
3546 return true; 3546 return true;
3547 } 3547 }
3548 3548
3549 } // namespace WebCore 3549 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698