Commit 7eb55ee1 authored by sataya.m@samsung.com's avatar sataya.m@samsung.com

Create custom scrollbars when html element has overflow:scroll

custom scrollbars are not created when html element has overflow:scroll
style. Reconstruct scrollbars from native to custom scrollbar when 
html element has overflow:scroll style. 

BUG=518757

Review URL: https://codereview.chromium.org/1292513002

git-svn-id: svn://svn.chromium.org/blink/trunk@201039 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 8dfc3c87
<!DOCTYPE HTML>
<style>
::-webkit-scrollbar {
width: 100px;
height: 10px;
}
::-webkit-scrollbar-track {
-webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3);
-webkit-border-radius: 10px;
border-radius: 10px;
}
::-webkit-scrollbar-thumb {
-webkit-border-radius: 1px;
background: rgba(255,0,0,0.8);
-webkit-box-shadow: inset 0 0 1px rgba(255,250,0,0.5);
}
#space {
width: 1000px;
height: 1000px;
}
html {
overflow: scroll;
}
</style>
<div id="space"></div>
\ No newline at end of file
<!DOCTYPE HTML>
<style>
::-webkit-scrollbar {
width: 10px;
height: 10px;
}
::-webkit-scrollbar-track {
-webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3);
-webkit-border-radius: 10px;
border-radius: 10px;
}
::-webkit-scrollbar-thumb {
-webkit-border-radius: 1px;
background: rgba(255,0,0,0.8);
-webkit-box-shadow: inset 0 0 1px rgba(255,250,0,0.5);
}
#space {
width: 1000px;
height: 1000px;
}
html {
overflow: scroll;
}
</style>
<div id="space"></div>
<script>
var styleElement = document.createElement("style");
var sheet = document.head.appendChild(styleElement).sheet;
document.body.offsetTop;
sheet.insertRule("::-webkit-scrollbar { width: 100px;}", 0);
</script>
\ No newline at end of file
...@@ -646,6 +646,13 @@ void DeprecatedPaintLayerScrollableArea::updateAfterLayout() ...@@ -646,6 +646,13 @@ void DeprecatedPaintLayerScrollableArea::updateAfterLayout()
{ {
ASSERT(box().hasOverflowClip()); ASSERT(box().hasOverflowClip());
if (needsScrollbarReconstruction()) {
if (m_hBar)
destroyScrollbar(HorizontalScrollbar);
if (m_vBar)
destroyScrollbar(VerticalScrollbar);
}
DoubleSize originalScrollOffset = adjustedScrollOffset(); DoubleSize originalScrollOffset = adjustedScrollOffset();
computeScrollDimensions(); computeScrollDimensions();
...@@ -673,21 +680,18 @@ void DeprecatedPaintLayerScrollableArea::updateAfterLayout() ...@@ -673,21 +680,18 @@ void DeprecatedPaintLayerScrollableArea::updateAfterLayout()
if (box().style()->overflowY() == OSCROLL && verticalScrollbar()) if (box().style()->overflowY() == OSCROLL && verticalScrollbar())
verticalScrollbar()->setEnabled(hasVerticalOverflow); verticalScrollbar()->setEnabled(hasVerticalOverflow);
} }
if (hasOverlayScrollbars()) {
if (!scrollSize(HorizontalScrollbar))
setHasHorizontalScrollbar(false);
if (!scrollSize(VerticalScrollbar))
setHasVerticalScrollbar(false);
}
// overflow:auto may need to lay out again if scrollbars got added/removed.
bool autoHorizontalScrollBarChanged = box().hasAutoHorizontalScrollbar() && (hasHorizontalScrollbar() != hasHorizontalOverflow);
bool autoVerticalScrollBarChanged = box().hasAutoVerticalScrollbar() && (hasVerticalScrollbar() != hasVerticalOverflow);
if (!visualViewportSuppliesScrollbars() && (autoHorizontalScrollBarChanged || autoVerticalScrollBarChanged)) { // We need to layout again if scrollbars are added or removed by overflow:auto,
if (box().hasAutoHorizontalScrollbar()) // or by changing between native and custom.
setHasHorizontalScrollbar(hasHorizontalOverflow); bool horizontalScrollBarChanged = (box().hasAutoHorizontalScrollbar() && (hasHorizontalScrollbar() != hasHorizontalOverflow))
if (box().hasAutoVerticalScrollbar()) || (box().style()->overflowX() == OSCROLL && !horizontalScrollbar());
setHasVerticalScrollbar(hasVerticalOverflow); bool verticalScrollBarChanged = (box().hasAutoVerticalScrollbar() && (hasVerticalScrollbar() != hasVerticalOverflow))
|| (box().style()->overflowY() == OSCROLL && !verticalScrollbar());
if (!visualViewportSuppliesScrollbars() && (horizontalScrollBarChanged || verticalScrollBarChanged)) {
if (box().hasAutoHorizontalScrollbar() || (box().style()->overflowX() == OSCROLL && !horizontalScrollbar()))
setHasHorizontalScrollbar(box().style()->overflowX() == OSCROLL ? true : hasHorizontalOverflow);
if (box().hasAutoVerticalScrollbar() || (box().style()->overflowY() == OSCROLL && !verticalScrollbar()))
setHasVerticalScrollbar(box().style()->overflowY() == OSCROLL ? true : hasVerticalOverflow);
if (hasVerticalOverflow || hasHorizontalOverflow) if (hasVerticalOverflow || hasHorizontalOverflow)
updateScrollCornerStyle(); updateScrollCornerStyle();
...@@ -698,15 +702,15 @@ void DeprecatedPaintLayerScrollableArea::updateAfterLayout() ...@@ -698,15 +702,15 @@ void DeprecatedPaintLayerScrollableArea::updateAfterLayout()
if (box().document().hasAnnotatedRegions()) if (box().document().hasAnnotatedRegions())
box().document().setAnnotatedRegionsDirty(true); box().document().setAnnotatedRegionsDirty(true);
if (box().style()->overflowX() == OAUTO || box().style()->overflowY() == OAUTO) { // Our proprietary overflow: overlay value doesn't trigger a layout.
if ((horizontalScrollBarChanged && box().style()->overflowX() != OOVERLAY) || (verticalScrollBarChanged && box().style()->overflowY() != OOVERLAY)) {
if (!m_inOverflowRelayout) { if (!m_inOverflowRelayout) {
// Our proprietary overflow: overlay value doesn't trigger a layout.
m_inOverflowRelayout = true; m_inOverflowRelayout = true;
SubtreeLayoutScope layoutScope(box()); SubtreeLayoutScope layoutScope(box());
layoutScope.setNeedsLayout(&box(), LayoutInvalidationReason::ScrollbarChanged); layoutScope.setNeedsLayout(&box(), LayoutInvalidationReason::ScrollbarChanged);
if (box().isLayoutBlock()) { if (box().isLayoutBlock()) {
LayoutBlock& block = toLayoutBlock(box()); LayoutBlock& block = toLayoutBlock(box());
block.scrollbarsChanged(autoHorizontalScrollBarChanged, autoVerticalScrollBarChanged); block.scrollbarsChanged(horizontalScrollBarChanged, verticalScrollBarChanged);
block.layoutBlock(true); block.layoutBlock(true);
} else { } else {
box().layout(); box().layout();
...@@ -731,6 +735,13 @@ void DeprecatedPaintLayerScrollableArea::updateAfterLayout() ...@@ -731,6 +735,13 @@ void DeprecatedPaintLayerScrollableArea::updateAfterLayout()
} }
} }
if (hasOverlayScrollbars()) {
if (!scrollSize(HorizontalScrollbar))
setHasHorizontalScrollbar(false);
if (!scrollSize(VerticalScrollbar))
setHasVerticalScrollbar(false);
}
bool hasOverflow = hasScrollableHorizontalOverflow() || hasScrollableVerticalOverflow(); bool hasOverflow = hasScrollableHorizontalOverflow() || hasScrollableVerticalOverflow();
updateScrollableAreaSet(hasOverflow); updateScrollableAreaSet(hasOverflow);
...@@ -958,6 +969,15 @@ static inline LayoutObject* layoutObjectForScrollbar(LayoutObject& layoutObject) ...@@ -958,6 +969,15 @@ static inline LayoutObject* layoutObjectForScrollbar(LayoutObject& layoutObject)
return &layoutObject; return &layoutObject;
} }
bool DeprecatedPaintLayerScrollableArea::needsScrollbarReconstruction() const
{
LayoutObject* actualLayoutObject = layoutObjectForScrollbar(box());
bool shouldUseCustom = actualLayoutObject->isBox() && actualLayoutObject->style()->hasPseudoStyle(SCROLLBAR);
bool hasAnyScrollbar = hasScrollbar();
bool hasCustom = (m_hBar && m_hBar->isCustomScrollbar()) || (m_vBar && m_vBar->isCustomScrollbar());
return hasAnyScrollbar && (shouldUseCustom != hasCustom);
}
PassRefPtrWillBeRawPtr<Scrollbar> DeprecatedPaintLayerScrollableArea::createScrollbar(ScrollbarOrientation orientation) PassRefPtrWillBeRawPtr<Scrollbar> DeprecatedPaintLayerScrollableArea::createScrollbar(ScrollbarOrientation orientation)
{ {
RefPtrWillBeRawPtr<Scrollbar> widget = nullptr; RefPtrWillBeRawPtr<Scrollbar> widget = nullptr;
......
...@@ -234,6 +234,8 @@ private: ...@@ -234,6 +234,8 @@ private:
bool hasScrollableVerticalOverflow() const; bool hasScrollableVerticalOverflow() const;
bool visualViewportSuppliesScrollbars() const; bool visualViewportSuppliesScrollbars() const;
bool needsScrollbarReconstruction() const;
void computeScrollDimensions(); void computeScrollDimensions();
// TODO(bokan): This method hides the base class version and is subtly different. // TODO(bokan): This method hides the base class version and is subtly different.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment