Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(150)

Side by Side Diff: Source/core/html/HTMLScriptElement.cpp

Issue 18676002: Refactoring: Decouple ScriptElement from HTMLScriptElement and SVGScriptElement. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Addressed points Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/html/HTMLScriptElement.h ('k') | Source/core/svg/SVGScriptElement.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Dirk Mueller (mueller@kde.org) 4 * (C) 2001 Dirk Mueller (mueller@kde.org)
5 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserv ed. 5 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserv ed.
6 * 6 *
7 * This library is free software; you can redistribute it and/or 7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public 8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either 9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version. 10 * version 2 of the License, or (at your option) any later version.
(...skipping 19 matching lines...) Expand all
30 #include "core/dom/Event.h" 30 #include "core/dom/Event.h"
31 #include "core/dom/EventNames.h" 31 #include "core/dom/EventNames.h"
32 #include "core/dom/Text.h" 32 #include "core/dom/Text.h"
33 33
34 namespace WebCore { 34 namespace WebCore {
35 35
36 using namespace HTMLNames; 36 using namespace HTMLNames;
37 37
38 inline HTMLScriptElement::HTMLScriptElement(const QualifiedName& tagName, Docume nt* document, bool wasInsertedByParser, bool alreadyStarted) 38 inline HTMLScriptElement::HTMLScriptElement(const QualifiedName& tagName, Docume nt* document, bool wasInsertedByParser, bool alreadyStarted)
39 : HTMLElement(tagName, document) 39 : HTMLElement(tagName, document)
40 , ScriptElement(this, wasInsertedByParser, alreadyStarted) 40 , m_scriptElement(ScriptElement::create(this, wasInsertedByParser, alreadySt arted))
41 { 41 {
42 ASSERT(hasTagName(scriptTag)); 42 ASSERT(hasTagName(scriptTag));
43 ScriptWrappable::init(this); 43 ScriptWrappable::init(this);
44 } 44 }
45 45
46 PassRefPtr<HTMLScriptElement> HTMLScriptElement::create(const QualifiedName& tag Name, Document* document, bool wasInsertedByParser, bool alreadyStarted) 46 PassRefPtr<HTMLScriptElement> HTMLScriptElement::create(const QualifiedName& tag Name, Document* document, bool wasInsertedByParser, bool alreadyStarted)
47 { 47 {
48 return adoptRef(new HTMLScriptElement(tagName, document, wasInsertedByParser , alreadyStarted)); 48 return adoptRef(new HTMLScriptElement(tagName, document, wasInsertedByParser , alreadyStarted));
49 } 49 }
50 50
51 bool HTMLScriptElement::isURLAttribute(const Attribute& attribute) const 51 bool HTMLScriptElement::isURLAttribute(const Attribute& attribute) const
52 { 52 {
53 return attribute.name() == srcAttr || HTMLElement::isURLAttribute(attribute) ; 53 return attribute.name() == srcAttr || HTMLElement::isURLAttribute(attribute) ;
54 } 54 }
55 55
56 void HTMLScriptElement::childrenChanged(bool changedByParser, Node* beforeChange , Node* afterChange, int childCountDelta) 56 void HTMLScriptElement::childrenChanged(bool changedByParser, Node* beforeChange , Node* afterChange, int childCountDelta)
57 { 57 {
58 HTMLElement::childrenChanged(changedByParser, beforeChange, afterChange, chi ldCountDelta); 58 HTMLElement::childrenChanged(changedByParser, beforeChange, afterChange, chi ldCountDelta);
59 ScriptElement::childrenChanged(); 59 m_scriptElement->childrenChanged();
60 } 60 }
61 61
62 void HTMLScriptElement::parseAttribute(const QualifiedName& name, const AtomicSt ring& value) 62 void HTMLScriptElement::parseAttribute(const QualifiedName& name, const AtomicSt ring& value)
63 { 63 {
64 if (name == srcAttr) 64 if (name == srcAttr)
65 handleSourceAttribute(value); 65 m_scriptElement->handleSourceAttribute(value);
66 else if (name == asyncAttr) 66 else if (name == asyncAttr)
67 handleAsyncAttribute(); 67 m_scriptElement->handleAsyncAttribute();
68 else if (name == onbeforeloadAttr) 68 else if (name == onbeforeloadAttr)
69 setAttributeEventListener(eventNames().beforeloadEvent, createAttributeE ventListener(this, name, value)); 69 setAttributeEventListener(eventNames().beforeloadEvent, createAttributeE ventListener(this, name, value));
70 else 70 else
71 HTMLElement::parseAttribute(name, value); 71 HTMLElement::parseAttribute(name, value);
72 } 72 }
73 73
74 Node::InsertionNotificationRequest HTMLScriptElement::insertedInto(ContainerNode * insertionPoint) 74 Node::InsertionNotificationRequest HTMLScriptElement::insertedInto(ContainerNode * insertionPoint)
75 { 75 {
76 HTMLElement::insertedInto(insertionPoint); 76 HTMLElement::insertedInto(insertionPoint);
77 ScriptElement::insertedInto(insertionPoint); 77 m_scriptElement->insertedInto(insertionPoint);
78 return InsertionDone; 78 return InsertionDone;
79 } 79 }
80 80
81 void HTMLScriptElement::setText(const String &value) 81 void HTMLScriptElement::setText(const String &value)
82 { 82 {
83 RefPtr<Node> protectFromMutationEvents(this); 83 RefPtr<Node> protectFromMutationEvents(this);
84 84
85 int numChildren = childNodeCount(); 85 int numChildren = childNodeCount();
86 86
87 if (numChildren == 1 && firstChild()->isTextNode()) { 87 if (numChildren == 1 && firstChild()->isTextNode()) {
88 toText(firstChild())->setData(value); 88 toText(firstChild())->setData(value);
89 return; 89 return;
90 } 90 }
91 91
92 if (numChildren > 0) 92 if (numChildren > 0)
93 removeChildren(); 93 removeChildren();
94 94
95 appendChild(document()->createTextNode(value.impl()), IGNORE_EXCEPTION); 95 appendChild(document()->createTextNode(value.impl()), IGNORE_EXCEPTION);
96 } 96 }
97 97
98 void HTMLScriptElement::setAsync(bool async) 98 void HTMLScriptElement::setAsync(bool async)
99 { 99 {
100 setBooleanAttribute(asyncAttr, async); 100 setBooleanAttribute(asyncAttr, async);
101 handleAsyncAttribute(); 101 m_scriptElement->handleAsyncAttribute();
102 } 102 }
103 103
104 bool HTMLScriptElement::async() const 104 bool HTMLScriptElement::async() const
105 { 105 {
106 return fastHasAttribute(asyncAttr) || forceAsync(); 106 return fastHasAttribute(asyncAttr) || (m_scriptElement->forceAsync());
107 } 107 }
108 108
109 KURL HTMLScriptElement::src() const 109 KURL HTMLScriptElement::src() const
110 { 110 {
111 return document()->completeURL(sourceAttributeValue()); 111 return document()->completeURL(sourceAttributeValue());
112 } 112 }
113 113
114 void HTMLScriptElement::addSubresourceAttributeURLs(ListHashSet<KURL>& urls) con st 114 void HTMLScriptElement::addSubresourceAttributeURLs(ListHashSet<KURL>& urls) con st
115 { 115 {
116 HTMLElement::addSubresourceAttributeURLs(urls); 116 HTMLElement::addSubresourceAttributeURLs(urls);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 return fastHasAttribute(deferAttr); 158 return fastHasAttribute(deferAttr);
159 } 159 }
160 160
161 bool HTMLScriptElement::hasSourceAttribute() const 161 bool HTMLScriptElement::hasSourceAttribute() const
162 { 162 {
163 return fastHasAttribute(srcAttr); 163 return fastHasAttribute(srcAttr);
164 } 164 }
165 165
166 void HTMLScriptElement::dispatchLoadEvent() 166 void HTMLScriptElement::dispatchLoadEvent()
167 { 167 {
168 ASSERT(!haveFiredLoadEvent());
169 setHaveFiredLoadEvent(true);
170
171 dispatchEvent(Event::create(eventNames().loadEvent, false, false)); 168 dispatchEvent(Event::create(eventNames().loadEvent, false, false));
172 } 169 }
173 170
174 PassRefPtr<Element> HTMLScriptElement::cloneElementWithoutAttributesAndChildren( ) 171 PassRefPtr<Element> HTMLScriptElement::cloneElementWithoutAttributesAndChildren( )
175 { 172 {
176 return adoptRef(new HTMLScriptElement(tagQName(), document(), false, already Started())); 173 return adoptRef(new HTMLScriptElement(tagQName(), document(), false, m_scrip tElement->alreadyStarted()));
177 } 174 }
178 175
179 } 176 }
OLDNEW
« no previous file with comments | « Source/core/html/HTMLScriptElement.h ('k') | Source/core/svg/SVGScriptElement.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698