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@web.de> | 9 * Christian Biesinger <cbiesinger@web.de> |
10 * Randall Jesup <rjesup@wgate.com> | 10 * Randall Jesup <rjesup@wgate.com> |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 #if ENABLE(ASSERT) | 95 #if ENABLE(ASSERT) |
96 , m_hasBeenDisposed(false) | 96 , m_hasBeenDisposed(false) |
97 #endif | 97 #endif |
98 { | 98 { |
99 Node* node = box().node(); | 99 Node* node = box().node(); |
100 if (node && node->isElementNode()) { | 100 if (node && node->isElementNode()) { |
101 // We save and restore only the scrollOffset as the other scroll values
are recalculated. | 101 // We save and restore only the scrollOffset as the other scroll values
are recalculated. |
102 Element* element = toElement(node); | 102 Element* element = toElement(node); |
103 m_scrollOffset = element->savedLayerScrollOffset(); | 103 m_scrollOffset = element->savedLayerScrollOffset(); |
104 if (!m_scrollOffset.isZero()) | 104 if (!m_scrollOffset.isZero()) |
105 scrollAnimator()->setCurrentPosition(FloatPoint(m_scrollOffset.width
(), m_scrollOffset.height())); | 105 scrollAnimator().setCurrentPosition(FloatPoint(m_scrollOffset.width(
), m_scrollOffset.height())); |
106 element->setSavedLayerScrollOffset(IntSize()); | 106 element->setSavedLayerScrollOffset(IntSize()); |
107 } | 107 } |
108 updateResizerAreaSet(); | 108 updateResizerAreaSet(); |
109 } | 109 } |
110 | 110 |
111 PaintLayerScrollableArea::~PaintLayerScrollableArea() | 111 PaintLayerScrollableArea::~PaintLayerScrollableArea() |
112 { | 112 { |
113 ASSERT(m_hasBeenDisposed); | 113 ASSERT(m_hasBeenDisposed); |
114 } | 114 } |
115 | 115 |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 return maxX - thickness - box.styleRef().borderRightWidth(); | 232 return maxX - thickness - box.styleRef().borderRightWidth(); |
233 } | 233 } |
234 | 234 |
235 static IntRect cornerRect(const LayoutBox& box, const Scrollbar* horizontalScrol
lbar, const Scrollbar* verticalScrollbar, const IntRect& bounds) | 235 static IntRect cornerRect(const LayoutBox& box, const Scrollbar* horizontalScrol
lbar, const Scrollbar* verticalScrollbar, const IntRect& bounds) |
236 { | 236 { |
237 int horizontalThickness; | 237 int horizontalThickness; |
238 int verticalThickness; | 238 int verticalThickness; |
239 if (!verticalScrollbar && !horizontalScrollbar) { | 239 if (!verticalScrollbar && !horizontalScrollbar) { |
240 // FIXME: This isn't right. We need to know the thickness of custom scro
llbars | 240 // FIXME: This isn't right. We need to know the thickness of custom scro
llbars |
241 // even when they don't exist in order to set the resizer square size pr
operly. | 241 // even when they don't exist in order to set the resizer square size pr
operly. |
242 horizontalThickness = ScrollbarTheme::theme()->scrollbarThickness(); | 242 horizontalThickness = ScrollbarTheme::theme().scrollbarThickness(); |
243 verticalThickness = horizontalThickness; | 243 verticalThickness = horizontalThickness; |
244 } else if (verticalScrollbar && !horizontalScrollbar) { | 244 } else if (verticalScrollbar && !horizontalScrollbar) { |
245 horizontalThickness = verticalScrollbar->width(); | 245 horizontalThickness = verticalScrollbar->width(); |
246 verticalThickness = horizontalThickness; | 246 verticalThickness = horizontalThickness; |
247 } else if (horizontalScrollbar && !verticalScrollbar) { | 247 } else if (horizontalScrollbar && !verticalScrollbar) { |
248 verticalThickness = horizontalScrollbar->height(); | 248 verticalThickness = horizontalScrollbar->height(); |
249 horizontalThickness = verticalThickness; | 249 horizontalThickness = verticalThickness; |
250 } else { | 250 } else { |
251 horizontalThickness = verticalScrollbar->width(); | 251 horizontalThickness = verticalScrollbar->width(); |
252 verticalThickness = horizontalScrollbar->height(); | 252 verticalThickness = horizontalScrollbar->height(); |
(...skipping 11 matching lines...) Expand all Loading... |
264 // (a) A resizer is present and at least one scrollbar is present | 264 // (a) A resizer is present and at least one scrollbar is present |
265 // (b) Both scrollbars are present. | 265 // (b) Both scrollbars are present. |
266 bool hasHorizontalBar = horizontalScrollbar(); | 266 bool hasHorizontalBar = horizontalScrollbar(); |
267 bool hasVerticalBar = verticalScrollbar(); | 267 bool hasVerticalBar = verticalScrollbar(); |
268 bool hasResizer = box().style()->resize() != RESIZE_NONE; | 268 bool hasResizer = box().style()->resize() != RESIZE_NONE; |
269 if ((hasHorizontalBar && hasVerticalBar) || (hasResizer && (hasHorizontalBar
|| hasVerticalBar))) | 269 if ((hasHorizontalBar && hasVerticalBar) || (hasResizer && (hasHorizontalBar
|| hasVerticalBar))) |
270 return cornerRect(box(), horizontalScrollbar(), verticalScrollbar(), box
().pixelSnappedBorderBoxRect()); | 270 return cornerRect(box(), horizontalScrollbar(), verticalScrollbar(), box
().pixelSnappedBorderBoxRect()); |
271 return IntRect(); | 271 return IntRect(); |
272 } | 272 } |
273 | 273 |
274 IntRect PaintLayerScrollableArea::convertFromScrollbarToContainingWidget(const S
crollbar* scrollbar, const IntRect& scrollbarRect) const | 274 IntRect PaintLayerScrollableArea::convertFromScrollbarToContainingWidget(const S
crollbar& scrollbar, const IntRect& scrollbarRect) const |
275 { | 275 { |
276 LayoutView* view = box().view(); | 276 LayoutView* view = box().view(); |
277 if (!view) | 277 if (!view) |
278 return scrollbarRect; | 278 return scrollbarRect; |
279 | 279 |
280 IntRect rect = scrollbarRect; | 280 IntRect rect = scrollbarRect; |
281 rect.move(scrollbarOffset(scrollbar)); | 281 rect.move(scrollbarOffset(scrollbar)); |
282 | 282 |
283 return view->frameView()->convertFromLayoutObject(box(), rect); | 283 return view->frameView()->convertFromLayoutObject(box(), rect); |
284 } | 284 } |
285 | 285 |
286 IntRect PaintLayerScrollableArea::convertFromContainingWidgetToScrollbar(const S
crollbar* scrollbar, const IntRect& parentRect) const | 286 IntRect PaintLayerScrollableArea::convertFromContainingWidgetToScrollbar(const S
crollbar& scrollbar, const IntRect& parentRect) const |
287 { | 287 { |
288 LayoutView* view = box().view(); | 288 LayoutView* view = box().view(); |
289 if (!view) | 289 if (!view) |
290 return parentRect; | 290 return parentRect; |
291 | 291 |
292 IntRect rect = view->frameView()->convertToLayoutObject(box(), parentRect); | 292 IntRect rect = view->frameView()->convertToLayoutObject(box(), parentRect); |
293 rect.move(-scrollbarOffset(scrollbar)); | 293 rect.move(-scrollbarOffset(scrollbar)); |
294 return rect; | 294 return rect; |
295 } | 295 } |
296 | 296 |
297 IntPoint PaintLayerScrollableArea::convertFromScrollbarToContainingWidget(const
Scrollbar* scrollbar, const IntPoint& scrollbarPoint) const | 297 IntPoint PaintLayerScrollableArea::convertFromScrollbarToContainingWidget(const
Scrollbar& scrollbar, const IntPoint& scrollbarPoint) const |
298 { | 298 { |
299 LayoutView* view = box().view(); | 299 LayoutView* view = box().view(); |
300 if (!view) | 300 if (!view) |
301 return scrollbarPoint; | 301 return scrollbarPoint; |
302 | 302 |
303 IntPoint point = scrollbarPoint; | 303 IntPoint point = scrollbarPoint; |
304 point.move(scrollbarOffset(scrollbar)); | 304 point.move(scrollbarOffset(scrollbar)); |
305 return view->frameView()->convertFromLayoutObject(box(), point); | 305 return view->frameView()->convertFromLayoutObject(box(), point); |
306 } | 306 } |
307 | 307 |
308 IntPoint PaintLayerScrollableArea::convertFromContainingWidgetToScrollbar(const
Scrollbar* scrollbar, const IntPoint& parentPoint) const | 308 IntPoint PaintLayerScrollableArea::convertFromContainingWidgetToScrollbar(const
Scrollbar& scrollbar, const IntPoint& parentPoint) const |
309 { | 309 { |
310 LayoutView* view = box().view(); | 310 LayoutView* view = box().view(); |
311 if (!view) | 311 if (!view) |
312 return parentPoint; | 312 return parentPoint; |
313 | 313 |
314 IntPoint point = view->frameView()->convertToLayoutObject(box(), parentPoint
); | 314 IntPoint point = view->frameView()->convertToLayoutObject(box(), parentPoint
); |
315 | 315 |
316 point.move(-scrollbarOffset(scrollbar)); | 316 point.move(-scrollbarOffset(scrollbar)); |
317 return point; | 317 return point; |
318 } | 318 } |
(...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
902 } | 902 } |
903 | 903 |
904 LayoutUnit PaintLayerScrollableArea::horizontalScrollbarStart(int minX) const | 904 LayoutUnit PaintLayerScrollableArea::horizontalScrollbarStart(int minX) const |
905 { | 905 { |
906 int x = minX + box().borderLeft(); | 906 int x = minX + box().borderLeft(); |
907 if (box().shouldPlaceBlockDirectionScrollbarOnLogicalLeft()) | 907 if (box().shouldPlaceBlockDirectionScrollbarOnLogicalLeft()) |
908 x += hasVerticalScrollbar() ? verticalScrollbar()->width() : resizerCorn
erRect(box().pixelSnappedBorderBoxRect(), ResizerForPointer).width(); | 908 x += hasVerticalScrollbar() ? verticalScrollbar()->width() : resizerCorn
erRect(box().pixelSnappedBorderBoxRect(), ResizerForPointer).width(); |
909 return x; | 909 return x; |
910 } | 910 } |
911 | 911 |
912 IntSize PaintLayerScrollableArea::scrollbarOffset(const Scrollbar* scrollbar) co
nst | 912 IntSize PaintLayerScrollableArea::scrollbarOffset(const Scrollbar& scrollbar) co
nst |
913 { | 913 { |
914 if (scrollbar == verticalScrollbar()) | 914 if (&scrollbar == verticalScrollbar()) |
915 return IntSize(verticalScrollbarStart(0, box().size().width()), box().bo
rderTop()); | 915 return IntSize(verticalScrollbarStart(0, box().size().width()), box().bo
rderTop()); |
916 | 916 |
917 if (scrollbar == horizontalScrollbar()) | 917 if (&scrollbar == horizontalScrollbar()) |
918 return IntSize(horizontalScrollbarStart(0), box().size().height() - box(
).borderBottom() - scrollbar->height()); | 918 return IntSize(horizontalScrollbarStart(0), box().size().height() - box(
).borderBottom() - scrollbar.height()); |
919 | 919 |
920 ASSERT_NOT_REACHED(); | 920 ASSERT_NOT_REACHED(); |
921 return IntSize(); | 921 return IntSize(); |
922 } | 922 } |
923 | 923 |
924 static inline const LayoutObject& layoutObjectForScrollbar(const LayoutObject& l
ayoutObject) | 924 static inline const LayoutObject& layoutObjectForScrollbar(const LayoutObject& l
ayoutObject) |
925 { | 925 { |
926 if (Node* node = layoutObject.node()) { | 926 if (Node* node = layoutObject.node()) { |
927 if (layoutObject.isLayoutView()) { | 927 if (layoutObject.isLayoutView()) { |
928 Document& doc = node->document(); | 928 Document& doc = node->document(); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
978 } | 978 } |
979 | 979 |
980 return hasAnyScrollbar && ((shouldUseCustom != hasCustom) || (shouldUseCusto
m && didCustomScrollbarOwnerChanged)); | 980 return hasAnyScrollbar && ((shouldUseCustom != hasCustom) || (shouldUseCusto
m && didCustomScrollbarOwnerChanged)); |
981 } | 981 } |
982 | 982 |
983 void PaintLayerScrollableArea::setHasHorizontalScrollbar(bool hasScrollbar) | 983 void PaintLayerScrollableArea::setHasHorizontalScrollbar(bool hasScrollbar) |
984 { | 984 { |
985 if (hasScrollbar == hasHorizontalScrollbar()) | 985 if (hasScrollbar == hasHorizontalScrollbar()) |
986 return; | 986 return; |
987 | 987 |
988 setScrollbarNeedsPaintInvalidation(horizontalScrollbar()); | 988 setScrollbarNeedsPaintInvalidation(HorizontalScrollbar); |
989 | |
990 | 989 |
991 m_scrollbarManager.setHasHorizontalScrollbar(hasScrollbar); | 990 m_scrollbarManager.setHasHorizontalScrollbar(hasScrollbar); |
992 | 991 |
993 // Destroying or creating one bar can cause our scrollbar corner to come and
go. We need to update the opposite scrollbar's style. | 992 // Destroying or creating one bar can cause our scrollbar corner to come and
go. We need to update the opposite scrollbar's style. |
994 if (hasHorizontalScrollbar()) | 993 if (hasHorizontalScrollbar()) |
995 horizontalScrollbar()->styleChanged(); | 994 horizontalScrollbar()->styleChanged(); |
996 if (hasVerticalScrollbar()) | 995 if (hasVerticalScrollbar()) |
997 verticalScrollbar()->styleChanged(); | 996 verticalScrollbar()->styleChanged(); |
998 | 997 |
999 setScrollCornerNeedsPaintInvalidation(); | 998 setScrollCornerNeedsPaintInvalidation(); |
1000 | 999 |
1001 // Force an update since we know the scrollbars have changed things. | 1000 // Force an update since we know the scrollbars have changed things. |
1002 if (box().document().hasAnnotatedRegions()) | 1001 if (box().document().hasAnnotatedRegions()) |
1003 box().document().setAnnotatedRegionsDirty(true); | 1002 box().document().setAnnotatedRegionsDirty(true); |
1004 } | 1003 } |
1005 | 1004 |
1006 void PaintLayerScrollableArea::setHasVerticalScrollbar(bool hasScrollbar) | 1005 void PaintLayerScrollableArea::setHasVerticalScrollbar(bool hasScrollbar) |
1007 { | 1006 { |
1008 if (hasScrollbar == hasVerticalScrollbar()) | 1007 if (hasScrollbar == hasVerticalScrollbar()) |
1009 return; | 1008 return; |
1010 | 1009 |
1011 setScrollbarNeedsPaintInvalidation(verticalScrollbar()); | 1010 setScrollbarNeedsPaintInvalidation(VerticalScrollbar); |
1012 | 1011 |
1013 m_scrollbarManager.setHasVerticalScrollbar(hasScrollbar); | 1012 m_scrollbarManager.setHasVerticalScrollbar(hasScrollbar); |
1014 | 1013 |
1015 // Destroying or creating one bar can cause our scrollbar corner to come and
go. We need to update the opposite scrollbar's style. | 1014 // Destroying or creating one bar can cause our scrollbar corner to come and
go. We need to update the opposite scrollbar's style. |
1016 if (hasHorizontalScrollbar()) | 1015 if (hasHorizontalScrollbar()) |
1017 horizontalScrollbar()->styleChanged(); | 1016 horizontalScrollbar()->styleChanged(); |
1018 if (hasVerticalScrollbar()) | 1017 if (hasVerticalScrollbar()) |
1019 verticalScrollbar()->styleChanged(); | 1018 verticalScrollbar()->styleChanged(); |
1020 | 1019 |
1021 setScrollCornerNeedsPaintInvalidation(); | 1020 setScrollCornerNeedsPaintInvalidation(); |
(...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1478 } else { | 1477 } else { |
1479 m_vBarIsAttached = 0; | 1478 m_vBarIsAttached = 0; |
1480 if (!m_canDetachScrollbars) | 1479 if (!m_canDetachScrollbars) |
1481 destroyScrollbar(VerticalScrollbar); | 1480 destroyScrollbar(VerticalScrollbar); |
1482 } | 1481 } |
1483 } | 1482 } |
1484 | 1483 |
1485 PassRefPtrWillBeRawPtr<Scrollbar> PaintLayerScrollableArea::ScrollbarManager::cr
eateScrollbar(ScrollbarOrientation orientation) | 1484 PassRefPtrWillBeRawPtr<Scrollbar> PaintLayerScrollableArea::ScrollbarManager::cr
eateScrollbar(ScrollbarOrientation orientation) |
1486 { | 1485 { |
1487 ASSERT(orientation == HorizontalScrollbar ? !m_hBarIsAttached : !m_vBarIsAtt
ached); | 1486 ASSERT(orientation == HorizontalScrollbar ? !m_hBarIsAttached : !m_vBarIsAtt
ached); |
1488 RefPtrWillBeRawPtr<Scrollbar> widget = nullptr; | 1487 RefPtrWillBeRawPtr<Scrollbar> scrollbar = nullptr; |
1489 const LayoutObject& actualLayoutObject = layoutObjectForScrollbar(m_scrollab
leArea->box()); | 1488 const LayoutObject& actualLayoutObject = layoutObjectForScrollbar(m_scrollab
leArea->box()); |
1490 bool hasCustomScrollbarStyle = actualLayoutObject.isBox() && actualLayoutObj
ect.styleRef().hasPseudoStyle(SCROLLBAR); | 1489 bool hasCustomScrollbarStyle = actualLayoutObject.isBox() && actualLayoutObj
ect.styleRef().hasPseudoStyle(SCROLLBAR); |
1491 if (hasCustomScrollbarStyle) { | 1490 if (hasCustomScrollbarStyle) { |
1492 widget = LayoutScrollbar::createCustomScrollbar(m_scrollableArea.get(),
orientation, actualLayoutObject.node()); | 1491 scrollbar = LayoutScrollbar::createCustomScrollbar(m_scrollableArea.get(
), orientation, actualLayoutObject.node()); |
1493 } else { | 1492 } else { |
1494 ScrollbarControlSize scrollbarSize = RegularScrollbar; | 1493 ScrollbarControlSize scrollbarSize = RegularScrollbar; |
1495 if (actualLayoutObject.styleRef().hasAppearance()) | 1494 if (actualLayoutObject.styleRef().hasAppearance()) |
1496 scrollbarSize = LayoutTheme::theme().scrollbarControlSizeForPart(act
ualLayoutObject.styleRef().appearance()); | 1495 scrollbarSize = LayoutTheme::theme().scrollbarControlSizeForPart(act
ualLayoutObject.styleRef().appearance()); |
1497 widget = Scrollbar::create(m_scrollableArea.get(), orientation, scrollba
rSize); | 1496 scrollbar = Scrollbar::create(m_scrollableArea.get(), orientation, scrol
lbarSize); |
1498 if (orientation == HorizontalScrollbar) | 1497 if (orientation == HorizontalScrollbar) |
1499 m_scrollableArea->didAddScrollbar(widget.get(), HorizontalScrollbar)
; | 1498 m_scrollableArea->didAddScrollbar(*scrollbar, HorizontalScrollbar); |
1500 else | 1499 else |
1501 m_scrollableArea->didAddScrollbar(widget.get(), VerticalScrollbar); | 1500 m_scrollableArea->didAddScrollbar(*scrollbar, VerticalScrollbar); |
1502 } | 1501 } |
1503 m_scrollableArea->box().document().view()->addChild(widget.get()); | 1502 m_scrollableArea->box().document().view()->addChild(scrollbar.get()); |
1504 return widget.release(); | 1503 return scrollbar.release(); |
1505 } | 1504 } |
1506 | 1505 |
1507 void PaintLayerScrollableArea::ScrollbarManager::destroyScrollbar(ScrollbarOrien
tation orientation) | 1506 void PaintLayerScrollableArea::ScrollbarManager::destroyScrollbar(ScrollbarOrien
tation orientation) |
1508 { | 1507 { |
1509 RefPtrWillBeMember<Scrollbar>& scrollbar = orientation == HorizontalScrollba
r ? m_hBar : m_vBar; | 1508 RefPtrWillBeMember<Scrollbar>& scrollbar = orientation == HorizontalScrollba
r ? m_hBar : m_vBar; |
1510 ASSERT(orientation == HorizontalScrollbar ? !m_hBarIsAttached: !m_vBarIsAtta
ched); | 1509 ASSERT(orientation == HorizontalScrollbar ? !m_hBarIsAttached: !m_vBarIsAtta
ched); |
1511 if (!scrollbar) | 1510 if (!scrollbar) |
1512 return; | 1511 return; |
1513 | 1512 |
1514 m_scrollableArea->setScrollbarNeedsPaintInvalidation(scrollbar.get()); | 1513 m_scrollableArea->setScrollbarNeedsPaintInvalidation(orientation); |
1515 | 1514 |
1516 if (!scrollbar->isCustomScrollbar()) | 1515 if (!scrollbar->isCustomScrollbar()) |
1517 m_scrollableArea->willRemoveScrollbar(scrollbar.get(), orientation); | 1516 m_scrollableArea->willRemoveScrollbar(*scrollbar, orientation); |
1518 | 1517 |
1519 toFrameView(scrollbar->parent())->removeChild(scrollbar.get()); | 1518 toFrameView(scrollbar->parent())->removeChild(scrollbar.get()); |
1520 scrollbar->disconnectFromScrollableArea(); | 1519 scrollbar->disconnectFromScrollableArea(); |
1521 scrollbar = nullptr; | 1520 scrollbar = nullptr; |
1522 } | 1521 } |
1523 | 1522 |
1524 DEFINE_TRACE(PaintLayerScrollableArea::ScrollbarManager) | 1523 DEFINE_TRACE(PaintLayerScrollableArea::ScrollbarManager) |
1525 { | 1524 { |
1526 visitor->trace(m_scrollableArea); | 1525 visitor->trace(m_scrollableArea); |
1527 visitor->trace(m_hBar); | 1526 visitor->trace(m_hBar); |
1528 visitor->trace(m_vBar); | 1527 visitor->trace(m_vBar); |
1529 } | 1528 } |
1530 | 1529 |
1531 } // namespace blink | 1530 } // namespace blink |
OLD | NEW |