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

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

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

Powered by Google App Engine
This is Rietveld 408576698