diff options
Diffstat (limited to 'WebCore/dom')
41 files changed, 1349 insertions, 519 deletions
diff --git a/WebCore/dom/Attr.cpp b/WebCore/dom/Attr.cpp index 2ef5f9b..597f9ba 100644 --- a/WebCore/dom/Attr.cpp +++ b/WebCore/dom/Attr.cpp @@ -38,10 +38,10 @@ inline Attr::Attr(Element* element, Document* document, PassRefPtr<Attribute> at , m_element(element) , m_attribute(attribute) , m_ignoreChildrenChanged(0) - , m_specified(true) + , m_specified(true) { ASSERT(!m_attribute->attr()); - m_attribute->m_impl = this; + m_attribute->bindAttr(this); } PassRefPtr<Attr> Attr::create(Element* element, Document* document, PassRefPtr<Attribute> attribute) @@ -54,7 +54,7 @@ PassRefPtr<Attr> Attr::create(Element* element, Document* document, PassRefPtr<A Attr::~Attr() { ASSERT(m_attribute->attr() == this); - m_attribute->m_impl = 0; + m_attribute->unbindAttr(this); } void Attr::createTextChild() diff --git a/WebCore/dom/Attr.idl b/WebCore/dom/Attr.idl index 3c73bc0..d959cd1 100644 --- a/WebCore/dom/Attr.idl +++ b/WebCore/dom/Attr.idl @@ -31,7 +31,7 @@ module core { readonly attribute boolean specified; - attribute [ConvertNullStringTo=Null, ConvertNullToNullString, CustomSetter] DOMString value + attribute [ConvertNullStringTo=Null, ConvertNullToNullString] DOMString value setter raises(DOMException); // DOM Level 2 diff --git a/WebCore/dom/Attribute.cpp b/WebCore/dom/Attribute.cpp index 0ab0bb6..20c05d8 100644 --- a/WebCore/dom/Attribute.cpp +++ b/WebCore/dom/Attribute.cpp @@ -26,20 +26,64 @@ #include "Attr.h" #include "Element.h" +#include <wtf/HashMap.h> +#include <wtf/UnusedParam.h> namespace WebCore { +typedef HashMap<Attribute*, Attr*> AttributeAttrMap; +static AttributeAttrMap& attributeAttrMap() +{ + DEFINE_STATIC_LOCAL(AttributeAttrMap, map, ()); + return map; +} + PassRefPtr<Attribute> Attribute::clone() const { - return adoptRef(new Attribute(m_name, m_value)); + return adoptRef(new Attribute(m_name, m_value, m_isMappedAttribute, m_styleDecl.get())); +} + +Attr* Attribute::attr() const +{ + if (m_hasAttr) { + ASSERT(attributeAttrMap().contains(const_cast<Attribute*>(this))); + return attributeAttrMap().get(const_cast<Attribute*>(this)); + } + + ASSERT(!attributeAttrMap().contains(const_cast<Attribute*>(this))); + return 0; } PassRefPtr<Attr> Attribute::createAttrIfNeeded(Element* e) { - RefPtr<Attr> r = m_impl; - if (!r) - r = Attr::create(e, e->document(), this); + RefPtr<Attr> r; + if (m_hasAttr) { + ASSERT(attributeAttrMap().contains(this)); + r = attributeAttrMap().get(this); + } else { + ASSERT(!attributeAttrMap().contains(this)); + r = Attr::create(e, e->document(), this); // This will end up calling Attribute::bindAttr. + ASSERT(attributeAttrMap().contains(this)); + } + return r.release(); } +void Attribute::bindAttr(Attr* attr) +{ + ASSERT(!m_hasAttr); + ASSERT(!attributeAttrMap().contains(this)); + attributeAttrMap().set(this, attr); + m_hasAttr = true; +} + +void Attribute::unbindAttr(Attr* attr) +{ + ASSERT(m_hasAttr); + ASSERT(attributeAttrMap().contains(this)); + ASSERT_UNUSED(attr, attributeAttrMap().get(this) == attr); + attributeAttrMap().remove(this); + m_hasAttr = false; } + +} // namespace WebCore diff --git a/WebCore/dom/Attribute.h b/WebCore/dom/Attribute.h index b06d120..9e1afc6 100644 --- a/WebCore/dom/Attribute.h +++ b/WebCore/dom/Attribute.h @@ -25,6 +25,7 @@ #ifndef Attribute_h #define Attribute_h +#include "CSSMappedAttributeDeclaration.h" #include "QualifiedName.h" namespace WebCore { @@ -43,10 +44,17 @@ class Attribute : public RefCounted<Attribute> { public: static PassRefPtr<Attribute> create(const QualifiedName& name, const AtomicString& value) { - return adoptRef(new Attribute(name, value)); + return adoptRef(new Attribute(name, value, false, 0)); } - virtual ~Attribute() { } - + static PassRefPtr<Attribute> createMapped(const QualifiedName& name, const AtomicString& value) + { + return adoptRef(new Attribute(name, value, true, 0)); + } + static PassRefPtr<Attribute> createMapped(const AtomicString& name, const AtomicString& value) + { + return adoptRef(new Attribute(name, value, true, 0)); + } + const AtomicString& value() const { return m_value; } const AtomicString& prefix() const { return m_name.prefix(); } const AtomicString& localName() const { return m_name.localName(); } @@ -54,38 +62,55 @@ public: const QualifiedName& name() const { return m_name; } - Attr* attr() const { return m_impl; } + Attr* attr() const; PassRefPtr<Attr> createAttrIfNeeded(Element*); bool isNull() const { return m_value.isNull(); } bool isEmpty() const { return m_value.isEmpty(); } - virtual PassRefPtr<Attribute> clone() const; + PassRefPtr<Attribute> clone() const; // An extension to get the style information for presentational attributes. - virtual CSSStyleDeclaration* style() const { return 0; } - + CSSStyleDeclaration* style() const { return m_styleDecl.get(); } + CSSMappedAttributeDeclaration* decl() const { return m_styleDecl.get(); } + void setDecl(PassRefPtr<CSSMappedAttributeDeclaration> decl) { m_styleDecl = decl; } + void setValue(const AtomicString& value) { m_value = value; } void setPrefix(const AtomicString& prefix) { m_name.setPrefix(prefix); } - virtual bool isMappedAttribute() { return false; } + bool isMappedAttribute() { return m_isMappedAttribute; } -protected: - Attribute(const QualifiedName& name, const AtomicString& value) - : m_name(name), m_value(value), m_impl(0) +private: + Attribute(const QualifiedName& name, const AtomicString& value, bool isMappedAttribute, CSSMappedAttributeDeclaration* styleDecl) + : m_isMappedAttribute(isMappedAttribute) + , m_hasAttr(false) + , m_name(name) + , m_value(value) + , m_styleDecl(styleDecl) { } - Attribute(const AtomicString& name, const AtomicString& value) - : m_name(nullAtom, name, nullAtom), m_value(value), m_impl(0) + + Attribute(const AtomicString& name, const AtomicString& value, bool isMappedAttribute, CSSMappedAttributeDeclaration* styleDecl) + : m_isMappedAttribute(isMappedAttribute) + , m_hasAttr(false) + , m_name(nullAtom, name, nullAtom) + , m_value(value) + , m_styleDecl(styleDecl) { } -private: + void bindAttr(Attr*); + void unbindAttr(Attr*); + + // These booleans will go into the spare 32-bits of padding from RefCounted in 64-bit. + bool m_isMappedAttribute; + bool m_hasAttr; + QualifiedName m_name; AtomicString m_value; - Attr* m_impl; + RefPtr<CSSMappedAttributeDeclaration> m_styleDecl; }; -} //namespace +} // namespace WebCore -#endif +#endif // Attribute_h diff --git a/WebCore/dom/CrossThreadTask.h b/WebCore/dom/CrossThreadTask.h new file mode 100644 index 0000000..ee05bec --- /dev/null +++ b/WebCore/dom/CrossThreadTask.h @@ -0,0 +1,477 @@ +/* + * Copyright (C) 2009-2010 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef CrossThreadTask_h +#define CrossThreadTask_h + +#include "CrossThreadCopier.h" +#include "ScriptExecutionContext.h" +#include <memory> +#include <wtf/PassOwnPtr.h> +#include <wtf/PassRefPtr.h> +#include <wtf/TypeTraits.h> + +namespace WebCore { + +// Traits for the CrossThreadTask. +template<typename T> struct CrossThreadTaskTraits { + typedef const T& ParamType; +}; + +template<typename T> struct CrossThreadTaskTraits<T*> { + typedef T* ParamType; +}; + +template<typename T> struct CrossThreadTaskTraits<PassRefPtr<T> > { + typedef PassRefPtr<T> ParamType; +}; + +template<typename T> struct CrossThreadTaskTraits<PassOwnPtr<T> > { + typedef PassOwnPtr<T> ParamType; +}; + +template<typename P1, typename MP1> +class CrossThreadTask1 : public ScriptExecutionContext::Task { +public: + typedef void (*Method)(ScriptExecutionContext*, MP1); + typedef CrossThreadTask1<P1, MP1> CrossThreadTask; + typedef typename CrossThreadTaskTraits<P1>::ParamType Param1; + + static PassOwnPtr<CrossThreadTask> create(Method method, Param1 parameter1) + { + return new CrossThreadTask(method, parameter1); + } + +private: + CrossThreadTask1(Method method, Param1 parameter1) + : m_method(method) + , m_parameter1(parameter1) + { + } + + virtual void performTask(ScriptExecutionContext* context) + { + (*m_method)(context, m_parameter1); + } + +private: + Method m_method; + P1 m_parameter1; +}; + +template<typename P1, typename MP1, typename P2, typename MP2> +class CrossThreadTask2 : public ScriptExecutionContext::Task { +public: + typedef void (*Method)(ScriptExecutionContext*, MP1, MP2); + typedef CrossThreadTask2<P1, MP1, P2, MP2> CrossThreadTask; + typedef typename CrossThreadTaskTraits<P1>::ParamType Param1; + typedef typename CrossThreadTaskTraits<P2>::ParamType Param2; + + static PassOwnPtr<CrossThreadTask> create(Method method, Param1 parameter1, Param2 parameter2) + { + return new CrossThreadTask(method, parameter1, parameter2); + } + +private: + CrossThreadTask2(Method method, Param1 parameter1, Param2 parameter2) + : m_method(method) + , m_parameter1(parameter1) + , m_parameter2(parameter2) + { + } + + virtual void performTask(ScriptExecutionContext* context) + { + (*m_method)(context, m_parameter1, m_parameter2); + } + +private: + Method m_method; + P1 m_parameter1; + P2 m_parameter2; +}; + +template<typename P1, typename MP1, typename P2, typename MP2, typename P3, typename MP3> +class CrossThreadTask3 : public ScriptExecutionContext::Task { +public: + typedef void (*Method)(ScriptExecutionContext*, MP1, MP2, MP3); + typedef CrossThreadTask3<P1, MP1, P2, MP2, P3, MP3> CrossThreadTask; + typedef typename CrossThreadTaskTraits<P1>::ParamType Param1; + typedef typename CrossThreadTaskTraits<P2>::ParamType Param2; + typedef typename CrossThreadTaskTraits<P3>::ParamType Param3; + + static PassOwnPtr<CrossThreadTask> create(Method method, Param1 parameter1, Param2 parameter2, Param3 parameter3) + { + return new CrossThreadTask(method, parameter1, parameter2, parameter3); + } + +private: + CrossThreadTask3(Method method, Param1 parameter1, Param2 parameter2, Param3 parameter3) + : m_method(method) + , m_parameter1(parameter1) + , m_parameter2(parameter2) + , m_parameter3(parameter3) + { + } + + virtual void performTask(ScriptExecutionContext* context) + { + (*m_method)(context, m_parameter1, m_parameter2, m_parameter3); + } + +private: + Method m_method; + P1 m_parameter1; + P2 m_parameter2; + P3 m_parameter3; +}; + +template<typename P1, typename MP1, typename P2, typename MP2, typename P3, typename MP3, typename P4, typename MP4> +class CrossThreadTask4 : public ScriptExecutionContext::Task { +public: + typedef void (*Method)(ScriptExecutionContext*, MP1, MP2, MP3, MP4); + typedef CrossThreadTask4<P1, MP1, P2, MP2, P3, MP3, P4, MP4> CrossThreadTask; + typedef typename CrossThreadTaskTraits<P1>::ParamType Param1; + typedef typename CrossThreadTaskTraits<P2>::ParamType Param2; + typedef typename CrossThreadTaskTraits<P3>::ParamType Param3; + typedef typename CrossThreadTaskTraits<P4>::ParamType Param4; + + static PassOwnPtr<CrossThreadTask> create(Method method, Param1 parameter1, Param2 parameter2, Param3 parameter3, Param4 parameter4) + { + return new CrossThreadTask(method, parameter1, parameter2, parameter3, parameter4); + } + +private: + CrossThreadTask4(Method method, Param1 parameter1, Param2 parameter2, Param3 parameter3, Param4 parameter4) + : m_method(method) + , m_parameter1(parameter1) + , m_parameter2(parameter2) + , m_parameter3(parameter3) + , m_parameter4(parameter4) + { + } + + virtual void performTask(ScriptExecutionContext* context) + { + (*m_method)(context, m_parameter1, m_parameter2, m_parameter3, m_parameter4); + } + +private: + Method m_method; + P1 m_parameter1; + P2 m_parameter2; + P3 m_parameter3; + P4 m_parameter4; +}; + +template<typename P1, typename MP1, typename P2, typename MP2, typename P3, typename MP3, typename P4, typename MP4, typename P5, typename MP5> +class CrossThreadTask5 : public ScriptExecutionContext::Task { +public: + typedef void (*Method)(ScriptExecutionContext*, MP1, MP2, MP3, MP4, MP5); + typedef CrossThreadTask5<P1, MP1, P2, MP2, P3, MP3, P4, MP4, P5, MP5> CrossThreadTask; + typedef typename CrossThreadTaskTraits<P1>::ParamType Param1; + typedef typename CrossThreadTaskTraits<P2>::ParamType Param2; + typedef typename CrossThreadTaskTraits<P3>::ParamType Param3; + typedef typename CrossThreadTaskTraits<P4>::ParamType Param4; + typedef typename CrossThreadTaskTraits<P5>::ParamType Param5; + + static PassOwnPtr<CrossThreadTask> create(Method method, Param1 parameter1, Param2 parameter2, Param3 parameter3, Param4 parameter4, Param5 parameter5) + { + return new CrossThreadTask(method, parameter1, parameter2, parameter3, parameter4, parameter5); + } + +private: + CrossThreadTask5(Method method, Param1 parameter1, Param2 parameter2, Param3 parameter3, Param4 parameter4, Param5 parameter5) + : m_method(method) + , m_parameter1(parameter1) + , m_parameter2(parameter2) + , m_parameter3(parameter3) + , m_parameter4(parameter4) + , m_parameter5(parameter5) + { + } + + virtual void performTask(ScriptExecutionContext* context) + { + (*m_method)(context, m_parameter1, m_parameter2, m_parameter3, m_parameter4, m_parameter5); + } + +private: + Method m_method; + P1 m_parameter1; + P2 m_parameter2; + P3 m_parameter3; + P4 m_parameter4; + P5 m_parameter5; +}; + +template<typename P1, typename MP1, typename P2, typename MP2, typename P3, typename MP3, typename P4, typename MP4, typename P5, typename MP5, typename P6, typename MP6> +class CrossThreadTask6 : public ScriptExecutionContext::Task { +public: + typedef void (*Method)(ScriptExecutionContext*, MP1, MP2, MP3, MP4, MP5, MP6); + typedef CrossThreadTask6<P1, MP1, P2, MP2, P3, MP3, P4, MP4, P5, MP5, P6, MP6> CrossThreadTask; + typedef typename CrossThreadTaskTraits<P1>::ParamType Param1; + typedef typename CrossThreadTaskTraits<P2>::ParamType Param2; + typedef typename CrossThreadTaskTraits<P3>::ParamType Param3; + typedef typename CrossThreadTaskTraits<P4>::ParamType Param4; + typedef typename CrossThreadTaskTraits<P5>::ParamType Param5; + typedef typename CrossThreadTaskTraits<P6>::ParamType Param6; + + static PassOwnPtr<CrossThreadTask> create(Method method, Param1 parameter1, Param2 parameter2, Param3 parameter3, Param4 parameter4, Param5 parameter5, Param6 parameter6) + { + return new CrossThreadTask(method, parameter1, parameter2, parameter3, parameter4, parameter5, parameter6); + } + +private: + CrossThreadTask6(Method method, Param1 parameter1, Param2 parameter2, Param3 parameter3, Param4 parameter4, Param5 parameter5, Param6 parameter6) + : m_method(method) + , m_parameter1(parameter1) + , m_parameter2(parameter2) + , m_parameter3(parameter3) + , m_parameter4(parameter4) + , m_parameter5(parameter5) + , m_parameter6(parameter6) + { + } + + virtual void performTask(ScriptExecutionContext* context) + { + (*m_method)(context, m_parameter1, m_parameter2, m_parameter3, m_parameter4, m_parameter5, m_parameter6); + } + +private: + Method m_method; + P1 m_parameter1; + P2 m_parameter2; + P3 m_parameter3; + P4 m_parameter4; + P5 m_parameter5; + P6 m_parameter6; +}; + +template<typename P1, typename MP1, typename P2, typename MP2, typename P3, typename MP3, typename P4, typename MP4, typename P5, typename MP5, typename P6, typename MP6, typename P7, typename MP7> +class CrossThreadTask7 : public ScriptExecutionContext::Task { +public: + typedef void (*Method)(ScriptExecutionContext*, MP1, MP2, MP3, MP4, MP5, MP6, MP7); + typedef CrossThreadTask7<P1, MP1, P2, MP2, P3, MP3, P4, MP4, P5, MP5, P6, MP6, P7, MP7> CrossThreadTask; + typedef typename CrossThreadTaskTraits<P1>::ParamType Param1; + typedef typename CrossThreadTaskTraits<P2>::ParamType Param2; + typedef typename CrossThreadTaskTraits<P3>::ParamType Param3; + typedef typename CrossThreadTaskTraits<P4>::ParamType Param4; + typedef typename CrossThreadTaskTraits<P5>::ParamType Param5; + typedef typename CrossThreadTaskTraits<P6>::ParamType Param6; + typedef typename CrossThreadTaskTraits<P7>::ParamType Param7; + + static PassOwnPtr<CrossThreadTask> create(Method method, Param1 parameter1, Param2 parameter2, Param3 parameter3, Param4 parameter4, Param5 parameter5, Param6 parameter6, Param7 parameter7) + { + return new CrossThreadTask(method, parameter1, parameter2, parameter3, parameter4, parameter5, parameter6, parameter7); + } + +private: + CrossThreadTask7(Method method, Param1 parameter1, Param2 parameter2, Param3 parameter3, Param4 parameter4, Param5 parameter5, Param6 parameter6, Param7 parameter7) + : m_method(method) + , m_parameter1(parameter1) + , m_parameter2(parameter2) + , m_parameter3(parameter3) + , m_parameter4(parameter4) + , m_parameter5(parameter5) + , m_parameter6(parameter6) + , m_parameter7(parameter7) + { + } + + virtual void performTask(ScriptExecutionContext* context) + { + (*m_method)(context, m_parameter1, m_parameter2, m_parameter3, m_parameter4, m_parameter5, m_parameter6, m_parameter7); + } + +private: + Method m_method; + P1 m_parameter1; + P2 m_parameter2; + P3 m_parameter3; + P4 m_parameter4; + P5 m_parameter5; + P6 m_parameter6; + P7 m_parameter7; +}; + +template<typename P1, typename MP1, typename P2, typename MP2, typename P3, typename MP3, typename P4, typename MP4, typename P5, typename MP5, typename P6, typename MP6, typename P7, typename MP7, typename P8, typename MP8> +class CrossThreadTask8 : public ScriptExecutionContext::Task { +public: + typedef void (*Method)(ScriptExecutionContext*, MP1, MP2, MP3, MP4, MP5, MP6, MP7, MP8); + typedef CrossThreadTask8<P1, MP1, P2, MP2, P3, MP3, P4, MP4, P5, MP5, P6, MP6, P7, MP7, P8, MP8> CrossThreadTask; + typedef typename CrossThreadTaskTraits<P1>::ParamType Param1; + typedef typename CrossThreadTaskTraits<P2>::ParamType Param2; + typedef typename CrossThreadTaskTraits<P3>::ParamType Param3; + typedef typename CrossThreadTaskTraits<P4>::ParamType Param4; + typedef typename CrossThreadTaskTraits<P5>::ParamType Param5; + typedef typename CrossThreadTaskTraits<P6>::ParamType Param6; + typedef typename CrossThreadTaskTraits<P7>::ParamType Param7; + typedef typename CrossThreadTaskTraits<P8>::ParamType Param8; + + static PassOwnPtr<CrossThreadTask> create(Method method, Param1 parameter1, Param2 parameter2, Param3 parameter3, Param4 parameter4, Param5 parameter5, Param6 parameter6, Param7 parameter7, Param8 parameter8) + { + return new CrossThreadTask(method, parameter1, parameter2, parameter3, parameter4, parameter5, parameter6, parameter7, parameter8); + } + +private: + CrossThreadTask8(Method method, Param1 parameter1, Param2 parameter2, Param3 parameter3, Param4 parameter4, Param5 parameter5, Param6 parameter6, Param7 parameter7, Param8 parameter8) + : m_method(method) + , m_parameter1(parameter1) + , m_parameter2(parameter2) + , m_parameter3(parameter3) + , m_parameter4(parameter4) + , m_parameter5(parameter5) + , m_parameter6(parameter6) + , m_parameter7(parameter7) + , m_parameter8(parameter8) + { + } + + virtual void performTask(ScriptExecutionContext* context) + { + (*m_method)(context, m_parameter1, m_parameter2, m_parameter3, m_parameter4, m_parameter5, m_parameter6, m_parameter7, m_parameter8); + } + +private: + Method m_method; + P1 m_parameter1; + P2 m_parameter2; + P3 m_parameter3; + P4 m_parameter4; + P5 m_parameter5; + P6 m_parameter6; + P7 m_parameter7; + P8 m_parameter8; +}; + +template<typename P1, typename MP1> +PassOwnPtr<ScriptExecutionContext::Task> createCallbackTask( + void (*method)(ScriptExecutionContext*, MP1), + const P1& parameter1) +{ + return CrossThreadTask1<typename CrossThreadCopier<P1>::Type, MP1>::create( + method, + CrossThreadCopier<P1>::copy(parameter1)); +} + +template<typename P1, typename MP1, typename P2, typename MP2> +PassOwnPtr<ScriptExecutionContext::Task> createCallbackTask( + void (*method)(ScriptExecutionContext*, MP1, MP2), + const P1& parameter1, const P2& parameter2) +{ + return CrossThreadTask2<typename CrossThreadCopier<P1>::Type, MP1, typename CrossThreadCopier<P2>::Type, MP2>::create( + method, + CrossThreadCopier<P1>::copy(parameter1), CrossThreadCopier<P2>::copy(parameter2)); +} + +template<typename P1, typename MP1, typename P2, typename MP2, typename P3, typename MP3> +PassOwnPtr<ScriptExecutionContext::Task> createCallbackTask( + void (*method)(ScriptExecutionContext*, MP1, MP2, MP3), + const P1& parameter1, const P2& parameter2, const P3& parameter3) +{ + return CrossThreadTask3<typename CrossThreadCopier<P1>::Type, MP1, typename CrossThreadCopier<P2>::Type, MP2, typename CrossThreadCopier<P3>::Type, MP3>::create( + method, + CrossThreadCopier<P1>::copy(parameter1), CrossThreadCopier<P2>::copy(parameter2), + CrossThreadCopier<P3>::copy(parameter3)); +} + +template<typename P1, typename MP1, typename P2, typename MP2, typename P3, typename MP3, typename P4, typename MP4> +PassOwnPtr<ScriptExecutionContext::Task> createCallbackTask( + void (*method)(ScriptExecutionContext*, MP1, MP2, MP3, MP4), + const P1& parameter1, const P2& parameter2, const P3& parameter3, const P4& parameter4) +{ + return CrossThreadTask4<typename CrossThreadCopier<P1>::Type, MP1, typename CrossThreadCopier<P2>::Type, MP2, typename CrossThreadCopier<P3>::Type, MP3, + typename CrossThreadCopier<P4>::Type, MP4>::create( + method, + CrossThreadCopier<P1>::copy(parameter1), CrossThreadCopier<P2>::copy(parameter2), + CrossThreadCopier<P3>::copy(parameter3), CrossThreadCopier<P4>::copy(parameter4)); +} + +template<typename P1, typename MP1, typename P2, typename MP2, typename P3, typename MP3, typename P4, typename MP4, typename P5, typename MP5> +PassOwnPtr<ScriptExecutionContext::Task> createCallbackTask( + void (*method)(ScriptExecutionContext*, MP1, MP2, MP3, MP4, MP5), + const P1& parameter1, const P2& parameter2, const P3& parameter3, const P4& parameter4, const P5& parameter5) +{ + return CrossThreadTask5<typename CrossThreadCopier<P1>::Type, MP1, typename CrossThreadCopier<P2>::Type, MP2, typename CrossThreadCopier<P3>::Type, MP3, + typename CrossThreadCopier<P4>::Type, MP4, typename CrossThreadCopier<P5>::Type, MP5>::create( + method, + CrossThreadCopier<P1>::copy(parameter1), CrossThreadCopier<P2>::copy(parameter2), + CrossThreadCopier<P3>::copy(parameter3), CrossThreadCopier<P4>::copy(parameter4), + CrossThreadCopier<P5>::copy(parameter5)); +} + +template<typename P1, typename MP1, typename P2, typename MP2, typename P3, typename MP3, typename P4, typename MP4, typename P5, typename MP5, typename P6, typename MP6> +PassOwnPtr<ScriptExecutionContext::Task> createCallbackTask( + void (*method)(ScriptExecutionContext*, MP1, MP2, MP3, MP4, MP5, MP6), + const P1& parameter1, const P2& parameter2, const P3& parameter3, const P4& parameter4, const P5& parameter5, const P6& parameter6) +{ + return CrossThreadTask6<typename CrossThreadCopier<P1>::Type, MP1, typename CrossThreadCopier<P2>::Type, MP2, typename CrossThreadCopier<P3>::Type, MP3, + typename CrossThreadCopier<P4>::Type, MP4, typename CrossThreadCopier<P5>::Type, MP5, typename CrossThreadCopier<P6>::Type, MP6>::create( + method, + CrossThreadCopier<P1>::copy(parameter1), CrossThreadCopier<P2>::copy(parameter2), + CrossThreadCopier<P3>::copy(parameter3), CrossThreadCopier<P4>::copy(parameter4), + CrossThreadCopier<P5>::copy(parameter5), CrossThreadCopier<P6>::copy(parameter6)); +} + +template<typename P1, typename MP1, typename P2, typename MP2, typename P3, typename MP3, typename P4, typename MP4, typename P5, typename MP5, typename P6, typename MP6, typename P7, typename MP7> +PassOwnPtr<ScriptExecutionContext::Task> createCallbackTask( + void (*method)(ScriptExecutionContext*, MP1, MP2, MP3, MP4, MP5, MP6, MP7), + const P1& parameter1, const P2& parameter2, const P3& parameter3, const P4& parameter4, const P5& parameter5, const P6& parameter6, const P7& parameter7) +{ + return CrossThreadTask7<typename CrossThreadCopier<P1>::Type, MP1, typename CrossThreadCopier<P2>::Type, MP2, typename CrossThreadCopier<P3>::Type, MP3, + typename CrossThreadCopier<P4>::Type, MP4, typename CrossThreadCopier<P5>::Type, MP5, typename CrossThreadCopier<P6>::Type, MP6, + typename CrossThreadCopier<P7>::Type, MP7>::create( + method, + CrossThreadCopier<P1>::copy(parameter1), CrossThreadCopier<P2>::copy(parameter2), + CrossThreadCopier<P3>::copy(parameter3), CrossThreadCopier<P4>::copy(parameter4), + CrossThreadCopier<P5>::copy(parameter5), CrossThreadCopier<P6>::copy(parameter6), + CrossThreadCopier<P7>::copy(parameter7)); +} + +template<typename P1, typename MP1, typename P2, typename MP2, typename P3, typename MP3, typename P4, typename MP4, typename P5, typename MP5, typename P6, typename MP6, typename P7, typename MP7, typename P8, typename MP8> +PassOwnPtr<ScriptExecutionContext::Task> createCallbackTask( + void (*method)(ScriptExecutionContext*, MP1, MP2, MP3, MP4, MP5, MP6, MP7, MP8), + const P1& parameter1, const P2& parameter2, const P3& parameter3, const P4& parameter4, const P5& parameter5, const P6& parameter6, const P7& parameter7, const P8& parameter8) +{ + return CrossThreadTask8<typename CrossThreadCopier<P1>::Type, MP1, typename CrossThreadCopier<P2>::Type, MP2, typename CrossThreadCopier<P3>::Type, MP3, + typename CrossThreadCopier<P4>::Type, MP4, typename CrossThreadCopier<P5>::Type, MP5, typename CrossThreadCopier<P6>::Type, MP6, + typename CrossThreadCopier<P7>::Type, MP7, typename CrossThreadCopier<P8>::Type, MP8>::create( + method, + CrossThreadCopier<P1>::copy(parameter1), CrossThreadCopier<P2>::copy(parameter2), + CrossThreadCopier<P3>::copy(parameter3), CrossThreadCopier<P4>::copy(parameter4), + CrossThreadCopier<P5>::copy(parameter5), CrossThreadCopier<P6>::copy(parameter6), + CrossThreadCopier<P7>::copy(parameter7), CrossThreadCopier<P8>::copy(parameter8)); +} + +} // namespace WebCore + +#endif // CrossThreadTask_h diff --git a/WebCore/dom/DOMStringList.cpp b/WebCore/dom/DOMStringList.cpp new file mode 100644 index 0000000..660be92 --- /dev/null +++ b/WebCore/dom/DOMStringList.cpp @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2010 Google Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "DOMStringList.h" + +namespace WebCore { + +bool DOMStringList::contains(const String& string) const +{ + // FIXME: Currently, all consumers of DOMStringList store fairly small lists and thus an O(n) + // algorithm is OK. But this may need to be optimized if larger amounts of data are + // stored in m_strings. + size_t count = m_strings.size(); + for (size_t i = 0; i < count; ++i) { + if (m_strings[i] == string) + return true; + } + return false; +} + +} // namespace WebCore diff --git a/WebCore/dom/DOMStringList.h b/WebCore/dom/DOMStringList.h new file mode 100644 index 0000000..a3f9b40 --- /dev/null +++ b/WebCore/dom/DOMStringList.h @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2010 Google Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef DOMStringList_h +#define DOMStringList_h + +#include "PlatformString.h" +#include <wtf/PassRefPtr.h> +#include <wtf/RefCounted.h> +#include <wtf/Vector.h> + +namespace WebCore { + +// FIXME: Some consumers of this class may benefit from lazily fetching items rather +// than creating the list statically as is currently the only option. +class DOMStringList : public RefCounted<DOMStringList> { +public: + static PassRefPtr<DOMStringList> create() + { + return adoptRef(new DOMStringList()); + } + + bool isEmpty() const { return m_strings.isEmpty(); } + void clear() { m_strings.clear(); } + void append(const String& string) { m_strings.append(string); } + + // Implements the IDL. + size_t length() const { return m_strings.size(); } + String item(unsigned index) const { return m_strings[index]; } + bool contains(const String& str) const; + +private: + DOMStringList() { } + + Vector<String> m_strings; +}; + +} // namespace WebCore + +#endif // DOMStringList_h + diff --git a/WebCore/dom/DOMStringList.idl b/WebCore/dom/DOMStringList.idl new file mode 100644 index 0000000..271c9de --- /dev/null +++ b/WebCore/dom/DOMStringList.idl @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2010 Google Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +module core { + + interface [ + GenerateConstructor, + HasIndexGetter + ] DOMStringList { + readonly attribute unsigned long length; + DOMString item(in [IsIndex] unsigned long index); + boolean contains(in DOMString string); + }; + +} + diff --git a/WebCore/dom/DeviceOrientation.cpp b/WebCore/dom/DeviceOrientation.cpp new file mode 100644 index 0000000..6f8d06a --- /dev/null +++ b/WebCore/dom/DeviceOrientation.cpp @@ -0,0 +1,54 @@ +/* + * Copyright 2010, The Android Open Source Project + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "DeviceOrientation.h" + +#if ENABLE(DEVICE_ORIENTATION) + +#include "DeviceOrientationClient.h" +#include "DeviceOrientationEvent.h" +#include <wtf/UnusedParam.h> + +namespace WebCore { + +DeviceOrientation::DeviceOrientation(Page* page, DeviceOrientationClient* client) + : m_page(page) + , m_client(client) +{ +} + +void DeviceOrientation::onDeviceOrientationChange(double alpha, double beta, double gamma) +{ + // FIXME: Fire DeviceOrientationEvents on the window object of all frames + // that are listening to orientation. + UNUSED_PARAM(alpha); + UNUSED_PARAM(beta); + UNUSED_PARAM(gamma); +} + +} // namespace WebCore + +#endif // ENABLE(DEVICE_ORIENTATION) diff --git a/WebCore/dom/DeviceOrientation.h b/WebCore/dom/DeviceOrientation.h new file mode 100644 index 0000000..e4d96be --- /dev/null +++ b/WebCore/dom/DeviceOrientation.h @@ -0,0 +1,49 @@ +/* + * Copyright 2010, The Android Open Source Project + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef DeviceOrientation_h +#define DeviceOrientation_h + +namespace WebCore { + +class DeviceOrientationClient; +class Page; + +class DeviceOrientation { +public: + DeviceOrientation(Page*, DeviceOrientationClient*); + + // FIXME: Add methods to start and stop the service. + + void onDeviceOrientationChange(double alpha, double beta, double gamma); + +private: + Page* m_page; + DeviceOrientationClient* m_client; +}; + +} // namespace WebCore + +#endif // DeviceOrientation_h diff --git a/WebCore/dom/DeviceOrientationClient.h b/WebCore/dom/DeviceOrientationClient.h new file mode 100644 index 0000000..e0f14eb --- /dev/null +++ b/WebCore/dom/DeviceOrientationClient.h @@ -0,0 +1,42 @@ +/* + * Copyright 2010, The Android Open Source Project + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef DeviceOrientationClient_h +#define DeviceOrientationClient_h + +namespace WebCore { + +class DeviceOrientationClient { +public: + virtual void startUpdating() = 0; + virtual void stopUpdating() = 0; + +protected: + virtual ~DeviceOrientationClient() {} +}; + +} // namespace WebCore + +#endif // DeviceOrientationClient_h diff --git a/WebCore/dom/DeviceOrientationEvent.cpp b/WebCore/dom/DeviceOrientationEvent.cpp new file mode 100644 index 0000000..b1aae65 --- /dev/null +++ b/WebCore/dom/DeviceOrientationEvent.cpp @@ -0,0 +1,62 @@ +/* + * Copyright 2010, The Android Open Source Project + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "DeviceOrientationEvent.h" + +#if ENABLE(DEVICE_ORIENTATION) + +namespace WebCore { + +DeviceOrientationEvent::DeviceOrientationEvent() + : m_alpha(0) + , m_beta(0) + , m_gamma(0) +{ +} + +DeviceOrientationEvent::DeviceOrientationEvent(const AtomicString& eventType, double alpha, double beta, double gamma) + : Event(eventType, false, false) // Can't bubble, not cancelable + , m_alpha(alpha) + , m_beta(beta) + , m_gamma(gamma) +{ +} + +void DeviceOrientationEvent::initDeviceOrientationEvent(const AtomicString& eventType, bool canBubble, bool cancelable, double alpha, double beta, double gamma) +{ + if (dispatched()) + return; + + initEvent(eventType, canBubble, cancelable); + + m_alpha = alpha; + m_beta = beta; + m_gamma = gamma; +} + +} // namespace WebCore + +#endif // ENABLE(DEVICE_ORIENTATION) diff --git a/WebCore/dom/DeviceOrientationEvent.h b/WebCore/dom/DeviceOrientationEvent.h new file mode 100644 index 0000000..0cec9ba --- /dev/null +++ b/WebCore/dom/DeviceOrientationEvent.h @@ -0,0 +1,63 @@ +/* + * Copyright 2010, The Android Open Source Project + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef DeviceOrientationEvent_h +#define DeviceOrientationEvent_h + +#include "DOMWindow.h" +#include "Event.h" + +namespace WebCore { + +class DeviceOrientationEvent : public Event { +public: + static PassRefPtr<DeviceOrientationEvent> create() + { + return adoptRef(new DeviceOrientationEvent); + } + static PassRefPtr<DeviceOrientationEvent> create(const AtomicString& eventType, double alpha, double beta, double gamma) + { + return adoptRef(new DeviceOrientationEvent(eventType, alpha, beta, gamma)); + } + + void initDeviceOrientationEvent(const AtomicString& eventType, bool canBubble, bool cancelable, double alpha, double beta, double gamma); + double alpha() const { return m_alpha; } + double beta() const { return m_beta; } + double gamma() const { return m_gamma; } + + virtual bool isDeviceOrientationEvent() const { return true; } + +private: + DeviceOrientationEvent(); + DeviceOrientationEvent(const AtomicString& eventType, double alpha, double beta, double gamma); + + double m_alpha; + double m_beta; + double m_gamma; +}; + +} // namespace WebCore + +#endif // DeviceOrientationEvent_h diff --git a/WebCore/dom/DeviceOrientationEvent.idl b/WebCore/dom/DeviceOrientationEvent.idl new file mode 100644 index 0000000..95d96ec --- /dev/null +++ b/WebCore/dom/DeviceOrientationEvent.idl @@ -0,0 +1,37 @@ +/* + * Copyright 2010, The Android Open Source Project + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +module core { + + interface [ + Conditional=DEVICE_ORIENTATION + ] DeviceOrientationEvent : Event { + readonly attribute double alpha; + readonly attribute double beta; + readonly attribute double gamma; + void initDeviceOrientationEvent(in DOMString typeArg, in boolean canBubbleArg, in boolean cancelableArg, in double alpha, in double beta, in double gamma); + }; + +} diff --git a/WebCore/dom/Document.cpp b/WebCore/dom/Document.cpp index 7fc7aa9..d8905c5 100644 --- a/WebCore/dom/Document.cpp +++ b/WebCore/dom/Document.cpp @@ -29,6 +29,7 @@ #include "AXObjectCache.h" #include "AnimationController.h" #include "Attr.h" +#include "Attribute.h" #include "CDATASection.h" #include "CSSHelper.h" #include "CSSStyleSelector.h" @@ -88,7 +89,6 @@ #include "InspectorTimelineAgent.h" #include "KeyboardEvent.h" #include "Logging.h" -#include "MappedAttribute.h" #include "MessageEvent.h" #include "MouseEvent.h" #include "MouseEventWithHitTestResults.h" @@ -477,7 +477,7 @@ Document::Document(Frame* frame, bool isXHTML, bool isHTML) static int docID = 0; m_docID = docID++; #if ENABLE(XHTMLMP) - m_shouldProcessNoScriptElement = m_frame->script()->canExecuteScripts(NotAboutToExecuteScript); + m_shouldProcessNoScriptElement = m_frame && m_frame->script()->canExecuteScripts(NotAboutToExecuteScript); #endif } @@ -2439,11 +2439,12 @@ void Document::processViewport(const String& features) if (!frame) return; - ViewportArguments arguments; - processArguments(features, (void*)&arguments, &setViewportFeature); + if (frame->page()) { + ViewportArguments arguments; + processArguments(features, (void*)&arguments, &setViewportFeature); - if (frame->page()) frame->page()->chrome()->client()->didReceiveViewportArguments(frame, arguments); + } } MouseEventWithHitTestResults Document::prepareMouseEvent(const HitTestRequest& request, const IntPoint& documentPoint, const PlatformMouseEvent& event) @@ -2679,9 +2680,9 @@ void Document::addStyleSheetCandidateNode(Node* node, bool createdByParser) } // Determine an appropriate insertion point. - ListHashSet<Node*>::iterator begin = m_styleSheetCandidateNodes.begin(); - ListHashSet<Node*>::iterator end = m_styleSheetCandidateNodes.end(); - ListHashSet<Node*>::iterator it = end; + StyleSheetCandidateListHashSet::iterator begin = m_styleSheetCandidateNodes.begin(); + StyleSheetCandidateListHashSet::iterator end = m_styleSheetCandidateNodes.end(); + StyleSheetCandidateListHashSet::iterator it = end; Node* followingNode = 0; do { --it; @@ -2713,11 +2714,11 @@ void Document::recalcStyleSelector() if (Settings* settings = this->settings()) matchAuthorAndUserStyles = settings->authorAndUserStylesEnabled(); - ListHashSet<Node*>::iterator begin = m_styleSheetCandidateNodes.begin(); - ListHashSet<Node*>::iterator end = m_styleSheetCandidateNodes.end(); + StyleSheetCandidateListHashSet::iterator begin = m_styleSheetCandidateNodes.begin(); + StyleSheetCandidateListHashSet::iterator end = m_styleSheetCandidateNodes.end(); if (!matchAuthorAndUserStyles) end = begin; - for (ListHashSet<Node*>::iterator it = begin; it != end; ++it) { + for (StyleSheetCandidateListHashSet::iterator it = begin; it != end; ++it) { Node* n = *it; StyleSheet* sheet = 0; @@ -4298,7 +4299,7 @@ PassRefPtr<Attr> Document::createAttributeNS(const String& namespaceURI, const S // FIXME: Assume this is a mapped attribute, since createAttribute isn't namespace-aware. There's no harm to XML // documents if we're wrong. - return Attr::create(0, this, MappedAttribute::create(qName, StringImpl::empty())); + return Attr::create(0, this, Attribute::createMapped(qName, StringImpl::empty())); } #if ENABLE(SVG) @@ -4421,7 +4422,7 @@ Vector<String> Document::formElementsState() const { Vector<String> stateVector; stateVector.reserveInitialCapacity(m_formElementsWithState.size() * 3); - typedef ListHashSet<Element*>::const_iterator Iterator; + typedef FormElementListHashSet::const_iterator Iterator; Iterator end = m_formElementsWithState.end(); for (Iterator it = m_formElementsWithState.begin(); it != end; ++it) { Element* elementWithState = *it; diff --git a/WebCore/dom/Document.h b/WebCore/dom/Document.h index 676caf9..aa4d9e3 100644 --- a/WebCore/dom/Document.h +++ b/WebCore/dom/Document.h @@ -1104,10 +1104,14 @@ private: unsigned short m_listenerTypes; RefPtr<StyleSheetList> m_styleSheets; // All of the stylesheets that are currently in effect for our media type and stylesheet set. - ListHashSet<Node*> m_styleSheetCandidateNodes; // All of the nodes that could potentially provide stylesheets to the document (<link>, <style>, <?xml-stylesheet>) + + typedef ListHashSet<Node*, 32> StyleSheetCandidateListHashSet; + StyleSheetCandidateListHashSet m_styleSheetCandidateNodes; // All of the nodes that could potentially provide stylesheets to the document (<link>, <style>, <?xml-stylesheet>) + + typedef ListHashSet<Element*, 64> FormElementListHashSet; + FormElementListHashSet m_formElementsWithState; typedef HashMap<FormElementKey, Vector<String>, FormElementKeyHash, FormElementKeyHashTraits> FormElementStateMap; - ListHashSet<Element*> m_formElementsWithState; FormElementStateMap m_stateForNewFormElements; Color m_linkColor; diff --git a/WebCore/dom/Element.cpp b/WebCore/dom/Element.cpp index 3e88071..ec33ea6 100644 --- a/WebCore/dom/Element.cpp +++ b/WebCore/dom/Element.cpp @@ -936,7 +936,7 @@ void Element::recalcStyle(StyleChange change) newStyle->setChildrenAffectedByDirectAdjacentRules(); } - if (ch != NoChange || pseudoStyleCacheIsInvalid(currentStyle.get(), newStyle.get())) { + if (ch != NoChange || pseudoStyleCacheIsInvalid(currentStyle.get(), newStyle.get()) || change == Force && renderer() && renderer()->requiresForcedStyleRecalcPropagation()) { setRenderStyle(newStyle); } else if (needsStyleRecalc() && (styleChangeType() != SyntheticStyleChange) && (document()->usesSiblingRules() || document()->usesDescendantRules())) { // Although no change occurred, we use the new style so that the cousin style sharing code won't get diff --git a/WebCore/dom/Element.h b/WebCore/dom/Element.h index e89cf37..8da2892 100644 --- a/WebCore/dom/Element.h +++ b/WebCore/dom/Element.h @@ -312,7 +312,7 @@ private: bool pseudoStyleCacheIsInvalid(const RenderStyle* currentStyle, RenderStyle* newStyle); - virtual void createAttributeMap() const; + void createAttributeMap() const; virtual void updateStyleAttribute() const { } diff --git a/WebCore/dom/Event.cpp b/WebCore/dom/Event.cpp index 876f8a8..4ea3e0c 100644 --- a/WebCore/dom/Event.cpp +++ b/WebCore/dom/Event.cpp @@ -212,6 +212,13 @@ bool Event::isTouchEvent() const } #endif +#if ENABLE(DEVICE_ORIENTATION) +bool Event::isDeviceOrientationEvent() const +{ + return false; +} +#endif + bool Event::fromUserGesture() { if (!UserGestureIndicator::processingUserGesture()) diff --git a/WebCore/dom/Event.h b/WebCore/dom/Event.h index fbcdc94..2b570d5 100644 --- a/WebCore/dom/Event.h +++ b/WebCore/dom/Event.h @@ -139,6 +139,9 @@ namespace WebCore { #if ENABLE(TOUCH_EVENTS) virtual bool isTouchEvent() const; #endif +#if ENABLE(DEVICE_ORIENTATION) + virtual bool isDeviceOrientationEvent() const; +#endif bool fromUserGesture(); bool propagationStopped() const { return m_propagationStopped || m_immediatePropagationStopped; } diff --git a/WebCore/dom/EventNames.h b/WebCore/dom/EventNames.h index ca2ae96..0491d02 100644 --- a/WebCore/dom/EventNames.h +++ b/WebCore/dom/EventNames.h @@ -49,6 +49,7 @@ namespace WebCore { macro(copy) \ macro(cut) \ macro(dblclick) \ + macro(deviceorientation) \ macro(display) \ macro(downloading) \ macro(drag) \ diff --git a/WebCore/dom/InputElement.cpp b/WebCore/dom/InputElement.cpp index 3459906..079dd56 100644 --- a/WebCore/dom/InputElement.cpp +++ b/WebCore/dom/InputElement.cpp @@ -31,6 +31,7 @@ #include "CSSStyleSelector.h" #endif +#include "Attribute.h" #include "Chrome.h" #include "ChromeClient.h" #include "Document.h" @@ -39,7 +40,6 @@ #include "Frame.h" #include "HTMLInputElement.h" #include "HTMLNames.h" -#include "MappedAttribute.h" #include "Page.h" #include "RenderTextControlSingleLine.h" #include "SelectionController.h" @@ -219,7 +219,7 @@ void InputElement::handleBeforeTextInsertedEvent(InputElementData& data, InputEl textEvent->setText(sanitizeUserInputValue(inputElement, textEvent->text(), appendableLength)); } -void InputElement::parseSizeAttribute(InputElementData& data, Element* element, MappedAttribute* attribute) +void InputElement::parseSizeAttribute(InputElementData& data, Element* element, Attribute* attribute) { data.setSize(attribute->isNull() ? InputElement::s_defaultSize : attribute->value().toInt()); @@ -227,7 +227,7 @@ void InputElement::parseSizeAttribute(InputElementData& data, Element* element, renderer->setNeedsLayoutAndPrefWidthsRecalc(); } -void InputElement::parseMaxLengthAttribute(InputElementData& data, InputElement* inputElement, Element* element, MappedAttribute* attribute) +void InputElement::parseMaxLengthAttribute(InputElementData& data, InputElement* inputElement, Element* element, Attribute* attribute) { int maxLength = attribute->isNull() ? InputElement::s_maximumLength : attribute->value().toInt(); if (maxLength <= 0 || maxLength > InputElement::s_maximumLength) diff --git a/WebCore/dom/InputElement.h b/WebCore/dom/InputElement.h index bdd5645..d477046 100644 --- a/WebCore/dom/InputElement.h +++ b/WebCore/dom/InputElement.h @@ -26,11 +26,11 @@ namespace WebCore { +class Attribute; class Document; class Element; class Event; class InputElementData; -class MappedAttribute; class InputElement { public: @@ -80,8 +80,8 @@ protected: // This should be applied to values specified by users. static String sanitizeUserInputValue(const InputElement*, const String&, int); static void handleBeforeTextInsertedEvent(InputElementData&, InputElement*, Element*, Event*); - static void parseSizeAttribute(InputElementData&, Element*, MappedAttribute*); - static void parseMaxLengthAttribute(InputElementData&, InputElement*, Element*, MappedAttribute*); + static void parseSizeAttribute(InputElementData&, Element*, Attribute*); + static void parseMaxLengthAttribute(InputElementData&, InputElement*, Element*, Attribute*); static void updateValueIfNeeded(InputElementData&, InputElement*); static void notifyFormStateChanged(Element*); #if ENABLE(WCSS) diff --git a/WebCore/dom/MappedAttribute.cpp b/WebCore/dom/MappedAttribute.cpp deleted file mode 100644 index 17d32c0..0000000 --- a/WebCore/dom/MappedAttribute.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (C) 1999 Lars Knoll (knoll@kde.org) - * (C) 1999 Antti Koivisto (koivisto@kde.org) - * (C) 2001 Peter Kelly (pmk@post.com) - * (C) 2001 Dirk Mueller (mueller@kde.org) - * Copyright (C) 2004, 2005, 2006, 2008 Apple Inc. All rights reserved. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "config.h" -#include "MappedAttribute.h" - -namespace WebCore { - -PassRefPtr<Attribute> MappedAttribute::clone() const -{ - return adoptRef(new MappedAttribute(name(), value(), m_styleDecl.get())); -} - -} diff --git a/WebCore/dom/MappedAttribute.h b/WebCore/dom/MappedAttribute.h deleted file mode 100644 index 4167e30..0000000 --- a/WebCore/dom/MappedAttribute.h +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (C) 1999 Lars Knoll (knoll@kde.org) - * (C) 1999 Antti Koivisto (koivisto@kde.org) - * (C) 2001 Peter Kelly (pmk@post.com) - * (C) 2001 Dirk Mueller (mueller@kde.org) - * Copyright (C) 2003, 2004, 2005, 2006, 2008 Apple Inc. All rights reserved. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - * - */ - -#ifndef MappedAttribute_h -#define MappedAttribute_h - -#include "Attribute.h" -#include "CSSMappedAttributeDeclaration.h" - -namespace WebCore { - -class MappedAttribute : public Attribute { -public: - static PassRefPtr<MappedAttribute> create(const QualifiedName& name, const AtomicString& value) - { - return adoptRef(new MappedAttribute(name, value, 0)); - } - static PassRefPtr<MappedAttribute> create(const AtomicString& name, const AtomicString& value) - { - return adoptRef(new MappedAttribute(name, value, 0)); - } - - virtual PassRefPtr<Attribute> clone() const; - - virtual CSSStyleDeclaration* style() const { return m_styleDecl.get(); } - - virtual bool isMappedAttribute() { return true; } - - CSSMappedAttributeDeclaration* decl() const { return m_styleDecl.get(); } - void setDecl(PassRefPtr<CSSMappedAttributeDeclaration> decl) { m_styleDecl = decl; } - -private: - MappedAttribute(const QualifiedName& name, const AtomicString& value, CSSMappedAttributeDeclaration* declaration) - : Attribute(name, value), m_styleDecl(declaration) - { - } - MappedAttribute(const AtomicString& name, const AtomicString& value, CSSMappedAttributeDeclaration* declaration) - : Attribute(name, value), m_styleDecl(declaration) - { - } - - RefPtr<CSSMappedAttributeDeclaration> m_styleDecl; -}; - -} //namespace - -#endif diff --git a/WebCore/dom/NamedAttrMap.h b/WebCore/dom/NamedAttrMap.h deleted file mode 100644 index e292576..0000000 --- a/WebCore/dom/NamedAttrMap.h +++ /dev/null @@ -1,151 +0,0 @@ -/* - * Copyright (C) 1999 Lars Knoll (knoll@kde.org) - * (C) 1999 Antti Koivisto (koivisto@kde.org) - * (C) 2001 Peter Kelly (pmk@post.com) - * (C) 2001 Dirk Mueller (mueller@kde.org) - * Copyright (C) 2003, 2004, 2005, 2006, 2008 Apple Inc. All rights reserved. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - * - */ - -#ifndef NamedAttrMap_h -#define NamedAttrMap_h - -#include "Attribute.h" - -#ifdef __OBJC__ -#define id id_AVOID_KEYWORD -#endif - -namespace WebCore { - -class Node; - -typedef int ExceptionCode; - -class NamedNodeMap : public RefCounted<NamedNodeMap> { - friend class Element; - -protected: - NamedNodeMap(Element* element) : m_element(element) { } - -public: - static PassRefPtr<NamedNodeMap> create(Element* element) { return adoptRef(new NamedNodeMap(element)); } - - virtual ~NamedNodeMap(); - - // Public DOM interface. - - PassRefPtr<Node> getNamedItem(const String& name) const; - PassRefPtr<Node> removeNamedItem(const String& name, ExceptionCode&); - - PassRefPtr<Node> getNamedItemNS(const String& namespaceURI, const String& localName) const; - PassRefPtr<Node> removeNamedItemNS(const String& namespaceURI, const String& localName, ExceptionCode&); - - PassRefPtr<Node> getNamedItem(const QualifiedName& name) const; - PassRefPtr<Node> removeNamedItem(const QualifiedName& name, ExceptionCode&); - PassRefPtr<Node> setNamedItem(Node*, ExceptionCode&); - PassRefPtr<Node> setNamedItemNS(Node* node, ExceptionCode& ec) { return setNamedItem(node, ec); } - - PassRefPtr<Node> item(unsigned index) const; - size_t length() const { return m_attributes.size(); } - bool isEmpty() const { return !length(); } - - // Internal interface. - - void setAttributes(const NamedNodeMap&); - - Attribute* attributeItem(unsigned index) const { return m_attributes[index].get(); } - Attribute* getAttributeItem(const QualifiedName&) const; - - void copyAttributesToVector(Vector<RefPtr<Attribute> >&); - - void shrinkToLength() { m_attributes.shrinkCapacity(length()); } - void reserveInitialCapacity(unsigned capacity) { m_attributes.reserveInitialCapacity(capacity); } - - // Used during parsing: only inserts if not already there. No error checking! - void insertAttribute(PassRefPtr<Attribute> newAttribute, bool allowDuplicates) - { - ASSERT(!m_element); - if (allowDuplicates || !getAttributeItem(newAttribute->name())) - addAttribute(newAttribute); - } - - virtual bool isMappedAttributeMap() const; - - const AtomicString& id() const { return m_id; } - void setID(const AtomicString& newId) { m_id = newId; } - - bool mapsEquivalent(const NamedNodeMap* otherMap) const; - - // These functions do no error checking. - void addAttribute(PassRefPtr<Attribute>); - void removeAttribute(const QualifiedName&); - - Element* element() const { return m_element; } - -protected: - virtual void clearAttributes(); - -private: - void detachAttributesFromElement(); - void detachFromElement(); - Attribute* getAttributeItem(const String& name, bool shouldIgnoreAttributeCase) const; - Attribute* getAttributeItemSlowCase(const String& name, bool shouldIgnoreAttributeCase) const; - - Element* m_element; - Vector<RefPtr<Attribute> > m_attributes; - AtomicString m_id; -}; - -inline Attribute* NamedNodeMap::getAttributeItem(const QualifiedName& name) const -{ - unsigned len = length(); - for (unsigned i = 0; i < len; ++i) { - if (m_attributes[i]->name().matches(name)) - return m_attributes[i].get(); - } - return 0; -} - -// We use a boolean parameter instead of calling shouldIgnoreAttributeCase so that the caller -// can tune the behaviour (hasAttribute is case sensitive whereas getAttribute is not). -inline Attribute* NamedNodeMap::getAttributeItem(const String& name, bool shouldIgnoreAttributeCase) const -{ - unsigned len = length(); - bool doSlowCheck = shouldIgnoreAttributeCase; - - // Optimize for the case where the attribute exists and its name exactly matches. - for (unsigned i = 0; i < len; ++i) { - const QualifiedName& attrName = m_attributes[i]->name(); - if (!attrName.hasPrefix()) { - if (name == attrName.localName()) - return m_attributes[i].get(); - } else - doSlowCheck = true; - } - - if (doSlowCheck) - return getAttributeItemSlowCase(name, shouldIgnoreAttributeCase); - return 0; -} - -} //namespace - -#undef id - -#endif diff --git a/WebCore/dom/NamedMappedAttrMap.cpp b/WebCore/dom/NamedMappedAttrMap.cpp deleted file mode 100644 index d8e3c80..0000000 --- a/WebCore/dom/NamedMappedAttrMap.cpp +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright (C) 1999 Lars Knoll (knoll@kde.org) - * (C) 1999 Antti Koivisto (koivisto@kde.org) - * (C) 2001 Peter Kelly (pmk@post.com) - * (C) 2001 Dirk Mueller (mueller@kde.org) - * (C) 2007 David Smith (catfish.man@gmail.com) - * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "config.h" -#include "NamedMappedAttrMap.h" - -#include "Document.h" -#include "Element.h" -#include "MappedAttribute.h" - -namespace WebCore { - -void NamedMappedAttrMap::clearAttributes() -{ - m_classNames.clear(); - m_mappedAttributeCount = 0; - NamedNodeMap::clearAttributes(); -} - -bool NamedMappedAttrMap::isMappedAttributeMap() const -{ - return true; -} - -int NamedMappedAttrMap::declCount() const -{ - int result = 0; - for (unsigned i = 0; i < length(); i++) { - Attribute* attr = attributeItem(i); - if (attr->isMappedAttribute() && - static_cast<MappedAttribute*>(attr)->decl()) - result++; - } - return result; -} - -bool NamedMappedAttrMap::mapsEquivalent(const NamedMappedAttrMap* otherMap) const -{ - // The # of decls must match. - if (declCount() != otherMap->declCount()) - return false; - - // The values for each decl must match. - for (unsigned i = 0; i < length(); i++) { - Attribute* attr = attributeItem(i); - if (attr->isMappedAttribute() && - static_cast<MappedAttribute*>(attr)->decl()) { - Attribute* otherAttr = otherMap->getAttributeItem(attr->name()); - if (!otherAttr || (attr->value() != otherAttr->value())) - return false; - } - } - return true; -} - -void NamedMappedAttrMap::setClass(const String& classStr) -{ - if (!element()->hasClass()) { - m_classNames.clear(); - return; - } - - m_classNames.set(classStr, element()->document()->inCompatMode()); -} - -} diff --git a/WebCore/dom/NamedMappedAttrMap.h b/WebCore/dom/NamedMappedAttrMap.h deleted file mode 100644 index a288685..0000000 --- a/WebCore/dom/NamedMappedAttrMap.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (C) 1999 Lars Knoll (knoll@kde.org) - * (C) 1999 Antti Koivisto (koivisto@kde.org) - * (C) 2001 Peter Kelly (pmk@post.com) - * (C) 2001 Dirk Mueller (mueller@kde.org) - * (C) 2007 David Smith (catfish.man@gmail.com) - * Copyright (C) 2003, 2004, 2005, 2006, 2008, 2009 Apple Inc. All rights reserved. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - * - */ - -#ifndef NamedMappedAttrMap_h -#define NamedMappedAttrMap_h - -#include "NamedNodeMap.h" -#include "SpaceSplitString.h" - -namespace WebCore { - -class NamedMappedAttrMap : public NamedNodeMap { -public: - static PassRefPtr<NamedMappedAttrMap> create(Element* element = 0) { return adoptRef(new NamedMappedAttrMap(element)); } - - void clearClass() { m_classNames.clear(); } - void setClass(const String&); - const SpaceSplitString& classNames() const { return m_classNames; } - - bool hasMappedAttributes() const { return m_mappedAttributeCount > 0; } - void declRemoved() { m_mappedAttributeCount--; } - void declAdded() { m_mappedAttributeCount++; } - - bool mapsEquivalent(const NamedMappedAttrMap*) const; - -private: - NamedMappedAttrMap(Element* element) : NamedNodeMap(element), m_mappedAttributeCount(0) { } - - virtual void clearAttributes(); - virtual bool isMappedAttributeMap() const; - - int declCount() const; - - SpaceSplitString m_classNames; - int m_mappedAttributeCount; -}; - -} //namespace - -#endif diff --git a/WebCore/dom/NamedAttrMap.cpp b/WebCore/dom/NamedNodeMap.cpp index ee979cf..e310ff8 100644 --- a/WebCore/dom/NamedAttrMap.cpp +++ b/WebCore/dom/NamedNodeMap.cpp @@ -54,11 +54,6 @@ NamedNodeMap::~NamedNodeMap() detachAttributesFromElement(); } -bool NamedNodeMap::isMappedAttributeMap() const -{ - return false; -} - PassRefPtr<Node> NamedNodeMap::getNamedItem(const String& name) const { Attribute* a = getAttributeItem(name, shouldIgnoreAttributeCase(m_element)); @@ -144,6 +139,11 @@ PassRefPtr<Node> NamedNodeMap::setNamedItem(Node* arg, ExceptionCode& ec) return r.release(); } +PassRefPtr<Node> NamedNodeMap::setNamedItemNS(Node* node, ExceptionCode& ec) +{ + return setNamedItem(node, ec); +} + // The DOM2 spec doesn't say that removeAttribute[NS] throws NOT_FOUND_ERR // if the attribute is not found, but at this level we have to throw NOT_FOUND_ERR // because of removeNamedItem, removeNamedItemNS, and removeAttributeNode. @@ -200,6 +200,9 @@ Attribute* NamedNodeMap::getAttributeItemSlowCase(const String& name, bool shoul void NamedNodeMap::clearAttributes() { + m_classNames.clear(); + m_mappedAttributeCount = 0; + detachAttributesFromElement(); m_attributes.clear(); } @@ -299,6 +302,29 @@ void NamedNodeMap::removeAttribute(const QualifiedName& name) } } +void NamedNodeMap::setClass(const String& classStr) +{ + if (!element()->hasClass()) { + m_classNames.clear(); + return; + } + + m_classNames.set(classStr, element()->document()->inCompatMode()); +} + +int NamedNodeMap::declCount() const +{ + int result = 0; + for (unsigned i = 0; i < length(); i++) { + Attribute* attr = attributeItem(i); + if (attr->decl()) { + ASSERT(attr->isMappedAttribute()); + result++; + } + } + return result; +} + bool NamedNodeMap::mapsEquivalent(const NamedNodeMap* otherMap) const { if (!otherMap) @@ -309,9 +335,8 @@ bool NamedNodeMap::mapsEquivalent(const NamedNodeMap* otherMap) const return false; for (unsigned i = 0; i < len; i++) { - Attribute *attr = attributeItem(i); - Attribute *otherAttr = otherMap->getAttributeItem(attr->name()); - + Attribute* attr = attributeItem(i); + Attribute* otherAttr = otherMap->getAttributeItem(attr->name()); if (!otherAttr || attr->value() != otherAttr->value()) return false; } @@ -319,4 +344,24 @@ bool NamedNodeMap::mapsEquivalent(const NamedNodeMap* otherMap) const return true; } +bool NamedNodeMap::mappedMapsEquivalent(const NamedNodeMap* otherMap) const +{ + // The # of decls must match. + if (declCount() != otherMap->declCount()) + return false; + + // The values for each decl must match. + for (unsigned i = 0; i < length(); i++) { + Attribute* attr = attributeItem(i); + if (attr->decl()) { + ASSERT(attr->isMappedAttribute()); + + Attribute* otherAttr = otherMap->getAttributeItem(attr->name()); + if (!otherAttr || attr->value() != otherAttr->value()) + return false; + } + } + return true; } + +} // namespace WebCore diff --git a/WebCore/dom/NamedNodeMap.h b/WebCore/dom/NamedNodeMap.h index 37ef870..50cb4cb 100644 --- a/WebCore/dom/NamedNodeMap.h +++ b/WebCore/dom/NamedNodeMap.h @@ -1 +1,166 @@ -#include "NamedAttrMap.h" +/* + * Copyright (C) 1999 Lars Knoll (knoll@kde.org) + * (C) 1999 Antti Koivisto (koivisto@kde.org) + * (C) 2001 Peter Kelly (pmk@post.com) + * (C) 2001 Dirk Mueller (mueller@kde.org) + * Copyright (C) 2003, 2004, 2005, 2006, 2008 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#ifndef NamedNodeMap_h +#define NamedNodeMap_h + +#include "Attribute.h" +#include "SpaceSplitString.h" + +#ifdef __OBJC__ +#define id id_AVOID_KEYWORD +#endif + +namespace WebCore { + +class Node; + +typedef int ExceptionCode; + +class NamedNodeMap : public RefCounted<NamedNodeMap> { + friend class Element; +public: + static PassRefPtr<NamedNodeMap> create(Element* element = 0) + { + return adoptRef(new NamedNodeMap(element)); + } + + ~NamedNodeMap(); + + // Public DOM interface. + + PassRefPtr<Node> getNamedItem(const String& name) const; + PassRefPtr<Node> removeNamedItem(const String& name, ExceptionCode&); + + PassRefPtr<Node> getNamedItemNS(const String& namespaceURI, const String& localName) const; + PassRefPtr<Node> removeNamedItemNS(const String& namespaceURI, const String& localName, ExceptionCode&); + + PassRefPtr<Node> getNamedItem(const QualifiedName& name) const; + PassRefPtr<Node> removeNamedItem(const QualifiedName& name, ExceptionCode&); + PassRefPtr<Node> setNamedItem(Node*, ExceptionCode&); + PassRefPtr<Node> setNamedItemNS(Node*, ExceptionCode&); + + PassRefPtr<Node> item(unsigned index) const; + size_t length() const { return m_attributes.size(); } + bool isEmpty() const { return !length(); } + + // Internal interface. + + void setAttributes(const NamedNodeMap&); + + Attribute* attributeItem(unsigned index) const { return m_attributes[index].get(); } + Attribute* getAttributeItem(const QualifiedName&) const; + + void copyAttributesToVector(Vector<RefPtr<Attribute> >&); + + void shrinkToLength() { m_attributes.shrinkCapacity(length()); } + void reserveInitialCapacity(unsigned capacity) { m_attributes.reserveInitialCapacity(capacity); } + + // Used during parsing: only inserts if not already there. No error checking! + void insertAttribute(PassRefPtr<Attribute> newAttribute, bool allowDuplicates) + { + ASSERT(!m_element); + if (allowDuplicates || !getAttributeItem(newAttribute->name())) + addAttribute(newAttribute); + } + + const AtomicString& id() const { return m_id; } + void setID(const AtomicString& newId) { m_id = newId; } + + // FIXME: These two functions should be merged if possible. + bool mapsEquivalent(const NamedNodeMap* otherMap) const; + bool mappedMapsEquivalent(const NamedNodeMap* otherMap) const; + + // These functions do no error checking. + void addAttribute(PassRefPtr<Attribute>); + void removeAttribute(const QualifiedName&); + + Element* element() const { return m_element; } + + void clearClass() { m_classNames.clear(); } + void setClass(const String&); + const SpaceSplitString& classNames() const { return m_classNames; } + + bool hasMappedAttributes() const { return m_mappedAttributeCount > 0; } + void declRemoved() { m_mappedAttributeCount--; } + void declAdded() { m_mappedAttributeCount++; } + +private: + NamedNodeMap(Element* element) + : m_mappedAttributeCount(0) + , m_element(element) + { + } + + void detachAttributesFromElement(); + void detachFromElement(); + Attribute* getAttributeItem(const String& name, bool shouldIgnoreAttributeCase) const; + Attribute* getAttributeItemSlowCase(const String& name, bool shouldIgnoreAttributeCase) const; + void clearAttributes(); + int declCount() const; + + int m_mappedAttributeCount; + SpaceSplitString m_classNames; + Element* m_element; + Vector<RefPtr<Attribute> > m_attributes; + AtomicString m_id; +}; + +inline Attribute* NamedNodeMap::getAttributeItem(const QualifiedName& name) const +{ + unsigned len = length(); + for (unsigned i = 0; i < len; ++i) { + if (m_attributes[i]->name().matches(name)) + return m_attributes[i].get(); + } + return 0; +} + +// We use a boolean parameter instead of calling shouldIgnoreAttributeCase so that the caller +// can tune the behaviour (hasAttribute is case sensitive whereas getAttribute is not). +inline Attribute* NamedNodeMap::getAttributeItem(const String& name, bool shouldIgnoreAttributeCase) const +{ + unsigned len = length(); + bool doSlowCheck = shouldIgnoreAttributeCase; + + // Optimize for the case where the attribute exists and its name exactly matches. + for (unsigned i = 0; i < len; ++i) { + const QualifiedName& attrName = m_attributes[i]->name(); + if (!attrName.hasPrefix()) { + if (name == attrName.localName()) + return m_attributes[i].get(); + } else + doSlowCheck = true; + } + + if (doSlowCheck) + return getAttributeItemSlowCase(name, shouldIgnoreAttributeCase); + return 0; +} + +} // namespace WebCore + +#undef id + +#endif // NamedNodeMap_h diff --git a/WebCore/dom/NamedNodeMap.idl b/WebCore/dom/NamedNodeMap.idl index 7bfbf23..4d36577 100644 --- a/WebCore/dom/NamedNodeMap.idl +++ b/WebCore/dom/NamedNodeMap.idl @@ -28,7 +28,7 @@ module core { Node getNamedItem(in DOMString name); - [Custom] Node setNamedItem(in Node node) + Node setNamedItem(in Node node) raises(DOMException); Node removeNamedItem(in DOMString name) @@ -46,7 +46,7 @@ module core { // FIXME: the implementation does take an exceptioncode parameter. /*raises(DOMException)*/; - [Custom] Node setNamedItemNS(in Node node) + Node setNamedItemNS(in Node node) raises(DOMException); [OldStyleObjC] Node removeNamedItemNS(in [ConvertNullToNullString] DOMString namespaceURI, diff --git a/WebCore/dom/Node.cpp b/WebCore/dom/Node.cpp index eb36417..a7d416a 100644 --- a/WebCore/dom/Node.cpp +++ b/WebCore/dom/Node.cpp @@ -31,6 +31,7 @@ #endif #include "Attr.h" +#include "Attribute.h" #include "CSSParser.h" #include "CSSRule.h" #include "CSSRuleList.h" @@ -58,7 +59,6 @@ #include "InspectorTimelineAgent.h" #include "KeyboardEvent.h" #include "Logging.h" -#include "MappedAttribute.h" #include "MouseEvent.h" #include "MutationEvent.h" #include "NameNodeList.h" @@ -84,11 +84,11 @@ #include "WheelEvent.h" #include "XMLNames.h" #include "htmlediting.h" -#include <wtf/text/CString.h> #include <wtf/HashSet.h> #include <wtf/PassOwnPtr.h> #include <wtf/RefCountedLeakCounter.h> #include <wtf/UnusedParam.h> +#include <wtf/text/CString.h> #if ENABLE(DOM_STORAGE) #include "StorageEvent.h" @@ -152,7 +152,6 @@ void Node::dumpStatistics() size_t mappedAttributesWithStyleDecl = 0; size_t attributesWithAttr = 0; size_t attrMaps = 0; - size_t mappedAttrMaps = 0; for (HashSet<Node*>::iterator it = liveNodeSet.begin(); it != liveNodeSet.end(); ++it) { Node* node = *it; @@ -174,8 +173,6 @@ void Node::dumpStatistics() if (NamedNodeMap* attrMap = element->attributes(true)) { attributes += attrMap->length(); ++attrMaps; - if (attrMap->isMappedAttributeMap()) - ++mappedAttrMaps; for (unsigned i = 0; i < attrMap->length(); ++i) { Attribute* attr = attrMap->attributeItem(i); if (attr->attr()) @@ -238,7 +235,6 @@ void Node::dumpStatistics() break; } } - } printf("Number of Nodes: %d\n\n", liveNodeSet.size()); @@ -265,11 +261,10 @@ void Node::dumpStatistics() printf("Attribute Maps:\n"); printf(" Number of Attributes (non-Node and Node): %zu [%zu]\n", attributes, sizeof(Attribute)); - printf(" Number of MappedAttributes: %zu [%zu]\n", mappedAttributes, sizeof(MappedAttribute)); - printf(" Number of MappedAttributes with a StyleDeclaration: %zu\n", mappedAttributesWithStyleDecl); + printf(" Number of Attributes that are mapped: %zu\n", mappedAttributes); + printf(" Number of Attributes with a StyleDeclaration: %zu\n", mappedAttributesWithStyleDecl); printf(" Number of Attributes with an Attr: %zu\n", attributesWithAttr); - printf(" Number of NamedNodeMaps: %zu\n", attrMaps); - printf(" Number of NamedMappedAttrMap: %zu\n", mappedAttrMaps); + printf(" Number of NamedNodeMaps: %zu [%zu]\n", attrMaps, sizeof(NamedNodeMap)); #endif } diff --git a/WebCore/dom/Node.idl b/WebCore/dom/Node.idl index 7bc6d1d..2db9c27 100644 --- a/WebCore/dom/Node.idl +++ b/WebCore/dom/Node.idl @@ -51,7 +51,7 @@ module core { readonly attribute [ConvertNullStringTo=Null] DOMString nodeName; // FIXME: the spec says this can also raise on retrieval. - attribute [CustomSetter, ConvertNullStringTo=Null, ConvertNullToNullString] DOMString nodeValue + attribute [ConvertNullStringTo=Null, ConvertNullToNullString] DOMString nodeValue setter raises(DOMException); readonly attribute unsigned short nodeType; @@ -96,7 +96,7 @@ module core { readonly attribute [ConvertNullStringTo=Null] DOMString baseURI; // FIXME: the spec says this can also raise on retrieval. - attribute [CustomSetter, ConvertNullStringTo=Null, ConvertNullToNullString] DOMString textContent + attribute [ConvertNullStringTo=Null, ConvertNullToNullString] DOMString textContent setter raises(DOMException); boolean isSameNode(in Node other); diff --git a/WebCore/dom/Position.h b/WebCore/dom/Position.h index 591b0e6..ce06f48 100644 --- a/WebCore/dom/Position.h +++ b/WebCore/dom/Position.h @@ -117,6 +117,7 @@ public: bool isNull() const { return !m_anchorNode; } bool isNotNull() const { return m_anchorNode; } + bool isOrphan() const { return m_anchorNode && !m_anchorNode->inDocument(); } Element* element() const; PassRefPtr<CSSComputedStyleDeclaration> computedStyle() const; diff --git a/WebCore/dom/ScriptElement.cpp b/WebCore/dom/ScriptElement.cpp index 22d6981..b457f5d 100644 --- a/WebCore/dom/ScriptElement.cpp +++ b/WebCore/dom/ScriptElement.cpp @@ -32,9 +32,11 @@ #include "HTMLNames.h" #include "HTMLScriptElement.h" #include "MIMETypeRegistry.h" +#include "Page.h" #include "ScriptController.h" #include "ScriptSourceCode.h" #include "ScriptValue.h" +#include "Settings.h" #include "StringHash.h" #include "Text.h" #include <wtf/StdLibExtras.h> @@ -82,12 +84,28 @@ void ScriptElement::childrenChanged(ScriptElementData& data) data.evaluateScript(ScriptSourceCode(data.scriptContent(), element->document()->url())); // FIXME: Provide a real starting line number here } +static inline bool useHTML5Parser(Document* document) +{ + ASSERT(document); + Settings* settings = document->page() ? document->page()->settings() : 0; + return settings && settings->html5ParserEnabled(); +} + void ScriptElement::finishParsingChildren(ScriptElementData& data, const String& sourceUrl) { // The parser just reached </script>. If we have no src and no text, // allow dynamic loading later. if (sourceUrl.isEmpty() && data.scriptContent().isEmpty()) data.setCreatedByParser(false); + // HTML5 Requires that we execute scripts from the parser, not from + // HTMLTokenizer like we currently do. + // FIXME: It may not be safe to execute scripts from here if + // HTMLParser::popOneBlockCommon is not reentrant. + else if (useHTML5Parser(data.element()->document())) { + // This is currently an incomplete implementation, see: + // http://www.whatwg.org/specs/web-apps/current-work/multipage/tokenization.html#parsing-main-incdata + data.evaluateScript(ScriptSourceCode(data.scriptContent(), data.element()->document()->url())); // FIXME: Provide a real starting line number here + } } void ScriptElement::handleSourceAttribute(ScriptElementData& data, const String& sourceUrl) diff --git a/WebCore/dom/SelectElement.cpp b/WebCore/dom/SelectElement.cpp index fb7d9a6..c7052b3 100644 --- a/WebCore/dom/SelectElement.cpp +++ b/WebCore/dom/SelectElement.cpp @@ -21,6 +21,7 @@ #include "config.h" #include "SelectElement.h" +#include "Attribute.h" #include "CharacterNames.h" #include "Chrome.h" #include "ChromeClient.h" @@ -30,11 +31,10 @@ #include "FormDataList.h" #include "Frame.h" #include "HTMLFormElement.h" -#include "HTMLNames.h" #include "HTMLKeygenElement.h" +#include "HTMLNames.h" #include "HTMLSelectElement.h" #include "KeyboardEvent.h" -#include "MappedAttribute.h" #include "MouseEvent.h" #include "OptionElement.h" #include "OptionGroupElement.h" @@ -443,7 +443,7 @@ void SelectElement::restoreFormControlState(SelectElementData& data, Element* el setOptionsChangedOnRenderer(data, element); } -void SelectElement::parseMultipleAttribute(SelectElementData& data, Element* element, MappedAttribute* attribute) +void SelectElement::parseMultipleAttribute(SelectElementData& data, Element* element, Attribute* attribute) { bool oldUsesMenuList = data.usesMenuList(); data.setMultiple(!attribute->isNull()); diff --git a/WebCore/dom/SelectElement.h b/WebCore/dom/SelectElement.h index 6db841e..493bee5 100644 --- a/WebCore/dom/SelectElement.h +++ b/WebCore/dom/SelectElement.h @@ -27,12 +27,12 @@ namespace WebCore { +class Attribute; class Element; class Event; class FormDataList; class HTMLFormElement; class KeyboardEvent; -class MappedAttribute; class SelectElementData; class String; @@ -89,7 +89,7 @@ protected: static void deselectItems(SelectElementData&, Element*, Element* excludeElement = 0); static bool saveFormControlState(const SelectElementData&, const Element*, String& state); static void restoreFormControlState(SelectElementData&, Element*, const String& state); - static void parseMultipleAttribute(SelectElementData&, Element*, MappedAttribute*); + static void parseMultipleAttribute(SelectElementData&, Element*, Attribute*); static bool appendFormData(SelectElementData&, Element*, FormDataList&); static void reset(SelectElementData&, Element*); static void defaultEventHandler(SelectElementData&, Element*, Event*); diff --git a/WebCore/dom/StyleElement.cpp b/WebCore/dom/StyleElement.cpp index f881179..a323e16 100644 --- a/WebCore/dom/StyleElement.cpp +++ b/WebCore/dom/StyleElement.cpp @@ -21,9 +21,9 @@ #include "config.h" #include "StyleElement.h" +#include "Attribute.h" #include "Document.h" #include "Element.h" -#include "MappedAttribute.h" #include "MediaList.h" #include "MediaQueryEvaluator.h" diff --git a/WebCore/dom/StyledElement.cpp b/WebCore/dom/StyledElement.cpp index cd5f863..34a593c 100644 --- a/WebCore/dom/StyledElement.cpp +++ b/WebCore/dom/StyledElement.cpp @@ -24,12 +24,12 @@ #include "config.h" #include "StyledElement.h" +#include "Attribute.h" #include "CSSStyleSelector.h" #include "CSSStyleSheet.h" #include "CSSValueKeywords.h" #include "Document.h" #include "HTMLNames.h" -#include "MappedAttribute.h" #include <wtf/HashFunctions.h> using namespace std; @@ -118,7 +118,7 @@ StyledElement::~StyledElement() PassRefPtr<Attribute> StyledElement::createAttribute(const QualifiedName& name, const AtomicString& value) { - return MappedAttribute::create(name, value); + return Attribute::createMapped(name, value); } void StyledElement::createInlineStyleDecl() @@ -145,9 +145,8 @@ void StyledElement::attributeChanged(Attribute* attr, bool preserveDecls) return; } - MappedAttribute* mappedAttr = static_cast<MappedAttribute*>(attr); - if (mappedAttr->decl() && !preserveDecls) { - mappedAttr->setDecl(0); + if (attr->decl() && !preserveDecls) { + attr->setDecl(0); setNeedsStyleRecalc(); if (namedAttrMap) mappedAttributes()->declRemoved(); @@ -157,17 +156,16 @@ void StyledElement::attributeChanged(Attribute* attr, bool preserveDecls) MappedAttributeEntry entry; bool needToParse = mapToEntry(attr->name(), entry); if (preserveDecls) { - if (mappedAttr->decl()) { + if (attr->decl()) { setNeedsStyleRecalc(); if (namedAttrMap) mappedAttributes()->declAdded(); checkDecl = false; } - } - else if (!attr->isNull() && entry != eNone) { + } else if (!attr->isNull() && entry != eNone) { CSSMappedAttributeDeclaration* decl = getMappedAttributeDecl(entry, attr); if (decl) { - mappedAttr->setDecl(decl); + attr->setDecl(decl); setNeedsStyleRecalc(); if (namedAttrMap) mappedAttributes()->declAdded(); @@ -182,17 +180,17 @@ void StyledElement::attributeChanged(Attribute* attr, bool preserveDecls) // If that changes for some reason moving between documents will be buggy. // webarchive/adopt-attribute-styled-node-webarchive.html should catch any resulting crashes. if (needToParse) - parseMappedAttribute(mappedAttr); + parseMappedAttribute(attr); if (entry == eNone) recalcStyleIfNeededAfterAttributeChanged(attr); - if (checkDecl && mappedAttr->decl()) { + if (checkDecl && attr->decl()) { // Add the decl to the table in the appropriate spot. - setMappedAttributeDecl(entry, attr, mappedAttr->decl()); - mappedAttr->decl()->setMappedState(entry, attr->name(), attr->value()); - mappedAttr->decl()->setParent(0); - mappedAttr->decl()->setNode(0); + setMappedAttributeDecl(entry, attr, attr->decl()); + attr->decl()->setMappedState(entry, attr->name(), attr->value()); + attr->decl()->setParent(0); + attr->decl()->setNode(0); if (namedAttrMap) mappedAttributes()->declAdded(); } @@ -227,7 +225,7 @@ void StyledElement::classAttributeChanged(const AtomicString& newClassString) dispatchSubtreeModifiedEvent(); } -void StyledElement::parseMappedAttribute(MappedAttribute *attr) +void StyledElement::parseMappedAttribute(Attribute* attr) { if (attr->name() == idAttributeName()) { // unique id @@ -253,11 +251,6 @@ void StyledElement::parseMappedAttribute(MappedAttribute *attr) } } -void StyledElement::createAttributeMap() const -{ - namedAttrMap = NamedMappedAttrMap::create(const_cast<StyledElement*>(this)); -} - CSSMutableStyleDeclaration* StyledElement::getInlineStyleDecl() { if (!m_inlineStyleDecl) @@ -270,25 +263,25 @@ CSSStyleDeclaration* StyledElement::style() return getInlineStyleDecl(); } -void StyledElement::addCSSProperty(MappedAttribute* attr, int id, const String &value) +void StyledElement::addCSSProperty(Attribute* attr, int id, const String &value) { if (!attr->decl()) createMappedDecl(attr); attr->decl()->setProperty(id, value, false); } -void StyledElement::addCSSProperty(MappedAttribute* attr, int id, int value) +void StyledElement::addCSSProperty(Attribute* attr, int id, int value) { if (!attr->decl()) createMappedDecl(attr); attr->decl()->setProperty(id, value, false); } -void StyledElement::addCSSImageProperty(MappedAttribute* attr, int id, const String& url) +void StyledElement::addCSSImageProperty(Attribute* attr, int id, const String& url) { if (!attr->decl()) createMappedDecl(attr); attr->decl()->setImageProperty(id, url, false); } -void StyledElement::addCSSLength(MappedAttribute* attr, int id, const String &value) +void StyledElement::addCSSLength(Attribute* attr, int id, const String &value) { // FIXME: This function should not spin up the CSS parser, but should instead just figure out the correct // length unit and make the appropriate parsed value. @@ -325,7 +318,7 @@ void StyledElement::addCSSLength(MappedAttribute* attr, int id, const String &va } /* color parsing that tries to match as close as possible IE 6. */ -void StyledElement::addCSSColor(MappedAttribute* attr, int id, const String& c) +void StyledElement::addCSSColor(Attribute* attr, int id, const String& c) { // this is the only case no color gets applied in IE. if (!c.length()) @@ -397,7 +390,7 @@ void StyledElement::addCSSColor(MappedAttribute* attr, int id, const String& c) attr->decl()->setProperty(id, CSSValueBlack, false); } -void StyledElement::createMappedDecl(MappedAttribute* attr) +void StyledElement::createMappedDecl(Attribute* attr) { RefPtr<CSSMappedAttributeDeclaration> decl = CSSMappedAttributeDeclaration::create(); attr->setDecl(decl); diff --git a/WebCore/dom/StyledElement.h b/WebCore/dom/StyledElement.h index 279282c..6facce7 100644 --- a/WebCore/dom/StyledElement.h +++ b/WebCore/dom/StyledElement.h @@ -29,28 +29,28 @@ #include "CSSPrimitiveValue.h" #include "Element.h" #include "MappedAttributeEntry.h" -#include "NamedMappedAttrMap.h" +#include "NamedNodeMap.h" namespace WebCore { +class Attribute; class CSSMappedAttributeDeclaration; -class MappedAttribute; class StyledElement : public Element { public: virtual ~StyledElement(); - NamedMappedAttrMap* mappedAttributes() { return static_cast<NamedMappedAttrMap*>(namedAttrMap.get()); } - const NamedMappedAttrMap* mappedAttributes() const { return static_cast<NamedMappedAttrMap*>(namedAttrMap.get()); } + NamedNodeMap* mappedAttributes() { return namedAttrMap.get(); } + const NamedNodeMap* mappedAttributes() const { return namedAttrMap.get(); } bool hasMappedAttributes() const { return namedAttrMap && mappedAttributes()->hasMappedAttributes(); } bool isMappedAttribute(const QualifiedName& name) const { MappedAttributeEntry res = eNone; mapToEntry(name, res); return res != eNone; } - void addCSSLength(MappedAttribute*, int id, const String& value); - void addCSSProperty(MappedAttribute*, int id, const String& value); - void addCSSProperty(MappedAttribute*, int id, int value); - void addCSSImageProperty(MappedAttribute*, int propertyID, const String& url); - void addCSSColor(MappedAttribute*, int id, const String& color); + void addCSSLength(Attribute*, int id, const String& value); + void addCSSProperty(Attribute*, int id, const String& value); + void addCSSProperty(Attribute*, int id, int value); + void addCSSImageProperty(Attribute*, int propertyID, const String& url); + void addCSSColor(Attribute*, int id, const String& color); static CSSMappedAttributeDeclaration* getMappedAttributeDecl(MappedAttributeEntry, const QualifiedName& name, const AtomicString& value); static void setMappedAttributeDecl(MappedAttributeEntry, const QualifiedName& name, const AtomicString& value, CSSMappedAttributeDeclaration*); @@ -79,7 +79,7 @@ protected: } virtual void attributeChanged(Attribute*, bool preserveDecls = false); - virtual void parseMappedAttribute(MappedAttribute*); + virtual void parseMappedAttribute(Attribute*); virtual void copyNonAttributeProperties(const Element*); virtual void addSubresourceAttributeURLs(ListHashSet<KURL>&) const; @@ -92,14 +92,12 @@ protected: virtual void didMoveToNewOwnerDocument(); private: - void createMappedDecl(MappedAttribute*); + void createMappedDecl(Attribute*); void createInlineStyleDecl(); void destroyInlineStyleDecl(); virtual void updateStyleAttribute() const; - virtual void createAttributeMap() const; - RefPtr<CSSMutableStyleDeclaration> m_inlineStyleDecl; }; diff --git a/WebCore/dom/Tokenizer.h b/WebCore/dom/Tokenizer.h index 939ac70..d6ac1a8 100644 --- a/WebCore/dom/Tokenizer.h +++ b/WebCore/dom/Tokenizer.h @@ -29,6 +29,9 @@ namespace WebCore { class SegmentedString; class XSSAuditor; + // FIXME: This class should renamed DocumentParser or similar to express + // that it does more than tokenizing. It manages the lifetime of of the + // parser as well as handles various tag-handling hacks for HTML/XML. class Tokenizer : public Noncopyable { public: virtual ~Tokenizer() { } |