OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
68 | 68 |
69 void ScrollView::setHasHorizontalScrollbar(bool hasBar) | 69 void ScrollView::setHasHorizontalScrollbar(bool hasBar) |
70 { | 70 { |
71 if (hasBar && !m_horizontalScrollbar) { | 71 if (hasBar && !m_horizontalScrollbar) { |
72 m_horizontalScrollbar = createScrollbar(HorizontalScrollbar); | 72 m_horizontalScrollbar = createScrollbar(HorizontalScrollbar); |
73 addChild(m_horizontalScrollbar.get()); | 73 addChild(m_horizontalScrollbar.get()); |
74 didAddScrollbar(m_horizontalScrollbar.get(), HorizontalScrollbar); | 74 didAddScrollbar(m_horizontalScrollbar.get(), HorizontalScrollbar); |
75 m_horizontalScrollbar->styleChanged(); | 75 m_horizontalScrollbar->styleChanged(); |
76 } else if (!hasBar && m_horizontalScrollbar) { | 76 } else if (!hasBar && m_horizontalScrollbar) { |
77 willRemoveScrollbar(m_horizontalScrollbar.get(), HorizontalScrollbar); | 77 willRemoveScrollbar(m_horizontalScrollbar.get(), HorizontalScrollbar); |
78 if (m_horizontalScrollbar->overlapsResizer()) | |
Ian Vollick
2014/10/04 01:25:44
It's not obvious to me how we'll know that ScrollV
skobes
2014/10/06 18:18:53
Added a comment. Note that if adjustScrollbarRect
| |
79 adjustScrollbarsAvoidingResizerCount(-1); | |
78 removeChild(m_horizontalScrollbar.get()); | 80 removeChild(m_horizontalScrollbar.get()); |
79 m_horizontalScrollbar = nullptr; | 81 m_horizontalScrollbar = nullptr; |
80 } | 82 } |
81 } | 83 } |
82 | 84 |
83 void ScrollView::setHasVerticalScrollbar(bool hasBar) | 85 void ScrollView::setHasVerticalScrollbar(bool hasBar) |
84 { | 86 { |
85 if (hasBar && !m_verticalScrollbar) { | 87 if (hasBar && !m_verticalScrollbar) { |
86 m_verticalScrollbar = createScrollbar(VerticalScrollbar); | 88 m_verticalScrollbar = createScrollbar(VerticalScrollbar); |
87 addChild(m_verticalScrollbar.get()); | 89 addChild(m_verticalScrollbar.get()); |
88 didAddScrollbar(m_verticalScrollbar.get(), VerticalScrollbar); | 90 didAddScrollbar(m_verticalScrollbar.get(), VerticalScrollbar); |
89 m_verticalScrollbar->styleChanged(); | 91 m_verticalScrollbar->styleChanged(); |
90 } else if (!hasBar && m_verticalScrollbar) { | 92 } else if (!hasBar && m_verticalScrollbar) { |
91 willRemoveScrollbar(m_verticalScrollbar.get(), VerticalScrollbar); | 93 willRemoveScrollbar(m_verticalScrollbar.get(), VerticalScrollbar); |
94 if (m_verticalScrollbar->overlapsResizer()) | |
95 adjustScrollbarsAvoidingResizerCount(-1); | |
92 removeChild(m_verticalScrollbar.get()); | 96 removeChild(m_verticalScrollbar.get()); |
93 m_verticalScrollbar = nullptr; | 97 m_verticalScrollbar = nullptr; |
94 } | 98 } |
95 } | 99 } |
96 | 100 |
97 PassRefPtr<Scrollbar> ScrollView::createScrollbar(ScrollbarOrientation orientati on) | 101 PassRefPtr<Scrollbar> ScrollView::createScrollbar(ScrollbarOrientation orientati on) |
98 { | 102 { |
99 return Scrollbar::create(this, orientation, RegularScrollbar); | 103 return Scrollbar::create(this, orientation, RegularScrollbar); |
100 } | 104 } |
101 | 105 |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
379 | 383 |
380 void ScrollView::updateScrollbarGeometry() | 384 void ScrollView::updateScrollbarGeometry() |
381 { | 385 { |
382 if (m_horizontalScrollbar) { | 386 if (m_horizontalScrollbar) { |
383 int clientWidth = visibleWidth(); | 387 int clientWidth = visibleWidth(); |
384 IntRect oldRect(m_horizontalScrollbar->frameRect()); | 388 IntRect oldRect(m_horizontalScrollbar->frameRect()); |
385 IntRect hBarRect((shouldPlaceVerticalScrollbarOnLeft() && m_verticalScro llbar) ? m_verticalScrollbar->width() : 0, | 389 IntRect hBarRect((shouldPlaceVerticalScrollbarOnLeft() && m_verticalScro llbar) ? m_verticalScrollbar->width() : 0, |
386 height() - m_horizontalScrollbar->height(), | 390 height() - m_horizontalScrollbar->height(), |
387 width() - (m_verticalScrollbar ? m_verticalScrollbar->wi dth() : 0), | 391 width() - (m_verticalScrollbar ? m_verticalScrollbar->wi dth() : 0), |
388 m_horizontalScrollbar->height()); | 392 m_horizontalScrollbar->height()); |
389 m_horizontalScrollbar->setFrameRect(hBarRect); | 393 m_horizontalScrollbar->setFrameRect(adjustScrollbarRectForResizer(hBarRe ct, m_horizontalScrollbar.get())); |
390 if (!m_scrollbarsSuppressed && oldRect != m_horizontalScrollbar->frameRe ct()) | 394 if (!m_scrollbarsSuppressed && oldRect != m_horizontalScrollbar->frameRe ct()) |
391 m_horizontalScrollbar->invalidate(); | 395 m_horizontalScrollbar->invalidate(); |
392 | 396 |
393 if (m_scrollbarsSuppressed) | 397 if (m_scrollbarsSuppressed) |
394 m_horizontalScrollbar->setSuppressInvalidation(true); | 398 m_horizontalScrollbar->setSuppressInvalidation(true); |
395 m_horizontalScrollbar->setEnabled(contentsWidth() > clientWidth); | 399 m_horizontalScrollbar->setEnabled(contentsWidth() > clientWidth); |
396 m_horizontalScrollbar->setProportion(clientWidth, contentsWidth()); | 400 m_horizontalScrollbar->setProportion(clientWidth, contentsWidth()); |
397 m_horizontalScrollbar->offsetDidChange(); | 401 m_horizontalScrollbar->offsetDidChange(); |
398 if (m_scrollbarsSuppressed) | 402 if (m_scrollbarsSuppressed) |
399 m_horizontalScrollbar->setSuppressInvalidation(false); | 403 m_horizontalScrollbar->setSuppressInvalidation(false); |
400 } | 404 } |
401 | 405 |
402 if (m_verticalScrollbar) { | 406 if (m_verticalScrollbar) { |
403 int clientHeight = visibleHeight(); | 407 int clientHeight = visibleHeight(); |
404 IntRect oldRect(m_verticalScrollbar->frameRect()); | 408 IntRect oldRect(m_verticalScrollbar->frameRect()); |
405 IntRect vBarRect(shouldPlaceVerticalScrollbarOnLeft() ? 0 : (width() - m _verticalScrollbar->width()), | 409 IntRect vBarRect(shouldPlaceVerticalScrollbarOnLeft() ? 0 : (width() - m _verticalScrollbar->width()), |
406 0, | 410 0, |
407 m_verticalScrollbar->width(), | 411 m_verticalScrollbar->width(), |
408 height() - (m_horizontalScrollbar ? m_horizontalScrollb ar->height() : 0)); | 412 height() - (m_horizontalScrollbar ? m_horizontalScrollb ar->height() : 0)); |
409 m_verticalScrollbar->setFrameRect(vBarRect); | 413 m_verticalScrollbar->setFrameRect(adjustScrollbarRectForResizer(vBarRect , m_verticalScrollbar.get())); |
410 if (!m_scrollbarsSuppressed && oldRect != m_verticalScrollbar->frameRect ()) | 414 if (!m_scrollbarsSuppressed && oldRect != m_verticalScrollbar->frameRect ()) |
411 m_verticalScrollbar->invalidate(); | 415 m_verticalScrollbar->invalidate(); |
412 | 416 |
413 if (m_scrollbarsSuppressed) | 417 if (m_scrollbarsSuppressed) |
414 m_verticalScrollbar->setSuppressInvalidation(true); | 418 m_verticalScrollbar->setSuppressInvalidation(true); |
415 m_verticalScrollbar->setEnabled(contentsHeight() > clientHeight); | 419 m_verticalScrollbar->setEnabled(contentsHeight() > clientHeight); |
416 m_verticalScrollbar->setProportion(clientHeight, contentsHeight()); | 420 m_verticalScrollbar->setProportion(clientHeight, contentsHeight()); |
417 m_verticalScrollbar->offsetDidChange(); | 421 m_verticalScrollbar->offsetDidChange(); |
418 if (m_scrollbarsSuppressed) | 422 if (m_scrollbarsSuppressed) |
419 m_verticalScrollbar->setSuppressInvalidation(false); | 423 m_verticalScrollbar->setSuppressInvalidation(false); |
420 } | 424 } |
421 } | 425 } |
422 | 426 |
427 IntRect ScrollView::adjustScrollbarRectForResizer(const IntRect& rect, Scrollbar * scrollbar) | |
428 { | |
429 // Get our window resizer rect and see if we overlap. Adjust to avoid the ov erlap | |
430 // if necessary. | |
431 IntRect adjustedRect(rect); | |
432 bool overlapsResizer = false; | |
433 if (!rect.isEmpty() && !windowResizerRect().isEmpty()) { | |
434 IntRect resizerRect = convertFromContainingWindow(windowResizerRect()); | |
435 if (rect.intersects(resizerRect)) { | |
436 if (scrollbar->orientation() == HorizontalScrollbar) { | |
437 int overlap = rect.maxX() - resizerRect.x(); | |
438 if (overlap > 0 && resizerRect.maxX() >= rect.maxX()) { | |
439 adjustedRect.setWidth(rect.width() - overlap); | |
440 overlapsResizer = true; | |
441 } | |
442 } else { | |
443 int overlap = rect.maxY() - resizerRect.y(); | |
444 if (overlap > 0 && resizerRect.maxY() >= rect.maxY()) { | |
445 adjustedRect.setHeight(rect.height() - overlap); | |
446 overlapsResizer = true; | |
447 } | |
448 } | |
449 } | |
450 } | |
451 if (overlapsResizer != scrollbar->overlapsResizer()) { | |
452 scrollbar->setOverlapsResizer(overlapsResizer); | |
453 adjustScrollbarsAvoidingResizerCount(overlapsResizer ? 1 : -1); | |
454 } | |
455 return adjustedRect; | |
456 } | |
457 | |
423 bool ScrollView::adjustScrollbarExistence(ComputeScrollbarExistenceOption option ) | 458 bool ScrollView::adjustScrollbarExistence(ComputeScrollbarExistenceOption option ) |
424 { | 459 { |
425 ASSERT(m_inUpdateScrollbars); | 460 ASSERT(m_inUpdateScrollbars); |
426 | 461 |
427 // If we came in here with the view already needing a layout, then go ahead and do that | 462 // If we came in here with the view already needing a layout, then go ahead and do that |
428 // first. (This will be the common case, e.g., when the page changes due to window resizing for example). | 463 // first. (This will be the common case, e.g., when the page changes due to window resizing for example). |
429 // This layout will not re-enter updateScrollbars and does not count towards our max layout pass total. | 464 // This layout will not re-enter updateScrollbars and does not count towards our max layout pass total. |
430 if (!m_scrollbarsSuppressed) | 465 if (!m_scrollbarsSuppressed) |
431 scrollbarExistenceDidChange(); | 466 scrollbarExistenceDidChange(); |
432 | 467 |
(...skipping 682 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1115 return; | 1150 return; |
1116 | 1151 |
1117 ScrollableArea::setScrollOrigin(origin); | 1152 ScrollableArea::setScrollOrigin(origin); |
1118 | 1153 |
1119 // Update if the scroll origin changes, since our position will be different if the content size did not change. | 1154 // Update if the scroll origin changes, since our position will be different if the content size did not change. |
1120 if (updatePositionAtAll && updatePositionSynchronously) | 1155 if (updatePositionAtAll && updatePositionSynchronously) |
1121 updateScrollbars(scrollOffset()); | 1156 updateScrollbars(scrollOffset()); |
1122 } | 1157 } |
1123 | 1158 |
1124 } // namespace blink | 1159 } // namespace blink |
OLD | NEW |