Chromium Code Reviews| 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(); |