#ifndef ScrollView_h
#define ScrollView_h
#include "platform/PlatformExport.h"
#include "platform/Widget.h"
#include "platform/geometry/IntRect.h"
#include "platform/scroll/ScrollTypes.h"
#include "platform/scroll/ScrollableArea.h"
#include "platform/scroll/Scrollbar.h"
#include "wtf/HashSet.h"
namespace WebCore {
class HostWindow;
class Scrollbar;
class PLATFORM_EXPORT ScrollView : public Widget, public ScrollableArea {
public:
virtual ~ScrollView();
virtual int scrollSize(ScrollbarOrientation) const OVERRIDE;
virtual void setScrollOffset(const IntPoint&) OVERRIDE;
virtual bool isScrollCornerVisible() const OVERRIDE;
virtual void scrollbarStyleChanged(int newStyle, bool forceUpdate) OVERRIDE;
virtual bool userInputScrollable(ScrollbarOrientation) const OVERRIDE;
virtual bool shouldPlaceVerticalScrollbarOnLeft() const OVERRIDE;
virtual void notifyPageThatContentAreaWillPaint() const;
virtual void scrollTo(const IntSize& newOffset);
virtual HostWindow* hostWindow() const = 0;
virtual IntRect windowClipRect(IncludeScrollbarsInRect = ExcludeScrollbars) const = 0;
const HashSet<RefPtr<Widget> >* children() const { return &m_children; }
virtual void addChild(PassRefPtr<Widget>);
virtual void removeChild(Widget*);
virtual Scrollbar* horizontalScrollbar() const OVERRIDE { return m_horizontalScrollbar.get(); }
virtual Scrollbar* verticalScrollbar() const OVERRIDE { return m_verticalScrollbar.get(); }
bool isScrollViewScrollbar(const Widget* child) const { return horizontalScrollbar() == child || verticalScrollbar() == child; }
void positionScrollbarLayers();
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); };
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; }
virtual void setCanHaveScrollbars(bool);
bool canHaveScrollbars() const { return horizontalScrollbarMode() != ScrollbarAlwaysOff || verticalScrollbarMode() != ScrollbarAlwaysOff; }
bool paintsEntireContents() const { return m_paintsEntireContents; }
void setPaintsEntireContents(bool);
bool clipsRepaints() const { return m_clipsRepaints; }
void setClipsRepaints(bool);
virtual PassRefPtr<Scrollbar> createScrollbar(ScrollbarOrientation);
virtual bool shouldAttemptToScrollUsingFastPath() const;
virtual IntRect visibleContentRect(IncludeScrollbarsInRect = ExcludeScrollbars) const OVERRIDE;
IntSize visibleSize() const { return visibleContentRect().size(); }
virtual int visibleWidth() const OVERRIDE { return visibleContentRect().width(); }
virtual int visibleHeight() const OVERRIDE { return visibleContentRect().height(); }
IntSize unscaledVisibleContentSize(IncludeScrollbarsInRect = ExcludeScrollbars) const;
virtual float visibleContentScaleFactor() const { return 1; }
virtual IntSize inputEventsOffsetForEmulation() const { return IntSize(); }
virtual float inputEventsScaleFactor() const { return visibleContentScaleFactor(); }
virtual IntSize contentsSize() const OVERRIDE;
int contentsWidth() const { return contentsSize().width(); }
int contentsHeight() const { return contentsSize().height(); }
virtual void setContentsSize(const IntSize&);
virtual IntPoint scrollPosition() const OVERRIDE { return visibleContentRect().location(); }
IntSize scrollOffset() const { return toIntSize(visibleContentRect().location()); }
IntSize pendingScrollDelta() const { return m_pendingScrollDelta; }
virtual IntPoint maximumScrollPosition() const OVERRIDE;
virtual IntPoint minimumScrollPosition() const OVERRIDE;
IntPoint adjustScrollPositionWithinRange(const IntPoint&) const;
int scrollX() const { return scrollPosition().x(); }
int scrollY() const { return scrollPosition().y(); }
virtual IntSize overhangAmount() const OVERRIDE;
void cacheCurrentScrollPosition() { m_cachedScrollPosition = scrollPosition(); }
IntPoint cachedScrollPosition() const { return m_cachedScrollPosition; }
virtual void setScrollPosition(const IntPoint&);
void scrollBy(const IntSize& s) { return setScrollPosition(scrollPosition() + s); }
bool scroll(ScrollDirection, ScrollGranularity);
void scrollContents(const IntSize& scrollDelta);
void setScrollbarsSuppressed(bool suppressed, bool repaintOnUnsuppress = false);
bool scrollbarsSuppressed() const { return m_scrollbarsSuppressed; }
IntPoint rootViewToContents(const IntPoint&) const;
IntPoint contentsToRootView(const IntPoint&) const;
IntRect rootViewToContents(const IntRect&) const;
IntRect contentsToRootView(const IntRect&) const;
IntPoint windowToContents(const IntPoint&) const;
IntPoint contentsToWindow(const IntPoint&) const;
IntRect windowToContents(const IntRect&) const;
IntRect contentsToWindow(const IntRect&) const;
IntRect contentsToScreen(const IntRect&) const;
virtual IntRect windowResizerRect() const { return IntRect(); }
bool containsScrollbarsAvoidingResizer() const;
void adjustScrollbarsAvoidingResizerCount(int overlapDelta);
void windowResizerRectChanged();
virtual void setParent(Widget*) OVERRIDE;
virtual void frameRectsChanged() OVERRIDE;
virtual void setFrameRect(const IntRect&) OVERRIDE;
Scrollbar* scrollbarAtPoint(const IntPoint& windowPoint);
virtual IntPoint convertChildToSelf(const Widget* child, const IntPoint& point) const OVERRIDE
{
IntPoint newPoint = point;
if (!isScrollViewScrollbar(child))
newPoint = point - scrollOffset();
newPoint.moveBy(child->location());
return newPoint;
}
virtual IntPoint convertSelfToChild(const Widget* child, const IntPoint& point) const OVERRIDE
{
IntPoint newPoint = point;
if (!isScrollViewScrollbar(child))
newPoint = point + scrollOffset();
newPoint.moveBy(-child->location());
return newPoint;
}
virtual void paint(GraphicsContext*, const IntRect&) OVERRIDE;
void paintScrollbars(GraphicsContext*, const IntRect&);
virtual void show() OVERRIDE;
virtual void hide() OVERRIDE;
virtual void setParentVisible(bool) OVERRIDE;
static const int noPanScrollRadius = 15;
void addPanScrollIcon(const IntPoint&);
void removePanScrollIcon();
void paintPanScrollIcon(GraphicsContext*);
virtual bool isPointInScrollbarCorner(const IntPoint&);
virtual bool scrollbarCornerPresent() const;
virtual IntRect scrollCornerRect() const OVERRIDE;
virtual void paintScrollCorner(GraphicsContext*, const IntRect& cornerRect);
virtual void paintScrollbar(GraphicsContext*, Scrollbar*, const IntRect&);
virtual IntRect convertFromScrollbarToContainingView(const Scrollbar*, const IntRect&) const OVERRIDE;
virtual IntRect convertFromContainingViewToScrollbar(const Scrollbar*, const IntRect&) const OVERRIDE;
virtual IntPoint convertFromScrollbarToContainingView(const Scrollbar*, const IntPoint&) const OVERRIDE;
virtual IntPoint convertFromContainingViewToScrollbar(const Scrollbar*, const IntPoint&) const OVERRIDE;
void calculateAndPaintOverhangAreas(GraphicsContext*, const IntRect& dirtyRect);
void calculateAndPaintOverhangBackground(GraphicsContext*, const IntRect& dirtyRect);
virtual bool isScrollView() const OVERRIDE FINAL { return true; }
protected:
ScrollView();
virtual void repaintContentRectangle(const IntRect&);
virtual void paintContents(GraphicsContext*, const IntRect& damageRect) = 0;
virtual void paintOverhangAreas(GraphicsContext*, const IntRect& horizontalOverhangArea, const IntRect& verticalOverhangArea, const IntRect& dirtyRect);
virtual void scrollbarExistenceDidChange() = 0;
void setHasHorizontalScrollbar(bool);
void setHasVerticalScrollbar(bool);
virtual void updateScrollCorner();
virtual void invalidateScrollCornerRect(const IntRect&) OVERRIDE;
virtual void scrollContentsIfNeeded();
virtual bool scrollContentsFastPath(const IntSize& scrollDelta, const IntRect& rectToScroll, const IntRect& clipRect);
virtual void scrollContentsSlowPath(const IntRect& updateRect);
void setScrollOrigin(const IntPoint&, bool updatePositionAtAll, bool updatePositionSynchronously);
virtual bool isVerticalDocument() const { return true; }
virtual bool isFlippedDocument() const { return false; }
void updateScrollbars(const IntSize& desiredOffset);
IntSize excludeScrollbars(const IntSize&) const;
private:
RefPtr<Scrollbar> m_horizontalScrollbar;
RefPtr<Scrollbar> m_verticalScrollbar;
ScrollbarMode m_horizontalScrollbarMode;
ScrollbarMode m_verticalScrollbarMode;
bool m_horizontalScrollbarLock;
bool m_verticalScrollbarLock;
HashSet<RefPtr<Widget> > m_children;
IntSize m_pendingScrollDelta;
IntSize m_scrollOffset;
IntPoint m_cachedScrollPosition;
IntSize m_contentsSize;
int m_scrollbarsAvoidingResizer;
bool m_scrollbarsSuppressed;
bool m_inUpdateScrollbars;
unsigned m_updateScrollbarsPass;
IntPoint m_panScrollIconPoint;
bool m_drawPanScrollIcon;
bool m_paintsEntireContents;
bool m_clipsRepaints;
void init();
void destroy();
IntRect rectToCopyOnScroll() const;
void calculateOverhangAreasForPainting(IntRect& horizontalOverhangRect, IntRect& verticalOverhangRect);
void updateOverhangAreas();
};
DEFINE_TYPE_CASTS(ScrollView, Widget, widget, widget->isScrollView(), widget.isScrollView());
}
#endif