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

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

Issue 2501493002: Revert "MainFrame scrollbars should work with RFV instead of FV" (Closed)
Patch Set: 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 422 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 if (!scrollbar) 433 if (!scrollbar)
434 return; 434 return;
435 435
436 m_scrollableArea->willRemoveScrollbar(*scrollbar, orientation); 436 m_scrollableArea->willRemoveScrollbar(*scrollbar, orientation);
437 m_scrollableArea->layoutBox()->document().view()->removeChild( 437 m_scrollableArea->layoutBox()->document().view()->removeChild(
438 scrollbar.get()); 438 scrollbar.get());
439 scrollbar->disconnectFromScrollableArea(); 439 scrollbar->disconnectFromScrollableArea();
440 scrollbar = nullptr; 440 scrollbar = nullptr;
441 } 441 }
442 442
443 ScrollableArea* FrameView::ScrollbarManager::scrollableArea() const {
444 return m_scrollableArea.get();
445 }
446
447 void FrameView::ScrollbarManager::updateScrollbarGeometry(IntSize viewSize) {
448 if (!hasHorizontalScrollbar() && !hasVerticalScrollbar())
449 return;
450
451 bool scrollbarOnLeft = m_scrollableArea->shouldPlaceVerticalScrollbarOnLeft();
452
453 if (hasHorizontalScrollbar()) {
454 int thickness = m_hBar->scrollbarThickness();
455 IntRect oldRect(m_hBar->frameRect());
456 IntRect hBarRect(
457 (scrollbarOnLeft && hasVerticalScrollbar()) ? m_vBar->width() : 0,
458 viewSize.height() - thickness,
459 viewSize.width() - (hasVerticalScrollbar() ? m_vBar->width() : 0),
460 thickness);
461 m_hBar->setFrameRect(hBarRect);
462 if (oldRect != m_hBar->frameRect())
463 m_scrollableArea->setScrollbarNeedsPaintInvalidation(HorizontalScrollbar);
464
465 int visibleWidth = m_scrollableArea->visibleWidth();
466 int contentsWidth = m_scrollableArea->contentsSize().width();
467 m_hBar->setEnabled(contentsWidth > visibleWidth &&
468 !m_scrollableArea->scrollbarsHidden());
469 m_hBar->setProportion(visibleWidth, contentsWidth);
470 m_hBar->offsetDidChange();
471 }
472
473 if (hasVerticalScrollbar()) {
474 int thickness = m_vBar->scrollbarThickness();
475 IntRect oldRect(m_vBar->frameRect());
476 IntRect vBarRect(
477 scrollbarOnLeft ? 0 : (viewSize.width() - thickness), 0, thickness,
478 viewSize.height() - (hasHorizontalScrollbar() ? m_hBar->height() : 0));
479 m_vBar->setFrameRect(vBarRect);
480 if (oldRect != m_vBar->frameRect())
481 m_scrollableArea->setScrollbarNeedsPaintInvalidation(VerticalScrollbar);
482
483 int clientHeight = m_scrollableArea->visibleHeight();
484 int contentsHeight = m_scrollableArea->contentsSize().height();
485 m_vBar->setEnabled(contentsHeight > clientHeight &&
486 !m_scrollableArea->scrollbarsHidden());
487 m_vBar->setProportion(clientHeight, contentsHeight);
488 m_vBar->offsetDidChange();
489 }
490 }
491
492 void FrameView::recalculateCustomScrollbarStyle() { 443 void FrameView::recalculateCustomScrollbarStyle() {
493 bool didStyleChange = false; 444 bool didStyleChange = false;
494 if (horizontalScrollbar() && horizontalScrollbar()->isCustomScrollbar()) { 445 if (horizontalScrollbar() && horizontalScrollbar()->isCustomScrollbar()) {
495 horizontalScrollbar()->styleChanged(); 446 horizontalScrollbar()->styleChanged();
496 didStyleChange = true; 447 didStyleChange = true;
497 } 448 }
498 if (verticalScrollbar() && verticalScrollbar()->isCustomScrollbar()) { 449 if (verticalScrollbar() && verticalScrollbar()->isCustomScrollbar()) {
499 verticalScrollbar()->styleChanged(); 450 verticalScrollbar()->styleChanged();
500 didStyleChange = true; 451 didStyleChange = true;
501 } 452 }
502 if (didStyleChange) { 453 if (didStyleChange) {
503 m_scrollbarManager.updateScrollbarGeometry(size()); 454 updateScrollbarGeometry();
504 updateScrollCorner(); 455 updateScrollCorner();
505 positionScrollbarLayers(); 456 positionScrollbarLayers();
506 } 457 }
507 } 458 }
508 459
509 void FrameView::invalidateAllCustomScrollbarsOnActiveChanged() { 460 void FrameView::invalidateAllCustomScrollbarsOnActiveChanged() {
510 bool usesWindowInactiveSelector = 461 bool usesWindowInactiveSelector =
511 m_frame->document()->styleEngine().usesWindowInactiveSelector(); 462 m_frame->document()->styleEngine().usesWindowInactiveSelector();
512 463
513 const ChildrenWidgetSet* viewChildren = children(); 464 const ChildrenWidgetSet* viewChildren = children();
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
846 797
847 bool hasHorizontalScrollbar = horizontalScrollbar(); 798 bool hasHorizontalScrollbar = horizontalScrollbar();
848 bool hasVerticalScrollbar = verticalScrollbar(); 799 bool hasVerticalScrollbar = verticalScrollbar();
849 if (hasHorizontalScrollbar != shouldHaveHorizontalScrollbar || 800 if (hasHorizontalScrollbar != shouldHaveHorizontalScrollbar ||
850 hasVerticalScrollbar != shouldHaveVerticalScrollbar) { 801 hasVerticalScrollbar != shouldHaveVerticalScrollbar) {
851 setNeedsLayout(); 802 setNeedsLayout();
852 return; 803 return;
853 } 804 }
854 805
855 adjustViewSize(); 806 adjustViewSize();
856 m_scrollbarManager.updateScrollbarGeometry(size()); 807 updateScrollbarGeometry();
857 808
858 if (scrollOriginChanged()) 809 if (scrollOriginChanged())
859 setNeedsLayout(); 810 setNeedsLayout();
860 } 811 }
861 812
862 bool FrameView::usesCompositedScrolling() const { 813 bool FrameView::usesCompositedScrolling() const {
863 LayoutViewItem layoutView = this->layoutViewItem(); 814 LayoutViewItem layoutView = this->layoutViewItem();
864 if (layoutView.isNull()) 815 if (layoutView.isNull())
865 return false; 816 return false;
866 if (m_frame->settings() && 817 if (m_frame->settings() &&
(...skipping 1595 matching lines...) Expand 10 before | Expand all | Expand 10 after
2462 2413
2463 return ScrollableArea::shouldUseIntegerScrollOffset(); 2414 return ScrollableArea::shouldUseIntegerScrollOffset();
2464 } 2415 }
2465 2416
2466 bool FrameView::isActive() const { 2417 bool FrameView::isActive() const {
2467 Page* page = frame().page(); 2418 Page* page = frame().page();
2468 return page && page->focusController().isActive(); 2419 return page && page->focusController().isActive();
2469 } 2420 }
2470 2421
2471 void FrameView::invalidatePaintForTickmarks() { 2422 void FrameView::invalidatePaintForTickmarks() {
2472 if (Scrollbar* scrollbar = getScrollableArea()->verticalScrollbar()) 2423 if (Scrollbar* scrollbar = verticalScrollbar())
2473 scrollbar->setNeedsPaintInvalidation( 2424 scrollbar->setNeedsPaintInvalidation(
2474 static_cast<ScrollbarPart>(~ThumbPart)); 2425 static_cast<ScrollbarPart>(~ThumbPart));
2475 } 2426 }
2476 2427
2477 void FrameView::getTickmarks(Vector<IntRect>& tickmarks) const { 2428 void FrameView::getTickmarks(Vector<IntRect>& tickmarks) const {
2478 if (!m_tickmarks.isEmpty()) 2429 if (!m_tickmarks.isEmpty())
2479 tickmarks = m_tickmarks; 2430 tickmarks = m_tickmarks;
2480 else 2431 else
2481 tickmarks = frame().document()->markers().renderedRectsForMarkers( 2432 tickmarks = frame().document()->markers().renderedRectsForMarkers(
2482 DocumentMarker::TextMatch); 2433 DocumentMarker::TextMatch);
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
2630 2581
2631 if (m_frame->isMainFrame()) { 2582 if (m_frame->isMainFrame()) {
2632 ScrollableArea& visualViewport = frameHost->visualViewport(); 2583 ScrollableArea& visualViewport = frameHost->visualViewport();
2633 ScrollableArea* layoutViewport = layoutViewportScrollableArea(); 2584 ScrollableArea* layoutViewport = layoutViewportScrollableArea();
2634 DCHECK(layoutViewport); 2585 DCHECK(layoutViewport);
2635 2586
2636 RootFrameViewport* rootFrameViewport = 2587 RootFrameViewport* rootFrameViewport =
2637 RootFrameViewport::create(visualViewport, *layoutViewport); 2588 RootFrameViewport::create(visualViewport, *layoutViewport);
2638 m_viewportScrollableArea = rootFrameViewport; 2589 m_viewportScrollableArea = rootFrameViewport;
2639 2590
2640 // TODO(crbug.com/661236): Currently for the main frame, the scroller that
2641 // the scrollbar manager works with is RootFrameViewport which is needed so
2642 // that the visual viewport is taken into account when determining scrollbar
2643 // extent and existence. Eventually, each scroller should have its own
2644 // scrollbar manager and we shouldn't set the scroller here.
2645 m_scrollbarManager.setScroller(rootFrameViewport);
2646
2647 frameHost->globalRootScrollerController().initializeViewportScrollCallback( 2591 frameHost->globalRootScrollerController().initializeViewportScrollCallback(
2648 *rootFrameViewport); 2592 *rootFrameViewport);
2649 } 2593 }
2650 } 2594 }
2651 2595
2652 void FrameView::updateScrollCorner() { 2596 void FrameView::updateScrollCorner() {
2653 RefPtr<ComputedStyle> cornerStyle; 2597 RefPtr<ComputedStyle> cornerStyle;
2654 IntRect cornerRect = scrollCornerRect(); 2598 IntRect cornerRect = scrollCornerRect();
2655 Document* doc = m_frame->document(); 2599 Document* doc = m_frame->document();
2656 2600
(...skipping 1118 matching lines...) Expand 10 before | Expand all | Expand 10 after
3775 setNeedsPaintPropertyUpdate(); 3719 setNeedsPaintPropertyUpdate();
3776 } 3720 }
3777 } 3721 }
3778 3722
3779 void FrameView::clearScrollAnchor() { 3723 void FrameView::clearScrollAnchor() {
3780 if (!RuntimeEnabledFeatures::scrollAnchoringEnabled()) 3724 if (!RuntimeEnabledFeatures::scrollAnchoringEnabled())
3781 return; 3725 return;
3782 m_scrollAnchor.clear(); 3726 m_scrollAnchor.clear();
3783 } 3727 }
3784 3728
3729 bool FrameView::hasOverlayScrollbars() const {
3730 return (horizontalScrollbar() &&
3731 horizontalScrollbar()->isOverlayScrollbar()) ||
3732 (verticalScrollbar() && verticalScrollbar()->isOverlayScrollbar());
3733 }
3734
3785 void FrameView::computeScrollbarExistence( 3735 void FrameView::computeScrollbarExistence(
3786 bool& newHasHorizontalScrollbar, 3736 bool& newHasHorizontalScrollbar,
3787 bool& newHasVerticalScrollbar, 3737 bool& newHasVerticalScrollbar,
3788 const IntSize& docSize, 3738 const IntSize& docSize,
3789 ComputeScrollbarExistenceOption option) const { 3739 ComputeScrollbarExistenceOption option) const {
3790 if (m_frame->settings() && m_frame->settings()->hideScrollbars()) { 3740 if (m_frame->settings() && m_frame->settings()->hideScrollbars()) {
3791 newHasHorizontalScrollbar = false; 3741 newHasHorizontalScrollbar = false;
3792 newHasVerticalScrollbar = false; 3742 newHasVerticalScrollbar = false;
3793 return; 3743 return;
3794 } 3744 }
(...skipping 12 matching lines...) Expand all
3807 3757
3808 if (hScroll != ScrollbarAuto) 3758 if (hScroll != ScrollbarAuto)
3809 newHasHorizontalScrollbar = (hScroll == ScrollbarAlwaysOn); 3759 newHasHorizontalScrollbar = (hScroll == ScrollbarAlwaysOn);
3810 if (vScroll != ScrollbarAuto) 3760 if (vScroll != ScrollbarAuto)
3811 newHasVerticalScrollbar = (vScroll == ScrollbarAlwaysOn); 3761 newHasVerticalScrollbar = (vScroll == ScrollbarAlwaysOn);
3812 3762
3813 if (m_scrollbarsSuppressed || 3763 if (m_scrollbarsSuppressed ||
3814 (hScroll != ScrollbarAuto && vScroll != ScrollbarAuto)) 3764 (hScroll != ScrollbarAuto && vScroll != ScrollbarAuto))
3815 return; 3765 return;
3816 3766
3817 ScrollableArea* scroller = m_scrollbarManager.scrollableArea();
3818 if (hScroll == ScrollbarAuto) 3767 if (hScroll == ScrollbarAuto)
3819 newHasHorizontalScrollbar = docSize.width() > scroller->visibleWidth(); 3768 newHasHorizontalScrollbar = docSize.width() > visibleWidth();
3820 if (vScroll == ScrollbarAuto) 3769 if (vScroll == ScrollbarAuto)
3821 newHasVerticalScrollbar = docSize.height() > scroller->visibleHeight(); 3770 newHasVerticalScrollbar = docSize.height() > visibleHeight();
3822 3771
3823 if (hasOverlayScrollbars()) 3772 if (hasOverlayScrollbars())
3824 return; 3773 return;
3825 3774
3826 IntSize fullVisibleSize = 3775 IntSize fullVisibleSize = visibleContentRect(IncludeScrollbars).size();
3827 scroller->visibleContentRect(IncludeScrollbars).size();
3828 3776
3829 bool attemptToRemoveScrollbars = 3777 bool attemptToRemoveScrollbars =
3830 (option == FirstPass && docSize.width() <= fullVisibleSize.width() && 3778 (option == FirstPass && docSize.width() <= fullVisibleSize.width() &&
3831 docSize.height() <= fullVisibleSize.height()); 3779 docSize.height() <= fullVisibleSize.height());
3832 if (attemptToRemoveScrollbars) { 3780 if (attemptToRemoveScrollbars) {
3833 if (hScroll == ScrollbarAuto) 3781 if (hScroll == ScrollbarAuto)
3834 newHasHorizontalScrollbar = false; 3782 newHasHorizontalScrollbar = false;
3835 if (vScroll == ScrollbarAuto) 3783 if (vScroll == ScrollbarAuto)
3836 newHasVerticalScrollbar = false; 3784 newHasVerticalScrollbar = false;
3837 } 3785 }
3838 } 3786 }
3839 3787
3788 void FrameView::updateScrollbarGeometry() {
3789 if (horizontalScrollbar()) {
3790 int thickness = horizontalScrollbar()->scrollbarThickness();
3791 int clientWidth = visibleWidth();
3792 IntRect oldRect(horizontalScrollbar()->frameRect());
3793 IntRect hBarRect(
3794 (shouldPlaceVerticalScrollbarOnLeft() && verticalScrollbar())
3795 ? verticalScrollbar()->width()
3796 : 0,
3797 height() - thickness,
3798 width() - (verticalScrollbar() ? verticalScrollbar()->width() : 0),
3799 thickness);
3800 horizontalScrollbar()->setFrameRect(hBarRect);
3801 if (oldRect != horizontalScrollbar()->frameRect())
3802 setScrollbarNeedsPaintInvalidation(HorizontalScrollbar);
3803
3804 horizontalScrollbar()->setEnabled(contentsWidth() > clientWidth);
3805 horizontalScrollbar()->setProportion(clientWidth, contentsWidth());
3806 horizontalScrollbar()->offsetDidChange();
3807 }
3808
3809 if (verticalScrollbar()) {
3810 int thickness = verticalScrollbar()->scrollbarThickness();
3811 int clientHeight = visibleHeight();
3812 IntRect oldRect(verticalScrollbar()->frameRect());
3813 IntRect vBarRect(
3814 shouldPlaceVerticalScrollbarOnLeft() ? 0 : (width() - thickness), 0,
3815 thickness,
3816 height() -
3817 (horizontalScrollbar() ? horizontalScrollbar()->height() : 0));
3818 verticalScrollbar()->setFrameRect(vBarRect);
3819 if (oldRect != verticalScrollbar()->frameRect())
3820 setScrollbarNeedsPaintInvalidation(VerticalScrollbar);
3821
3822 verticalScrollbar()->setEnabled(contentsHeight() > clientHeight);
3823 verticalScrollbar()->setProportion(clientHeight, contentsHeight());
3824 verticalScrollbar()->offsetDidChange();
3825 }
3826 }
3827
3840 bool FrameView::adjustScrollbarExistence( 3828 bool FrameView::adjustScrollbarExistence(
3841 ComputeScrollbarExistenceOption option) { 3829 ComputeScrollbarExistenceOption option) {
3842 ASSERT(m_inUpdateScrollbars); 3830 ASSERT(m_inUpdateScrollbars);
3843 3831
3844 // 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
3845 // 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
3846 // 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
3847 // updateScrollbars and does not count towards our max layout pass total. 3835 // updateScrollbars and does not count towards our max layout pass total.
3848 if (!m_scrollbarsSuppressed) 3836 if (!m_scrollbarsSuppressed)
3849 scrollbarExistenceDidChange(); 3837 scrollbarExistenceDidChange();
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
3928 int maxUpdateScrollbarsPass = 3916 int maxUpdateScrollbarsPass =
3929 hasOverlayScrollbars() || m_scrollbarsSuppressed ? 1 : 3; 3917 hasOverlayScrollbars() || m_scrollbarsSuppressed ? 1 : 3;
3930 for (int updateScrollbarsPass = 0; 3918 for (int updateScrollbarsPass = 0;
3931 updateScrollbarsPass < maxUpdateScrollbarsPass; updateScrollbarsPass++) { 3919 updateScrollbarsPass < maxUpdateScrollbarsPass; updateScrollbarsPass++) {
3932 if (!adjustScrollbarExistence(updateScrollbarsPass ? Incremental 3920 if (!adjustScrollbarExistence(updateScrollbarsPass ? Incremental
3933 : FirstPass)) 3921 : FirstPass))
3934 break; 3922 break;
3935 scrollbarExistenceChanged = true; 3923 scrollbarExistenceChanged = true;
3936 } 3924 }
3937 3925
3938 m_scrollbarManager.updateScrollbarGeometry(size()); 3926 updateScrollbarGeometry();
3939 3927
3940 if (scrollbarExistenceChanged) { 3928 if (scrollbarExistenceChanged) {
3941 // FIXME: Is frameRectsChanged really necessary here? Have any frame rects 3929 // FIXME: Is frameRectsChanged really necessary here? Have any frame rects
3942 // changed? 3930 // changed?
3943 frameRectsChanged(); 3931 frameRectsChanged();
3944 positionScrollbarLayers(); 3932 positionScrollbarLayers();
3945 updateScrollCorner(); 3933 updateScrollCorner();
3946 } 3934 }
3947 3935
3948 adjustScrollOffsetFromUpdateScrollbars(); 3936 adjustScrollOffsetFromUpdateScrollbars();
(...skipping 637 matching lines...) Expand 10 before | Expand all | Expand 10 after
4586 DCHECK(m_frame->isMainFrame()); 4574 DCHECK(m_frame->isMainFrame());
4587 return m_initialViewportSize.width(); 4575 return m_initialViewportSize.width();
4588 } 4576 }
4589 4577
4590 int FrameView::initialViewportHeight() const { 4578 int FrameView::initialViewportHeight() const {
4591 DCHECK(m_frame->isMainFrame()); 4579 DCHECK(m_frame->isMainFrame());
4592 return m_initialViewportSize.height(); 4580 return m_initialViewportSize.height();
4593 } 4581 }
4594 4582
4595 } // 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