1 | /* |
2 | * Copyright (C) 2004-2018 Apple Inc. All rights reserved. |
3 | * Copyright (C) 2009 Holger Hans Peter Freyther |
4 | * |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions |
7 | * are met: |
8 | * 1. Redistributions of source code must retain the above copyright |
9 | * notice, this list of conditions and the following disclaimer. |
10 | * 2. Redistributions in binary form must reproduce the above copyright |
11 | * notice, this list of conditions and the following disclaimer in the |
12 | * documentation and/or other materials provided with the distribution. |
13 | * |
14 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
15 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
17 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
18 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
19 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
20 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
21 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
22 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
24 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
25 | */ |
26 | |
27 | #pragma once |
28 | |
29 | #include "FloatRect.h" |
30 | #include "IntRect.h" |
31 | #include "Scrollbar.h" |
32 | #include "ScrollableArea.h" |
33 | #include "ScrollTypes.h" |
34 | #include "Widget.h" |
35 | #include <wtf/HashSet.h> |
36 | #include <wtf/WeakPtr.h> |
37 | |
38 | #if PLATFORM(IOS_FAMILY) |
39 | |
40 | OBJC_CLASS WAKScrollView; |
41 | OBJC_CLASS WAKView; |
42 | |
43 | #ifndef NSScrollView |
44 | #define NSScrollView WAKScrollView |
45 | #endif |
46 | |
47 | #ifndef NSView |
48 | #define NSView WAKView |
49 | #endif |
50 | |
51 | #endif // PLATFORM(IOS_FAMILY) |
52 | |
53 | #if PLATFORM(COCOA) && defined __OBJC__ |
54 | @class NSScrollView; |
55 | @protocol WebCoreFrameScrollView; |
56 | #endif |
57 | |
58 | namespace WebCore { |
59 | |
60 | class HostWindow; |
61 | class LegacyTileCache; |
62 | class Scrollbar; |
63 | |
64 | class ScrollView : public Widget, public ScrollableArea { |
65 | public: |
66 | virtual ~ScrollView(); |
67 | |
68 | using WeakValueType = Widget::WeakValueType; |
69 | using Widget::weakPtrFactory; |
70 | |
71 | // ScrollableArea functions. |
72 | WEBCORE_EXPORT void setScrollOffset(const ScrollOffset&) final; |
73 | bool isScrollCornerVisible() const final; |
74 | void scrollbarStyleChanged(ScrollbarStyle, bool forceUpdate) override; |
75 | |
76 | virtual void notifyPageThatContentAreaWillPaint() const; |
77 | |
78 | IntPoint locationOfContents() const; |
79 | |
80 | // NOTE: This should only be called by the overridden setScrollOffset from ScrollableArea. |
81 | virtual void scrollTo(const ScrollPosition&); |
82 | |
83 | // The window thats hosts the ScrollView. The ScrollView will communicate scrolls and repaints to the |
84 | // host window in the window's coordinate space. |
85 | virtual HostWindow* hostWindow() const = 0; |
86 | |
87 | // Returns a clip rect in host window coordinates. Used to clip the blit on a scroll. |
88 | virtual IntRect windowClipRect() const = 0; |
89 | |
90 | // Functions for child manipulation and inspection. |
91 | const HashSet<Ref<Widget>>& children() const { return m_children; } |
92 | WEBCORE_EXPORT virtual void addChild(Widget&); |
93 | WEBCORE_EXPORT virtual void removeChild(Widget&); |
94 | |
95 | // If the scroll view does not use a native widget, then it will have cross-platform Scrollbars. These functions |
96 | // can be used to obtain those scrollbars. |
97 | Scrollbar* horizontalScrollbar() const final { return m_horizontalScrollbar.get(); } |
98 | Scrollbar* verticalScrollbar() const final { return m_verticalScrollbar.get(); } |
99 | bool isScrollViewScrollbar(const Widget* child) const { return horizontalScrollbar() == child || verticalScrollbar() == child; } |
100 | |
101 | void positionScrollbarLayers(); |
102 | |
103 | // Functions for setting and retrieving the scrolling mode in each axis (horizontal/vertical). The mode has values of |
104 | // AlwaysOff, AlwaysOn, and Auto. AlwaysOff means never show a scrollbar, AlwaysOn means always show a scrollbar. |
105 | // Auto means show a scrollbar only when one is needed. |
106 | // Note that for platforms with native widgets, these modes are considered advisory. In other words the underlying native |
107 | // widget may choose not to honor the requested modes. |
108 | WEBCORE_EXPORT void setScrollbarModes(ScrollbarMode horizontalMode, ScrollbarMode verticalMode, bool horizontalLock = false, bool verticalLock = false); |
109 | void setHorizontalScrollbarMode(ScrollbarMode mode, bool lock = false) { setScrollbarModes(mode, verticalScrollbarMode(), lock, verticalScrollbarLock()); } |
110 | void setVerticalScrollbarMode(ScrollbarMode mode, bool lock = false) { setScrollbarModes(horizontalScrollbarMode(), mode, horizontalScrollbarLock(), lock); }; |
111 | WEBCORE_EXPORT void scrollbarModes(ScrollbarMode& horizontalMode, ScrollbarMode& verticalMode) const; |
112 | ScrollbarMode horizontalScrollbarMode() const final { ScrollbarMode horizontal, vertical; scrollbarModes(horizontal, vertical); return horizontal; } |
113 | ScrollbarMode verticalScrollbarMode() const final { ScrollbarMode horizontal, vertical; scrollbarModes(horizontal, vertical); return vertical; } |
114 | |
115 | void setHorizontalScrollbarLock(bool lock = true) { m_horizontalScrollbarLock = lock; } |
116 | bool horizontalScrollbarLock() const { return m_horizontalScrollbarLock; } |
117 | void setVerticalScrollbarLock(bool lock = true) { m_verticalScrollbarLock = lock; } |
118 | bool verticalScrollbarLock() const { return m_verticalScrollbarLock; } |
119 | |
120 | void setScrollingModesLock(bool lock = true) { m_horizontalScrollbarLock = m_verticalScrollbarLock = lock; } |
121 | |
122 | WEBCORE_EXPORT virtual void setCanHaveScrollbars(bool); |
123 | bool canHaveScrollbars() const { return horizontalScrollbarMode() != ScrollbarAlwaysOff || verticalScrollbarMode() != ScrollbarAlwaysOff; } |
124 | |
125 | virtual bool avoidScrollbarCreation() const { return false; } |
126 | |
127 | void setScrollbarOverlayStyle(ScrollbarOverlayStyle) final; |
128 | |
129 | // By default you only receive paint events for the area that is visible. In the case of using a |
130 | // tiled backing store, this function can be set, so that the view paints the entire contents. |
131 | bool paintsEntireContents() const { return m_paintsEntireContents; } |
132 | WEBCORE_EXPORT void setPaintsEntireContents(bool); |
133 | |
134 | // By default programmatic scrolling is handled by WebCore and not by the UI application. |
135 | // In the case of using a tiled backing store, this mode can be set, so that the scroll requests |
136 | // are delegated to the UI application. |
137 | bool delegatesScrolling() const { return m_delegatesScrolling; } |
138 | WEBCORE_EXPORT void setDelegatesScrolling(bool); |
139 | |
140 | // Overridden by FrameView to create custom CSS scrollbars if applicable. |
141 | virtual Ref<Scrollbar> createScrollbar(ScrollbarOrientation); |
142 | |
143 | void styleDidChange(); |
144 | |
145 | // If the prohibits scrolling flag is set, then all scrolling in the view (even programmatic scrolling) is turned off. |
146 | void setProhibitsScrolling(bool b) { m_prohibitsScrolling = b; } |
147 | bool prohibitsScrolling() const { return m_prohibitsScrolling; } |
148 | |
149 | // Whether or not a scroll view will blit visible contents when it is scrolled. Blitting is disabled in situations |
150 | // where it would cause rendering glitches (such as with fixed backgrounds or when the view is partially transparent). |
151 | void setCanBlitOnScroll(bool); |
152 | bool canBlitOnScroll() const; |
153 | |
154 | // There are at least three types of contentInset. Usually we just care about WebCoreContentInset, which is the inset |
155 | // that is set on a Page that requires WebCore to move its layers to accomodate the inset. However, there are platform |
156 | // concepts that are similar on both iOS and Mac when there is a platformWidget(). Sometimes we need the Mac platform value |
157 | // for topContentInset, so when the TopContentInsetType is WebCoreOrPlatformContentInset, platformTopContentInset() |
158 | // will be returned instead of the value set on Page. |
159 | enum class TopContentInsetType { WebCoreContentInset, WebCoreOrPlatformContentInset }; |
160 | virtual float topContentInset(TopContentInsetType = TopContentInsetType::WebCoreContentInset) const { return 0; } |
161 | |
162 | // The visible content rect has a location that is the scrolled offset of the document. The width and height are the unobscured viewport |
163 | // width and height. By default the scrollbars themselves are excluded from this rectangle, but an optional boolean argument allows them |
164 | // to be included. |
165 | // In the situation the client is responsible for the scrolling (ie. with a tiled backing store) it is possible to use |
166 | // the setFixedVisibleContentRect instead for the mainframe, though this must be updated manually, e.g just before resuming the page |
167 | // which usually will happen when panning, pinching and rotation ends, or when scale or position are changed manually. |
168 | IntSize visibleSize() const final { return visibleContentRect(LegacyIOSDocumentVisibleRect).size(); } |
169 | |
170 | #if USE(COORDINATED_GRAPHICS) |
171 | virtual void setFixedVisibleContentRect(const IntRect& visibleContentRect) { m_fixedVisibleContentRect = visibleContentRect; } |
172 | IntRect fixedVisibleContentRect() const { return m_fixedVisibleContentRect; } |
173 | #endif |
174 | |
175 | // Parts of the document can be visible through transparent or blured UI widgets of the chrome. Those parts |
176 | // contribute to painting but not to the scrollable area. |
177 | // The unobscuredContentRect is the area that is not covered by UI elements. |
178 | WEBCORE_EXPORT IntRect unobscuredContentRect(VisibleContentRectIncludesScrollbars = ExcludeScrollbars) const; |
179 | #if PLATFORM(IOS_FAMILY) |
180 | IntRect unobscuredContentRectIncludingScrollbars() const { return unobscuredContentRect(IncludeScrollbars); } |
181 | #else |
182 | IntRect unobscuredContentRectIncludingScrollbars() const { return visibleContentRectIncludingScrollbars(); } |
183 | #endif |
184 | |
185 | #if PLATFORM(IOS_FAMILY) |
186 | // This is the area that is partially or fully exposed, and may extend under overlapping UI elements. |
187 | WEBCORE_EXPORT FloatRect exposedContentRect() const; |
188 | |
189 | // The given rects are only used if there is no platform widget. |
190 | WEBCORE_EXPORT void setExposedContentRect(const FloatRect&); |
191 | const FloatSize& unobscuredContentSize() const { return m_unobscuredContentSize; } |
192 | WEBCORE_EXPORT void setUnobscuredContentSize(const FloatSize&); |
193 | |
194 | void setActualScrollPosition(const IntPoint&); |
195 | LegacyTileCache* legacyTileCache(); |
196 | #endif |
197 | |
198 | // Size available for view contents, including content inset areas. Not affected by zooming. |
199 | IntSize sizeForVisibleContent(VisibleContentRectIncludesScrollbars = ExcludeScrollbars) const; |
200 | // FIXME: remove this. It's only used for the incorrectly behaving ScrollView::unobscuredContentRectInternal(). |
201 | virtual float visibleContentScaleFactor() const { return 1; } |
202 | |
203 | // Functions for getting/setting the size webkit should use to layout the contents. By default this is the same as the visible |
204 | // content size. Explicitly setting a layout size value will cause webkit to layout the contents using this size instead. |
205 | WEBCORE_EXPORT IntSize layoutSize() const; |
206 | int layoutWidth() const { return layoutSize().width(); } |
207 | int layoutHeight() const { return layoutSize().height(); } |
208 | |
209 | WEBCORE_EXPORT IntSize fixedLayoutSize() const; |
210 | WEBCORE_EXPORT void setFixedLayoutSize(const IntSize&); |
211 | WEBCORE_EXPORT bool useFixedLayout() const; |
212 | WEBCORE_EXPORT void setUseFixedLayout(bool enable); |
213 | |
214 | // Functions for getting/setting the size of the document contained inside the ScrollView (as an IntSize or as individual width and height |
215 | // values). |
216 | WEBCORE_EXPORT IntSize contentsSize() const final; // Always at least as big as the visibleWidth()/visibleHeight(). |
217 | int contentsWidth() const { return contentsSize().width(); } |
218 | int contentsHeight() const { return contentsSize().height(); } |
219 | virtual void setContentsSize(const IntSize&); |
220 | |
221 | // Functions for querying the current scrolled position (both as a point, a size, or as individual X and Y values). |
222 | ScrollPosition scrollPosition() const final { return visibleContentRect(LegacyIOSDocumentVisibleRect).location(); } |
223 | |
224 | ScrollPosition maximumScrollPosition() const override; // The maximum position we can be scrolled to. |
225 | |
226 | // Adjust the passed in scroll position to keep it between the minimum and maximum positions. |
227 | ScrollPosition adjustScrollPositionWithinRange(const ScrollPosition&) const; |
228 | int scrollX() const { return scrollPosition().x(); } |
229 | int scrollY() const { return scrollPosition().y(); } |
230 | |
231 | // Scroll position used by web-exposed features (has legacy iOS behavior). |
232 | WEBCORE_EXPORT IntPoint contentsScrollPosition() const; |
233 | void setContentsScrollPosition(const IntPoint&); |
234 | |
235 | #if PLATFORM(IOS_FAMILY) |
236 | int actualScrollX() const { return unobscuredContentRect().x(); } |
237 | int actualScrollY() const { return unobscuredContentRect().y(); } |
238 | // FIXME: maybe fix scrollPosition() on iOS to return the actual scroll position. |
239 | IntPoint actualScrollPosition() const { return unobscuredContentRect().location(); } |
240 | #endif |
241 | |
242 | // scrollOffset() anchors its (0,0) point at the ScrollableArea's origin. When the Page has a |
243 | // header, the header is positioned at (0,0), ABOVE the start of the Document. So when a page with |
244 | // a header is pinned to the top, the scrollOffset() is (0,0), but the Document is actually at |
245 | // (0, -headerHeight()). documentScrollPositionRelativeToScrollableAreaOrigin() will return this |
246 | // version of the offset, which tracks the top of Document relative to where scrolling was achored. |
247 | ScrollPosition documentScrollPositionRelativeToScrollableAreaOrigin() const; |
248 | |
249 | // scrollPostion() anchors its (0,0) point at the ScrollableArea's origin. The top of the scrolling |
250 | // layer does not represent the top of the view when there is a topContentInset. Additionally, as |
251 | // detailed above, the origin of the scrolling layer also does not necessarily correspond with the |
252 | // top of the document anyway, since there could also be header. documentScrollPositionRelativeToViewOrigin() |
253 | // will return a version of the current scroll offset which tracks the top of the Document |
254 | // relative to the very top of the view. |
255 | WEBCORE_EXPORT ScrollPosition documentScrollPositionRelativeToViewOrigin() const; |
256 | |
257 | IntSize overhangAmount() const final; |
258 | |
259 | void cacheCurrentScrollPosition() { m_cachedScrollPosition = scrollPosition(); } |
260 | ScrollPosition cachedScrollPosition() const { return m_cachedScrollPosition; } |
261 | |
262 | // Functions for scrolling the view. |
263 | virtual void setScrollPosition(const ScrollPosition&); |
264 | void scrollBy(const IntSize& s) { return setScrollPosition(scrollPosition() + s); } |
265 | |
266 | // This function scrolls by lines, pages or pixels. |
267 | bool scroll(ScrollDirection, ScrollGranularity); |
268 | |
269 | // A logical scroll that just ends up calling the corresponding physical scroll() based off the document's writing mode. |
270 | bool logicalScroll(ScrollLogicalDirection, ScrollGranularity); |
271 | |
272 | // Scroll the actual contents of the view (either blitting or invalidating as needed). |
273 | void scrollContents(const IntSize& scrollDelta); |
274 | |
275 | // This gives us a means of blocking painting on our scrollbars until the first layout has occurred. |
276 | WEBCORE_EXPORT void (bool suppressed, bool repaintOnUnsuppress = false); |
277 | bool () const { return m_scrollbarsSuppressed; } |
278 | |
279 | WEBCORE_EXPORT IntPoint rootViewToContents(const IntPoint&) const; |
280 | WEBCORE_EXPORT IntPoint contentsToRootView(const IntPoint&) const; |
281 | WEBCORE_EXPORT FloatPoint contentsToRootView(const FloatPoint&) const; |
282 | WEBCORE_EXPORT IntRect rootViewToContents(const IntRect&) const; |
283 | WEBCORE_EXPORT IntRect contentsToRootView(const IntRect&) const; |
284 | WEBCORE_EXPORT FloatRect rootViewToContents(const FloatRect&) const; |
285 | WEBCORE_EXPORT FloatRect contentsToRootView(const FloatRect&) const; |
286 | |
287 | IntPoint viewToContents(const IntPoint&) const; |
288 | IntPoint contentsToView(const IntPoint&) const; |
289 | |
290 | FloatPoint viewToContents(const FloatPoint&) const; |
291 | FloatPoint contentsToView(const FloatPoint&) const; |
292 | |
293 | IntRect viewToContents(IntRect) const; |
294 | IntRect contentsToView(IntRect) const; |
295 | |
296 | FloatRect viewToContents(FloatRect) const; |
297 | FloatRect contentsToView(FloatRect) const; |
298 | |
299 | IntPoint contentsToContainingViewContents(const IntPoint&) const; |
300 | IntRect contentsToContainingViewContents(IntRect) const; |
301 | |
302 | WEBCORE_EXPORT IntPoint rootViewToTotalContents(const IntPoint&) const; |
303 | |
304 | // Event coordinates are assumed to be in the coordinate space of a window that contains |
305 | // the entire widget hierarchy. It is up to the platform to decide what the precise definition |
306 | // of containing window is. (For example on Mac it is the containing NSWindow.) |
307 | WEBCORE_EXPORT IntPoint windowToContents(const IntPoint&) const; |
308 | WEBCORE_EXPORT IntPoint contentsToWindow(const IntPoint&) const; |
309 | WEBCORE_EXPORT IntRect windowToContents(const IntRect&) const; |
310 | WEBCORE_EXPORT IntRect contentsToWindow(const IntRect&) const; |
311 | |
312 | // Functions for converting to and from screen coordinates. |
313 | WEBCORE_EXPORT IntRect contentsToScreen(const IntRect&) const; |
314 | IntPoint screenToContents(const IntPoint&) const; |
315 | |
316 | // The purpose of this function is to answer whether or not the scroll view is currently visible. Animations and painting updates can be suspended if |
317 | // we know that we are either not in a window right now or if that window is not visible. |
318 | bool isOffscreen() const; |
319 | |
320 | // Called when our frame rect changes (or the rect/scroll position of an ancestor changes). |
321 | void frameRectsChanged() final; |
322 | |
323 | // Widget override to update our scrollbars and notify our contents of the resize. |
324 | void setFrameRect(const IntRect&) override; |
325 | |
326 | // Widget override to notify our contents of a cliprect change. |
327 | void clipRectChanged() final; |
328 | |
329 | // For platforms that need to hit test scrollbars from within the engine's event handlers (like Win32). |
330 | Scrollbar* scrollbarAtPoint(const IntPoint& windowPoint); |
331 | |
332 | IntPoint convertChildToSelf(const Widget* child, const IntPoint& point) const |
333 | { |
334 | IntPoint newPoint = point; |
335 | if (!isScrollViewScrollbar(child)) |
336 | newPoint = point - toIntSize(scrollPosition()); |
337 | newPoint.moveBy(child->location()); |
338 | return newPoint; |
339 | } |
340 | |
341 | IntPoint convertSelfToChild(const Widget* child, const IntPoint& point) const |
342 | { |
343 | IntPoint newPoint = point; |
344 | if (!isScrollViewScrollbar(child)) |
345 | newPoint = point + toIntSize(scrollPosition()); |
346 | newPoint.moveBy(-child->location()); |
347 | return newPoint; |
348 | } |
349 | |
350 | // Widget override. Handles painting of the contents of the view as well as the scrollbars. |
351 | WEBCORE_EXPORT void paint(GraphicsContext&, const IntRect&, Widget::SecurityOriginPaintPolicy = SecurityOriginPaintPolicy::AnyOrigin) final; |
352 | void paintScrollbars(GraphicsContext&, const IntRect&); |
353 | |
354 | // Widget overrides to ensure that our children's visibility status is kept up to date when we get shown and hidden. |
355 | WEBCORE_EXPORT void show() override; |
356 | WEBCORE_EXPORT void hide() override; |
357 | WEBCORE_EXPORT void setParentVisible(bool) final; |
358 | |
359 | // Pan scrolling. |
360 | static const int noPanScrollRadius = 15; |
361 | void addPanScrollIcon(const IntPoint&); |
362 | void removePanScrollIcon(); |
363 | void paintPanScrollIcon(GraphicsContext&); |
364 | |
365 | bool isPointInScrollbarCorner(const IntPoint&); |
366 | bool scrollbarCornerPresent() const; |
367 | IntRect scrollCornerRect() const final; |
368 | virtual void paintScrollCorner(GraphicsContext&, const IntRect& cornerRect); |
369 | virtual void paintScrollbar(GraphicsContext&, Scrollbar&, const IntRect&); |
370 | |
371 | IntRect convertFromScrollbarToContainingView(const Scrollbar&, const IntRect&) const final; |
372 | IntRect convertFromContainingViewToScrollbar(const Scrollbar&, const IntRect&) const final; |
373 | IntPoint convertFromScrollbarToContainingView(const Scrollbar&, const IntPoint&) const final; |
374 | IntPoint convertFromContainingViewToScrollbar(const Scrollbar&, const IntPoint&) const final; |
375 | |
376 | void calculateAndPaintOverhangAreas(GraphicsContext&, const IntRect& dirtyRect); |
377 | |
378 | WEBCORE_EXPORT void scrollOffsetChangedViaPlatformWidget(const ScrollOffset& oldOffset, const ScrollOffset& newOffset); |
379 | |
380 | void setAllowsUnclampedScrollPositionForTesting(bool allowsUnclampedScrollPosition) { m_allowsUnclampedScrollPosition = allowsUnclampedScrollPosition; } |
381 | bool allowsUnclampedScrollPosition() const { return m_allowsUnclampedScrollPosition; } |
382 | |
383 | bool managesScrollbars() const; |
384 | |
385 | protected: |
386 | ScrollView(); |
387 | |
388 | virtual void repaintContentRectangle(const IntRect&); |
389 | virtual void paintContents(GraphicsContext&, const IntRect& damageRect, SecurityOriginPaintPolicy = SecurityOriginPaintPolicy::AnyOrigin) = 0; |
390 | |
391 | virtual void paintOverhangAreas(GraphicsContext&, const IntRect& horizontalOverhangArea, const IntRect& verticalOverhangArea, const IntRect& dirtyRect); |
392 | |
393 | void availableContentSizeChanged(AvailableSizeChangeReason) override; |
394 | virtual void addedOrRemovedScrollbar() = 0; |
395 | virtual void delegatesScrollingDidChange() = 0; |
396 | |
397 | // These functions are used to create/destroy scrollbars. |
398 | // They return true if the scrollbar was added or removed. |
399 | bool setHasHorizontalScrollbar(bool, bool* contentSizeAffected = nullptr); |
400 | bool setHasVerticalScrollbar(bool, bool* contentSizeAffected = nullptr); |
401 | |
402 | virtual void updateScrollCorner() = 0; |
403 | void invalidateScrollCornerRect(const IntRect&) final; |
404 | |
405 | // Scroll the content by blitting the pixels. |
406 | virtual bool scrollContentsFastPath(const IntSize& scrollDelta, const IntRect& rectToScroll, const IntRect& clipRect) = 0; |
407 | // Scroll the content by invalidating everything. |
408 | virtual void scrollContentsSlowPath(const IntRect& updateRect); |
409 | |
410 | void setScrollOrigin(const IntPoint&, bool updatePositionAtAll, bool updatePositionSynchronously); |
411 | |
412 | // Subclassed by FrameView to check the writing-mode of the document. |
413 | virtual bool isVerticalDocument() const = 0; |
414 | virtual bool isFlippedDocument() const = 0; |
415 | |
416 | // Called to update the scrollbars to accurately reflect the state of the view. |
417 | void updateScrollbars(const ScrollPosition& desiredPosition); |
418 | |
419 | float platformTopContentInset() const; |
420 | void platformSetTopContentInset(float); |
421 | |
422 | void handleDeferredScrollUpdateAfterContentSizeChange(); |
423 | |
424 | virtual bool shouldDeferScrollUpdateAfterContentSizeChange() = 0; |
425 | |
426 | virtual void scrollOffsetChangedViaPlatformWidgetImpl(const ScrollOffset&, const ScrollOffset&) = 0; |
427 | |
428 | #if PLATFORM(IOS_FAMILY) |
429 | virtual void unobscuredContentSizeChanged() = 0; |
430 | #endif |
431 | |
432 | #if PLATFORM(COCOA) && defined __OBJC__ |
433 | public: |
434 | WEBCORE_EXPORT NSView* documentView() const; |
435 | |
436 | private: |
437 | NSScrollView<WebCoreFrameScrollView>* scrollView() const; |
438 | #endif |
439 | |
440 | private: |
441 | // Size available for view contents, excluding content insets. Not affected by zooming. |
442 | IntSize sizeForUnobscuredContent(VisibleContentRectIncludesScrollbars = ExcludeScrollbars) const; |
443 | |
444 | IntRect visibleContentRectInternal(VisibleContentRectIncludesScrollbars, VisibleContentRectBehavior) const final; |
445 | WEBCORE_EXPORT IntRect unobscuredContentRectInternal(VisibleContentRectIncludesScrollbars = ExcludeScrollbars) const; |
446 | |
447 | void completeUpdatesAfterScrollTo(const IntSize& scrollDelta); |
448 | |
449 | bool setHasScrollbarInternal(RefPtr<Scrollbar>&, ScrollbarOrientation, bool hasBar, bool* contentSizeAffected); |
450 | |
451 | bool isScrollView() const final { return true; } |
452 | |
453 | void init(); |
454 | void destroy(); |
455 | |
456 | IntRect rectToCopyOnScroll() const; |
457 | |
458 | // Called when the scroll position within this view changes. FrameView overrides this to generate repaint invalidations. |
459 | virtual void updateLayerPositionsAfterScrolling() = 0; |
460 | virtual void updateCompositingLayersAfterScrolling() = 0; |
461 | |
462 | void platformAddChild(Widget*); |
463 | void platformRemoveChild(Widget*); |
464 | void platformSetScrollbarModes(); |
465 | void platformScrollbarModes(ScrollbarMode& horizontal, ScrollbarMode& vertical) const; |
466 | void platformSetCanBlitOnScroll(bool); |
467 | bool platformCanBlitOnScroll() const; |
468 | IntRect platformVisibleContentRect(bool includeScrollbars) const; |
469 | IntSize platformVisibleContentSize(bool includeScrollbars) const; |
470 | IntRect platformVisibleContentRectIncludingObscuredArea(bool includeScrollbars) const; |
471 | IntSize platformVisibleContentSizeIncludingObscuredArea(bool includeScrollbars) const; |
472 | void platformSetContentsSize(); |
473 | IntRect platformContentsToScreen(const IntRect&) const; |
474 | IntPoint platformScreenToContents(const IntPoint&) const; |
475 | void platformSetScrollPosition(const IntPoint&); |
476 | bool platformScroll(ScrollDirection, ScrollGranularity); |
477 | void (bool repaintOnUnsuppress); |
478 | void platformRepaintContentRectangle(const IntRect&); |
479 | bool platformIsOffscreen() const; |
480 | void platformSetScrollbarOverlayStyle(ScrollbarOverlayStyle); |
481 | void platformSetScrollOrigin(const IntPoint&, bool updatePositionAtAll, bool updatePositionSynchronously); |
482 | |
483 | void calculateOverhangAreasForPainting(IntRect& horizontalOverhangRect, IntRect& verticalOverhangRect); |
484 | void updateOverhangAreas(); |
485 | |
486 | HashSet<Ref<Widget>> m_children; |
487 | |
488 | RefPtr<Scrollbar> m_horizontalScrollbar; |
489 | RefPtr<Scrollbar> m_verticalScrollbar; |
490 | ScrollbarMode m_horizontalScrollbarMode { ScrollbarAuto }; |
491 | ScrollbarMode m_verticalScrollbarMode { ScrollbarAuto }; |
492 | |
493 | #if PLATFORM(IOS_FAMILY) |
494 | // FIXME: exposedContentRect is a very similar concept to fixedVisibleContentRect except it does not differentiate |
495 | // between exposed and unobscured areas. The two attributes should eventually be merged. |
496 | FloatRect m_exposedContentRect; |
497 | FloatSize m_unobscuredContentSize; |
498 | // This is only used for history scroll position restoration. |
499 | #else |
500 | IntRect m_fixedVisibleContentRect; |
501 | #endif |
502 | ScrollPosition m_scrollPosition; |
503 | IntPoint m_cachedScrollPosition; |
504 | IntSize m_fixedLayoutSize; |
505 | IntSize m_contentsSize; |
506 | |
507 | Optional<IntSize> m_deferredScrollDelta; // Needed for WebKit scrolling |
508 | Optional<std::pair<ScrollOffset, ScrollOffset>> m_deferredScrollOffsets; // Needed for platform widget scrolling |
509 | |
510 | IntPoint m_panScrollIconPoint; |
511 | |
512 | unsigned m_updateScrollbarsPass { 0 }; |
513 | |
514 | bool m_horizontalScrollbarLock { false }; |
515 | bool m_verticalScrollbarLock { false }; |
516 | |
517 | bool m_prohibitsScrolling { false }; |
518 | bool m_allowsUnclampedScrollPosition { false }; |
519 | |
520 | // This bool is unused on Mac OS because we directly ask the platform widget |
521 | // whether it is safe to blit on scroll. |
522 | bool m_canBlitOnScroll { true }; |
523 | |
524 | bool { false }; |
525 | bool m_inUpdateScrollbars { false }; |
526 | |
527 | bool m_drawPanScrollIcon { false }; |
528 | bool m_useFixedLayout { false }; |
529 | |
530 | bool m_paintsEntireContents { false }; |
531 | bool m_delegatesScrolling { false }; |
532 | }; // class ScrollView |
533 | |
534 | } // namespace WebCore |
535 | |
536 | SPECIALIZE_TYPE_TRAITS_WIDGET(ScrollView, isScrollView()) |
537 | |