Changeset 154707 in webkit


Ignore:
Timestamp:
Aug 27, 2013 1:49:57 PM (11 years ago)
Author:
benjamin@webkit.org
Message:

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):

Location:
trunk/Source/WebCore
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r154706 r154707  
     12013-08-27  Benjamin Poulain  <benjamin@webkit.org>
     2
     3        Clean ClassList and DOMSettableTokenList
     4        https://bugs.webkit.org/show_bug.cgi?id=120344
     5
     6        Reviewed by Ryosuke Niwa.
     7
     8        This patch cleans ClassList and DOMSettableTokenList to make it simpler to update
     9        SpaceSplitString:
     10        - Move the implementation of virtual functions to the cpp file.
     11        - Clean the #includes.
     12        - Make the implemented pure virtual methods final.
     13        - Make the element() accessor const.
     14
     15        * html/ClassList.cpp:
     16        (WebCore::ClassList::create):
     17        (WebCore::ClassList::element):
     18        (WebCore::ClassList::value):
     19        (WebCore::ClassList::setValue):
     20        (WebCore::ClassList::classNames):
     21        * html/ClassList.h:
     22        * html/DOMSettableTokenList.cpp:
     23        (WebCore::DOMSettableTokenList::create):
     24        (WebCore::DOMSettableTokenList::ref):
     25        (WebCore::DOMSettableTokenList::deref):
     26        (WebCore::DOMSettableTokenList::length):
     27        (WebCore::DOMSettableTokenList::value):
     28        * html/DOMSettableTokenList.h:
     29        * html/DOMTokenList.h:
     30        (WebCore::DOMTokenList::element):
     31
    1322013-08-27  Arunprasad Rajkumar  <arurajku@cisco.com>
    233
  • trunk/Source/WebCore/html/ClassList.cpp

    r151947 r154707  
    11/*
    22 * Copyright (C) 2010 Google Inc. All rights reserved.
     3 * Copyright (C) 2013 Apple Inc. All rights reserved.
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    2627#include "ClassList.h"
    2728
     29#include "Element.h"
     30#include "HTMLNames.h"
    2831#include "HTMLParserIdioms.h"
    29 #include "SpaceSplitString.h"
    3032
    3133namespace WebCore {
    3234
    33 using namespace HTMLNames;
    34 
    35 ClassList::ClassList(Element* element) : m_element(element) { }
     35PassOwnPtr<ClassList> ClassList::create(Element* element)
     36{
     37    return adoptPtr(new ClassList(element));
     38}
    3639
    3740void ClassList::ref()
     
    5760}
    5861
     62Element* ClassList::element() const
     63{
     64    return m_element;
     65}
     66
    5967bool ClassList::containsInternal(const AtomicString& token) const
    6068{
    6169    return m_element->hasClass() && classNames().contains(token);
     70}
     71
     72AtomicString ClassList::value() const
     73{
     74    return m_element->getAttribute(HTMLNames::classAttr);
     75}
     76
     77void ClassList::setValue(const AtomicString& value)
     78{
     79    m_element->setAttribute(HTMLNames::classAttr, value);
    6280}
    6381
     
    6684    ASSERT(m_element->hasClass());
    6785    if (m_element->document()->inQuirksMode()) {
    68         if (!m_classNamesForQuirksMode)
    69             m_classNamesForQuirksMode = adoptPtr(new SpaceSplitString(value(), false));
    70         return *m_classNamesForQuirksMode.get();
     86        if (!m_classNamesForQuirksMode.size())
     87            m_classNamesForQuirksMode.set(value(), false);
     88        return m_classNamesForQuirksMode;
    7189    }
    7290    return m_element->elementData()->classNames();
  • trunk/Source/WebCore/html/ClassList.h

    r151947 r154707  
    11/*
    22 * Copyright (C) 2010 Google Inc. All rights reserved.
     3 * Copyright (C) 2013 Apple Inc. All rights reserved.
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    2728
    2829#include "DOMTokenList.h"
    29 #include "Element.h"
    30 #include "HTMLNames.h"
    3130#include "SpaceSplitString.h"
    32 #include <wtf/OwnPtr.h>
    33 #include <wtf/PassOwnPtr.h>
    3431
    3532namespace WebCore {
     
    3734class Element;
    3835
    39 typedef int ExceptionCode;
    40 
    4136class ClassList : public DOMTokenList {
    4237public:
    43     static PassOwnPtr<ClassList> create(Element* element)
     38    static PassOwnPtr<ClassList> create(Element*);
     39
     40    virtual void ref() OVERRIDE FINAL;
     41    virtual void deref() OVERRIDE FINAL;
     42
     43    virtual unsigned length() const OVERRIDE FINAL;
     44    virtual const AtomicString item(unsigned index) const OVERRIDE FINAL;
     45
     46    virtual Element* element() const OVERRIDE FINAL;
     47
     48    void clearValueForQuirksMode() { m_classNamesForQuirksMode.clear(); }
     49
     50private:
     51    ClassList(Element* element)
     52        : m_element(element)
    4453    {
    45         return adoptPtr(new ClassList(element));
    4654    }
    4755
    48     virtual void ref() OVERRIDE;
    49     virtual void deref() OVERRIDE;
    50 
    51     virtual unsigned length() const OVERRIDE;
    52     virtual const AtomicString item(unsigned index) const OVERRIDE;
    53 
    54     virtual Element* element() OVERRIDE { return m_element; }
    55 
    56     void clearValueForQuirksMode() { m_classNamesForQuirksMode = nullptr; }
    57 
    58 private:
    59     ClassList(Element*);
    60 
    61     virtual bool containsInternal(const AtomicString&) const OVERRIDE;
     56    virtual bool containsInternal(const AtomicString&) const OVERRIDE FINAL;
     57    virtual AtomicString value() const OVERRIDE FINAL;
     58    virtual void setValue(const AtomicString&) OVERRIDE FINAL;
    6259
    6360    const SpaceSplitString& classNames() const;
    6461
    65     virtual AtomicString value() const OVERRIDE { return m_element->getAttribute(HTMLNames::classAttr); }
    66     virtual void setValue(const AtomicString& value) OVERRIDE { m_element->setAttribute(HTMLNames::classAttr, value); }
    67 
    6862    Element* m_element;
    69     mutable OwnPtr<SpaceSplitString> m_classNamesForQuirksMode;
     63    mutable SpaceSplitString m_classNamesForQuirksMode;
    7064};
    7165
  • trunk/Source/WebCore/html/DOMSettableTokenList.cpp

    r154667 r154707  
    11/*
    22 * Copyright (C) 2010 Google Inc. All rights reserved.
     3 * Copyright (C) 2013 Apple Inc. All rights reserved.
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    2829namespace WebCore {
    2930
    30 DOMSettableTokenList::DOMSettableTokenList()
    31     : m_value()
    32     , m_tokens()
     31PassRefPtr<DOMSettableTokenList> DOMSettableTokenList::create()
    3332{
     33    return adoptRef(new DOMSettableTokenList());
    3434}
    3535
    36 DOMSettableTokenList::~DOMSettableTokenList()
     36void DOMSettableTokenList::ref()
    3737{
     38    RefCounted<DOMSettableTokenList>::ref();
     39}
     40
     41void DOMSettableTokenList::deref()
     42{
     43    RefCounted<DOMSettableTokenList>::deref();
     44}
     45
     46unsigned DOMSettableTokenList::length() const
     47{
     48    return m_tokens.size();
    3849}
    3950
     
    5061}
    5162
     63AtomicString DOMSettableTokenList::value() const
     64{
     65    return m_value;
     66}
     67
    5268void DOMSettableTokenList::setValue(const AtomicString& value)
    5369{
  • trunk/Source/WebCore/html/DOMSettableTokenList.h

    r154667 r154707  
    11/*
    22 * Copyright (C) 2010 Google Inc. All rights reserved.
     3 * Copyright (C) 2013 Apple Inc. All rights reserved.
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    3839    WTF_MAKE_FAST_ALLOCATED;
    3940public:
    40     static PassRefPtr<DOMSettableTokenList> create()
    41     {
    42         return adoptRef(new DOMSettableTokenList());
    43     }
    44     virtual ~DOMSettableTokenList();
     41    static PassRefPtr<DOMSettableTokenList> create();
    4542
    46     virtual void ref() OVERRIDE { RefCounted<DOMSettableTokenList>::ref(); }
    47     virtual void deref() OVERRIDE { RefCounted<DOMSettableTokenList>::deref(); }
     43    virtual void ref() OVERRIDE FINAL;
     44    virtual void deref() OVERRIDE FINAL;
    4845
    49     virtual unsigned length() const OVERRIDE { return m_tokens.size(); }
    50     virtual const AtomicString item(unsigned index) const OVERRIDE;
     46    virtual unsigned length() const OVERRIDE FINAL;
     47    virtual const AtomicString item(unsigned index) const OVERRIDE FINAL;
    5148
    52     virtual AtomicString value() const OVERRIDE { return m_value; }
    53     virtual void setValue(const AtomicString&) OVERRIDE;
    54 
    55     const SpaceSplitString& tokens() const { return m_tokens; }
    56 
    57 protected:
    58     DOMSettableTokenList();
     49    virtual AtomicString value() const OVERRIDE FINAL;
     50    virtual void setValue(const AtomicString&) OVERRIDE FINAL;
    5951
    6052private:
    61     virtual bool containsInternal(const AtomicString&) const OVERRIDE;
     53    virtual bool containsInternal(const AtomicString&) const OVERRIDE FINAL;
    6254
    6355    AtomicString m_value;
  • trunk/Source/WebCore/html/DOMTokenList.h

    r154667 r154707  
    5757    AtomicString toString() const { return value(); }
    5858
    59     virtual Element* element() { return 0; }
     59    virtual Element* element() const { return 0; }
    6060
    6161protected:
Note: See TracChangeset for help on using the changeset viewer.