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

Unified 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, 2 months 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/frame/FrameView.cpp
diff --git a/third_party/WebKit/Source/core/frame/FrameView.cpp b/third_party/WebKit/Source/core/frame/FrameView.cpp
index 8a3bfdab13304af8192d6e487225889e4d25b60f..e8bdfa0fb7ff8763911d2abee20615fe5c8ca20b 100644
--- a/third_party/WebKit/Source/core/frame/FrameView.cpp
+++ b/third_party/WebKit/Source/core/frame/FrameView.cpp
@@ -413,6 +413,73 @@ void FrameView::ScrollbarManager::destroyScrollbar(
scrollbar = nullptr;
}
+bool FrameView::ScrollbarManager::needScrollbar(
+ ScrollbarOrientation orientation,
+ const IntSize& docSize,
+ ComputeScrollbarExistenceOption option) const {
+ bool needScrollbar =
+ orientation == HorizontalScrollbar
+ ? docSize.width() > m_scrollableArea->visibleWidth()
+ : docSize.height() > m_scrollableArea->visibleHeight();
+
+ if (m_scrollableArea->hasOverlayScrollbars())
+ return needScrollbar;
+
+ // Will the content fit iff there are no scrollbars.
+ IntSize fullVisibleSize =
+ m_scrollableArea->visibleContentRect(IncludeScrollbars).size();
+ bool needNewScrollbar = orientation == HorizontalScrollbar
+ ? docSize.width() <= fullVisibleSize.width()
+ : docSize.height() <= fullVisibleSize.height();
+ if (option == FirstPass && needNewScrollbar)
+ needScrollbar = false;
+
+ return needScrollbar;
+}
+
+void FrameView::ScrollbarManager::updateScrollbarGeometry(IntSize viewSize) {
+ if (!hasHorizontalScrollbar() && !hasVerticalScrollbar())
+ return;
+
+ bool scrollbarOnLeft = m_scrollableArea->shouldPlaceVerticalScrollbarOnLeft();
+
+ if (hasHorizontalScrollbar()) {
+ int thickness = m_hBar->scrollbarThickness();
+ IntRect oldRect(m_hBar->frameRect());
+ IntRect hBarRect(
+ (scrollbarOnLeft && hasVerticalScrollbar()) ? m_vBar->width() : 0,
+ viewSize.height() - thickness,
+ viewSize.width() - (hasVerticalScrollbar() ? m_vBar->width() : 0),
+ thickness);
+ m_hBar->setFrameRect(hBarRect);
+ if (oldRect != m_hBar->frameRect())
+ m_scrollableArea->setScrollbarNeedsPaintInvalidation(HorizontalScrollbar);
+
+ int visibleWidth = m_scrollableArea->visibleWidth();
+ int contentsWidth = m_scrollableArea->contentsSize().width();
+ m_hBar->setEnabled(contentsWidth > visibleWidth);
+ m_hBar->setProportion(visibleWidth, contentsWidth);
+ m_hBar->offsetDidChange();
+ }
+
+ if (hasVerticalScrollbar()) {
+ int thickness = m_vBar->scrollbarThickness();
+ IntRect oldRect(m_vBar->frameRect());
+ IntRect vBarRect(
+ scrollbarOnLeft ? 0 : (viewSize.width() - thickness), 0, thickness,
+ viewSize.height() - (hasHorizontalScrollbar() ? m_hBar->height() : 0));
+ m_vBar->setFrameRect(vBarRect);
+ if (oldRect != m_vBar->frameRect())
+ m_scrollableArea->setScrollbarNeedsPaintInvalidation(VerticalScrollbar);
+
+ int clientHeight = m_scrollableArea->visibleHeight();
+ int contentsHeight = m_scrollableArea->contentsSize().height();
+ m_vBar->setEnabled(contentsHeight > clientHeight);
+ m_vBar->setProportion(clientHeight, contentsHeight);
+ m_vBar->offsetDidChange();
+ }
+}
+
void FrameView::recalculateCustomScrollbarStyle() {
bool didStyleChange = false;
if (horizontalScrollbar() && horizontalScrollbar()->isCustomScrollbar()) {
@@ -424,7 +491,7 @@ void FrameView::recalculateCustomScrollbarStyle() {
didStyleChange = true;
}
if (didStyleChange) {
- updateScrollbarGeometry();
+ m_scrollbarManager.updateScrollbarGeometry(size());
updateScrollCorner();
positionScrollbarLayers();
}
@@ -758,7 +825,7 @@ void FrameView::recalcOverflowAfterStyleChange() {
}
adjustViewSize();
- updateScrollbarGeometry();
+ m_scrollbarManager.updateScrollbarGeometry(size());
if (scrollOriginChanged())
setNeedsLayout();
@@ -2359,6 +2426,16 @@ void FrameView::invalidatePaintForTickmarks() {
static_cast<ScrollbarPart>(~ThumbPart));
}
+void FrameView::setTickmarks(const Vector<IntRect>& tickmarks) {
+ // Tickmarks for main frame are stored in RFV.
+ if (m_frame->isMainFrame())
+ m_viewportScrollableArea->setTickmarks(tickmarks);
+ else
+ m_tickmarks = tickmarks;
+
+ invalidatePaintForTickmarks();
+}
+
void FrameView::getTickmarks(Vector<IntRect>& tickmarks) const {
if (!m_tickmarks.isEmpty())
tickmarks = m_tickmarks;
@@ -2522,6 +2599,8 @@ void FrameView::didAttachDocument() {
RootFrameViewport::create(visualViewport, *layoutViewport);
m_viewportScrollableArea = rootFrameViewport;
+ m_scrollbarManager.setScroller(rootFrameViewport);
+
frameHost->globalRootScrollerController().initializeViewportScrollCallback(
*rootFrameViewport);
}
@@ -3661,12 +3740,6 @@ void FrameView::clearScrollAnchor() {
m_scrollAnchor.clear();
}
-bool FrameView::hasOverlayScrollbars() const {
- return (horizontalScrollbar() &&
- horizontalScrollbar()->isOverlayScrollbar()) ||
- (verticalScrollbar() && verticalScrollbar()->isOverlayScrollbar());
-}
-
void FrameView::computeScrollbarExistence(
bool& newHasHorizontalScrollbar,
bool& newHasVerticalScrollbar,
@@ -3699,64 +3772,13 @@ void FrameView::computeScrollbarExistence(
(hScroll != ScrollbarAuto && vScroll != ScrollbarAuto))
return;
- if (hScroll == ScrollbarAuto)
- newHasHorizontalScrollbar = docSize.width() > visibleWidth();
- if (vScroll == ScrollbarAuto)
- newHasVerticalScrollbar = docSize.height() > visibleHeight();
-
- if (hasOverlayScrollbars())
- return;
-
- IntSize fullVisibleSize = visibleContentRect(IncludeScrollbars).size();
-
- bool attemptToRemoveScrollbars =
- (option == FirstPass && docSize.width() <= fullVisibleSize.width() &&
- docSize.height() <= fullVisibleSize.height());
- if (attemptToRemoveScrollbars) {
- if (hScroll == ScrollbarAuto)
- newHasHorizontalScrollbar = false;
- if (vScroll == ScrollbarAuto)
- newHasVerticalScrollbar = false;
- }
-}
-
-void FrameView::updateScrollbarGeometry() {
- if (horizontalScrollbar()) {
- int thickness = horizontalScrollbar()->scrollbarThickness();
- int clientWidth = visibleWidth();
- IntRect oldRect(horizontalScrollbar()->frameRect());
- IntRect hBarRect(
- (shouldPlaceVerticalScrollbarOnLeft() && verticalScrollbar())
- ? verticalScrollbar()->width()
- : 0,
- height() - thickness,
- width() - (verticalScrollbar() ? verticalScrollbar()->width() : 0),
- thickness);
- horizontalScrollbar()->setFrameRect(hBarRect);
- if (oldRect != horizontalScrollbar()->frameRect())
- setScrollbarNeedsPaintInvalidation(HorizontalScrollbar);
-
- horizontalScrollbar()->setEnabled(contentsWidth() > clientWidth);
- horizontalScrollbar()->setProportion(clientWidth, contentsWidth());
- horizontalScrollbar()->offsetDidChange();
+ if (hScroll == ScrollbarAuto) {
+ newHasHorizontalScrollbar =
+ m_scrollbarManager.needScrollbar(HorizontalScrollbar, docSize, option);
}
-
- if (verticalScrollbar()) {
- int thickness = verticalScrollbar()->scrollbarThickness();
- int clientHeight = visibleHeight();
- IntRect oldRect(verticalScrollbar()->frameRect());
- IntRect vBarRect(
- shouldPlaceVerticalScrollbarOnLeft() ? 0 : (width() - thickness), 0,
- thickness,
- height() -
- (horizontalScrollbar() ? horizontalScrollbar()->height() : 0));
- verticalScrollbar()->setFrameRect(vBarRect);
- if (oldRect != verticalScrollbar()->frameRect())
- setScrollbarNeedsPaintInvalidation(VerticalScrollbar);
-
- verticalScrollbar()->setEnabled(contentsHeight() > clientHeight);
- verticalScrollbar()->setProportion(clientHeight, contentsHeight());
- verticalScrollbar()->offsetDidChange();
+ if (vScroll == ScrollbarAuto) {
+ newHasVerticalScrollbar =
+ m_scrollbarManager.needScrollbar(VerticalScrollbar, docSize, option);
}
}
@@ -3858,7 +3880,7 @@ void FrameView::updateScrollbars() {
scrollbarExistenceChanged = true;
}
- updateScrollbarGeometry();
+ m_scrollbarManager.updateScrollbarGeometry(size());
if (scrollbarExistenceChanged) {
// FIXME: Is frameRectsChanged really necessary here? Have any frame rects

Powered by Google App Engine
This is Rietveld 408576698