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

Side by Side Diff: third_party/WebKit/Source/core/frame/FrameView.cpp

Issue 2894823002: Clean up blink::FrameView::ForceLayoutForPagination().
Patch Set: cleanup Created 3 years, 7 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 unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/core/frame/FrameView.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1998, 1999 Torben Weis <weis@kde.org> 2 * Copyright (C) 1998, 1999 Torben Weis <weis@kde.org>
3 * 1999 Lars Knoll <knoll@kde.org> 3 * 1999 Lars Knoll <knoll@kde.org>
4 * 1999 Antti Koivisto <koivisto@kde.org> 4 * 1999 Antti Koivisto <koivisto@kde.org>
5 * 2000 Dirk Mueller <mueller@kde.org> 5 * 2000 Dirk Mueller <mueller@kde.org>
6 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
7 * (C) 2006 Graham Dennis (graham.dennis@gmail.com) 7 * (C) 2006 Graham Dennis (graham.dennis@gmail.com)
8 * (C) 2006 Alexey Proskuryakov (ap@nypop.com) 8 * (C) 2006 Alexey Proskuryakov (ap@nypop.com)
9 * Copyright (C) 2009 Google Inc. All rights reserved. 9 * Copyright (C) 2009 Google Inc. All rights reserved.
10 * 10 *
(...skipping 3512 matching lines...) Expand 10 before | Expand all | Expand 10 after
3523 SetNeedsLayout(); 3523 SetNeedsLayout();
3524 ScheduleRelayout(); 3524 ScheduleRelayout();
3525 3525
3526 // Since autosize mode forces the scrollbar mode, change them to being auto. 3526 // Since autosize mode forces the scrollbar mode, change them to being auto.
3527 SetVerticalScrollbarLock(false); 3527 SetVerticalScrollbarLock(false);
3528 SetHorizontalScrollbarLock(false); 3528 SetHorizontalScrollbarLock(false);
3529 SetScrollbarModes(kScrollbarAuto, kScrollbarAuto); 3529 SetScrollbarModes(kScrollbarAuto, kScrollbarAuto);
3530 auto_size_info_.Clear(); 3530 auto_size_info_.Clear();
3531 } 3531 }
3532 3532
3533 bool FrameView::ForceLayoutForPaginationHelper(
3534 const FloatSize& page_size,
3535 const FloatSize& original_page_size,
3536 float maximum_shrink_factor) {
3537 // Dumping ExternalRepresentation(m_frame->LayoutObject()).Ascii() is a good
3538 // trick to see the state of things before and after the layout
3539 LayoutView* layout_view = GetLayoutView();
3540 if (!layout_view)
3541 return false;
3542
3543 bool horizontal_writing_mode =
3544 layout_view->Style()->IsHorizontalWritingMode();
3545 float page_logical_width =
3546 horizontal_writing_mode ? page_size.Width() : page_size.Height();
3547 float page_logical_height =
3548 horizontal_writing_mode ? page_size.Height() : page_size.Width();
3549
3550 LayoutUnit floored_page_logical_width =
3551 static_cast<LayoutUnit>(page_logical_width);
3552 LayoutUnit floored_page_logical_height =
3553 static_cast<LayoutUnit>(page_logical_height);
3554 layout_view->SetLogicalWidth(floored_page_logical_width);
3555 layout_view->SetPageLogicalHeight(floored_page_logical_height);
3556 layout_view->SetNeedsLayoutAndPrefWidthsRecalcAndFullPaintInvalidation(
3557 LayoutInvalidationReason::kPrintingChanged);
3558 UpdateLayout();
3559
3560 // If we don't fit in the given page width, we'll lay out again. If we don't
3561 // fit in the page width when shrunk, we will lay out at maximum shrink and
3562 // clip extra content.
3563 // FIXME: We are assuming a shrink-to-fit printing implementation. A
3564 // cropping implementation should not do this!
3565 const LayoutRect& document_rect = LayoutRect(layout_view->DocumentRect());
3566 LayoutUnit doc_logical_width =
3567 horizontal_writing_mode ? document_rect.Width() : document_rect.Height();
3568 if (doc_logical_width <= page_logical_width)
3569 return false;
3570
3571 FloatSize expected_page_size(
3572 std::min<float>(document_rect.Width().ToFloat(),
3573 page_size.Width() * maximum_shrink_factor),
3574 std::min<float>(document_rect.Height().ToFloat(),
3575 page_size.Height() * maximum_shrink_factor));
3576 FloatSize max_page_size = frame_->ResizePageRectsKeepingRatio(
3577 FloatSize(original_page_size.Width(), original_page_size.Height()),
3578 expected_page_size);
3579 page_logical_width =
3580 horizontal_writing_mode ? max_page_size.Width() : max_page_size.Height();
3581 page_logical_height =
3582 horizontal_writing_mode ? max_page_size.Height() : max_page_size.Width();
3583
3584 floored_page_logical_width = static_cast<LayoutUnit>(page_logical_width);
3585 floored_page_logical_height = static_cast<LayoutUnit>(page_logical_height);
3586 layout_view->SetLogicalWidth(floored_page_logical_width);
3587 layout_view->SetPageLogicalHeight(floored_page_logical_height);
3588 layout_view->SetNeedsLayoutAndPrefWidthsRecalcAndFullPaintInvalidation(
3589 LayoutInvalidationReason::kPrintingChanged);
3590 UpdateLayout();
3591
3592 const LayoutRect& updated_document_rect =
3593 LayoutRect(layout_view->DocumentRect());
3594 LayoutUnit doc_logical_height = horizontal_writing_mode
3595 ? updated_document_rect.Height()
3596 : updated_document_rect.Width();
3597 LayoutUnit doc_logical_top = horizontal_writing_mode
3598 ? updated_document_rect.Y()
3599 : updated_document_rect.X();
3600 LayoutUnit doc_logical_right = horizontal_writing_mode
3601 ? updated_document_rect.MaxX()
3602 : updated_document_rect.MaxY();
3603 LayoutUnit clipped_logical_left;
3604 if (!layout_view->Style()->IsLeftToRightDirection())
3605 clipped_logical_left = LayoutUnit(doc_logical_right - page_logical_width);
3606 LayoutRect overflow(clipped_logical_left, doc_logical_top,
3607 LayoutUnit(page_logical_width), doc_logical_height);
3608
3609 if (!horizontal_writing_mode)
3610 overflow = overflow.TransposedRect();
3611 AdjustViewSizeAndLayout();
3612 // This is how we clip in case we overflow again.
3613 layout_view->ClearLayoutOverflow();
3614 layout_view->AddLayoutOverflow(overflow);
3615 return true;
3616 }
3617
3533 void FrameView::ForceLayoutForPagination(const FloatSize& page_size, 3618 void FrameView::ForceLayoutForPagination(const FloatSize& page_size,
3534 const FloatSize& original_page_size, 3619 const FloatSize& original_page_size,
3535 float maximum_shrink_factor) { 3620 float maximum_shrink_factor) {
3536 // Dumping externalRepresentation(m_frame->layoutObject()).ascii() is a good 3621 if (ForceLayoutForPaginationHelper(page_size, original_page_size,
3537 // trick to see the state of things before and after the layout 3622 maximum_shrink_factor)) {
3538 if (LayoutView* layout_view = this->GetLayoutView()) { 3623 return;
3539 float page_logical_width = layout_view->Style()->IsHorizontalWritingMode()
3540 ? page_size.Width()
3541 : page_size.Height();
3542 float page_logical_height = layout_view->Style()->IsHorizontalWritingMode()
3543 ? page_size.Height()
3544 : page_size.Width();
3545
3546 LayoutUnit floored_page_logical_width =
3547 static_cast<LayoutUnit>(page_logical_width);
3548 LayoutUnit floored_page_logical_height =
3549 static_cast<LayoutUnit>(page_logical_height);
3550 layout_view->SetLogicalWidth(floored_page_logical_width);
3551 layout_view->SetPageLogicalHeight(floored_page_logical_height);
3552 layout_view->SetNeedsLayoutAndPrefWidthsRecalcAndFullPaintInvalidation(
3553 LayoutInvalidationReason::kPrintingChanged);
3554 UpdateLayout();
3555
3556 // If we don't fit in the given page width, we'll lay out again. If we don't
3557 // fit in the page width when shrunk, we will lay out at maximum shrink and
3558 // clip extra content.
3559 // FIXME: We are assuming a shrink-to-fit printing implementation. A
3560 // cropping implementation should not do this!
3561 bool horizontal_writing_mode =
3562 layout_view->Style()->IsHorizontalWritingMode();
3563 const LayoutRect& document_rect = LayoutRect(layout_view->DocumentRect());
3564 LayoutUnit doc_logical_width = horizontal_writing_mode
3565 ? document_rect.Width()
3566 : document_rect.Height();
3567 if (doc_logical_width > page_logical_width) {
3568 FloatSize expected_page_size(
3569 std::min<float>(document_rect.Width().ToFloat(),
3570 page_size.Width() * maximum_shrink_factor),
3571 std::min<float>(document_rect.Height().ToFloat(),
3572 page_size.Height() * maximum_shrink_factor));
3573 FloatSize max_page_size = frame_->ResizePageRectsKeepingRatio(
3574 FloatSize(original_page_size.Width(), original_page_size.Height()),
3575 expected_page_size);
3576 page_logical_width = horizontal_writing_mode ? max_page_size.Width()
3577 : max_page_size.Height();
3578 page_logical_height = horizontal_writing_mode ? max_page_size.Height()
3579 : max_page_size.Width();
3580
3581 floored_page_logical_width = static_cast<LayoutUnit>(page_logical_width);
3582 floored_page_logical_height =
3583 static_cast<LayoutUnit>(page_logical_height);
3584 layout_view->SetLogicalWidth(floored_page_logical_width);
3585 layout_view->SetPageLogicalHeight(floored_page_logical_height);
3586 layout_view->SetNeedsLayoutAndPrefWidthsRecalcAndFullPaintInvalidation(
3587 LayoutInvalidationReason::kPrintingChanged);
3588 UpdateLayout();
3589
3590 const LayoutRect& updated_document_rect =
3591 LayoutRect(layout_view->DocumentRect());
3592 LayoutUnit doc_logical_height = horizontal_writing_mode
3593 ? updated_document_rect.Height()
3594 : updated_document_rect.Width();
3595 LayoutUnit doc_logical_top = horizontal_writing_mode
3596 ? updated_document_rect.Y()
3597 : updated_document_rect.X();
3598 LayoutUnit doc_logical_right = horizontal_writing_mode
3599 ? updated_document_rect.MaxX()
3600 : updated_document_rect.MaxY();
3601 LayoutUnit clipped_logical_left;
3602 if (!layout_view->Style()->IsLeftToRightDirection())
3603 clipped_logical_left =
3604 LayoutUnit(doc_logical_right - page_logical_width);
3605 LayoutRect overflow(clipped_logical_left, doc_logical_top,
3606 LayoutUnit(page_logical_width), doc_logical_height);
3607
3608 if (!horizontal_writing_mode)
3609 overflow = overflow.TransposedRect();
3610 AdjustViewSizeAndLayout();
3611 // This is how we clip in case we overflow again.
3612 layout_view->ClearLayoutOverflow();
3613 layout_view->AddLayoutOverflow(overflow);
3614 return;
3615 }
3616 } 3624 }
3617 3625
3618 if (TextAutosizer* text_autosizer = frame_->GetDocument()->GetTextAutosizer()) 3626 if (TextAutosizer* text_autosizer = frame_->GetDocument()->GetTextAutosizer())
3619 text_autosizer->UpdatePageInfo(); 3627 text_autosizer->UpdatePageInfo();
3620 AdjustViewSizeAndLayout(); 3628 AdjustViewSizeAndLayout();
3621 } 3629 }
3622 3630
3623 IntRect FrameView::ConvertFromLayoutItem( 3631 IntRect FrameView::ConvertFromLayoutItem(
3624 const LayoutItem& layout_item, 3632 const LayoutItem& layout_item,
3625 const IntRect& layout_object_rect) const { 3633 const IntRect& layout_object_rect) const {
(...skipping 1798 matching lines...) Expand 10 before | Expand all | Expand 10 after
5424 void FrameView::SetAnimationHost( 5432 void FrameView::SetAnimationHost(
5425 std::unique_ptr<CompositorAnimationHost> host) { 5433 std::unique_ptr<CompositorAnimationHost> host) {
5426 animation_host_ = std::move(host); 5434 animation_host_ = std::move(host);
5427 } 5435 }
5428 5436
5429 LayoutUnit FrameView::CaretWidth() const { 5437 LayoutUnit FrameView::CaretWidth() const {
5430 return LayoutUnit(GetChromeClient()->WindowToViewportScalar(1)); 5438 return LayoutUnit(GetChromeClient()->WindowToViewportScalar(1));
5431 } 5439 }
5432 5440
5433 } // namespace blink 5441 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/frame/FrameView.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698