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

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: add test + rebase 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 395 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 if (!scrollbar) 406 if (!scrollbar)
407 return; 407 return;
408 408
409 m_scrollableArea->willRemoveScrollbar(*scrollbar, orientation); 409 m_scrollableArea->willRemoveScrollbar(*scrollbar, orientation);
410 m_scrollableArea->layoutBox()->document().view()->removeChild( 410 m_scrollableArea->layoutBox()->document().view()->removeChild(
411 scrollbar.get()); 411 scrollbar.get());
412 scrollbar->disconnectFromScrollableArea(); 412 scrollbar->disconnectFromScrollableArea();
413 scrollbar = nullptr; 413 scrollbar = nullptr;
414 } 414 }
415 415
416 bool FrameView::ScrollbarManager::needScrollbar(
417 ScrollbarOrientation orientation,
418 const IntSize& docSize,
419 ComputeScrollbarExistenceOption option) const {
420 bool needScrollbar =
421 orientation == HorizontalScrollbar
422 ? docSize.width() > m_scrollableArea->visibleWidth()
423 : docSize.height() > m_scrollableArea->visibleHeight();
424
425 if (m_scrollableArea->hasOverlayScrollbars())
426 return needScrollbar;
427
428 // Will the content fit iff there are no scrollbars.
429 IntSize fullVisibleSize =
430 m_scrollableArea->visibleContentRect(IncludeScrollbars).size();
431 bool needNewScrollbar = orientation == HorizontalScrollbar
432 ? docSize.width() <= fullVisibleSize.width()
433 : docSize.height() <= fullVisibleSize.height();
434 if (option == FirstPass && needNewScrollbar)
435 needScrollbar = false;
436
437 return needScrollbar;
438 }
439
440 void FrameView::ScrollbarManager::updateScrollbarGeometry(IntSize viewSize) {
441 if (!hasHorizontalScrollbar() && !hasVerticalScrollbar())
442 return;
443
444 bool scrollbarOnLeft = m_scrollableArea->shouldPlaceVerticalScrollbarOnLeft();
445
446 if (hasHorizontalScrollbar()) {
447 int thickness = m_hBar->scrollbarThickness();
448 IntRect oldRect(m_hBar->frameRect());
449 IntRect hBarRect(
450 (scrollbarOnLeft && hasVerticalScrollbar()) ? m_vBar->width() : 0,
451 viewSize.height() - thickness,
452 viewSize.width() - (hasVerticalScrollbar() ? m_vBar->width() : 0),
453 thickness);
454 m_hBar->setFrameRect(hBarRect);
455 if (oldRect != m_hBar->frameRect())
456 m_scrollableArea->setScrollbarNeedsPaintInvalidation(HorizontalScrollbar);
457
458 int visibleWidth = m_scrollableArea->visibleWidth();
459 int contentsWidth = m_scrollableArea->contentsSize().width();
460 m_hBar->setEnabled(contentsWidth > visibleWidth);
461 m_hBar->setProportion(visibleWidth, contentsWidth);
462 m_hBar->offsetDidChange();
463 }
464
465 if (hasVerticalScrollbar()) {
466 int thickness = m_vBar->scrollbarThickness();
467 IntRect oldRect(m_vBar->frameRect());
468 IntRect vBarRect(
469 scrollbarOnLeft ? 0 : (viewSize.width() - thickness), 0, thickness,
470 viewSize.height() - (hasHorizontalScrollbar() ? m_hBar->height() : 0));
471 m_vBar->setFrameRect(vBarRect);
472 if (oldRect != m_vBar->frameRect())
473 m_scrollableArea->setScrollbarNeedsPaintInvalidation(VerticalScrollbar);
474
475 int clientHeight = m_scrollableArea->visibleHeight();
476 int contentsHeight = m_scrollableArea->contentsSize().height();
477 m_vBar->setEnabled(contentsHeight > clientHeight);
478 m_vBar->setProportion(clientHeight, contentsHeight);
479 m_vBar->offsetDidChange();
480 }
481 }
482
416 void FrameView::recalculateCustomScrollbarStyle() { 483 void FrameView::recalculateCustomScrollbarStyle() {
417 bool didStyleChange = false; 484 bool didStyleChange = false;
418 if (horizontalScrollbar() && horizontalScrollbar()->isCustomScrollbar()) { 485 if (horizontalScrollbar() && horizontalScrollbar()->isCustomScrollbar()) {
419 horizontalScrollbar()->styleChanged(); 486 horizontalScrollbar()->styleChanged();
420 didStyleChange = true; 487 didStyleChange = true;
421 } 488 }
422 if (verticalScrollbar() && verticalScrollbar()->isCustomScrollbar()) { 489 if (verticalScrollbar() && verticalScrollbar()->isCustomScrollbar()) {
423 verticalScrollbar()->styleChanged(); 490 verticalScrollbar()->styleChanged();
424 didStyleChange = true; 491 didStyleChange = true;
425 } 492 }
426 if (didStyleChange) { 493 if (didStyleChange) {
427 updateScrollbarGeometry(); 494 m_scrollbarManager.updateScrollbarGeometry(size());
428 updateScrollCorner(); 495 updateScrollCorner();
429 positionScrollbarLayers(); 496 positionScrollbarLayers();
430 } 497 }
431 } 498 }
432 499
433 void FrameView::invalidateAllCustomScrollbarsOnActiveChanged() { 500 void FrameView::invalidateAllCustomScrollbarsOnActiveChanged() {
434 bool usesWindowInactiveSelector = 501 bool usesWindowInactiveSelector =
435 m_frame->document()->styleEngine().usesWindowInactiveSelector(); 502 m_frame->document()->styleEngine().usesWindowInactiveSelector();
436 503
437 const ChildrenWidgetSet* viewChildren = children(); 504 const ChildrenWidgetSet* viewChildren = children();
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
751 818
752 bool hasHorizontalScrollbar = horizontalScrollbar(); 819 bool hasHorizontalScrollbar = horizontalScrollbar();
753 bool hasVerticalScrollbar = verticalScrollbar(); 820 bool hasVerticalScrollbar = verticalScrollbar();
754 if (hasHorizontalScrollbar != shouldHaveHorizontalScrollbar || 821 if (hasHorizontalScrollbar != shouldHaveHorizontalScrollbar ||
755 hasVerticalScrollbar != shouldHaveVerticalScrollbar) { 822 hasVerticalScrollbar != shouldHaveVerticalScrollbar) {
756 setNeedsLayout(); 823 setNeedsLayout();
757 return; 824 return;
758 } 825 }
759 826
760 adjustViewSize(); 827 adjustViewSize();
761 updateScrollbarGeometry(); 828 m_scrollbarManager.updateScrollbarGeometry(size());
762 829
763 if (scrollOriginChanged()) 830 if (scrollOriginChanged())
764 setNeedsLayout(); 831 setNeedsLayout();
765 } 832 }
766 833
767 bool FrameView::usesCompositedScrolling() const { 834 bool FrameView::usesCompositedScrolling() const {
768 LayoutViewItem layoutView = this->layoutViewItem(); 835 LayoutViewItem layoutView = this->layoutViewItem();
769 if (layoutView.isNull()) 836 if (layoutView.isNull())
770 return false; 837 return false;
771 if (m_frame->settings() && 838 if (m_frame->settings() &&
(...skipping 1580 matching lines...) Expand 10 before | Expand all | Expand 10 after
2352 Page* page = frame().page(); 2419 Page* page = frame().page();
2353 return page && page->focusController().isActive(); 2420 return page && page->focusController().isActive();
2354 } 2421 }
2355 2422
2356 void FrameView::invalidatePaintForTickmarks() { 2423 void FrameView::invalidatePaintForTickmarks() {
2357 if (Scrollbar* scrollbar = verticalScrollbar()) 2424 if (Scrollbar* scrollbar = verticalScrollbar())
2358 scrollbar->setNeedsPaintInvalidation( 2425 scrollbar->setNeedsPaintInvalidation(
2359 static_cast<ScrollbarPart>(~ThumbPart)); 2426 static_cast<ScrollbarPart>(~ThumbPart));
2360 } 2427 }
2361 2428
2429 void FrameView::setTickmarks(const Vector<IntRect>& tickmarks) {
2430 // Tickmarks for main frame are stored in RFV.
2431 if (m_frame->isMainFrame())
2432 m_viewportScrollableArea->setTickmarks(tickmarks);
2433 else
2434 m_tickmarks = tickmarks;
2435
2436 invalidatePaintForTickmarks();
2437 }
2438
2362 void FrameView::getTickmarks(Vector<IntRect>& tickmarks) const { 2439 void FrameView::getTickmarks(Vector<IntRect>& tickmarks) const {
2363 if (!m_tickmarks.isEmpty()) 2440 if (!m_tickmarks.isEmpty())
2364 tickmarks = m_tickmarks; 2441 tickmarks = m_tickmarks;
2365 else 2442 else
2366 tickmarks = frame().document()->markers().renderedRectsForMarkers( 2443 tickmarks = frame().document()->markers().renderedRectsForMarkers(
2367 DocumentMarker::TextMatch); 2444 DocumentMarker::TextMatch);
2368 } 2445 }
2369 2446
2370 void FrameView::setInputEventsTransformForEmulation(const IntSize& offset, 2447 void FrameView::setInputEventsTransformForEmulation(const IntSize& offset,
2371 float contentScaleFactor) { 2448 float contentScaleFactor) {
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
2515 2592
2516 if (m_frame->isMainFrame()) { 2593 if (m_frame->isMainFrame()) {
2517 ScrollableArea& visualViewport = frameHost->visualViewport(); 2594 ScrollableArea& visualViewport = frameHost->visualViewport();
2518 ScrollableArea* layoutViewport = layoutViewportScrollableArea(); 2595 ScrollableArea* layoutViewport = layoutViewportScrollableArea();
2519 DCHECK(layoutViewport); 2596 DCHECK(layoutViewport);
2520 2597
2521 RootFrameViewport* rootFrameViewport = 2598 RootFrameViewport* rootFrameViewport =
2522 RootFrameViewport::create(visualViewport, *layoutViewport); 2599 RootFrameViewport::create(visualViewport, *layoutViewport);
2523 m_viewportScrollableArea = rootFrameViewport; 2600 m_viewportScrollableArea = rootFrameViewport;
2524 2601
2602 m_scrollbarManager.setScroller(rootFrameViewport);
2603
2525 frameHost->globalRootScrollerController().initializeViewportScrollCallback( 2604 frameHost->globalRootScrollerController().initializeViewportScrollCallback(
2526 *rootFrameViewport); 2605 *rootFrameViewport);
2527 } 2606 }
2528 } 2607 }
2529 2608
2530 void FrameView::updateScrollCorner() { 2609 void FrameView::updateScrollCorner() {
2531 RefPtr<ComputedStyle> cornerStyle; 2610 RefPtr<ComputedStyle> cornerStyle;
2532 IntRect cornerRect = scrollCornerRect(); 2611 IntRect cornerRect = scrollCornerRect();
2533 Document* doc = m_frame->document(); 2612 Document* doc = m_frame->document();
2534 2613
(...skipping 1119 matching lines...) Expand 10 before | Expand all | Expand 10 after
3654 if (frame().isMainFrame()) 3733 if (frame().isMainFrame())
3655 frame().host()->chromeClient().mainFrameScrollOffsetChanged(); 3734 frame().host()->chromeClient().mainFrameScrollOffsetChanged();
3656 } 3735 }
3657 3736
3658 void FrameView::clearScrollAnchor() { 3737 void FrameView::clearScrollAnchor() {
3659 if (!RuntimeEnabledFeatures::scrollAnchoringEnabled()) 3738 if (!RuntimeEnabledFeatures::scrollAnchoringEnabled())
3660 return; 3739 return;
3661 m_scrollAnchor.clear(); 3740 m_scrollAnchor.clear();
3662 } 3741 }
3663 3742
3664 bool FrameView::hasOverlayScrollbars() const {
3665 return (horizontalScrollbar() &&
3666 horizontalScrollbar()->isOverlayScrollbar()) ||
3667 (verticalScrollbar() && verticalScrollbar()->isOverlayScrollbar());
3668 }
3669
3670 void FrameView::computeScrollbarExistence( 3743 void FrameView::computeScrollbarExistence(
3671 bool& newHasHorizontalScrollbar, 3744 bool& newHasHorizontalScrollbar,
3672 bool& newHasVerticalScrollbar, 3745 bool& newHasVerticalScrollbar,
3673 const IntSize& docSize, 3746 const IntSize& docSize,
3674 ComputeScrollbarExistenceOption option) const { 3747 ComputeScrollbarExistenceOption option) const {
3675 if (m_frame->settings() && m_frame->settings()->hideScrollbars()) { 3748 if (m_frame->settings() && m_frame->settings()->hideScrollbars()) {
3676 newHasHorizontalScrollbar = false; 3749 newHasHorizontalScrollbar = false;
3677 newHasVerticalScrollbar = false; 3750 newHasVerticalScrollbar = false;
3678 return; 3751 return;
3679 } 3752 }
(...skipping 12 matching lines...) Expand all
3692 3765
3693 if (hScroll != ScrollbarAuto) 3766 if (hScroll != ScrollbarAuto)
3694 newHasHorizontalScrollbar = (hScroll == ScrollbarAlwaysOn); 3767 newHasHorizontalScrollbar = (hScroll == ScrollbarAlwaysOn);
3695 if (vScroll != ScrollbarAuto) 3768 if (vScroll != ScrollbarAuto)
3696 newHasVerticalScrollbar = (vScroll == ScrollbarAlwaysOn); 3769 newHasVerticalScrollbar = (vScroll == ScrollbarAlwaysOn);
3697 3770
3698 if (m_scrollbarsSuppressed || 3771 if (m_scrollbarsSuppressed ||
3699 (hScroll != ScrollbarAuto && vScroll != ScrollbarAuto)) 3772 (hScroll != ScrollbarAuto && vScroll != ScrollbarAuto))
3700 return; 3773 return;
3701 3774
3702 if (hScroll == ScrollbarAuto) 3775 if (hScroll == ScrollbarAuto) {
3703 newHasHorizontalScrollbar = docSize.width() > visibleWidth(); 3776 newHasHorizontalScrollbar =
3704 if (vScroll == ScrollbarAuto) 3777 m_scrollbarManager.needScrollbar(HorizontalScrollbar, docSize, option);
3705 newHasVerticalScrollbar = docSize.height() > visibleHeight(); 3778 }
3706 3779 if (vScroll == ScrollbarAuto) {
3707 if (hasOverlayScrollbars()) 3780 newHasVerticalScrollbar =
3708 return; 3781 m_scrollbarManager.needScrollbar(VerticalScrollbar, docSize, option);
3709
3710 IntSize fullVisibleSize = visibleContentRect(IncludeScrollbars).size();
3711
3712 bool attemptToRemoveScrollbars =
3713 (option == FirstPass && docSize.width() <= fullVisibleSize.width() &&
3714 docSize.height() <= fullVisibleSize.height());
3715 if (attemptToRemoveScrollbars) {
3716 if (hScroll == ScrollbarAuto)
3717 newHasHorizontalScrollbar = false;
3718 if (vScroll == ScrollbarAuto)
3719 newHasVerticalScrollbar = false;
3720 } 3782 }
3721 } 3783 }
3722 3784
3723 void FrameView::updateScrollbarGeometry() {
3724 if (horizontalScrollbar()) {
3725 int thickness = horizontalScrollbar()->scrollbarThickness();
3726 int clientWidth = visibleWidth();
3727 IntRect oldRect(horizontalScrollbar()->frameRect());
3728 IntRect hBarRect(
3729 (shouldPlaceVerticalScrollbarOnLeft() && verticalScrollbar())
3730 ? verticalScrollbar()->width()
3731 : 0,
3732 height() - thickness,
3733 width() - (verticalScrollbar() ? verticalScrollbar()->width() : 0),
3734 thickness);
3735 horizontalScrollbar()->setFrameRect(hBarRect);
3736 if (oldRect != horizontalScrollbar()->frameRect())
3737 setScrollbarNeedsPaintInvalidation(HorizontalScrollbar);
3738
3739 horizontalScrollbar()->setEnabled(contentsWidth() > clientWidth);
3740 horizontalScrollbar()->setProportion(clientWidth, contentsWidth());
3741 horizontalScrollbar()->offsetDidChange();
3742 }
3743
3744 if (verticalScrollbar()) {
3745 int thickness = verticalScrollbar()->scrollbarThickness();
3746 int clientHeight = visibleHeight();
3747 IntRect oldRect(verticalScrollbar()->frameRect());
3748 IntRect vBarRect(
3749 shouldPlaceVerticalScrollbarOnLeft() ? 0 : (width() - thickness), 0,
3750 thickness,
3751 height() -
3752 (horizontalScrollbar() ? horizontalScrollbar()->height() : 0));
3753 verticalScrollbar()->setFrameRect(vBarRect);
3754 if (oldRect != verticalScrollbar()->frameRect())
3755 setScrollbarNeedsPaintInvalidation(VerticalScrollbar);
3756
3757 verticalScrollbar()->setEnabled(contentsHeight() > clientHeight);
3758 verticalScrollbar()->setProportion(clientHeight, contentsHeight());
3759 verticalScrollbar()->offsetDidChange();
3760 }
3761 }
3762
3763 bool FrameView::adjustScrollbarExistence( 3785 bool FrameView::adjustScrollbarExistence(
3764 ComputeScrollbarExistenceOption option) { 3786 ComputeScrollbarExistenceOption option) {
3765 ASSERT(m_inUpdateScrollbars); 3787 ASSERT(m_inUpdateScrollbars);
3766 3788
3767 // If we came in here with the view already needing a layout, then go ahead 3789 // If we came in here with the view already needing a layout, then go ahead
3768 // and do that first. (This will be the common case, e.g., when the page 3790 // and do that first. (This will be the common case, e.g., when the page
3769 // changes due to window resizing for example). This layout will not re-enter 3791 // changes due to window resizing for example). This layout will not re-enter
3770 // updateScrollbars and does not count towards our max layout pass total. 3792 // updateScrollbars and does not count towards our max layout pass total.
3771 if (!m_scrollbarsSuppressed) 3793 if (!m_scrollbarsSuppressed)
3772 scrollbarExistenceDidChange(); 3794 scrollbarExistenceDidChange();
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
3851 int maxUpdateScrollbarsPass = 3873 int maxUpdateScrollbarsPass =
3852 hasOverlayScrollbars() || m_scrollbarsSuppressed ? 1 : 3; 3874 hasOverlayScrollbars() || m_scrollbarsSuppressed ? 1 : 3;
3853 for (int updateScrollbarsPass = 0; 3875 for (int updateScrollbarsPass = 0;
3854 updateScrollbarsPass < maxUpdateScrollbarsPass; updateScrollbarsPass++) { 3876 updateScrollbarsPass < maxUpdateScrollbarsPass; updateScrollbarsPass++) {
3855 if (!adjustScrollbarExistence(updateScrollbarsPass ? Incremental 3877 if (!adjustScrollbarExistence(updateScrollbarsPass ? Incremental
3856 : FirstPass)) 3878 : FirstPass))
3857 break; 3879 break;
3858 scrollbarExistenceChanged = true; 3880 scrollbarExistenceChanged = true;
3859 } 3881 }
3860 3882
3861 updateScrollbarGeometry(); 3883 m_scrollbarManager.updateScrollbarGeometry(size());
3862 3884
3863 if (scrollbarExistenceChanged) { 3885 if (scrollbarExistenceChanged) {
3864 // FIXME: Is frameRectsChanged really necessary here? Have any frame rects 3886 // FIXME: Is frameRectsChanged really necessary here? Have any frame rects
3865 // changed? 3887 // changed?
3866 frameRectsChanged(); 3888 frameRectsChanged();
3867 positionScrollbarLayers(); 3889 positionScrollbarLayers();
3868 updateScrollCorner(); 3890 updateScrollCorner();
3869 } 3891 }
3870 3892
3871 adjustScrollOffsetFromUpdateScrollbars(); 3893 adjustScrollOffsetFromUpdateScrollbars();
(...skipping 668 matching lines...) Expand 10 before | Expand all | Expand 10 after
4540 DCHECK(m_frame->isMainFrame()); 4562 DCHECK(m_frame->isMainFrame());
4541 return m_initialViewportSize.width(); 4563 return m_initialViewportSize.width();
4542 } 4564 }
4543 4565
4544 int FrameView::initialViewportHeight() const { 4566 int FrameView::initialViewportHeight() const {
4545 DCHECK(m_frame->isMainFrame()); 4567 DCHECK(m_frame->isMainFrame());
4546 return m_initialViewportSize.height(); 4568 return m_initialViewportSize.height();
4547 } 4569 }
4548 4570
4549 } // namespace blink 4571 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698