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

Unified Diff: third_party/WebKit/Source/core/paint/PaintLayerScrollableArea.cpp

Issue 1738503003: Fix overlay scroll bar color on elements with dark background (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix issue with custom scroll bar style Created 4 years, 10 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/paint/PaintLayerScrollableArea.cpp
diff --git a/third_party/WebKit/Source/core/paint/PaintLayerScrollableArea.cpp b/third_party/WebKit/Source/core/paint/PaintLayerScrollableArea.cpp
index ba2878b3f7468b7f66b5582495755e38850c1913..429ac98381cff679198e280227d64a6c4a0fdc7b 100644
--- a/third_party/WebKit/Source/core/paint/PaintLayerScrollableArea.cpp
+++ b/third_party/WebKit/Source/core/paint/PaintLayerScrollableArea.cpp
@@ -839,6 +839,19 @@ void PaintLayerScrollableArea::updateAfterStyleChange(const ComputedStyle* oldSt
updateScrollCornerStyle();
updateResizerAreaSet();
updateResizerStyle();
+
+ // Whenever background changes on the scrollable element, the scroll bar
+ // overlay style might need to be changed to have contrast against the
+ // background.
+ Color oldBackground;
+ if (oldStyle) {
+ oldBackground = oldStyle->visitedDependentColor(CSSPropertyBackgroundColor);
+ }
+ Color newBackground = box().style()->visitedDependentColor(CSSPropertyBackgroundColor);
+
+ if (newBackground != oldBackground) {
+ recalculateScrollbarOverlayStyle(newBackground);
+ }
}
bool PaintLayerScrollableArea::updateAfterCompositingChange()
@@ -961,10 +974,16 @@ static inline const LayoutObject& layoutObjectForScrollbar(const LayoutObject& l
return layoutObject;
}
+bool PaintLayerScrollableArea::useCustomScrollbarStyle() const
+{
+ const LayoutObject& actualLayoutObject = layoutObjectForScrollbar(box());
+ return actualLayoutObject.isBox() && actualLayoutObject.styleRef().hasPseudoStyle(SCROLLBAR);
+}
+
bool PaintLayerScrollableArea::needsScrollbarReconstruction() const
{
const LayoutObject& actualLayoutObject = layoutObjectForScrollbar(box());
- bool shouldUseCustom = actualLayoutObject.isBox() && actualLayoutObject.styleRef().hasPseudoStyle(SCROLLBAR);
+ bool shouldUseCustom = useCustomScrollbarStyle();
bool hasAnyScrollbar = hasScrollbar();
bool hasCustom = (hasHorizontalScrollbar() && horizontalScrollbar()->isCustomScrollbar()) || (hasVerticalScrollbar() && verticalScrollbar()->isCustomScrollbar());
bool didCustomScrollbarOwnerChanged = false;
@@ -989,7 +1008,7 @@ void PaintLayerScrollableArea::setHasHorizontalScrollbar(bool hasScrollbar)
setScrollbarNeedsPaintInvalidation(HorizontalScrollbar);
- m_scrollbarManager.setHasHorizontalScrollbar(hasScrollbar);
+ m_scrollbarManager.setHasHorizontalScrollbar(hasScrollbar, useCustomScrollbarStyle());
// Destroying or creating one bar can cause our scrollbar corner to come and go. We need to update the opposite scrollbar's style.
if (hasHorizontalScrollbar())
@@ -1011,7 +1030,7 @@ void PaintLayerScrollableArea::setHasVerticalScrollbar(bool hasScrollbar)
setScrollbarNeedsPaintInvalidation(VerticalScrollbar);
- m_scrollbarManager.setHasVerticalScrollbar(hasScrollbar);
+ m_scrollbarManager.setHasVerticalScrollbar(hasScrollbar, useCustomScrollbarStyle());
// Destroying or creating one bar can cause our scrollbar corner to come and go. We need to update the opposite scrollbar's style.
if (hasHorizontalScrollbar())
@@ -1475,15 +1494,21 @@ void PaintLayerScrollableArea::ScrollbarManager::setCanDetachScrollbars(bool det
}
}
-void PaintLayerScrollableArea::ScrollbarManager::setHasHorizontalScrollbar(bool hasScrollbar)
+void PaintLayerScrollableArea::ScrollbarManager::setHasHorizontalScrollbar(bool hasScrollbar, bool useCustomScrollbarStyle)
{
if (hasScrollbar) {
// This doesn't hit in any tests, but since the equivalent code in setHasVerticalScrollbar
// does, presumably this code does as well.
DisableCompositingQueryAsserts disabler;
- if (!m_hBar)
- m_hBar = createScrollbar(HorizontalScrollbar);
- m_hBarIsAttached = 1;
+ if (!m_hBar) {
+ m_hBar = createScrollbar(HorizontalScrollbar, useCustomScrollbarStyle);
+ m_hBarIsAttached = 1;
+ if (!useCustomScrollbarStyle)
+ m_scrollableArea->didAddScrollbar(*m_hBar, HorizontalScrollbar);
Xianzhu 2016/03/02 00:03:50 I suggest to check the condition in ScrollableArea
+ } else {
+ m_hBarIsAttached = 1;
+ }
+
} else {
m_hBarIsAttached = 0;
if (!m_canDetachScrollbars)
@@ -1491,13 +1516,19 @@ void PaintLayerScrollableArea::ScrollbarManager::setHasHorizontalScrollbar(bool
}
}
-void PaintLayerScrollableArea::ScrollbarManager::setHasVerticalScrollbar(bool hasScrollbar)
+void PaintLayerScrollableArea::ScrollbarManager::setHasVerticalScrollbar(bool hasScrollbar, bool useCustomScrollbarStyle)
{
if (hasScrollbar) {
DisableCompositingQueryAsserts disabler;
- if (!m_vBar)
- m_vBar = createScrollbar(VerticalScrollbar);
- m_vBarIsAttached = 1;
+ if (!m_vBar) {
+ m_vBar = createScrollbar(VerticalScrollbar, useCustomScrollbarStyle);
+ m_vBarIsAttached = 1;
+ if (!useCustomScrollbarStyle)
+ m_scrollableArea->didAddScrollbar(*m_vBar, VerticalScrollbar);
+ } else {
+ m_vBarIsAttached = 1;
+ }
+
} else {
m_vBarIsAttached = 0;
if (!m_canDetachScrollbars)
@@ -1505,23 +1536,18 @@ void PaintLayerScrollableArea::ScrollbarManager::setHasVerticalScrollbar(bool ha
}
}
-PassRefPtrWillBeRawPtr<Scrollbar> PaintLayerScrollableArea::ScrollbarManager::createScrollbar(ScrollbarOrientation orientation)
+PassRefPtrWillBeRawPtr<Scrollbar> PaintLayerScrollableArea::ScrollbarManager::createScrollbar(ScrollbarOrientation orientation, bool useCustomScrollbarStyle)
Xianzhu 2016/03/02 00:03:50 I suggest to avoid the new parameter and call useC
{
ASSERT(orientation == HorizontalScrollbar ? !m_hBarIsAttached : !m_vBarIsAttached);
RefPtrWillBeRawPtr<Scrollbar> scrollbar = nullptr;
const LayoutObject& actualLayoutObject = layoutObjectForScrollbar(m_scrollableArea->box());
- bool hasCustomScrollbarStyle = actualLayoutObject.isBox() && actualLayoutObject.styleRef().hasPseudoStyle(SCROLLBAR);
- if (hasCustomScrollbarStyle) {
+ if (useCustomScrollbarStyle) {
scrollbar = LayoutScrollbar::createCustomScrollbar(m_scrollableArea.get(), orientation, actualLayoutObject.node());
} else {
ScrollbarControlSize scrollbarSize = RegularScrollbar;
if (actualLayoutObject.styleRef().hasAppearance())
scrollbarSize = LayoutTheme::theme().scrollbarControlSizeForPart(actualLayoutObject.styleRef().appearance());
scrollbar = Scrollbar::create(m_scrollableArea.get(), orientation, scrollbarSize, &m_scrollableArea->box().frame()->page()->chromeClient());
- if (orientation == HorizontalScrollbar)
- m_scrollableArea->didAddScrollbar(*scrollbar, HorizontalScrollbar);
- else
- m_scrollableArea->didAddScrollbar(*scrollbar, VerticalScrollbar);
}
m_scrollableArea->box().document().view()->addChild(scrollbar.get());
return scrollbar.release();

Powered by Google App Engine
This is Rietveld 408576698