Changeset 64420 in webkit
- Timestamp:
- Jul 31, 2010 10:30:54 AM (14 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r64416 r64420 1 2010-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 1 41 2010-07-31 Kinuko Yasuda <kinuko@chromium.org> 2 42 -
trunk/WebCore/dom/StyleElement.cpp
r62630 r64420 27 27 #include "MediaList.h" 28 28 #include "MediaQueryEvaluator.h" 29 #include "ScriptableDocumentParser.h" 29 30 30 31 namespace WebCore { 31 32 32 StyleElement::StyleElement() 33 StyleElement::StyleElement(Document* document, bool createdByParser) 34 : m_createdByParser(createdByParser) 35 , m_loading(false) 36 , m_startLineNumber(0) 33 37 { 38 if (createdByParser && document && document->scriptableDocumentParser()) 39 m_startLineNumber = document->scriptableDocumentParser()->lineNumber(); 34 40 } 35 41 … … 41 47 } 42 48 43 void StyleElement::insertedIntoDocument(Document* , Element* element)49 void StyleElement::insertedIntoDocument(Document* document, Element* element) 44 50 { 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); 46 58 } 47 59 48 void StyleElement::removedFromDocument(Document* document )60 void StyleElement::removedFromDocument(Document* document, Element* element) 49 61 { 62 ASSERT(document); 63 ASSERT(element); 64 document->removeStyleSheetCandidateNode(element); 65 50 66 // If we're in document teardown, then we don't need to do any notification of our sheet's removal. 51 67 if (!document->renderer()) … … 57 73 } 58 74 59 void StyleElement::process(Element* e, int startLineNumber) 75 void StyleElement::childrenChanged(Element* element) 76 { 77 ASSERT(element); 78 if (m_createdByParser) 79 return; 80 81 process(element); 82 } 83 84 void StyleElement::finishParsingChildren(Element* element) 85 { 86 ASSERT(element); 87 process(element); 88 sheet(element); 89 m_createdByParser = false; 90 } 91 92 void StyleElement::process(Element* e) 60 93 { 61 94 if (!e || !e->inDocument()) … … 83 116 ASSERT(p == text + resultLength); 84 117 85 createSheet(e, startLineNumber, sheetText);118 createSheet(e, m_startLineNumber, sheetText); 86 119 } 87 120 88 121 void StyleElement::createSheet(Element* e, int startLineNumber, const String& text) 89 122 { 123 ASSERT(e); 90 124 Document* document = e->document(); 91 125 if (m_sheet) { 92 if ( static_cast<CSSStyleSheet*>(m_sheet.get())->isLoading())126 if (m_sheet->isLoading()) 93 127 document->removePendingSheet(); 94 128 m_sheet = 0; … … 103 137 if (screenEval.eval(mediaList.get()) || printEval.eval(mediaList.get())) { 104 138 document->addPendingSheet(); 105 setLoading(true);139 m_loading = true; 106 140 m_sheet = CSSStyleSheet::create(e, String(), KURL(), document->inputEncoding()); 107 141 m_sheet->parseStringAtLine(text, !document->inCompatMode(), startLineNumber); 108 142 m_sheet->setMedia(mediaList.get()); 109 143 m_sheet->setTitle(e->title()); 110 setLoading(false);144 m_loading = false; 111 145 } 112 146 } … … 116 150 } 117 151 152 bool StyleElement::isLoading() const 153 { 154 if (m_loading) 155 return true; 156 return m_sheet ? m_sheet->isLoading() : false; 118 157 } 158 159 bool 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 18 18 * 19 19 */ 20 20 21 #ifndef StyleElement_h 21 22 #define StyleElement_h … … 30 31 class StyleElement { 31 32 public: 32 StyleElement( );33 StyleElement(Document*, bool createdByParser); 33 34 virtual ~StyleElement() {} 34 35 35 36 protected: 36 StyleSheet* sheet(Element*);37 38 virtual void setLoading(bool) {}39 40 37 virtual const AtomicString& type() const = 0; 41 38 virtual const AtomicString& media() const = 0; 42 39 40 StyleSheet* sheet(Element*); 41 42 bool isLoading() const; 43 bool sheetLoaded(Document*); 44 43 45 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*); 46 49 47 void createSheet(Element* e, int startLineNumber, const String& text = String());50 RefPtr<CSSStyleSheet> m_sheet; 48 51 49 protected: 50 RefPtr<CSSStyleSheet> m_sheet; 52 private: 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; 51 59 }; 52 60 53 } //namespace61 } 54 62 55 63 #endif -
trunk/WebCore/html/HTMLStyleElement.cpp
r62630 r64420 37 37 inline HTMLStyleElement::HTMLStyleElement(const QualifiedName& tagName, Document* document, bool createdByParser) 38 38 : HTMLElement(tagName, document) 39 , m_loading(false) 40 , m_createdByParser(createdByParser) 41 , m_startLineNumber(0) 39 , StyleElement(document, createdByParser) 42 40 { 43 41 ASSERT(hasTagName(styleTag)); 44 if (createdByParser && document && document->scriptableDocumentParser())45 m_startLineNumber = document->scriptableDocumentParser()->lineNumber();46 42 } 47 43 … … 63 59 void HTMLStyleElement::finishParsingChildren() 64 60 { 65 StyleElement::process(this, m_startLineNumber); 66 StyleElement::sheet(this); 67 m_createdByParser = false; 61 StyleElement::finishParsingChildren(this); 68 62 HTMLElement::finishParsingChildren(); 69 63 } … … 72 66 { 73 67 HTMLElement::insertedIntoDocument(); 74 75 document()->addStyleSheetCandidateNode(this, m_createdByParser); 76 if (!m_createdByParser) 77 StyleElement::insertedIntoDocument(document(), this); 68 StyleElement::insertedIntoDocument(document(), this); 78 69 } 79 70 … … 81 72 { 82 73 HTMLElement::removedFromDocument(); 83 document()->removeStyleSheetCandidateNode(this); 84 StyleElement::removedFromDocument(document()); 74 StyleElement::removedFromDocument(document(), this); 85 75 } 86 76 87 77 void HTMLStyleElement::childrenChanged(bool changedByParser, Node* beforeChange, Node* afterChange, int childCountDelta) 88 78 { 89 if (!changedByParser) 90 StyleElement::process(this, 0); 79 StyleElement::childrenChanged(this); 91 80 HTMLElement::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta); 92 81 } … … 95 84 { 96 85 return StyleElement::sheet(this); 97 }98 99 bool HTMLStyleElement::isLoading() const100 {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;115 86 } 116 87 -
trunk/WebCore/html/HTMLStyleElement.h
r62630 r64420 54 54 virtual void finishParsingChildren(); 55 55 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()); } 60 58 61 59 virtual void addSubresourceAttributeURLs(ListHashSet<KURL>&) const; … … 63 61 virtual const AtomicString& media() const; 64 62 virtual const AtomicString& type() const; 65 66 bool m_loading;67 bool m_createdByParser;68 int m_startLineNumber;69 63 }; 70 64 -
trunk/WebCore/svg/SVGStyleElement.cpp
r62630 r64420 1 1 /* 2 Copyright (C) 2004, 2005 Nikolas Zimmermann < wildfox@kde.org>2 Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org> 3 3 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org> 4 4 Copyright (C) 2006 Apple Computer, Inc. … … 35 35 namespace WebCore { 36 36 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) 37 SVGStyleElement::SVGStyleElement(const QualifiedName& tagName, Document* document, bool createdByParser) 38 : SVGElement(tagName, document) 39 , SVGLangSpace() 40 , StyleElement(document, createdByParser) 43 41 { 44 42 } … … 91 89 void SVGStyleElement::finishParsingChildren() 92 90 { 93 StyleElement::sheet(this); 94 m_createdByParser = false; 91 StyleElement::finishParsingChildren(this); 95 92 SVGElement::finishParsingChildren(); 96 93 } … … 99 96 { 100 97 SVGElement::insertedIntoDocument(); 101 document()->addStyleSheetCandidateNode(this, m_createdByParser); 102 if (!m_createdByParser) 103 StyleElement::insertedIntoDocument(document(), this); 98 StyleElement::insertedIntoDocument(document(), this); 104 99 } 105 100 … … 107 102 { 108 103 SVGElement::removedFromDocument(); 109 if (document()->renderer()) 110 document()->removeStyleSheetCandidateNode(this); 111 StyleElement::removedFromDocument(document()); 104 StyleElement::removedFromDocument(document(), this); 112 105 } 113 106 114 107 void SVGStyleElement::childrenChanged(bool changedByParser, Node* beforeChange, Node* afterChange, int childCountDelta) 115 108 { 109 StyleElement::childrenChanged(this); 116 110 SVGElement::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta); 117 StyleElement::process(this, 0);118 111 } 119 112 … … 123 116 } 124 117 125 bool SVGStyleElement::sheetLoaded()126 {127 document()->removePendingSheet();128 return true;129 118 } 130 119 131 }132 133 // vim:ts=4:noet134 120 #endif // ENABLE(SVG) -
trunk/WebCore/svg/SVGStyleElement.h
r59773 r64420 1 1 /* 2 Copyright (C) 2004, 2005 Nikolas Zimmermann < wildfox@kde.org>2 Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org> 3 3 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org> 4 4 … … 21 21 #ifndef SVGStyleElement_h 22 22 #define SVGStyleElement_h 23 23 24 #if ENABLE(SVG) 24 25 #include <SVGElement.h> 25 #include "SVGElement.h" 26 26 #include "SVGLangSpace.h" 27 27 #include "StyleElement.h" … … 29 29 namespace WebCore { 30 30 31 class SVGStyleElement : public SVGElement, 32 public SVGLangSpace,33 34 35 31 class SVGStyleElement : public SVGElement 32 , public SVGLangSpace 33 , public StyleElement { 34 public: 35 SVGStyleElement(const QualifiedName&, Document*, bool createdByParser); 36 36 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); 42 41 43 42 virtual void finishParsingChildren(); 44 43 45 virtual bool sheetLoaded(); 44 virtual bool isLoading() const { return StyleElement::isLoading(); } 45 virtual bool sheetLoaded() { return StyleElement::sheetLoaded(document()); } 46 46 47 48 47 virtual const AtomicString& type() const; 48 void setType(const AtomicString&, ExceptionCode&); 49 49 50 51 50 virtual const AtomicString& media() const; 51 void setMedia(const AtomicString&, ExceptionCode&); 52 52 53 54 53 virtual String title() const; 54 void setTitle(const AtomicString&, ExceptionCode&); 55 55 56 StyleSheet* sheet(); 57 58 protected: 59 bool m_createdByParser; 60 }; 56 StyleSheet* sheet(); 57 }; 61 58 62 59 } // namespace WebCore … … 64 61 #endif // ENABLE(SVG) 65 62 #endif // SVGStyleElement_h 66 67 // vim:ts=4:noet
Note: See TracChangeset
for help on using the changeset viewer.