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

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 broken chromeos bot 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 1595 matching lines...) Expand 10 before | Expand all | Expand 10 after
2406 2455
2407 return ScrollableArea::shouldUseIntegerScrollOffset(); 2456 return ScrollableArea::shouldUseIntegerScrollOffset();
2408 } 2457 }
2409 2458
2410 bool FrameView::isActive() const { 2459 bool FrameView::isActive() const {
2411 Page* page = frame().page(); 2460 Page* page = frame().page();
2412 return page && page->focusController().isActive(); 2461 return page && page->focusController().isActive();
2413 } 2462 }
2414 2463
2415 void FrameView::invalidatePaintForTickmarks() { 2464 void FrameView::invalidatePaintForTickmarks() {
2416 if (Scrollbar* scrollbar = verticalScrollbar()) 2465 if (Scrollbar* scrollbar = getScrollableArea()->verticalScrollbar())
2417 scrollbar->setNeedsPaintInvalidation( 2466 scrollbar->setNeedsPaintInvalidation(
2418 static_cast<ScrollbarPart>(~ThumbPart)); 2467 static_cast<ScrollbarPart>(~ThumbPart));
2419 } 2468 }
2420 2469
2421 void FrameView::getTickmarks(Vector<IntRect>& tickmarks) const { 2470 void FrameView::getTickmarks(Vector<IntRect>& tickmarks) const {
2422 if (!m_tickmarks.isEmpty()) 2471 if (!m_tickmarks.isEmpty())
2423 tickmarks = m_tickmarks; 2472 tickmarks = m_tickmarks;
2424 else 2473 else
2425 tickmarks = frame().document()->markers().renderedRectsForMarkers( 2474 tickmarks = frame().document()->markers().renderedRectsForMarkers(
2426 DocumentMarker::TextMatch); 2475 DocumentMarker::TextMatch);
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
2574 2623
2575 if (m_frame->isMainFrame()) { 2624 if (m_frame->isMainFrame()) {
2576 ScrollableArea& visualViewport = frameHost->visualViewport(); 2625 ScrollableArea& visualViewport = frameHost->visualViewport();
2577 ScrollableArea* layoutViewport = layoutViewportScrollableArea(); 2626 ScrollableArea* layoutViewport = layoutViewportScrollableArea();
2578 DCHECK(layoutViewport); 2627 DCHECK(layoutViewport);
2579 2628
2580 RootFrameViewport* rootFrameViewport = 2629 RootFrameViewport* rootFrameViewport =
2581 RootFrameViewport::create(visualViewport, *layoutViewport); 2630 RootFrameViewport::create(visualViewport, *layoutViewport);
2582 m_viewportScrollableArea = rootFrameViewport; 2631 m_viewportScrollableArea = rootFrameViewport;
2583 2632
2633 // TODO(crbug.com/661236): Currently for the main frame, the scroller that
2634 // the scrollbar manager works with is RootFrameViewport which is needed so
2635 // that the visual viewport is taken into account when determining scrollbar
2636 // extent and existence. Eventually, each scroller should have its own
2637 // scrollbar manager and we shouldn't set the scroller here.
2638 m_scrollbarManager.setScroller(rootFrameViewport);
2639
2584 frameHost->globalRootScrollerController().initializeViewportScrollCallback( 2640 frameHost->globalRootScrollerController().initializeViewportScrollCallback(
2585 *rootFrameViewport); 2641 *rootFrameViewport);
2586 } 2642 }
2587 } 2643 }
2588 2644
2589 void FrameView::updateScrollCorner() { 2645 void FrameView::updateScrollCorner() {
2590 RefPtr<ComputedStyle> cornerStyle; 2646 RefPtr<ComputedStyle> cornerStyle;
2591 IntRect cornerRect = scrollCornerRect(); 2647 IntRect cornerRect = scrollCornerRect();
2592 Document* doc = m_frame->document(); 2648 Document* doc = m_frame->document();
2593 2649
(...skipping 1113 matching lines...) Expand 10 before | Expand all | Expand 10 after
3707 if (frame().isMainFrame()) 3763 if (frame().isMainFrame())
3708 frame().host()->chromeClient().mainFrameScrollOffsetChanged(); 3764 frame().host()->chromeClient().mainFrameScrollOffsetChanged();
3709 } 3765 }
3710 3766
3711 void FrameView::clearScrollAnchor() { 3767 void FrameView::clearScrollAnchor() {
3712 if (!RuntimeEnabledFeatures::scrollAnchoringEnabled()) 3768 if (!RuntimeEnabledFeatures::scrollAnchoringEnabled())
3713 return; 3769 return;
3714 m_scrollAnchor.clear(); 3770 m_scrollAnchor.clear();
3715 } 3771 }
3716 3772
3717 bool FrameView::hasOverlayScrollbars() const {
3718 return (horizontalScrollbar() &&
3719 horizontalScrollbar()->isOverlayScrollbar()) ||
3720 (verticalScrollbar() && verticalScrollbar()->isOverlayScrollbar());
3721 }
3722
3723 void FrameView::computeScrollbarExistence( 3773 void FrameView::computeScrollbarExistence(
3724 bool& newHasHorizontalScrollbar, 3774 bool& newHasHorizontalScrollbar,
3725 bool& newHasVerticalScrollbar, 3775 bool& newHasVerticalScrollbar,
3726 const IntSize& docSize, 3776 const IntSize& docSize,
3727 ComputeScrollbarExistenceOption option) const { 3777 ComputeScrollbarExistenceOption option) const {
3728 if (m_frame->settings() && m_frame->settings()->hideScrollbars()) { 3778 if (m_frame->settings() && m_frame->settings()->hideScrollbars()) {
3729 newHasHorizontalScrollbar = false; 3779 newHasHorizontalScrollbar = false;
3730 newHasVerticalScrollbar = false; 3780 newHasVerticalScrollbar = false;
3731 return; 3781 return;
3732 } 3782 }
(...skipping 12 matching lines...) Expand all
3745 3795
3746 if (hScroll != ScrollbarAuto) 3796 if (hScroll != ScrollbarAuto)
3747 newHasHorizontalScrollbar = (hScroll == ScrollbarAlwaysOn); 3797 newHasHorizontalScrollbar = (hScroll == ScrollbarAlwaysOn);
3748 if (vScroll != ScrollbarAuto) 3798 if (vScroll != ScrollbarAuto)
3749 newHasVerticalScrollbar = (vScroll == ScrollbarAlwaysOn); 3799 newHasVerticalScrollbar = (vScroll == ScrollbarAlwaysOn);
3750 3800
3751 if (m_scrollbarsSuppressed || 3801 if (m_scrollbarsSuppressed ||
3752 (hScroll != ScrollbarAuto && vScroll != ScrollbarAuto)) 3802 (hScroll != ScrollbarAuto && vScroll != ScrollbarAuto))
3753 return; 3803 return;
3754 3804
3805 ScrollableArea* scroller = m_scrollbarManager.scrollableArea();
3755 if (hScroll == ScrollbarAuto) 3806 if (hScroll == ScrollbarAuto)
3756 newHasHorizontalScrollbar = docSize.width() > visibleWidth(); 3807 newHasHorizontalScrollbar = docSize.width() > scroller->visibleWidth();
3757 if (vScroll == ScrollbarAuto) 3808 if (vScroll == ScrollbarAuto)
3758 newHasVerticalScrollbar = docSize.height() > visibleHeight(); 3809 newHasVerticalScrollbar = docSize.height() > scroller->visibleHeight();
3759 3810
3760 if (hasOverlayScrollbars()) 3811 if (hasOverlayScrollbars())
3761 return; 3812 return;
3762 3813
3763 IntSize fullVisibleSize = visibleContentRect(IncludeScrollbars).size(); 3814 IntSize fullVisibleSize =
3815 scroller->visibleContentRect(IncludeScrollbars).size();
3764 3816
3765 bool attemptToRemoveScrollbars = 3817 bool attemptToRemoveScrollbars =
3766 (option == FirstPass && docSize.width() <= fullVisibleSize.width() && 3818 (option == FirstPass && docSize.width() <= fullVisibleSize.width() &&
3767 docSize.height() <= fullVisibleSize.height()); 3819 docSize.height() <= fullVisibleSize.height());
3768 if (attemptToRemoveScrollbars) { 3820 if (attemptToRemoveScrollbars) {
3769 if (hScroll == ScrollbarAuto) 3821 if (hScroll == ScrollbarAuto)
3770 newHasHorizontalScrollbar = false; 3822 newHasHorizontalScrollbar = false;
3771 if (vScroll == ScrollbarAuto) 3823 if (vScroll == ScrollbarAuto)
3772 newHasVerticalScrollbar = false; 3824 newHasVerticalScrollbar = false;
3773 } 3825 }
3774 } 3826 }
3775 3827
3776 void FrameView::updateScrollbarGeometry() {
3777 if (horizontalScrollbar()) {
3778 int thickness = horizontalScrollbar()->scrollbarThickness();
3779 int clientWidth = visibleWidth();
3780 IntRect oldRect(horizontalScrollbar()->frameRect());
3781 IntRect hBarRect(
3782 (shouldPlaceVerticalScrollbarOnLeft() && verticalScrollbar())
3783 ? verticalScrollbar()->width()
3784 : 0,
3785 height() - thickness,
3786 width() - (verticalScrollbar() ? verticalScrollbar()->width() : 0),
3787 thickness);
3788 horizontalScrollbar()->setFrameRect(hBarRect);
3789 if (oldRect != horizontalScrollbar()->frameRect())
3790 setScrollbarNeedsPaintInvalidation(HorizontalScrollbar);
3791
3792 horizontalScrollbar()->setEnabled(contentsWidth() > clientWidth);
3793 horizontalScrollbar()->setProportion(clientWidth, contentsWidth());
3794 horizontalScrollbar()->offsetDidChange();
3795 }
3796
3797 if (verticalScrollbar()) {
3798 int thickness = verticalScrollbar()->scrollbarThickness();
3799 int clientHeight = visibleHeight();
3800 IntRect oldRect(verticalScrollbar()->frameRect());
3801 IntRect vBarRect(
3802 shouldPlaceVerticalScrollbarOnLeft() ? 0 : (width() - thickness), 0,
3803 thickness,
3804 height() -
3805 (horizontalScrollbar() ? horizontalScrollbar()->height() : 0));
3806 verticalScrollbar()->setFrameRect(vBarRect);
3807 if (oldRect != verticalScrollbar()->frameRect())
3808 setScrollbarNeedsPaintInvalidation(VerticalScrollbar);
3809
3810 verticalScrollbar()->setEnabled(contentsHeight() > clientHeight);
3811 verticalScrollbar()->setProportion(clientHeight, contentsHeight());
3812 verticalScrollbar()->offsetDidChange();
3813 }
3814 }
3815
3816 bool FrameView::adjustScrollbarExistence( 3828 bool FrameView::adjustScrollbarExistence(
3817 ComputeScrollbarExistenceOption option) { 3829 ComputeScrollbarExistenceOption option) {
3818 ASSERT(m_inUpdateScrollbars); 3830 ASSERT(m_inUpdateScrollbars);
3819 3831
3820 // If we came in here with the view already needing a layout, then go ahead 3832 // If we came in here with the view already needing a layout, then go ahead
3821 // and do that first. (This will be the common case, e.g., when the page 3833 // and do that first. (This will be the common case, e.g., when the page
3822 // changes due to window resizing for example). This layout will not re-enter 3834 // changes due to window resizing for example). This layout will not re-enter
3823 // updateScrollbars and does not count towards our max layout pass total. 3835 // updateScrollbars and does not count towards our max layout pass total.
3824 if (!m_scrollbarsSuppressed) 3836 if (!m_scrollbarsSuppressed)
3825 scrollbarExistenceDidChange(); 3837 scrollbarExistenceDidChange();
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
3904 int maxUpdateScrollbarsPass = 3916 int maxUpdateScrollbarsPass =
3905 hasOverlayScrollbars() || m_scrollbarsSuppressed ? 1 : 3; 3917 hasOverlayScrollbars() || m_scrollbarsSuppressed ? 1 : 3;
3906 for (int updateScrollbarsPass = 0; 3918 for (int updateScrollbarsPass = 0;
3907 updateScrollbarsPass < maxUpdateScrollbarsPass; updateScrollbarsPass++) { 3919 updateScrollbarsPass < maxUpdateScrollbarsPass; updateScrollbarsPass++) {
3908 if (!adjustScrollbarExistence(updateScrollbarsPass ? Incremental 3920 if (!adjustScrollbarExistence(updateScrollbarsPass ? Incremental
3909 : FirstPass)) 3921 : FirstPass))
3910 break; 3922 break;
3911 scrollbarExistenceChanged = true; 3923 scrollbarExistenceChanged = true;
3912 } 3924 }
3913 3925
3914 updateScrollbarGeometry(); 3926 m_scrollbarManager.updateScrollbarGeometry(size());
3915 3927
3916 if (scrollbarExistenceChanged) { 3928 if (scrollbarExistenceChanged) {
3917 // FIXME: Is frameRectsChanged really necessary here? Have any frame rects 3929 // FIXME: Is frameRectsChanged really necessary here? Have any frame rects
3918 // changed? 3930 // changed?
3919 frameRectsChanged(); 3931 frameRectsChanged();
3920 positionScrollbarLayers(); 3932 positionScrollbarLayers();
3921 updateScrollCorner(); 3933 updateScrollCorner();
3922 } 3934 }
3923 3935
3924 adjustScrollOffsetFromUpdateScrollbars(); 3936 adjustScrollOffsetFromUpdateScrollbars();
(...skipping 637 matching lines...) Expand 10 before | Expand all | Expand 10 after
4562 DCHECK(m_frame->isMainFrame()); 4574 DCHECK(m_frame->isMainFrame());
4563 return m_initialViewportSize.width(); 4575 return m_initialViewportSize.width();
4564 } 4576 }
4565 4577
4566 int FrameView::initialViewportHeight() const { 4578 int FrameView::initialViewportHeight() const {
4567 DCHECK(m_frame->isMainFrame()); 4579 DCHECK(m_frame->isMainFrame());
4568 return m_initialViewportSize.height(); 4580 return m_initialViewportSize.height();
4569 } 4581 }
4570 4582
4571 } // namespace blink 4583 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/frame/FrameView.h ('k') | third_party/WebKit/Source/core/frame/RootFrameViewport.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698