| Index: third_party/WebKit/Source/core/frame/FrameView.cpp
|
| diff --git a/third_party/WebKit/Source/core/frame/FrameView.cpp b/third_party/WebKit/Source/core/frame/FrameView.cpp
|
| index 3cf3699fb85abee836666befe7a2a69c98a19460..ab7926294619e29e030a62e3cbfd928f8846001b 100644
|
| --- a/third_party/WebKit/Source/core/frame/FrameView.cpp
|
| +++ b/third_party/WebKit/Source/core/frame/FrameView.cpp
|
| @@ -3530,89 +3530,97 @@ void FrameView::DisableAutoSizeMode() {
|
| auto_size_info_.Clear();
|
| }
|
|
|
| -void FrameView::ForceLayoutForPagination(const FloatSize& page_size,
|
| - const FloatSize& original_page_size,
|
| - float maximum_shrink_factor) {
|
| - // Dumping externalRepresentation(m_frame->layoutObject()).ascii() is a good
|
| +bool FrameView::ForceLayoutForPaginationHelper(
|
| + const FloatSize& page_size,
|
| + const FloatSize& original_page_size,
|
| + float maximum_shrink_factor) {
|
| + // Dumping ExternalRepresentation(m_frame->LayoutObject()).Ascii() is a good
|
| // trick to see the state of things before and after the layout
|
| - if (LayoutView* layout_view = this->GetLayoutView()) {
|
| - float page_logical_width = layout_view->Style()->IsHorizontalWritingMode()
|
| - ? page_size.Width()
|
| - : page_size.Height();
|
| - float page_logical_height = layout_view->Style()->IsHorizontalWritingMode()
|
| - ? page_size.Height()
|
| - : page_size.Width();
|
| -
|
| - LayoutUnit floored_page_logical_width =
|
| - static_cast<LayoutUnit>(page_logical_width);
|
| - LayoutUnit floored_page_logical_height =
|
| - static_cast<LayoutUnit>(page_logical_height);
|
| - layout_view->SetLogicalWidth(floored_page_logical_width);
|
| - layout_view->SetPageLogicalHeight(floored_page_logical_height);
|
| - layout_view->SetNeedsLayoutAndPrefWidthsRecalcAndFullPaintInvalidation(
|
| - LayoutInvalidationReason::kPrintingChanged);
|
| - UpdateLayout();
|
| + LayoutView* layout_view = GetLayoutView();
|
| + if (!layout_view)
|
| + return false;
|
|
|
| - // If we don't fit in the given page width, we'll lay out again. If we don't
|
| - // fit in the page width when shrunk, we will lay out at maximum shrink and
|
| - // clip extra content.
|
| - // FIXME: We are assuming a shrink-to-fit printing implementation. A
|
| - // cropping implementation should not do this!
|
| - bool horizontal_writing_mode =
|
| - layout_view->Style()->IsHorizontalWritingMode();
|
| - const LayoutRect& document_rect = LayoutRect(layout_view->DocumentRect());
|
| - LayoutUnit doc_logical_width = horizontal_writing_mode
|
| - ? document_rect.Width()
|
| - : document_rect.Height();
|
| - if (doc_logical_width > page_logical_width) {
|
| - FloatSize expected_page_size(
|
| - std::min<float>(document_rect.Width().ToFloat(),
|
| - page_size.Width() * maximum_shrink_factor),
|
| - std::min<float>(document_rect.Height().ToFloat(),
|
| - page_size.Height() * maximum_shrink_factor));
|
| - FloatSize max_page_size = frame_->ResizePageRectsKeepingRatio(
|
| - FloatSize(original_page_size.Width(), original_page_size.Height()),
|
| - expected_page_size);
|
| - page_logical_width = horizontal_writing_mode ? max_page_size.Width()
|
| - : max_page_size.Height();
|
| - page_logical_height = horizontal_writing_mode ? max_page_size.Height()
|
| - : max_page_size.Width();
|
| -
|
| - floored_page_logical_width = static_cast<LayoutUnit>(page_logical_width);
|
| - floored_page_logical_height =
|
| - static_cast<LayoutUnit>(page_logical_height);
|
| - layout_view->SetLogicalWidth(floored_page_logical_width);
|
| - layout_view->SetPageLogicalHeight(floored_page_logical_height);
|
| - layout_view->SetNeedsLayoutAndPrefWidthsRecalcAndFullPaintInvalidation(
|
| - LayoutInvalidationReason::kPrintingChanged);
|
| - UpdateLayout();
|
| + bool horizontal_writing_mode =
|
| + layout_view->Style()->IsHorizontalWritingMode();
|
| + float page_logical_width =
|
| + horizontal_writing_mode ? page_size.Width() : page_size.Height();
|
| + float page_logical_height =
|
| + horizontal_writing_mode ? page_size.Height() : page_size.Width();
|
| +
|
| + LayoutUnit floored_page_logical_width =
|
| + static_cast<LayoutUnit>(page_logical_width);
|
| + LayoutUnit floored_page_logical_height =
|
| + static_cast<LayoutUnit>(page_logical_height);
|
| + layout_view->SetLogicalWidth(floored_page_logical_width);
|
| + layout_view->SetPageLogicalHeight(floored_page_logical_height);
|
| + layout_view->SetNeedsLayoutAndPrefWidthsRecalcAndFullPaintInvalidation(
|
| + LayoutInvalidationReason::kPrintingChanged);
|
| + UpdateLayout();
|
| +
|
| + // If we don't fit in the given page width, we'll lay out again. If we don't
|
| + // fit in the page width when shrunk, we will lay out at maximum shrink and
|
| + // clip extra content.
|
| + // FIXME: We are assuming a shrink-to-fit printing implementation. A
|
| + // cropping implementation should not do this!
|
| + const LayoutRect& document_rect = LayoutRect(layout_view->DocumentRect());
|
| + LayoutUnit doc_logical_width =
|
| + horizontal_writing_mode ? document_rect.Width() : document_rect.Height();
|
| + if (doc_logical_width <= page_logical_width)
|
| + return false;
|
|
|
| - const LayoutRect& updated_document_rect =
|
| - LayoutRect(layout_view->DocumentRect());
|
| - LayoutUnit doc_logical_height = horizontal_writing_mode
|
| - ? updated_document_rect.Height()
|
| - : updated_document_rect.Width();
|
| - LayoutUnit doc_logical_top = horizontal_writing_mode
|
| - ? updated_document_rect.Y()
|
| - : updated_document_rect.X();
|
| - LayoutUnit doc_logical_right = horizontal_writing_mode
|
| - ? updated_document_rect.MaxX()
|
| - : updated_document_rect.MaxY();
|
| - LayoutUnit clipped_logical_left;
|
| - if (!layout_view->Style()->IsLeftToRightDirection())
|
| - clipped_logical_left =
|
| - LayoutUnit(doc_logical_right - page_logical_width);
|
| - LayoutRect overflow(clipped_logical_left, doc_logical_top,
|
| - LayoutUnit(page_logical_width), doc_logical_height);
|
| -
|
| - if (!horizontal_writing_mode)
|
| - overflow = overflow.TransposedRect();
|
| - AdjustViewSizeAndLayout();
|
| - // This is how we clip in case we overflow again.
|
| - layout_view->ClearLayoutOverflow();
|
| - layout_view->AddLayoutOverflow(overflow);
|
| - return;
|
| - }
|
| + FloatSize expected_page_size(
|
| + std::min<float>(document_rect.Width().ToFloat(),
|
| + page_size.Width() * maximum_shrink_factor),
|
| + std::min<float>(document_rect.Height().ToFloat(),
|
| + page_size.Height() * maximum_shrink_factor));
|
| + FloatSize max_page_size = frame_->ResizePageRectsKeepingRatio(
|
| + FloatSize(original_page_size.Width(), original_page_size.Height()),
|
| + expected_page_size);
|
| + page_logical_width =
|
| + horizontal_writing_mode ? max_page_size.Width() : max_page_size.Height();
|
| + page_logical_height =
|
| + horizontal_writing_mode ? max_page_size.Height() : max_page_size.Width();
|
| +
|
| + floored_page_logical_width = static_cast<LayoutUnit>(page_logical_width);
|
| + floored_page_logical_height = static_cast<LayoutUnit>(page_logical_height);
|
| + layout_view->SetLogicalWidth(floored_page_logical_width);
|
| + layout_view->SetPageLogicalHeight(floored_page_logical_height);
|
| + layout_view->SetNeedsLayoutAndPrefWidthsRecalcAndFullPaintInvalidation(
|
| + LayoutInvalidationReason::kPrintingChanged);
|
| + UpdateLayout();
|
| +
|
| + const LayoutRect& updated_document_rect =
|
| + LayoutRect(layout_view->DocumentRect());
|
| + LayoutUnit doc_logical_height = horizontal_writing_mode
|
| + ? updated_document_rect.Height()
|
| + : updated_document_rect.Width();
|
| + LayoutUnit doc_logical_top = horizontal_writing_mode
|
| + ? updated_document_rect.Y()
|
| + : updated_document_rect.X();
|
| + LayoutUnit doc_logical_right = horizontal_writing_mode
|
| + ? updated_document_rect.MaxX()
|
| + : updated_document_rect.MaxY();
|
| + LayoutUnit clipped_logical_left;
|
| + if (!layout_view->Style()->IsLeftToRightDirection())
|
| + clipped_logical_left = LayoutUnit(doc_logical_right - page_logical_width);
|
| + LayoutRect overflow(clipped_logical_left, doc_logical_top,
|
| + LayoutUnit(page_logical_width), doc_logical_height);
|
| +
|
| + if (!horizontal_writing_mode)
|
| + overflow = overflow.TransposedRect();
|
| + AdjustViewSizeAndLayout();
|
| + // This is how we clip in case we overflow again.
|
| + layout_view->ClearLayoutOverflow();
|
| + layout_view->AddLayoutOverflow(overflow);
|
| + return true;
|
| +}
|
| +
|
| +void FrameView::ForceLayoutForPagination(const FloatSize& page_size,
|
| + const FloatSize& original_page_size,
|
| + float maximum_shrink_factor) {
|
| + if (ForceLayoutForPaginationHelper(page_size, original_page_size,
|
| + maximum_shrink_factor)) {
|
| + return;
|
| }
|
|
|
| if (TextAutosizer* text_autosizer = frame_->GetDocument()->GetTextAutosizer())
|
|
|