OLD | NEW |
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, 2010 Apple Inc. All rights reserved. | 5 * Copyright (C) 2003, 2010 Apple Inc. All rights reserved. |
6 * (C) 2007 Rob Buis (buis@kde.org) | 6 * (C) 2007 Rob Buis (buis@kde.org) |
7 * | 7 * |
8 * This library is free software; you can redistribute it and/or | 8 * This library is free software; you can redistribute it and/or |
9 * modify it under the terms of the GNU Library General Public | 9 * modify it under the terms of the GNU Library General Public |
10 * License as published by the Free Software Foundation; either | 10 * License as published by the Free Software Foundation; either |
11 * version 2 of the License, or (at your option) any later version. | 11 * version 2 of the License, or (at your option) any later version. |
12 * | 12 * |
13 * This library is distributed in the hope that it will be useful, | 13 * This library is distributed in the hope that it will be useful, |
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
16 * Library General Public License for more details. | 16 * Library General Public License for more details. |
17 * | 17 * |
18 * You should have received a copy of the GNU Library General Public License | 18 * You should have received a copy of the GNU Library General Public License |
19 * along with this library; see the file COPYING.LIB. If not, write to | 19 * along with this library; see the file COPYING.LIB. If not, write to |
20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
21 * Boston, MA 02110-1301, USA. | 21 * Boston, MA 02110-1301, USA. |
22 */ | 22 */ |
23 | 23 |
24 #include "core/html/HTMLStyleElement.h" | 24 #include "core/html/HTMLStyleElement.h" |
25 | 25 |
26 #include "core/HTMLNames.h" | 26 #include "core/HTMLNames.h" |
27 #include "core/css/MediaList.h" | 27 #include "core/css/MediaList.h" |
28 #include "core/dom/Document.h" | 28 #include "core/dom/Document.h" |
29 #include "core/dom/StyleEngine.h" | 29 #include "core/dom/StyleEngine.h" |
| 30 #include "core/dom/TaskRunnerHelper.h" |
30 #include "core/dom/shadow/ShadowRoot.h" | 31 #include "core/dom/shadow/ShadowRoot.h" |
31 #include "core/events/Event.h" | 32 #include "core/events/Event.h" |
32 #include "core/events/EventSender.h" | |
33 | 33 |
34 namespace blink { | 34 namespace blink { |
35 | 35 |
36 using namespace HTMLNames; | 36 using namespace HTMLNames; |
37 | 37 |
38 static StyleEventSender& styleLoadEventSender() { | |
39 DEFINE_STATIC_LOCAL(StyleEventSender, sharedLoadEventSender, | |
40 (StyleEventSender::create(EventTypeNames::load))); | |
41 return sharedLoadEventSender; | |
42 } | |
43 | |
44 inline HTMLStyleElement::HTMLStyleElement(Document& document, | 38 inline HTMLStyleElement::HTMLStyleElement(Document& document, |
45 bool createdByParser) | 39 bool createdByParser) |
46 : HTMLElement(styleTag, document), | 40 : HTMLElement(styleTag, document), |
47 StyleElement(&document, createdByParser), | 41 StyleElement(&document, createdByParser), |
48 m_firedLoad(false), | 42 m_firedLoad(false), |
49 m_loadedSheet(false) {} | 43 m_loadedSheet(false) {} |
50 | 44 |
51 HTMLStyleElement::~HTMLStyleElement() {} | 45 HTMLStyleElement::~HTMLStyleElement() {} |
52 | 46 |
53 HTMLStyleElement* HTMLStyleElement::create(Document& document, | 47 HTMLStyleElement* HTMLStyleElement::create(Document& document, |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 } | 100 } |
107 | 101 |
108 const AtomicString& HTMLStyleElement::media() const { | 102 const AtomicString& HTMLStyleElement::media() const { |
109 return getAttribute(mediaAttr); | 103 return getAttribute(mediaAttr); |
110 } | 104 } |
111 | 105 |
112 const AtomicString& HTMLStyleElement::type() const { | 106 const AtomicString& HTMLStyleElement::type() const { |
113 return getAttribute(typeAttr); | 107 return getAttribute(typeAttr); |
114 } | 108 } |
115 | 109 |
116 void HTMLStyleElement::dispatchPendingLoadEvents() { | 110 void HTMLStyleElement::dispatchPendingEvent( |
117 styleLoadEventSender().dispatchPendingEvents(); | 111 std::unique_ptr<IncrementLoadEventDelayCount>) { |
118 } | |
119 | |
120 void HTMLStyleElement::dispatchPendingEvent(StyleEventSender* eventSender) { | |
121 DCHECK_EQ(eventSender, &styleLoadEventSender()); | |
122 dispatchEvent(Event::create(m_loadedSheet ? EventTypeNames::load | 112 dispatchEvent(Event::create(m_loadedSheet ? EventTypeNames::load |
123 : EventTypeNames::error)); | 113 : EventTypeNames::error)); |
124 } | 114 } |
125 | 115 |
126 void HTMLStyleElement::notifyLoadedSheetAndAllCriticalSubresources( | 116 void HTMLStyleElement::notifyLoadedSheetAndAllCriticalSubresources( |
127 LoadedSheetErrorStatus errorStatus) { | 117 LoadedSheetErrorStatus errorStatus) { |
128 bool isLoadEvent = errorStatus == NoErrorLoadingSubresource; | 118 bool isLoadEvent = errorStatus == NoErrorLoadingSubresource; |
129 if (m_firedLoad && isLoadEvent) | 119 if (m_firedLoad && isLoadEvent) |
130 return; | 120 return; |
131 m_loadedSheet = isLoadEvent; | 121 m_loadedSheet = isLoadEvent; |
132 styleLoadEventSender().dispatchEventSoon(this); | 122 TaskRunnerHelper::get(TaskType::DOMManipulation, &document()) |
| 123 ->postTask( |
| 124 BLINK_FROM_HERE, |
| 125 WTF::bind(&HTMLStyleElement::dispatchPendingEvent, |
| 126 wrapPersistent(this), |
| 127 passed(IncrementLoadEventDelayCount::create(document())))); |
133 m_firedLoad = true; | 128 m_firedLoad = true; |
134 } | 129 } |
135 | 130 |
136 bool HTMLStyleElement::disabled() const { | 131 bool HTMLStyleElement::disabled() const { |
137 if (!m_sheet) | 132 if (!m_sheet) |
138 return false; | 133 return false; |
139 | 134 |
140 return m_sheet->disabled(); | 135 return m_sheet->disabled(); |
141 } | 136 } |
142 | 137 |
143 void HTMLStyleElement::setDisabled(bool setDisabled) { | 138 void HTMLStyleElement::setDisabled(bool setDisabled) { |
144 if (CSSStyleSheet* styleSheet = sheet()) | 139 if (CSSStyleSheet* styleSheet = sheet()) |
145 styleSheet->setDisabled(setDisabled); | 140 styleSheet->setDisabled(setDisabled); |
146 } | 141 } |
147 | 142 |
148 DEFINE_TRACE(HTMLStyleElement) { | 143 DEFINE_TRACE(HTMLStyleElement) { |
149 StyleElement::trace(visitor); | 144 StyleElement::trace(visitor); |
150 HTMLElement::trace(visitor); | 145 HTMLElement::trace(visitor); |
151 } | 146 } |
152 | 147 |
153 } // namespace blink | 148 } // namespace blink |
OLD | NEW |