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

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: 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..1b735f104b2d23c200b07fccdfa3250e5689f907 100644
--- a/third_party/WebKit/Source/core/paint/PaintLayerScrollableArea.cpp
+++ b/third_party/WebKit/Source/core/paint/PaintLayerScrollableArea.cpp
@@ -839,6 +839,31 @@ 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) {
+ ScrollbarOverlayStyle oldOverlayStyle = scrollbarOverlayStyle();
+ ScrollbarOverlayStyle overlayStyle = ScrollbarOverlayStyleDefault;
+
+ // Reduce the background color from RGB to a lightness value
+ // and determine which scrollbar style to use based on a lightness
+ // heuristic.
+ double hue, saturation, lightness;
+ newBackground.getHSL(hue, saturation, lightness);
+ if (lightness <= .5)
+ overlayStyle = ScrollbarOverlayStyleLight;
+
+ if (oldOverlayStyle != overlayStyle)
+ setScrollbarOverlayStyle(overlayStyle);
+ }
Xianzhu 2016/02/24 23:48:26 Can you extract common code in here and in FrameVi
}
bool PaintLayerScrollableArea::updateAfterCompositingChange()
@@ -1481,9 +1506,14 @@ void PaintLayerScrollableArea::ScrollbarManager::setHasHorizontalScrollbar(bool
// 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)
+ if (!m_hBar) {
m_hBar = createScrollbar(HorizontalScrollbar);
- m_hBarIsAttached = 1;
+ m_hBarIsAttached = 1;
+ m_scrollableArea->didAddScrollbar(*m_hBar, HorizontalScrollbar);
+ } else {
+ m_hBarIsAttached = 1;
+ }
+
} else {
m_hBarIsAttached = 0;
if (!m_canDetachScrollbars)
@@ -1495,9 +1525,14 @@ void PaintLayerScrollableArea::ScrollbarManager::setHasVerticalScrollbar(bool ha
{
if (hasScrollbar) {
DisableCompositingQueryAsserts disabler;
- if (!m_vBar)
+ if (!m_vBar) {
m_vBar = createScrollbar(VerticalScrollbar);
- m_vBarIsAttached = 1;
+ m_vBarIsAttached = 1;
+ m_scrollableArea->didAddScrollbar(*m_vBar, VerticalScrollbar);
+ } else {
+ m_vBarIsAttached = 1;
+ }
+
} else {
m_vBarIsAttached = 0;
if (!m_canDetachScrollbars)
@@ -1518,10 +1553,6 @@ PassRefPtrWillBeRawPtr<Scrollbar> PaintLayerScrollableArea::ScrollbarManager::cr
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