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

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 VisualViewportTest 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 412 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 if (!scrollbar) 423 if (!scrollbar)
424 return; 424 return;
425 425
426 m_scrollableArea->willRemoveScrollbar(*scrollbar, orientation); 426 m_scrollableArea->willRemoveScrollbar(*scrollbar, orientation);
427 m_scrollableArea->layoutBox()->document().view()->removeChild( 427 m_scrollableArea->layoutBox()->document().view()->removeChild(
428 scrollbar.get()); 428 scrollbar.get());
429 scrollbar->disconnectFromScrollableArea(); 429 scrollbar->disconnectFromScrollableArea();
430 scrollbar = nullptr; 430 scrollbar = nullptr;
431 } 431 }
432 432
433 ScrollableArea* FrameView::ScrollbarManager::scrollableArea() const {
434 return m_scrollableArea.get();
435 }
436
437 void FrameView::ScrollbarManager::updateScrollbarGeometry(IntSize viewSize) {
438 if (!hasHorizontalScrollbar() && !hasVerticalScrollbar())
439 return;
440
441 bool scrollbarOnLeft = m_scrollableArea->shouldPlaceVerticalScrollbarOnLeft();
442
443 if (hasHorizontalScrollbar()) {
444 int thickness = m_hBar->scrollbarThickness();
445 IntRect oldRect(m_hBar->frameRect());
446 IntRect hBarRect(
447 (scrollbarOnLeft && hasVerticalScrollbar()) ? m_vBar->width() : 0,
448 viewSize.height() - thickness,
449 viewSize.width() - (hasVerticalScrollbar() ? m_vBar->width() : 0),
450 thickness);
451 m_hBar->setFrameRect(hBarRect);
452 if (oldRect != m_hBar->frameRect())
453 m_scrollableArea->setScrollbarNeedsPaintInvalidation(HorizontalScrollbar);
454
455 int visibleWidth = m_scrollableArea->visibleWidth();
456 int contentsWidth = m_scrollableArea->contentsSize().width();
457 m_hBar->setEnabled(contentsWidth > visibleWidth);
458 m_hBar->setProportion(visibleWidth, contentsWidth);
459 m_hBar->offsetDidChange();
460 }
461
462 if (hasVerticalScrollbar()) {
463 int thickness = m_vBar->scrollbarThickness();
464 IntRect oldRect(m_vBar->frameRect());
465 IntRect vBarRect(
466 scrollbarOnLeft ? 0 : (viewSize.width() - thickness), 0, thickness,
467 viewSize.height() - (hasHorizontalScrollbar() ? m_hBar->height() : 0));
468 m_vBar->setFrameRect(vBarRect);
469 if (oldRect != m_vBar->frameRect())
470 m_scrollableArea->setScrollbarNeedsPaintInvalidation(VerticalScrollbar);
471
472 int clientHeight = m_scrollableArea->visibleHeight();
473 int contentsHeight = m_scrollableArea->contentsSize().height();
474 m_vBar->setEnabled(contentsHeight > clientHeight);
475 m_vBar->setProportion(clientHeight, contentsHeight);
476 m_vBar->offsetDidChange();
477 }
478 }
479
433 void FrameView::recalculateCustomScrollbarStyle() { 480 void FrameView::recalculateCustomScrollbarStyle() {
434 bool didStyleChange = false; 481 bool didStyleChange = false;
435 if (horizontalScrollbar() && horizontalScrollbar()->isCustomScrollbar()) { 482 if (horizontalScrollbar() && horizontalScrollbar()->isCustomScrollbar()) {
436 horizontalScrollbar()->styleChanged(); 483 horizontalScrollbar()->styleChanged();
437 didStyleChange = true; 484 didStyleChange = true;
438 } 485 }
439 if (verticalScrollbar() && verticalScrollbar()->isCustomScrollbar()) { 486 if (verticalScrollbar() && verticalScrollbar()->isCustomScrollbar()) {
440 verticalScrollbar()->styleChanged(); 487 verticalScrollbar()->styleChanged();
441 didStyleChange = true; 488 didStyleChange = true;
442 } 489 }
443 if (didStyleChange) { 490 if (didStyleChange) {
444 updateScrollbarGeometry(); 491 m_scrollbarManager.updateScrollbarGeometry(size());
445 updateScrollCorner(); 492 updateScrollCorner();
446 positionScrollbarLayers(); 493 positionScrollbarLayers();
447 } 494 }
448 } 495 }
449 496
450 void FrameView::invalidateAllCustomScrollbarsOnActiveChanged() { 497 void FrameView::invalidateAllCustomScrollbarsOnActiveChanged() {
451 bool usesWindowInactiveSelector = 498 bool usesWindowInactiveSelector =
452 m_frame->document()->styleEngine().usesWindowInactiveSelector(); 499 m_frame->document()->styleEngine().usesWindowInactiveSelector();
453 500
454 const ChildrenWidgetSet* viewChildren = children(); 501 const ChildrenWidgetSet* viewChildren = children();
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
781 828
782 bool hasHorizontalScrollbar = horizontalScrollbar(); 829 bool hasHorizontalScrollbar = horizontalScrollbar();
783 bool hasVerticalScrollbar = verticalScrollbar(); 830 bool hasVerticalScrollbar = verticalScrollbar();
784 if (hasHorizontalScrollbar != shouldHaveHorizontalScrollbar || 831 if (hasHorizontalScrollbar != shouldHaveHorizontalScrollbar ||
785 hasVerticalScrollbar != shouldHaveVerticalScrollbar) { 832 hasVerticalScrollbar != shouldHaveVerticalScrollbar) {
786 setNeedsLayout(); 833 setNeedsLayout();
787 return; 834 return;
788 } 835 }
789 836
790 adjustViewSize(); 837 adjustViewSize();
791 updateScrollbarGeometry(); 838 m_scrollbarManager.updateScrollbarGeometry(size());
792 839
793 if (scrollOriginChanged()) 840 if (scrollOriginChanged())
794 setNeedsLayout(); 841 setNeedsLayout();
795 } 842 }
796 843
797 bool FrameView::usesCompositedScrolling() const { 844 bool FrameView::usesCompositedScrolling() const {
798 LayoutViewItem layoutView = this->layoutViewItem(); 845 LayoutViewItem layoutView = this->layoutViewItem();
799 if (layoutView.isNull()) 846 if (layoutView.isNull())
800 return false; 847 return false;
801 if (m_frame->settings() && 848 if (m_frame->settings() &&
(...skipping 1581 matching lines...) Expand 10 before | Expand all | Expand 10 after
2383 Page* page = frame().page(); 2430 Page* page = frame().page();
2384 return page && page->focusController().isActive(); 2431 return page && page->focusController().isActive();
2385 } 2432 }
2386 2433
2387 void FrameView::invalidatePaintForTickmarks() { 2434 void FrameView::invalidatePaintForTickmarks() {
2388 if (Scrollbar* scrollbar = verticalScrollbar()) 2435 if (Scrollbar* scrollbar = verticalScrollbar())
2389 scrollbar->setNeedsPaintInvalidation( 2436 scrollbar->setNeedsPaintInvalidation(
2390 static_cast<ScrollbarPart>(~ThumbPart)); 2437 static_cast<ScrollbarPart>(~ThumbPart));
2391 } 2438 }
2392 2439
2440 void FrameView::setTickmarks(const Vector<IntRect>& tickmarks) {
2441 // Tickmarks for main frame are stored in RFV.
2442 if (m_frame->isMainFrame())
bokan 2016/11/03 19:59:59 You'll need a similar check in getTickmarks.
ymalik 2016/11/04 18:54:17 So RFV::getTickmarks calls layoutViewport().getTic
2443 m_viewportScrollableArea->setTickmarks(tickmarks);
2444 else
2445 m_tickmarks = tickmarks;
2446
2447 invalidatePaintForTickmarks();
2448 }
2449
2393 void FrameView::getTickmarks(Vector<IntRect>& tickmarks) const { 2450 void FrameView::getTickmarks(Vector<IntRect>& tickmarks) const {
2394 if (!m_tickmarks.isEmpty()) 2451 if (!m_tickmarks.isEmpty())
2395 tickmarks = m_tickmarks; 2452 tickmarks = m_tickmarks;
2396 else 2453 else
2397 tickmarks = frame().document()->markers().renderedRectsForMarkers( 2454 tickmarks = frame().document()->markers().renderedRectsForMarkers(
2398 DocumentMarker::TextMatch); 2455 DocumentMarker::TextMatch);
2399 } 2456 }
2400 2457
2401 void FrameView::setInputEventsTransformForEmulation(const IntSize& offset, 2458 void FrameView::setInputEventsTransformForEmulation(const IntSize& offset,
2402 float contentScaleFactor) { 2459 float contentScaleFactor) {
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
2546 2603
2547 if (m_frame->isMainFrame()) { 2604 if (m_frame->isMainFrame()) {
2548 ScrollableArea& visualViewport = frameHost->visualViewport(); 2605 ScrollableArea& visualViewport = frameHost->visualViewport();
2549 ScrollableArea* layoutViewport = layoutViewportScrollableArea(); 2606 ScrollableArea* layoutViewport = layoutViewportScrollableArea();
2550 DCHECK(layoutViewport); 2607 DCHECK(layoutViewport);
2551 2608
2552 RootFrameViewport* rootFrameViewport = 2609 RootFrameViewport* rootFrameViewport =
2553 RootFrameViewport::create(visualViewport, *layoutViewport); 2610 RootFrameViewport::create(visualViewport, *layoutViewport);
2554 m_viewportScrollableArea = rootFrameViewport; 2611 m_viewportScrollableArea = rootFrameViewport;
2555 2612
2613 m_scrollbarManager.setScroller(rootFrameViewport);
2614
2556 frameHost->globalRootScrollerController().initializeViewportScrollCallback( 2615 frameHost->globalRootScrollerController().initializeViewportScrollCallback(
2557 *rootFrameViewport); 2616 *rootFrameViewport);
2558 } 2617 }
2559 } 2618 }
2560 2619
2561 void FrameView::updateScrollCorner() { 2620 void FrameView::updateScrollCorner() {
2562 RefPtr<ComputedStyle> cornerStyle; 2621 RefPtr<ComputedStyle> cornerStyle;
2563 IntRect cornerRect = scrollCornerRect(); 2622 IntRect cornerRect = scrollCornerRect();
2564 Document* doc = m_frame->document(); 2623 Document* doc = m_frame->document();
2565 2624
(...skipping 1124 matching lines...) Expand 10 before | Expand all | Expand 10 after
3690 if (frame().isMainFrame()) 3749 if (frame().isMainFrame())
3691 frame().host()->chromeClient().mainFrameScrollOffsetChanged(); 3750 frame().host()->chromeClient().mainFrameScrollOffsetChanged();
3692 } 3751 }
3693 3752
3694 void FrameView::clearScrollAnchor() { 3753 void FrameView::clearScrollAnchor() {
3695 if (!RuntimeEnabledFeatures::scrollAnchoringEnabled()) 3754 if (!RuntimeEnabledFeatures::scrollAnchoringEnabled())
3696 return; 3755 return;
3697 m_scrollAnchor.clear(); 3756 m_scrollAnchor.clear();
3698 } 3757 }
3699 3758
3700 bool FrameView::hasOverlayScrollbars() const {
3701 return (horizontalScrollbar() &&
3702 horizontalScrollbar()->isOverlayScrollbar()) ||
3703 (verticalScrollbar() && verticalScrollbar()->isOverlayScrollbar());
3704 }
3705
3706 void FrameView::computeScrollbarExistence( 3759 void FrameView::computeScrollbarExistence(
3707 bool& newHasHorizontalScrollbar, 3760 bool& newHasHorizontalScrollbar,
3708 bool& newHasVerticalScrollbar, 3761 bool& newHasVerticalScrollbar,
3709 const IntSize& docSize, 3762 const IntSize& docSize,
3710 ComputeScrollbarExistenceOption option) const { 3763 ComputeScrollbarExistenceOption option) const {
3711 if (m_frame->settings() && m_frame->settings()->hideScrollbars()) { 3764 if (m_frame->settings() && m_frame->settings()->hideScrollbars()) {
3712 newHasHorizontalScrollbar = false; 3765 newHasHorizontalScrollbar = false;
3713 newHasVerticalScrollbar = false; 3766 newHasVerticalScrollbar = false;
3714 return; 3767 return;
3715 } 3768 }
(...skipping 12 matching lines...) Expand all
3728 3781
3729 if (hScroll != ScrollbarAuto) 3782 if (hScroll != ScrollbarAuto)
3730 newHasHorizontalScrollbar = (hScroll == ScrollbarAlwaysOn); 3783 newHasHorizontalScrollbar = (hScroll == ScrollbarAlwaysOn);
3731 if (vScroll != ScrollbarAuto) 3784 if (vScroll != ScrollbarAuto)
3732 newHasVerticalScrollbar = (vScroll == ScrollbarAlwaysOn); 3785 newHasVerticalScrollbar = (vScroll == ScrollbarAlwaysOn);
3733 3786
3734 if (m_scrollbarsSuppressed || 3787 if (m_scrollbarsSuppressed ||
3735 (hScroll != ScrollbarAuto && vScroll != ScrollbarAuto)) 3788 (hScroll != ScrollbarAuto && vScroll != ScrollbarAuto))
3736 return; 3789 return;
3737 3790
3791 ScrollableArea* scroller = m_scrollbarManager.scrollableArea();
3738 if (hScroll == ScrollbarAuto) 3792 if (hScroll == ScrollbarAuto)
3739 newHasHorizontalScrollbar = docSize.width() > visibleWidth(); 3793 newHasHorizontalScrollbar = docSize.width() > scroller->visibleWidth();
3740 if (vScroll == ScrollbarAuto) 3794 if (vScroll == ScrollbarAuto)
3741 newHasVerticalScrollbar = docSize.height() > visibleHeight(); 3795 newHasVerticalScrollbar = docSize.height() > scroller->visibleHeight();
3742 3796
3743 if (hasOverlayScrollbars()) 3797 if (hasOverlayScrollbars())
3744 return; 3798 return;
3745 3799
3746 IntSize fullVisibleSize = visibleContentRect(IncludeScrollbars).size(); 3800 IntSize fullVisibleSize =
3801 scroller->visibleContentRect(IncludeScrollbars).size();
3747 3802
3748 bool attemptToRemoveScrollbars = 3803 bool attemptToRemoveScrollbars =
3749 (option == FirstPass && docSize.width() <= fullVisibleSize.width() && 3804 (option == FirstPass && docSize.width() <= fullVisibleSize.width() &&
3750 docSize.height() <= fullVisibleSize.height()); 3805 docSize.height() <= fullVisibleSize.height());
3751 if (attemptToRemoveScrollbars) { 3806 if (attemptToRemoveScrollbars) {
3752 if (hScroll == ScrollbarAuto) 3807 if (hScroll == ScrollbarAuto)
3753 newHasHorizontalScrollbar = false; 3808 newHasHorizontalScrollbar = false;
3754 if (vScroll == ScrollbarAuto) 3809 if (vScroll == ScrollbarAuto)
3755 newHasVerticalScrollbar = false; 3810 newHasVerticalScrollbar = false;
3756 } 3811 }
3757 } 3812 }
3758 3813
3759 void FrameView::updateScrollbarGeometry() {
3760 if (horizontalScrollbar()) {
3761 int thickness = horizontalScrollbar()->scrollbarThickness();
3762 int clientWidth = visibleWidth();
3763 IntRect oldRect(horizontalScrollbar()->frameRect());
3764 IntRect hBarRect(
3765 (shouldPlaceVerticalScrollbarOnLeft() && verticalScrollbar())
3766 ? verticalScrollbar()->width()
3767 : 0,
3768 height() - thickness,
3769 width() - (verticalScrollbar() ? verticalScrollbar()->width() : 0),
3770 thickness);
3771 horizontalScrollbar()->setFrameRect(hBarRect);
3772 if (oldRect != horizontalScrollbar()->frameRect())
3773 setScrollbarNeedsPaintInvalidation(HorizontalScrollbar);
3774
3775 horizontalScrollbar()->setEnabled(contentsWidth() > clientWidth &&
3776 !scrollbarsHidden());
3777 horizontalScrollbar()->setProportion(clientWidth, contentsWidth());
3778 horizontalScrollbar()->offsetDidChange();
3779 }
3780
3781 if (verticalScrollbar()) {
3782 int thickness = verticalScrollbar()->scrollbarThickness();
3783 int clientHeight = visibleHeight();
3784 IntRect oldRect(verticalScrollbar()->frameRect());
3785 IntRect vBarRect(
3786 shouldPlaceVerticalScrollbarOnLeft() ? 0 : (width() - thickness), 0,
3787 thickness,
3788 height() -
3789 (horizontalScrollbar() ? horizontalScrollbar()->height() : 0));
3790 verticalScrollbar()->setFrameRect(vBarRect);
3791 if (oldRect != verticalScrollbar()->frameRect())
3792 setScrollbarNeedsPaintInvalidation(VerticalScrollbar);
3793
3794 verticalScrollbar()->setEnabled(contentsHeight() > clientHeight &&
3795 !scrollbarsHidden());
3796 verticalScrollbar()->setProportion(clientHeight, contentsHeight());
3797 verticalScrollbar()->offsetDidChange();
3798 }
3799 }
3800
3801 bool FrameView::adjustScrollbarExistence( 3814 bool FrameView::adjustScrollbarExistence(
3802 ComputeScrollbarExistenceOption option) { 3815 ComputeScrollbarExistenceOption option) {
3803 ASSERT(m_inUpdateScrollbars); 3816 ASSERT(m_inUpdateScrollbars);
3804 3817
3805 // If we came in here with the view already needing a layout, then go ahead 3818 // If we came in here with the view already needing a layout, then go ahead
3806 // and do that first. (This will be the common case, e.g., when the page 3819 // and do that first. (This will be the common case, e.g., when the page
3807 // changes due to window resizing for example). This layout will not re-enter 3820 // changes due to window resizing for example). This layout will not re-enter
3808 // updateScrollbars and does not count towards our max layout pass total. 3821 // updateScrollbars and does not count towards our max layout pass total.
3809 if (!m_scrollbarsSuppressed) 3822 if (!m_scrollbarsSuppressed)
3810 scrollbarExistenceDidChange(); 3823 scrollbarExistenceDidChange();
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
3893 int maxUpdateScrollbarsPass = 3906 int maxUpdateScrollbarsPass =
3894 hasOverlayScrollbars() || m_scrollbarsSuppressed ? 1 : 3; 3907 hasOverlayScrollbars() || m_scrollbarsSuppressed ? 1 : 3;
3895 for (int updateScrollbarsPass = 0; 3908 for (int updateScrollbarsPass = 0;
3896 updateScrollbarsPass < maxUpdateScrollbarsPass; updateScrollbarsPass++) { 3909 updateScrollbarsPass < maxUpdateScrollbarsPass; updateScrollbarsPass++) {
3897 if (!adjustScrollbarExistence(updateScrollbarsPass ? Incremental 3910 if (!adjustScrollbarExistence(updateScrollbarsPass ? Incremental
3898 : FirstPass)) 3911 : FirstPass))
3899 break; 3912 break;
3900 scrollbarExistenceChanged = true; 3913 scrollbarExistenceChanged = true;
3901 } 3914 }
3902 3915
3903 updateScrollbarGeometry(); 3916 m_scrollbarManager.updateScrollbarGeometry(size());
3904 3917
3905 if (scrollbarExistenceChanged) { 3918 if (scrollbarExistenceChanged) {
3906 // FIXME: Is frameRectsChanged really necessary here? Have any frame rects 3919 // FIXME: Is frameRectsChanged really necessary here? Have any frame rects
3907 // changed? 3920 // changed?
3908 frameRectsChanged(); 3921 frameRectsChanged();
3909 positionScrollbarLayers(); 3922 positionScrollbarLayers();
3910 updateScrollCorner(); 3923 updateScrollCorner();
3911 } 3924 }
3912 3925
3913 adjustScrollOffsetFromUpdateScrollbars(); 3926 adjustScrollOffsetFromUpdateScrollbars();
(...skipping 616 matching lines...) Expand 10 before | Expand all | Expand 10 after
4530 DCHECK(m_frame->isMainFrame()); 4543 DCHECK(m_frame->isMainFrame());
4531 return m_initialViewportSize.width(); 4544 return m_initialViewportSize.width();
4532 } 4545 }
4533 4546
4534 int FrameView::initialViewportHeight() const { 4547 int FrameView::initialViewportHeight() const {
4535 DCHECK(m_frame->isMainFrame()); 4548 DCHECK(m_frame->isMainFrame());
4536 return m_initialViewportSize.height(); 4549 return m_initialViewportSize.height();
4537 } 4550 }
4538 4551
4539 } // namespace blink 4552 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698