Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006, 2007, 2008, 2010 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007, 2008, 2010 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 20 matching lines...) Expand all Loading... | |
| 31 #include "core/events/MouseEvent.h" | 31 #include "core/events/MouseEvent.h" |
| 32 #include "core/fetch/ImageResource.h" | 32 #include "core/fetch/ImageResource.h" |
| 33 #include "core/frame/FrameHost.h" | 33 #include "core/frame/FrameHost.h" |
| 34 #include "core/frame/FrameView.h" | 34 #include "core/frame/FrameView.h" |
| 35 #include "core/frame/LocalDOMWindow.h" | 35 #include "core/frame/LocalDOMWindow.h" |
| 36 #include "core/frame/LocalFrame.h" | 36 #include "core/frame/LocalFrame.h" |
| 37 #include "core/frame/Settings.h" | 37 #include "core/frame/Settings.h" |
| 38 #include "core/frame/UseCounter.h" | 38 #include "core/frame/UseCounter.h" |
| 39 #include "core/frame/VisualViewport.h" | 39 #include "core/frame/VisualViewport.h" |
| 40 #include "core/html/HTMLBodyElement.h" | 40 #include "core/html/HTMLBodyElement.h" |
| 41 #include "core/html/HTMLContentElement.h" | |
| 42 #include "core/html/HTMLDivElement.h" | |
| 41 #include "core/html/HTMLHeadElement.h" | 43 #include "core/html/HTMLHeadElement.h" |
| 42 #include "core/html/HTMLHtmlElement.h" | 44 #include "core/html/HTMLHtmlElement.h" |
| 43 #include "core/html/HTMLImageElement.h" | 45 #include "core/html/HTMLImageElement.h" |
| 44 #include "core/html/HTMLMetaElement.h" | 46 #include "core/html/HTMLMetaElement.h" |
| 45 #include "core/layout/LayoutObject.h" | 47 #include "core/layout/LayoutObject.h" |
| 46 #include "core/loader/DocumentLoader.h" | 48 #include "core/loader/DocumentLoader.h" |
| 47 #include "core/loader/FrameLoader.h" | 49 #include "core/loader/FrameLoader.h" |
| 48 #include "core/loader/FrameLoaderClient.h" | 50 #include "core/loader/FrameLoaderClient.h" |
| 49 #include "platform/HostWindow.h" | 51 #include "platform/HostWindow.h" |
| 50 #include "wtf/text/StringBuilder.h" | 52 #include "wtf/text/StringBuilder.h" |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 205 if (isStopped()) | 207 if (isStopped()) |
| 206 return; // runScriptsAtDocumentElementAvailable can detach the frame. | 208 return; // runScriptsAtDocumentElementAvailable can detach the frame. |
| 207 | 209 |
| 208 HTMLHeadElement* head = HTMLHeadElement::create(*this); | 210 HTMLHeadElement* head = HTMLHeadElement::create(*this); |
| 209 HTMLMetaElement* meta = HTMLMetaElement::create(*this); | 211 HTMLMetaElement* meta = HTMLMetaElement::create(*this); |
| 210 meta->setAttribute(nameAttr, "viewport"); | 212 meta->setAttribute(nameAttr, "viewport"); |
| 211 meta->setAttribute(contentAttr, "width=device-width, minimum-scale=0.1"); | 213 meta->setAttribute(contentAttr, "width=device-width, minimum-scale=0.1"); |
| 212 head->appendChild(meta); | 214 head->appendChild(meta); |
| 213 | 215 |
| 214 HTMLBodyElement* body = HTMLBodyElement::create(*this); | 216 HTMLBodyElement* body = HTMLBodyElement::create(*this); |
| 215 body->setAttribute(styleAttr, "margin: 0px;"); | 217 |
| 218 if (shouldShrinkToFit()) { | |
| 219 // Display the image prominently in the middle of the viewport. | |
| 220 body->setAttribute(styleAttr, | |
| 221 "margin: 0px;" | |
| 222 "background: black;"); | |
| 223 | |
| 224 // See w3c example on how to centering an element: | |
| 225 // https://www.w3.org/Style/Examples/007/center.en.html | |
| 226 HTMLDivElement* div = HTMLDivElement::create(Node::document()); | |
| 227 div->setAttribute(styleAttr, | |
| 228 "display: flex;" | |
| 229 "flex-direction: column;" | |
| 230 "justify-content: center;" | |
| 231 "align-items: center;" | |
| 232 "min-height: min-content;" | |
| 233 "min-width: min-content;" | |
| 234 "height: 100%;" | |
| 235 "width: 100%;"); | |
| 236 HTMLContentElement* content = HTMLContentElement::create(Node::document()); | |
| 237 div->appendChild(content); | |
| 238 | |
| 239 ShadowRoot& shadowRoot = body->ensureUserAgentShadowRoot(); | |
| 240 shadowRoot.appendChild(div); | |
| 241 } else { | |
| 242 body->setAttribute(styleAttr, "margin: 0px;"); | |
| 243 } | |
| 216 | 244 |
| 217 willInsertBody(); | 245 willInsertBody(); |
| 218 | 246 |
| 219 m_imageElement = HTMLImageElement::create(*this); | 247 m_imageElement = HTMLImageElement::create(*this); |
| 220 m_imageElement->setAttribute(styleAttr, "-webkit-user-select: none"); | 248 if (shouldShrinkToFit() && m_shrinkToFitMode == Viewport) { |
| 249 m_imageElement->setAttribute(styleAttr, | |
| 250 "-webkit-user-select: none;" | |
| 251 "max-width: 100%;"); | |
| 252 } else { | |
| 253 m_imageElement->setAttribute(styleAttr, "-webkit-user-select: none;"); | |
| 254 } | |
| 221 m_imageElement->setLoadingImageDocument(); | 255 m_imageElement->setLoadingImageDocument(); |
| 222 m_imageElement->setSrc(url().getString()); | 256 m_imageElement->setSrc(url().getString()); |
| 223 body->appendChild(m_imageElement.get()); | 257 body->appendChild(m_imageElement.get()); |
| 224 if (loader() && m_imageElement->cachedImage()) | 258 if (loader() && m_imageElement->cachedImage()) |
| 225 m_imageElement->cachedImage()->responseReceived(loader()->response(), | 259 m_imageElement->cachedImage()->responseReceived(loader()->response(), |
| 226 nullptr); | 260 nullptr); |
| 227 | 261 |
| 228 if (shouldShrinkToFit()) { | 262 if (shouldShrinkToFit()) { |
| 229 // Add event listeners | 263 // Add event listeners |
| 230 EventListener* listener = ImageEventListener::create(this); | 264 EventListener* listener = ImageEventListener::create(this); |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 356 m_didShrinkImage = false; | 390 m_didShrinkImage = false; |
| 357 } | 391 } |
| 358 | 392 |
| 359 bool ImageDocument::imageFitsInWindow() const { | 393 bool ImageDocument::imageFitsInWindow() const { |
| 360 DCHECK_EQ(m_shrinkToFitMode, Desktop); | 394 DCHECK_EQ(m_shrinkToFitMode, Desktop); |
| 361 return this->scale() >= 1; | 395 return this->scale() >= 1; |
| 362 } | 396 } |
| 363 | 397 |
| 364 void ImageDocument::windowSizeChanged() { | 398 void ImageDocument::windowSizeChanged() { |
| 365 if (!m_imageElement || !m_imageSizeIsKnown || | 399 if (!m_imageElement || !m_imageSizeIsKnown || |
| 366 m_imageElement->document() != this) | 400 m_imageElement->document() != this || m_shrinkToFitMode == Viewport) |
| 367 return; | 401 return; |
| 368 | 402 |
| 369 if (m_shrinkToFitMode == Viewport) { | |
| 370 // For huge images, minimum-scale=0.1 is still too big on small screens. | |
| 371 // Set max-width so that the image will shrink to fit the width of the | |
| 372 // screen when the scale is minimum. Don't shrink height to fit because we | |
| 373 // use width=device-width in viewport meta tag, and expect a full-width | |
| 374 // 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
| |
| 375 int viewportWidth = frame()->host()->visualViewport().size().width(); | |
| 376 m_imageElement->setInlineStyleProperty(CSSPropertyMaxWidth, | |
| 377 viewportWidth * 10, | |
| 378 CSSPrimitiveValue::UnitType::Pixels); | |
| 379 return; | |
| 380 } | |
| 381 | |
| 382 bool fitsInWindow = imageFitsInWindow(); | 403 bool fitsInWindow = imageFitsInWindow(); |
| 383 | 404 |
| 384 // If the image has been explicitly zoomed in, restore the cursor if the image | 405 // If the image has been explicitly zoomed in, restore the cursor if the image |
| 385 // fits and set it to a zoom out cursor if the image doesn't fit | 406 // fits and set it to a zoom out cursor if the image doesn't fit |
| 386 if (!m_shouldShrinkImage) { | 407 if (!m_shouldShrinkImage) { |
| 387 if (fitsInWindow) | 408 if (fitsInWindow) |
| 388 m_imageElement->removeInlineStyleProperty(CSSPropertyCursor); | 409 m_imageElement->removeInlineStyleProperty(CSSPropertyCursor); |
| 389 else | 410 else |
| 390 m_imageElement->setInlineStyleProperty(CSSPropertyCursor, | 411 m_imageElement->setInlineStyleProperty(CSSPropertyCursor, |
| 391 CSSValueZoomOut); | 412 CSSValueZoomOut); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 441 } | 462 } |
| 442 | 463 |
| 443 bool ImageEventListener::operator==(const EventListener& listener) const { | 464 bool ImageEventListener::operator==(const EventListener& listener) const { |
| 444 if (const ImageEventListener* imageEventListener = | 465 if (const ImageEventListener* imageEventListener = |
| 445 ImageEventListener::cast(&listener)) | 466 ImageEventListener::cast(&listener)) |
| 446 return m_doc == imageEventListener->m_doc; | 467 return m_doc == imageEventListener->m_doc; |
| 447 return false; | 468 return false; |
| 448 } | 469 } |
| 449 | 470 |
| 450 } // namespace blink | 471 } // namespace blink |
| OLD | NEW |