Changeset 64420 in webkit


Ignore:
Timestamp:
Jul 31, 2010 10:30:54 AM (14 years ago)
Author:
Nikolas Zimmermann
Message:

2010-07-31 Nikolas Zimmermann <nzimmermann@rim.com>

Reviewed by Dirk Schulze.

HTMLStyleElement/SVGStyleElement need to share more code
https://bugs.webkit.org/show_bug.cgi?id=43293

Simplify HTMLStyleElement/SVGStyleElement. They look identically now, as all code is shared in StyleElement.
Doesn't affect any tests.

  • dom/StyleElement.cpp: (WebCore::StyleElement::StyleElement): Take createdByParser & Document arguments, to share the line number extraction logic. Store it in m_lineNumber. (WebCore::StyleElement::insertedIntoDocument): Moved addStyleSheetCandidateNode here, to share code between HTML/SVGStyleElement. (WebCore::StyleElement::removedFromDocument): Same for removeStyleSheetCandidateNode. (WebCore::StyleElement::childrenChanged): Introduced new helper function. (WebCore::StyleElement::finishParsingChildren): Ditto. (WebCore::StyleElement::process): Use stored m_lineNumber, avoids a parameter. (WebCore::StyleElement::createSheet): No need to call the virtual setLoading() function, just store m_loading in StyleElement, and set it from here. (WebCore::StyleElement::isLoading): Introduced new helper function. (WebCore::StyleElement::sheetLoaded): Ditto.
  • dom/StyleElement.h:
  • html/HTMLStyleElement.cpp: (WebCore::HTMLStyleElement::HTMLStyleElement): Pass Document & createdByParser arguments to StyleElement. (WebCore::HTMLStyleElement::finishParsingChildren): Delegate work to StyleElement. (WebCore::HTMLStyleElement::insertedIntoDocument): Ditto. (WebCore::HTMLStyleElement::removedFromDocument): Ditto. (WebCore::HTMLStyleElement::childrenChanged): Ditto.
  • html/HTMLStyleElement.h: (WebCore::HTMLStyleElement::isLoading): Ditto. (WebCore::HTMLStyleElement::sheetLoaded): Ditto.
  • svg/SVGStyleElement.cpp: (WebCore::SVGStyleElement::SVGStyleElement): Pass Document & createdByParser arguments to StyleElement. (WebCore::SVGStyleElement::finishParsingChildren): Delegate work to StyleElement. (WebCore::SVGStyleElement::insertedIntoDocument): Ditto. (WebCore::SVGStyleElement::removedFromDocument): Ditto. (WebCore::SVGStyleElement::childrenChanged): Ditto.
  • svg/SVGStyleElement.h: (WebCore::SVGStyleElement::isLoading): Ditto. (WebCore::SVGStyleElement::sheetLoaded): Ditto.
Location:
trunk/WebCore
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r64416 r64420  
     12010-07-31  Nikolas Zimmermann  <nzimmermann@rim.com>
     2
     3        Reviewed by Dirk Schulze.
     4
     5        HTMLStyleElement/SVGStyleElement need to share more code
     6        https://bugs.webkit.org/show_bug.cgi?id=43293
     7
     8        Simplify HTMLStyleElement/SVGStyleElement. They look identically now, as all code is shared in StyleElement.
     9        Doesn't affect any tests.
     10
     11        * dom/StyleElement.cpp:
     12        (WebCore::StyleElement::StyleElement): Take createdByParser & Document arguments, to share the line number extraction logic. Store it in m_lineNumber.
     13        (WebCore::StyleElement::insertedIntoDocument): Moved addStyleSheetCandidateNode here, to share code between HTML/SVGStyleElement.
     14        (WebCore::StyleElement::removedFromDocument): Same for removeStyleSheetCandidateNode.
     15        (WebCore::StyleElement::childrenChanged): Introduced new helper function.
     16        (WebCore::StyleElement::finishParsingChildren): Ditto.
     17        (WebCore::StyleElement::process): Use stored m_lineNumber, avoids a parameter.
     18        (WebCore::StyleElement::createSheet): No need to call the virtual setLoading() function, just store m_loading in StyleElement, and set it from here.
     19        (WebCore::StyleElement::isLoading): Introduced new helper function.
     20        (WebCore::StyleElement::sheetLoaded): Ditto.
     21        * dom/StyleElement.h:
     22        * html/HTMLStyleElement.cpp:
     23        (WebCore::HTMLStyleElement::HTMLStyleElement): Pass Document & createdByParser arguments to StyleElement.
     24        (WebCore::HTMLStyleElement::finishParsingChildren): Delegate work to StyleElement.
     25        (WebCore::HTMLStyleElement::insertedIntoDocument): Ditto.
     26        (WebCore::HTMLStyleElement::removedFromDocument): Ditto.
     27        (WebCore::HTMLStyleElement::childrenChanged): Ditto.
     28        * html/HTMLStyleElement.h:
     29        (WebCore::HTMLStyleElement::isLoading): Ditto.
     30        (WebCore::HTMLStyleElement::sheetLoaded): Ditto.
     31        * svg/SVGStyleElement.cpp:
     32        (WebCore::SVGStyleElement::SVGStyleElement): Pass Document & createdByParser arguments to StyleElement.
     33        (WebCore::SVGStyleElement::finishParsingChildren): Delegate work to StyleElement.
     34        (WebCore::SVGStyleElement::insertedIntoDocument): Ditto.
     35        (WebCore::SVGStyleElement::removedFromDocument): Ditto.
     36        (WebCore::SVGStyleElement::childrenChanged): Ditto.
     37        * svg/SVGStyleElement.h:
     38        (WebCore::SVGStyleElement::isLoading): Ditto.
     39        (WebCore::SVGStyleElement::sheetLoaded): Ditto.
     40
    1412010-07-31  Kinuko Yasuda  <kinuko@chromium.org>
    242
  • trunk/WebCore/dom/StyleElement.cpp

    r62630 r64420  
    2727#include "MediaList.h"
    2828#include "MediaQueryEvaluator.h"
     29#include "ScriptableDocumentParser.h"
    2930
    3031namespace WebCore {
    3132
    32 StyleElement::StyleElement()
     33StyleElement::StyleElement(Document* document, bool createdByParser)
     34    : m_createdByParser(createdByParser)
     35    , m_loading(false)
     36    , m_startLineNumber(0)
    3337{
     38    if (createdByParser && document && document->scriptableDocumentParser())
     39        m_startLineNumber = document->scriptableDocumentParser()->lineNumber();
    3440}
    3541
     
    4147}
    4248
    43 void StyleElement::insertedIntoDocument(Document*, Element* element)
     49void StyleElement::insertedIntoDocument(Document* document, Element* element)
    4450{
    45     process(element, 0);
     51    ASSERT(document);
     52    ASSERT(element);
     53    document->addStyleSheetCandidateNode(element, m_createdByParser);
     54    if (m_createdByParser)
     55        return;
     56
     57    process(element);
    4658}
    4759
    48 void StyleElement::removedFromDocument(Document* document)
     60void StyleElement::removedFromDocument(Document* document, Element* element)
    4961{
     62    ASSERT(document);
     63    ASSERT(element);
     64    document->removeStyleSheetCandidateNode(element);
     65
    5066    // If we're in document teardown, then we don't need to do any notification of our sheet's removal.
    5167    if (!document->renderer())
     
    5773}
    5874
    59 void StyleElement::process(Element* e, int startLineNumber)
     75void StyleElement::childrenChanged(Element* element)
     76{
     77    ASSERT(element);
     78    if (m_createdByParser)
     79        return;
     80
     81    process(element);
     82}
     83
     84void StyleElement::finishParsingChildren(Element* element)
     85{
     86    ASSERT(element);
     87    process(element);
     88    sheet(element);
     89    m_createdByParser = false;
     90}
     91
     92void StyleElement::process(Element* e)
    6093{
    6194    if (!e || !e->inDocument())
     
    83116    ASSERT(p == text + resultLength);
    84117
    85     createSheet(e, startLineNumber, sheetText);
     118    createSheet(e, m_startLineNumber, sheetText);
    86119}
    87120
    88121void StyleElement::createSheet(Element* e, int startLineNumber, const String& text)
    89122{
     123    ASSERT(e);
    90124    Document* document = e->document();
    91125    if (m_sheet) {
    92         if (static_cast<CSSStyleSheet*>(m_sheet.get())->isLoading())
     126        if (m_sheet->isLoading())
    93127            document->removePendingSheet();
    94128        m_sheet = 0;
     
    103137        if (screenEval.eval(mediaList.get()) || printEval.eval(mediaList.get())) {
    104138            document->addPendingSheet();
    105             setLoading(true);
     139            m_loading = true;
    106140            m_sheet = CSSStyleSheet::create(e, String(), KURL(), document->inputEncoding());
    107141            m_sheet->parseStringAtLine(text, !document->inCompatMode(), startLineNumber);
    108142            m_sheet->setMedia(mediaList.get());
    109143            m_sheet->setTitle(e->title());
    110             setLoading(false);
     144            m_loading = false;
    111145        }
    112146    }
     
    116150}
    117151
     152bool StyleElement::isLoading() const
     153{
     154    if (m_loading)
     155        return true;
     156    return m_sheet ? m_sheet->isLoading() : false;
    118157}
     158
     159bool StyleElement::sheetLoaded(Document* document)
     160{
     161    ASSERT(document);
     162    if (isLoading())
     163        return false;
     164
     165    document->removePendingSheet();
     166    return true;
     167}
     168
     169}
  • trunk/WebCore/dom/StyleElement.h

    r63042 r64420  
    1818 *
    1919 */
     20
    2021#ifndef StyleElement_h
    2122#define StyleElement_h
     
    3031class StyleElement {
    3132public:
    32     StyleElement();
     33    StyleElement(Document*, bool createdByParser);
    3334    virtual ~StyleElement() {}
    3435
    3536protected:
    36     StyleSheet* sheet(Element*);
    37 
    38     virtual void setLoading(bool) {}
    39 
    4037    virtual const AtomicString& type() const = 0;
    4138    virtual const AtomicString& media() const = 0;
    4239
     40    StyleSheet* sheet(Element*);
     41
     42    bool isLoading() const;
     43    bool sheetLoaded(Document*);
     44
    4345    void insertedIntoDocument(Document*, Element*);
    44     void removedFromDocument(Document*);
    45     void process(Element*, int startLineNumber);
     46    void removedFromDocument(Document*, Element*);
     47    void childrenChanged(Element*);
     48    void finishParsingChildren(Element*);
    4649
    47     void createSheet(Element* e, int startLineNumber, const String& text = String());
     50    RefPtr<CSSStyleSheet> m_sheet;
    4851
    49 protected:
    50     RefPtr<CSSStyleSheet> m_sheet;
     52private:
     53    void createSheet(Element*, int startLineNumber, const String& text = String());
     54    void process(Element*);
     55
     56    bool m_createdByParser;
     57    bool m_loading;
     58    int m_startLineNumber;
    5159};
    5260
    53 } //namespace
     61}
    5462
    5563#endif
  • trunk/WebCore/html/HTMLStyleElement.cpp

    r62630 r64420  
    3737inline HTMLStyleElement::HTMLStyleElement(const QualifiedName& tagName, Document* document, bool createdByParser)
    3838    : HTMLElement(tagName, document)
    39     , m_loading(false)
    40     , m_createdByParser(createdByParser)
    41     , m_startLineNumber(0)
     39    , StyleElement(document, createdByParser)
    4240{
    4341    ASSERT(hasTagName(styleTag));
    44     if (createdByParser && document && document->scriptableDocumentParser())
    45         m_startLineNumber = document->scriptableDocumentParser()->lineNumber();
    4642}
    4743
     
    6359void HTMLStyleElement::finishParsingChildren()
    6460{
    65     StyleElement::process(this, m_startLineNumber);
    66     StyleElement::sheet(this);
    67     m_createdByParser = false;
     61    StyleElement::finishParsingChildren(this);
    6862    HTMLElement::finishParsingChildren();
    6963}
     
    7266{
    7367    HTMLElement::insertedIntoDocument();
    74 
    75     document()->addStyleSheetCandidateNode(this, m_createdByParser);
    76     if (!m_createdByParser)
    77         StyleElement::insertedIntoDocument(document(), this);
     68    StyleElement::insertedIntoDocument(document(), this);
    7869}
    7970
     
    8172{
    8273    HTMLElement::removedFromDocument();
    83     document()->removeStyleSheetCandidateNode(this);
    84     StyleElement::removedFromDocument(document());
     74    StyleElement::removedFromDocument(document(), this);
    8575}
    8676
    8777void HTMLStyleElement::childrenChanged(bool changedByParser, Node* beforeChange, Node* afterChange, int childCountDelta)
    8878{
    89     if (!changedByParser)
    90         StyleElement::process(this, 0);
     79    StyleElement::childrenChanged(this);
    9180    HTMLElement::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta);
    9281}
     
    9584{
    9685    return StyleElement::sheet(this);
    97 }
    98 
    99 bool HTMLStyleElement::isLoading() const
    100 {
    101     if (m_loading)
    102         return true;
    103     if (!m_sheet)
    104         return false;
    105     return static_cast<CSSStyleSheet *>(m_sheet.get())->isLoading();
    106 }
    107 
    108 bool HTMLStyleElement::sheetLoaded()
    109 {
    110     if (!isLoading()) {
    111         document()->removePendingSheet();
    112         return true;
    113     }
    114     return false;
    11586}
    11687
  • trunk/WebCore/html/HTMLStyleElement.h

    r62630 r64420  
    5454    virtual void finishParsingChildren();
    5555
    56     virtual bool isLoading() const;
    57     virtual bool sheetLoaded();
    58 
    59     virtual void setLoading(bool loading) { m_loading = loading; }
     56    virtual bool isLoading() const { return StyleElement::isLoading(); }
     57    virtual bool sheetLoaded() { return StyleElement::sheetLoaded(document()); }
    6058
    6159    virtual void addSubresourceAttributeURLs(ListHashSet<KURL>&) const;
     
    6361    virtual const AtomicString& media() const;
    6462    virtual const AtomicString& type() const;
    65 
    66     bool m_loading;
    67     bool m_createdByParser;
    68     int m_startLineNumber;
    6963};
    7064
  • trunk/WebCore/svg/SVGStyleElement.cpp

    r62630 r64420  
    11/*
    2     Copyright (C) 2004, 2005 Nikolas Zimmermann <wildfox@kde.org>
     2    Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org>
    33                  2004, 2005, 2006, 2007 Rob Buis <buis@kde.org>
    44    Copyright (C) 2006 Apple Computer, Inc.
     
    3535namespace WebCore {
    3636
    37 using namespace SVGNames;
    38 
    39 SVGStyleElement::SVGStyleElement(const QualifiedName& tagName, Document* doc, bool createdByParser)
    40      : SVGElement(tagName, doc)
    41      , SVGLangSpace()
    42      , m_createdByParser(createdByParser)
     37SVGStyleElement::SVGStyleElement(const QualifiedName& tagName, Document* document, bool createdByParser)
     38    : SVGElement(tagName, document)
     39    , SVGLangSpace()
     40    , StyleElement(document, createdByParser)
    4341{
    4442}
     
    9189void SVGStyleElement::finishParsingChildren()
    9290{
    93     StyleElement::sheet(this);
    94     m_createdByParser = false;
     91    StyleElement::finishParsingChildren(this);
    9592    SVGElement::finishParsingChildren();
    9693}
     
    9996{
    10097    SVGElement::insertedIntoDocument();
    101     document()->addStyleSheetCandidateNode(this, m_createdByParser);
    102     if (!m_createdByParser)
    103         StyleElement::insertedIntoDocument(document(), this);
     98    StyleElement::insertedIntoDocument(document(), this);
    10499}
    105100
     
    107102{
    108103    SVGElement::removedFromDocument();
    109     if (document()->renderer())
    110         document()->removeStyleSheetCandidateNode(this);
    111     StyleElement::removedFromDocument(document());
     104    StyleElement::removedFromDocument(document(), this);
    112105}
    113106
    114107void SVGStyleElement::childrenChanged(bool changedByParser, Node* beforeChange, Node* afterChange, int childCountDelta)
    115108{
     109    StyleElement::childrenChanged(this);
    116110    SVGElement::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta);
    117     StyleElement::process(this, 0);
    118111}
    119112
     
    123116}
    124117
    125 bool SVGStyleElement::sheetLoaded()
    126 {
    127     document()->removePendingSheet();
    128     return true;
    129118}
    130119
    131 }
    132 
    133 // vim:ts=4:noet
    134120#endif // ENABLE(SVG)
  • trunk/WebCore/svg/SVGStyleElement.h

    r59773 r64420  
    11/*
    2     Copyright (C) 2004, 2005 Nikolas Zimmermann <wildfox@kde.org>
     2    Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org>
    33                  2004, 2005, 2006, 2007 Rob Buis <buis@kde.org>
    44
     
    2121#ifndef SVGStyleElement_h
    2222#define SVGStyleElement_h
     23
    2324#if ENABLE(SVG)
    24 
    25 #include <SVGElement.h>
     25#include "SVGElement.h"
    2626#include "SVGLangSpace.h"
    2727#include "StyleElement.h"
     
    2929namespace WebCore {
    3030
    31     class SVGStyleElement : public SVGElement,
    32                             public SVGLangSpace,
    33                             public StyleElement {
    34     public:
    35         SVGStyleElement(const QualifiedName&, Document*, bool createdByParser);
     31class SVGStyleElement : public SVGElement
     32                      , public SVGLangSpace
     33                      , public StyleElement {
     34public:
     35    SVGStyleElement(const QualifiedName&, Document*, bool createdByParser);
    3636
    37         // Derived from: 'Element'
    38         virtual void parseMappedAttribute(Attribute*);
    39         virtual void insertedIntoDocument();
    40         virtual void removedFromDocument();
    41         virtual void childrenChanged(bool changedByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0);
     37    virtual void parseMappedAttribute(Attribute*);
     38    virtual void insertedIntoDocument();
     39    virtual void removedFromDocument();
     40    virtual void childrenChanged(bool changedByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0);
    4241
    43         virtual void finishParsingChildren();
     42    virtual void finishParsingChildren();
    4443
    45         virtual bool sheetLoaded();
     44    virtual bool isLoading() const { return StyleElement::isLoading(); }
     45    virtual bool sheetLoaded() { return StyleElement::sheetLoaded(document()); }
    4646
    47         virtual const AtomicString& type() const;
    48         void setType(const AtomicString&, ExceptionCode&);
     47    virtual const AtomicString& type() const;
     48    void setType(const AtomicString&, ExceptionCode&);
    4949
    50         virtual const AtomicString& media() const;
    51         void setMedia(const AtomicString&, ExceptionCode&);
     50    virtual const AtomicString& media() const;
     51    void setMedia(const AtomicString&, ExceptionCode&);
    5252
    53         virtual String title() const;
    54         void setTitle(const AtomicString&, ExceptionCode&);
     53    virtual String title() const;
     54    void setTitle(const AtomicString&, ExceptionCode&);
    5555
    56         StyleSheet* sheet();
    57        
    58     protected:
    59         bool m_createdByParser;
    60     };
     56    StyleSheet* sheet();
     57};
    6158
    6259} // namespace WebCore
     
    6461#endif // ENABLE(SVG)
    6562#endif // SVGStyleElement_h
    66 
    67 // vim:ts=4:noet
Note: See TracChangeset for help on using the changeset viewer.