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" |
| 41 #include "core/html/HTMLStyleElement.h" | |
| 39 #include "core/html/HTMLVideoElement.h" | 42 #include "core/html/HTMLVideoElement.h" |
| 40 #include "core/loader/DocumentLoader.h" | 43 #include "core/loader/DocumentLoader.h" |
| 41 #include "core/loader/FrameLoader.h" | 44 #include "core/loader/FrameLoader.h" |
| 42 #include "core/loader/FrameLoaderClient.h" | 45 #include "core/loader/FrameLoaderClient.h" |
| 43 #include "platform/KeyboardCodes.h" | 46 #include "platform/KeyboardCodes.h" |
| 47 #include "platform/text/PlatformLocale.h" | |
| 44 | 48 |
| 45 namespace blink { | 49 namespace blink { |
| 46 | 50 |
| 47 using namespace HTMLNames; | 51 using namespace HTMLNames; |
| 48 | 52 |
| 49 // FIXME: Share more code with PluginDocumentParser. | 53 // FIXME: Share more code with PluginDocumentParser. |
| 50 class MediaDocumentParser : public RawDataDocumentParser { | 54 class MediaDocumentParser : public RawDataDocumentParser { |
| 51 public: | 55 public: |
| 52 static PassRefPtrWillBeRawPtr<MediaDocumentParser> create(MediaDocument* doc ument) | 56 static PassRefPtrWillBeRawPtr<MediaDocumentParser> create(MediaDocument* doc ument) |
| 53 { | 57 { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 93 | 97 |
| 94 RefPtrWillBeRawPtr<HTMLSourceElement> source = HTMLSourceElement::create(*do cument()); | 98 RefPtrWillBeRawPtr<HTMLSourceElement> source = HTMLSourceElement::create(*do cument()); |
| 95 source->setSrc(document()->url()); | 99 source->setSrc(document()->url()); |
| 96 | 100 |
| 97 if (DocumentLoader* loader = document()->loader()) | 101 if (DocumentLoader* loader = document()->loader()) |
| 98 source->setType(loader->responseMIMEType()); | 102 source->setType(loader->responseMIMEType()); |
| 99 | 103 |
| 100 media->appendChild(source.release()); | 104 media->appendChild(source.release()); |
| 101 | 105 |
| 102 RefPtrWillBeRawPtr<HTMLBodyElement> body = HTMLBodyElement::create(*document ()); | 106 RefPtrWillBeRawPtr<HTMLBodyElement> body = HTMLBodyElement::create(*document ()); |
| 103 body->appendChild(media.release()); | |
| 104 | 107 |
| 108 RefPtrWillBeRawPtr<HTMLDivElement> div = HTMLDivElement::create(*document()) ; | |
| 109 div->setAttribute(idAttr, "container"); | |
| 110 | |
| 111 // Style sheets for media controls are lazily loaded until a media element i s encountered. | |
| 112 // As a result, elements encountered before the media element will not get t he right | |
| 113 // style at first if we put the styles in mediacontrols.css. To solve this i ssue, set the | |
| 114 // styles inline so that they will be applied when the page loads. | |
| 115 RefPtrWillBeRawPtr<HTMLStyleElement> style = HTMLStyleElement::create(*docum ent(), false); | |
| 116 StringBuilder styleContent; | |
|
esprehn
2016/03/29 05:10:31
On second thought lets do inline styles. I'd still
qinmin
2016/03/29 19:23:37
Done.
| |
| 117 // See w3c example on how to centering an element: https://www.w3.org/Style/ Examples/007/center.en.html | |
| 118 styleContent.append( | |
| 119 "body {" | |
| 120 "margin: 0;" | |
| 121 "}" | |
| 122 "#container {" | |
| 123 "display: flex;" | |
| 124 "flex-direction: column;" | |
| 125 "justify-content: center;" | |
| 126 "align-items: center;" | |
| 127 "min-height: min-content;" | |
| 128 "height: 100%;" | |
| 129 "}\n"); | |
| 130 | |
| 131 div->appendChild(media.release()); | |
| 132 | |
| 133 if (RuntimeEnabledFeatures::mediaDocumentDownloadButtonEnabled()) { | |
| 134 RefPtrWillBeRawPtr<HTMLAnchorElement> anchor = HTMLAnchorElement::create (*document()); | |
| 135 anchor->setAttribute(downloadAttr, ""); | |
| 136 anchor->setURL(document()->url()); | |
| 137 anchor->setTextContent(document()->getCachedLocale(document()->contentLa nguage()).queryString(WebLocalizedString::DownloadButtonLabel).upper()); | |
| 138 anchor->setAttribute(idAttr, "download"); | |
| 139 // Using CSS style according to Android material design. | |
| 140 styleContent.append( | |
| 141 "#download {" | |
|
esprehn
2016/03/29 05:10:31
no need to guard this, just put all your CSS in a
qinmin
2016/03/29 19:23:37
Done. use inline style
| |
| 142 "display: inline-block;" | |
| 143 "margin-top: 32px;" | |
| 144 "padding: 0 16px 0 16px;" | |
| 145 "height: 36px;" | |
| 146 "background: #4285F4;" | |
| 147 "font-family: Roboto;" | |
| 148 "font-size: 14px;" | |
| 149 "border-radius: 5px;" | |
| 150 "color: white;" | |
| 151 "font-weight: bold;" | |
| 152 "text-decoration: none;" | |
| 153 "line-height: 36px;" | |
| 154 "}\n"); | |
| 155 RefPtrWillBeRawPtr<HTMLDivElement> buttonContainer = HTMLDivElement::cre ate(*document()); | |
| 156 buttonContainer->setAttribute(idAttr, "button-container"); | |
| 157 styleContent.append("#button-container { position: absolute; text-align: center; left: 0; right: 0; }\n"); | |
|
esprehn
2016/03/29 05:10:31
I'd just make the styles inline styles if you're g
qinmin
2016/03/29 19:23:37
Done.
| |
| 158 buttonContainer->appendChild(anchor.release()); | |
| 159 div->appendChild(buttonContainer.release()); | |
| 160 } | |
| 161 | |
| 162 body->appendChild(div.release()); | |
| 163 | |
| 164 style->setTextContent(styleContent.toString()); | |
| 165 head->appendChild(style.release()); | |
| 105 rootElement->appendChild(head.release()); | 166 rootElement->appendChild(head.release()); |
| 106 rootElement->appendChild(body.release()); | 167 rootElement->appendChild(body.release()); |
| 107 | 168 |
| 108 m_didBuildDocumentStructure = true; | 169 m_didBuildDocumentStructure = true; |
| 109 } | 170 } |
| 110 | 171 |
| 111 void MediaDocumentParser::appendBytes(const char*, size_t) | 172 void MediaDocumentParser::appendBytes(const char*, size_t) |
| 112 { | 173 { |
| 113 if (m_didBuildDocumentStructure) | 174 if (m_didBuildDocumentStructure) |
| 114 return; | 175 return; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 147 KeyboardEvent* keyboardEvent = toKeyboardEvent(event); | 208 KeyboardEvent* keyboardEvent = toKeyboardEvent(event); |
| 148 if (keyboardEvent->keyIdentifier() == "U+0020" || keyboardEvent->keyCode () == VKEY_MEDIA_PLAY_PAUSE) { | 209 if (keyboardEvent->keyIdentifier() == "U+0020" || keyboardEvent->keyCode () == VKEY_MEDIA_PLAY_PAUSE) { |
| 149 // space or media key (play/pause) | 210 // space or media key (play/pause) |
| 150 video->togglePlayState(); | 211 video->togglePlayState(); |
| 151 event->setDefaultHandled(); | 212 event->setDefaultHandled(); |
| 152 } | 213 } |
| 153 } | 214 } |
| 154 } | 215 } |
| 155 | 216 |
| 156 } // namespace blink | 217 } // namespace blink |
| OLD | NEW |