Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(232)

Unified Diff: third_party/WebKit/Source/core/html/ImageDocument.cpp

Issue 2376163002: [Blink] Display images in the center of the screen (Closed)
Patch Set: Yet another attempt at rebaselining Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/html/ImageDocument.cpp
diff --git a/third_party/WebKit/Source/core/html/ImageDocument.cpp b/third_party/WebKit/Source/core/html/ImageDocument.cpp
index fbd45ecc7f12271702235af0f334d11ac0a1cc19..5faa8988c819a6d0b73e2a1798d5930d1f1234d5 100644
--- a/third_party/WebKit/Source/core/html/ImageDocument.cpp
+++ b/third_party/WebKit/Source/core/html/ImageDocument.cpp
@@ -38,6 +38,8 @@
#include "core/frame/UseCounter.h"
#include "core/frame/VisualViewport.h"
#include "core/html/HTMLBodyElement.h"
+#include "core/html/HTMLContentElement.h"
+#include "core/html/HTMLDivElement.h"
#include "core/html/HTMLHeadElement.h"
#include "core/html/HTMLHtmlElement.h"
#include "core/html/HTMLImageElement.h"
@@ -212,12 +214,44 @@ void ImageDocument::createDocumentStructure() {
head->appendChild(meta);
HTMLBodyElement* body = HTMLBodyElement::create(*this);
- body->setAttribute(styleAttr, "margin: 0px;");
+
+ if (shouldShrinkToFit()) {
+ // Display the image prominently in the middle of the viewport.
+ body->setAttribute(styleAttr,
+ "margin: 0px;"
+ "background: black;");
+
+ // See w3c example on how to centering an element:
+ // https://www.w3.org/Style/Examples/007/center.en.html
+ HTMLDivElement* div = HTMLDivElement::create(Node::document());
+ div->setAttribute(styleAttr,
+ "display: flex;"
+ "flex-direction: column;"
+ "justify-content: center;"
+ "align-items: center;"
+ "min-height: min-content;"
+ "min-width: min-content;"
+ "height: 100%;"
+ "width: 100%;");
+ HTMLContentElement* content = HTMLContentElement::create(Node::document());
+ div->appendChild(content);
+
+ ShadowRoot& shadowRoot = body->ensureUserAgentShadowRoot();
+ shadowRoot.appendChild(div);
+ } else {
+ body->setAttribute(styleAttr, "margin: 0px;");
+ }
willInsertBody();
m_imageElement = HTMLImageElement::create(*this);
- m_imageElement->setAttribute(styleAttr, "-webkit-user-select: none");
+ if (shouldShrinkToFit() && m_shrinkToFitMode == Viewport) {
+ m_imageElement->setAttribute(styleAttr,
+ "-webkit-user-select: none;"
+ "max-width: 100%;");
+ } else {
+ m_imageElement->setAttribute(styleAttr, "-webkit-user-select: none;");
+ }
m_imageElement->setLoadingImageDocument();
m_imageElement->setSrc(url().getString());
body->appendChild(m_imageElement.get());
@@ -363,22 +397,9 @@ bool ImageDocument::imageFitsInWindow() const {
void ImageDocument::windowSizeChanged() {
if (!m_imageElement || !m_imageSizeIsKnown ||
- m_imageElement->document() != this)
+ m_imageElement->document() != this || m_shrinkToFitMode == Viewport)
return;
- if (m_shrinkToFitMode == Viewport) {
- // For huge images, minimum-scale=0.1 is still too big on small screens.
- // Set max-width so that the image will shrink to fit the width of the
- // screen when the scale is minimum. Don't shrink height to fit because we
- // use width=device-width in viewport meta tag, and expect a full-width
- // reading mode for normal-width-huge-height images.
esprehn 2016/10/08 03:09:19 Why don't we need this now?
gone 2016/10/10 22:01:01 Turns out we do... I tested a 16k x 1k image this
- int viewportWidth = frame()->host()->visualViewport().size().width();
- m_imageElement->setInlineStyleProperty(CSSPropertyMaxWidth,
- viewportWidth * 10,
- CSSPrimitiveValue::UnitType::Pixels);
- return;
- }
-
bool fitsInWindow = imageFitsInWindow();
// If the image has been explicitly zoomed in, restore the cursor if the image

Powered by Google App Engine
This is Rietveld 408576698