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 13 matching lines...) Expand all Loading... | |
| 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/KeyboardEvent.h" | 32 #include "core/events/KeyboardEvent.h" |
| 33 #include "core/frame/LocalFrame.h" | 33 #include "core/frame/LocalFrame.h" |
| 34 #include "core/html/HTMLAnchorElement.h" | |
| 34 #include "core/html/HTMLBodyElement.h" | 35 #include "core/html/HTMLBodyElement.h" |
| 36 #include "core/html/HTMLDivElement.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 { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 91 | 94 |
| 92 RefPtrWillBeRawPtr<HTMLSourceElement> source = HTMLSourceElement::create(*do cument()); | 95 RefPtrWillBeRawPtr<HTMLSourceElement> source = HTMLSourceElement::create(*do cument()); |
| 93 source->setSrc(document()->url()); | 96 source->setSrc(document()->url()); |
| 94 | 97 |
| 95 if (DocumentLoader* loader = document()->loader()) | 98 if (DocumentLoader* loader = document()->loader()) |
| 96 source->setType(loader->responseMIMEType()); | 99 source->setType(loader->responseMIMEType()); |
| 97 | 100 |
| 98 media->appendChild(source.release()); | 101 media->appendChild(source.release()); |
| 99 | 102 |
| 100 RefPtrWillBeRawPtr<HTMLBodyElement> body = HTMLBodyElement::create(*document ()); | 103 RefPtrWillBeRawPtr<HTMLBodyElement> body = HTMLBodyElement::create(*document ()); |
| 101 body->appendChild(media.release()); | |
| 102 | 104 |
| 105 // Style sheets for media controls are lazily loaded until a media element i s encountered. | |
| 106 // As a result, elements encountered before the media element will not get t he right | |
| 107 // style at first if we put the styles in mediacontrols.css. To solve this i ssue, set the | |
| 108 // styles inline so that they will be applied when the page loads. | |
| 109 RefPtrWillBeRawPtr<HTMLDivElement> div = HTMLDivElement::create(*document()) ; | |
| 110 div->setAttribute( | |
| 111 styleAttr, | |
| 112 "max-height: 100%;" | |
| 113 "max-width: 100%;" | |
| 114 "position: absolute;" | |
| 115 "top: 50%;" | |
| 116 "left: 50%;" | |
| 117 "margin-right: -50%;" | |
| 118 "transform: translate(-50%, -50%);"); | |
|
esprehn
2016/03/18 05:19:39
Can you explain what you're doing here? magin-righ
qinmin
2016/03/18 06:52:40
The technique for centering the element with the m
qinmin
2016/03/18 19:42:03
Added a comment here to include the w3c example pa
| |
| 119 | |
| 120 if (RuntimeEnabledFeatures::mediaDocumentDownloadButtonEnabled()) { | |
| 121 // Padding is used to compensate for the height of the download button s o that the media element can still be centered. | |
| 122 RefPtrWillBeRawPtr<HTMLDivElement> padding = HTMLDivElement::create(*doc ument()); | |
| 123 padding->setAttribute(heightAttr, "68px;"); | |
| 124 div->appendChild(padding.release()); | |
| 125 } | |
| 126 | |
| 127 div->appendChild(media.release()); | |
| 128 | |
| 129 if (RuntimeEnabledFeatures::mediaDocumentDownloadButtonEnabled()) { | |
| 130 RefPtrWillBeRawPtr<HTMLAnchorElement> anchor = HTMLAnchorElement::create (*document()); | |
| 131 anchor->setAttribute(downloadAttr, ""); | |
| 132 anchor->setURL(document()->url()); | |
| 133 anchor->setTextContent(document()->getCachedLocale(document()->contentLa nguage()).queryString(WebLocalizedString::DownloadButtonLabel)); | |
| 134 // Using CSS style according to Android material design. | |
| 135 anchor->setAttribute( | |
| 136 styleAttr, | |
| 137 "display: block;" | |
| 138 "width: 120px;" | |
| 139 "height: 36px;" | |
| 140 "background: #4285F4;" | |
| 141 "font-family: Roboto;" | |
| 142 "font-size: 14px;" | |
| 143 "border-radius: 5px;" | |
| 144 "color: white;" | |
| 145 "font-weight: bold;" | |
| 146 "text-decoration: none;" | |
| 147 "text-transform: uppercase;" | |
| 148 "text-align: center;" | |
| 149 "line-height: 36px;" | |
| 150 "margin: 32px auto 0 auto;"); | |
|
esprehn
2016/03/18 05:19:39
can we insert a <style> element and give these two
qinmin
2016/03/18 19:42:03
Done.
| |
| 151 div->appendChild(anchor.release()); | |
| 152 } | |
| 153 | |
| 154 body->appendChild(div.release()); | |
| 103 rootElement->appendChild(head.release()); | 155 rootElement->appendChild(head.release()); |
| 104 rootElement->appendChild(body.release()); | 156 rootElement->appendChild(body.release()); |
| 105 | 157 |
| 106 m_didBuildDocumentStructure = true; | 158 m_didBuildDocumentStructure = true; |
| 107 } | 159 } |
| 108 | 160 |
| 109 void MediaDocumentParser::appendBytes(const char*, size_t) | 161 void MediaDocumentParser::appendBytes(const char*, size_t) |
| 110 { | 162 { |
| 111 if (m_didBuildDocumentStructure) | 163 if (m_didBuildDocumentStructure) |
| 112 return; | 164 return; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 145 KeyboardEvent* keyboardEvent = toKeyboardEvent(event); | 197 KeyboardEvent* keyboardEvent = toKeyboardEvent(event); |
| 146 if (keyboardEvent->keyIdentifier() == "U+0020" || keyboardEvent->keyCode () == VKEY_MEDIA_PLAY_PAUSE) { | 198 if (keyboardEvent->keyIdentifier() == "U+0020" || keyboardEvent->keyCode () == VKEY_MEDIA_PLAY_PAUSE) { |
| 147 // space or media key (play/pause) | 199 // space or media key (play/pause) |
| 148 video->togglePlayState(); | 200 video->togglePlayState(); |
| 149 event->setDefaultHandled(); | 201 event->setDefaultHandled(); |
| 150 } | 202 } |
| 151 } | 203 } |
| 152 } | 204 } |
| 153 | 205 |
| 154 } // namespace blink | 206 } // namespace blink |
| OLD | NEW |