| 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 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 int newCheckerSize = kBaseCheckerSize; | 387 int newCheckerSize = kBaseCheckerSize; |
| 388 MouseCursorMode newCursorMode = Default; | 388 MouseCursorMode newCursorMode = Default; |
| 389 | 389 |
| 390 if (m_shrinkToFitMode == Viewport) { | 390 if (m_shrinkToFitMode == Viewport) { |
| 391 double scale; | 391 double scale; |
| 392 | 392 |
| 393 if (hasFinishedParsing()) { | 393 if (hasFinishedParsing()) { |
| 394 // To ensure the checker pattern is visible for large images, the | 394 // To ensure the checker pattern is visible for large images, the |
| 395 // checker size is dynamically adjusted to account for how much the | 395 // checker size is dynamically adjusted to account for how much the |
| 396 // page is currently being scaled. | 396 // page is currently being scaled. |
| 397 scale = frame()->host()->visualViewport().scale(); | 397 scale = frame()->page()->visualViewport().scale(); |
| 398 } else { | 398 } else { |
| 399 // The checker pattern is initialized based on how large the image is | 399 // The checker pattern is initialized based on how large the image is |
| 400 // relative to the viewport. | 400 // relative to the viewport. |
| 401 int viewportWidth = frame()->host()->visualViewport().size().width(); | 401 int viewportWidth = frame()->page()->visualViewport().size().width(); |
| 402 scale = viewportWidth / static_cast<double>(calculateDivWidth()); | 402 scale = viewportWidth / static_cast<double>(calculateDivWidth()); |
| 403 } | 403 } |
| 404 | 404 |
| 405 newCheckerSize = std::round(std::max(1.0, newCheckerSize / scale)); | 405 newCheckerSize = std::round(std::max(1.0, newCheckerSize / scale)); |
| 406 } else { | 406 } else { |
| 407 // In desktop mode, the user can click on the image to zoom in or out. | 407 // In desktop mode, the user can click on the image to zoom in or out. |
| 408 DCHECK_EQ(m_shrinkToFitMode, Desktop); | 408 DCHECK_EQ(m_shrinkToFitMode, Desktop); |
| 409 if (imageFitsInWindow()) { | 409 if (imageFitsInWindow()) { |
| 410 newCursorMode = Default; | 410 newCursorMode = Default; |
| 411 } else { | 411 } else { |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 504 | 504 |
| 505 int ImageDocument::calculateDivWidth() { | 505 int ImageDocument::calculateDivWidth() { |
| 506 // Zooming in and out of an image being displayed within a viewport is done | 506 // Zooming in and out of an image being displayed within a viewport is done |
| 507 // by changing the page scale factor of the page instead of changing the | 507 // by changing the page scale factor of the page instead of changing the |
| 508 // size of the image. The size of the image is set so that: | 508 // size of the image. The size of the image is set so that: |
| 509 // * Images wider than the viewport take the full width of the screen. | 509 // * Images wider than the viewport take the full width of the screen. |
| 510 // * Images taller than the viewport are initially aligned with the top of | 510 // * Images taller than the viewport are initially aligned with the top of |
| 511 // of the frame. | 511 // of the frame. |
| 512 // * Images smaller in either dimension are centered along that axis. | 512 // * Images smaller in either dimension are centered along that axis. |
| 513 LayoutSize imageSize = cachedImageSize(m_imageElement); | 513 LayoutSize imageSize = cachedImageSize(m_imageElement); |
| 514 int viewportWidth = frame()->host()->visualViewport().size().width(); | 514 int viewportWidth = frame()->page()->visualViewport().size().width(); |
| 515 | 515 |
| 516 // For huge images, minimum-scale=0.1 is still too big on small screens. | 516 // For huge images, minimum-scale=0.1 is still too big on small screens. |
| 517 // Set the <div> width so that the image will shrink to fit the width of the | 517 // Set the <div> width so that the image will shrink to fit the width of the |
| 518 // screen when the scale is minimum. | 518 // screen when the scale is minimum. |
| 519 int maxWidth = std::min(imageSize.width().toInt(), viewportWidth * 10); | 519 int maxWidth = std::min(imageSize.width().toInt(), viewportWidth * 10); |
| 520 return std::max(viewportWidth, maxWidth); | 520 return std::max(viewportWidth, maxWidth); |
| 521 } | 521 } |
| 522 | 522 |
| 523 void ImageDocument::windowSizeChanged() { | 523 void ImageDocument::windowSizeChanged() { |
| 524 if (!m_imageElement || !m_imageSizeIsKnown || | 524 if (!m_imageElement || !m_imageSizeIsKnown || |
| 525 m_imageElement->document() != this) | 525 m_imageElement->document() != this) |
| 526 return; | 526 return; |
| 527 | 527 |
| 528 if (m_shrinkToFitMode == Viewport) { | 528 if (m_shrinkToFitMode == Viewport) { |
| 529 LayoutSize imageSize = cachedImageSize(m_imageElement); | 529 LayoutSize imageSize = cachedImageSize(m_imageElement); |
| 530 int divWidth = calculateDivWidth(); | 530 int divWidth = calculateDivWidth(); |
| 531 m_divElement->setInlineStyleProperty(CSSPropertyWidth, divWidth, | 531 m_divElement->setInlineStyleProperty(CSSPropertyWidth, divWidth, |
| 532 CSSPrimitiveValue::UnitType::Pixels); | 532 CSSPrimitiveValue::UnitType::Pixels); |
| 533 | 533 |
| 534 // Explicitly set the height of the <div> containing the <img> so that it | 534 // Explicitly set the height of the <div> containing the <img> so that it |
| 535 // can display the full image without shrinking it, allowing a full-width | 535 // can display the full image without shrinking it, allowing a full-width |
| 536 // reading mode for normal-width-huge-height images. | 536 // reading mode for normal-width-huge-height images. |
| 537 float viewportAspectRatio = | 537 float viewportAspectRatio = |
| 538 frame()->host()->visualViewport().size().aspectRatio(); | 538 frame()->page()->visualViewport().size().aspectRatio(); |
| 539 int divHeight = std::max(imageSize.height().toInt(), | 539 int divHeight = std::max(imageSize.height().toInt(), |
| 540 static_cast<int>(divWidth / viewportAspectRatio)); | 540 static_cast<int>(divWidth / viewportAspectRatio)); |
| 541 m_divElement->setInlineStyleProperty(CSSPropertyHeight, divHeight, | 541 m_divElement->setInlineStyleProperty(CSSPropertyHeight, divHeight, |
| 542 CSSPrimitiveValue::UnitType::Pixels); | 542 CSSPrimitiveValue::UnitType::Pixels); |
| 543 return; | 543 return; |
| 544 } | 544 } |
| 545 | 545 |
| 546 bool fitsInWindow = imageFitsInWindow(); | 546 bool fitsInWindow = imageFitsInWindow(); |
| 547 | 547 |
| 548 // If the image has been explicitly zoomed in, restore the cursor if the image | 548 // If the image has been explicitly zoomed in, restore the cursor if the image |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 623 } | 623 } |
| 624 | 624 |
| 625 bool ImageEventListener::operator==(const EventListener& listener) const { | 625 bool ImageEventListener::operator==(const EventListener& listener) const { |
| 626 if (const ImageEventListener* imageEventListener = | 626 if (const ImageEventListener* imageEventListener = |
| 627 ImageEventListener::cast(&listener)) | 627 ImageEventListener::cast(&listener)) |
| 628 return m_doc == imageEventListener->m_doc; | 628 return m_doc == imageEventListener->m_doc; |
| 629 return false; | 629 return false; |
| 630 } | 630 } |
| 631 | 631 |
| 632 } // namespace blink | 632 } // namespace blink |
| OLD | NEW |