hyatt@apple.com | 912c1b1 | 2008-09-25 07:38:56 +0000 | [diff] [blame] | 1 | /* |
darin@apple.com | 6c71ce2 | 2017-01-14 03:35:54 +0000 | [diff] [blame] | 2 | * Copyright (C) 2006-2017 Apple Inc. All rights reserved. |
hyatt@apple.com | 912c1b1 | 2008-09-25 07:38:56 +0000 | [diff] [blame] | 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions |
| 6 | * are met: |
| 7 | * 1. Redistributions of source code must retain the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer. |
| 9 | * 2. Redistributions in binary form must reproduce the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer in the |
| 11 | * documentation and/or other materials provided with the distribution. |
| 12 | * |
mjs@apple.com | 9204733 | 2014-03-15 04:08:27 +0000 | [diff] [blame] | 13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
hyatt@apple.com | 912c1b1 | 2008-09-25 07:38:56 +0000 | [diff] [blame] | 14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
mjs@apple.com | 9204733 | 2014-03-15 04:08:27 +0000 | [diff] [blame] | 16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
hyatt@apple.com | 912c1b1 | 2008-09-25 07:38:56 +0000 | [diff] [blame] | 17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 18 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 19 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 20 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 21 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 | */ |
| 25 | |
| 26 | #include "config.h" |
| 27 | #include "ScrollView.h" |
| 28 | |
hyatt@apple.com | 3b82dce | 2008-10-01 17:51:02 +0000 | [diff] [blame] | 29 | #include "GraphicsContext.h" |
jamesr@google.com | e53ce64 | 2011-04-14 06:51:50 +0000 | [diff] [blame] | 30 | #include "GraphicsLayer.h" |
hyatt@apple.com | 70936b5 | 2008-09-30 20:09:42 +0000 | [diff] [blame] | 31 | #include "HostWindow.h" |
simon.fraser@apple.com | 37f5269 | 2015-12-24 00:35:04 +0000 | [diff] [blame] | 32 | #include "Logging.h" |
hyatt@apple.com | 880cbb1 | 2008-09-28 03:51:41 +0000 | [diff] [blame] | 33 | #include "PlatformMouseEvent.h" |
hyatt@apple.com | aede3de | 2008-09-28 08:21:09 +0000 | [diff] [blame] | 34 | #include "PlatformWheelEvent.h" |
bdakin@apple.com | 3216752 | 2011-02-01 20:35:25 +0000 | [diff] [blame] | 35 | #include "ScrollAnimator.h" |
hyatt@apple.com | 79be62c | 2008-09-25 22:25:22 +0000 | [diff] [blame] | 36 | #include "Scrollbar.h" |
hyatt@apple.com | 3b82dce | 2008-10-01 17:51:02 +0000 | [diff] [blame] | 37 | #include "ScrollbarTheme.h" |
bolsinga@apple.com | 4f65747 | 2008-11-17 01:05:20 +0000 | [diff] [blame] | 38 | #include <wtf/StdLibExtras.h> |
don.olmstead@sony.com | d57eb47 | 2017-08-10 01:15:14 +0000 | [diff] [blame] | 39 | #include <wtf/text/TextStream.h> |
hyatt@apple.com | 79be62c | 2008-09-25 22:25:22 +0000 | [diff] [blame] | 40 | |
hyatt@apple.com | 912c1b1 | 2008-09-25 07:38:56 +0000 | [diff] [blame] | 41 | namespace WebCore { |
| 42 | |
dbates@webkit.org | f21f3ae | 2017-10-19 23:48:45 +0000 | [diff] [blame] | 43 | ScrollView::ScrollView() = default; |
hyatt@apple.com | 64a3be2 | 2008-09-25 20:49:17 +0000 | [diff] [blame] | 44 | |
dbates@webkit.org | f21f3ae | 2017-10-19 23:48:45 +0000 | [diff] [blame] | 45 | ScrollView::~ScrollView() = default; |
hyatt@apple.com | f1ffabf | 2008-10-02 18:23:32 +0000 | [diff] [blame] | 46 | |
darin@apple.com | 6c71ce2 | 2017-01-14 03:35:54 +0000 | [diff] [blame] | 47 | void ScrollView::addChild(Widget& child) |
hyatt@apple.com | 912c1b1 | 2008-09-25 07:38:56 +0000 | [diff] [blame] | 48 | { |
darin@apple.com | 6c71ce2 | 2017-01-14 03:35:54 +0000 | [diff] [blame] | 49 | ASSERT(&child != this); |
| 50 | ASSERT(!child.parent()); |
| 51 | child.setParent(this); |
| 52 | m_children.add(child); |
| 53 | if (child.platformWidget()) |
| 54 | platformAddChild(&child); |
hyatt@apple.com | 912c1b1 | 2008-09-25 07:38:56 +0000 | [diff] [blame] | 55 | } |
| 56 | |
cdumez@apple.com | 63c654d | 2014-10-09 16:45:32 +0000 | [diff] [blame] | 57 | void ScrollView::removeChild(Widget& child) |
hyatt@apple.com | 912c1b1 | 2008-09-25 07:38:56 +0000 | [diff] [blame] | 58 | { |
cdumez@apple.com | 63c654d | 2014-10-09 16:45:32 +0000 | [diff] [blame] | 59 | ASSERT(child.parent() == this); |
| 60 | child.setParent(nullptr); |
| 61 | m_children.remove(&child); |
| 62 | if (child.platformWidget()) |
| 63 | platformRemoveChild(&child); |
hyatt@apple.com | 912c1b1 | 2008-09-25 07:38:56 +0000 | [diff] [blame] | 64 | } |
| 65 | |
simon.fraser@apple.com | 0cdf36c | 2013-09-20 21:47:47 +0000 | [diff] [blame] | 66 | bool ScrollView::setHasHorizontalScrollbar(bool hasBar, bool* contentSizeAffected) |
hyatt@apple.com | f1ffabf | 2008-10-02 18:23:32 +0000 | [diff] [blame] | 67 | { |
tonikitoo@webkit.org | bcbbf83 | 2016-07-15 20:19:29 +0000 | [diff] [blame] | 68 | return setHasScrollbarInternal(m_horizontalScrollbar, HorizontalScrollbar, hasBar, contentSizeAffected); |
hyatt@apple.com | f1ffabf | 2008-10-02 18:23:32 +0000 | [diff] [blame] | 69 | } |
| 70 | |
simon.fraser@apple.com | 0cdf36c | 2013-09-20 21:47:47 +0000 | [diff] [blame] | 71 | bool ScrollView::setHasVerticalScrollbar(bool hasBar, bool* contentSizeAffected) |
hyatt@apple.com | f1ffabf | 2008-10-02 18:23:32 +0000 | [diff] [blame] | 72 | { |
tonikitoo@webkit.org | bcbbf83 | 2016-07-15 20:19:29 +0000 | [diff] [blame] | 73 | return setHasScrollbarInternal(m_verticalScrollbar, VerticalScrollbar, hasBar, contentSizeAffected); |
| 74 | } |
| 75 | |
| 76 | bool ScrollView::setHasScrollbarInternal(RefPtr<Scrollbar>& scrollbar, ScrollbarOrientation orientation, bool hasBar, bool* contentSizeAffected) |
| 77 | { |
ryuan.choi@samsung.com | 2d22b11c | 2011-07-06 19:04:47 +0000 | [diff] [blame] | 78 | ASSERT(!hasBar || !avoidScrollbarCreation()); |
tonikitoo@webkit.org | bcbbf83 | 2016-07-15 20:19:29 +0000 | [diff] [blame] | 79 | |
| 80 | if (hasBar && !scrollbar) { |
| 81 | scrollbar = createScrollbar(orientation); |
darin@apple.com | 6c71ce2 | 2017-01-14 03:35:54 +0000 | [diff] [blame] | 82 | addChild(*scrollbar); |
tonikitoo@webkit.org | bcbbf83 | 2016-07-15 20:19:29 +0000 | [diff] [blame] | 83 | didAddScrollbar(scrollbar.get(), orientation); |
| 84 | scrollbar->styleChanged(); |
simon.fraser@apple.com | 0cdf36c | 2013-09-20 21:47:47 +0000 | [diff] [blame] | 85 | if (contentSizeAffected) |
tonikitoo@webkit.org | bcbbf83 | 2016-07-15 20:19:29 +0000 | [diff] [blame] | 86 | *contentSizeAffected = !scrollbar->isOverlayScrollbar(); |
simon.fraser@apple.com | 0cdf36c | 2013-09-20 21:47:47 +0000 | [diff] [blame] | 87 | return true; |
simon.fraser@apple.com | 8018847 | 2013-09-12 23:28:32 +0000 | [diff] [blame] | 88 | } |
| 89 | |
tonikitoo@webkit.org | bcbbf83 | 2016-07-15 20:19:29 +0000 | [diff] [blame] | 90 | if (!hasBar && scrollbar) { |
| 91 | bool wasOverlayScrollbar = scrollbar->isOverlayScrollbar(); |
| 92 | willRemoveScrollbar(scrollbar.get(), orientation); |
| 93 | removeChild(*scrollbar); |
| 94 | scrollbar = nullptr; |
simon.fraser@apple.com | 0cdf36c | 2013-09-20 21:47:47 +0000 | [diff] [blame] | 95 | if (contentSizeAffected) |
| 96 | *contentSizeAffected = !wasOverlayScrollbar; |
| 97 | return true; |
hyatt@apple.com | f1ffabf | 2008-10-02 18:23:32 +0000 | [diff] [blame] | 98 | } |
simon.fraser@apple.com | 8018847 | 2013-09-12 23:28:32 +0000 | [diff] [blame] | 99 | |
| 100 | return false; |
hyatt@apple.com | f1ffabf | 2008-10-02 18:23:32 +0000 | [diff] [blame] | 101 | } |
| 102 | |
akling@apple.com | 2799ae9 | 2016-10-25 10:27:12 +0000 | [diff] [blame] | 103 | Ref<Scrollbar> ScrollView::createScrollbar(ScrollbarOrientation orientation) |
hyatt@apple.com | 0f97fcc | 2008-12-08 22:36:54 +0000 | [diff] [blame] | 104 | { |
bfulgham@apple.com | 3cb8c99 | 2015-02-21 03:34:09 +0000 | [diff] [blame] | 105 | return Scrollbar::createNativeScrollbar(*this, orientation, RegularScrollbar); |
hyatt@apple.com | 0f97fcc | 2008-12-08 22:36:54 +0000 | [diff] [blame] | 106 | } |
| 107 | |
tonikitoo@webkit.org | 18656ae | 2010-04-08 14:38:12 +0000 | [diff] [blame] | 108 | void ScrollView::setScrollbarModes(ScrollbarMode horizontalMode, ScrollbarMode verticalMode, |
| 109 | bool horizontalLock, bool verticalLock) |
hyatt@apple.com | 01adde8 | 2008-09-26 20:49:34 +0000 | [diff] [blame] | 110 | { |
tonikitoo@webkit.org | 18656ae | 2010-04-08 14:38:12 +0000 | [diff] [blame] | 111 | bool needsUpdate = false; |
| 112 | |
| 113 | if (horizontalMode != horizontalScrollbarMode() && !m_horizontalScrollbarLock) { |
| 114 | m_horizontalScrollbarMode = horizontalMode; |
| 115 | needsUpdate = true; |
| 116 | } |
| 117 | |
| 118 | if (verticalMode != verticalScrollbarMode() && !m_verticalScrollbarLock) { |
| 119 | m_verticalScrollbarMode = verticalMode; |
| 120 | needsUpdate = true; |
| 121 | } |
| 122 | |
| 123 | if (horizontalLock) |
| 124 | setHorizontalScrollbarLock(); |
| 125 | |
| 126 | if (verticalLock) |
| 127 | setVerticalScrollbarLock(); |
| 128 | |
| 129 | if (!needsUpdate) |
hyatt@apple.com | 4ce2a1d | 2008-09-29 20:09:59 +0000 | [diff] [blame] | 130 | return; |
tonikitoo@webkit.org | 18656ae | 2010-04-08 14:38:12 +0000 | [diff] [blame] | 131 | |
hyatt@apple.com | 01adde8 | 2008-09-26 20:49:34 +0000 | [diff] [blame] | 132 | if (platformWidget()) |
| 133 | platformSetScrollbarModes(); |
| 134 | else |
simon.fraser@apple.com | db0e067 | 2015-12-30 00:29:36 +0000 | [diff] [blame] | 135 | updateScrollbars(scrollPosition()); |
hyatt@apple.com | 01adde8 | 2008-09-26 20:49:34 +0000 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | void ScrollView::scrollbarModes(ScrollbarMode& horizontalMode, ScrollbarMode& verticalMode) const |
| 139 | { |
| 140 | if (platformWidget()) { |
| 141 | platformScrollbarModes(horizontalMode, verticalMode); |
| 142 | return; |
| 143 | } |
| 144 | horizontalMode = m_horizontalScrollbarMode; |
| 145 | verticalMode = m_verticalScrollbarMode; |
| 146 | } |
| 147 | |
hyatt@apple.com | 2f02912 | 2008-10-01 22:12:23 +0000 | [diff] [blame] | 148 | void ScrollView::setCanHaveScrollbars(bool canScroll) |
hyatt@apple.com | b37db69 | 2008-09-27 04:43:00 +0000 | [diff] [blame] | 149 | { |
| 150 | ScrollbarMode newHorizontalMode; |
| 151 | ScrollbarMode newVerticalMode; |
| 152 | |
| 153 | scrollbarModes(newHorizontalMode, newVerticalMode); |
| 154 | |
| 155 | if (canScroll && newVerticalMode == ScrollbarAlwaysOff) |
| 156 | newVerticalMode = ScrollbarAuto; |
| 157 | else if (!canScroll) |
| 158 | newVerticalMode = ScrollbarAlwaysOff; |
| 159 | |
| 160 | if (canScroll && newHorizontalMode == ScrollbarAlwaysOff) |
| 161 | newHorizontalMode = ScrollbarAuto; |
| 162 | else if (!canScroll) |
| 163 | newHorizontalMode = ScrollbarAlwaysOff; |
| 164 | |
| 165 | setScrollbarModes(newHorizontalMode, newVerticalMode); |
| 166 | } |
| 167 | |
hyatt@apple.com | 64a3be2 | 2008-09-25 20:49:17 +0000 | [diff] [blame] | 168 | void ScrollView::setCanBlitOnScroll(bool b) |
| 169 | { |
cwzwarich@webkit.org | d96b94e | 2008-12-11 21:56:07 +0000 | [diff] [blame] | 170 | if (platformWidget()) { |
| 171 | platformSetCanBlitOnScroll(b); |
hyatt@apple.com | 64a3be2 | 2008-09-25 20:49:17 +0000 | [diff] [blame] | 172 | return; |
cwzwarich@webkit.org | d96b94e | 2008-12-11 21:56:07 +0000 | [diff] [blame] | 173 | } |
| 174 | |
hyatt@apple.com | 64a3be2 | 2008-09-25 20:49:17 +0000 | [diff] [blame] | 175 | m_canBlitOnScroll = b; |
cwzwarich@webkit.org | d96b94e | 2008-12-11 21:56:07 +0000 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | bool ScrollView::canBlitOnScroll() const |
| 179 | { |
hyatt@apple.com | 64a3be2 | 2008-09-25 20:49:17 +0000 | [diff] [blame] | 180 | if (platformWidget()) |
cwzwarich@webkit.org | d96b94e | 2008-12-11 21:56:07 +0000 | [diff] [blame] | 181 | return platformCanBlitOnScroll(); |
| 182 | |
| 183 | return m_canBlitOnScroll; |
hyatt@apple.com | 64a3be2 | 2008-09-25 20:49:17 +0000 | [diff] [blame] | 184 | } |
| 185 | |
kenneth@webkit.org | 9ba6222 | 2009-12-03 14:25:50 +0000 | [diff] [blame] | 186 | void ScrollView::setPaintsEntireContents(bool paintsEntireContents) |
| 187 | { |
| 188 | m_paintsEntireContents = paintsEntireContents; |
| 189 | } |
| 190 | |
andreas.kling@nokia.com | 51bae85 | 2010-11-23 16:58:46 +0000 | [diff] [blame] | 191 | void ScrollView::setDelegatesScrolling(bool delegatesScrolling) |
| 192 | { |
noam.rosenthal@nokia.com | 91de1b5 | 2012-01-27 15:35:40 +0000 | [diff] [blame] | 193 | if (m_delegatesScrolling == delegatesScrolling) |
| 194 | return; |
| 195 | |
andreas.kling@nokia.com | 51bae85 | 2010-11-23 16:58:46 +0000 | [diff] [blame] | 196 | m_delegatesScrolling = delegatesScrolling; |
noam.rosenthal@nokia.com | 91de1b5 | 2012-01-27 15:35:40 +0000 | [diff] [blame] | 197 | delegatesScrollingDidChange(); |
andreas.kling@nokia.com | 51bae85 | 2010-11-23 16:58:46 +0000 | [diff] [blame] | 198 | } |
simon.fraser@apple.com | 53149ac | 2014-03-21 18:56:04 +0000 | [diff] [blame] | 199 | |
simon.fraser@apple.com | 947a90e | 2014-04-18 20:31:35 +0000 | [diff] [blame] | 200 | IntPoint ScrollView::contentsScrollPosition() const |
| 201 | { |
ap@apple.com | 1e847592 | 2018-10-18 21:38:50 +0000 | [diff] [blame] | 202 | #if PLATFORM(IOS_FAMILY) |
simon.fraser@apple.com | 947a90e | 2014-04-18 20:31:35 +0000 | [diff] [blame] | 203 | if (platformWidget()) |
| 204 | return actualScrollPosition(); |
| 205 | #endif |
| 206 | return scrollPosition(); |
| 207 | } |
| 208 | |
| 209 | void ScrollView::setContentsScrollPosition(const IntPoint& position) |
| 210 | { |
ap@apple.com | 1e847592 | 2018-10-18 21:38:50 +0000 | [diff] [blame] | 211 | #if PLATFORM(IOS_FAMILY) |
simon.fraser@apple.com | 947a90e | 2014-04-18 20:31:35 +0000 | [diff] [blame] | 212 | if (platformWidget()) |
| 213 | setActualScrollPosition(position); |
| 214 | #endif |
| 215 | setScrollPosition(position); |
| 216 | } |
| 217 | |
ap@apple.com | 1e847592 | 2018-10-18 21:38:50 +0000 | [diff] [blame] | 218 | #if !PLATFORM(IOS_FAMILY) |
bdakin@apple.com | 572c9f3 | 2014-03-20 23:19:04 +0000 | [diff] [blame] | 219 | IntRect ScrollView::unobscuredContentRect(VisibleContentRectIncludesScrollbars scrollbarInclusion) const |
| 220 | { |
simon.fraser@apple.com | 53149ac | 2014-03-21 18:56:04 +0000 | [diff] [blame] | 221 | return unobscuredContentRectInternal(scrollbarInclusion); |
| 222 | } |
| 223 | #endif |
| 224 | |
| 225 | IntRect ScrollView::unobscuredContentRectInternal(VisibleContentRectIncludesScrollbars scrollbarInclusion) const |
| 226 | { |
simon.fraser@apple.com | 82c0d2d | 2016-11-05 00:55:43 +0000 | [diff] [blame] | 227 | FloatSize visibleContentSize = sizeForUnobscuredContent(scrollbarInclusion); |
bdakin@apple.com | 572c9f3 | 2014-03-20 23:19:04 +0000 | [diff] [blame] | 228 | visibleContentSize.scale(1 / visibleContentScaleFactor()); |
simon.fraser@apple.com | 149e80d | 2015-12-31 18:50:10 +0000 | [diff] [blame] | 229 | return IntRect(m_scrollPosition, expandedIntSize(visibleContentSize)); |
bdakin@apple.com | 572c9f3 | 2014-03-20 23:19:04 +0000 | [diff] [blame] | 230 | } |
simon.fraser@apple.com | 53149ac | 2014-03-21 18:56:04 +0000 | [diff] [blame] | 231 | |
simon.fraser@apple.com | 82c0d2d | 2016-11-05 00:55:43 +0000 | [diff] [blame] | 232 | IntSize ScrollView::sizeForVisibleContent(VisibleContentRectIncludesScrollbars scrollbarInclusion) const |
hyatt@apple.com | 79be62c | 2008-09-25 22:25:22 +0000 | [diff] [blame] | 233 | { |
| 234 | if (platformWidget()) |
bdakin@apple.com | 3834ce7 | 2014-08-01 22:47:57 +0000 | [diff] [blame] | 235 | return platformVisibleContentSizeIncludingObscuredArea(scrollbarInclusion == IncludeScrollbars); |
andreas.kling@nokia.com | 7f1b0a4 | 2010-11-11 12:38:58 +0000 | [diff] [blame] | 236 | |
ryuan.choi@navercorp.com | 05ea83f | 2015-04-29 05:05:48 +0000 | [diff] [blame] | 237 | #if USE(COORDINATED_GRAPHICS) |
commit-queue@webkit.org | 1c60f94 | 2016-07-23 15:25:42 +0000 | [diff] [blame] | 238 | if (m_useFixedLayout && !m_fixedVisibleContentRect.isEmpty()) |
aelias@chromium.org | d230b35 | 2013-01-29 06:19:10 +0000 | [diff] [blame] | 239 | return m_fixedVisibleContentRect.size(); |
dbates@webkit.org | b8ade58 | 2014-01-09 22:59:07 +0000 | [diff] [blame] | 240 | #endif |
andreas.kling@nokia.com | e066ecf | 2010-11-17 22:02:28 +0000 | [diff] [blame] | 241 | |
simon.fraser@apple.com | 870034d | 2015-12-16 23:41:05 +0000 | [diff] [blame] | 242 | IntSize scrollbarSpace; |
| 243 | if (scrollbarInclusion == ExcludeScrollbars) |
| 244 | scrollbarSpace = scrollbarIntrusion(); |
kling@webkit.org | 8c0a7db | 2011-12-07 16:40:31 +0000 | [diff] [blame] | 245 | |
simon.fraser@apple.com | 870034d | 2015-12-16 23:41:05 +0000 | [diff] [blame] | 246 | return IntSize(width() - scrollbarSpace.width(), height() - scrollbarSpace.height()).expandedTo(IntSize()); |
hyatt@apple.com | c01fb23 | 2008-09-26 04:28:25 +0000 | [diff] [blame] | 247 | } |
bdakin@apple.com | 572c9f3 | 2014-03-20 23:19:04 +0000 | [diff] [blame] | 248 | |
simon.fraser@apple.com | 82c0d2d | 2016-11-05 00:55:43 +0000 | [diff] [blame] | 249 | IntSize ScrollView::sizeForUnobscuredContent(VisibleContentRectIncludesScrollbars scrollbarInclusion) const |
bdakin@apple.com | 572c9f3 | 2014-03-20 23:19:04 +0000 | [diff] [blame] | 250 | { |
bdakin@apple.com | 572c9f3 | 2014-03-20 23:19:04 +0000 | [diff] [blame] | 251 | if (platformWidget()) |
bdakin@apple.com | 35d6420 | 2014-08-01 22:39:52 +0000 | [diff] [blame] | 252 | return platformVisibleContentSize(scrollbarInclusion == IncludeScrollbars); |
bdakin@apple.com | 572c9f3 | 2014-03-20 23:19:04 +0000 | [diff] [blame] | 253 | |
simon.fraser@apple.com | 82c0d2d | 2016-11-05 00:55:43 +0000 | [diff] [blame] | 254 | IntSize visibleContentSize = sizeForVisibleContent(scrollbarInclusion); |
| 255 | |
ryuan.choi@navercorp.com | 05ea83f | 2015-04-29 05:05:48 +0000 | [diff] [blame] | 256 | #if USE(COORDINATED_GRAPHICS) |
commit-queue@webkit.org | 1c60f94 | 2016-07-23 15:25:42 +0000 | [diff] [blame] | 257 | if (m_useFixedLayout && !m_fixedVisibleContentRect.isEmpty()) |
bdakin@apple.com | 572c9f3 | 2014-03-20 23:19:04 +0000 | [diff] [blame] | 258 | return visibleContentSize; |
| 259 | #endif |
| 260 | |
| 261 | visibleContentSize.setHeight(visibleContentSize.height() - topContentInset()); |
| 262 | return visibleContentSize; |
| 263 | } |
aelias@chromium.org | d230b35 | 2013-01-29 06:19:10 +0000 | [diff] [blame] | 264 | |
bdakin@apple.com | 572c9f3 | 2014-03-20 23:19:04 +0000 | [diff] [blame] | 265 | IntRect ScrollView::visibleContentRectInternal(VisibleContentRectIncludesScrollbars scrollbarInclusion, VisibleContentRectBehavior visibleContentRectBehavior) const |
aelias@chromium.org | d230b35 | 2013-01-29 06:19:10 +0000 | [diff] [blame] | 266 | { |
ap@apple.com | 1e847592 | 2018-10-18 21:38:50 +0000 | [diff] [blame] | 267 | #if PLATFORM(IOS_FAMILY) |
simon.fraser@apple.com | 846bdab | 2014-01-24 00:39:46 +0000 | [diff] [blame] | 268 | if (visibleContentRectBehavior == LegacyIOSDocumentViewRect) { |
| 269 | if (platformWidget()) |
commit-queue@webkit.org | 13f9215 | 2014-10-02 06:10:59 +0000 | [diff] [blame] | 270 | return platformVisibleContentRect(scrollbarInclusion == IncludeScrollbars); |
simon.fraser@apple.com | 846bdab | 2014-01-24 00:39:46 +0000 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | if (platformWidget()) |
simon.fraser@apple.com | 53149ac | 2014-03-21 18:56:04 +0000 | [diff] [blame] | 274 | return unobscuredContentRect(scrollbarInclusion); |
simon.fraser@apple.com | 846bdab | 2014-01-24 00:39:46 +0000 | [diff] [blame] | 275 | #else |
| 276 | UNUSED_PARAM(visibleContentRectBehavior); |
| 277 | #endif |
| 278 | |
aelias@chromium.org | d230b35 | 2013-01-29 06:19:10 +0000 | [diff] [blame] | 279 | if (platformWidget()) |
bdakin@apple.com | 572c9f3 | 2014-03-20 23:19:04 +0000 | [diff] [blame] | 280 | return platformVisibleContentRect(scrollbarInclusion == IncludeScrollbars); |
aelias@chromium.org | d230b35 | 2013-01-29 06:19:10 +0000 | [diff] [blame] | 281 | |
ryuan.choi@navercorp.com | 05ea83f | 2015-04-29 05:05:48 +0000 | [diff] [blame] | 282 | #if USE(COORDINATED_GRAPHICS) |
commit-queue@webkit.org | 1c60f94 | 2016-07-23 15:25:42 +0000 | [diff] [blame] | 283 | if (m_useFixedLayout && !m_fixedVisibleContentRect.isEmpty()) |
aelias@chromium.org | d230b35 | 2013-01-29 06:19:10 +0000 | [diff] [blame] | 284 | return m_fixedVisibleContentRect; |
dbates@webkit.org | b8ade58 | 2014-01-09 22:59:07 +0000 | [diff] [blame] | 285 | #endif |
aelias@chromium.org | d230b35 | 2013-01-29 06:19:10 +0000 | [diff] [blame] | 286 | |
benjamin@webkit.org | 78113d0 | 2014-05-16 21:39:43 +0000 | [diff] [blame] | 287 | return unobscuredContentRect(scrollbarInclusion); |
aelias@chromium.org | d230b35 | 2013-01-29 06:19:10 +0000 | [diff] [blame] | 288 | } |
hyatt@apple.com | c01fb23 | 2008-09-26 04:28:25 +0000 | [diff] [blame] | 289 | |
simon.fraser@apple.com | ece0467 | 2012-06-07 17:57:00 +0000 | [diff] [blame] | 290 | IntSize ScrollView::layoutSize() const |
| 291 | { |
simon.fraser@apple.com | 82c0d2d | 2016-11-05 00:55:43 +0000 | [diff] [blame] | 292 | return m_fixedLayoutSize.isEmpty() || !m_useFixedLayout ? sizeForUnobscuredContent() : m_fixedLayoutSize; |
treat@webkit.org | 17db32f | 2009-01-04 17:25:30 +0000 | [diff] [blame] | 293 | } |
| 294 | |
eae@chromium.org | 92a579f | 2011-11-08 02:11:06 +0000 | [diff] [blame] | 295 | IntSize ScrollView::fixedLayoutSize() const |
treat@webkit.org | 17db32f | 2009-01-04 17:25:30 +0000 | [diff] [blame] | 296 | { |
| 297 | return m_fixedLayoutSize; |
| 298 | } |
| 299 | |
eae@chromium.org | 92a579f | 2011-11-08 02:11:06 +0000 | [diff] [blame] | 300 | void ScrollView::setFixedLayoutSize(const IntSize& newSize) |
treat@webkit.org | 17db32f | 2009-01-04 17:25:30 +0000 | [diff] [blame] | 301 | { |
| 302 | if (fixedLayoutSize() == newSize) |
| 303 | return; |
simon.fraser@apple.com | 677f042 | 2017-12-02 17:55:24 +0000 | [diff] [blame] | 304 | |
| 305 | LOG_WITH_STREAM(Layout, stream << "ScrollView " << this << " setFixedLayoutSize " << newSize); |
treat@webkit.org | 17db32f | 2009-01-04 17:25:30 +0000 | [diff] [blame] | 306 | m_fixedLayoutSize = newSize; |
aelias@chromium.org | 3d1c26a | 2013-01-31 19:25:41 +0000 | [diff] [blame] | 307 | if (m_useFixedLayout) |
simon.fraser@apple.com | 448c42e | 2015-02-25 05:35:38 +0000 | [diff] [blame] | 308 | availableContentSizeChanged(AvailableSizeChangeReason::AreaSizeChanged); |
treat@webkit.org | 17db32f | 2009-01-04 17:25:30 +0000 | [diff] [blame] | 309 | } |
| 310 | |
| 311 | bool ScrollView::useFixedLayout() const |
| 312 | { |
| 313 | return m_useFixedLayout; |
| 314 | } |
| 315 | |
| 316 | void ScrollView::setUseFixedLayout(bool enable) |
| 317 | { |
| 318 | if (useFixedLayout() == enable) |
| 319 | return; |
| 320 | m_useFixedLayout = enable; |
allan.jensen@digia.com | 970a0bf | 2013-08-14 11:29:32 +0000 | [diff] [blame] | 321 | if (!m_fixedLayoutSize.isEmpty()) |
simon.fraser@apple.com | 448c42e | 2015-02-25 05:35:38 +0000 | [diff] [blame] | 322 | availableContentSizeChanged(AvailableSizeChangeReason::AreaSizeChanged); |
allan.jensen@digia.com | 970a0bf | 2013-08-14 11:29:32 +0000 | [diff] [blame] | 323 | } |
| 324 | |
simon.fraser@apple.com | 448c42e | 2015-02-25 05:35:38 +0000 | [diff] [blame] | 325 | void ScrollView::availableContentSizeChanged(AvailableSizeChangeReason reason) |
allan.jensen@digia.com | 970a0bf | 2013-08-14 11:29:32 +0000 | [diff] [blame] | 326 | { |
simon.fraser@apple.com | 448c42e | 2015-02-25 05:35:38 +0000 | [diff] [blame] | 327 | ScrollableArea::availableContentSizeChanged(reason); |
simon.fraser@apple.com | 346c8be | 2015-03-01 04:36:39 +0000 | [diff] [blame] | 328 | |
| 329 | if (platformWidget()) |
| 330 | return; |
| 331 | |
simon.fraser@apple.com | 448c42e | 2015-02-25 05:35:38 +0000 | [diff] [blame] | 332 | if (reason != AvailableSizeChangeReason::ScrollbarsChanged) |
simon.fraser@apple.com | db0e067 | 2015-12-30 00:29:36 +0000 | [diff] [blame] | 333 | updateScrollbars(scrollPosition()); |
treat@webkit.org | 17db32f | 2009-01-04 17:25:30 +0000 | [diff] [blame] | 334 | } |
| 335 | |
eae@chromium.org | 92a579f | 2011-11-08 02:11:06 +0000 | [diff] [blame] | 336 | IntSize ScrollView::contentsSize() const |
hyatt@apple.com | c01fb23 | 2008-09-26 04:28:25 +0000 | [diff] [blame] | 337 | { |
hyatt@apple.com | c01fb23 | 2008-09-26 04:28:25 +0000 | [diff] [blame] | 338 | return m_contentsSize; |
hyatt@apple.com | 79be62c | 2008-09-25 22:25:22 +0000 | [diff] [blame] | 339 | } |
| 340 | |
eae@chromium.org | 92a579f | 2011-11-08 02:11:06 +0000 | [diff] [blame] | 341 | void ScrollView::setContentsSize(const IntSize& newSize) |
hyatt@apple.com | 25cd25e | 2008-09-26 06:07:14 +0000 | [diff] [blame] | 342 | { |
| 343 | if (contentsSize() == newSize) |
| 344 | return; |
| 345 | m_contentsSize = newSize; |
| 346 | if (platformWidget()) |
| 347 | platformSetContentsSize(); |
| 348 | else |
simon.fraser@apple.com | db0e067 | 2015-12-30 00:29:36 +0000 | [diff] [blame] | 349 | updateScrollbars(scrollPosition()); |
commit-queue@webkit.org | c1e9436 | 2012-02-22 20:18:30 +0000 | [diff] [blame] | 350 | updateOverhangAreas(); |
hyatt@apple.com | 25cd25e | 2008-09-26 06:07:14 +0000 | [diff] [blame] | 351 | } |
| 352 | |
simon.fraser@apple.com | db0e067 | 2015-12-30 00:29:36 +0000 | [diff] [blame] | 353 | ScrollPosition ScrollView::maximumScrollPosition() const |
hyatt@apple.com | 7eedf8f | 2008-09-26 05:40:50 +0000 | [diff] [blame] | 354 | { |
simon.fraser@apple.com | efc492b | 2015-12-30 20:15:27 +0000 | [diff] [blame] | 355 | ScrollPosition maximumPosition = ScrollableArea::maximumScrollPosition(); |
| 356 | // FIXME: can this be moved into the base class? |
| 357 | maximumPosition.clampNegativeToZero(); |
| 358 | return maximumPosition; |
xji@chromium.org | 506e6f6 | 2010-11-30 01:11:08 +0000 | [diff] [blame] | 359 | } |
| 360 | |
simon.fraser@apple.com | db0e067 | 2015-12-30 00:29:36 +0000 | [diff] [blame] | 361 | ScrollPosition ScrollView::adjustScrollPositionWithinRange(const ScrollPosition& scrollPoint) const |
xji@chromium.org | 506e6f6 | 2010-11-30 01:11:08 +0000 | [diff] [blame] | 362 | { |
simon.fraser@apple.com | d61b65e | 2017-01-30 19:46:40 +0000 | [diff] [blame] | 363 | if (!constrainsScrollingToContentEdge() || m_allowsUnclampedScrollPosition) |
tonikitoo@webkit.org | c45e9b3 | 2012-04-20 19:11:52 +0000 | [diff] [blame] | 364 | return scrollPoint; |
| 365 | |
simon.fraser@apple.com | e84dd14 | 2015-12-24 03:43:23 +0000 | [diff] [blame] | 366 | return scrollPoint.constrainedBetween(minimumScrollPosition(), maximumScrollPosition()); |
hyatt@apple.com | 7eedf8f | 2008-09-26 05:40:50 +0000 | [diff] [blame] | 367 | } |
| 368 | |
simon.fraser@apple.com | 94cc9c2 | 2016-01-01 03:17:31 +0000 | [diff] [blame] | 369 | ScrollPosition ScrollView::documentScrollPositionRelativeToViewOrigin() const |
bdakin@apple.com | b622f31 | 2013-04-10 20:57:25 +0000 | [diff] [blame] | 370 | { |
mmaxfield@apple.com | 11fab7d | 2016-03-18 01:02:32 +0000 | [diff] [blame] | 371 | return scrollPosition() - IntSize( |
mmaxfield@apple.com | 4195a70 | 2016-04-27 01:25:26 +0000 | [diff] [blame] | 372 | shouldPlaceBlockDirectionScrollbarOnLeft() && m_verticalScrollbar ? m_verticalScrollbar->occupiedWidth() : 0, |
mmaxfield@apple.com | 11fab7d | 2016-03-18 01:02:32 +0000 | [diff] [blame] | 373 | headerHeight() + topContentInset(TopContentInsetType::WebCoreOrPlatformContentInset)); |
bdakin@apple.com | b622f31 | 2013-04-10 20:57:25 +0000 | [diff] [blame] | 374 | } |
| 375 | |
simon.fraser@apple.com | 94cc9c2 | 2016-01-01 03:17:31 +0000 | [diff] [blame] | 376 | ScrollPosition ScrollView::documentScrollPositionRelativeToScrollableAreaOrigin() const |
bdakin@apple.com | fd0dfc8 | 2013-04-17 23:23:20 +0000 | [diff] [blame] | 377 | { |
simon.fraser@apple.com | 94cc9c2 | 2016-01-01 03:17:31 +0000 | [diff] [blame] | 378 | return scrollPosition() - IntSize(0, headerHeight()); |
bdakin@apple.com | 19403f8 | 2014-05-14 00:13:56 +0000 | [diff] [blame] | 379 | } |
| 380 | |
commit-queue@webkit.org | 1bf3b4b | 2010-09-08 19:31:47 +0000 | [diff] [blame] | 381 | int ScrollView::scrollSize(ScrollbarOrientation orientation) const |
| 382 | { |
tonikitoo@webkit.org | b65231f | 2012-04-27 03:08:47 +0000 | [diff] [blame] | 383 | // If no scrollbars are present, it does not indicate content is not be scrollable. |
| 384 | if (!m_horizontalScrollbar && !m_verticalScrollbar && !prohibitsScrolling()) { |
aestes@apple.com | 0f23b26 | 2014-01-29 03:06:01 +0000 | [diff] [blame] | 385 | IntSize scrollSize = m_contentsSize - visibleContentRect(LegacyIOSDocumentVisibleRect).size(); |
tonikitoo@webkit.org | b65231f | 2012-04-27 03:08:47 +0000 | [diff] [blame] | 386 | scrollSize.clampNegativeToZero(); |
| 387 | return orientation == HorizontalScrollbar ? scrollSize.width() : scrollSize.height(); |
| 388 | } |
| 389 | |
| 390 | Scrollbar* scrollbar = ((orientation == HorizontalScrollbar) ? m_horizontalScrollbar : m_verticalScrollbar).get(); |
| 391 | return scrollbar ? (scrollbar->totalSize() - scrollbar->visibleSize()) : 0; |
commit-queue@webkit.org | 1bf3b4b | 2010-09-08 19:31:47 +0000 | [diff] [blame] | 392 | } |
| 393 | |
bdakin@apple.com | 9e05cff | 2011-03-16 02:21:59 +0000 | [diff] [blame] | 394 | void ScrollView::notifyPageThatContentAreaWillPaint() const |
| 395 | { |
| 396 | } |
| 397 | |
simon.fraser@apple.com | a10a6d4 | 2016-01-02 04:45:36 +0000 | [diff] [blame] | 398 | void ScrollView::setScrollOffset(const ScrollOffset& offset) |
commit-queue@webkit.org | 1bf3b4b | 2010-09-08 19:31:47 +0000 | [diff] [blame] | 399 | { |
simon.fraser@apple.com | d61b65e | 2017-01-30 19:46:40 +0000 | [diff] [blame] | 400 | LOG_WITH_STREAM(Scrolling, stream << "\nScrollView::setScrollOffset " << offset << " constrains " << constrainsScrollingToContentEdge()); |
simon.fraser@apple.com | a10a6d4 | 2016-01-02 04:45:36 +0000 | [diff] [blame] | 401 | |
simon.fraser@apple.com | efc492b | 2015-12-30 20:15:27 +0000 | [diff] [blame] | 402 | IntPoint constrainedOffset = offset; |
| 403 | if (constrainsScrollingToContentEdge()) |
| 404 | constrainedOffset = constrainedOffset.constrainedBetween(IntPoint(), maximumScrollOffset()); |
weinig@apple.com | 2a13aa8 | 2011-01-20 23:14:47 +0000 | [diff] [blame] | 405 | |
simon.fraser@apple.com | 149e80d | 2015-12-31 18:50:10 +0000 | [diff] [blame] | 406 | scrollTo(scrollPositionFromOffset(constrainedOffset)); |
commit-queue@webkit.org | 1bf3b4b | 2010-09-08 19:31:47 +0000 | [diff] [blame] | 407 | } |
| 408 | |
simon.fraser@apple.com | 3d2abaa | 2015-12-31 19:35:18 +0000 | [diff] [blame] | 409 | void ScrollView::scrollOffsetChangedViaPlatformWidget(const ScrollOffset& oldOffset, const ScrollOffset& newOffset) |
bfulgham@apple.com | a41524c | 2015-01-19 20:02:01 +0000 | [diff] [blame] | 410 | { |
| 411 | // We should not attempt to actually modify (paint) platform widgets if the layout phase |
| 412 | // is not complete. Instead, defer the scroll event until the layout finishes. |
| 413 | if (shouldDeferScrollUpdateAfterContentSizeChange()) { |
| 414 | // We only care about the most recent scroll position change request |
cdumez@apple.com | caf9068 | 2016-05-16 20:24:52 +0000 | [diff] [blame] | 415 | m_deferredScrollOffsets = std::make_pair(oldOffset, newOffset); |
bfulgham@apple.com | a41524c | 2015-01-19 20:02:01 +0000 | [diff] [blame] | 416 | return; |
| 417 | } |
| 418 | |
simon.fraser@apple.com | 3d2abaa | 2015-12-31 19:35:18 +0000 | [diff] [blame] | 419 | scrollOffsetChangedViaPlatformWidgetImpl(oldOffset, newOffset); |
bfulgham@apple.com | a41524c | 2015-01-19 20:02:01 +0000 | [diff] [blame] | 420 | } |
| 421 | |
| 422 | void ScrollView::handleDeferredScrollUpdateAfterContentSizeChange() |
| 423 | { |
| 424 | ASSERT(!shouldDeferScrollUpdateAfterContentSizeChange()); |
| 425 | |
simon.fraser@apple.com | 3d2abaa | 2015-12-31 19:35:18 +0000 | [diff] [blame] | 426 | if (!m_deferredScrollDelta && !m_deferredScrollOffsets) |
bfulgham@apple.com | a41524c | 2015-01-19 20:02:01 +0000 | [diff] [blame] | 427 | return; |
| 428 | |
simon.fraser@apple.com | 3d2abaa | 2015-12-31 19:35:18 +0000 | [diff] [blame] | 429 | ASSERT(static_cast<bool>(m_deferredScrollDelta) != static_cast<bool>(m_deferredScrollOffsets)); |
bfulgham@apple.com | a41524c | 2015-01-19 20:02:01 +0000 | [diff] [blame] | 430 | |
| 431 | if (m_deferredScrollDelta) |
cdumez@apple.com | caf9068 | 2016-05-16 20:24:52 +0000 | [diff] [blame] | 432 | completeUpdatesAfterScrollTo(m_deferredScrollDelta.value()); |
simon.fraser@apple.com | 3d2abaa | 2015-12-31 19:35:18 +0000 | [diff] [blame] | 433 | else if (m_deferredScrollOffsets) |
cdumez@apple.com | caf9068 | 2016-05-16 20:24:52 +0000 | [diff] [blame] | 434 | scrollOffsetChangedViaPlatformWidgetImpl(m_deferredScrollOffsets.value().first, m_deferredScrollOffsets.value().second); |
bfulgham@apple.com | a41524c | 2015-01-19 20:02:01 +0000 | [diff] [blame] | 435 | |
utatane.tea@gmail.com | 4392696 | 2016-11-27 06:08:16 +0000 | [diff] [blame] | 436 | m_deferredScrollDelta = std::nullopt; |
| 437 | m_deferredScrollOffsets = std::nullopt; |
bfulgham@apple.com | a41524c | 2015-01-19 20:02:01 +0000 | [diff] [blame] | 438 | } |
| 439 | |
simon.fraser@apple.com | 149e80d | 2015-12-31 18:50:10 +0000 | [diff] [blame] | 440 | void ScrollView::scrollTo(const ScrollPosition& newPosition) |
hyatt@apple.com | f1ffabf | 2008-10-02 18:23:32 +0000 | [diff] [blame] | 441 | { |
simon.fraser@apple.com | a10a6d4 | 2016-01-02 04:45:36 +0000 | [diff] [blame] | 442 | LOG_WITH_STREAM(Scrolling, stream << "ScrollView::scrollTo " << newPosition << " min: " << minimumScrollPosition() << " max: " << maximumScrollPosition()); |
| 443 | |
simon.fraser@apple.com | 149e80d | 2015-12-31 18:50:10 +0000 | [diff] [blame] | 444 | IntSize scrollDelta = newPosition - m_scrollPosition; |
bfulgham@apple.com | a41524c | 2015-01-19 20:02:01 +0000 | [diff] [blame] | 445 | if (scrollDelta.isZero()) |
hyatt@apple.com | f1ffabf | 2008-10-02 18:23:32 +0000 | [diff] [blame] | 446 | return; |
simon.fraser@apple.com | 149e80d | 2015-12-31 18:50:10 +0000 | [diff] [blame] | 447 | |
| 448 | m_scrollPosition = newPosition; |
hyatt@apple.com | f1ffabf | 2008-10-02 18:23:32 +0000 | [diff] [blame] | 449 | |
| 450 | if (scrollbarsSuppressed()) |
| 451 | return; |
| 452 | |
ryuan.choi@navercorp.com | 05ea83f | 2015-04-29 05:05:48 +0000 | [diff] [blame] | 453 | #if USE(COORDINATED_GRAPHICS) |
commit-queue@webkit.org | f03960f | 2012-05-15 15:07:59 +0000 | [diff] [blame] | 454 | if (delegatesScrolling()) { |
simon.fraser@apple.com | 149e80d | 2015-12-31 18:50:10 +0000 | [diff] [blame] | 455 | requestScrollPositionUpdate(newPosition); |
commit-queue@webkit.org | f03960f | 2012-05-15 15:07:59 +0000 | [diff] [blame] | 456 | return; |
| 457 | } |
| 458 | #endif |
bfulgham@apple.com | a41524c | 2015-01-19 20:02:01 +0000 | [diff] [blame] | 459 | // We should not attempt to actually modify layer contents if the layout phase |
| 460 | // is not complete. Instead, defer the scroll event until the layout finishes. |
| 461 | if (shouldDeferScrollUpdateAfterContentSizeChange()) { |
| 462 | ASSERT(!m_deferredScrollDelta); |
cdumez@apple.com | caf9068 | 2016-05-16 20:24:52 +0000 | [diff] [blame] | 463 | m_deferredScrollDelta = scrollDelta; |
bfulgham@apple.com | a41524c | 2015-01-19 20:02:01 +0000 | [diff] [blame] | 464 | return; |
| 465 | } |
| 466 | |
| 467 | completeUpdatesAfterScrollTo(scrollDelta); |
| 468 | } |
| 469 | |
| 470 | void ScrollView::completeUpdatesAfterScrollTo(const IntSize& scrollDelta) |
| 471 | { |
simon.fraser@apple.com | 71ffa3d | 2013-11-13 22:22:14 +0000 | [diff] [blame] | 472 | updateLayerPositionsAfterScrolling(); |
hyatt@apple.com | f1ffabf | 2008-10-02 18:23:32 +0000 | [diff] [blame] | 473 | scrollContents(scrollDelta); |
simon.fraser@apple.com | 71ffa3d | 2013-11-13 22:22:14 +0000 | [diff] [blame] | 474 | updateCompositingLayersAfterScrolling(); |
hyatt@apple.com | f1ffabf | 2008-10-02 18:23:32 +0000 | [diff] [blame] | 475 | } |
| 476 | |
simon.fraser@apple.com | 936d921 | 2016-01-03 19:50:51 +0000 | [diff] [blame] | 477 | int ScrollView::scrollOffset(ScrollbarOrientation orientation) const |
commit-queue@webkit.org | 4a8bb26 | 2010-09-13 06:24:41 +0000 | [diff] [blame] | 478 | { |
simon.fraser@apple.com | 936d921 | 2016-01-03 19:50:51 +0000 | [diff] [blame] | 479 | ScrollOffset offset = scrollOffsetFromPosition(scrollPosition()); |
| 480 | |
| 481 | if (orientation == HorizontalScrollbar) |
| 482 | return offset.x(); |
| 483 | |
| 484 | if (orientation == VerticalScrollbar) |
| 485 | return offset.y(); |
| 486 | |
weinig@apple.com | 2a13aa8 | 2011-01-20 23:14:47 +0000 | [diff] [blame] | 487 | return 0; |
commit-queue@webkit.org | 4a8bb26 | 2010-09-13 06:24:41 +0000 | [diff] [blame] | 488 | } |
| 489 | |
simon.fraser@apple.com | db0e067 | 2015-12-30 00:29:36 +0000 | [diff] [blame] | 490 | void ScrollView::setScrollPosition(const ScrollPosition& scrollPosition) |
hyatt@apple.com | 90abd56 | 2008-09-29 19:46:37 +0000 | [diff] [blame] | 491 | { |
simon.fraser@apple.com | a10a6d4 | 2016-01-02 04:45:36 +0000 | [diff] [blame] | 492 | LOG_WITH_STREAM(Scrolling, stream << "ScrollView::setScrollPosition " << scrollPosition); |
| 493 | |
hyatt@apple.com | deb39ee | 2008-10-01 22:30:56 +0000 | [diff] [blame] | 494 | if (prohibitsScrolling()) |
| 495 | return; |
| 496 | |
hyatt@apple.com | 90abd56 | 2008-09-29 19:46:37 +0000 | [diff] [blame] | 497 | if (platformWidget()) { |
simon.fraser@apple.com | db0e067 | 2015-12-30 00:29:36 +0000 | [diff] [blame] | 498 | platformSetScrollPosition(scrollPosition); |
hyatt@apple.com | 90abd56 | 2008-09-29 19:46:37 +0000 | [diff] [blame] | 499 | return; |
| 500 | } |
| 501 | |
simon.fraser@apple.com | 3d2abaa | 2015-12-31 19:35:18 +0000 | [diff] [blame] | 502 | ScrollPosition newScrollPosition = !delegatesScrolling() ? adjustScrollPositionWithinRange(scrollPosition) : scrollPosition; |
andreas.kling@nokia.com | 7d61c56 | 2010-11-17 21:16:11 +0000 | [diff] [blame] | 503 | |
simon.fraser@apple.com | db0e067 | 2015-12-30 00:29:36 +0000 | [diff] [blame] | 504 | if ((!delegatesScrolling() || !inProgrammaticScroll()) && newScrollPosition == this->scrollPosition()) |
hyatt@apple.com | 90abd56 | 2008-09-29 19:46:37 +0000 | [diff] [blame] | 505 | return; |
| 506 | |
benjamin@webkit.org | e0b04c1 | 2013-06-09 19:52:49 +0000 | [diff] [blame] | 507 | if (requestScrollPositionUpdate(newScrollPosition)) |
| 508 | return; |
| 509 | |
simon.fraser@apple.com | db0e067 | 2015-12-30 00:29:36 +0000 | [diff] [blame] | 510 | updateScrollbars(newScrollPosition); |
hyatt@apple.com | 90abd56 | 2008-09-29 19:46:37 +0000 | [diff] [blame] | 511 | } |
| 512 | |
| 513 | bool ScrollView::scroll(ScrollDirection direction, ScrollGranularity granularity) |
| 514 | { |
tonikitoo@webkit.org | 3d48488 | 2010-10-10 14:23:49 +0000 | [diff] [blame] | 515 | if (platformWidget()) |
hyatt@apple.com | 90abd56 | 2008-09-29 19:46:37 +0000 | [diff] [blame] | 516 | return platformScroll(direction, granularity); |
weinig@apple.com | 2a13aa8 | 2011-01-20 23:14:47 +0000 | [diff] [blame] | 517 | |
weinig@apple.com | d7d77c3 | 2011-01-21 20:15:04 +0000 | [diff] [blame] | 518 | return ScrollableArea::scroll(direction, granularity); |
hyatt@apple.com | 90abd56 | 2008-09-29 19:46:37 +0000 | [diff] [blame] | 519 | } |
| 520 | |
hyatt@apple.com | a60d0ce | 2010-12-13 20:14:28 +0000 | [diff] [blame] | 521 | bool ScrollView::logicalScroll(ScrollLogicalDirection direction, ScrollGranularity granularity) |
| 522 | { |
| 523 | return scroll(logicalToPhysical(direction, isVerticalDocument(), isFlippedDocument()), granularity); |
| 524 | } |
| 525 | |
eae@chromium.org | 92a579f | 2011-11-08 02:11:06 +0000 | [diff] [blame] | 526 | IntSize ScrollView::overhangAmount() const |
weinig@apple.com | cc0f140 | 2011-01-28 19:05:43 +0000 | [diff] [blame] | 527 | { |
eae@chromium.org | 92a579f | 2011-11-08 02:11:06 +0000 | [diff] [blame] | 528 | IntSize stretch; |
weinig@apple.com | cc0f140 | 2011-01-28 19:05:43 +0000 | [diff] [blame] | 529 | |
simon.fraser@apple.com | efc492b | 2015-12-30 20:15:27 +0000 | [diff] [blame] | 530 | // FIXME: use maximumScrollOffset() |
| 531 | ScrollOffset scrollOffset = scrollOffsetFromPosition(scrollPosition()); |
| 532 | if (scrollOffset.y() < 0) |
| 533 | stretch.setHeight(scrollOffset.y()); |
| 534 | else if (totalContentsSize().height() && scrollOffset.y() > totalContentsSize().height() - visibleHeight()) |
| 535 | stretch.setHeight(scrollOffset.y() - (totalContentsSize().height() - visibleHeight())); |
weinig@apple.com | 8c01924 | 2011-03-10 21:43:37 +0000 | [diff] [blame] | 536 | |
simon.fraser@apple.com | efc492b | 2015-12-30 20:15:27 +0000 | [diff] [blame] | 537 | if (scrollOffset.x() < 0) |
| 538 | stretch.setWidth(scrollOffset.x()); |
| 539 | else if (contentsWidth() && scrollOffset.x() > contentsWidth() - visibleWidth()) |
| 540 | stretch.setWidth(scrollOffset.x() - (contentsWidth() - visibleWidth())); |
weinig@apple.com | cc0f140 | 2011-01-28 19:05:43 +0000 | [diff] [blame] | 541 | |
| 542 | return stretch; |
| 543 | } |
| 544 | |
simon.fraser@apple.com | db0e067 | 2015-12-30 00:29:36 +0000 | [diff] [blame] | 545 | void ScrollView::updateScrollbars(const ScrollPosition& desiredPosition) |
hyatt@apple.com | f1ffabf | 2008-10-02 18:23:32 +0000 | [diff] [blame] | 546 | { |
simon.fraser@apple.com | a10a6d4 | 2016-01-02 04:45:36 +0000 | [diff] [blame] | 547 | LOG_WITH_STREAM(Scrolling, stream << "ScrollView::updateScrollbars " << desiredPosition); |
| 548 | |
simon.fraser@apple.com | 0235bd5 | 2016-03-19 00:00:46 +0000 | [diff] [blame] | 549 | if (m_inUpdateScrollbars || prohibitsScrolling() || platformWidget()) |
hyatt@apple.com | f1ffabf | 2008-10-02 18:23:32 +0000 | [diff] [blame] | 550 | return; |
simon.fraser@apple.com | 0235bd5 | 2016-03-19 00:00:46 +0000 | [diff] [blame] | 551 | |
| 552 | if (delegatesScrolling()) { |
| 553 | if (scrollOriginChanged()) { |
| 554 | ScrollableArea::scrollToOffsetWithoutAnimation(scrollOffsetFromPosition(desiredPosition)); |
| 555 | resetScrollOriginChanged(); |
| 556 | } |
| 557 | return; |
| 558 | } |
hyatt@apple.com | f1ffabf | 2008-10-02 18:23:32 +0000 | [diff] [blame] | 559 | |
antti@apple.com | df98517 | 2014-01-22 13:07:25 +0000 | [diff] [blame] | 560 | bool hasOverlayScrollbars = (!m_horizontalScrollbar || m_horizontalScrollbar->isOverlayScrollbar()) && (!m_verticalScrollbar || m_verticalScrollbar->isOverlayScrollbar()); |
| 561 | |
simon.fraser@apple.com | 03e6103 | 2015-04-05 20:17:11 +0000 | [diff] [blame] | 562 | // If we came in here with the view already needing a layout then do that first. |
| 563 | // (This will be the common case, e.g., when the page changes due to window resizing for example). |
dglazkov@chromium.org | f0234eb | 2009-09-04 17:59:46 +0000 | [diff] [blame] | 564 | // This layout will not re-enter updateScrollbars and does not count towards our max layout pass total. |
antti@apple.com | df98517 | 2014-01-22 13:07:25 +0000 | [diff] [blame] | 565 | if (!m_scrollbarsSuppressed && !hasOverlayScrollbars) { |
dglazkov@chromium.org | f0234eb | 2009-09-04 17:59:46 +0000 | [diff] [blame] | 566 | m_inUpdateScrollbars = true; |
simon.fraser@apple.com | 448c42e | 2015-02-25 05:35:38 +0000 | [diff] [blame] | 567 | updateContentsSize(); |
dglazkov@chromium.org | f0234eb | 2009-09-04 17:59:46 +0000 | [diff] [blame] | 568 | m_inUpdateScrollbars = false; |
| 569 | } |
| 570 | |
eae@chromium.org | 92a579f | 2011-11-08 02:11:06 +0000 | [diff] [blame] | 571 | IntRect oldScrollCornerRect = scrollCornerRect(); |
simon.fraser@apple.com | c8bf639 | 2011-09-27 19:00:56 +0000 | [diff] [blame] | 572 | |
hyatt@apple.com | f1ffabf | 2008-10-02 18:23:32 +0000 | [diff] [blame] | 573 | bool hasHorizontalScrollbar = m_horizontalScrollbar; |
hyatt@apple.com | 82b0281 | 2009-04-08 22:33:48 +0000 | [diff] [blame] | 574 | bool hasVerticalScrollbar = m_verticalScrollbar; |
| 575 | |
| 576 | bool newHasHorizontalScrollbar = hasHorizontalScrollbar; |
| 577 | bool newHasVerticalScrollbar = hasVerticalScrollbar; |
| 578 | |
hyatt@apple.com | f1ffabf | 2008-10-02 18:23:32 +0000 | [diff] [blame] | 579 | ScrollbarMode hScroll = m_horizontalScrollbarMode; |
| 580 | ScrollbarMode vScroll = m_verticalScrollbarMode; |
| 581 | |
dglazkov@chromium.org | c0e2d52 | 2009-04-23 22:33:25 +0000 | [diff] [blame] | 582 | if (hScroll != ScrollbarAuto) |
| 583 | newHasHorizontalScrollbar = (hScroll == ScrollbarAlwaysOn); |
| 584 | if (vScroll != ScrollbarAuto) |
| 585 | newHasVerticalScrollbar = (vScroll == ScrollbarAlwaysOn); |
| 586 | |
simon.fraser@apple.com | 0cdf36c | 2013-09-20 21:47:47 +0000 | [diff] [blame] | 587 | bool scrollbarAddedOrRemoved = false; |
| 588 | |
hyatt@apple.com | 82b0281 | 2009-04-08 22:33:48 +0000 | [diff] [blame] | 589 | if (m_scrollbarsSuppressed || (hScroll != ScrollbarAuto && vScroll != ScrollbarAuto)) { |
simon.fraser@apple.com | 0cdf36c | 2013-09-20 21:47:47 +0000 | [diff] [blame] | 590 | if (hasHorizontalScrollbar != newHasHorizontalScrollbar && (hasHorizontalScrollbar || !avoidScrollbarCreation())) { |
| 591 | if (setHasHorizontalScrollbar(newHasHorizontalScrollbar)) |
| 592 | scrollbarAddedOrRemoved = true; |
| 593 | } |
| 594 | |
| 595 | if (hasVerticalScrollbar != newHasVerticalScrollbar && (hasVerticalScrollbar || !avoidScrollbarCreation())) { |
| 596 | if (setHasVerticalScrollbar(newHasVerticalScrollbar)) |
| 597 | scrollbarAddedOrRemoved = true; |
| 598 | } |
hyatt@apple.com | 82b0281 | 2009-04-08 22:33:48 +0000 | [diff] [blame] | 599 | } else { |
| 600 | bool sendContentResizedNotification = false; |
hyatt@apple.com | f1ffabf | 2008-10-02 18:23:32 +0000 | [diff] [blame] | 601 | |
bdakin@apple.com | 9d3bf06 | 2013-03-28 00:42:35 +0000 | [diff] [blame] | 602 | IntSize docSize = totalContentsSize(); |
benjamin@webkit.org | 25bc57c | 2014-03-10 21:25:24 +0000 | [diff] [blame] | 603 | IntSize fullVisibleSize = unobscuredContentRectIncludingScrollbars().size(); |
hyatt@apple.com | f931bc7 | 2009-05-26 18:16:58 +0000 | [diff] [blame] | 604 | |
antti@apple.com | df98517 | 2014-01-22 13:07:25 +0000 | [diff] [blame] | 605 | if (hScroll == ScrollbarAuto) |
hyatt@apple.com | 82b0281 | 2009-04-08 22:33:48 +0000 | [diff] [blame] | 606 | newHasHorizontalScrollbar = docSize.width() > visibleWidth(); |
antti@apple.com | df98517 | 2014-01-22 13:07:25 +0000 | [diff] [blame] | 607 | if (vScroll == ScrollbarAuto) |
commit-queue@webkit.org | a059000 | 2014-01-21 18:06:06 +0000 | [diff] [blame] | 608 | newHasVerticalScrollbar = docSize.height() > visibleHeight(); |
commit-queue@webkit.org | a059000 | 2014-01-21 18:06:06 +0000 | [diff] [blame] | 609 | |
commit-queue@webkit.org | a059000 | 2014-01-21 18:06:06 +0000 | [diff] [blame] | 610 | bool needAnotherPass = false; |
antti@apple.com | df98517 | 2014-01-22 13:07:25 +0000 | [diff] [blame] | 611 | if (!hasOverlayScrollbars) { |
commit-queue@webkit.org | 9c71a89 | 2017-10-31 20:27:18 +0000 | [diff] [blame] | 612 | // If we ever turn one scrollbar off, do not turn the other one on. Never ever |
antti@apple.com | df98517 | 2014-01-22 13:07:25 +0000 | [diff] [blame] | 613 | // try to both gain/lose a scrollbar in the same pass. |
| 614 | if (!m_updateScrollbarsPass && docSize.width() <= fullVisibleSize.width() && docSize.height() <= fullVisibleSize.height()) { |
| 615 | if (hScroll == ScrollbarAuto) |
| 616 | newHasHorizontalScrollbar = false; |
| 617 | if (vScroll == ScrollbarAuto) |
| 618 | newHasVerticalScrollbar = false; |
| 619 | } |
commit-queue@webkit.org | fc72687 | 2017-11-03 18:32:19 +0000 | [diff] [blame] | 620 | if (!newHasHorizontalScrollbar && hasHorizontalScrollbar && vScroll != ScrollbarAlwaysOn && !hasVerticalScrollbar) { |
antti@apple.com | df98517 | 2014-01-22 13:07:25 +0000 | [diff] [blame] | 621 | newHasVerticalScrollbar = false; |
| 622 | needAnotherPass = true; |
| 623 | } |
commit-queue@webkit.org | 9c71a89 | 2017-10-31 20:27:18 +0000 | [diff] [blame] | 624 | if (!newHasVerticalScrollbar && hasVerticalScrollbar && hScroll != ScrollbarAlwaysOn && !hasHorizontalScrollbar) { |
antti@apple.com | df98517 | 2014-01-22 13:07:25 +0000 | [diff] [blame] | 625 | newHasHorizontalScrollbar = false; |
| 626 | needAnotherPass = true; |
| 627 | } |
simon.fraser@apple.com | f760ec1 | 2013-11-08 23:53:54 +0000 | [diff] [blame] | 628 | } |
hyatt@apple.com | 82b0281 | 2009-04-08 22:33:48 +0000 | [diff] [blame] | 629 | |
ryuan.choi@samsung.com | 2d22b11c | 2011-07-06 19:04:47 +0000 | [diff] [blame] | 630 | if (hasHorizontalScrollbar != newHasHorizontalScrollbar && (hasHorizontalScrollbar || !avoidScrollbarCreation())) { |
xji@chromium.org | 85d8754 | 2011-11-01 22:06:46 +0000 | [diff] [blame] | 631 | if (scrollOrigin().y() && !newHasHorizontalScrollbar) |
simon.fraser@apple.com | fc5a7a3 | 2015-12-17 06:56:55 +0000 | [diff] [blame] | 632 | ScrollableArea::setScrollOrigin(IntPoint(scrollOrigin().x(), scrollOrigin().y() - m_horizontalScrollbar->occupiedHeight())); |
simon.fraser@apple.com | 3c063c2 | 2011-10-10 20:05:16 +0000 | [diff] [blame] | 633 | if (m_horizontalScrollbar) |
| 634 | m_horizontalScrollbar->invalidate(); |
simon.fraser@apple.com | 8018847 | 2013-09-12 23:28:32 +0000 | [diff] [blame] | 635 | |
simon.fraser@apple.com | 0cdf36c | 2013-09-20 21:47:47 +0000 | [diff] [blame] | 636 | bool changeAffectsContentSize = false; |
| 637 | if (setHasHorizontalScrollbar(newHasHorizontalScrollbar, &changeAffectsContentSize)) { |
| 638 | scrollbarAddedOrRemoved = true; |
| 639 | sendContentResizedNotification |= changeAffectsContentSize; |
| 640 | } |
hyatt@apple.com | 82b0281 | 2009-04-08 22:33:48 +0000 | [diff] [blame] | 641 | } |
dglazkov@chromium.org | c0e2d52 | 2009-04-23 22:33:25 +0000 | [diff] [blame] | 642 | |
ryuan.choi@samsung.com | 2d22b11c | 2011-07-06 19:04:47 +0000 | [diff] [blame] | 643 | if (hasVerticalScrollbar != newHasVerticalScrollbar && (hasVerticalScrollbar || !avoidScrollbarCreation())) { |
xji@chromium.org | 85d8754 | 2011-11-01 22:06:46 +0000 | [diff] [blame] | 644 | if (scrollOrigin().x() && !newHasVerticalScrollbar) |
simon.fraser@apple.com | fc5a7a3 | 2015-12-17 06:56:55 +0000 | [diff] [blame] | 645 | ScrollableArea::setScrollOrigin(IntPoint(scrollOrigin().x() - m_verticalScrollbar->occupiedWidth(), scrollOrigin().y())); |
simon.fraser@apple.com | 3c063c2 | 2011-10-10 20:05:16 +0000 | [diff] [blame] | 646 | if (m_verticalScrollbar) |
| 647 | m_verticalScrollbar->invalidate(); |
simon.fraser@apple.com | 8018847 | 2013-09-12 23:28:32 +0000 | [diff] [blame] | 648 | |
simon.fraser@apple.com | 0cdf36c | 2013-09-20 21:47:47 +0000 | [diff] [blame] | 649 | bool changeAffectsContentSize = false; |
| 650 | if (setHasVerticalScrollbar(newHasVerticalScrollbar, &changeAffectsContentSize)) { |
| 651 | scrollbarAddedOrRemoved = true; |
| 652 | sendContentResizedNotification |= changeAffectsContentSize; |
| 653 | } |
hyatt@apple.com | f1ffabf | 2008-10-02 18:23:32 +0000 | [diff] [blame] | 654 | } |
| 655 | |
benjamin@webkit.org | 34ad562 | 2014-04-17 03:26:53 +0000 | [diff] [blame] | 656 | const unsigned cMaxUpdateScrollbarsPass = 2; |
simon.fraser@apple.com | f760ec1 | 2013-11-08 23:53:54 +0000 | [diff] [blame] | 657 | if ((sendContentResizedNotification || needAnotherPass) && m_updateScrollbarsPass < cMaxUpdateScrollbarsPass) { |
hyatt@apple.com | 82b0281 | 2009-04-08 22:33:48 +0000 | [diff] [blame] | 658 | m_updateScrollbarsPass++; |
simon.fraser@apple.com | 448c42e | 2015-02-25 05:35:38 +0000 | [diff] [blame] | 659 | availableContentSizeChanged(AvailableSizeChangeReason::ScrollbarsChanged); |
| 660 | updateContentsSize(); |
bdakin@apple.com | 9d3bf06 | 2013-03-28 00:42:35 +0000 | [diff] [blame] | 661 | IntSize newDocSize = totalContentsSize(); |
hyatt@apple.com | 3d454b7 | 2009-04-08 23:06:52 +0000 | [diff] [blame] | 662 | if (newDocSize == docSize) { |
hyatt@apple.com | 82b0281 | 2009-04-08 22:33:48 +0000 | [diff] [blame] | 663 | // The layout with the new scroll state had no impact on |
| 664 | // the document's overall size, so updateScrollbars didn't get called. |
| 665 | // Recur manually. |
simon.fraser@apple.com | db0e067 | 2015-12-30 00:29:36 +0000 | [diff] [blame] | 666 | updateScrollbars(desiredPosition); |
hyatt@apple.com | 82b0281 | 2009-04-08 22:33:48 +0000 | [diff] [blame] | 667 | } |
| 668 | m_updateScrollbarsPass--; |
hyatt@apple.com | f1ffabf | 2008-10-02 18:23:32 +0000 | [diff] [blame] | 669 | } |
| 670 | } |
jer.noble@apple.com | bfdbdad | 2014-01-07 22:31:49 +0000 | [diff] [blame] | 671 | |
| 672 | if (scrollbarAddedOrRemoved) |
| 673 | addedOrRemovedScrollbar(); |
| 674 | |
hyatt@apple.com | 82b0281 | 2009-04-08 22:33:48 +0000 | [diff] [blame] | 675 | // Set up the range (and page step/line step), but only do this if we're not in a nested call (to avoid |
| 676 | // doing it multiple times). |
| 677 | if (m_updateScrollbarsPass) |
| 678 | return; |
| 679 | |
hyatt@apple.com | aa5afdb | 2009-04-13 21:34:21 +0000 | [diff] [blame] | 680 | m_inUpdateScrollbars = true; |
xji@chromium.org | 506e6f6 | 2010-11-30 01:11:08 +0000 | [diff] [blame] | 681 | |
zecke@webkit.org | 815d9a1 | 2009-05-27 05:25:48 +0000 | [diff] [blame] | 682 | if (m_horizontalScrollbar) { |
hyatt@apple.com | f1ffabf | 2008-10-02 18:23:32 +0000 | [diff] [blame] | 683 | int clientWidth = visibleWidth(); |
bfulgham@apple.com | 0ef31c3 | 2014-08-06 23:04:05 +0000 | [diff] [blame] | 684 | int pageStep = Scrollbar::pageStep(clientWidth); |
eae@chromium.org | 92a579f | 2011-11-08 02:11:06 +0000 | [diff] [blame] | 685 | IntRect oldRect(m_horizontalScrollbar->frameRect()); |
mmaxfield@apple.com | 4195a70 | 2016-04-27 01:25:26 +0000 | [diff] [blame] | 686 | IntRect hBarRect(shouldPlaceBlockDirectionScrollbarOnLeft() && m_verticalScrollbar ? m_verticalScrollbar->occupiedWidth() : 0, |
bdakin@apple.com | 572c9f3 | 2014-03-20 23:19:04 +0000 | [diff] [blame] | 687 | height() - m_horizontalScrollbar->height(), |
carlosgc@webkit.org | 93bbb73 | 2016-01-27 10:28:49 +0000 | [diff] [blame] | 688 | width() - (m_verticalScrollbar ? m_verticalScrollbar->occupiedWidth() : 0), |
bdakin@apple.com | 572c9f3 | 2014-03-20 23:19:04 +0000 | [diff] [blame] | 689 | m_horizontalScrollbar->height()); |
hyatt@apple.com | f1ffabf | 2008-10-02 18:23:32 +0000 | [diff] [blame] | 690 | m_horizontalScrollbar->setFrameRect(hBarRect); |
| 691 | if (!m_scrollbarsSuppressed && oldRect != m_horizontalScrollbar->frameRect()) |
| 692 | m_horizontalScrollbar->invalidate(); |
| 693 | |
| 694 | if (m_scrollbarsSuppressed) |
| 695 | m_horizontalScrollbar->setSuppressInvalidation(true); |
mitz@apple.com | b26148f | 2011-10-06 23:42:57 +0000 | [diff] [blame] | 696 | m_horizontalScrollbar->setEnabled(contentsWidth() > clientWidth); |
mitz@apple.com | ed85003 | 2010-02-04 17:35:58 +0000 | [diff] [blame] | 697 | m_horizontalScrollbar->setSteps(Scrollbar::pixelsPerLineStep(), pageStep); |
hyatt@apple.com | f1ffabf | 2008-10-02 18:23:32 +0000 | [diff] [blame] | 698 | m_horizontalScrollbar->setProportion(clientWidth, contentsWidth()); |
hyatt@apple.com | f1ffabf | 2008-10-02 18:23:32 +0000 | [diff] [blame] | 699 | if (m_scrollbarsSuppressed) |
| 700 | m_horizontalScrollbar->setSuppressInvalidation(false); |
| 701 | } |
| 702 | |
zecke@webkit.org | 815d9a1 | 2009-05-27 05:25:48 +0000 | [diff] [blame] | 703 | if (m_verticalScrollbar) { |
hyatt@apple.com | f1ffabf | 2008-10-02 18:23:32 +0000 | [diff] [blame] | 704 | int clientHeight = visibleHeight(); |
bfulgham@apple.com | 0ef31c3 | 2014-08-06 23:04:05 +0000 | [diff] [blame] | 705 | int pageStep = Scrollbar::pageStep(clientHeight); |
eae@chromium.org | 92a579f | 2011-11-08 02:11:06 +0000 | [diff] [blame] | 706 | IntRect oldRect(m_verticalScrollbar->frameRect()); |
mmaxfield@apple.com | 4195a70 | 2016-04-27 01:25:26 +0000 | [diff] [blame] | 707 | IntRect vBarRect(shouldPlaceBlockDirectionScrollbarOnLeft() ? 0 : width() - m_verticalScrollbar->width(), |
bdakin@apple.com | 572c9f3 | 2014-03-20 23:19:04 +0000 | [diff] [blame] | 708 | topContentInset(), |
| 709 | m_verticalScrollbar->width(), |
carlosgc@webkit.org | 93bbb73 | 2016-01-27 10:28:49 +0000 | [diff] [blame] | 710 | height() - topContentInset() - (m_horizontalScrollbar ? m_horizontalScrollbar->occupiedHeight() : 0)); |
hyatt@apple.com | f1ffabf | 2008-10-02 18:23:32 +0000 | [diff] [blame] | 711 | m_verticalScrollbar->setFrameRect(vBarRect); |
| 712 | if (!m_scrollbarsSuppressed && oldRect != m_verticalScrollbar->frameRect()) |
| 713 | m_verticalScrollbar->invalidate(); |
| 714 | |
| 715 | if (m_scrollbarsSuppressed) |
| 716 | m_verticalScrollbar->setSuppressInvalidation(true); |
bdakin@apple.com | 9d3bf06 | 2013-03-28 00:42:35 +0000 | [diff] [blame] | 717 | m_verticalScrollbar->setEnabled(totalContentsSize().height() > clientHeight); |
mitz@apple.com | ed85003 | 2010-02-04 17:35:58 +0000 | [diff] [blame] | 718 | m_verticalScrollbar->setSteps(Scrollbar::pixelsPerLineStep(), pageStep); |
bdakin@apple.com | 9d3bf06 | 2013-03-28 00:42:35 +0000 | [diff] [blame] | 719 | m_verticalScrollbar->setProportion(clientHeight, totalContentsSize().height()); |
hyatt@apple.com | f1ffabf | 2008-10-02 18:23:32 +0000 | [diff] [blame] | 720 | if (m_scrollbarsSuppressed) |
| 721 | m_verticalScrollbar->setSuppressInvalidation(false); |
| 722 | } |
| 723 | |
commit-queue@webkit.org | c977b8f | 2013-01-30 06:30:43 +0000 | [diff] [blame] | 724 | if (hasHorizontalScrollbar != newHasHorizontalScrollbar || hasVerticalScrollbar != newHasVerticalScrollbar) { |
aroben@apple.com | 9f9a70a | 2011-05-13 17:24:55 +0000 | [diff] [blame] | 725 | // FIXME: Is frameRectsChanged really necessary here? Have any frame rects changed? |
hyatt@apple.com | f1ffabf | 2008-10-02 18:23:32 +0000 | [diff] [blame] | 726 | frameRectsChanged(); |
aroben@apple.com | 9f9a70a | 2011-05-13 17:24:55 +0000 | [diff] [blame] | 727 | positionScrollbarLayers(); |
andersca@apple.com | 7d8fe98 | 2009-08-20 00:04:48 +0000 | [diff] [blame] | 728 | updateScrollCorner(); |
simon.fraser@apple.com | c8bf639 | 2011-09-27 19:00:56 +0000 | [diff] [blame] | 729 | if (!m_horizontalScrollbar && !m_verticalScrollbar) |
| 730 | invalidateScrollCornerRect(oldScrollCornerRect); |
andersca@apple.com | 7d8fe98 | 2009-08-20 00:04:48 +0000 | [diff] [blame] | 731 | } |
hyatt@apple.com | f1ffabf | 2008-10-02 18:23:32 +0000 | [diff] [blame] | 732 | |
simon.fraser@apple.com | db0e067 | 2015-12-30 00:29:36 +0000 | [diff] [blame] | 733 | IntPoint adjustedScrollPosition = desiredPosition; |
bdakin@apple.com | c975f55 | 2013-01-23 20:17:01 +0000 | [diff] [blame] | 734 | if (!isRubberBandInProgress()) |
| 735 | adjustedScrollPosition = adjustScrollPositionWithinRange(adjustedScrollPosition); |
andersca@apple.com | 84d12b8 | 2012-03-14 20:07:42 +0000 | [diff] [blame] | 736 | |
xji@chromium.org | 24f5740 | 2011-11-08 22:22:24 +0000 | [diff] [blame] | 737 | if (adjustedScrollPosition != scrollPosition() || scrollOriginChanged()) { |
simon.fraser@apple.com | efc492b | 2015-12-30 20:15:27 +0000 | [diff] [blame] | 738 | ScrollableArea::scrollToOffsetWithoutAnimation(scrollOffsetFromPosition(adjustedScrollPosition)); |
bdakin@apple.com | 096c962 | 2011-12-08 19:19:05 +0000 | [diff] [blame] | 739 | resetScrollOriginChanged(); |
xji@chromium.org | 24f5740 | 2011-11-08 22:22:24 +0000 | [diff] [blame] | 740 | } |
hyatt@apple.com | f1ffabf | 2008-10-02 18:23:32 +0000 | [diff] [blame] | 741 | |
weinig@apple.com | 155785f | 2011-02-04 00:11:25 +0000 | [diff] [blame] | 742 | // Make sure the scrollbar offsets are up to date. |
| 743 | if (m_horizontalScrollbar) |
| 744 | m_horizontalScrollbar->offsetDidChange(); |
| 745 | if (m_verticalScrollbar) |
| 746 | m_verticalScrollbar->offsetDidChange(); |
| 747 | |
hyatt@apple.com | aa5afdb | 2009-04-13 21:34:21 +0000 | [diff] [blame] | 748 | m_inUpdateScrollbars = false; |
hyatt@apple.com | f1ffabf | 2008-10-02 18:23:32 +0000 | [diff] [blame] | 749 | } |
| 750 | |
eric@webkit.org | ac25cf2 | 2009-08-21 19:02:20 +0000 | [diff] [blame] | 751 | const int panIconSizeLength = 16; |
hyatt@apple.com | 98682b3 | 2008-10-02 20:17:08 +0000 | [diff] [blame] | 752 | |
simon.fraser@apple.com | 856ca86 | 2011-04-24 05:53:06 +0000 | [diff] [blame] | 753 | IntRect ScrollView::rectToCopyOnScroll() const |
| 754 | { |
andersca@apple.com | fdd25eb | 2011-11-15 17:54:52 +0000 | [diff] [blame] | 755 | IntRect scrollViewRect = convertToRootView(IntRect(0, 0, visibleWidth(), visibleHeight())); |
simon.fraser@apple.com | 856ca86 | 2011-04-24 05:53:06 +0000 | [diff] [blame] | 756 | if (hasOverlayScrollbars()) { |
eae@chromium.org | 92a579f | 2011-11-08 02:11:06 +0000 | [diff] [blame] | 757 | int verticalScrollbarWidth = (verticalScrollbar() && !hasLayerForVerticalScrollbar()) ? verticalScrollbar()->width() : 0; |
| 758 | int horizontalScrollbarHeight = (horizontalScrollbar() && !hasLayerForHorizontalScrollbar()) ? horizontalScrollbar()->height() : 0; |
simon.fraser@apple.com | 856ca86 | 2011-04-24 05:53:06 +0000 | [diff] [blame] | 759 | |
| 760 | scrollViewRect.setWidth(scrollViewRect.width() - verticalScrollbarWidth); |
| 761 | scrollViewRect.setHeight(scrollViewRect.height() - horizontalScrollbarHeight); |
| 762 | } |
| 763 | return scrollViewRect; |
| 764 | } |
| 765 | |
hyatt@apple.com | 98682b3 | 2008-10-02 20:17:08 +0000 | [diff] [blame] | 766 | void ScrollView::scrollContents(const IntSize& scrollDelta) |
hyatt@apple.com | f1ffabf | 2008-10-02 18:23:32 +0000 | [diff] [blame] | 767 | { |
commit-queue@webkit.org | 6121dfd | 2013-06-28 11:14:18 +0000 | [diff] [blame] | 768 | HostWindow* window = hostWindow(); |
| 769 | if (!window) |
darin@chromium.org | fbf4658 | 2009-02-26 19:32:49 +0000 | [diff] [blame] | 770 | return; |
| 771 | |
hyatt@apple.com | 98682b3 | 2008-10-02 20:17:08 +0000 | [diff] [blame] | 772 | // Since scrolling is double buffered, we will be blitting the scroll view's intersection |
| 773 | // with the clip rect every time to keep it smooth. |
hyatt@apple.com | 6fa40c5 | 2008-10-03 07:06:28 +0000 | [diff] [blame] | 774 | IntRect clipRect = windowClipRect(); |
simon.fraser@apple.com | 856ca86 | 2011-04-24 05:53:06 +0000 | [diff] [blame] | 775 | IntRect scrollViewRect = rectToCopyOnScroll(); |
hyatt@apple.com | 98682b3 | 2008-10-02 20:17:08 +0000 | [diff] [blame] | 776 | IntRect updateRect = clipRect; |
| 777 | updateRect.intersect(scrollViewRect); |
| 778 | |
andersca@apple.com | fdd25eb | 2011-11-15 17:54:52 +0000 | [diff] [blame] | 779 | // Invalidate the root view (not the backing store). |
commit-queue@webkit.org | 4149b93 | 2014-02-24 19:05:21 +0000 | [diff] [blame] | 780 | window->invalidateRootView(updateRect); |
hyatt@apple.com | 98682b3 | 2008-10-02 20:17:08 +0000 | [diff] [blame] | 781 | |
| 782 | if (m_drawPanScrollIcon) { |
simon.fraser@apple.com | 2fb2dbf | 2010-10-26 01:06:30 +0000 | [diff] [blame] | 783 | // FIXME: the pan icon is broken when accelerated compositing is on, since it will draw under the compositing layers. |
| 784 | // https://bugs.webkit.org/show_bug.cgi?id=47837 |
andersca@apple.com | 8629863 | 2013-11-10 19:32:33 +0000 | [diff] [blame] | 785 | int panIconDirtySquareSizeLength = 2 * (panIconSizeLength + std::max(abs(scrollDelta.width()), abs(scrollDelta.height()))); // We only want to repaint what's necessary |
eae@chromium.org | 92a579f | 2011-11-08 02:11:06 +0000 | [diff] [blame] | 786 | IntPoint panIconDirtySquareLocation = IntPoint(m_panScrollIconPoint.x() - (panIconDirtySquareSizeLength / 2), m_panScrollIconPoint.y() - (panIconDirtySquareSizeLength / 2)); |
| 787 | IntRect panScrollIconDirtyRect = IntRect(panIconDirtySquareLocation, IntSize(panIconDirtySquareSizeLength, panIconDirtySquareSizeLength)); |
hyatt@apple.com | 98682b3 | 2008-10-02 20:17:08 +0000 | [diff] [blame] | 788 | panScrollIconDirtyRect.intersect(clipRect); |
commit-queue@webkit.org | 4149b93 | 2014-02-24 19:05:21 +0000 | [diff] [blame] | 789 | window->invalidateContentsAndRootView(panScrollIconDirtyRect); |
hyatt@apple.com | 98682b3 | 2008-10-02 20:17:08 +0000 | [diff] [blame] | 790 | } |
| 791 | |
eric@webkit.org | d14c4c6 | 2010-01-14 12:15:03 +0000 | [diff] [blame] | 792 | if (canBlitOnScroll()) { // The main frame can just blit the WebView window |
eric@webkit.org | 3754c52 | 2010-03-12 07:07:06 +0000 | [diff] [blame] | 793 | // FIXME: Find a way to scroll subframes with this faster path |
benjamin.poulain@nokia.com | 3e96035 | 2010-06-23 14:11:26 +0000 | [diff] [blame] | 794 | if (!scrollContentsFastPath(-scrollDelta, scrollViewRect, clipRect)) |
simon.fraser@apple.com | 2fb2dbf | 2010-10-26 01:06:30 +0000 | [diff] [blame] | 795 | scrollContentsSlowPath(updateRect); |
hyatt@apple.com | 98682b3 | 2008-10-02 20:17:08 +0000 | [diff] [blame] | 796 | } else { |
simon.fraser@apple.com | 03e6103 | 2015-04-05 20:17:11 +0000 | [diff] [blame] | 797 | // We need to repaint the entire backing store. Do it now before moving the windowed plugins. |
| 798 | scrollContentsSlowPath(updateRect); |
hyatt@apple.com | 98682b3 | 2008-10-02 20:17:08 +0000 | [diff] [blame] | 799 | } |
| 800 | |
weinig@apple.com | 69c853d | 2011-02-22 01:18:23 +0000 | [diff] [blame] | 801 | // Invalidate the overhang areas if they are visible. |
commit-queue@webkit.org | c1e9436 | 2012-02-22 20:18:30 +0000 | [diff] [blame] | 802 | updateOverhangAreas(); |
weinig@apple.com | 69c853d | 2011-02-22 01:18:23 +0000 | [diff] [blame] | 803 | |
hyatt@apple.com | 98682b3 | 2008-10-02 20:17:08 +0000 | [diff] [blame] | 804 | // This call will move children with native widgets (plugins) and invalidate them as well. |
| 805 | frameRectsChanged(); |
| 806 | |
treat@webkit.org | ea79524 | 2010-03-08 19:43:43 +0000 | [diff] [blame] | 807 | // Now blit the backingstore into the window which should be very fast. |
commit-queue@webkit.org | 4149b93 | 2014-02-24 19:05:21 +0000 | [diff] [blame] | 808 | window->invalidateRootView(IntRect()); |
hyatt@apple.com | f1ffabf | 2008-10-02 18:23:32 +0000 | [diff] [blame] | 809 | } |
hyatt@apple.com | f1ffabf | 2008-10-02 18:23:32 +0000 | [diff] [blame] | 810 | |
simon.fraser@apple.com | 2fb2dbf | 2010-10-26 01:06:30 +0000 | [diff] [blame] | 811 | void ScrollView::scrollContentsSlowPath(const IntRect& updateRect) |
| 812 | { |
commit-queue@webkit.org | 4149b93 | 2014-02-24 19:05:21 +0000 | [diff] [blame] | 813 | hostWindow()->invalidateContentsForSlowScroll(updateRect); |
simon.fraser@apple.com | 2fb2dbf | 2010-10-26 01:06:30 +0000 | [diff] [blame] | 814 | } |
| 815 | |
simon.fraser@apple.com | f06ee4b | 2015-04-28 21:51:04 +0000 | [diff] [blame] | 816 | IntPoint ScrollView::viewToContents(const IntPoint& point) const |
| 817 | { |
simon.fraser@apple.com | 94cc9c2 | 2016-01-01 03:17:31 +0000 | [diff] [blame] | 818 | return point + toIntSize(documentScrollPositionRelativeToViewOrigin()); |
simon.fraser@apple.com | f06ee4b | 2015-04-28 21:51:04 +0000 | [diff] [blame] | 819 | } |
| 820 | |
| 821 | IntPoint ScrollView::contentsToView(const IntPoint& point) const |
| 822 | { |
simon.fraser@apple.com | 94cc9c2 | 2016-01-01 03:17:31 +0000 | [diff] [blame] | 823 | return point - toIntSize(documentScrollPositionRelativeToViewOrigin()); |
simon.fraser@apple.com | f06ee4b | 2015-04-28 21:51:04 +0000 | [diff] [blame] | 824 | } |
| 825 | |
| 826 | IntRect ScrollView::viewToContents(IntRect rect) const |
| 827 | { |
simon.fraser@apple.com | 94cc9c2 | 2016-01-01 03:17:31 +0000 | [diff] [blame] | 828 | rect.moveBy(documentScrollPositionRelativeToViewOrigin()); |
simon.fraser@apple.com | f06ee4b | 2015-04-28 21:51:04 +0000 | [diff] [blame] | 829 | return rect; |
| 830 | } |
| 831 | |
ajuma@chromium.org | 5eefc54 | 2018-11-02 16:55:13 +0000 | [diff] [blame^] | 832 | FloatRect ScrollView::viewToContents(FloatRect rect) const |
| 833 | { |
| 834 | rect.moveBy(documentScrollPositionRelativeToViewOrigin()); |
| 835 | return rect; |
| 836 | } |
| 837 | |
simon.fraser@apple.com | f06ee4b | 2015-04-28 21:51:04 +0000 | [diff] [blame] | 838 | IntRect ScrollView::contentsToView(IntRect rect) const |
| 839 | { |
simon.fraser@apple.com | 94cc9c2 | 2016-01-01 03:17:31 +0000 | [diff] [blame] | 840 | rect.moveBy(-documentScrollPositionRelativeToViewOrigin()); |
simon.fraser@apple.com | f06ee4b | 2015-04-28 21:51:04 +0000 | [diff] [blame] | 841 | return rect; |
| 842 | } |
| 843 | |
ajuma@chromium.org | 5eefc54 | 2018-11-02 16:55:13 +0000 | [diff] [blame^] | 844 | FloatRect ScrollView::contentsToView(FloatRect rect) const |
| 845 | { |
| 846 | rect.moveBy(-documentScrollPositionRelativeToViewOrigin()); |
| 847 | return rect; |
| 848 | } |
| 849 | |
simon.fraser@apple.com | 37f5269 | 2015-12-24 00:35:04 +0000 | [diff] [blame] | 850 | IntPoint ScrollView::contentsToContainingViewContents(const IntPoint& point) const |
| 851 | { |
| 852 | if (const ScrollView* parentScrollView = parent()) { |
| 853 | IntPoint pointInContainingView = convertToContainingView(contentsToView(point)); |
| 854 | return parentScrollView->viewToContents(pointInContainingView); |
| 855 | } |
| 856 | |
| 857 | return contentsToView(point); |
| 858 | } |
| 859 | |
| 860 | IntRect ScrollView::contentsToContainingViewContents(IntRect rect) const |
| 861 | { |
n_wang@apple.com | e626f71 | 2018-06-29 23:33:30 +0000 | [diff] [blame] | 862 | if (delegatesScrolling()) |
| 863 | return convertToContainingView(contentsToView(rect)); |
| 864 | |
simon.fraser@apple.com | 37f5269 | 2015-12-24 00:35:04 +0000 | [diff] [blame] | 865 | if (const ScrollView* parentScrollView = parent()) { |
| 866 | IntRect rectInContainingView = convertToContainingView(contentsToView(rect)); |
| 867 | return parentScrollView->viewToContents(rectInContainingView); |
| 868 | } |
| 869 | |
| 870 | return contentsToView(rect); |
| 871 | } |
| 872 | |
jeffm@apple.com | 13f98eb | 2011-10-14 22:11:12 +0000 | [diff] [blame] | 873 | IntPoint ScrollView::rootViewToContents(const IntPoint& rootViewPoint) const |
| 874 | { |
enrica@apple.com | 2a78a51 | 2014-02-12 22:37:20 +0000 | [diff] [blame] | 875 | if (delegatesScrolling()) |
| 876 | return convertFromRootView(rootViewPoint); |
| 877 | |
simon.fraser@apple.com | f06ee4b | 2015-04-28 21:51:04 +0000 | [diff] [blame] | 878 | return viewToContents(convertFromRootView(rootViewPoint)); |
jeffm@apple.com | 13f98eb | 2011-10-14 22:11:12 +0000 | [diff] [blame] | 879 | } |
| 880 | |
| 881 | IntPoint ScrollView::contentsToRootView(const IntPoint& contentsPoint) const |
| 882 | { |
enrica@apple.com | 2a78a51 | 2014-02-12 22:37:20 +0000 | [diff] [blame] | 883 | if (delegatesScrolling()) |
| 884 | return convertToRootView(contentsPoint); |
| 885 | |
simon.fraser@apple.com | f06ee4b | 2015-04-28 21:51:04 +0000 | [diff] [blame] | 886 | return convertToRootView(contentsToView(contentsPoint)); |
jeffm@apple.com | 13f98eb | 2011-10-14 22:11:12 +0000 | [diff] [blame] | 887 | } |
| 888 | |
| 889 | IntRect ScrollView::rootViewToContents(const IntRect& rootViewRect) const |
| 890 | { |
enrica@apple.com | 2a78a51 | 2014-02-12 22:37:20 +0000 | [diff] [blame] | 891 | if (delegatesScrolling()) |
| 892 | return convertFromRootView(rootViewRect); |
| 893 | |
simon.fraser@apple.com | f06ee4b | 2015-04-28 21:51:04 +0000 | [diff] [blame] | 894 | return viewToContents(convertFromRootView(rootViewRect)); |
jeffm@apple.com | 13f98eb | 2011-10-14 22:11:12 +0000 | [diff] [blame] | 895 | } |
| 896 | |
ajuma@chromium.org | 5eefc54 | 2018-11-02 16:55:13 +0000 | [diff] [blame^] | 897 | FloatRect ScrollView::rootViewToContents(const FloatRect& rootViewRect) const |
| 898 | { |
| 899 | if (delegatesScrolling()) |
| 900 | return convertFromRootView(rootViewRect); |
| 901 | |
| 902 | return viewToContents(convertFromRootView(rootViewRect)); |
| 903 | } |
| 904 | |
weinig@apple.com | 29098d3 | 2013-05-01 01:24:57 +0000 | [diff] [blame] | 905 | IntPoint ScrollView::rootViewToTotalContents(const IntPoint& rootViewPoint) const |
| 906 | { |
enrica@apple.com | 2a78a51 | 2014-02-12 22:37:20 +0000 | [diff] [blame] | 907 | if (delegatesScrolling()) |
| 908 | return convertFromRootView(rootViewPoint); |
| 909 | |
weinig@apple.com | 29098d3 | 2013-05-01 01:24:57 +0000 | [diff] [blame] | 910 | IntPoint viewPoint = convertFromRootView(rootViewPoint); |
simon.fraser@apple.com | f06ee4b | 2015-04-28 21:51:04 +0000 | [diff] [blame] | 911 | // Like rootViewToContents(), but ignores headerHeight. |
simon.fraser@apple.com | db0e067 | 2015-12-30 00:29:36 +0000 | [diff] [blame] | 912 | return viewPoint + toIntSize(scrollPosition()) - IntSize(0, topContentInset(TopContentInsetType::WebCoreOrPlatformContentInset)); |
weinig@apple.com | 29098d3 | 2013-05-01 01:24:57 +0000 | [diff] [blame] | 913 | } |
| 914 | |
simon.fraser@apple.com | f06ee4b | 2015-04-28 21:51:04 +0000 | [diff] [blame] | 915 | IntRect ScrollView::contentsToRootView(const IntRect& contentsRect) const |
| 916 | { |
| 917 | if (delegatesScrolling()) |
| 918 | return convertToRootView(contentsRect); |
| 919 | |
| 920 | return convertToRootView(contentsToView(contentsRect)); |
| 921 | } |
| 922 | |
hyatt@apple.com | 0315e53 | 2008-09-27 06:23:58 +0000 | [diff] [blame] | 923 | IntPoint ScrollView::windowToContents(const IntPoint& windowPoint) const |
| 924 | { |
zeno.albisser@nokia.com | 1bbb63c | 2011-11-17 14:15:36 +0000 | [diff] [blame] | 925 | if (delegatesScrolling()) |
| 926 | return convertFromContainingWindow(windowPoint); |
| 927 | |
simon.fraser@apple.com | f06ee4b | 2015-04-28 21:51:04 +0000 | [diff] [blame] | 928 | return viewToContents(convertFromContainingWindow(windowPoint)); |
hyatt@apple.com | 0315e53 | 2008-09-27 06:23:58 +0000 | [diff] [blame] | 929 | } |
| 930 | |
| 931 | IntPoint ScrollView::contentsToWindow(const IntPoint& contentsPoint) const |
| 932 | { |
zeno.albisser@nokia.com | 1bbb63c | 2011-11-17 14:15:36 +0000 | [diff] [blame] | 933 | if (delegatesScrolling()) |
| 934 | return convertToContainingWindow(contentsPoint); |
| 935 | |
simon.fraser@apple.com | f06ee4b | 2015-04-28 21:51:04 +0000 | [diff] [blame] | 936 | return convertToContainingWindow(contentsToView(contentsPoint)); |
hyatt@apple.com | 0315e53 | 2008-09-27 06:23:58 +0000 | [diff] [blame] | 937 | } |
| 938 | |
| 939 | IntRect ScrollView::windowToContents(const IntRect& windowRect) const |
| 940 | { |
zeno.albisser@nokia.com | 1bbb63c | 2011-11-17 14:15:36 +0000 | [diff] [blame] | 941 | if (delegatesScrolling()) |
| 942 | return convertFromContainingWindow(windowRect); |
| 943 | |
simon.fraser@apple.com | f06ee4b | 2015-04-28 21:51:04 +0000 | [diff] [blame] | 944 | return viewToContents(convertFromContainingWindow(windowRect)); |
hyatt@apple.com | 0315e53 | 2008-09-27 06:23:58 +0000 | [diff] [blame] | 945 | } |
| 946 | |
| 947 | IntRect ScrollView::contentsToWindow(const IntRect& contentsRect) const |
| 948 | { |
zeno.albisser@nokia.com | 1bbb63c | 2011-11-17 14:15:36 +0000 | [diff] [blame] | 949 | if (delegatesScrolling()) |
| 950 | return convertToContainingWindow(contentsRect); |
| 951 | |
simon.fraser@apple.com | f06ee4b | 2015-04-28 21:51:04 +0000 | [diff] [blame] | 952 | return convertToContainingWindow(contentsToView(contentsRect)); |
hyatt@apple.com | 0315e53 | 2008-09-27 06:23:58 +0000 | [diff] [blame] | 953 | } |
| 954 | |
hyatt@apple.com | fe9c130 | 2008-10-01 20:34:07 +0000 | [diff] [blame] | 955 | IntRect ScrollView::contentsToScreen(const IntRect& rect) const |
| 956 | { |
commit-queue@webkit.org | 6121dfd | 2013-06-28 11:14:18 +0000 | [diff] [blame] | 957 | HostWindow* window = hostWindow(); |
hyatt@apple.com | fe9c130 | 2008-10-01 20:34:07 +0000 | [diff] [blame] | 958 | if (platformWidget()) |
| 959 | return platformContentsToScreen(rect); |
commit-queue@webkit.org | 6121dfd | 2013-06-28 11:14:18 +0000 | [diff] [blame] | 960 | if (!window) |
alice.liu@apple.com | 3c49db4 | 2009-06-21 05:42:39 +0000 | [diff] [blame] | 961 | return IntRect(); |
commit-queue@webkit.org | 6121dfd | 2013-06-28 11:14:18 +0000 | [diff] [blame] | 962 | return window->rootViewToScreen(contentsToRootView(rect)); |
hyatt@apple.com | fe9c130 | 2008-10-01 20:34:07 +0000 | [diff] [blame] | 963 | } |
| 964 | |
eae@chromium.org | 92a579f | 2011-11-08 02:11:06 +0000 | [diff] [blame] | 965 | IntPoint ScrollView::screenToContents(const IntPoint& point) const |
hyatt@apple.com | fe9c130 | 2008-10-01 20:34:07 +0000 | [diff] [blame] | 966 | { |
commit-queue@webkit.org | 6121dfd | 2013-06-28 11:14:18 +0000 | [diff] [blame] | 967 | HostWindow* window = hostWindow(); |
hyatt@apple.com | fe9c130 | 2008-10-01 20:34:07 +0000 | [diff] [blame] | 968 | if (platformWidget()) |
| 969 | return platformScreenToContents(point); |
commit-queue@webkit.org | 6121dfd | 2013-06-28 11:14:18 +0000 | [diff] [blame] | 970 | if (!window) |
eae@chromium.org | 92a579f | 2011-11-08 02:11:06 +0000 | [diff] [blame] | 971 | return IntPoint(); |
commit-queue@webkit.org | 6121dfd | 2013-06-28 11:14:18 +0000 | [diff] [blame] | 972 | return rootViewToContents(window->screenToRootView(point)); |
hyatt@apple.com | fe9c130 | 2008-10-01 20:34:07 +0000 | [diff] [blame] | 973 | } |
| 974 | |
hyatt@apple.com | e6f04e5 | 2008-09-28 01:07:05 +0000 | [diff] [blame] | 975 | void ScrollView::setScrollbarsSuppressed(bool suppressed, bool repaintOnUnsuppress) |
| 976 | { |
| 977 | if (suppressed == m_scrollbarsSuppressed) |
| 978 | return; |
| 979 | |
| 980 | m_scrollbarsSuppressed = suppressed; |
| 981 | |
| 982 | if (platformWidget()) |
| 983 | platformSetScrollbarsSuppressed(repaintOnUnsuppress); |
| 984 | else if (repaintOnUnsuppress && !suppressed) { |
| 985 | if (m_horizontalScrollbar) |
| 986 | m_horizontalScrollbar->invalidate(); |
| 987 | if (m_verticalScrollbar) |
| 988 | m_verticalScrollbar->invalidate(); |
| 989 | |
| 990 | // Invalidate the scroll corner too on unsuppress. |
andersca@apple.com | 7d8fe98 | 2009-08-20 00:04:48 +0000 | [diff] [blame] | 991 | invalidateRect(scrollCornerRect()); |
hyatt@apple.com | e6f04e5 | 2008-09-28 01:07:05 +0000 | [diff] [blame] | 992 | } |
| 993 | } |
| 994 | |
bweinstein@apple.com | 817c602 | 2009-06-30 18:23:49 +0000 | [diff] [blame] | 995 | Scrollbar* ScrollView::scrollbarAtPoint(const IntPoint& windowPoint) |
hyatt@apple.com | 880cbb1 | 2008-09-28 03:51:41 +0000 | [diff] [blame] | 996 | { |
| 997 | if (platformWidget()) |
| 998 | return 0; |
| 999 | |
bdakin@apple.com | 9200182 | 2015-12-16 18:08:57 +0000 | [diff] [blame] | 1000 | // convertFromContainingWindow doesn't do what it sounds like it does. We need it here just to get this |
| 1001 | // point into the right coordinates if this is the ScrollView of a sub-frame. |
| 1002 | IntPoint convertedPoint = convertFromContainingWindow(windowPoint); |
| 1003 | if (m_horizontalScrollbar && m_horizontalScrollbar->shouldParticipateInHitTesting() && m_horizontalScrollbar->frameRect().contains(convertedPoint)) |
hyatt@apple.com | 880cbb1 | 2008-09-28 03:51:41 +0000 | [diff] [blame] | 1004 | return m_horizontalScrollbar.get(); |
bdakin@apple.com | 9200182 | 2015-12-16 18:08:57 +0000 | [diff] [blame] | 1005 | if (m_verticalScrollbar && m_verticalScrollbar->shouldParticipateInHitTesting() && m_verticalScrollbar->frameRect().contains(convertedPoint)) |
hyatt@apple.com | 880cbb1 | 2008-09-28 03:51:41 +0000 | [diff] [blame] | 1006 | return m_verticalScrollbar.get(); |
| 1007 | return 0; |
| 1008 | } |
| 1009 | |
commit-queue@webkit.org | b31092d | 2011-07-21 01:32:17 +0000 | [diff] [blame] | 1010 | void ScrollView::setScrollbarOverlayStyle(ScrollbarOverlayStyle overlayStyle) |
| 1011 | { |
| 1012 | ScrollableArea::setScrollbarOverlayStyle(overlayStyle); |
| 1013 | platformSetScrollbarOverlayStyle(overlayStyle); |
| 1014 | } |
| 1015 | |
eae@chromium.org | 92a579f | 2011-11-08 02:11:06 +0000 | [diff] [blame] | 1016 | void ScrollView::setFrameRect(const IntRect& newRect) |
hyatt@apple.com | c5a54f4 | 2008-10-01 19:23:05 +0000 | [diff] [blame] | 1017 | { |
beidson@apple.com | 7bd3d3b | 2016-05-13 23:42:17 +0000 | [diff] [blame] | 1018 | Ref<ScrollView> protectedThis(*this); |
eae@chromium.org | 92a579f | 2011-11-08 02:11:06 +0000 | [diff] [blame] | 1019 | IntRect oldRect = frameRect(); |
hyatt@apple.com | c5a54f4 | 2008-10-01 19:23:05 +0000 | [diff] [blame] | 1020 | |
| 1021 | if (newRect == oldRect) |
| 1022 | return; |
| 1023 | |
| 1024 | Widget::setFrameRect(newRect); |
aroben@apple.com | 9f9a70a | 2011-05-13 17:24:55 +0000 | [diff] [blame] | 1025 | frameRectsChanged(); |
timothy_horton@apple.com | bd1cdca | 2015-04-03 06:37:15 +0000 | [diff] [blame] | 1026 | |
simon.fraser@apple.com | db0e067 | 2015-12-30 00:29:36 +0000 | [diff] [blame] | 1027 | updateScrollbars(scrollPosition()); |
simon.fraser@apple.com | 448c42e | 2015-02-25 05:35:38 +0000 | [diff] [blame] | 1028 | |
mitz@apple.com | 2153ba0 | 2012-03-01 22:42:44 +0000 | [diff] [blame] | 1029 | if (!m_useFixedLayout && oldRect.size() != newRect.size()) |
simon.fraser@apple.com | 448c42e | 2015-02-25 05:35:38 +0000 | [diff] [blame] | 1030 | availableContentSizeChanged(AvailableSizeChangeReason::AreaSizeChanged); |
mitz@apple.com | eb5f9a5 | 2011-02-21 03:06:48 +0000 | [diff] [blame] | 1031 | } |
| 1032 | |
vestbo@webkit.org | 70da8f0 | 2008-12-11 10:09:50 +0000 | [diff] [blame] | 1033 | void ScrollView::frameRectsChanged() |
hyatt@apple.com | 2225aef | 2008-09-28 08:52:26 +0000 | [diff] [blame] | 1034 | { |
| 1035 | if (platformWidget()) |
| 1036 | return; |
darin@apple.com | 6c71ce2 | 2017-01-14 03:35:54 +0000 | [diff] [blame] | 1037 | for (auto& child : m_children) |
| 1038 | child->frameRectsChanged(); |
hyatt@apple.com | 2225aef | 2008-09-28 08:52:26 +0000 | [diff] [blame] | 1039 | } |
| 1040 | |
commit-queue@webkit.org | 216b5ea | 2013-02-27 22:05:07 +0000 | [diff] [blame] | 1041 | void ScrollView::clipRectChanged() |
| 1042 | { |
darin@apple.com | 6c71ce2 | 2017-01-14 03:35:54 +0000 | [diff] [blame] | 1043 | for (auto& child : m_children) |
| 1044 | child->clipRectChanged(); |
commit-queue@webkit.org | 216b5ea | 2013-02-27 22:05:07 +0000 | [diff] [blame] | 1045 | } |
| 1046 | |
jamesr@google.com | e53ce64 | 2011-04-14 06:51:50 +0000 | [diff] [blame] | 1047 | static void positionScrollbarLayer(GraphicsLayer* graphicsLayer, Scrollbar* scrollbar) |
| 1048 | { |
| 1049 | if (!graphicsLayer || !scrollbar) |
| 1050 | return; |
andersca@apple.com | eda9e81 | 2011-12-21 23:02:33 +0000 | [diff] [blame] | 1051 | |
eae@chromium.org | 92a579f | 2011-11-08 02:11:06 +0000 | [diff] [blame] | 1052 | IntRect scrollbarRect = scrollbar->frameRect(); |
jamesr@google.com | e53ce64 | 2011-04-14 06:51:50 +0000 | [diff] [blame] | 1053 | graphicsLayer->setPosition(scrollbarRect.location()); |
andersca@apple.com | eda9e81 | 2011-12-21 23:02:33 +0000 | [diff] [blame] | 1054 | |
| 1055 | if (scrollbarRect.size() == graphicsLayer->size()) |
| 1056 | return; |
| 1057 | |
jamesr@google.com | e53ce64 | 2011-04-14 06:51:50 +0000 | [diff] [blame] | 1058 | graphicsLayer->setSize(scrollbarRect.size()); |
andersca@apple.com | eda9e81 | 2011-12-21 23:02:33 +0000 | [diff] [blame] | 1059 | |
simon.fraser@apple.com | ff54931 | 2014-04-19 05:31:39 +0000 | [diff] [blame] | 1060 | if (graphicsLayer->usesContentsLayer()) { |
andersca@apple.com | eda9e81 | 2011-12-21 23:02:33 +0000 | [diff] [blame] | 1061 | graphicsLayer->setContentsRect(IntRect(0, 0, scrollbarRect.width(), scrollbarRect.height())); |
| 1062 | return; |
| 1063 | } |
| 1064 | |
| 1065 | graphicsLayer->setDrawsContent(true); |
| 1066 | graphicsLayer->setNeedsDisplay(); |
jamesr@google.com | e53ce64 | 2011-04-14 06:51:50 +0000 | [diff] [blame] | 1067 | } |
| 1068 | |
eae@chromium.org | 92a579f | 2011-11-08 02:11:06 +0000 | [diff] [blame] | 1069 | static void positionScrollCornerLayer(GraphicsLayer* graphicsLayer, const IntRect& cornerRect) |
jamesr@google.com | e53ce64 | 2011-04-14 06:51:50 +0000 | [diff] [blame] | 1070 | { |
| 1071 | if (!graphicsLayer) |
| 1072 | return; |
| 1073 | graphicsLayer->setDrawsContent(!cornerRect.isEmpty()); |
| 1074 | graphicsLayer->setPosition(cornerRect.location()); |
| 1075 | if (cornerRect.size() != graphicsLayer->size()) |
| 1076 | graphicsLayer->setNeedsDisplay(); |
| 1077 | graphicsLayer->setSize(cornerRect.size()); |
| 1078 | } |
jamesr@google.com | e53ce64 | 2011-04-14 06:51:50 +0000 | [diff] [blame] | 1079 | |
| 1080 | void ScrollView::positionScrollbarLayers() |
| 1081 | { |
jamesr@google.com | e53ce64 | 2011-04-14 06:51:50 +0000 | [diff] [blame] | 1082 | positionScrollbarLayer(layerForHorizontalScrollbar(), horizontalScrollbar()); |
| 1083 | positionScrollbarLayer(layerForVerticalScrollbar(), verticalScrollbar()); |
| 1084 | positionScrollCornerLayer(layerForScrollCorner(), scrollCornerRect()); |
jamesr@google.com | e53ce64 | 2011-04-14 06:51:50 +0000 | [diff] [blame] | 1085 | } |
| 1086 | |
commit-queue@webkit.org | 4149b93 | 2014-02-24 19:05:21 +0000 | [diff] [blame] | 1087 | void ScrollView::repaintContentRectangle(const IntRect& rect) |
hyatt@apple.com | 70936b5 | 2008-09-30 20:09:42 +0000 | [diff] [blame] | 1088 | { |
eae@chromium.org | 92a579f | 2011-11-08 02:11:06 +0000 | [diff] [blame] | 1089 | IntRect paintRect = rect; |
simon.fraser@apple.com | 69bbc01 | 2017-08-16 02:05:28 +0000 | [diff] [blame] | 1090 | if (!paintsEntireContents()) |
aestes@apple.com | 0f23b26 | 2014-01-29 03:06:01 +0000 | [diff] [blame] | 1091 | paintRect.intersect(visibleContentRect(LegacyIOSDocumentVisibleRect)); |
kenneth@webkit.org | 9ba6222 | 2009-12-03 14:25:50 +0000 | [diff] [blame] | 1092 | if (paintRect.isEmpty()) |
hyatt@apple.com | 70936b5 | 2008-09-30 20:09:42 +0000 | [diff] [blame] | 1093 | return; |
| 1094 | |
hyatt@apple.com | 70936b5 | 2008-09-30 20:09:42 +0000 | [diff] [blame] | 1095 | if (platformWidget()) { |
commit-queue@webkit.org | 277ad99 | 2011-07-16 05:15:36 +0000 | [diff] [blame] | 1096 | notifyPageThatContentAreaWillPaint(); |
commit-queue@webkit.org | 4149b93 | 2014-02-24 19:05:21 +0000 | [diff] [blame] | 1097 | platformRepaintContentRectangle(paintRect); |
hyatt@apple.com | 70936b5 | 2008-09-30 20:09:42 +0000 | [diff] [blame] | 1098 | return; |
| 1099 | } |
| 1100 | |
commit-queue@webkit.org | 6121dfd | 2013-06-28 11:14:18 +0000 | [diff] [blame] | 1101 | if (HostWindow* window = hostWindow()) |
commit-queue@webkit.org | 4149b93 | 2014-02-24 19:05:21 +0000 | [diff] [blame] | 1102 | window->invalidateContentsAndRootView(contentsToWindow(paintRect)); |
hyatt@apple.com | 70936b5 | 2008-09-30 20:09:42 +0000 | [diff] [blame] | 1103 | } |
| 1104 | |
eae@chromium.org | 92a579f | 2011-11-08 02:11:06 +0000 | [diff] [blame] | 1105 | IntRect ScrollView::scrollCornerRect() const |
andersca@apple.com | 7d8fe98 | 2009-08-20 00:04:48 +0000 | [diff] [blame] | 1106 | { |
eae@chromium.org | 92a579f | 2011-11-08 02:11:06 +0000 | [diff] [blame] | 1107 | IntRect cornerRect; |
bdakin@apple.com | a9d8d85 | 2011-01-19 18:49:35 +0000 | [diff] [blame] | 1108 | |
bdakin@apple.com | 1592fa2 | 2011-02-22 22:28:52 +0000 | [diff] [blame] | 1109 | if (hasOverlayScrollbars()) |
bdakin@apple.com | a9d8d85 | 2011-01-19 18:49:35 +0000 | [diff] [blame] | 1110 | return cornerRect; |
| 1111 | |
bdakin@apple.com | 572c9f3 | 2014-03-20 23:19:04 +0000 | [diff] [blame] | 1112 | int heightTrackedByScrollbar = height() - topContentInset(); |
| 1113 | |
andersca@apple.com | 98f7e26 | 2011-09-22 17:09:22 +0000 | [diff] [blame] | 1114 | if (m_horizontalScrollbar && width() - m_horizontalScrollbar->width() > 0) { |
mmaxfield@apple.com | 4195a70 | 2016-04-27 01:25:26 +0000 | [diff] [blame] | 1115 | cornerRect.unite(IntRect(shouldPlaceBlockDirectionScrollbarOnLeft() ? 0 : m_horizontalScrollbar->width(), |
bdakin@apple.com | 572c9f3 | 2014-03-20 23:19:04 +0000 | [diff] [blame] | 1116 | height() - m_horizontalScrollbar->height(), |
| 1117 | width() - m_horizontalScrollbar->width(), |
| 1118 | m_horizontalScrollbar->height())); |
andersca@apple.com | 7d8fe98 | 2009-08-20 00:04:48 +0000 | [diff] [blame] | 1119 | } |
| 1120 | |
bdakin@apple.com | 572c9f3 | 2014-03-20 23:19:04 +0000 | [diff] [blame] | 1121 | if (m_verticalScrollbar && heightTrackedByScrollbar - m_verticalScrollbar->height() > 0) { |
mmaxfield@apple.com | 4195a70 | 2016-04-27 01:25:26 +0000 | [diff] [blame] | 1122 | cornerRect.unite(IntRect(shouldPlaceBlockDirectionScrollbarOnLeft() ? 0 : width() - m_verticalScrollbar->width(), |
bdakin@apple.com | 572c9f3 | 2014-03-20 23:19:04 +0000 | [diff] [blame] | 1123 | m_verticalScrollbar->height() + topContentInset(), |
| 1124 | m_verticalScrollbar->width(), |
| 1125 | heightTrackedByScrollbar - m_verticalScrollbar->height())); |
andersca@apple.com | 7d8fe98 | 2009-08-20 00:04:48 +0000 | [diff] [blame] | 1126 | } |
bdakin@apple.com | 572c9f3 | 2014-03-20 23:19:04 +0000 | [diff] [blame] | 1127 | |
andersca@apple.com | 7d8fe98 | 2009-08-20 00:04:48 +0000 | [diff] [blame] | 1128 | return cornerRect; |
| 1129 | } |
| 1130 | |
jamesr@google.com | e53ce64 | 2011-04-14 06:51:50 +0000 | [diff] [blame] | 1131 | bool ScrollView::isScrollCornerVisible() const |
| 1132 | { |
| 1133 | return !scrollCornerRect().isEmpty(); |
| 1134 | } |
| 1135 | |
simon.fraser@apple.com | 448c42e | 2015-02-25 05:35:38 +0000 | [diff] [blame] | 1136 | void ScrollView::scrollbarStyleChanged(ScrollbarStyle newStyle, bool forceUpdate) |
bdakin@apple.com | cbaf03e | 2011-06-15 00:09:01 +0000 | [diff] [blame] | 1137 | { |
simon.fraser@apple.com | 448c42e | 2015-02-25 05:35:38 +0000 | [diff] [blame] | 1138 | ScrollableArea::scrollbarStyleChanged(newStyle, forceUpdate); |
bdakin@apple.com | 83c96f4 | 2011-11-28 23:06:56 +0000 | [diff] [blame] | 1139 | if (!forceUpdate) |
| 1140 | return; |
| 1141 | |
simon.fraser@apple.com | db0e067 | 2015-12-30 00:29:36 +0000 | [diff] [blame] | 1142 | updateScrollbars(scrollPosition()); |
andersca@apple.com | 55b3a2a | 2012-01-27 02:01:47 +0000 | [diff] [blame] | 1143 | positionScrollbarLayers(); |
bdakin@apple.com | cbaf03e | 2011-06-15 00:09:01 +0000 | [diff] [blame] | 1144 | } |
| 1145 | |
mmaxfield@apple.com | a93d7ef | 2015-08-29 06:15:28 +0000 | [diff] [blame] | 1146 | void ScrollView::paintScrollCorner(GraphicsContext& context, const IntRect& cornerRect) |
andersca@apple.com | 7d8fe98 | 2009-08-20 00:04:48 +0000 | [diff] [blame] | 1147 | { |
timothy@apple.com | f8942ab | 2018-06-23 01:21:13 +0000 | [diff] [blame] | 1148 | ScrollbarTheme::theme().paintScrollCorner(context, cornerRect); |
andersca@apple.com | 7d8fe98 | 2009-08-20 00:04:48 +0000 | [diff] [blame] | 1149 | } |
| 1150 | |
mmaxfield@apple.com | a93d7ef | 2015-08-29 06:15:28 +0000 | [diff] [blame] | 1151 | void ScrollView::paintScrollbar(GraphicsContext& context, Scrollbar& bar, const IntRect& rect) |
morrita@google.com | c6c4fca | 2012-03-02 02:39:38 +0000 | [diff] [blame] | 1152 | { |
mmaxfield@apple.com | a93d7ef | 2015-08-29 06:15:28 +0000 | [diff] [blame] | 1153 | bar.paint(context, rect); |
morrita@google.com | c6c4fca | 2012-03-02 02:39:38 +0000 | [diff] [blame] | 1154 | } |
| 1155 | |
eae@chromium.org | 92a579f | 2011-11-08 02:11:06 +0000 | [diff] [blame] | 1156 | void ScrollView::invalidateScrollCornerRect(const IntRect& rect) |
jamesr@google.com | e53ce64 | 2011-04-14 06:51:50 +0000 | [diff] [blame] | 1157 | { |
| 1158 | invalidateRect(rect); |
| 1159 | } |
| 1160 | |
mmaxfield@apple.com | a93d7ef | 2015-08-29 06:15:28 +0000 | [diff] [blame] | 1161 | void ScrollView::paintScrollbars(GraphicsContext& context, const IntRect& rect) |
kenneth@webkit.org | cd73270 | 2009-10-19 20:25:25 +0000 | [diff] [blame] | 1162 | { |
abucur@adobe.com | 46b0fd5 | 2014-01-30 10:22:36 +0000 | [diff] [blame] | 1163 | if (m_horizontalScrollbar && !layerForHorizontalScrollbar()) |
mmaxfield@apple.com | a93d7ef | 2015-08-29 06:15:28 +0000 | [diff] [blame] | 1164 | paintScrollbar(context, *m_horizontalScrollbar.get(), rect); |
abucur@adobe.com | 46b0fd5 | 2014-01-30 10:22:36 +0000 | [diff] [blame] | 1165 | if (m_verticalScrollbar && !layerForVerticalScrollbar()) |
mmaxfield@apple.com | a93d7ef | 2015-08-29 06:15:28 +0000 | [diff] [blame] | 1166 | paintScrollbar(context, *m_verticalScrollbar.get(), rect); |
kenneth@webkit.org | cd73270 | 2009-10-19 20:25:25 +0000 | [diff] [blame] | 1167 | |
jamesr@google.com | e53ce64 | 2011-04-14 06:51:50 +0000 | [diff] [blame] | 1168 | if (layerForScrollCorner()) |
| 1169 | return; |
abucur@adobe.com | 46b0fd5 | 2014-01-30 10:22:36 +0000 | [diff] [blame] | 1170 | |
kenneth@webkit.org | cd73270 | 2009-10-19 20:25:25 +0000 | [diff] [blame] | 1171 | paintScrollCorner(context, scrollCornerRect()); |
| 1172 | } |
| 1173 | |
mmaxfield@apple.com | a93d7ef | 2015-08-29 06:15:28 +0000 | [diff] [blame] | 1174 | void ScrollView::paintPanScrollIcon(GraphicsContext& context) |
kenneth@webkit.org | cd73270 | 2009-10-19 20:25:25 +0000 | [diff] [blame] | 1175 | { |
cdumez@apple.com | bb4fe7b | 2017-05-11 23:40:14 +0000 | [diff] [blame] | 1176 | static Image& panScrollIcon = Image::loadPlatformResource("panIcon").leakRef(); |
commit-queue@webkit.org | 1748b12 | 2012-03-10 03:53:50 +0000 | [diff] [blame] | 1177 | IntPoint iconGCPoint = m_panScrollIconPoint; |
| 1178 | if (parent()) |
| 1179 | iconGCPoint = parent()->windowToContents(iconGCPoint); |
cdumez@apple.com | bb4fe7b | 2017-05-11 23:40:14 +0000 | [diff] [blame] | 1180 | context.drawImage(panScrollIcon, iconGCPoint); |
kenneth@webkit.org | cd73270 | 2009-10-19 20:25:25 +0000 | [diff] [blame] | 1181 | } |
| 1182 | |
dino@apple.com | 79c37e3 | 2017-05-09 21:35:55 +0000 | [diff] [blame] | 1183 | void ScrollView::paint(GraphicsContext& context, const IntRect& rect, SecurityOriginPaintPolicy securityOriginPaintPolicy) |
hyatt@apple.com | 3b82dce | 2008-10-01 17:51:02 +0000 | [diff] [blame] | 1184 | { |
| 1185 | if (platformWidget()) { |
| 1186 | Widget::paint(context, rect); |
| 1187 | return; |
| 1188 | } |
| 1189 | |
commit-queue@webkit.org | 55712e8 | 2018-07-17 00:17:45 +0000 | [diff] [blame] | 1190 | if (context.paintingDisabled() && !context.performingPaintInvalidation()) |
hyatt@apple.com | 3b82dce | 2008-10-01 17:51:02 +0000 | [diff] [blame] | 1191 | return; |
| 1192 | |
bdakin@apple.com | 9e05cff | 2011-03-16 02:21:59 +0000 | [diff] [blame] | 1193 | notifyPageThatContentAreaWillPaint(); |
bdakin@apple.com | 98933a5 | 2011-04-14 22:09:04 +0000 | [diff] [blame] | 1194 | |
eae@chromium.org | 92a579f | 2011-11-08 02:11:06 +0000 | [diff] [blame] | 1195 | IntRect documentDirtyRect = rect; |
mikhail.pozdnyakov@intel.com | 5b0415c6 | 2013-02-07 16:46:49 +0000 | [diff] [blame] | 1196 | if (!paintsEntireContents()) { |
mmaxfield@apple.com | 4280b49 | 2016-03-22 22:15:45 +0000 | [diff] [blame] | 1197 | IntRect visibleAreaWithoutScrollbars(locationOfContents(), visibleContentRect(LegacyIOSDocumentVisibleRect).size()); |
mikhail.pozdnyakov@intel.com | 5b0415c6 | 2013-02-07 16:46:49 +0000 | [diff] [blame] | 1198 | documentDirtyRect.intersect(visibleAreaWithoutScrollbars); |
| 1199 | } |
mitz@apple.com | e4c40cc | 2011-04-22 18:13:24 +0000 | [diff] [blame] | 1200 | |
| 1201 | if (!documentDirtyRect.isEmpty()) { |
mmaxfield@apple.com | a93d7ef | 2015-08-29 06:15:28 +0000 | [diff] [blame] | 1202 | GraphicsContextStateSaver stateSaver(context); |
hyatt@apple.com | 3b82dce | 2008-10-01 17:51:02 +0000 | [diff] [blame] | 1203 | |
mmaxfield@apple.com | 4280b49 | 2016-03-22 22:15:45 +0000 | [diff] [blame] | 1204 | IntPoint locationOfContents = this->locationOfContents(); |
| 1205 | context.translate(locationOfContents.x(), locationOfContents.y()); |
| 1206 | documentDirtyRect.moveBy(-locationOfContents); |
hyatt@apple.com | 3b82dce | 2008-10-01 17:51:02 +0000 | [diff] [blame] | 1207 | |
simon.fraser@apple.com | 09cdc29 | 2011-04-21 15:55:57 +0000 | [diff] [blame] | 1208 | if (!paintsEntireContents()) { |
mmaxfield@apple.com | a93d7ef | 2015-08-29 06:15:28 +0000 | [diff] [blame] | 1209 | context.translate(-scrollX(), -scrollY()); |
leviw@chromium.org | 35e0131 | 2011-06-03 02:41:09 +0000 | [diff] [blame] | 1210 | documentDirtyRect.moveBy(scrollPosition()); |
hyatt@apple.com | 3b82dce | 2008-10-01 17:51:02 +0000 | [diff] [blame] | 1211 | |
mmaxfield@apple.com | a93d7ef | 2015-08-29 06:15:28 +0000 | [diff] [blame] | 1212 | context.clip(visibleContentRect(LegacyIOSDocumentVisibleRect)); |
simon.fraser@apple.com | 09cdc29 | 2011-04-21 15:55:57 +0000 | [diff] [blame] | 1213 | } |
| 1214 | |
dino@apple.com | 79c37e3 | 2017-05-09 21:35:55 +0000 | [diff] [blame] | 1215 | paintContents(context, documentDirtyRect, securityOriginPaintPolicy); |
andreas.kling@nokia.com | 9b08b64 | 2010-11-17 23:37:04 +0000 | [diff] [blame] | 1216 | } |
hyatt@apple.com | 3b82dce | 2008-10-01 17:51:02 +0000 | [diff] [blame] | 1217 | |
abucur@adobe.com | 46b0fd5 | 2014-01-30 10:22:36 +0000 | [diff] [blame] | 1218 | #if ENABLE(RUBBER_BANDING) |
commit-queue@webkit.org | 0a4465d | 2011-09-15 04:06:49 +0000 | [diff] [blame] | 1219 | if (!layerForOverhangAreas()) |
| 1220 | calculateAndPaintOverhangAreas(context, rect); |
| 1221 | #else |
| 1222 | calculateAndPaintOverhangAreas(context, rect); |
| 1223 | #endif |
weinig@apple.com | fe3ba1a | 2011-01-27 21:23:06 +0000 | [diff] [blame] | 1224 | |
hyatt@apple.com | 3b82dce | 2008-10-01 17:51:02 +0000 | [diff] [blame] | 1225 | // Now paint the scrollbars. |
| 1226 | if (!m_scrollbarsSuppressed && (m_horizontalScrollbar || m_verticalScrollbar)) { |
mmaxfield@apple.com | a93d7ef | 2015-08-29 06:15:28 +0000 | [diff] [blame] | 1227 | GraphicsContextStateSaver stateSaver(context); |
eae@chromium.org | 92a579f | 2011-11-08 02:11:06 +0000 | [diff] [blame] | 1228 | IntRect scrollViewDirtyRect = rect; |
benjamin@webkit.org | 25bc57c | 2014-03-10 21:25:24 +0000 | [diff] [blame] | 1229 | IntRect visibleAreaWithScrollbars(location(), unobscuredContentRectIncludingScrollbars().size()); |
aelias@chromium.org | a49e9d2 | 2013-02-06 23:47:17 +0000 | [diff] [blame] | 1230 | scrollViewDirtyRect.intersect(visibleAreaWithScrollbars); |
mmaxfield@apple.com | a93d7ef | 2015-08-29 06:15:28 +0000 | [diff] [blame] | 1231 | context.translate(x(), y()); |
leviw@chromium.org | 35e0131 | 2011-06-03 02:41:09 +0000 | [diff] [blame] | 1232 | scrollViewDirtyRect.moveBy(-location()); |
mmaxfield@apple.com | a93d7ef | 2015-08-29 06:15:28 +0000 | [diff] [blame] | 1233 | context.clip(IntRect(IntPoint(), visibleAreaWithScrollbars.size())); |
hyatt@apple.com | 3b82dce | 2008-10-01 17:51:02 +0000 | [diff] [blame] | 1234 | |
kenneth@webkit.org | cd73270 | 2009-10-19 20:25:25 +0000 | [diff] [blame] | 1235 | paintScrollbars(context, scrollViewDirtyRect); |
hyatt@apple.com | 3b82dce | 2008-10-01 17:51:02 +0000 | [diff] [blame] | 1236 | } |
| 1237 | |
| 1238 | // Paint the panScroll Icon |
kenneth@webkit.org | cd73270 | 2009-10-19 20:25:25 +0000 | [diff] [blame] | 1239 | if (m_drawPanScrollIcon) |
| 1240 | paintPanScrollIcon(context); |
hyatt@apple.com | 3b82dce | 2008-10-01 17:51:02 +0000 | [diff] [blame] | 1241 | } |
| 1242 | |
eae@chromium.org | 92a579f | 2011-11-08 02:11:06 +0000 | [diff] [blame] | 1243 | void ScrollView::calculateOverhangAreasForPainting(IntRect& horizontalOverhangRect, IntRect& verticalOverhangRect) |
weinig@apple.com | fe3ba1a | 2011-01-27 21:23:06 +0000 | [diff] [blame] | 1244 | { |
simon.fraser@apple.com | 870034d | 2015-12-16 23:41:05 +0000 | [diff] [blame] | 1245 | IntSize scrollbarSpace = scrollbarIntrusion(); |
weinig@apple.com | 645f83d | 2011-02-03 03:45:32 +0000 | [diff] [blame] | 1246 | |
simon.fraser@apple.com | efc492b | 2015-12-30 20:15:27 +0000 | [diff] [blame] | 1247 | // FIXME: use maximumScrollOffset(). |
| 1248 | ScrollOffset scrollOffset = scrollOffsetFromPosition(scrollPosition()); |
| 1249 | if (scrollOffset.y() < 0) { |
weinig@apple.com | fe3ba1a | 2011-01-27 21:23:06 +0000 | [diff] [blame] | 1250 | horizontalOverhangRect = frameRect(); |
simon.fraser@apple.com | efc492b | 2015-12-30 20:15:27 +0000 | [diff] [blame] | 1251 | horizontalOverhangRect.setHeight(-scrollOffset.y()); |
simon.fraser@apple.com | 870034d | 2015-12-16 23:41:05 +0000 | [diff] [blame] | 1252 | horizontalOverhangRect.setWidth(horizontalOverhangRect.width() - scrollbarSpace.width()); |
simon.fraser@apple.com | efc492b | 2015-12-30 20:15:27 +0000 | [diff] [blame] | 1253 | } else if (totalContentsSize().height() && scrollOffset.y() > totalContentsSize().height() - visibleHeight()) { |
| 1254 | int height = scrollOffset.y() - (totalContentsSize().height() - visibleHeight()); |
weinig@apple.com | fe3ba1a | 2011-01-27 21:23:06 +0000 | [diff] [blame] | 1255 | horizontalOverhangRect = frameRect(); |
simon.fraser@apple.com | 870034d | 2015-12-16 23:41:05 +0000 | [diff] [blame] | 1256 | horizontalOverhangRect.setY(frameRect().maxY() - height - scrollbarSpace.height()); |
weinig@apple.com | fe3ba1a | 2011-01-27 21:23:06 +0000 | [diff] [blame] | 1257 | horizontalOverhangRect.setHeight(height); |
simon.fraser@apple.com | 870034d | 2015-12-16 23:41:05 +0000 | [diff] [blame] | 1258 | horizontalOverhangRect.setWidth(horizontalOverhangRect.width() - scrollbarSpace.width()); |
weinig@apple.com | fe3ba1a | 2011-01-27 21:23:06 +0000 | [diff] [blame] | 1259 | } |
| 1260 | |
simon.fraser@apple.com | efc492b | 2015-12-30 20:15:27 +0000 | [diff] [blame] | 1261 | if (scrollOffset.x() < 0) { |
| 1262 | verticalOverhangRect.setWidth(-scrollOffset.x()); |
simon.fraser@apple.com | 870034d | 2015-12-16 23:41:05 +0000 | [diff] [blame] | 1263 | verticalOverhangRect.setHeight(frameRect().height() - horizontalOverhangRect.height() - scrollbarSpace.height()); |
weinig@apple.com | 8c01924 | 2011-03-10 21:43:37 +0000 | [diff] [blame] | 1264 | verticalOverhangRect.setX(frameRect().x()); |
weinig@apple.com | fe3ba1a | 2011-01-27 21:23:06 +0000 | [diff] [blame] | 1265 | if (horizontalOverhangRect.y() == frameRect().y()) |
| 1266 | verticalOverhangRect.setY(frameRect().y() + horizontalOverhangRect.height()); |
| 1267 | else |
| 1268 | verticalOverhangRect.setY(frameRect().y()); |
simon.fraser@apple.com | efc492b | 2015-12-30 20:15:27 +0000 | [diff] [blame] | 1269 | } else if (contentsWidth() && scrollOffset.x() > contentsWidth() - visibleWidth()) { |
| 1270 | int width = scrollOffset.x() - (contentsWidth() - visibleWidth()); |
weinig@apple.com | fe3ba1a | 2011-01-27 21:23:06 +0000 | [diff] [blame] | 1271 | verticalOverhangRect.setWidth(width); |
simon.fraser@apple.com | 870034d | 2015-12-16 23:41:05 +0000 | [diff] [blame] | 1272 | verticalOverhangRect.setHeight(frameRect().height() - horizontalOverhangRect.height() - scrollbarSpace.height()); |
| 1273 | verticalOverhangRect.setX(frameRect().maxX() - width - scrollbarSpace.width()); |
weinig@apple.com | fe3ba1a | 2011-01-27 21:23:06 +0000 | [diff] [blame] | 1274 | if (horizontalOverhangRect.y() == frameRect().y()) |
| 1275 | verticalOverhangRect.setY(frameRect().y() + horizontalOverhangRect.height()); |
| 1276 | else |
| 1277 | verticalOverhangRect.setY(frameRect().y()); |
| 1278 | } |
| 1279 | } |
| 1280 | |
commit-queue@webkit.org | c1e9436 | 2012-02-22 20:18:30 +0000 | [diff] [blame] | 1281 | void ScrollView::updateOverhangAreas() |
| 1282 | { |
commit-queue@webkit.org | 6121dfd | 2013-06-28 11:14:18 +0000 | [diff] [blame] | 1283 | HostWindow* window = hostWindow(); |
| 1284 | if (!window) |
commit-queue@webkit.org | c1e9436 | 2012-02-22 20:18:30 +0000 | [diff] [blame] | 1285 | return; |
| 1286 | |
| 1287 | IntRect horizontalOverhangRect; |
| 1288 | IntRect verticalOverhangRect; |
| 1289 | calculateOverhangAreasForPainting(horizontalOverhangRect, verticalOverhangRect); |
commit-queue@webkit.org | c1e9436 | 2012-02-22 20:18:30 +0000 | [diff] [blame] | 1290 | if (!horizontalOverhangRect.isEmpty()) |
commit-queue@webkit.org | 4149b93 | 2014-02-24 19:05:21 +0000 | [diff] [blame] | 1291 | window->invalidateContentsAndRootView(horizontalOverhangRect); |
commit-queue@webkit.org | c1e9436 | 2012-02-22 20:18:30 +0000 | [diff] [blame] | 1292 | if (!verticalOverhangRect.isEmpty()) |
commit-queue@webkit.org | 4149b93 | 2014-02-24 19:05:21 +0000 | [diff] [blame] | 1293 | window->invalidateContentsAndRootView(verticalOverhangRect); |
commit-queue@webkit.org | c1e9436 | 2012-02-22 20:18:30 +0000 | [diff] [blame] | 1294 | } |
| 1295 | |
mmaxfield@apple.com | a93d7ef | 2015-08-29 06:15:28 +0000 | [diff] [blame] | 1296 | void ScrollView::paintOverhangAreas(GraphicsContext& context, const IntRect& horizontalOverhangRect, const IntRect& verticalOverhangRect, const IntRect& dirtyRect) |
weinig@apple.com | fe3ba1a | 2011-01-27 21:23:06 +0000 | [diff] [blame] | 1297 | { |
akling@apple.com | 53dfd8e | 2015-09-03 02:58:14 +0000 | [diff] [blame] | 1298 | ScrollbarTheme::theme().paintOverhangAreas(*this, context, horizontalOverhangRect, verticalOverhangRect, dirtyRect); |
weinig@apple.com | fe3ba1a | 2011-01-27 21:23:06 +0000 | [diff] [blame] | 1299 | } |
| 1300 | |
mmaxfield@apple.com | a93d7ef | 2015-08-29 06:15:28 +0000 | [diff] [blame] | 1301 | void ScrollView::calculateAndPaintOverhangAreas(GraphicsContext& context, const IntRect& dirtyRect) |
commit-queue@webkit.org | 0a4465d | 2011-09-15 04:06:49 +0000 | [diff] [blame] | 1302 | { |
eae@chromium.org | 92a579f | 2011-11-08 02:11:06 +0000 | [diff] [blame] | 1303 | IntRect horizontalOverhangRect; |
| 1304 | IntRect verticalOverhangRect; |
commit-queue@webkit.org | 0a4465d | 2011-09-15 04:06:49 +0000 | [diff] [blame] | 1305 | calculateOverhangAreasForPainting(horizontalOverhangRect, verticalOverhangRect); |
| 1306 | |
| 1307 | if (dirtyRect.intersects(horizontalOverhangRect) || dirtyRect.intersects(verticalOverhangRect)) |
| 1308 | paintOverhangAreas(context, horizontalOverhangRect, verticalOverhangRect, dirtyRect); |
| 1309 | } |
| 1310 | |
bweinstein@apple.com | 9f624e5 | 2009-07-23 18:05:21 +0000 | [diff] [blame] | 1311 | bool ScrollView::isPointInScrollbarCorner(const IntPoint& windowPoint) |
| 1312 | { |
| 1313 | if (!scrollbarCornerPresent()) |
| 1314 | return false; |
| 1315 | |
eae@chromium.org | 92a579f | 2011-11-08 02:11:06 +0000 | [diff] [blame] | 1316 | IntPoint viewPoint = convertFromContainingWindow(windowPoint); |
bweinstein@apple.com | 9f624e5 | 2009-07-23 18:05:21 +0000 | [diff] [blame] | 1317 | |
| 1318 | if (m_horizontalScrollbar) { |
eae@chromium.org | 92a579f | 2011-11-08 02:11:06 +0000 | [diff] [blame] | 1319 | int horizontalScrollbarYMin = m_horizontalScrollbar->frameRect().y(); |
| 1320 | int horizontalScrollbarYMax = m_horizontalScrollbar->frameRect().y() + m_horizontalScrollbar->frameRect().height(); |
| 1321 | int horizontalScrollbarXMin = m_horizontalScrollbar->frameRect().x() + m_horizontalScrollbar->frameRect().width(); |
bweinstein@apple.com | 9f624e5 | 2009-07-23 18:05:21 +0000 | [diff] [blame] | 1322 | |
| 1323 | return viewPoint.y() > horizontalScrollbarYMin && viewPoint.y() < horizontalScrollbarYMax && viewPoint.x() > horizontalScrollbarXMin; |
| 1324 | } |
| 1325 | |
eae@chromium.org | 92a579f | 2011-11-08 02:11:06 +0000 | [diff] [blame] | 1326 | int verticalScrollbarXMin = m_verticalScrollbar->frameRect().x(); |
| 1327 | int verticalScrollbarXMax = m_verticalScrollbar->frameRect().x() + m_verticalScrollbar->frameRect().width(); |
| 1328 | int verticalScrollbarYMin = m_verticalScrollbar->frameRect().y() + m_verticalScrollbar->frameRect().height(); |
bweinstein@apple.com | 9f624e5 | 2009-07-23 18:05:21 +0000 | [diff] [blame] | 1329 | |
| 1330 | return viewPoint.x() > verticalScrollbarXMin && viewPoint.x() < verticalScrollbarXMax && viewPoint.y() > verticalScrollbarYMin; |
| 1331 | } |
| 1332 | |
hyatt@apple.com | e2a30fd | 2008-10-13 21:23:21 +0000 | [diff] [blame] | 1333 | bool ScrollView::scrollbarCornerPresent() const |
| 1334 | { |
andersca@apple.com | 98f7e26 | 2011-09-22 17:09:22 +0000 | [diff] [blame] | 1335 | return (m_horizontalScrollbar && width() - m_horizontalScrollbar->width() > 0) |
| 1336 | || (m_verticalScrollbar && height() - m_verticalScrollbar->height() > 0); |
hyatt@apple.com | e2a30fd | 2008-10-13 21:23:21 +0000 | [diff] [blame] | 1337 | } |
| 1338 | |
mmaxfield@apple.com | 221502e | 2016-03-30 16:50:14 +0000 | [diff] [blame] | 1339 | IntRect ScrollView::convertFromScrollbarToContainingView(const Scrollbar& scrollbar, const IntRect& localRect) const |
hyatt@apple.com | 6dc5ec3 | 2009-07-02 20:18:53 +0000 | [diff] [blame] | 1340 | { |
| 1341 | // Scrollbars won't be transformed within us |
eae@chromium.org | 92a579f | 2011-11-08 02:11:06 +0000 | [diff] [blame] | 1342 | IntRect newRect = localRect; |
mmaxfield@apple.com | 221502e | 2016-03-30 16:50:14 +0000 | [diff] [blame] | 1343 | newRect.moveBy(scrollbar.location()); |
hyatt@apple.com | 6dc5ec3 | 2009-07-02 20:18:53 +0000 | [diff] [blame] | 1344 | return newRect; |
| 1345 | } |
| 1346 | |
mmaxfield@apple.com | 221502e | 2016-03-30 16:50:14 +0000 | [diff] [blame] | 1347 | IntRect ScrollView::convertFromContainingViewToScrollbar(const Scrollbar& scrollbar, const IntRect& parentRect) const |
hyatt@apple.com | 6dc5ec3 | 2009-07-02 20:18:53 +0000 | [diff] [blame] | 1348 | { |
eae@chromium.org | 92a579f | 2011-11-08 02:11:06 +0000 | [diff] [blame] | 1349 | IntRect newRect = parentRect; |
hyatt@apple.com | 6dc5ec3 | 2009-07-02 20:18:53 +0000 | [diff] [blame] | 1350 | // Scrollbars won't be transformed within us |
mmaxfield@apple.com | 221502e | 2016-03-30 16:50:14 +0000 | [diff] [blame] | 1351 | newRect.moveBy(-scrollbar.location()); |
hyatt@apple.com | 6dc5ec3 | 2009-07-02 20:18:53 +0000 | [diff] [blame] | 1352 | return newRect; |
| 1353 | } |
| 1354 | |
| 1355 | // FIXME: test these on windows |
mmaxfield@apple.com | 221502e | 2016-03-30 16:50:14 +0000 | [diff] [blame] | 1356 | IntPoint ScrollView::convertFromScrollbarToContainingView(const Scrollbar& scrollbar, const IntPoint& localPoint) const |
hyatt@apple.com | 6dc5ec3 | 2009-07-02 20:18:53 +0000 | [diff] [blame] | 1357 | { |
| 1358 | // Scrollbars won't be transformed within us |
eae@chromium.org | 92a579f | 2011-11-08 02:11:06 +0000 | [diff] [blame] | 1359 | IntPoint newPoint = localPoint; |
mmaxfield@apple.com | 221502e | 2016-03-30 16:50:14 +0000 | [diff] [blame] | 1360 | newPoint.moveBy(scrollbar.location()); |
hyatt@apple.com | 6dc5ec3 | 2009-07-02 20:18:53 +0000 | [diff] [blame] | 1361 | return newPoint; |
| 1362 | } |
| 1363 | |
mmaxfield@apple.com | 221502e | 2016-03-30 16:50:14 +0000 | [diff] [blame] | 1364 | IntPoint ScrollView::convertFromContainingViewToScrollbar(const Scrollbar& scrollbar, const IntPoint& parentPoint) const |
hyatt@apple.com | 6dc5ec3 | 2009-07-02 20:18:53 +0000 | [diff] [blame] | 1365 | { |
eae@chromium.org | 92a579f | 2011-11-08 02:11:06 +0000 | [diff] [blame] | 1366 | IntPoint newPoint = parentPoint; |
hyatt@apple.com | 6dc5ec3 | 2009-07-02 20:18:53 +0000 | [diff] [blame] | 1367 | // Scrollbars won't be transformed within us |
mmaxfield@apple.com | 221502e | 2016-03-30 16:50:14 +0000 | [diff] [blame] | 1368 | newPoint.moveBy(-scrollbar.location()); |
hyatt@apple.com | 6dc5ec3 | 2009-07-02 20:18:53 +0000 | [diff] [blame] | 1369 | return newPoint; |
| 1370 | } |
| 1371 | |
hyatt@apple.com | e72b16e | 2008-10-01 20:58:19 +0000 | [diff] [blame] | 1372 | void ScrollView::setParentVisible(bool visible) |
| 1373 | { |
| 1374 | if (isParentVisible() == visible) |
| 1375 | return; |
| 1376 | |
| 1377 | Widget::setParentVisible(visible); |
| 1378 | |
hyatt@apple.com | 587b30b | 2008-12-04 20:07:41 +0000 | [diff] [blame] | 1379 | if (!isSelfVisible()) |
hyatt@apple.com | e72b16e | 2008-10-01 20:58:19 +0000 | [diff] [blame] | 1380 | return; |
| 1381 | |
darin@apple.com | 6c71ce2 | 2017-01-14 03:35:54 +0000 | [diff] [blame] | 1382 | for (auto& child : m_children) |
| 1383 | child->setParentVisible(visible); |
hyatt@apple.com | e72b16e | 2008-10-01 20:58:19 +0000 | [diff] [blame] | 1384 | } |
| 1385 | |
| 1386 | void ScrollView::show() |
| 1387 | { |
| 1388 | if (!isSelfVisible()) { |
| 1389 | setSelfVisible(true); |
| 1390 | if (isParentVisible()) { |
darin@apple.com | 6c71ce2 | 2017-01-14 03:35:54 +0000 | [diff] [blame] | 1391 | for (auto& child : m_children) |
| 1392 | child->setParentVisible(true); |
hyatt@apple.com | e72b16e | 2008-10-01 20:58:19 +0000 | [diff] [blame] | 1393 | } |
| 1394 | } |
| 1395 | |
| 1396 | Widget::show(); |
| 1397 | } |
| 1398 | |
| 1399 | void ScrollView::hide() |
| 1400 | { |
| 1401 | if (isSelfVisible()) { |
| 1402 | if (isParentVisible()) { |
darin@apple.com | 6c71ce2 | 2017-01-14 03:35:54 +0000 | [diff] [blame] | 1403 | for (auto& child : m_children) |
| 1404 | child->setParentVisible(false); |
hyatt@apple.com | e72b16e | 2008-10-01 20:58:19 +0000 | [diff] [blame] | 1405 | } |
| 1406 | setSelfVisible(false); |
| 1407 | } |
| 1408 | |
| 1409 | Widget::hide(); |
| 1410 | } |
| 1411 | |
hyatt@apple.com | 08ef1ea | 2008-10-01 21:11:07 +0000 | [diff] [blame] | 1412 | bool ScrollView::isOffscreen() const |
| 1413 | { |
| 1414 | if (platformWidget()) |
| 1415 | return platformIsOffscreen(); |
| 1416 | |
| 1417 | if (!isVisible()) |
| 1418 | return true; |
| 1419 | |
| 1420 | // FIXME: Add a HostWindow::isOffscreen method here. Since only Mac implements this method |
| 1421 | // currently, we can add the method when the other platforms decide to implement this concept. |
| 1422 | return false; |
| 1423 | } |
| 1424 | |
hyatt@apple.com | 98682b3 | 2008-10-02 20:17:08 +0000 | [diff] [blame] | 1425 | |
eae@chromium.org | 92a579f | 2011-11-08 02:11:06 +0000 | [diff] [blame] | 1426 | void ScrollView::addPanScrollIcon(const IntPoint& iconPosition) |
hyatt@apple.com | 98682b3 | 2008-10-02 20:17:08 +0000 | [diff] [blame] | 1427 | { |
commit-queue@webkit.org | 6121dfd | 2013-06-28 11:14:18 +0000 | [diff] [blame] | 1428 | HostWindow* window = hostWindow(); |
| 1429 | if (!window) |
alice.liu@apple.com | 3c49db4 | 2009-06-21 05:42:39 +0000 | [diff] [blame] | 1430 | return; |
hyatt@apple.com | 98682b3 | 2008-10-02 20:17:08 +0000 | [diff] [blame] | 1431 | m_drawPanScrollIcon = true; |
| 1432 | m_panScrollIconPoint = IntPoint(iconPosition.x() - panIconSizeLength / 2 , iconPosition.y() - panIconSizeLength / 2) ; |
commit-queue@webkit.org | 4149b93 | 2014-02-24 19:05:21 +0000 | [diff] [blame] | 1433 | window->invalidateContentsAndRootView(IntRect(m_panScrollIconPoint, IntSize(panIconSizeLength, panIconSizeLength))); |
hyatt@apple.com | 98682b3 | 2008-10-02 20:17:08 +0000 | [diff] [blame] | 1434 | } |
| 1435 | |
| 1436 | void ScrollView::removePanScrollIcon() |
| 1437 | { |
commit-queue@webkit.org | 6121dfd | 2013-06-28 11:14:18 +0000 | [diff] [blame] | 1438 | HostWindow* window = hostWindow(); |
| 1439 | if (!window) |
alice.liu@apple.com | 3c49db4 | 2009-06-21 05:42:39 +0000 | [diff] [blame] | 1440 | return; |
hyatt@apple.com | 98682b3 | 2008-10-02 20:17:08 +0000 | [diff] [blame] | 1441 | m_drawPanScrollIcon = false; |
commit-queue@webkit.org | 4149b93 | 2014-02-24 19:05:21 +0000 | [diff] [blame] | 1442 | window->invalidateContentsAndRootView(IntRect(m_panScrollIconPoint, IntSize(panIconSizeLength, panIconSizeLength))); |
hyatt@apple.com | 98682b3 | 2008-10-02 20:17:08 +0000 | [diff] [blame] | 1443 | } |
| 1444 | |
hyatt@apple.com | caa25f0 | 2011-02-01 18:44:10 +0000 | [diff] [blame] | 1445 | void ScrollView::setScrollOrigin(const IntPoint& origin, bool updatePositionAtAll, bool updatePositionSynchronously) |
xji@chromium.org | 506e6f6 | 2010-11-30 01:11:08 +0000 | [diff] [blame] | 1446 | { |
xji@chromium.org | 85d8754 | 2011-11-01 22:06:46 +0000 | [diff] [blame] | 1447 | if (scrollOrigin() == origin) |
hyatt@apple.com | a26422b | 2010-12-01 21:31:50 +0000 | [diff] [blame] | 1448 | return; |
xji@chromium.org | 506e6f6 | 2010-11-30 01:11:08 +0000 | [diff] [blame] | 1449 | |
xji@chromium.org | 85d8754 | 2011-11-01 22:06:46 +0000 | [diff] [blame] | 1450 | ScrollableArea::setScrollOrigin(origin); |
xji@chromium.org | 506e6f6 | 2010-11-30 01:11:08 +0000 | [diff] [blame] | 1451 | |
hyatt@apple.com | a26422b | 2010-12-01 21:31:50 +0000 | [diff] [blame] | 1452 | if (platformWidget()) { |
hyatt@apple.com | caa25f0 | 2011-02-01 18:44:10 +0000 | [diff] [blame] | 1453 | platformSetScrollOrigin(origin, updatePositionAtAll, updatePositionSynchronously); |
hyatt@apple.com | a26422b | 2010-12-01 21:31:50 +0000 | [diff] [blame] | 1454 | return; |
| 1455 | } |
| 1456 | |
| 1457 | // Update if the scroll origin changes, since our position will be different if the content size did not change. |
hyatt@apple.com | caa25f0 | 2011-02-01 18:44:10 +0000 | [diff] [blame] | 1458 | if (updatePositionAtAll && updatePositionSynchronously) |
simon.fraser@apple.com | db0e067 | 2015-12-30 00:29:36 +0000 | [diff] [blame] | 1459 | updateScrollbars(scrollPosition()); |
xji@chromium.org | 506e6f6 | 2010-11-30 01:11:08 +0000 | [diff] [blame] | 1460 | } |
| 1461 | |
akling@apple.com | 86ab981 | 2014-05-03 22:16:53 +0000 | [diff] [blame] | 1462 | void ScrollView::styleDidChange() |
| 1463 | { |
| 1464 | if (m_horizontalScrollbar) |
| 1465 | m_horizontalScrollbar->styleChanged(); |
| 1466 | |
| 1467 | if (m_verticalScrollbar) |
| 1468 | m_verticalScrollbar->styleChanged(); |
| 1469 | } |
| 1470 | |
mmaxfield@apple.com | 4280b49 | 2016-03-22 22:15:45 +0000 | [diff] [blame] | 1471 | IntPoint ScrollView::locationOfContents() const |
| 1472 | { |
| 1473 | IntPoint result = location(); |
mmaxfield@apple.com | 4195a70 | 2016-04-27 01:25:26 +0000 | [diff] [blame] | 1474 | if (shouldPlaceBlockDirectionScrollbarOnLeft() && m_verticalScrollbar) |
mmaxfield@apple.com | 4280b49 | 2016-03-22 22:15:45 +0000 | [diff] [blame] | 1475 | result.move(m_verticalScrollbar->occupiedWidth(), 0); |
| 1476 | return result; |
| 1477 | } |
| 1478 | |
mitz@apple.com | 1a8d7d3 | 2014-02-07 23:37:54 +0000 | [diff] [blame] | 1479 | #if !PLATFORM(COCOA) |
darin@apple.com | 9576119 | 2009-05-17 17:47:13 +0000 | [diff] [blame] | 1480 | |
hyatt@apple.com | 8de3eb7 | 2008-10-03 18:29:28 +0000 | [diff] [blame] | 1481 | void ScrollView::platformAddChild(Widget*) |
| 1482 | { |
| 1483 | } |
| 1484 | |
| 1485 | void ScrollView::platformRemoveChild(Widget*) |
| 1486 | { |
| 1487 | } |
darin@apple.com | 9576119 | 2009-05-17 17:47:13 +0000 | [diff] [blame] | 1488 | |
hyatt@apple.com | 8de3eb7 | 2008-10-03 18:29:28 +0000 | [diff] [blame] | 1489 | #endif |
| 1490 | |
mitz@apple.com | 1a8d7d3 | 2014-02-07 23:37:54 +0000 | [diff] [blame] | 1491 | #if !PLATFORM(COCOA) |
darin@apple.com | 9576119 | 2009-05-17 17:47:13 +0000 | [diff] [blame] | 1492 | |
weinig@apple.com | 5851894 | 2009-12-13 04:45:31 +0000 | [diff] [blame] | 1493 | void ScrollView::platformSetScrollbarsSuppressed(bool) |
hyatt@apple.com | e6f04e5 | 2008-09-28 01:07:05 +0000 | [diff] [blame] | 1494 | { |
| 1495 | } |
darin@apple.com | 9576119 | 2009-05-17 17:47:13 +0000 | [diff] [blame] | 1496 | |
commit-queue@webkit.org | d22205d | 2012-09-14 08:42:44 +0000 | [diff] [blame] | 1497 | void ScrollView::platformSetScrollOrigin(const IntPoint&, bool, bool) |
xji@chromium.org | 506e6f6 | 2010-11-30 01:11:08 +0000 | [diff] [blame] | 1498 | { |
| 1499 | } |
| 1500 | |
commit-queue@webkit.org | b31092d | 2011-07-21 01:32:17 +0000 | [diff] [blame] | 1501 | void ScrollView::platformSetScrollbarOverlayStyle(ScrollbarOverlayStyle) |
| 1502 | { |
| 1503 | } |
| 1504 | |
hyatt@apple.com | 64a3be2 | 2008-09-25 20:49:17 +0000 | [diff] [blame] | 1505 | #endif |
| 1506 | |
mitz@apple.com | 1a8d7d3 | 2014-02-07 23:37:54 +0000 | [diff] [blame] | 1507 | #if !PLATFORM(COCOA) |
darin@apple.com | 9576119 | 2009-05-17 17:47:13 +0000 | [diff] [blame] | 1508 | |
hyatt@apple.com | 01adde8 | 2008-09-26 20:49:34 +0000 | [diff] [blame] | 1509 | void ScrollView::platformSetScrollbarModes() |
| 1510 | { |
| 1511 | } |
| 1512 | |
| 1513 | void ScrollView::platformScrollbarModes(ScrollbarMode& horizontal, ScrollbarMode& vertical) const |
| 1514 | { |
darin@apple.com | 9576119 | 2009-05-17 17:47:13 +0000 | [diff] [blame] | 1515 | horizontal = ScrollbarAuto; |
| 1516 | vertical = ScrollbarAuto; |
hyatt@apple.com | 01adde8 | 2008-09-26 20:49:34 +0000 | [diff] [blame] | 1517 | } |
| 1518 | |
cwzwarich@webkit.org | d96b94e | 2008-12-11 21:56:07 +0000 | [diff] [blame] | 1519 | void ScrollView::platformSetCanBlitOnScroll(bool) |
| 1520 | { |
| 1521 | } |
| 1522 | |
| 1523 | bool ScrollView::platformCanBlitOnScroll() const |
| 1524 | { |
| 1525 | return false; |
| 1526 | } |
| 1527 | |
hyatt@apple.com | 9a6f73c | 2008-09-25 22:34:43 +0000 | [diff] [blame] | 1528 | IntRect ScrollView::platformVisibleContentRect(bool) const |
hyatt@apple.com | 79be62c | 2008-09-25 22:25:22 +0000 | [diff] [blame] | 1529 | { |
hyatt@apple.com | 282364d | 2008-09-25 22:52:03 +0000 | [diff] [blame] | 1530 | return IntRect(); |
hyatt@apple.com | 79be62c | 2008-09-25 22:25:22 +0000 | [diff] [blame] | 1531 | } |
hyatt@apple.com | c01fb23 | 2008-09-26 04:28:25 +0000 | [diff] [blame] | 1532 | |
bdakin@apple.com | 044c2c1 | 2014-07-31 22:32:40 +0000 | [diff] [blame] | 1533 | float ScrollView::platformTopContentInset() const |
| 1534 | { |
| 1535 | return 0; |
| 1536 | } |
| 1537 | |
| 1538 | void ScrollView::platformSetTopContentInset(float) |
| 1539 | { |
| 1540 | } |
| 1541 | |
simon.fraser@apple.com | 23bb504 | 2013-08-08 02:00:07 +0000 | [diff] [blame] | 1542 | IntSize ScrollView::platformVisibleContentSize(bool) const |
| 1543 | { |
| 1544 | return IntSize(); |
| 1545 | } |
| 1546 | |
bdakin@apple.com | 35d6420 | 2014-08-01 22:39:52 +0000 | [diff] [blame] | 1547 | IntRect ScrollView::platformVisibleContentRectIncludingObscuredArea(bool) const |
| 1548 | { |
| 1549 | return IntRect(); |
| 1550 | } |
| 1551 | |
| 1552 | IntSize ScrollView::platformVisibleContentSizeIncludingObscuredArea(bool) const |
| 1553 | { |
| 1554 | return IntSize(); |
| 1555 | } |
| 1556 | |
hyatt@apple.com | 70ef2a3 | 2008-09-26 07:15:03 +0000 | [diff] [blame] | 1557 | void ScrollView::platformSetContentsSize() |
| 1558 | { |
| 1559 | } |
mitz@apple.com | ad171f1 | 2008-09-29 20:52:19 +0000 | [diff] [blame] | 1560 | |
eae@chromium.org | 92a579f | 2011-11-08 02:11:06 +0000 | [diff] [blame] | 1561 | IntRect ScrollView::platformContentsToScreen(const IntRect& rect) const |
hyatt@apple.com | fe9c130 | 2008-10-01 20:34:07 +0000 | [diff] [blame] | 1562 | { |
| 1563 | return rect; |
| 1564 | } |
| 1565 | |
eae@chromium.org | 92a579f | 2011-11-08 02:11:06 +0000 | [diff] [blame] | 1566 | IntPoint ScrollView::platformScreenToContents(const IntPoint& point) const |
hyatt@apple.com | fe9c130 | 2008-10-01 20:34:07 +0000 | [diff] [blame] | 1567 | { |
| 1568 | return point; |
| 1569 | } |
| 1570 | |
mitz@apple.com | ad171f1 | 2008-09-29 20:52:19 +0000 | [diff] [blame] | 1571 | void ScrollView::platformSetScrollPosition(const IntPoint&) |
| 1572 | { |
| 1573 | } |
mitz@apple.com | 2449a05 | 2008-09-29 20:57:33 +0000 | [diff] [blame] | 1574 | |
mitz@apple.com | 9a3e3c8 | 2008-09-29 21:04:54 +0000 | [diff] [blame] | 1575 | bool ScrollView::platformScroll(ScrollDirection, ScrollGranularity) |
mitz@apple.com | 2449a05 | 2008-09-29 20:57:33 +0000 | [diff] [blame] | 1576 | { |
mitz@apple.com | 9a3e3c8 | 2008-09-29 21:04:54 +0000 | [diff] [blame] | 1577 | return true; |
mitz@apple.com | 2449a05 | 2008-09-29 20:57:33 +0000 | [diff] [blame] | 1578 | } |
hyatt@apple.com | 70936b5 | 2008-09-30 20:09:42 +0000 | [diff] [blame] | 1579 | |
commit-queue@webkit.org | 4149b93 | 2014-02-24 19:05:21 +0000 | [diff] [blame] | 1580 | void ScrollView::platformRepaintContentRectangle(const IntRect&) |
hyatt@apple.com | 70936b5 | 2008-09-30 20:09:42 +0000 | [diff] [blame] | 1581 | { |
| 1582 | } |
hyatt@apple.com | 08ef1ea | 2008-10-01 21:11:07 +0000 | [diff] [blame] | 1583 | |
| 1584 | bool ScrollView::platformIsOffscreen() const |
| 1585 | { |
| 1586 | return false; |
| 1587 | } |
darin@apple.com | 9576119 | 2009-05-17 17:47:13 +0000 | [diff] [blame] | 1588 | |
hyatt@apple.com | 79be62c | 2008-09-25 22:25:22 +0000 | [diff] [blame] | 1589 | #endif |
| 1590 | |
hyatt@apple.com | f1ffabf | 2008-10-02 18:23:32 +0000 | [diff] [blame] | 1591 | } |