Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 recalculateScrollbarOverlayStyle(newBackground); | |
| 854 } | |
| 842 } | 855 } |
| 843 | 856 |
| 844 bool PaintLayerScrollableArea::updateAfterCompositingChange() | 857 bool PaintLayerScrollableArea::updateAfterCompositingChange() |
| 845 { | 858 { |
| 846 layer()->updateScrollingStateAfterCompositingChange(); | 859 layer()->updateScrollingStateAfterCompositingChange(); |
| 847 const bool layersChanged = m_topmostScrollChild != m_nextTopmostScrollChild; | 860 const bool layersChanged = m_topmostScrollChild != m_nextTopmostScrollChild; |
| 848 m_topmostScrollChild = m_nextTopmostScrollChild; | 861 m_topmostScrollChild = m_nextTopmostScrollChild; |
| 849 m_nextTopmostScrollChild = nullptr; | 862 m_nextTopmostScrollChild = nullptr; |
| 850 return layersChanged; | 863 return layersChanged; |
| 851 } | 864 } |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 954 | 967 |
| 955 if (ShadowRoot* shadowRoot = node->containingShadowRoot()) { | 968 if (ShadowRoot* shadowRoot = node->containingShadowRoot()) { |
| 956 if (shadowRoot->type() == ShadowRootType::UserAgent) | 969 if (shadowRoot->type() == ShadowRootType::UserAgent) |
| 957 return *shadowRoot->host()->layoutObject(); | 970 return *shadowRoot->host()->layoutObject(); |
| 958 } | 971 } |
| 959 } | 972 } |
| 960 | 973 |
| 961 return layoutObject; | 974 return layoutObject; |
| 962 } | 975 } |
| 963 | 976 |
| 977 bool PaintLayerScrollableArea::useCustomScrollbarStyle() const | |
| 978 { | |
| 979 const LayoutObject& actualLayoutObject = layoutObjectForScrollbar(box()); | |
| 980 return actualLayoutObject.isBox() && actualLayoutObject.styleRef().hasPseudo Style(SCROLLBAR); | |
| 981 } | |
| 982 | |
| 964 bool PaintLayerScrollableArea::needsScrollbarReconstruction() const | 983 bool PaintLayerScrollableArea::needsScrollbarReconstruction() const |
| 965 { | 984 { |
| 966 const LayoutObject& actualLayoutObject = layoutObjectForScrollbar(box()); | 985 const LayoutObject& actualLayoutObject = layoutObjectForScrollbar(box()); |
| 967 bool shouldUseCustom = actualLayoutObject.isBox() && actualLayoutObject.styl eRef().hasPseudoStyle(SCROLLBAR); | 986 bool shouldUseCustom = useCustomScrollbarStyle(); |
| 968 bool hasAnyScrollbar = hasScrollbar(); | 987 bool hasAnyScrollbar = hasScrollbar(); |
| 969 bool hasCustom = (hasHorizontalScrollbar() && horizontalScrollbar()->isCusto mScrollbar()) || (hasVerticalScrollbar() && verticalScrollbar()->isCustomScrollb ar()); | 988 bool hasCustom = (hasHorizontalScrollbar() && horizontalScrollbar()->isCusto mScrollbar()) || (hasVerticalScrollbar() && verticalScrollbar()->isCustomScrollb ar()); |
| 970 bool didCustomScrollbarOwnerChanged = false; | 989 bool didCustomScrollbarOwnerChanged = false; |
| 971 | 990 |
| 972 if (hasHorizontalScrollbar() && horizontalScrollbar()->isCustomScrollbar()) { | 991 if (hasHorizontalScrollbar() && horizontalScrollbar()->isCustomScrollbar()) { |
| 973 if (actualLayoutObject != toLayoutScrollbar(horizontalScrollbar())->owni ngLayoutObject()) | 992 if (actualLayoutObject != toLayoutScrollbar(horizontalScrollbar())->owni ngLayoutObject()) |
| 974 didCustomScrollbarOwnerChanged = true; | 993 didCustomScrollbarOwnerChanged = true; |
| 975 } | 994 } |
| 976 | 995 |
| 977 if (hasVerticalScrollbar() && verticalScrollbar()->isCustomScrollbar()) { | 996 if (hasVerticalScrollbar() && verticalScrollbar()->isCustomScrollbar()) { |
| 978 if (actualLayoutObject != toLayoutScrollbar(verticalScrollbar())->owning LayoutObject()) | 997 if (actualLayoutObject != toLayoutScrollbar(verticalScrollbar())->owning LayoutObject()) |
| 979 didCustomScrollbarOwnerChanged = true; | 998 didCustomScrollbarOwnerChanged = true; |
| 980 } | 999 } |
| 981 | 1000 |
| 982 return hasAnyScrollbar && ((shouldUseCustom != hasCustom) || (shouldUseCusto m && didCustomScrollbarOwnerChanged)); | 1001 return hasAnyScrollbar && ((shouldUseCustom != hasCustom) || (shouldUseCusto m && didCustomScrollbarOwnerChanged)); |
| 983 } | 1002 } |
| 984 | 1003 |
| 985 void PaintLayerScrollableArea::setHasHorizontalScrollbar(bool hasScrollbar) | 1004 void PaintLayerScrollableArea::setHasHorizontalScrollbar(bool hasScrollbar) |
| 986 { | 1005 { |
| 987 if (hasScrollbar == hasHorizontalScrollbar()) | 1006 if (hasScrollbar == hasHorizontalScrollbar()) |
| 988 return; | 1007 return; |
| 989 | 1008 |
| 990 setScrollbarNeedsPaintInvalidation(HorizontalScrollbar); | 1009 setScrollbarNeedsPaintInvalidation(HorizontalScrollbar); |
| 991 | 1010 |
| 992 m_scrollbarManager.setHasHorizontalScrollbar(hasScrollbar); | 1011 m_scrollbarManager.setHasHorizontalScrollbar(hasScrollbar, useCustomScrollba rStyle()); |
| 993 | 1012 |
| 994 // Destroying or creating one bar can cause our scrollbar corner to come and go. We need to update the opposite scrollbar's style. | 1013 // Destroying or creating one bar can cause our scrollbar corner to come and go. We need to update the opposite scrollbar's style. |
| 995 if (hasHorizontalScrollbar()) | 1014 if (hasHorizontalScrollbar()) |
| 996 horizontalScrollbar()->styleChanged(); | 1015 horizontalScrollbar()->styleChanged(); |
| 997 if (hasVerticalScrollbar()) | 1016 if (hasVerticalScrollbar()) |
| 998 verticalScrollbar()->styleChanged(); | 1017 verticalScrollbar()->styleChanged(); |
| 999 | 1018 |
| 1000 setScrollCornerNeedsPaintInvalidation(); | 1019 setScrollCornerNeedsPaintInvalidation(); |
| 1001 | 1020 |
| 1002 // Force an update since we know the scrollbars have changed things. | 1021 // Force an update since we know the scrollbars have changed things. |
| 1003 if (box().document().hasAnnotatedRegions()) | 1022 if (box().document().hasAnnotatedRegions()) |
| 1004 box().document().setAnnotatedRegionsDirty(true); | 1023 box().document().setAnnotatedRegionsDirty(true); |
| 1005 } | 1024 } |
| 1006 | 1025 |
| 1007 void PaintLayerScrollableArea::setHasVerticalScrollbar(bool hasScrollbar) | 1026 void PaintLayerScrollableArea::setHasVerticalScrollbar(bool hasScrollbar) |
| 1008 { | 1027 { |
| 1009 if (hasScrollbar == hasVerticalScrollbar()) | 1028 if (hasScrollbar == hasVerticalScrollbar()) |
| 1010 return; | 1029 return; |
| 1011 | 1030 |
| 1012 setScrollbarNeedsPaintInvalidation(VerticalScrollbar); | 1031 setScrollbarNeedsPaintInvalidation(VerticalScrollbar); |
| 1013 | 1032 |
| 1014 m_scrollbarManager.setHasVerticalScrollbar(hasScrollbar); | 1033 m_scrollbarManager.setHasVerticalScrollbar(hasScrollbar, useCustomScrollbarS tyle()); |
| 1015 | 1034 |
| 1016 // Destroying or creating one bar can cause our scrollbar corner to come and go. We need to update the opposite scrollbar's style. | 1035 // Destroying or creating one bar can cause our scrollbar corner to come and go. We need to update the opposite scrollbar's style. |
| 1017 if (hasHorizontalScrollbar()) | 1036 if (hasHorizontalScrollbar()) |
| 1018 horizontalScrollbar()->styleChanged(); | 1037 horizontalScrollbar()->styleChanged(); |
| 1019 if (hasVerticalScrollbar()) | 1038 if (hasVerticalScrollbar()) |
| 1020 verticalScrollbar()->styleChanged(); | 1039 verticalScrollbar()->styleChanged(); |
| 1021 | 1040 |
| 1022 setScrollCornerNeedsPaintInvalidation(); | 1041 setScrollCornerNeedsPaintInvalidation(); |
| 1023 | 1042 |
| 1024 // Force an update since we know the scrollbars have changed things. | 1043 // Force an update since we know the scrollbars have changed things. |
| (...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1468 ASSERT(!m_vBarIsAttached || m_vBar); | 1487 ASSERT(!m_vBarIsAttached || m_vBar); |
| 1469 m_canDetachScrollbars = detach ? 1 : 0; | 1488 m_canDetachScrollbars = detach ? 1 : 0; |
| 1470 if (!detach) { | 1489 if (!detach) { |
| 1471 if (m_hBar && !m_hBarIsAttached) | 1490 if (m_hBar && !m_hBarIsAttached) |
| 1472 destroyScrollbar(HorizontalScrollbar); | 1491 destroyScrollbar(HorizontalScrollbar); |
| 1473 if (m_vBar && !m_vBarIsAttached) | 1492 if (m_vBar && !m_vBarIsAttached) |
| 1474 destroyScrollbar(VerticalScrollbar); | 1493 destroyScrollbar(VerticalScrollbar); |
| 1475 } | 1494 } |
| 1476 } | 1495 } |
| 1477 | 1496 |
| 1478 void PaintLayerScrollableArea::ScrollbarManager::setHasHorizontalScrollbar(bool hasScrollbar) | 1497 void PaintLayerScrollableArea::ScrollbarManager::setHasHorizontalScrollbar(bool hasScrollbar, bool useCustomScrollbarStyle) |
| 1479 { | 1498 { |
| 1480 if (hasScrollbar) { | 1499 if (hasScrollbar) { |
| 1481 // This doesn't hit in any tests, but since the equivalent code in setHa sVerticalScrollbar | 1500 // This doesn't hit in any tests, but since the equivalent code in setHa sVerticalScrollbar |
| 1482 // does, presumably this code does as well. | 1501 // does, presumably this code does as well. |
| 1483 DisableCompositingQueryAsserts disabler; | 1502 DisableCompositingQueryAsserts disabler; |
| 1484 if (!m_hBar) | 1503 if (!m_hBar) { |
| 1485 m_hBar = createScrollbar(HorizontalScrollbar); | 1504 m_hBar = createScrollbar(HorizontalScrollbar, useCustomScrollbarStyl e); |
| 1486 m_hBarIsAttached = 1; | 1505 m_hBarIsAttached = 1; |
| 1506 if (!useCustomScrollbarStyle) | |
| 1507 m_scrollableArea->didAddScrollbar(*m_hBar, HorizontalScrollbar); | |
|
Xianzhu
2016/03/02 00:03:50
I suggest to check the condition in ScrollableArea
| |
| 1508 } else { | |
| 1509 m_hBarIsAttached = 1; | |
| 1510 } | |
| 1511 | |
| 1487 } else { | 1512 } else { |
| 1488 m_hBarIsAttached = 0; | 1513 m_hBarIsAttached = 0; |
| 1489 if (!m_canDetachScrollbars) | 1514 if (!m_canDetachScrollbars) |
| 1490 destroyScrollbar(HorizontalScrollbar); | 1515 destroyScrollbar(HorizontalScrollbar); |
| 1491 } | 1516 } |
| 1492 } | 1517 } |
| 1493 | 1518 |
| 1494 void PaintLayerScrollableArea::ScrollbarManager::setHasVerticalScrollbar(bool ha sScrollbar) | 1519 void PaintLayerScrollableArea::ScrollbarManager::setHasVerticalScrollbar(bool ha sScrollbar, bool useCustomScrollbarStyle) |
| 1495 { | 1520 { |
| 1496 if (hasScrollbar) { | 1521 if (hasScrollbar) { |
| 1497 DisableCompositingQueryAsserts disabler; | 1522 DisableCompositingQueryAsserts disabler; |
| 1498 if (!m_vBar) | 1523 if (!m_vBar) { |
| 1499 m_vBar = createScrollbar(VerticalScrollbar); | 1524 m_vBar = createScrollbar(VerticalScrollbar, useCustomScrollbarStyle) ; |
| 1500 m_vBarIsAttached = 1; | 1525 m_vBarIsAttached = 1; |
| 1526 if (!useCustomScrollbarStyle) | |
| 1527 m_scrollableArea->didAddScrollbar(*m_vBar, VerticalScrollbar); | |
| 1528 } else { | |
| 1529 m_vBarIsAttached = 1; | |
| 1530 } | |
| 1531 | |
| 1501 } else { | 1532 } else { |
| 1502 m_vBarIsAttached = 0; | 1533 m_vBarIsAttached = 0; |
| 1503 if (!m_canDetachScrollbars) | 1534 if (!m_canDetachScrollbars) |
| 1504 destroyScrollbar(VerticalScrollbar); | 1535 destroyScrollbar(VerticalScrollbar); |
| 1505 } | 1536 } |
| 1506 } | 1537 } |
| 1507 | 1538 |
| 1508 PassRefPtrWillBeRawPtr<Scrollbar> PaintLayerScrollableArea::ScrollbarManager::cr eateScrollbar(ScrollbarOrientation orientation) | 1539 PassRefPtrWillBeRawPtr<Scrollbar> PaintLayerScrollableArea::ScrollbarManager::cr eateScrollbar(ScrollbarOrientation orientation, bool useCustomScrollbarStyle) |
|
Xianzhu
2016/03/02 00:03:50
I suggest to avoid the new parameter and call useC
| |
| 1509 { | 1540 { |
| 1510 ASSERT(orientation == HorizontalScrollbar ? !m_hBarIsAttached : !m_vBarIsAtt ached); | 1541 ASSERT(orientation == HorizontalScrollbar ? !m_hBarIsAttached : !m_vBarIsAtt ached); |
| 1511 RefPtrWillBeRawPtr<Scrollbar> scrollbar = nullptr; | 1542 RefPtrWillBeRawPtr<Scrollbar> scrollbar = nullptr; |
| 1512 const LayoutObject& actualLayoutObject = layoutObjectForScrollbar(m_scrollab leArea->box()); | 1543 const LayoutObject& actualLayoutObject = layoutObjectForScrollbar(m_scrollab leArea->box()); |
| 1513 bool hasCustomScrollbarStyle = actualLayoutObject.isBox() && actualLayoutObj ect.styleRef().hasPseudoStyle(SCROLLBAR); | 1544 if (useCustomScrollbarStyle) { |
| 1514 if (hasCustomScrollbarStyle) { | |
| 1515 scrollbar = LayoutScrollbar::createCustomScrollbar(m_scrollableArea.get( ), orientation, actualLayoutObject.node()); | 1545 scrollbar = LayoutScrollbar::createCustomScrollbar(m_scrollableArea.get( ), orientation, actualLayoutObject.node()); |
| 1516 } else { | 1546 } else { |
| 1517 ScrollbarControlSize scrollbarSize = RegularScrollbar; | 1547 ScrollbarControlSize scrollbarSize = RegularScrollbar; |
| 1518 if (actualLayoutObject.styleRef().hasAppearance()) | 1548 if (actualLayoutObject.styleRef().hasAppearance()) |
| 1519 scrollbarSize = LayoutTheme::theme().scrollbarControlSizeForPart(act ualLayoutObject.styleRef().appearance()); | 1549 scrollbarSize = LayoutTheme::theme().scrollbarControlSizeForPart(act ualLayoutObject.styleRef().appearance()); |
| 1520 scrollbar = Scrollbar::create(m_scrollableArea.get(), orientation, scrol lbarSize, &m_scrollableArea->box().frame()->page()->chromeClient()); | 1550 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 } | 1551 } |
| 1526 m_scrollableArea->box().document().view()->addChild(scrollbar.get()); | 1552 m_scrollableArea->box().document().view()->addChild(scrollbar.get()); |
| 1527 return scrollbar.release(); | 1553 return scrollbar.release(); |
| 1528 } | 1554 } |
| 1529 | 1555 |
| 1530 void PaintLayerScrollableArea::ScrollbarManager::destroyScrollbar(ScrollbarOrien tation orientation) | 1556 void PaintLayerScrollableArea::ScrollbarManager::destroyScrollbar(ScrollbarOrien tation orientation) |
| 1531 { | 1557 { |
| 1532 RefPtrWillBeMember<Scrollbar>& scrollbar = orientation == HorizontalScrollba r ? m_hBar : m_vBar; | 1558 RefPtrWillBeMember<Scrollbar>& scrollbar = orientation == HorizontalScrollba r ? m_hBar : m_vBar; |
| 1533 ASSERT(orientation == HorizontalScrollbar ? !m_hBarIsAttached: !m_vBarIsAtta ched); | 1559 ASSERT(orientation == HorizontalScrollbar ? !m_hBarIsAttached: !m_vBarIsAtta ched); |
| 1534 if (!scrollbar) | 1560 if (!scrollbar) |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 1549 } | 1575 } |
| 1550 | 1576 |
| 1551 DEFINE_TRACE(PaintLayerScrollableArea::ScrollbarManager) | 1577 DEFINE_TRACE(PaintLayerScrollableArea::ScrollbarManager) |
| 1552 { | 1578 { |
| 1553 visitor->trace(m_scrollableArea); | 1579 visitor->trace(m_scrollableArea); |
| 1554 visitor->trace(m_hBar); | 1580 visitor->trace(m_hBar); |
| 1555 visitor->trace(m_vBar); | 1581 visitor->trace(m_vBar); |
| 1556 } | 1582 } |
| 1557 | 1583 |
| 1558 } // namespace blink | 1584 } // namespace blink |
| OLD | NEW |