Index: third_party/WebKit/Source/core/html/MediaDocument.cpp |
diff --git a/third_party/WebKit/Source/core/html/MediaDocument.cpp b/third_party/WebKit/Source/core/html/MediaDocument.cpp |
index 3435ebd037dbe23c5481dda4aebc720cc748087e..0374b881bf8206346f10b439f8f94c3af8f0c7f3 100644 |
--- a/third_party/WebKit/Source/core/html/MediaDocument.cpp |
+++ b/third_party/WebKit/Source/core/html/MediaDocument.cpp |
@@ -31,16 +31,20 @@ |
#include "core/dom/RawDataDocumentParser.h" |
#include "core/events/KeyboardEvent.h" |
#include "core/frame/LocalFrame.h" |
+#include "core/html/HTMLAnchorElement.h" |
#include "core/html/HTMLBodyElement.h" |
+#include "core/html/HTMLDivElement.h" |
#include "core/html/HTMLHeadElement.h" |
#include "core/html/HTMLHtmlElement.h" |
#include "core/html/HTMLMetaElement.h" |
#include "core/html/HTMLSourceElement.h" |
+#include "core/html/HTMLStyleElement.h" |
#include "core/html/HTMLVideoElement.h" |
#include "core/loader/DocumentLoader.h" |
#include "core/loader/FrameLoader.h" |
#include "core/loader/FrameLoaderClient.h" |
#include "platform/KeyboardCodes.h" |
+#include "platform/text/PlatformLocale.h" |
namespace blink { |
@@ -100,8 +104,65 @@ void MediaDocumentParser::createDocumentStructure() |
media->appendChild(source.release()); |
RefPtrWillBeRawPtr<HTMLBodyElement> body = HTMLBodyElement::create(*document()); |
- body->appendChild(media.release()); |
+ RefPtrWillBeRawPtr<HTMLDivElement> div = HTMLDivElement::create(*document()); |
+ div->setAttribute(idAttr, "container"); |
+ |
+ // Style sheets for media controls are lazily loaded until a media element is encountered. |
+ // As a result, elements encountered before the media element will not get the right |
+ // style at first if we put the styles in mediacontrols.css. To solve this issue, set the |
+ // styles inline so that they will be applied when the page loads. |
+ RefPtrWillBeRawPtr<HTMLStyleElement> style = HTMLStyleElement::create(*document(), false); |
+ 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.
|
+ // See w3c example on how to centering an element: https://www.w3.org/Style/Examples/007/center.en.html |
+ styleContent.append( |
+ "body {" |
+ "margin: 0;" |
+ "}" |
+ "#container {" |
+ "display: flex;" |
+ "flex-direction: column;" |
+ "justify-content: center;" |
+ "align-items: center;" |
+ "min-height: min-content;" |
+ "height: 100%;" |
+ "}\n"); |
+ |
+ div->appendChild(media.release()); |
+ |
+ if (RuntimeEnabledFeatures::mediaDocumentDownloadButtonEnabled()) { |
+ RefPtrWillBeRawPtr<HTMLAnchorElement> anchor = HTMLAnchorElement::create(*document()); |
+ anchor->setAttribute(downloadAttr, ""); |
+ anchor->setURL(document()->url()); |
+ anchor->setTextContent(document()->getCachedLocale(document()->contentLanguage()).queryString(WebLocalizedString::DownloadButtonLabel).upper()); |
+ anchor->setAttribute(idAttr, "download"); |
+ // Using CSS style according to Android material design. |
+ styleContent.append( |
+ "#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
|
+ "display: inline-block;" |
+ "margin-top: 32px;" |
+ "padding: 0 16px 0 16px;" |
+ "height: 36px;" |
+ "background: #4285F4;" |
+ "font-family: Roboto;" |
+ "font-size: 14px;" |
+ "border-radius: 5px;" |
+ "color: white;" |
+ "font-weight: bold;" |
+ "text-decoration: none;" |
+ "line-height: 36px;" |
+ "}\n"); |
+ RefPtrWillBeRawPtr<HTMLDivElement> buttonContainer = HTMLDivElement::create(*document()); |
+ buttonContainer->setAttribute(idAttr, "button-container"); |
+ 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.
|
+ buttonContainer->appendChild(anchor.release()); |
+ div->appendChild(buttonContainer.release()); |
+ } |
+ |
+ body->appendChild(div.release()); |
+ |
+ style->setTextContent(styleContent.toString()); |
+ head->appendChild(style.release()); |
rootElement->appendChild(head.release()); |
rootElement->appendChild(body.release()); |