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

Side by Side Diff: sky/engine/core/html/HTMLSourceElement.cpp

Issue 706093002: Remove <picture> and <source>. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: ojan review Created 6 years, 1 month 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
« no previous file with comments | « sky/engine/core/html/HTMLSourceElement.h ('k') | sky/engine/core/html/HTMLSourceElement.idl » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2007, 2008, 2010 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26 #include "config.h"
27 #include "core/html/HTMLSourceElement.h"
28
29 #include "core/HTMLNames.h"
30 #include "core/css/MediaList.h"
31 #include "core/css/MediaQueryList.h"
32 #include "core/css/MediaQueryMatcher.h"
33 #include "core/dom/Document.h"
34 #include "core/events/Event.h"
35 #include "core/events/EventSender.h"
36 #include "core/html/HTMLPictureElement.h"
37 #include "platform/Logging.h"
38
39 namespace blink {
40
41 static SourceEventSender& sourceErrorEventSender()
42 {
43 DEFINE_STATIC_LOCAL(SourceEventSender, sharedErrorEventSender, (EventTypeNam es::error));
44 return sharedErrorEventSender;
45 }
46
47 class HTMLSourceElement::Listener final : public MediaQueryListListener {
48 public:
49 explicit Listener(HTMLSourceElement* element) : m_element(element) { }
50 virtual void notifyMediaQueryChanged() override
51 {
52 if (m_element)
53 m_element->notifyMediaQueryChanged();
54 }
55
56 void clearElement() { m_element = nullptr; }
57 virtual void trace(Visitor* visitor) override
58 {
59 visitor->trace(m_element);
60 MediaQueryListListener::trace(visitor);
61 }
62 private:
63 RawPtr<HTMLSourceElement> m_element;
64 };
65
66 inline HTMLSourceElement::HTMLSourceElement(Document& document)
67 : HTMLElement(HTMLNames::sourceTag, document)
68 , m_listener(adoptRef(new Listener(this)))
69 {
70 WTF_LOG(Media, "HTMLSourceElement::HTMLSourceElement - %p", this);
71 ScriptWrappable::init(this);
72 }
73
74 DEFINE_NODE_FACTORY(HTMLSourceElement)
75
76 HTMLSourceElement::~HTMLSourceElement()
77 {
78 sourceErrorEventSender().cancelEvent(this);
79 #if !ENABLE(OILPAN)
80 m_listener->clearElement();
81 #endif
82 }
83
84 Node::InsertionNotificationRequest HTMLSourceElement::insertedInto(ContainerNode * insertionPoint)
85 {
86 HTMLElement::insertedInto(insertionPoint);
87 Element* parent = parentElement();
88 if (isHTMLPictureElement(parent))
89 toHTMLPictureElement(parent)->sourceOrMediaChanged();
90 return InsertionDone;
91 }
92
93 void HTMLSourceElement::removedFrom(ContainerNode* removalRoot)
94 {
95 Element* parent = parentElement();
96 if (!parent && removalRoot->isElementNode())
97 parent = toElement(removalRoot);
98 if (isHTMLPictureElement(parent))
99 toHTMLPictureElement(parent)->sourceOrMediaChanged();
100 HTMLElement::removedFrom(removalRoot);
101 }
102
103 void HTMLSourceElement::setSrc(const String& url)
104 {
105 setAttribute(HTMLNames::srcAttr, AtomicString(url));
106 }
107
108 const AtomicString& HTMLSourceElement::type() const
109 {
110 return getAttribute(HTMLNames::typeAttr);
111 }
112
113 void HTMLSourceElement::setType(const AtomicString& type)
114 {
115 setAttribute(HTMLNames::typeAttr, type);
116 }
117
118 void HTMLSourceElement::scheduleErrorEvent()
119 {
120 WTF_LOG(Media, "HTMLSourceElement::scheduleErrorEvent - %p", this);
121 sourceErrorEventSender().dispatchEventSoon(this);
122 }
123
124 void HTMLSourceElement::cancelPendingErrorEvent()
125 {
126 WTF_LOG(Media, "HTMLSourceElement::cancelPendingErrorEvent - %p", this);
127 sourceErrorEventSender().cancelEvent(this);
128 }
129
130 void HTMLSourceElement::dispatchPendingEvent(SourceEventSender* eventSender)
131 {
132 ASSERT_UNUSED(eventSender, eventSender == &sourceErrorEventSender());
133 WTF_LOG(Media, "HTMLSourceElement::dispatchPendingEvent - %p", this);
134 dispatchEvent(Event::createCancelable(EventTypeNames::error));
135 }
136
137 bool HTMLSourceElement::mediaQueryMatches() const
138 {
139 if (!m_mediaQueryList)
140 return true;
141
142 return m_mediaQueryList->matches();
143 }
144
145 bool HTMLSourceElement::isURLAttribute(const Attribute& attribute) const
146 {
147 return attribute.name() == HTMLNames::srcAttr || HTMLElement::isURLAttribute (attribute);
148 }
149
150 void HTMLSourceElement::parseAttribute(const QualifiedName& name, const AtomicSt ring& value)
151 {
152 HTMLElement::parseAttribute(name, value);
153 if (name == HTMLNames::mediaAttr) {
154 if (m_mediaQueryList)
155 m_mediaQueryList->removeListener(m_listener);
156 RefPtr<MediaQuerySet> set = MediaQuerySet::create(value);
157 m_mediaQueryList = MediaQueryList::create(&document(), &document().media QueryMatcher(), set.release());
158 m_mediaQueryList->addListener(m_listener);
159 }
160 if (name == HTMLNames::srcsetAttr
161 || name == HTMLNames::sizesAttr
162 || name == HTMLNames::mediaAttr
163 || name == HTMLNames::typeAttr) {
164 Element* parent = parentElement();
165 if (isHTMLPictureElement(parent))
166 toHTMLPictureElement(parent)->sourceOrMediaChanged();
167 }
168 }
169
170 void HTMLSourceElement::notifyMediaQueryChanged()
171 {
172 Element* parent = parentElement();
173 if (isHTMLPictureElement(parent))
174 toHTMLPictureElement(parent)->sourceOrMediaChanged();
175 }
176
177 void HTMLSourceElement::trace(Visitor* visitor)
178 {
179 visitor->trace(m_mediaQueryList);
180 visitor->trace(m_listener);
181 HTMLElement::trace(visitor);
182 }
183
184 }
OLDNEW
« no previous file with comments | « sky/engine/core/html/HTMLSourceElement.h ('k') | sky/engine/core/html/HTMLSourceElement.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698