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 525d869dbb2ff380d5110f98d9e9b3d3e17ac593..2b4e7c2158e13ed0d5c30b79ce896576a01d204b 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 { |
@@ -98,8 +102,68 @@ 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; |
+ // See w3c example on how to centering an element: https://www.w3.org/Style/Examples/007/center.en.html |
+ styleContent.append( |
+ "#container {" |
+ "max-height: 100%;" |
+ "max-width: 100%;" |
+ "position: absolute;" |
+ "top: 50%;" |
+ "left: 50%;" |
+ "margin-right: -50%;" |
+ "transform: translate(-50%, -50%);" |
+ "}\n"); |
+ |
+ if (RuntimeEnabledFeatures::mediaDocumentDownloadButtonEnabled()) { |
+ // Padding is used to compensate for the height of the download button so that the media element can still be centered. |
+ RefPtrWillBeRawPtr<HTMLDivElement> padding = HTMLDivElement::create(*document()); |
+ 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.
|
+ div->appendChild(padding.release()); |
+ } |
+ |
+ 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)); |
+ anchor->setAttribute(idAttr, "download"); |
+ // Using CSS style according to Android material design. |
+ styleContent.append( |
+ "#download {" |
+ "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
|
+ "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.
|
+ "height: 36px;" |
+ "background: #4285F4;" |
+ "font-family: Roboto;" |
+ "font-size: 14px;" |
+ "border-radius: 5px;" |
+ "color: white;" |
+ "font-weight: bold;" |
+ "text-decoration: none;" |
+ "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.
|
+ "text-align: center;" |
+ "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
|
+ "margin: 32px auto 0 auto;" |
+ "}"); |
+ div->appendChild(anchor.release()); |
+ } |
+ |
+ body->appendChild(div.release()); |
+ |
+ style->setTextContent(styleContent.toString()); |
+ head->appendChild(style.release()); |
rootElement->appendChild(head.release()); |
rootElement->appendChild(body.release()); |