#pragma once
#include "FloatRect.h"
#include "IntRect.h"
#include "Scrollbar.h"
#include "ScrollableArea.h"
#include "ScrollTypes.h"
#include "Widget.h"
#include <wtf/HashSet.h>
#if PLATFORM(IOS)
OBJC_CLASS WAKScrollView;
OBJC_CLASS WAKView;
#ifndef NSScrollView
#define NSScrollView WAKScrollView
#endif
#ifndef NSView
#define NSView WAKView
#endif
#endif // PLATFORM(IOS)
#if PLATFORM(COCOA) && defined __OBJC__
@class NSScrollView;
@protocol WebCoreFrameScrollView;
#endif
namespace WebCore {
class HostWindow;
class LegacyTileCache;
class Scrollbar;
class ScrollView : public Widget, public ScrollableArea {
public:
virtual ~ScrollView();
int scrollSize(ScrollbarOrientation) const final;
int scrollOffset(ScrollbarOrientation) const final;
WEBCORE_EXPORT void setScrollOffset(const ScrollOffset&) final;
bool isScrollCornerVisible() const final;
void scrollbarStyleChanged(ScrollbarStyle, bool forceUpdate) override;
virtual void notifyPageThatContentAreaWillPaint() const;
IntPoint locationOfContents() const;
virtual void scrollTo(const ScrollPosition&);
virtual HostWindow* hostWindow() const = 0;
virtual IntRect windowClipRect() const = 0;
const HashSet<Ref<Widget>>& children() const { return m_children; }
WEBCORE_EXPORT void addChild(Widget&);
virtual void removeChild(Widget&);
Scrollbar* horizontalScrollbar() const final { return m_horizontalScrollbar.get(); }
Scrollbar* verticalScrollbar() const final { return m_verticalScrollbar.get(); }
bool isScrollViewScrollbar(const Widget* child) const { return horizontalScrollbar() == child || verticalScrollbar() == child; }
void positionScrollbarLayers();
WEBCORE_EXPORT void setScrollbarModes(ScrollbarMode horizontalMode, ScrollbarMode verticalMode, bool horizontalLock = false, bool verticalLock = false);
void setHorizontalScrollbarMode(ScrollbarMode mode, bool lock = false) { setScrollbarModes(mode, verticalScrollbarMode(), lock, verticalScrollbarLock()); }
void setVerticalScrollbarMode(ScrollbarMode mode, bool lock = false) { setScrollbarModes(horizontalScrollbarMode(), mode, horizontalScrollbarLock(), lock); };
WEBCORE_EXPORT void scrollbarModes(ScrollbarMode& horizontalMode, ScrollbarMode& verticalMode) const;
ScrollbarMode horizontalScrollbarMode() const { ScrollbarMode horizontal, vertical; scrollbarModes(horizontal, vertical); return horizontal; }
ScrollbarMode verticalScrollbarMode() const { ScrollbarMode horizontal, vertical; scrollbarModes(horizontal, vertical); return vertical; }
void setHorizontalScrollbarLock(bool lock = true) { m_horizontalScrollbarLock = lock; }
bool horizontalScrollbarLock() const { return m_horizontalScrollbarLock; }
void setVerticalScrollbarLock(bool lock = true) { m_verticalScrollbarLock = lock; }
bool verticalScrollbarLock() const { return m_verticalScrollbarLock; }
void setScrollingModesLock(bool lock = true) { m_horizontalScrollbarLock = m_verticalScrollbarLock = lock; }
WEBCORE_EXPORT virtual void setCanHaveScrollbars(bool);
bool canHaveScrollbars() const { return horizontalScrollbarMode() != ScrollbarAlwaysOff || verticalScrollbarMode() != ScrollbarAlwaysOff; }
virtual bool avoidScrollbarCreation() const { return false; }
void setScrollbarOverlayStyle(ScrollbarOverlayStyle) final;
bool paintsEntireContents() const { return m_paintsEntireContents; }
WEBCORE_EXPORT void setPaintsEntireContents(bool);
bool delegatesScrolling() const { return m_delegatesScrolling; }
WEBCORE_EXPORT void setDelegatesScrolling(bool);
virtual Ref<Scrollbar> createScrollbar(ScrollbarOrientation);
void styleDidChange();
void setProhibitsScrolling(bool b) { m_prohibitsScrolling = b; }
bool prohibitsScrolling() const { return m_prohibitsScrolling; }
void setCanBlitOnScroll(bool);
bool canBlitOnScroll() const;
enum class TopContentInsetType { WebCoreContentInset, WebCoreOrPlatformContentInset };
virtual float topContentInset(TopContentInsetType = TopContentInsetType::WebCoreContentInset) const { return 0; }
IntSize visibleSize() const final { return visibleContentRect(LegacyIOSDocumentVisibleRect).size(); }
#if USE(COORDINATED_GRAPHICS)
virtual void setFixedVisibleContentRect(const IntRect& visibleContentRect) { m_fixedVisibleContentRect = visibleContentRect; }
IntRect fixedVisibleContentRect() const { return m_fixedVisibleContentRect; }
#endif
WEBCORE_EXPORT IntRect unobscuredContentRect(VisibleContentRectIncludesScrollbars = ExcludeScrollbars) const;
#if PLATFORM(IOS)
IntRect unobscuredContentRectIncludingScrollbars() const { return unobscuredContentRect(IncludeScrollbars); }
#else
IntRect unobscuredContentRectIncludingScrollbars() const { return visibleContentRectIncludingScrollbars(); }
#endif
#if PLATFORM(IOS)
WEBCORE_EXPORT FloatRect exposedContentRect() const;
WEBCORE_EXPORT void setExposedContentRect(const FloatRect&);
const FloatSize& unobscuredContentSize() const { return m_unobscuredContentSize; }
WEBCORE_EXPORT void setUnobscuredContentSize(const FloatSize&);
void setActualScrollPosition(const IntPoint&);
LegacyTileCache* legacyTileCache();
#endif
virtual bool inProgrammaticScroll() const { return false; }
IntSize sizeForVisibleContent(VisibleContentRectIncludesScrollbars = ExcludeScrollbars) const;
virtual float visibleContentScaleFactor() const { return 1; }
WEBCORE_EXPORT IntSize layoutSize() const;
int layoutWidth() const { return layoutSize().width(); }
int layoutHeight() const { return layoutSize().height(); }
WEBCORE_EXPORT IntSize fixedLayoutSize() const;
WEBCORE_EXPORT void setFixedLayoutSize(const IntSize&);
WEBCORE_EXPORT bool useFixedLayout() const;
WEBCORE_EXPORT void setUseFixedLayout(bool enable);
WEBCORE_EXPORT IntSize contentsSize() const final; int contentsWidth() const { return contentsSize().width(); }
int contentsHeight() const { return contentsSize().height(); }
virtual void setContentsSize(const IntSize&);
ScrollPosition scrollPosition() const final { return visibleContentRect(LegacyIOSDocumentVisibleRect).location(); }
ScrollPosition maximumScrollPosition() const override;
ScrollPosition adjustScrollPositionWithinRange(const ScrollPosition&) const;
int scrollX() const { return scrollPosition().x(); }
int scrollY() const { return scrollPosition().y(); }
IntPoint contentsScrollPosition() const;
void setContentsScrollPosition(const IntPoint&);
#if PLATFORM(IOS)
int actualScrollX() const { return unobscuredContentRect().x(); }
int actualScrollY() const { return unobscuredContentRect().y(); }
IntPoint actualScrollPosition() const { return unobscuredContentRect().location(); }
#endif
ScrollPosition documentScrollPositionRelativeToScrollableAreaOrigin() const;
WEBCORE_EXPORT ScrollPosition documentScrollPositionRelativeToViewOrigin() const;
IntSize overhangAmount() const final;
void cacheCurrentScrollPosition() { m_cachedScrollPosition = scrollPosition(); }
ScrollPosition cachedScrollPosition() const { return m_cachedScrollPosition; }
virtual void setScrollPosition(const ScrollPosition&);
void scrollBy(const IntSize& s) { return setScrollPosition(scrollPosition() + s); }
bool scroll(ScrollDirection, ScrollGranularity);
bool logicalScroll(ScrollLogicalDirection, ScrollGranularity);
void scrollContents(const IntSize& scrollDelta);
WEBCORE_EXPORT void setScrollbarsSuppressed(bool suppressed, bool repaintOnUnsuppress = false);
bool scrollbarsSuppressed() const { return m_scrollbarsSuppressed; }
WEBCORE_EXPORT IntPoint rootViewToContents(const IntPoint&) const;
WEBCORE_EXPORT IntPoint contentsToRootView(const IntPoint&) const;
WEBCORE_EXPORT IntRect rootViewToContents(const IntRect&) const;
WEBCORE_EXPORT IntRect contentsToRootView(const IntRect&) const;
IntPoint viewToContents(const IntPoint&) const;
IntPoint contentsToView(const IntPoint&) const;
IntRect viewToContents(IntRect) const;
IntRect contentsToView(IntRect) const;
IntPoint contentsToContainingViewContents(const IntPoint&) const;
IntRect contentsToContainingViewContents(IntRect) const;
WEBCORE_EXPORT IntPoint rootViewToTotalContents(const IntPoint&) const;
WEBCORE_EXPORT IntPoint windowToContents(const IntPoint&) const;
WEBCORE_EXPORT IntPoint contentsToWindow(const IntPoint&) const;
WEBCORE_EXPORT IntRect windowToContents(const IntRect&) const;
WEBCORE_EXPORT IntRect contentsToWindow(const IntRect&) const;
WEBCORE_EXPORT IntRect contentsToScreen(const IntRect&) const;
IntPoint screenToContents(const IntPoint&) const;
bool isOffscreen() const;
void frameRectsChanged() final;
void setFrameRect(const IntRect&) override;
void clipRectChanged() final;
Scrollbar* scrollbarAtPoint(const IntPoint& windowPoint);
IntPoint convertChildToSelf(const Widget* child, const IntPoint& point) const
{
IntPoint newPoint = point;
if (!isScrollViewScrollbar(child))
newPoint = point - toIntSize(scrollPosition());
newPoint.moveBy(child->location());
return newPoint;
}
IntPoint convertSelfToChild(const Widget* child, const IntPoint& point) const
{
IntPoint newPoint = point;
if (!isScrollViewScrollbar(child))
newPoint = point + toIntSize(scrollPosition());
newPoint.moveBy(-child->location());
return newPoint;
}
WEBCORE_EXPORT void paint(GraphicsContext&, const IntRect&, Widget::SecurityOriginPaintPolicy = SecurityOriginPaintPolicy::AnyOrigin) final;
void paintScrollbars(GraphicsContext&, const IntRect&);
WEBCORE_EXPORT void show() override;
WEBCORE_EXPORT void hide() override;
WEBCORE_EXPORT void setParentVisible(bool) final;
static const int noPanScrollRadius = 15;
void addPanScrollIcon(const IntPoint&);
void removePanScrollIcon();
void paintPanScrollIcon(GraphicsContext&);
bool isPointInScrollbarCorner(const IntPoint&);
bool scrollbarCornerPresent() const;
IntRect scrollCornerRect() const final;
virtual void paintScrollCorner(GraphicsContext&, const IntRect& cornerRect);
virtual void paintScrollbar(GraphicsContext&, Scrollbar&, const IntRect&);
IntRect convertFromScrollbarToContainingView(const Scrollbar&, const IntRect&) const final;
IntRect convertFromContainingViewToScrollbar(const Scrollbar&, const IntRect&) const final;
IntPoint convertFromScrollbarToContainingView(const Scrollbar&, const IntPoint&) const final;
IntPoint convertFromContainingViewToScrollbar(const Scrollbar&, const IntPoint&) const final;
void calculateAndPaintOverhangAreas(GraphicsContext&, const IntRect& dirtyRect);
WEBCORE_EXPORT void scrollOffsetChangedViaPlatformWidget(const ScrollOffset& oldOffset, const ScrollOffset& newOffset);
void setAllowsUnclampedScrollPositionForTesting(bool allowsUnclampedScrollPosition) { m_allowsUnclampedScrollPosition = allowsUnclampedScrollPosition; }
bool allowsUnclampedScrollPosition() const { return m_allowsUnclampedScrollPosition; }
protected:
ScrollView();
virtual void repaintContentRectangle(const IntRect&);
virtual void paintContents(GraphicsContext&, const IntRect& damageRect, SecurityOriginPaintPolicy = SecurityOriginPaintPolicy::AnyOrigin) = 0;
virtual void paintOverhangAreas(GraphicsContext&, const IntRect& horizontalOverhangArea, const IntRect& verticalOverhangArea, const IntRect& dirtyRect);
void availableContentSizeChanged(AvailableSizeChangeReason) override;
virtual void addedOrRemovedScrollbar() = 0;
virtual void delegatesScrollingDidChange() = 0;
bool setHasHorizontalScrollbar(bool, bool* contentSizeAffected = nullptr);
bool setHasVerticalScrollbar(bool, bool* contentSizeAffected = nullptr);
virtual void updateScrollCorner() = 0;
void invalidateScrollCornerRect(const IntRect&) final;
virtual bool scrollContentsFastPath(const IntSize& scrollDelta, const IntRect& rectToScroll, const IntRect& clipRect) = 0;
virtual void scrollContentsSlowPath(const IntRect& updateRect);
void setScrollOrigin(const IntPoint&, bool updatePositionAtAll, bool updatePositionSynchronously);
virtual bool isVerticalDocument() const = 0;
virtual bool isFlippedDocument() const = 0;
void updateScrollbars(const ScrollPosition& desiredPosition);
float platformTopContentInset() const;
void platformSetTopContentInset(float);
void handleDeferredScrollUpdateAfterContentSizeChange();
virtual bool shouldDeferScrollUpdateAfterContentSizeChange() = 0;
virtual void scrollOffsetChangedViaPlatformWidgetImpl(const ScrollOffset&, const ScrollOffset&) = 0;
#if PLATFORM(IOS)
virtual void unobscuredContentSizeChanged() = 0;
#endif
private:
IntSize sizeForUnobscuredContent(VisibleContentRectIncludesScrollbars = ExcludeScrollbars) const;
IntRect visibleContentRectInternal(VisibleContentRectIncludesScrollbars, VisibleContentRectBehavior) const final;
WEBCORE_EXPORT IntRect unobscuredContentRectInternal(VisibleContentRectIncludesScrollbars = ExcludeScrollbars) const;
void completeUpdatesAfterScrollTo(const IntSize& scrollDelta);
bool setHasScrollbarInternal(RefPtr<Scrollbar>&, ScrollbarOrientation, bool hasBar, bool* contentSizeAffected);
bool isScrollView() const final { return true; }
HashSet<Ref<Widget>> m_children;
RefPtr<Scrollbar> m_horizontalScrollbar;
RefPtr<Scrollbar> m_verticalScrollbar;
ScrollbarMode m_horizontalScrollbarMode { ScrollbarAuto };
ScrollbarMode m_verticalScrollbarMode { ScrollbarAuto };
#if PLATFORM(IOS)
FloatRect m_exposedContentRect;
FloatSize m_unobscuredContentSize;
#else
IntRect m_fixedVisibleContentRect;
#endif
ScrollPosition m_scrollPosition;
IntPoint m_cachedScrollPosition;
IntSize m_fixedLayoutSize;
IntSize m_contentsSize;
std::optional<IntSize> m_deferredScrollDelta; std::optional<std::pair<ScrollOffset, ScrollOffset>> m_deferredScrollOffsets;
IntPoint m_panScrollIconPoint;
bool m_horizontalScrollbarLock { false };
bool m_verticalScrollbarLock { false };
bool m_prohibitsScrolling { false };
bool m_allowsUnclampedScrollPosition { false };
bool m_canBlitOnScroll { true };
bool m_scrollbarsSuppressed { false };
bool m_inUpdateScrollbars { false };
unsigned m_updateScrollbarsPass { 0 };
bool m_drawPanScrollIcon { false };
bool m_useFixedLayout { false };
bool m_paintsEntireContents { false };
bool m_delegatesScrolling { false };
void init();
void destroy();
IntRect rectToCopyOnScroll() const;
virtual void updateLayerPositionsAfterScrolling() = 0;
virtual void updateCompositingLayersAfterScrolling() = 0;
void platformAddChild(Widget*);
void platformRemoveChild(Widget*);
void platformSetScrollbarModes();
void platformScrollbarModes(ScrollbarMode& horizontal, ScrollbarMode& vertical) const;
void platformSetCanBlitOnScroll(bool);
bool platformCanBlitOnScroll() const;
IntRect platformVisibleContentRect(bool includeScrollbars) const;
IntSize platformVisibleContentSize(bool includeScrollbars) const;
IntRect platformVisibleContentRectIncludingObscuredArea(bool includeScrollbars) const;
IntSize platformVisibleContentSizeIncludingObscuredArea(bool includeScrollbars) const;
void platformSetContentsSize();
IntRect platformContentsToScreen(const IntRect&) const;
IntPoint platformScreenToContents(const IntPoint&) const;
void platformSetScrollPosition(const IntPoint&);
bool platformScroll(ScrollDirection, ScrollGranularity);
void platformSetScrollbarsSuppressed(bool repaintOnUnsuppress);
void platformRepaintContentRectangle(const IntRect&);
bool platformIsOffscreen() const;
void platformSetScrollbarOverlayStyle(ScrollbarOverlayStyle);
void platformSetScrollOrigin(const IntPoint&, bool updatePositionAtAll, bool updatePositionSynchronously);
void calculateOverhangAreasForPainting(IntRect& horizontalOverhangRect, IntRect& verticalOverhangRect);
void updateOverhangAreas();
#if PLATFORM(COCOA) && defined __OBJC__
public:
WEBCORE_EXPORT NSView* documentView() const;
private:
NSScrollView<WebCoreFrameScrollView>* scrollView() const;
#endif
};
}
SPECIALIZE_TYPE_TRAITS_WIDGET(ScrollView, isScrollView())