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

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

Issue 2454913003: MainFrame scrollbars should work with RFV instead of FV (Closed)
Patch Set: Fix failing test Created 4 years, 1 month 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
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 421 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 if (!scrollbar) 432 if (!scrollbar)
433 return; 433 return;
434 434
435 m_scrollableArea->willRemoveScrollbar(*scrollbar, orientation); 435 m_scrollableArea->willRemoveScrollbar(*scrollbar, orientation);
436 m_scrollableArea->layoutBox()->document().view()->removeChild( 436 m_scrollableArea->layoutBox()->document().view()->removeChild(
437 scrollbar.get()); 437 scrollbar.get());
438 scrollbar->disconnectFromScrollableArea(); 438 scrollbar->disconnectFromScrollableArea();
439 scrollbar = nullptr; 439 scrollbar = nullptr;
440 } 440 }
441 441
442 ScrollableArea* FrameView::ScrollbarManager::scrollableArea() const {
443 return m_scrollableArea.get();
444 }
445
446 void FrameView::ScrollbarManager::updateScrollbarGeometry(IntSize viewSize) {
447 if (!hasHorizontalScrollbar() && !hasVerticalScrollbar())
448 return;
449
450 bool scrollbarOnLeft = m_scrollableArea->shouldPlaceVerticalScrollbarOnLeft();
451
452 if (hasHorizontalScrollbar()) {
453 int thickness = m_hBar->scrollbarThickness();
454 IntRect oldRect(m_hBar->frameRect());
455 IntRect hBarRect(
456 (scrollbarOnLeft && hasVerticalScrollbar()) ? m_vBar->width() : 0,
457 viewSize.height() - thickness,
458 viewSize.width() - (hasVerticalScrollbar() ? m_vBar->width() : 0),
459 thickness);
460 m_hBar->setFrameRect(hBarRect);
461 if (oldRect != m_hBar->frameRect())
462 m_scrollableArea->setScrollbarNeedsPaintInvalidation(HorizontalScrollbar);
463
464 int visibleWidth = m_scrollableArea->visibleWidth();
465 int contentsWidth = m_scrollableArea->contentsSize().width();
466 m_hBar->setEnabled(contentsWidth > visibleWidth &&
467 !m_scrollableArea->scrollbarsHidden());
468 m_hBar->setProportion(visibleWidth, contentsWidth);
469 m_hBar->offsetDidChange();
470 }
471
472 if (hasVerticalScrollbar()) {
473 int thickness = m_vBar->scrollbarThickness();
474 IntRect oldRect(m_vBar->frameRect());
475 IntRect vBarRect(
476 scrollbarOnLeft ? 0 : (viewSize.width() - thickness), 0, thickness,
477 viewSize.height() - (hasHorizontalScrollbar() ? m_hBar->height() : 0));
478 m_vBar->setFrameRect(vBarRect);
479 if (oldRect != m_vBar->frameRect())
480 m_scrollableArea->setScrollbarNeedsPaintInvalidation(VerticalScrollbar);
481
482 int clientHeight = m_scrollableArea->visibleHeight();
483 int contentsHeight = m_scrollableArea->contentsSize().height();
484 m_vBar->setEnabled(contentsHeight > clientHeight &&
485 !m_scrollableArea->scrollbarsHidden());
486 m_vBar->setProportion(clientHeight, contentsHeight);
487 m_vBar->offsetDidChange();
488 }
489 }
490
442 void FrameView::recalculateCustomScrollbarStyle() { 491 void FrameView::recalculateCustomScrollbarStyle() {
443 bool didStyleChange = false; 492 bool didStyleChange = false;
444 if (horizontalScrollbar() && horizontalScrollbar()->isCustomScrollbar()) { 493 if (horizontalScrollbar() && horizontalScrollbar()->isCustomScrollbar()) {
445 horizontalScrollbar()->styleChanged(); 494 horizontalScrollbar()->styleChanged();
446 didStyleChange = true; 495 didStyleChange = true;
447 } 496 }
448 if (verticalScrollbar() && verticalScrollbar()->isCustomScrollbar()) { 497 if (verticalScrollbar() && verticalScrollbar()->isCustomScrollbar()) {
449 verticalScrollbar()->styleChanged(); 498 verticalScrollbar()->styleChanged();
450 didStyleChange = true; 499 didStyleChange = true;
451 } 500 }
452 if (didStyleChange) { 501 if (didStyleChange) {
453 updateScrollbarGeometry(); 502 m_scrollbarManager.updateScrollbarGeometry(size());
454 updateScrollCorner(); 503 updateScrollCorner();
455 positionScrollbarLayers(); 504 positionScrollbarLayers();
456 } 505 }
457 } 506 }
458 507
459 void FrameView::invalidateAllCustomScrollbarsOnActiveChanged() { 508 void FrameView::invalidateAllCustomScrollbarsOnActiveChanged() {
460 bool usesWindowInactiveSelector = 509 bool usesWindowInactiveSelector =
461 m_frame->document()->styleEngine().usesWindowInactiveSelector(); 510 m_frame->document()->styleEngine().usesWindowInactiveSelector();
462 511
463 const ChildrenWidgetSet* viewChildren = children(); 512 const ChildrenWidgetSet* viewChildren = children();
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
790 839
791 bool hasHorizontalScrollbar = horizontalScrollbar(); 840 bool hasHorizontalScrollbar = horizontalScrollbar();
792 bool hasVerticalScrollbar = verticalScrollbar(); 841 bool hasVerticalScrollbar = verticalScrollbar();
793 if (hasHorizontalScrollbar != shouldHaveHorizontalScrollbar || 842 if (hasHorizontalScrollbar != shouldHaveHorizontalScrollbar ||
794 hasVerticalScrollbar != shouldHaveVerticalScrollbar) { 843 hasVerticalScrollbar != shouldHaveVerticalScrollbar) {
795 setNeedsLayout(); 844 setNeedsLayout();
796 return; 845 return;
797 } 846 }
798 847
799 adjustViewSize(); 848 adjustViewSize();
800 updateScrollbarGeometry(); 849 m_scrollbarManager.updateScrollbarGeometry(size());
801 850
802 if (scrollOriginChanged()) 851 if (scrollOriginChanged())
803 setNeedsLayout(); 852 setNeedsLayout();
804 } 853 }
805 854
806 bool FrameView::usesCompositedScrolling() const { 855 bool FrameView::usesCompositedScrolling() const {
807 LayoutViewItem layoutView = this->layoutViewItem(); 856 LayoutViewItem layoutView = this->layoutViewItem();
808 if (layoutView.isNull()) 857 if (layoutView.isNull())
809 return false; 858 return false;
810 if (m_frame->settings() && 859 if (m_frame->settings() &&
(...skipping 1594 matching lines...) Expand 10 before | Expand all | Expand 10 after
2405 2454
2406 return ScrollableArea::shouldUseIntegerScrollOffset(); 2455 return ScrollableArea::shouldUseIntegerScrollOffset();
2407 } 2456 }
2408 2457
2409 bool FrameView::isActive() const { 2458 bool FrameView::isActive() const {
2410 Page* page = frame().page(); 2459 Page* page = frame().page();
2411 return page && page->focusController().isActive(); 2460 return page && page->focusController().isActive();
2412 } 2461 }
2413 2462
2414 void FrameView::invalidatePaintForTickmarks() { 2463 void FrameView::invalidatePaintForTickmarks() {
2415 if (Scrollbar* scrollbar = verticalScrollbar()) 2464 if (Scrollbar* scrollbar = getScrollableArea()->verticalScrollbar())
2416 scrollbar->setNeedsPaintInvalidation( 2465 scrollbar->setNeedsPaintInvalidation(
2417 static_cast<ScrollbarPart>(~ThumbPart)); 2466 static_cast<ScrollbarPart>(~ThumbPart));
2418 } 2467 }
2419 2468
2420 void FrameView::getTickmarks(Vector<IntRect>& tickmarks) const { 2469 void FrameView::getTickmarks(Vector<IntRect>& tickmarks) const {
2421 if (!m_tickmarks.isEmpty()) 2470 if (!m_tickmarks.isEmpty())
2422 tickmarks = m_tickmarks; 2471 tickmarks = m_tickmarks;
2423 else 2472 else
2424 tickmarks = frame().document()->markers().renderedRectsForMarkers( 2473 tickmarks = frame().document()->markers().renderedRectsForMarkers(
2425 DocumentMarker::TextMatch); 2474 DocumentMarker::TextMatch);
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
2573 2622
2574 if (m_frame->isMainFrame()) { 2623 if (m_frame->isMainFrame()) {
2575 ScrollableArea& visualViewport = frameHost->visualViewport(); 2624 ScrollableArea& visualViewport = frameHost->visualViewport();
2576 ScrollableArea* layoutViewport = layoutViewportScrollableArea(); 2625 ScrollableArea* layoutViewport = layoutViewportScrollableArea();
2577 DCHECK(layoutViewport); 2626 DCHECK(layoutViewport);
2578 2627
2579 RootFrameViewport* rootFrameViewport = 2628 RootFrameViewport* rootFrameViewport =
2580 RootFrameViewport::create(visualViewport, *layoutViewport); 2629 RootFrameViewport::create(visualViewport, *layoutViewport);
2581 m_viewportScrollableArea = rootFrameViewport; 2630 m_viewportScrollableArea = rootFrameViewport;
2582 2631
2632 // TODO(crbug.com/661236): Currently for the main frame, the scroller that
2633 // the scrollbar manager works with is RootFrameViewport which is needed so
2634 // that the visual viewport is taken into account when determining scrollbar
2635 // extent and existence. Eventually, each scroller should have its own
2636 // scrollbar manager and we shouldn't set the scroller here.
2637 m_scrollbarManager.setScroller(rootFrameViewport);
2638
2583 frameHost->globalRootScrollerController().initializeViewportScrollCallback( 2639 frameHost->globalRootScrollerController().initializeViewportScrollCallback(
2584 *rootFrameViewport); 2640 *rootFrameViewport);
2585 } 2641 }
2586 } 2642 }
2587 2643
2588 void FrameView::updateScrollCorner() { 2644 void FrameView::updateScrollCorner() {
2589 RefPtr<ComputedStyle> cornerStyle; 2645 RefPtr<ComputedStyle> cornerStyle;
2590 IntRect cornerRect = scrollCornerRect(); 2646 IntRect cornerRect = scrollCornerRect();
2591 Document* doc = m_frame->document(); 2647 Document* doc = m_frame->document();
2592 2648
(...skipping 1111 matching lines...) Expand 10 before | Expand all | Expand 10 after
3704 if (frame().isMainFrame()) 3760 if (frame().isMainFrame())
3705 frame().host()->chromeClient().mainFrameScrollOffsetChanged(); 3761 frame().host()->chromeClient().mainFrameScrollOffsetChanged();
3706 } 3762 }
3707 3763
3708 void FrameView::clearScrollAnchor() { 3764 void FrameView::clearScrollAnchor() {
3709 if (!RuntimeEnabledFeatures::scrollAnchoringEnabled()) 3765 if (!RuntimeEnabledFeatures::scrollAnchoringEnabled())
3710 return; 3766 return;
3711 m_scrollAnchor.clear(); 3767 m_scrollAnchor.clear();
3712 } 3768 }
3713 3769
3714 bool FrameView::hasOverlayScrollbars() const {
3715 return (horizontalScrollbar() &&
3716 horizontalScrollbar()->isOverlayScrollbar()) ||
3717 (verticalScrollbar() && verticalScrollbar()->isOverlayScrollbar());
3718 }
3719
3720 void FrameView::computeScrollbarExistence( 3770 void FrameView::computeScrollbarExistence(
3721 bool& newHasHorizontalScrollbar, 3771 bool& newHasHorizontalScrollbar,
3722 bool& newHasVerticalScrollbar, 3772 bool& newHasVerticalScrollbar,
3723 const IntSize& docSize, 3773 const IntSize& docSize,
3724 ComputeScrollbarExistenceOption option) const { 3774 ComputeScrollbarExistenceOption option) const {
3725 if (m_frame->settings() && m_frame->settings()->hideScrollbars()) { 3775 if (m_frame->settings() && m_frame->settings()->hideScrollbars()) {
3726 newHasHorizontalScrollbar = false; 3776 newHasHorizontalScrollbar = false;
3727 newHasVerticalScrollbar = false; 3777 newHasVerticalScrollbar = false;
3728 return; 3778 return;
3729 } 3779 }
(...skipping 12 matching lines...) Expand all
3742 3792
3743 if (hScroll != ScrollbarAuto) 3793 if (hScroll != ScrollbarAuto)
3744 newHasHorizontalScrollbar = (hScroll == ScrollbarAlwaysOn); 3794 newHasHorizontalScrollbar = (hScroll == ScrollbarAlwaysOn);
3745 if (vScroll != ScrollbarAuto) 3795 if (vScroll != ScrollbarAuto)
3746 newHasVerticalScrollbar = (vScroll == ScrollbarAlwaysOn); 3796 newHasVerticalScrollbar = (vScroll == ScrollbarAlwaysOn);
3747 3797
3748 if (m_scrollbarsSuppressed || 3798 if (m_scrollbarsSuppressed ||
3749 (hScroll != ScrollbarAuto && vScroll != ScrollbarAuto)) 3799 (hScroll != ScrollbarAuto && vScroll != ScrollbarAuto))
3750 return; 3800 return;
3751 3801
3802 ScrollableArea* scroller = m_scrollbarManager.scrollableArea();
3752 if (hScroll == ScrollbarAuto) 3803 if (hScroll == ScrollbarAuto)
3753 newHasHorizontalScrollbar = docSize.width() > visibleWidth(); 3804 newHasHorizontalScrollbar = docSize.width() > scroller->visibleWidth();
3754 if (vScroll == ScrollbarAuto) 3805 if (vScroll == ScrollbarAuto)
3755 newHasVerticalScrollbar = docSize.height() > visibleHeight(); 3806 newHasVerticalScrollbar = docSize.height() > scroller->visibleHeight();
3756 3807
3757 if (hasOverlayScrollbars()) 3808 if (hasOverlayScrollbars())
3758 return; 3809 return;
3759 3810
3760 IntSize fullVisibleSize = visibleContentRect(IncludeScrollbars).size(); 3811 IntSize fullVisibleSize =
3812 scroller->visibleContentRect(IncludeScrollbars).size();
3761 3813
3762 bool attemptToRemoveScrollbars = 3814 bool attemptToRemoveScrollbars =
3763 (option == FirstPass && docSize.width() <= fullVisibleSize.width() && 3815 (option == FirstPass && docSize.width() <= fullVisibleSize.width() &&
3764 docSize.height() <= fullVisibleSize.height()); 3816 docSize.height() <= fullVisibleSize.height());
3765 if (attemptToRemoveScrollbars) { 3817 if (attemptToRemoveScrollbars) {
3766 if (hScroll == ScrollbarAuto) 3818 if (hScroll == ScrollbarAuto)
3767 newHasHorizontalScrollbar = false; 3819 newHasHorizontalScrollbar = false;
3768 if (vScroll == ScrollbarAuto) 3820 if (vScroll == ScrollbarAuto)
3769 newHasVerticalScrollbar = false; 3821 newHasVerticalScrollbar = false;
3770 } 3822 }
3771 } 3823 }
3772 3824
3773 void FrameView::updateScrollbarGeometry() {
3774 if (horizontalScrollbar()) {
3775 int thickness = horizontalScrollbar()->scrollbarThickness();
3776 int clientWidth = visibleWidth();
3777 IntRect oldRect(horizontalScrollbar()->frameRect());
3778 IntRect hBarRect(
3779 (shouldPlaceVerticalScrollbarOnLeft() && verticalScrollbar())
3780 ? verticalScrollbar()->width()
3781 : 0,
3782 height() - thickness,
3783 width() - (verticalScrollbar() ? verticalScrollbar()->width() : 0),
3784 thickness);
3785 horizontalScrollbar()->setFrameRect(hBarRect);
3786 if (oldRect != horizontalScrollbar()->frameRect())
3787 setScrollbarNeedsPaintInvalidation(HorizontalScrollbar);
3788
3789 horizontalScrollbar()->setEnabled(contentsWidth() > clientWidth &&
3790 !scrollbarsHidden());
3791 horizontalScrollbar()->setProportion(clientWidth, contentsWidth());
3792 horizontalScrollbar()->offsetDidChange();
3793 }
3794
3795 if (verticalScrollbar()) {
3796 int thickness = verticalScrollbar()->scrollbarThickness();
3797 int clientHeight = visibleHeight();
3798 IntRect oldRect(verticalScrollbar()->frameRect());
3799 IntRect vBarRect(
3800 shouldPlaceVerticalScrollbarOnLeft() ? 0 : (width() - thickness), 0,
3801 thickness,
3802 height() -
3803 (horizontalScrollbar() ? horizontalScrollbar()->height() : 0));
3804 verticalScrollbar()->setFrameRect(vBarRect);
3805 if (oldRect != verticalScrollbar()->frameRect())
3806 setScrollbarNeedsPaintInvalidation(VerticalScrollbar);
3807
3808 verticalScrollbar()->setEnabled(contentsHeight() > clientHeight &&
3809 !scrollbarsHidden());
3810 verticalScrollbar()->setProportion(clientHeight, contentsHeight());
3811 verticalScrollbar()->offsetDidChange();
3812 }
3813 }
3814
3815 bool FrameView::adjustScrollbarExistence( 3825 bool FrameView::adjustScrollbarExistence(
3816 ComputeScrollbarExistenceOption option) { 3826 ComputeScrollbarExistenceOption option) {
3817 ASSERT(m_inUpdateScrollbars); 3827 ASSERT(m_inUpdateScrollbars);
3818 3828
3819 // If we came in here with the view already needing a layout, then go ahead 3829 // If we came in here with the view already needing a layout, then go ahead
3820 // and do that first. (This will be the common case, e.g., when the page 3830 // and do that first. (This will be the common case, e.g., when the page
3821 // changes due to window resizing for example). This layout will not re-enter 3831 // changes due to window resizing for example). This layout will not re-enter
3822 // updateScrollbars and does not count towards our max layout pass total. 3832 // updateScrollbars and does not count towards our max layout pass total.
3823 if (!m_scrollbarsSuppressed) 3833 if (!m_scrollbarsSuppressed)
3824 scrollbarExistenceDidChange(); 3834 scrollbarExistenceDidChange();
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
3907 int maxUpdateScrollbarsPass = 3917 int maxUpdateScrollbarsPass =
3908 hasOverlayScrollbars() || m_scrollbarsSuppressed ? 1 : 3; 3918 hasOverlayScrollbars() || m_scrollbarsSuppressed ? 1 : 3;
3909 for (int updateScrollbarsPass = 0; 3919 for (int updateScrollbarsPass = 0;
3910 updateScrollbarsPass < maxUpdateScrollbarsPass; updateScrollbarsPass++) { 3920 updateScrollbarsPass < maxUpdateScrollbarsPass; updateScrollbarsPass++) {
3911 if (!adjustScrollbarExistence(updateScrollbarsPass ? Incremental 3921 if (!adjustScrollbarExistence(updateScrollbarsPass ? Incremental
3912 : FirstPass)) 3922 : FirstPass))
3913 break; 3923 break;
3914 scrollbarExistenceChanged = true; 3924 scrollbarExistenceChanged = true;
3915 } 3925 }
3916 3926
3917 updateScrollbarGeometry(); 3927 m_scrollbarManager.updateScrollbarGeometry(size());
3918 3928
3919 if (scrollbarExistenceChanged) { 3929 if (scrollbarExistenceChanged) {
3920 // FIXME: Is frameRectsChanged really necessary here? Have any frame rects 3930 // FIXME: Is frameRectsChanged really necessary here? Have any frame rects
3921 // changed? 3931 // changed?
3922 frameRectsChanged(); 3932 frameRectsChanged();
3923 positionScrollbarLayers(); 3933 positionScrollbarLayers();
3924 updateScrollCorner(); 3934 updateScrollCorner();
3925 } 3935 }
3926 3936
3927 adjustScrollOffsetFromUpdateScrollbars(); 3937 adjustScrollOffsetFromUpdateScrollbars();
(...skipping 637 matching lines...) Expand 10 before | Expand all | Expand 10 after
4565 DCHECK(m_frame->isMainFrame()); 4575 DCHECK(m_frame->isMainFrame());
4566 return m_initialViewportSize.width(); 4576 return m_initialViewportSize.width();
4567 } 4577 }
4568 4578
4569 int FrameView::initialViewportHeight() const { 4579 int FrameView::initialViewportHeight() const {
4570 DCHECK(m_frame->isMainFrame()); 4580 DCHECK(m_frame->isMainFrame());
4571 return m_initialViewportSize.height(); 4581 return m_initialViewportSize.height();
4572 } 4582 }
4573 4583
4574 } // namespace blink 4584 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698