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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
91 | 95 |
92 RefPtrWillBeRawPtr<HTMLSourceElement> source = HTMLSourceElement::create(*do cument()); | 96 RefPtrWillBeRawPtr<HTMLSourceElement> source = HTMLSourceElement::create(*do cument()); |
93 source->setSrc(document()->url()); | 97 source->setSrc(document()->url()); |
94 | 98 |
95 if (DocumentLoader* loader = document()->loader()) | 99 if (DocumentLoader* loader = document()->loader()) |
96 source->setType(loader->responseMIMEType()); | 100 source->setType(loader->responseMIMEType()); |
97 | 101 |
98 media->appendChild(source.release()); | 102 media->appendChild(source.release()); |
99 | 103 |
100 RefPtrWillBeRawPtr<HTMLBodyElement> body = HTMLBodyElement::create(*document ()); | 104 RefPtrWillBeRawPtr<HTMLBodyElement> body = HTMLBodyElement::create(*document ()); |
101 body->appendChild(media.release()); | |
102 | 105 |
106 RefPtrWillBeRawPtr<HTMLDivElement> div = HTMLDivElement::create(*document()) ; | |
107 div->setAttribute(idAttr, "container"); | |
108 | |
109 // Style sheets for media controls are lazily loaded until a media element i s encountered. | |
110 // As a result, elements encountered before the media element will not get t he right | |
111 // style at first if we put the styles in mediacontrols.css. To solve this i ssue, set the | |
112 // styles inline so that they will be applied when the page loads. | |
113 RefPtrWillBeRawPtr<HTMLStyleElement> style = HTMLStyleElement::create(*docum ent(), false); | |
114 StringBuilder styleContent; | |
115 // See w3c example on how to centering an element: https://www.w3.org/Style/ Examples/007/center.en.html | |
116 styleContent.append( | |
117 "#container {" | |
118 "max-height: 100%;" | |
119 "max-width: 100%;" | |
120 "position: absolute;" | |
121 "top: 50%;" | |
122 "left: 50%;" | |
123 "margin-right: -50%;" | |
124 "transform: translate(-50%, -50%);" | |
125 "}\n"); | |
126 | |
127 if (RuntimeEnabledFeatures::mediaDocumentDownloadButtonEnabled()) { | |
128 // Padding is used to compensate for the height of the download button s o that the media element can still be centered. | |
129 RefPtrWillBeRawPtr<HTMLDivElement> padding = HTMLDivElement::create(*doc ument()); | |
130 padding->setAttribute(heightAttr, "68px;"); | |
esprehn
2016/03/22 18:11:21
please don't add spacer divs, I think you want to
qinmin
2016/03/24 18:51:19
Switched to use ojan's flex trick.
| |
131 div->appendChild(padding.release()); | |
132 } | |
133 | |
134 div->appendChild(media.release()); | |
135 | |
136 if (RuntimeEnabledFeatures::mediaDocumentDownloadButtonEnabled()) { | |
137 RefPtrWillBeRawPtr<HTMLAnchorElement> anchor = HTMLAnchorElement::create (*document()); | |
138 anchor->setAttribute(downloadAttr, ""); | |
139 anchor->setURL(document()->url()); | |
140 anchor->setTextContent(document()->getCachedLocale(document()->contentLa nguage()).queryString(WebLocalizedString::DownloadButtonLabel)); | |
141 anchor->setAttribute(idAttr, "download"); | |
142 // Using CSS style according to Android material design. | |
143 styleContent.append( | |
144 "#download {" | |
145 "display: block;" | |
ojan
2016/03/22 20:13:39
Use an inline-block instead. Then you won't need t
qinmin
2016/03/24 18:51:19
inline-block will append the anchor element to the
| |
146 "width: 120px;" | |
ojan
2016/03/22 20:13:39
I don't think you want to set an explicit width an
qinmin
2016/03/24 18:51:19
Done.
| |
147 "height: 36px;" | |
148 "background: #4285F4;" | |
149 "font-family: Roboto;" | |
150 "font-size: 14px;" | |
151 "border-radius: 5px;" | |
152 "color: white;" | |
153 "font-weight: bold;" | |
154 "text-decoration: none;" | |
155 "text-transform: uppercase;" | |
ojan
2016/03/22 20:13:39
Don't use text-transform to uppercase it. It's muc
qinmin
2016/03/24 18:51:19
Done.
| |
156 "text-align: center;" | |
157 "line-height: 36px;" | |
ojan
2016/03/22 20:13:39
You shouldn't need to set line-height.
qinmin
2016/03/24 18:51:19
Android material design uses 36px for button heigh
| |
158 "margin: 32px auto 0 auto;" | |
159 "}"); | |
160 div->appendChild(anchor.release()); | |
161 } | |
162 | |
163 body->appendChild(div.release()); | |
164 | |
165 style->setTextContent(styleContent.toString()); | |
166 head->appendChild(style.release()); | |
103 rootElement->appendChild(head.release()); | 167 rootElement->appendChild(head.release()); |
104 rootElement->appendChild(body.release()); | 168 rootElement->appendChild(body.release()); |
105 | 169 |
106 m_didBuildDocumentStructure = true; | 170 m_didBuildDocumentStructure = true; |
107 } | 171 } |
108 | 172 |
109 void MediaDocumentParser::appendBytes(const char*, size_t) | 173 void MediaDocumentParser::appendBytes(const char*, size_t) |
110 { | 174 { |
111 if (m_didBuildDocumentStructure) | 175 if (m_didBuildDocumentStructure) |
112 return; | 176 return; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
145 KeyboardEvent* keyboardEvent = toKeyboardEvent(event); | 209 KeyboardEvent* keyboardEvent = toKeyboardEvent(event); |
146 if (keyboardEvent->keyIdentifier() == "U+0020" || keyboardEvent->keyCode () == VKEY_MEDIA_PLAY_PAUSE) { | 210 if (keyboardEvent->keyIdentifier() == "U+0020" || keyboardEvent->keyCode () == VKEY_MEDIA_PLAY_PAUSE) { |
147 // space or media key (play/pause) | 211 // space or media key (play/pause) |
148 video->togglePlayState(); | 212 video->togglePlayState(); |
149 event->setDefaultHandled(); | 213 event->setDefaultHandled(); |
150 } | 214 } |
151 } | 215 } |
152 } | 216 } |
153 | 217 |
154 } // namespace blink | 218 } // namespace blink |
OLD | NEW |