| OLD | NEW |
| 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 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 detachAttrNodeFromElementWithValue(attr, attribute->value()); | 354 detachAttrNodeFromElementWithValue(attr, attribute->value()); |
| 355 removeAttributeInternal(index, NotInSynchronizationOfLazyAttribute); | 355 removeAttributeInternal(index, NotInSynchronizationOfLazyAttribute); |
| 356 } | 356 } |
| 357 | 357 |
| 358 void Element::removeAttribute(const QualifiedName& name) | 358 void Element::removeAttribute(const QualifiedName& name) |
| 359 { | 359 { |
| 360 if (!elementData()) | 360 if (!elementData()) |
| 361 return; | 361 return; |
| 362 | 362 |
| 363 size_t index = elementData()->getAttributeItemIndex(name); | 363 size_t index = elementData()->getAttributeItemIndex(name); |
| 364 if (index == notFound) | 364 if (index == kNotFound) |
| 365 return; | 365 return; |
| 366 | 366 |
| 367 removeAttributeInternal(index, NotInSynchronizationOfLazyAttribute); | 367 removeAttributeInternal(index, NotInSynchronizationOfLazyAttribute); |
| 368 } | 368 } |
| 369 | 369 |
| 370 void Element::setBooleanAttribute(const QualifiedName& name, bool value) | 370 void Element::setBooleanAttribute(const QualifiedName& name, bool value) |
| 371 { | 371 { |
| 372 if (value) | 372 if (value) |
| 373 setAttribute(name, emptyAtom); | 373 setAttribute(name, emptyAtom); |
| 374 else | 374 else |
| (...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 831 void Element::setAttribute(const AtomicString& localName, const AtomicString& va
lue, ExceptionState& es) | 831 void Element::setAttribute(const AtomicString& localName, const AtomicString& va
lue, ExceptionState& es) |
| 832 { | 832 { |
| 833 if (!Document::isValidName(localName)) { | 833 if (!Document::isValidName(localName)) { |
| 834 es.throwDOMException(InvalidCharacterError); | 834 es.throwDOMException(InvalidCharacterError); |
| 835 return; | 835 return; |
| 836 } | 836 } |
| 837 | 837 |
| 838 synchronizeAttribute(localName); | 838 synchronizeAttribute(localName); |
| 839 const AtomicString& caseAdjustedLocalName = shouldIgnoreAttributeCase(this)
? localName.lower() : localName; | 839 const AtomicString& caseAdjustedLocalName = shouldIgnoreAttributeCase(this)
? localName.lower() : localName; |
| 840 | 840 |
| 841 size_t index = elementData() ? elementData()->getAttributeItemIndex(caseAdju
stedLocalName, false) : notFound; | 841 size_t index = elementData() ? elementData()->getAttributeItemIndex(caseAdju
stedLocalName, false) : kNotFound; |
| 842 const QualifiedName& qName = index != notFound ? attributeItem(index)->name(
) : QualifiedName(nullAtom, caseAdjustedLocalName, nullAtom); | 842 const QualifiedName& qName = index != kNotFound ? attributeItem(index)->name
() : QualifiedName(nullAtom, caseAdjustedLocalName, nullAtom); |
| 843 setAttributeInternal(index, qName, value, NotInSynchronizationOfLazyAttribut
e); | 843 setAttributeInternal(index, qName, value, NotInSynchronizationOfLazyAttribut
e); |
| 844 } | 844 } |
| 845 | 845 |
| 846 void Element::setAttribute(const QualifiedName& name, const AtomicString& value) | 846 void Element::setAttribute(const QualifiedName& name, const AtomicString& value) |
| 847 { | 847 { |
| 848 synchronizeAttribute(name); | 848 synchronizeAttribute(name); |
| 849 size_t index = elementData() ? elementData()->getAttributeItemIndex(name) :
notFound; | 849 size_t index = elementData() ? elementData()->getAttributeItemIndex(name) :
kNotFound; |
| 850 setAttributeInternal(index, name, value, NotInSynchronizationOfLazyAttribute
); | 850 setAttributeInternal(index, name, value, NotInSynchronizationOfLazyAttribute
); |
| 851 } | 851 } |
| 852 | 852 |
| 853 void Element::setSynchronizedLazyAttribute(const QualifiedName& name, const Atom
icString& value) | 853 void Element::setSynchronizedLazyAttribute(const QualifiedName& name, const Atom
icString& value) |
| 854 { | 854 { |
| 855 size_t index = elementData() ? elementData()->getAttributeItemIndex(name) :
notFound; | 855 size_t index = elementData() ? elementData()->getAttributeItemIndex(name) :
kNotFound; |
| 856 setAttributeInternal(index, name, value, InSynchronizationOfLazyAttribute); | 856 setAttributeInternal(index, name, value, InSynchronizationOfLazyAttribute); |
| 857 } | 857 } |
| 858 | 858 |
| 859 inline void Element::setAttributeInternal(size_t index, const QualifiedName& nam
e, const AtomicString& newValue, SynchronizationOfLazyAttribute inSynchronizatio
nOfLazyAttribute) | 859 inline void Element::setAttributeInternal(size_t index, const QualifiedName& nam
e, const AtomicString& newValue, SynchronizationOfLazyAttribute inSynchronizatio
nOfLazyAttribute) |
| 860 { | 860 { |
| 861 if (newValue.isNull()) { | 861 if (newValue.isNull()) { |
| 862 if (index != notFound) | 862 if (index != kNotFound) |
| 863 removeAttributeInternal(index, inSynchronizationOfLazyAttribute); | 863 removeAttributeInternal(index, inSynchronizationOfLazyAttribute); |
| 864 return; | 864 return; |
| 865 } | 865 } |
| 866 | 866 |
| 867 if (index == notFound) { | 867 if (index == kNotFound) { |
| 868 addAttributeInternal(name, newValue, inSynchronizationOfLazyAttribute); | 868 addAttributeInternal(name, newValue, inSynchronizationOfLazyAttribute); |
| 869 return; | 869 return; |
| 870 } | 870 } |
| 871 | 871 |
| 872 QualifiedName existingAttributeName = attributeItem(index)->name(); | 872 QualifiedName existingAttributeName = attributeItem(index)->name(); |
| 873 | 873 |
| 874 if (!inSynchronizationOfLazyAttribute) | 874 if (!inSynchronizationOfLazyAttribute) |
| 875 willModifyAttribute(existingAttributeName, attributeItem(index)->value()
, newValue); | 875 willModifyAttribute(existingAttributeName, attributeItem(index)->value()
, newValue); |
| 876 | 876 |
| 877 if (newValue != attributeItem(index)->value()) { | 877 if (newValue != attributeItem(index)->value()) { |
| (...skipping 948 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1826 // The DOM user must explicitly clone Attr nodes to re-use them in other ele
ments. | 1826 // The DOM user must explicitly clone Attr nodes to re-use them in other ele
ments. |
| 1827 if (attrNode->ownerElement()) { | 1827 if (attrNode->ownerElement()) { |
| 1828 es.throwDOMException(InUseAttributeError); | 1828 es.throwDOMException(InUseAttributeError); |
| 1829 return 0; | 1829 return 0; |
| 1830 } | 1830 } |
| 1831 | 1831 |
| 1832 synchronizeAllAttributes(); | 1832 synchronizeAllAttributes(); |
| 1833 UniqueElementData* elementData = ensureUniqueElementData(); | 1833 UniqueElementData* elementData = ensureUniqueElementData(); |
| 1834 | 1834 |
| 1835 size_t index = elementData->getAttributeItemIndex(attrNode->qualifiedName(),
shouldIgnoreAttributeCase(this)); | 1835 size_t index = elementData->getAttributeItemIndex(attrNode->qualifiedName(),
shouldIgnoreAttributeCase(this)); |
| 1836 if (index != notFound) { | 1836 if (index != kNotFound) { |
| 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); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1863 if (attr->ownerElement() != this) { | 1863 if (attr->ownerElement() != this) { |
| 1864 es.throwDOMException(NotFoundError); | 1864 es.throwDOMException(NotFoundError); |
| 1865 return 0; | 1865 return 0; |
| 1866 } | 1866 } |
| 1867 | 1867 |
| 1868 ASSERT(&document() == &attr->document()); | 1868 ASSERT(&document() == &attr->document()); |
| 1869 | 1869 |
| 1870 synchronizeAttribute(attr->qualifiedName()); | 1870 synchronizeAttribute(attr->qualifiedName()); |
| 1871 | 1871 |
| 1872 size_t index = elementData()->getAttrIndex(attr); | 1872 size_t index = elementData()->getAttrIndex(attr); |
| 1873 if (index == notFound) { | 1873 if (index == kNotFound) { |
| 1874 es.throwDOMException(NotFoundError); | 1874 es.throwDOMException(NotFoundError); |
| 1875 return 0; | 1875 return 0; |
| 1876 } | 1876 } |
| 1877 | 1877 |
| 1878 RefPtr<Attr> guard(attr); | 1878 RefPtr<Attr> guard(attr); |
| 1879 detachAttrNodeAtIndex(attr, index); | 1879 detachAttrNodeAtIndex(attr, index); |
| 1880 return guard.release(); | 1880 return guard.release(); |
| 1881 } | 1881 } |
| 1882 | 1882 |
| 1883 bool Element::parseAttributeName(QualifiedName& out, const AtomicString& namespa
ceURI, const AtomicString& qualifiedName, ExceptionState& es) | 1883 bool Element::parseAttributeName(QualifiedName& out, const AtomicString& namespa
ceURI, const AtomicString& qualifiedName, ExceptionState& es) |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1938 didAddAttribute(name, value); | 1938 didAddAttribute(name, value); |
| 1939 } | 1939 } |
| 1940 | 1940 |
| 1941 void Element::removeAttribute(const AtomicString& name) | 1941 void Element::removeAttribute(const AtomicString& name) |
| 1942 { | 1942 { |
| 1943 if (!elementData()) | 1943 if (!elementData()) |
| 1944 return; | 1944 return; |
| 1945 | 1945 |
| 1946 AtomicString localName = shouldIgnoreAttributeCase(this) ? name.lower() : na
me; | 1946 AtomicString localName = shouldIgnoreAttributeCase(this) ? name.lower() : na
me; |
| 1947 size_t index = elementData()->getAttributeItemIndex(localName, false); | 1947 size_t index = elementData()->getAttributeItemIndex(localName, false); |
| 1948 if (index == notFound) { | 1948 if (index == kNotFound) { |
| 1949 if (UNLIKELY(localName == styleAttr) && elementData()->m_styleAttributeI
sDirty && isStyledElement()) | 1949 if (UNLIKELY(localName == styleAttr) && elementData()->m_styleAttributeI
sDirty && isStyledElement()) |
| 1950 removeAllInlineStyleProperties(); | 1950 removeAllInlineStyleProperties(); |
| 1951 return; | 1951 return; |
| 1952 } | 1952 } |
| 1953 | 1953 |
| 1954 removeAttributeInternal(index, NotInSynchronizationOfLazyAttribute); | 1954 removeAttributeInternal(index, NotInSynchronizationOfLazyAttribute); |
| 1955 } | 1955 } |
| 1956 | 1956 |
| 1957 void Element::removeAttributeNS(const AtomicString& namespaceURI, const AtomicSt
ring& localName) | 1957 void Element::removeAttributeNS(const AtomicString& namespaceURI, const AtomicSt
ring& localName) |
| 1958 { | 1958 { |
| (...skipping 1645 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3604 return true; | 3604 return true; |
| 3605 } | 3605 } |
| 3606 | 3606 |
| 3607 size_t ElementData::getAttrIndex(Attr* attr) const | 3607 size_t ElementData::getAttrIndex(Attr* attr) const |
| 3608 { | 3608 { |
| 3609 // This relies on the fact that Attr's QualifiedName == the Attribute's name
. | 3609 // This relies on the fact that Attr's QualifiedName == the Attribute's name
. |
| 3610 for (unsigned i = 0; i < length(); ++i) { | 3610 for (unsigned i = 0; i < length(); ++i) { |
| 3611 if (attributeItem(i)->name() == attr->qualifiedName()) | 3611 if (attributeItem(i)->name() == attr->qualifiedName()) |
| 3612 return i; | 3612 return i; |
| 3613 } | 3613 } |
| 3614 return notFound; | 3614 return kNotFound; |
| 3615 } | 3615 } |
| 3616 | 3616 |
| 3617 size_t ElementData::getAttributeItemIndexSlowCase(const AtomicString& name, bool
shouldIgnoreAttributeCase) const | 3617 size_t ElementData::getAttributeItemIndexSlowCase(const AtomicString& name, bool
shouldIgnoreAttributeCase) const |
| 3618 { | 3618 { |
| 3619 // Continue to checking case-insensitively and/or full namespaced names if n
ecessary: | 3619 // Continue to checking case-insensitively and/or full namespaced names if n
ecessary: |
| 3620 for (unsigned i = 0; i < length(); ++i) { | 3620 for (unsigned i = 0; i < length(); ++i) { |
| 3621 const Attribute* attribute = attributeItem(i); | 3621 const Attribute* attribute = attributeItem(i); |
| 3622 if (!attribute->name().hasPrefix()) { | 3622 if (!attribute->name().hasPrefix()) { |
| 3623 if (shouldIgnoreAttributeCase && equalIgnoringCase(name, attribute->
localName())) | 3623 if (shouldIgnoreAttributeCase && equalIgnoringCase(name, attribute->
localName())) |
| 3624 return i; | 3624 return i; |
| 3625 } else { | 3625 } else { |
| 3626 // FIXME: Would be faster to do this comparison without calling toSt
ring, which | 3626 // FIXME: Would be faster to do this comparison without calling toSt
ring, which |
| 3627 // generates a temporary string by concatenation. But this branch is
only reached | 3627 // generates a temporary string by concatenation. But this branch is
only reached |
| 3628 // if the attribute name has a prefix, which is rare in HTML. | 3628 // if the attribute name has a prefix, which is rare in HTML. |
| 3629 if (equalPossiblyIgnoringCase(name, attribute->name().toString(), sh
ouldIgnoreAttributeCase)) | 3629 if (equalPossiblyIgnoringCase(name, attribute->name().toString(), sh
ouldIgnoreAttributeCase)) |
| 3630 return i; | 3630 return i; |
| 3631 } | 3631 } |
| 3632 } | 3632 } |
| 3633 return notFound; | 3633 return kNotFound; |
| 3634 } | 3634 } |
| 3635 | 3635 |
| 3636 Attribute* UniqueElementData::getAttributeItem(const QualifiedName& name) | 3636 Attribute* UniqueElementData::getAttributeItem(const QualifiedName& name) |
| 3637 { | 3637 { |
| 3638 for (unsigned i = 0; i < length(); ++i) { | 3638 for (unsigned i = 0; i < length(); ++i) { |
| 3639 if (m_attributeVector.at(i).name().matches(name)) | 3639 if (m_attributeVector.at(i).name().matches(name)) |
| 3640 return &m_attributeVector.at(i); | 3640 return &m_attributeVector.at(i); |
| 3641 } | 3641 } |
| 3642 return 0; | 3642 return 0; |
| 3643 } | 3643 } |
| 3644 | 3644 |
| 3645 Attribute* UniqueElementData::attributeItem(unsigned index) | 3645 Attribute* UniqueElementData::attributeItem(unsigned index) |
| 3646 { | 3646 { |
| 3647 ASSERT_WITH_SECURITY_IMPLICATION(index < length()); | 3647 ASSERT_WITH_SECURITY_IMPLICATION(index < length()); |
| 3648 return &m_attributeVector.at(index); | 3648 return &m_attributeVector.at(index); |
| 3649 } | 3649 } |
| 3650 | 3650 |
| 3651 } // namespace WebCore | 3651 } // namespace WebCore |
| OLD | NEW |