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

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: Rebase and fix merge conflicts 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_scrollableArea->scrollbarsHidden());
459 m_hBar->setProportion(visibleWidth, contentsWidth);
460 m_hBar->offsetDidChange();
461 }
462
463 if (hasVerticalScrollbar()) {
464 int thickness = m_vBar->scrollbarThickness();
465 IntRect oldRect(m_vBar->frameRect());
466 IntRect vBarRect(
467 scrollbarOnLeft ? 0 : (viewSize.width() - thickness), 0, thickness,
468 viewSize.height() - (hasHorizontalScrollbar() ? m_hBar->height() : 0));
469 m_vBar->setFrameRect(vBarRect);
470 if (oldRect != m_vBar->frameRect())
471 m_scrollableArea->setScrollbarNeedsPaintInvalidation(VerticalScrollbar);
472
473 int clientHeight = m_scrollableArea->visibleHeight();
474 int contentsHeight = m_scrollableArea->contentsSize().height();
475 m_vBar->setEnabled(contentsHeight > clientHeight &&
476 !m_scrollableArea->scrollbarsHidden());
477 m_vBar->setProportion(clientHeight, contentsHeight);
478 m_vBar->offsetDidChange();
479 }
480 }
481
433 void FrameView::recalculateCustomScrollbarStyle() { 482 void FrameView::recalculateCustomScrollbarStyle() {
434 bool didStyleChange = false; 483 bool didStyleChange = false;
435 if (horizontalScrollbar() && horizontalScrollbar()->isCustomScrollbar()) { 484 if (horizontalScrollbar() && horizontalScrollbar()->isCustomScrollbar()) {
436 horizontalScrollbar()->styleChanged(); 485 horizontalScrollbar()->styleChanged();
437 didStyleChange = true; 486 didStyleChange = true;
438 } 487 }
439 if (verticalScrollbar() && verticalScrollbar()->isCustomScrollbar()) { 488 if (verticalScrollbar() && verticalScrollbar()->isCustomScrollbar()) {
440 verticalScrollbar()->styleChanged(); 489 verticalScrollbar()->styleChanged();
441 didStyleChange = true; 490 didStyleChange = true;
442 } 491 }
443 if (didStyleChange) { 492 if (didStyleChange) {
444 updateScrollbarGeometry(); 493 m_scrollbarManager.updateScrollbarGeometry(size());
445 updateScrollCorner(); 494 updateScrollCorner();
446 positionScrollbarLayers(); 495 positionScrollbarLayers();
447 } 496 }
448 } 497 }
449 498
450 void FrameView::invalidateAllCustomScrollbarsOnActiveChanged() { 499 void FrameView::invalidateAllCustomScrollbarsOnActiveChanged() {
451 bool usesWindowInactiveSelector = 500 bool usesWindowInactiveSelector =
452 m_frame->document()->styleEngine().usesWindowInactiveSelector(); 501 m_frame->document()->styleEngine().usesWindowInactiveSelector();
453 502
454 const ChildrenWidgetSet* viewChildren = children(); 503 const ChildrenWidgetSet* viewChildren = children();
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
781 830
782 bool hasHorizontalScrollbar = horizontalScrollbar(); 831 bool hasHorizontalScrollbar = horizontalScrollbar();
783 bool hasVerticalScrollbar = verticalScrollbar(); 832 bool hasVerticalScrollbar = verticalScrollbar();
784 if (hasHorizontalScrollbar != shouldHaveHorizontalScrollbar || 833 if (hasHorizontalScrollbar != shouldHaveHorizontalScrollbar ||
785 hasVerticalScrollbar != shouldHaveVerticalScrollbar) { 834 hasVerticalScrollbar != shouldHaveVerticalScrollbar) {
786 setNeedsLayout(); 835 setNeedsLayout();
787 return; 836 return;
788 } 837 }
789 838
790 adjustViewSize(); 839 adjustViewSize();
791 updateScrollbarGeometry(); 840 m_scrollbarManager.updateScrollbarGeometry(size());
792 841
793 if (scrollOriginChanged()) 842 if (scrollOriginChanged())
794 setNeedsLayout(); 843 setNeedsLayout();
795 } 844 }
796 845
797 bool FrameView::usesCompositedScrolling() const { 846 bool FrameView::usesCompositedScrolling() const {
798 LayoutViewItem layoutView = this->layoutViewItem(); 847 LayoutViewItem layoutView = this->layoutViewItem();
799 if (layoutView.isNull()) 848 if (layoutView.isNull())
800 return false; 849 return false;
801 if (m_frame->settings() && 850 if (m_frame->settings() &&
(...skipping 1598 matching lines...) Expand 10 before | Expand all | Expand 10 after
2400 Page* page = frame().page(); 2449 Page* page = frame().page();
2401 return page && page->focusController().isActive(); 2450 return page && page->focusController().isActive();
2402 } 2451 }
2403 2452
2404 void FrameView::invalidatePaintForTickmarks() { 2453 void FrameView::invalidatePaintForTickmarks() {
2405 if (Scrollbar* scrollbar = verticalScrollbar()) 2454 if (Scrollbar* scrollbar = verticalScrollbar())
2406 scrollbar->setNeedsPaintInvalidation( 2455 scrollbar->setNeedsPaintInvalidation(
2407 static_cast<ScrollbarPart>(~ThumbPart)); 2456 static_cast<ScrollbarPart>(~ThumbPart));
2408 } 2457 }
2409 2458
2459 void FrameView::setTickmarks(const Vector<IntRect>& tickmarks) {
2460 // Tickmarks for main frame are stored in RFV.
2461 if (m_frame->isMainFrame())
2462 m_viewportScrollableArea->setTickmarks(tickmarks);
2463 else
2464 m_tickmarks = tickmarks;
2465
2466 invalidatePaintForTickmarks();
2467 }
2468
2410 void FrameView::getTickmarks(Vector<IntRect>& tickmarks) const { 2469 void FrameView::getTickmarks(Vector<IntRect>& tickmarks) const {
2411 if (!m_tickmarks.isEmpty()) 2470 if (!m_tickmarks.isEmpty())
2412 tickmarks = m_tickmarks; 2471 tickmarks = m_tickmarks;
2413 else 2472 else
2414 tickmarks = frame().document()->markers().renderedRectsForMarkers( 2473 tickmarks = frame().document()->markers().renderedRectsForMarkers(
2415 DocumentMarker::TextMatch); 2474 DocumentMarker::TextMatch);
2416 } 2475 }
2417 2476
2418 void FrameView::setInputEventsTransformForEmulation(const IntSize& offset, 2477 void FrameView::setInputEventsTransformForEmulation(const IntSize& offset,
2419 float contentScaleFactor) { 2478 float contentScaleFactor) {
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
2563 2622
2564 if (m_frame->isMainFrame()) { 2623 if (m_frame->isMainFrame()) {
2565 ScrollableArea& visualViewport = frameHost->visualViewport(); 2624 ScrollableArea& visualViewport = frameHost->visualViewport();
2566 ScrollableArea* layoutViewport = layoutViewportScrollableArea(); 2625 ScrollableArea* layoutViewport = layoutViewportScrollableArea();
2567 DCHECK(layoutViewport); 2626 DCHECK(layoutViewport);
2568 2627
2569 RootFrameViewport* rootFrameViewport = 2628 RootFrameViewport* rootFrameViewport =
2570 RootFrameViewport::create(visualViewport, *layoutViewport); 2629 RootFrameViewport::create(visualViewport, *layoutViewport);
2571 m_viewportScrollableArea = rootFrameViewport; 2630 m_viewportScrollableArea = rootFrameViewport;
2572 2631
2632 m_scrollbarManager.setScroller(rootFrameViewport);
2633
2573 frameHost->globalRootScrollerController().initializeViewportScrollCallback( 2634 frameHost->globalRootScrollerController().initializeViewportScrollCallback(
2574 *rootFrameViewport); 2635 *rootFrameViewport);
2575 } 2636 }
2576 } 2637 }
2577 2638
2578 void FrameView::updateScrollCorner() { 2639 void FrameView::updateScrollCorner() {
2579 RefPtr<ComputedStyle> cornerStyle; 2640 RefPtr<ComputedStyle> cornerStyle;
2580 IntRect cornerRect = scrollCornerRect(); 2641 IntRect cornerRect = scrollCornerRect();
2581 Document* doc = m_frame->document(); 2642 Document* doc = m_frame->document();
2582 2643
(...skipping 1124 matching lines...) Expand 10 before | Expand all | Expand 10 after
3707 if (frame().isMainFrame()) 3768 if (frame().isMainFrame())
3708 frame().host()->chromeClient().mainFrameScrollOffsetChanged(); 3769 frame().host()->chromeClient().mainFrameScrollOffsetChanged();
3709 } 3770 }
3710 3771
3711 void FrameView::clearScrollAnchor() { 3772 void FrameView::clearScrollAnchor() {
3712 if (!RuntimeEnabledFeatures::scrollAnchoringEnabled()) 3773 if (!RuntimeEnabledFeatures::scrollAnchoringEnabled())
3713 return; 3774 return;
3714 m_scrollAnchor.clear(); 3775 m_scrollAnchor.clear();
3715 } 3776 }
3716 3777
3717 bool FrameView::hasOverlayScrollbars() const {
3718 return (horizontalScrollbar() &&
3719 horizontalScrollbar()->isOverlayScrollbar()) ||
3720 (verticalScrollbar() && verticalScrollbar()->isOverlayScrollbar());
3721 }
3722
3723 void FrameView::computeScrollbarExistence( 3778 void FrameView::computeScrollbarExistence(
3724 bool& newHasHorizontalScrollbar, 3779 bool& newHasHorizontalScrollbar,
3725 bool& newHasVerticalScrollbar, 3780 bool& newHasVerticalScrollbar,
3726 const IntSize& docSize, 3781 const IntSize& docSize,
3727 ComputeScrollbarExistenceOption option) const { 3782 ComputeScrollbarExistenceOption option) const {
3728 if (m_frame->settings() && m_frame->settings()->hideScrollbars()) { 3783 if (m_frame->settings() && m_frame->settings()->hideScrollbars()) {
3729 newHasHorizontalScrollbar = false; 3784 newHasHorizontalScrollbar = false;
3730 newHasVerticalScrollbar = false; 3785 newHasVerticalScrollbar = false;
3731 return; 3786 return;
3732 } 3787 }
(...skipping 12 matching lines...) Expand all
3745 3800
3746 if (hScroll != ScrollbarAuto) 3801 if (hScroll != ScrollbarAuto)
3747 newHasHorizontalScrollbar = (hScroll == ScrollbarAlwaysOn); 3802 newHasHorizontalScrollbar = (hScroll == ScrollbarAlwaysOn);
3748 if (vScroll != ScrollbarAuto) 3803 if (vScroll != ScrollbarAuto)
3749 newHasVerticalScrollbar = (vScroll == ScrollbarAlwaysOn); 3804 newHasVerticalScrollbar = (vScroll == ScrollbarAlwaysOn);
3750 3805
3751 if (m_scrollbarsSuppressed || 3806 if (m_scrollbarsSuppressed ||
3752 (hScroll != ScrollbarAuto && vScroll != ScrollbarAuto)) 3807 (hScroll != ScrollbarAuto && vScroll != ScrollbarAuto))
3753 return; 3808 return;
3754 3809
3810 ScrollableArea* scroller = m_scrollbarManager.scrollableArea();
3755 if (hScroll == ScrollbarAuto) 3811 if (hScroll == ScrollbarAuto)
3756 newHasHorizontalScrollbar = docSize.width() > visibleWidth(); 3812 newHasHorizontalScrollbar = docSize.width() > scroller->visibleWidth();
3757 if (vScroll == ScrollbarAuto) 3813 if (vScroll == ScrollbarAuto)
3758 newHasVerticalScrollbar = docSize.height() > visibleHeight(); 3814 newHasVerticalScrollbar = docSize.height() > scroller->visibleHeight();
3759 3815
3760 if (hasOverlayScrollbars()) 3816 if (hasOverlayScrollbars())
3761 return; 3817 return;
3762 3818
3763 IntSize fullVisibleSize = visibleContentRect(IncludeScrollbars).size(); 3819 IntSize fullVisibleSize =
3820 scroller->visibleContentRect(IncludeScrollbars).size();
3764 3821
3765 bool attemptToRemoveScrollbars = 3822 bool attemptToRemoveScrollbars =
3766 (option == FirstPass && docSize.width() <= fullVisibleSize.width() && 3823 (option == FirstPass && docSize.width() <= fullVisibleSize.width() &&
3767 docSize.height() <= fullVisibleSize.height()); 3824 docSize.height() <= fullVisibleSize.height());
3768 if (attemptToRemoveScrollbars) { 3825 if (attemptToRemoveScrollbars) {
3769 if (hScroll == ScrollbarAuto) 3826 if (hScroll == ScrollbarAuto)
3770 newHasHorizontalScrollbar = false; 3827 newHasHorizontalScrollbar = false;
3771 if (vScroll == ScrollbarAuto) 3828 if (vScroll == ScrollbarAuto)
3772 newHasVerticalScrollbar = false; 3829 newHasVerticalScrollbar = false;
3773 } 3830 }
3774 } 3831 }
3775 3832
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 !scrollbarsHidden());
3794 horizontalScrollbar()->setProportion(clientWidth, contentsWidth());
3795 horizontalScrollbar()->offsetDidChange();
3796 }
3797
3798 if (verticalScrollbar()) {
3799 int thickness = verticalScrollbar()->scrollbarThickness();
3800 int clientHeight = visibleHeight();
3801 IntRect oldRect(verticalScrollbar()->frameRect());
3802 IntRect vBarRect(
3803 shouldPlaceVerticalScrollbarOnLeft() ? 0 : (width() - thickness), 0,
3804 thickness,
3805 height() -
3806 (horizontalScrollbar() ? horizontalScrollbar()->height() : 0));
3807 verticalScrollbar()->setFrameRect(vBarRect);
3808 if (oldRect != verticalScrollbar()->frameRect())
3809 setScrollbarNeedsPaintInvalidation(VerticalScrollbar);
3810
3811 verticalScrollbar()->setEnabled(contentsHeight() > clientHeight &&
3812 !scrollbarsHidden());
3813 verticalScrollbar()->setProportion(clientHeight, contentsHeight());
3814 verticalScrollbar()->offsetDidChange();
3815 }
3816 }
3817
3818 bool FrameView::adjustScrollbarExistence( 3833 bool FrameView::adjustScrollbarExistence(
3819 ComputeScrollbarExistenceOption option) { 3834 ComputeScrollbarExistenceOption option) {
3820 ASSERT(m_inUpdateScrollbars); 3835 ASSERT(m_inUpdateScrollbars);
3821 3836
3822 // If we came in here with the view already needing a layout, then go ahead 3837 // If we came in here with the view already needing a layout, then go ahead
3823 // and do that first. (This will be the common case, e.g., when the page 3838 // and do that first. (This will be the common case, e.g., when the page
3824 // changes due to window resizing for example). This layout will not re-enter 3839 // changes due to window resizing for example). This layout will not re-enter
3825 // updateScrollbars and does not count towards our max layout pass total. 3840 // updateScrollbars and does not count towards our max layout pass total.
3826 if (!m_scrollbarsSuppressed) 3841 if (!m_scrollbarsSuppressed)
3827 scrollbarExistenceDidChange(); 3842 scrollbarExistenceDidChange();
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
3910 int maxUpdateScrollbarsPass = 3925 int maxUpdateScrollbarsPass =
3911 hasOverlayScrollbars() || m_scrollbarsSuppressed ? 1 : 3; 3926 hasOverlayScrollbars() || m_scrollbarsSuppressed ? 1 : 3;
3912 for (int updateScrollbarsPass = 0; 3927 for (int updateScrollbarsPass = 0;
3913 updateScrollbarsPass < maxUpdateScrollbarsPass; updateScrollbarsPass++) { 3928 updateScrollbarsPass < maxUpdateScrollbarsPass; updateScrollbarsPass++) {
3914 if (!adjustScrollbarExistence(updateScrollbarsPass ? Incremental 3929 if (!adjustScrollbarExistence(updateScrollbarsPass ? Incremental
3915 : FirstPass)) 3930 : FirstPass))
3916 break; 3931 break;
3917 scrollbarExistenceChanged = true; 3932 scrollbarExistenceChanged = true;
3918 } 3933 }
3919 3934
3920 updateScrollbarGeometry(); 3935 m_scrollbarManager.updateScrollbarGeometry(size());
3921 3936
3922 if (scrollbarExistenceChanged) { 3937 if (scrollbarExistenceChanged) {
3923 // FIXME: Is frameRectsChanged really necessary here? Have any frame rects 3938 // FIXME: Is frameRectsChanged really necessary here? Have any frame rects
3924 // changed? 3939 // changed?
3925 frameRectsChanged(); 3940 frameRectsChanged();
3926 positionScrollbarLayers(); 3941 positionScrollbarLayers();
3927 updateScrollCorner(); 3942 updateScrollCorner();
3928 } 3943 }
3929 3944
3930 adjustScrollOffsetFromUpdateScrollbars(); 3945 adjustScrollOffsetFromUpdateScrollbars();
(...skipping 616 matching lines...) Expand 10 before | Expand all | Expand 10 after
4547 DCHECK(m_frame->isMainFrame()); 4562 DCHECK(m_frame->isMainFrame());
4548 return m_initialViewportSize.width(); 4563 return m_initialViewportSize.width();
4549 } 4564 }
4550 4565
4551 int FrameView::initialViewportHeight() const { 4566 int FrameView::initialViewportHeight() const {
4552 DCHECK(m_frame->isMainFrame()); 4567 DCHECK(m_frame->isMainFrame());
4553 return m_initialViewportSize.height(); 4568 return m_initialViewportSize.height();
4554 } 4569 }
4555 4570
4556 } // namespace blink 4571 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698