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

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: review comments 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
46 inline HTMLSourceElement::HTMLSourceElement(Document& document) 50 inline HTMLSourceElement::HTMLSourceElement(Document& document)
47 : HTMLElement(sourceTag, document) 51 : HTMLElement(sourceTag, document)
52 , m_listener(adoptRefWillBeNoop(new Listener(this)))
48 { 53 {
49 WTF_LOG(Media, "HTMLSourceElement::HTMLSourceElement - %p", this); 54 WTF_LOG(Media, "HTMLSourceElement::HTMLSourceElement - %p", this);
50 ScriptWrappable::init(this); 55 ScriptWrappable::init(this);
51 } 56 }
52 57
53 DEFINE_NODE_FACTORY(HTMLSourceElement) 58 DEFINE_NODE_FACTORY(HTMLSourceElement)
54 59
55 HTMLSourceElement::~HTMLSourceElement() 60 HTMLSourceElement::~HTMLSourceElement()
56 { 61 {
57 sourceErrorEventSender().cancelEvent(this); 62 sourceErrorEventSender().cancelEvent(this);
63 m_listener->clearElement();
58 } 64 }
59 65
60 Node::InsertionNotificationRequest HTMLSourceElement::insertedInto(ContainerNode * insertionPoint) 66 Node::InsertionNotificationRequest HTMLSourceElement::insertedInto(ContainerNode * insertionPoint)
61 { 67 {
62 HTMLElement::insertedInto(insertionPoint); 68 HTMLElement::insertedInto(insertionPoint);
63 Element* parent = parentElement(); 69 Element* parent = parentElement();
64 if (isHTMLMediaElement(parent)) 70 if (isHTMLMediaElement(parent))
65 toHTMLMediaElement(parent)->sourceWasAdded(this); 71 toHTMLMediaElement(parent)->sourceWasAdded(this);
66 if (isHTMLPictureElement(parent)) 72 if (isHTMLPictureElement(parent))
67 toHTMLPictureElement(parent)->sourceOrMediaChanged(); 73 toHTMLPictureElement(parent)->sourceOrMediaChanged();
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 sourceErrorEventSender().cancelEvent(this); 113 sourceErrorEventSender().cancelEvent(this);
108 } 114 }
109 115
110 void HTMLSourceElement::dispatchPendingEvent(SourceEventSender* eventSender) 116 void HTMLSourceElement::dispatchPendingEvent(SourceEventSender* eventSender)
111 { 117 {
112 ASSERT_UNUSED(eventSender, eventSender == &sourceErrorEventSender()); 118 ASSERT_UNUSED(eventSender, eventSender == &sourceErrorEventSender());
113 WTF_LOG(Media, "HTMLSourceElement::dispatchPendingEvent - %p", this); 119 WTF_LOG(Media, "HTMLSourceElement::dispatchPendingEvent - %p", this);
114 dispatchEvent(Event::createCancelable(EventTypeNames::error)); 120 dispatchEvent(Event::createCancelable(EventTypeNames::error));
115 } 121 }
116 122
123 bool HTMLSourceElement::mediaQueryMatches() const
124 {
125 if (!m_mediaQueryList)
126 return true;
127
128 return m_mediaQueryList->matches();
129 }
130
117 bool HTMLSourceElement::isURLAttribute(const Attribute& attribute) const 131 bool HTMLSourceElement::isURLAttribute(const Attribute& attribute) const
118 { 132 {
119 return attribute.name() == srcAttr || HTMLElement::isURLAttribute(attribute) ; 133 return attribute.name() == srcAttr || HTMLElement::isURLAttribute(attribute) ;
120 } 134 }
121 135
122 void HTMLSourceElement::parseAttribute(const QualifiedName& name, const AtomicSt ring& value) 136 void HTMLSourceElement::parseAttribute(const QualifiedName& name, const AtomicSt ring& value)
123 { 137 {
124 HTMLElement::parseAttribute(name, value); 138 HTMLElement::parseAttribute(name, value);
139 if (name == mediaAttr) {
140 if (m_mediaQueryList)
141 m_mediaQueryList->removeListener(m_listener);
142 RefPtrWillBeRawPtr<MediaQuerySet> set = MediaQuerySet::create(value);
143 m_mediaQueryList = MediaQueryList::create(&document().mediaQueryMatcher( ), set.release());
144 m_mediaQueryList->addListener(m_listener);
145 }
125 if (name == srcsetAttr || name == sizesAttr || name == mediaAttr || name == typeAttr) { 146 if (name == srcsetAttr || name == sizesAttr || name == mediaAttr || name == typeAttr) {
126 Element* parent = parentElement(); 147 Element* parent = parentElement();
127 if (isHTMLPictureElement(parent)) 148 if (isHTMLPictureElement(parent))
128 toHTMLPictureElement(parent)->sourceOrMediaChanged(); 149 toHTMLPictureElement(parent)->sourceOrMediaChanged();
129 } 150 }
130 } 151 }
131 152
153 void HTMLSourceElement::notifyMediaQueryChanged()
154 {
155 Element* parent = parentElement();
156 if (isHTMLPictureElement(parent))
157 toHTMLPictureElement(parent)->sourceOrMediaChanged();
132 } 158 }
159
160 }
OLDNEW
« Source/core/html/HTMLSourceElement.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