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

Side by Side 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights reserved.
3 * 3 *
4 * Portions are Copyright (C) 1998 Netscape Communications Corporation. 4 * Portions are Copyright (C) 1998 Netscape Communications Corporation.
5 * 5 *
6 * Other contributors: 6 * Other contributors:
7 * Robert O'Callahan <roc+@cs.cmu.edu> 7 * Robert O'Callahan <roc+@cs.cmu.edu>
8 * David Baron <dbaron@fas.harvard.edu> 8 * David Baron <dbaron@fas.harvard.edu>
9 * Christian Biesinger <cbiesinger@gmail.com> 9 * Christian Biesinger <cbiesinger@gmail.com>
10 * Randall Jesup <rjesup@wgate.com> 10 * Randall Jesup <rjesup@wgate.com>
(...skipping 821 matching lines...) Expand 10 before | Expand all | Expand 10 after
832 832
833 // FIXME: Need to detect a swap from custom to native scrollbars (and vice v ersa). 833 // FIXME: Need to detect a swap from custom to native scrollbars (and vice v ersa).
834 if (horizontalScrollbar()) 834 if (horizontalScrollbar())
835 horizontalScrollbar()->styleChanged(); 835 horizontalScrollbar()->styleChanged();
836 if (verticalScrollbar()) 836 if (verticalScrollbar())
837 verticalScrollbar()->styleChanged(); 837 verticalScrollbar()->styleChanged();
838 838
839 updateScrollCornerStyle(); 839 updateScrollCornerStyle();
840 updateResizerAreaSet(); 840 updateResizerAreaSet();
841 updateResizerStyle(); 841 updateResizerStyle();
842
843 // Whenever background changes on the scrollable element, the scroll bar
844 // overlay style might need to be changed to have contrast against the
845 // background.
846 Color oldBackground;
847 if (oldStyle) {
848 oldBackground = oldStyle->visitedDependentColor(CSSPropertyBackgroundCol or);
849 }
850 Color newBackground = box().style()->visitedDependentColor(CSSPropertyBackgr oundColor);
851
852 if (newBackground != oldBackground) {
853 ScrollbarOverlayStyle oldOverlayStyle = scrollbarOverlayStyle();
854 ScrollbarOverlayStyle overlayStyle = ScrollbarOverlayStyleDefault;
855
856 // Reduce the background color from RGB to a lightness value
857 // and determine which scrollbar style to use based on a lightness
858 // heuristic.
859 double hue, saturation, lightness;
860 newBackground.getHSL(hue, saturation, lightness);
861 if (lightness <= .5)
862 overlayStyle = ScrollbarOverlayStyleLight;
863
864 if (oldOverlayStyle != overlayStyle)
865 setScrollbarOverlayStyle(overlayStyle);
866 }
Xianzhu 2016/02/24 23:48:26 Can you extract common code in here and in FrameVi
842 } 867 }
843 868
844 bool PaintLayerScrollableArea::updateAfterCompositingChange() 869 bool PaintLayerScrollableArea::updateAfterCompositingChange()
845 { 870 {
846 layer()->updateScrollingStateAfterCompositingChange(); 871 layer()->updateScrollingStateAfterCompositingChange();
847 const bool layersChanged = m_topmostScrollChild != m_nextTopmostScrollChild; 872 const bool layersChanged = m_topmostScrollChild != m_nextTopmostScrollChild;
848 m_topmostScrollChild = m_nextTopmostScrollChild; 873 m_topmostScrollChild = m_nextTopmostScrollChild;
849 m_nextTopmostScrollChild = nullptr; 874 m_nextTopmostScrollChild = nullptr;
850 return layersChanged; 875 return layersChanged;
851 } 876 }
(...skipping 622 matching lines...) Expand 10 before | Expand all | Expand 10 after
1474 destroyScrollbar(VerticalScrollbar); 1499 destroyScrollbar(VerticalScrollbar);
1475 } 1500 }
1476 } 1501 }
1477 1502
1478 void PaintLayerScrollableArea::ScrollbarManager::setHasHorizontalScrollbar(bool hasScrollbar) 1503 void PaintLayerScrollableArea::ScrollbarManager::setHasHorizontalScrollbar(bool hasScrollbar)
1479 { 1504 {
1480 if (hasScrollbar) { 1505 if (hasScrollbar) {
1481 // This doesn't hit in any tests, but since the equivalent code in setHa sVerticalScrollbar 1506 // This doesn't hit in any tests, but since the equivalent code in setHa sVerticalScrollbar
1482 // does, presumably this code does as well. 1507 // does, presumably this code does as well.
1483 DisableCompositingQueryAsserts disabler; 1508 DisableCompositingQueryAsserts disabler;
1484 if (!m_hBar) 1509 if (!m_hBar) {
1485 m_hBar = createScrollbar(HorizontalScrollbar); 1510 m_hBar = createScrollbar(HorizontalScrollbar);
1486 m_hBarIsAttached = 1; 1511 m_hBarIsAttached = 1;
1512 m_scrollableArea->didAddScrollbar(*m_hBar, HorizontalScrollbar);
1513 } else {
1514 m_hBarIsAttached = 1;
1515 }
1516
1487 } else { 1517 } else {
1488 m_hBarIsAttached = 0; 1518 m_hBarIsAttached = 0;
1489 if (!m_canDetachScrollbars) 1519 if (!m_canDetachScrollbars)
1490 destroyScrollbar(HorizontalScrollbar); 1520 destroyScrollbar(HorizontalScrollbar);
1491 } 1521 }
1492 } 1522 }
1493 1523
1494 void PaintLayerScrollableArea::ScrollbarManager::setHasVerticalScrollbar(bool ha sScrollbar) 1524 void PaintLayerScrollableArea::ScrollbarManager::setHasVerticalScrollbar(bool ha sScrollbar)
1495 { 1525 {
1496 if (hasScrollbar) { 1526 if (hasScrollbar) {
1497 DisableCompositingQueryAsserts disabler; 1527 DisableCompositingQueryAsserts disabler;
1498 if (!m_vBar) 1528 if (!m_vBar) {
1499 m_vBar = createScrollbar(VerticalScrollbar); 1529 m_vBar = createScrollbar(VerticalScrollbar);
1500 m_vBarIsAttached = 1; 1530 m_vBarIsAttached = 1;
1531 m_scrollableArea->didAddScrollbar(*m_vBar, VerticalScrollbar);
1532 } else {
1533 m_vBarIsAttached = 1;
1534 }
1535
1501 } else { 1536 } else {
1502 m_vBarIsAttached = 0; 1537 m_vBarIsAttached = 0;
1503 if (!m_canDetachScrollbars) 1538 if (!m_canDetachScrollbars)
1504 destroyScrollbar(VerticalScrollbar); 1539 destroyScrollbar(VerticalScrollbar);
1505 } 1540 }
1506 } 1541 }
1507 1542
1508 PassRefPtrWillBeRawPtr<Scrollbar> PaintLayerScrollableArea::ScrollbarManager::cr eateScrollbar(ScrollbarOrientation orientation) 1543 PassRefPtrWillBeRawPtr<Scrollbar> PaintLayerScrollableArea::ScrollbarManager::cr eateScrollbar(ScrollbarOrientation orientation)
1509 { 1544 {
1510 ASSERT(orientation == HorizontalScrollbar ? !m_hBarIsAttached : !m_vBarIsAtt ached); 1545 ASSERT(orientation == HorizontalScrollbar ? !m_hBarIsAttached : !m_vBarIsAtt ached);
1511 RefPtrWillBeRawPtr<Scrollbar> scrollbar = nullptr; 1546 RefPtrWillBeRawPtr<Scrollbar> scrollbar = nullptr;
1512 const LayoutObject& actualLayoutObject = layoutObjectForScrollbar(m_scrollab leArea->box()); 1547 const LayoutObject& actualLayoutObject = layoutObjectForScrollbar(m_scrollab leArea->box());
1513 bool hasCustomScrollbarStyle = actualLayoutObject.isBox() && actualLayoutObj ect.styleRef().hasPseudoStyle(SCROLLBAR); 1548 bool hasCustomScrollbarStyle = actualLayoutObject.isBox() && actualLayoutObj ect.styleRef().hasPseudoStyle(SCROLLBAR);
1514 if (hasCustomScrollbarStyle) { 1549 if (hasCustomScrollbarStyle) {
1515 scrollbar = LayoutScrollbar::createCustomScrollbar(m_scrollableArea.get( ), orientation, actualLayoutObject.node()); 1550 scrollbar = LayoutScrollbar::createCustomScrollbar(m_scrollableArea.get( ), orientation, actualLayoutObject.node());
1516 } else { 1551 } else {
1517 ScrollbarControlSize scrollbarSize = RegularScrollbar; 1552 ScrollbarControlSize scrollbarSize = RegularScrollbar;
1518 if (actualLayoutObject.styleRef().hasAppearance()) 1553 if (actualLayoutObject.styleRef().hasAppearance())
1519 scrollbarSize = LayoutTheme::theme().scrollbarControlSizeForPart(act ualLayoutObject.styleRef().appearance()); 1554 scrollbarSize = LayoutTheme::theme().scrollbarControlSizeForPart(act ualLayoutObject.styleRef().appearance());
1520 scrollbar = Scrollbar::create(m_scrollableArea.get(), orientation, scrol lbarSize, &m_scrollableArea->box().frame()->page()->chromeClient()); 1555 scrollbar = Scrollbar::create(m_scrollableArea.get(), orientation, scrol lbarSize, &m_scrollableArea->box().frame()->page()->chromeClient());
1521 if (orientation == HorizontalScrollbar)
1522 m_scrollableArea->didAddScrollbar(*scrollbar, HorizontalScrollbar);
1523 else
1524 m_scrollableArea->didAddScrollbar(*scrollbar, VerticalScrollbar);
1525 } 1556 }
1526 m_scrollableArea->box().document().view()->addChild(scrollbar.get()); 1557 m_scrollableArea->box().document().view()->addChild(scrollbar.get());
1527 return scrollbar.release(); 1558 return scrollbar.release();
1528 } 1559 }
1529 1560
1530 void PaintLayerScrollableArea::ScrollbarManager::destroyScrollbar(ScrollbarOrien tation orientation) 1561 void PaintLayerScrollableArea::ScrollbarManager::destroyScrollbar(ScrollbarOrien tation orientation)
1531 { 1562 {
1532 RefPtrWillBeMember<Scrollbar>& scrollbar = orientation == HorizontalScrollba r ? m_hBar : m_vBar; 1563 RefPtrWillBeMember<Scrollbar>& scrollbar = orientation == HorizontalScrollba r ? m_hBar : m_vBar;
1533 ASSERT(orientation == HorizontalScrollbar ? !m_hBarIsAttached: !m_vBarIsAtta ched); 1564 ASSERT(orientation == HorizontalScrollbar ? !m_hBarIsAttached: !m_vBarIsAtta ched);
1534 if (!scrollbar) 1565 if (!scrollbar)
(...skipping 14 matching lines...) Expand all
1549 } 1580 }
1550 1581
1551 DEFINE_TRACE(PaintLayerScrollableArea::ScrollbarManager) 1582 DEFINE_TRACE(PaintLayerScrollableArea::ScrollbarManager)
1552 { 1583 {
1553 visitor->trace(m_scrollableArea); 1584 visitor->trace(m_scrollableArea);
1554 visitor->trace(m_hBar); 1585 visitor->trace(m_hBar);
1555 visitor->trace(m_vBar); 1586 visitor->trace(m_vBar);
1556 } 1587 }
1557 1588
1558 } // namespace blink 1589 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698