Commit 1190b0b7 authored by benjamin@webkit.org's avatar benjamin@webkit.org

Clean ClassList and DOMSettableTokenList

https://bugs.webkit.org/show_bug.cgi?id=120344

Reviewed by Ryosuke Niwa.

This patch cleans ClassList and DOMSettableTokenList to make it simpler to update
SpaceSplitString:
- Move the implementation of virtual functions to the cpp file.
- Clean the #includes.
- Make the implemented pure virtual methods final.
- Make the element() accessor const.

* html/ClassList.cpp:
(WebCore::ClassList::create):
(WebCore::ClassList::element):
(WebCore::ClassList::value):
(WebCore::ClassList::setValue):
(WebCore::ClassList::classNames):
* html/ClassList.h:
* html/DOMSettableTokenList.cpp:
(WebCore::DOMSettableTokenList::create):
(WebCore::DOMSettableTokenList::ref):
(WebCore::DOMSettableTokenList::deref):
(WebCore::DOMSettableTokenList::length):
(WebCore::DOMSettableTokenList::value):
* html/DOMSettableTokenList.h:
* html/DOMTokenList.h:
(WebCore::DOMTokenList::element):


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@154707 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 7aee36d3
2013-08-27 Benjamin Poulain <benjamin@webkit.org>
Clean ClassList and DOMSettableTokenList
https://bugs.webkit.org/show_bug.cgi?id=120344
Reviewed by Ryosuke Niwa.
This patch cleans ClassList and DOMSettableTokenList to make it simpler to update
SpaceSplitString:
- Move the implementation of virtual functions to the cpp file.
- Clean the #includes.
- Make the implemented pure virtual methods final.
- Make the element() accessor const.
* html/ClassList.cpp:
(WebCore::ClassList::create):
(WebCore::ClassList::element):
(WebCore::ClassList::value):
(WebCore::ClassList::setValue):
(WebCore::ClassList::classNames):
* html/ClassList.h:
* html/DOMSettableTokenList.cpp:
(WebCore::DOMSettableTokenList::create):
(WebCore::DOMSettableTokenList::ref):
(WebCore::DOMSettableTokenList::deref):
(WebCore::DOMSettableTokenList::length):
(WebCore::DOMSettableTokenList::value):
* html/DOMSettableTokenList.h:
* html/DOMTokenList.h:
(WebCore::DOMTokenList::element):
2013-08-27 Arunprasad Rajkumar <arurajku@cisco.com>
Replace currentTime() with monotonicallyIncreasingTime() in WebCore
/*
* Copyright (C) 2010 Google Inc. All rights reserved.
* Copyright (C) 2013 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
......@@ -25,14 +26,16 @@
#include "config.h"
#include "ClassList.h"
#include "Element.h"
#include "HTMLNames.h"
#include "HTMLParserIdioms.h"
#include "SpaceSplitString.h"
namespace WebCore {
using namespace HTMLNames;
ClassList::ClassList(Element* element) : m_element(element) { }
PassOwnPtr<ClassList> ClassList::create(Element* element)
{
return adoptPtr(new ClassList(element));
}
void ClassList::ref()
{
......@@ -56,18 +59,33 @@ const AtomicString ClassList::item(unsigned index) const
return classNames()[index];
}
Element* ClassList::element() const
{
return m_element;
}
bool ClassList::containsInternal(const AtomicString& token) const
{
return m_element->hasClass() && classNames().contains(token);
}
AtomicString ClassList::value() const
{
return m_element->getAttribute(HTMLNames::classAttr);
}
void ClassList::setValue(const AtomicString& value)
{
m_element->setAttribute(HTMLNames::classAttr, value);
}
const SpaceSplitString& ClassList::classNames() const
{
ASSERT(m_element->hasClass());
if (m_element->document()->inQuirksMode()) {
if (!m_classNamesForQuirksMode)
m_classNamesForQuirksMode = adoptPtr(new SpaceSplitString(value(), false));
return *m_classNamesForQuirksMode.get();
if (!m_classNamesForQuirksMode.size())
m_classNamesForQuirksMode.set(value(), false);
return m_classNamesForQuirksMode;
}
return m_element->elementData()->classNames();
}
......
/*
* Copyright (C) 2010 Google Inc. All rights reserved.
* Copyright (C) 2013 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
......@@ -26,47 +27,40 @@
#define ClassList_h
#include "DOMTokenList.h"
#include "Element.h"
#include "HTMLNames.h"
#include "SpaceSplitString.h"
#include <wtf/OwnPtr.h>
#include <wtf/PassOwnPtr.h>
namespace WebCore {
class Element;
typedef int ExceptionCode;
class ClassList : public DOMTokenList {
public:
static PassOwnPtr<ClassList> create(Element* element)
{
return adoptPtr(new ClassList(element));
}
static PassOwnPtr<ClassList> create(Element*);
virtual void ref() OVERRIDE;
virtual void deref() OVERRIDE;
virtual void ref() OVERRIDE FINAL;
virtual void deref() OVERRIDE FINAL;
virtual unsigned length() const OVERRIDE;
virtual const AtomicString item(unsigned index) const OVERRIDE;
virtual unsigned length() const OVERRIDE FINAL;
virtual const AtomicString item(unsigned index) const OVERRIDE FINAL;
virtual Element* element() OVERRIDE { return m_element; }
virtual Element* element() const OVERRIDE FINAL;
void clearValueForQuirksMode() { m_classNamesForQuirksMode = nullptr; }
void clearValueForQuirksMode() { m_classNamesForQuirksMode.clear(); }
private:
ClassList(Element*);
ClassList(Element* element)
: m_element(element)
{
}
virtual bool containsInternal(const AtomicString&) const OVERRIDE;
virtual bool containsInternal(const AtomicString&) const OVERRIDE FINAL;
virtual AtomicString value() const OVERRIDE FINAL;
virtual void setValue(const AtomicString&) OVERRIDE FINAL;
const SpaceSplitString& classNames() const;
virtual AtomicString value() const OVERRIDE { return m_element->getAttribute(HTMLNames::classAttr); }
virtual void setValue(const AtomicString& value) OVERRIDE { m_element->setAttribute(HTMLNames::classAttr, value); }
Element* m_element;
mutable OwnPtr<SpaceSplitString> m_classNamesForQuirksMode;
mutable SpaceSplitString m_classNamesForQuirksMode;
};
} // namespace WebCore
......
/*
* Copyright (C) 2010 Google Inc. All rights reserved.
* Copyright (C) 2013 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
......@@ -27,14 +28,24 @@
namespace WebCore {
DOMSettableTokenList::DOMSettableTokenList()
: m_value()
, m_tokens()
PassRefPtr<DOMSettableTokenList> DOMSettableTokenList::create()
{
return adoptRef(new DOMSettableTokenList());
}
DOMSettableTokenList::~DOMSettableTokenList()
void DOMSettableTokenList::ref()
{
RefCounted<DOMSettableTokenList>::ref();
}
void DOMSettableTokenList::deref()
{
RefCounted<DOMSettableTokenList>::deref();
}
unsigned DOMSettableTokenList::length() const
{
return m_tokens.size();
}
const AtomicString DOMSettableTokenList::item(unsigned index) const
......@@ -49,6 +60,11 @@ bool DOMSettableTokenList::containsInternal(const AtomicString& token) const
return m_tokens.contains(token);
}
AtomicString DOMSettableTokenList::value() const
{
return m_value;
}
void DOMSettableTokenList::setValue(const AtomicString& value)
{
m_value = value;
......
/*
* Copyright (C) 2010 Google Inc. All rights reserved.
* Copyright (C) 2013 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
......@@ -37,28 +38,19 @@ typedef int ExceptionCode;
class DOMSettableTokenList : public DOMTokenList, public RefCounted<DOMSettableTokenList> {
WTF_MAKE_FAST_ALLOCATED;
public:
static PassRefPtr<DOMSettableTokenList> create()
{
return adoptRef(new DOMSettableTokenList());
}
virtual ~DOMSettableTokenList();
static PassRefPtr<DOMSettableTokenList> create();
virtual void ref() OVERRIDE { RefCounted<DOMSettableTokenList>::ref(); }
virtual void deref() OVERRIDE { RefCounted<DOMSettableTokenList>::deref(); }
virtual void ref() OVERRIDE FINAL;
virtual void deref() OVERRIDE FINAL;
virtual unsigned length() const OVERRIDE { return m_tokens.size(); }
virtual const AtomicString item(unsigned index) const OVERRIDE;
virtual unsigned length() const OVERRIDE FINAL;
virtual const AtomicString item(unsigned index) const OVERRIDE FINAL;
virtual AtomicString value() const OVERRIDE { return m_value; }
virtual void setValue(const AtomicString&) OVERRIDE;
const SpaceSplitString& tokens() const { return m_tokens; }
protected:
DOMSettableTokenList();
virtual AtomicString value() const OVERRIDE FINAL;
virtual void setValue(const AtomicString&) OVERRIDE FINAL;
private:
virtual bool containsInternal(const AtomicString&) const OVERRIDE;
virtual bool containsInternal(const AtomicString&) const OVERRIDE FINAL;
AtomicString m_value;
SpaceSplitString m_tokens;
......
......@@ -56,7 +56,7 @@ public:
AtomicString toString() const { return value(); }
virtual Element* element() { return 0; }
virtual Element* element() const { return 0; }
protected:
virtual AtomicString value() const = 0;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment