Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. | 2 * Copyright (C) 2008 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 |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 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 "core/html/MediaDocument.h" | 26 #include "core/html/MediaDocument.h" |
| 27 | 27 |
| 28 #include "bindings/core/v8/ExceptionStatePlaceholder.h" | 28 #include "bindings/core/v8/ExceptionStatePlaceholder.h" |
| 29 #include "core/HTMLNames.h" | 29 #include "core/HTMLNames.h" |
| 30 #include "core/dom/ElementTraversal.h" | 30 #include "core/dom/ElementTraversal.h" |
| 31 #include "core/dom/RawDataDocumentParser.h" | 31 #include "core/dom/RawDataDocumentParser.h" |
| 32 #include "core/events/EventListener.h" | |
| 32 #include "core/events/KeyboardEvent.h" | 33 #include "core/events/KeyboardEvent.h" |
| 33 #include "core/frame/LocalFrame.h" | 34 #include "core/frame/LocalFrame.h" |
| 35 #include "core/html/HTMLAnchorElement.h" | |
| 34 #include "core/html/HTMLBodyElement.h" | 36 #include "core/html/HTMLBodyElement.h" |
| 35 #include "core/html/HTMLHeadElement.h" | 37 #include "core/html/HTMLHeadElement.h" |
| 36 #include "core/html/HTMLHtmlElement.h" | 38 #include "core/html/HTMLHtmlElement.h" |
| 37 #include "core/html/HTMLMetaElement.h" | 39 #include "core/html/HTMLMetaElement.h" |
| 38 #include "core/html/HTMLSourceElement.h" | 40 #include "core/html/HTMLSourceElement.h" |
| 39 #include "core/html/HTMLVideoElement.h" | 41 #include "core/html/HTMLVideoElement.h" |
| 40 #include "core/loader/DocumentLoader.h" | 42 #include "core/loader/DocumentLoader.h" |
| 41 #include "core/loader/FrameLoader.h" | 43 #include "core/loader/FrameLoader.h" |
| 42 #include "core/loader/FrameLoaderClient.h" | 44 #include "core/loader/FrameLoaderClient.h" |
| 43 #include "platform/KeyboardCodes.h" | 45 #include "platform/KeyboardCodes.h" |
| 46 #include "platform/text/PlatformLocale.h" | |
| 44 | 47 |
| 45 namespace blink { | 48 namespace blink { |
| 46 | 49 |
| 47 using namespace HTMLNames; | 50 using namespace HTMLNames; |
| 48 | 51 |
| 49 // FIXME: Share more code with PluginDocumentParser. | 52 // FIXME: Share more code with PluginDocumentParser. |
| 50 class MediaDocumentParser : public RawDataDocumentParser { | 53 class MediaDocumentParser : public RawDataDocumentParser { |
| 51 public: | 54 public: |
| 52 static PassRefPtrWillBeRawPtr<MediaDocumentParser> create(MediaDocument* doc ument) | 55 static PassRefPtrWillBeRawPtr<MediaDocumentParser> create(MediaDocument* doc ument) |
| 53 { | 56 { |
| 54 return adoptRefWillBeNoop(new MediaDocumentParser(document)); | 57 return adoptRefWillBeNoop(new MediaDocumentParser(document)); |
| 55 } | 58 } |
| 56 | 59 |
| 57 private: | 60 private: |
| 58 explicit MediaDocumentParser(Document* document) | 61 explicit MediaDocumentParser(Document* document) |
| 59 : RawDataDocumentParser(document) | 62 : RawDataDocumentParser(document) |
| 60 , m_didBuildDocumentStructure(false) | 63 , m_didBuildDocumentStructure(false) |
| 61 { | 64 { |
| 62 } | 65 } |
| 63 | 66 |
| 64 void appendBytes(const char*, size_t) override; | 67 void appendBytes(const char*, size_t) override; |
| 65 | 68 |
| 66 void createDocumentStructure(); | 69 void createDocumentStructure(); |
| 67 | 70 |
| 68 bool m_didBuildDocumentStructure; | 71 bool m_didBuildDocumentStructure; |
| 69 }; | 72 }; |
| 70 | 73 |
| 74 class MediaEventListener : public EventListener { | |
|
esprehn
2016/03/11 00:35:32
final
qinmin
2016/03/11 23:50:55
Done. This class is no longer needed
| |
| 75 public: | |
| 76 static PassRefPtrWillBeRawPtr<MediaEventListener> create(MediaDocument* docu ment) | |
| 77 { | |
| 78 return adoptRefWillBeNoop(new MediaEventListener(document)); | |
| 79 } | |
| 80 | |
| 81 static const MediaEventListener* cast(const EventListener* listener) | |
|
esprehn
2016/03/11 00:35:32
this cast method doesn't seem used outside ==, jus
qinmin
2016/03/11 23:50:55
Done. Class removed
| |
| 82 { | |
| 83 return listener->type() == MediaEventListenerType | |
| 84 ? static_cast<const MediaEventListener*>(listener) : 0; | |
| 85 } | |
| 86 | |
| 87 bool operator==(const EventListener& other) const override; | |
| 88 | |
| 89 DEFINE_INLINE_VIRTUAL_TRACE() | |
| 90 { | |
| 91 visitor->trace(m_doc); | |
| 92 EventListener::trace(visitor); | |
| 93 } | |
| 94 | |
| 95 private: | |
| 96 MediaEventListener(MediaDocument* document) | |
|
esprehn
2016/03/11 00:35:33
explicit
qinmin
2016/03/11 23:50:55
Class removed.
| |
| 97 : EventListener(MediaEventListenerType) | |
| 98 , m_doc(document) | |
|
esprehn
2016/03/11 00:35:33
m_document, don't abbreviate
qinmin
2016/03/11 23:50:55
Class removed
| |
| 99 { | |
| 100 } | |
| 101 | |
| 102 virtual void handleEvent(ExecutionContext*, Event* event) | |
| 103 { | |
| 104 m_doc->updateLayout(); | |
|
esprehn
2016/03/11 00:35:33
you don't need the m_document thing, just do toDoc
qinmin
2016/03/11 23:50:55
Class removed
| |
| 105 } | |
| 106 | |
| 107 RawPtrWillBeMember<MediaDocument> m_doc; | |
| 108 }; | |
| 109 | |
| 71 void MediaDocumentParser::createDocumentStructure() | 110 void MediaDocumentParser::createDocumentStructure() |
| 72 { | 111 { |
| 73 ASSERT(document()); | 112 ASSERT(document()); |
| 74 RefPtrWillBeRawPtr<HTMLHtmlElement> rootElement = HTMLHtmlElement::create(*d ocument()); | 113 RefPtrWillBeRawPtr<HTMLHtmlElement> rootElement = HTMLHtmlElement::create(*d ocument()); |
| 75 rootElement->insertedByParser(); | 114 rootElement->insertedByParser(); |
| 76 document()->appendChild(rootElement); | 115 document()->appendChild(rootElement); |
| 77 | 116 |
| 78 if (document()->frame()) | 117 if (document()->frame()) |
| 79 document()->frame()->loader().dispatchDocumentElementAvailable(); | 118 document()->frame()->loader().dispatchDocumentElementAvailable(); |
| 80 | 119 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 91 | 130 |
| 92 RefPtrWillBeRawPtr<HTMLSourceElement> source = HTMLSourceElement::create(*do cument()); | 131 RefPtrWillBeRawPtr<HTMLSourceElement> source = HTMLSourceElement::create(*do cument()); |
| 93 source->setSrc(document()->url()); | 132 source->setSrc(document()->url()); |
| 94 | 133 |
| 95 if (DocumentLoader* loader = document()->loader()) | 134 if (DocumentLoader* loader = document()->loader()) |
| 96 source->setType(loader->responseMIMEType()); | 135 source->setType(loader->responseMIMEType()); |
| 97 | 136 |
| 98 media->appendChild(source.release()); | 137 media->appendChild(source.release()); |
| 99 | 138 |
| 100 RefPtrWillBeRawPtr<HTMLBodyElement> body = HTMLBodyElement::create(*document ()); | 139 RefPtrWillBeRawPtr<HTMLBodyElement> body = HTMLBodyElement::create(*document ()); |
| 140 | |
| 141 if (RuntimeEnabledFeatures::mediaDocumentDownloadButtonEnabled()) { | |
| 142 RefPtrWillBeRawPtr<EventListener> listener = MediaEventListener::create( static_cast<MediaDocument*>(document())); | |
|
esprehn
2016/03/11 00:35:33
toMediaDocument, don't static cast. If toMediaDocu
qinmin
2016/03/11 23:50:55
Line removed
| |
| 143 media->addEventListener("resize", listener, false); | |
|
esprehn
2016/03/11 00:35:33
forcing a layout for ever resize event doesn't mak
qinmin
2016/03/11 23:50:55
removed
| |
| 144 | |
| 145 RefPtrWillBeRawPtr<HTMLAnchorElement> anchor = HTMLAnchorElement::create (*document()); | |
| 146 anchor->setAttribute(downloadAttr, ""); | |
| 147 anchor->setURL(document()->url()); | |
| 148 anchor->setInnerText(document()->getCachedLocale(document()->contentLang uage()).queryString(WebLocalizedString::DownloadButtonLabel), ASSERT_NO_EXCEPTIO N); | |
|
esprehn
2016/03/11 00:35:32
setTextContent, don't use setInnerText
qinmin
2016/03/11 23:50:55
Done.
| |
| 149 // TODO(qinmin): Move these css to MediaControlsAndroidNew.css when http ://crbug.com/592080 is fixed. | |
| 150 anchor->setAttribute( | |
| 151 styleAttr, | |
| 152 "position: absolute;" | |
| 153 "display: block;" | |
| 154 "width: 120px;" | |
| 155 "height: 36px;" | |
| 156 "background: #4285F4;" | |
| 157 "font-family: Roboto;" | |
| 158 "font-size: 14px;" | |
| 159 "border-radius: 5px;" | |
| 160 "color: white;" | |
| 161 "font-weight: bold;" | |
| 162 "text-decoration:none;" | |
|
esprehn
2016/03/11 00:35:33
missing space, also this is so much stuff. Is ther
qinmin
2016/03/11 23:50:55
Done. As I mentioned in the TODO above, these css
| |
| 163 "text-transform: uppercase;" | |
| 164 "text-align: center;" | |
| 165 "line-height: 36px;" | |
| 166 "margin: auto;" | |
| 167 "top: 108px;" | |
| 168 "bottom: 0;" | |
| 169 "left: 0;" | |
| 170 "right: 0;"); | |
| 171 body->appendChild(anchor.release()); | |
| 172 } | |
| 101 body->appendChild(media.release()); | 173 body->appendChild(media.release()); |
| 102 | 174 |
| 103 rootElement->appendChild(head.release()); | 175 rootElement->appendChild(head.release()); |
| 104 rootElement->appendChild(body.release()); | 176 rootElement->appendChild(body.release()); |
| 105 | 177 |
| 106 m_didBuildDocumentStructure = true; | 178 m_didBuildDocumentStructure = true; |
| 107 } | 179 } |
| 108 | 180 |
| 109 void MediaDocumentParser::appendBytes(const char*, size_t) | 181 void MediaDocumentParser::appendBytes(const char*, size_t) |
| 110 { | 182 { |
| 111 if (m_didBuildDocumentStructure) | 183 if (m_didBuildDocumentStructure) |
| 112 return; | 184 return; |
| 113 | 185 |
| 114 LocalFrame* frame = document()->frame(); | 186 LocalFrame* frame = document()->frame(); |
| 115 if (!frame->loader().client()->allowMedia(document()->url())) | 187 if (!frame->loader().client()->allowMedia(document()->url())) |
| 116 return; | 188 return; |
| 117 | 189 |
| 118 createDocumentStructure(); | 190 createDocumentStructure(); |
| 119 finish(); | 191 finish(); |
| 120 } | 192 } |
| 121 | 193 |
| 194 bool MediaEventListener::operator==(const EventListener& listener) const | |
| 195 { | |
| 196 if (const MediaEventListener* mediaEventListener = MediaEventListener::cast( &listener)) | |
| 197 return m_doc == mediaEventListener->m_doc; | |
| 198 return false; | |
| 199 } | |
| 200 | |
| 122 MediaDocument::MediaDocument(const DocumentInit& initializer) | 201 MediaDocument::MediaDocument(const DocumentInit& initializer) |
| 123 : HTMLDocument(initializer, MediaDocumentClass) | 202 : HTMLDocument(initializer, MediaDocumentClass) |
| 124 { | 203 { |
| 125 setCompatibilityMode(QuirksMode); | 204 setCompatibilityMode(QuirksMode); |
| 126 lockCompatibilityMode(); | 205 lockCompatibilityMode(); |
| 127 } | 206 } |
| 128 | 207 |
| 129 PassRefPtrWillBeRawPtr<DocumentParser> MediaDocument::createParser() | 208 PassRefPtrWillBeRawPtr<DocumentParser> MediaDocument::createParser() |
| 130 { | 209 { |
| 131 return MediaDocumentParser::create(this); | 210 return MediaDocumentParser::create(this); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 144 | 223 |
| 145 KeyboardEvent* keyboardEvent = toKeyboardEvent(event); | 224 KeyboardEvent* keyboardEvent = toKeyboardEvent(event); |
| 146 if (keyboardEvent->keyIdentifier() == "U+0020" || keyboardEvent->keyCode () == VKEY_MEDIA_PLAY_PAUSE) { | 225 if (keyboardEvent->keyIdentifier() == "U+0020" || keyboardEvent->keyCode () == VKEY_MEDIA_PLAY_PAUSE) { |
| 147 // space or media key (play/pause) | 226 // space or media key (play/pause) |
| 148 video->togglePlayState(); | 227 video->togglePlayState(); |
| 149 event->setDefaultHandled(); | 228 event->setDefaultHandled(); |
| 150 } | 229 } |
| 151 } | 230 } |
| 152 } | 231 } |
| 153 | 232 |
| 233 void MediaDocument::updateLayout() | |
|
esprehn
2016/03/11 00:35:33
updateLayout is a real method you're shadowing, yo
qinmin
2016/03/11 23:50:55
removed
| |
| 234 { | |
| 235 HTMLAnchorElement* anchorElement = Traversal<HTMLAnchorElement>::firstWithin (*this); | |
| 236 HTMLMediaElement* mediaElement = Traversal<HTMLMediaElement>::firstWithin(*t his); | |
| 237 | |
| 238 int top = mediaElement->offsetTop() + mediaElement->offsetHeight() + 36; | |
|
esprehn
2016/03/11 00:35:33
this doesn't seem right, what is 36? This seems re
qinmin
2016/03/11 23:50:55
This should actually be 32. It is to move the butt
| |
| 239 anchorElement->setInlineStyleProperty(CSSPropertyTop, top, CSSPrimitiveValue ::UnitType::Pixels); | |
| 240 anchorElement->setInlineStyleProperty(CSSPropertyMarginTop, 0, CSSPrimitiveV alue::UnitType::Pixels); | |
|
esprehn
2016/03/11 00:35:32
huh? why always set to 0?
qinmin
2016/03/11 23:50:55
This is margin top. Since both the video and ancho
| |
| 241 } | |
| 242 | |
| 154 } // namespace blink | 243 } // namespace blink |
| OLD | NEW |