| 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" | |
| 31 #include "core/dom/shadow/ShadowRoot.h" | 30 #include "core/dom/shadow/ShadowRoot.h" |
| 32 #include "core/events/Event.h" | 31 #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 |
| 38 inline HTMLStyleElement::HTMLStyleElement(Document& document, | 44 inline HTMLStyleElement::HTMLStyleElement(Document& document, |
| 39 bool createdByParser) | 45 bool createdByParser) |
| 40 : HTMLElement(styleTag, document), | 46 : HTMLElement(styleTag, document), |
| 41 StyleElement(&document, createdByParser), | 47 StyleElement(&document, createdByParser), |
| 42 m_firedLoad(false), | 48 m_firedLoad(false), |
| 43 m_loadedSheet(false) {} | 49 m_loadedSheet(false) {} |
| 44 | 50 |
| 45 HTMLStyleElement::~HTMLStyleElement() {} | 51 HTMLStyleElement::~HTMLStyleElement() {} |
| 46 | 52 |
| 47 HTMLStyleElement* HTMLStyleElement::create(Document& document, | 53 HTMLStyleElement* HTMLStyleElement::create(Document& document, |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 } | 106 } |
| 101 | 107 |
| 102 const AtomicString& HTMLStyleElement::media() const { | 108 const AtomicString& HTMLStyleElement::media() const { |
| 103 return getAttribute(mediaAttr); | 109 return getAttribute(mediaAttr); |
| 104 } | 110 } |
| 105 | 111 |
| 106 const AtomicString& HTMLStyleElement::type() const { | 112 const AtomicString& HTMLStyleElement::type() const { |
| 107 return getAttribute(typeAttr); | 113 return getAttribute(typeAttr); |
| 108 } | 114 } |
| 109 | 115 |
| 110 void HTMLStyleElement::dispatchPendingEvent( | 116 void HTMLStyleElement::dispatchPendingLoadEvents() { |
| 111 std::unique_ptr<IncrementLoadEventDelayCount>) { | 117 styleLoadEventSender().dispatchPendingEvents(); |
| 118 } |
| 119 |
| 120 void HTMLStyleElement::dispatchPendingEvent(StyleEventSender* eventSender) { |
| 121 DCHECK_EQ(eventSender, &styleLoadEventSender()); |
| 112 dispatchEvent(Event::create(m_loadedSheet ? EventTypeNames::load | 122 dispatchEvent(Event::create(m_loadedSheet ? EventTypeNames::load |
| 113 : EventTypeNames::error)); | 123 : EventTypeNames::error)); |
| 114 } | 124 } |
| 115 | 125 |
| 116 void HTMLStyleElement::notifyLoadedSheetAndAllCriticalSubresources( | 126 void HTMLStyleElement::notifyLoadedSheetAndAllCriticalSubresources( |
| 117 LoadedSheetErrorStatus errorStatus) { | 127 LoadedSheetErrorStatus errorStatus) { |
| 118 bool isLoadEvent = errorStatus == NoErrorLoadingSubresource; | 128 bool isLoadEvent = errorStatus == NoErrorLoadingSubresource; |
| 119 if (m_firedLoad && isLoadEvent) | 129 if (m_firedLoad && isLoadEvent) |
| 120 return; | 130 return; |
| 121 m_loadedSheet = isLoadEvent; | 131 m_loadedSheet = isLoadEvent; |
| 122 TaskRunnerHelper::get(TaskType::DOMManipulation, &document()) | 132 styleLoadEventSender().dispatchEventSoon(this); |
| 123 ->postTask( | |
| 124 BLINK_FROM_HERE, | |
| 125 WTF::bind(&HTMLStyleElement::dispatchPendingEvent, | |
| 126 wrapPersistent(this), | |
| 127 passed(IncrementLoadEventDelayCount::create(document())))); | |
| 128 m_firedLoad = true; | 133 m_firedLoad = true; |
| 129 } | 134 } |
| 130 | 135 |
| 131 bool HTMLStyleElement::disabled() const { | 136 bool HTMLStyleElement::disabled() const { |
| 132 if (!m_sheet) | 137 if (!m_sheet) |
| 133 return false; | 138 return false; |
| 134 | 139 |
| 135 return m_sheet->disabled(); | 140 return m_sheet->disabled(); |
| 136 } | 141 } |
| 137 | 142 |
| 138 void HTMLStyleElement::setDisabled(bool setDisabled) { | 143 void HTMLStyleElement::setDisabled(bool setDisabled) { |
| 139 if (CSSStyleSheet* styleSheet = sheet()) | 144 if (CSSStyleSheet* styleSheet = sheet()) |
| 140 styleSheet->setDisabled(setDisabled); | 145 styleSheet->setDisabled(setDisabled); |
| 141 } | 146 } |
| 142 | 147 |
| 143 DEFINE_TRACE(HTMLStyleElement) { | 148 DEFINE_TRACE(HTMLStyleElement) { |
| 144 StyleElement::trace(visitor); | 149 StyleElement::trace(visitor); |
| 145 HTMLElement::trace(visitor); | 150 HTMLElement::trace(visitor); |
| 146 } | 151 } |
| 147 | 152 |
| 148 } // namespace blink | 153 } // namespace blink |
| OLD | NEW |