| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 2004, 2006, 2007, 2008 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 COMPUTER, 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 COMPUTER, 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 #ifndef ScrollView_h | |
| 28 #define ScrollView_h | |
| 29 | |
| 30 #include "core/platform/ScrollableArea.h" | |
| 31 #include "core/platform/Scrollbar.h" | |
| 32 #include "platform/Widget.h" | |
| 33 #include "platform/geometry/IntRect.h" | |
| 34 #include "platform/scroll/ScrollTypes.h" | |
| 35 | |
| 36 #include "wtf/HashSet.h" | |
| 37 | |
| 38 namespace WebCore { | |
| 39 | |
| 40 class HostWindow; | |
| 41 class Scrollbar; | |
| 42 | |
| 43 class ScrollView : public Widget, public ScrollableArea { | |
| 44 public: | |
| 45 ~ScrollView(); | |
| 46 | |
| 47 // ScrollableArea functions. | |
| 48 virtual int scrollSize(ScrollbarOrientation) const OVERRIDE; | |
| 49 virtual void setScrollOffset(const IntPoint&) OVERRIDE; | |
| 50 virtual bool isScrollCornerVisible() const OVERRIDE; | |
| 51 virtual void scrollbarStyleChanged(int newStyle, bool forceUpdate) OVERRIDE; | |
| 52 virtual bool userInputScrollable(ScrollbarOrientation) const OVERRIDE; | |
| 53 virtual bool shouldPlaceVerticalScrollbarOnLeft() const OVERRIDE; | |
| 54 | |
| 55 virtual void notifyPageThatContentAreaWillPaint() const; | |
| 56 | |
| 57 // NOTE: This should only be called by the overriden setScrollOffset from Sc
rollableArea. | |
| 58 virtual void scrollTo(const IntSize& newOffset); | |
| 59 | |
| 60 // The window thats hosts the ScrollView. The ScrollView will communicate sc
rolls and repaints to the | |
| 61 // host window in the window's coordinate space. | |
| 62 virtual HostWindow* hostWindow() const = 0; | |
| 63 | |
| 64 // Returns a clip rect in host window coordinates. Used to clip the blit on
a scroll. | |
| 65 virtual IntRect windowClipRect(bool clipToContents = true) const = 0; | |
| 66 | |
| 67 // Functions for child manipulation and inspection. | |
| 68 const HashSet<RefPtr<Widget> >* children() const { return &m_children; } | |
| 69 virtual void addChild(PassRefPtr<Widget>); | |
| 70 virtual void removeChild(Widget*); | |
| 71 | |
| 72 // If the scroll view does not use a native widget, then it will have cross-
platform Scrollbars. These functions | |
| 73 // can be used to obtain those scrollbars. | |
| 74 virtual Scrollbar* horizontalScrollbar() const OVERRIDE { return m_horizonta
lScrollbar.get(); } | |
| 75 virtual Scrollbar* verticalScrollbar() const OVERRIDE { return m_verticalScr
ollbar.get(); } | |
| 76 bool isScrollViewScrollbar(const Widget* child) const { return horizontalScr
ollbar() == child || verticalScrollbar() == child; } | |
| 77 | |
| 78 void positionScrollbarLayers(); | |
| 79 | |
| 80 // Functions for setting and retrieving the scrolling mode in each axis (hor
izontal/vertical). The mode has values of | |
| 81 // AlwaysOff, AlwaysOn, and Auto. AlwaysOff means never show a scrollbar, Al
waysOn means always show a scrollbar. | |
| 82 // Auto means show a scrollbar only when one is needed. | |
| 83 // Note that for platforms with native widgets, these modes are considered a
dvisory. In other words the underlying native | |
| 84 // widget may choose not to honor the requested modes. | |
| 85 void setScrollbarModes(ScrollbarMode horizontalMode, ScrollbarMode verticalM
ode, bool horizontalLock = false, bool verticalLock = false); | |
| 86 void setHorizontalScrollbarMode(ScrollbarMode mode, bool lock = false) { set
ScrollbarModes(mode, verticalScrollbarMode(), lock, verticalScrollbarLock()); } | |
| 87 void setVerticalScrollbarMode(ScrollbarMode mode, bool lock = false) { setSc
rollbarModes(horizontalScrollbarMode(), mode, horizontalScrollbarLock(), lock);
}; | |
| 88 void scrollbarModes(ScrollbarMode& horizontalMode, ScrollbarMode& verticalMo
de) const; | |
| 89 ScrollbarMode horizontalScrollbarMode() const { ScrollbarMode horizontal, ve
rtical; scrollbarModes(horizontal, vertical); return horizontal; } | |
| 90 ScrollbarMode verticalScrollbarMode() const { ScrollbarMode horizontal, vert
ical; scrollbarModes(horizontal, vertical); return vertical; } | |
| 91 | |
| 92 void setHorizontalScrollbarLock(bool lock = true) { m_horizontalScrollbarLoc
k = lock; } | |
| 93 bool horizontalScrollbarLock() const { return m_horizontalScrollbarLock; } | |
| 94 void setVerticalScrollbarLock(bool lock = true) { m_verticalScrollbarLock =
lock; } | |
| 95 bool verticalScrollbarLock() const { return m_verticalScrollbarLock; } | |
| 96 | |
| 97 void setScrollingModesLock(bool lock = true) { m_horizontalScrollbarLock = m
_verticalScrollbarLock = lock; } | |
| 98 | |
| 99 virtual void setCanHaveScrollbars(bool); | |
| 100 bool canHaveScrollbars() const { return horizontalScrollbarMode() != Scrollb
arAlwaysOff || verticalScrollbarMode() != ScrollbarAlwaysOff; } | |
| 101 | |
| 102 // By default you only receive paint events for the area that is visible. In
the case of using a | |
| 103 // tiled backing store, this function can be set, so that the view paints th
e entire contents. | |
| 104 bool paintsEntireContents() const { return m_paintsEntireContents; } | |
| 105 void setPaintsEntireContents(bool); | |
| 106 | |
| 107 // By default, paint events are clipped to the visible area. If set to | |
| 108 // false, paint events are no longer clipped. paintsEntireContents() implie
s !clipsRepaints(). | |
| 109 bool clipsRepaints() const { return m_clipsRepaints; } | |
| 110 void setClipsRepaints(bool); | |
| 111 | |
| 112 // Overridden by FrameView to create custom CSS scrollbars if applicable. | |
| 113 virtual PassRefPtr<Scrollbar> createScrollbar(ScrollbarOrientation); | |
| 114 | |
| 115 // Whether or not a scroll view will blit visible contents when it is scroll
ed. Blitting is disabled in situations | |
| 116 // where it would cause rendering glitches (such as with fixed backgrounds o
r when the view is partially transparent). | |
| 117 void setCanBlitOnScroll(bool); | |
| 118 bool canBlitOnScroll() const; | |
| 119 | |
| 120 // The visible content rect has a location that is the scrolled offset of th
e document. The width and height are the viewport width | |
| 121 // and height. By default the scrollbars themselves are excluded from this r
ectangle, but an optional boolean argument allows them to be | |
| 122 // included. | |
| 123 virtual IntRect visibleContentRect(IncludeScrollbarsInRect = ExcludeScrollba
rs) const OVERRIDE; | |
| 124 IntSize visibleSize() const { return visibleContentRect().size(); } | |
| 125 virtual int visibleWidth() const OVERRIDE { return visibleContentRect().widt
h(); } | |
| 126 virtual int visibleHeight() const OVERRIDE { return visibleContentRect().hei
ght(); } | |
| 127 | |
| 128 // visibleContentRect().size() is computed from unscaledVisibleContentSize()
divided by the value of visibleContentScaleFactor. | |
| 129 // For the main frame, visibleContentScaleFactor is equal to the page's page
ScaleFactor; it's 1 otherwise. | |
| 130 IntSize unscaledVisibleContentSize(IncludeScrollbarsInRect = ExcludeScrollba
rs) const; | |
| 131 virtual float visibleContentScaleFactor() const { return 1; } | |
| 132 | |
| 133 // Offset used to convert incoming input events while emulating device metic
s. | |
| 134 virtual IntSize inputEventsOffsetForEmulation() const { return IntSize(); } | |
| 135 | |
| 136 // Scale used to convert incoming input events. Usually the same as visibleC
ontentScaleFactor(), unless specifically changed. | |
| 137 virtual float inputEventsScaleFactor() const { return visibleContentScaleFac
tor(); } | |
| 138 | |
| 139 // Functions for getting/setting the size of the document contained inside t
he ScrollView (as an IntSize or as individual width and height | |
| 140 // values). | |
| 141 virtual IntSize contentsSize() const OVERRIDE; // Always at least as big as
the visibleWidth()/visibleHeight(). | |
| 142 int contentsWidth() const { return contentsSize().width(); } | |
| 143 int contentsHeight() const { return contentsSize().height(); } | |
| 144 virtual void setContentsSize(const IntSize&); | |
| 145 | |
| 146 // Functions for querying the current scrolled position (both as a point, a
size, or as individual X and Y values). | |
| 147 virtual IntPoint scrollPosition() const OVERRIDE { return visibleContentRect
().location(); } | |
| 148 IntSize scrollOffset() const { return toIntSize(visibleContentRect().locatio
n()); } // Gets the scrolled position as an IntSize. Convenient for adding to ot
her sizes. | |
| 149 virtual IntPoint maximumScrollPosition() const OVERRIDE; // The maximum posi
tion we can be scrolled to. | |
| 150 virtual IntPoint minimumScrollPosition() const OVERRIDE; // The minimum posi
tion we can be scrolled to. | |
| 151 // Adjust the passed in scroll position to keep it between the minimum and m
aximum positions. | |
| 152 IntPoint adjustScrollPositionWithinRange(const IntPoint&) const; | |
| 153 int scrollX() const { return scrollPosition().x(); } | |
| 154 int scrollY() const { return scrollPosition().y(); } | |
| 155 | |
| 156 virtual IntSize overhangAmount() const OVERRIDE; | |
| 157 | |
| 158 void cacheCurrentScrollPosition() { m_cachedScrollPosition = scrollPosition(
); } | |
| 159 IntPoint cachedScrollPosition() const { return m_cachedScrollPosition; } | |
| 160 | |
| 161 // Functions for scrolling the view. | |
| 162 virtual void setScrollPosition(const IntPoint&); | |
| 163 void scrollBy(const IntSize& s) { return setScrollPosition(scrollPosition()
+ s); } | |
| 164 | |
| 165 // A logical scroll that just ends up calling the corresponding physical scr
oll() based off the document's writing mode. | |
| 166 bool logicalScroll(ScrollLogicalDirection, ScrollGranularity); | |
| 167 | |
| 168 // Scroll the actual contents of the view (either blitting or invalidating a
s needed). | |
| 169 void scrollContents(const IntSize& scrollDelta); | |
| 170 | |
| 171 // This gives us a means of blocking painting on our scrollbars until the fi
rst layout has occurred. | |
| 172 void setScrollbarsSuppressed(bool suppressed, bool repaintOnUnsuppress = fal
se); | |
| 173 bool scrollbarsSuppressed() const { return m_scrollbarsSuppressed; } | |
| 174 | |
| 175 IntPoint rootViewToContents(const IntPoint&) const; | |
| 176 IntPoint contentsToRootView(const IntPoint&) const; | |
| 177 IntRect rootViewToContents(const IntRect&) const; | |
| 178 IntRect contentsToRootView(const IntRect&) const; | |
| 179 | |
| 180 // Event coordinates are assumed to be in the coordinate space of a window t
hat contains | |
| 181 // the entire widget hierarchy. It is up to the platform to decide what the
precise definition | |
| 182 // of containing window is. (For example on Mac it is the containing NSWindo
w.) | |
| 183 IntPoint windowToContents(const IntPoint&) const; | |
| 184 IntPoint contentsToWindow(const IntPoint&) const; | |
| 185 IntRect windowToContents(const IntRect&) const; | |
| 186 IntRect contentsToWindow(const IntRect&) const; | |
| 187 | |
| 188 // Functions for converting to and from screen coordinates. | |
| 189 IntRect contentsToScreen(const IntRect&) const; | |
| 190 IntPoint screenToContents(const IntPoint&) const; | |
| 191 | |
| 192 // 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 | |
| 193 // we know that we are either not in a window right now or if that window is
not visible. | |
| 194 bool isOffscreen() const; | |
| 195 | |
| 196 // These functions are used to enable scrollbars to avoid window resizer con
trols that overlap the scroll view. This happens on Mac | |
| 197 // for example. | |
| 198 virtual IntRect windowResizerRect() const { return IntRect(); } | |
| 199 bool containsScrollbarsAvoidingResizer() const; | |
| 200 void adjustScrollbarsAvoidingResizerCount(int overlapDelta); | |
| 201 void windowResizerRectChanged(); | |
| 202 | |
| 203 virtual void setParent(Widget*) OVERRIDE; // Overridden to update the overla
pping scrollbar count. | |
| 204 | |
| 205 // Called when our frame rect changes (or the rect/scroll position of an anc
estor changes). | |
| 206 virtual void frameRectsChanged(); | |
| 207 | |
| 208 // Widget override to update our scrollbars and notify our contents of the r
esize. | |
| 209 virtual void setFrameRect(const IntRect&); | |
| 210 | |
| 211 // Widget override to notify our contents of a cliprect change. | |
| 212 virtual void clipRectChanged() OVERRIDE; | |
| 213 | |
| 214 // For platforms that need to hit test scrollbars from within the engine's e
vent handlers (like Win32). | |
| 215 Scrollbar* scrollbarAtPoint(const IntPoint& windowPoint); | |
| 216 | |
| 217 virtual IntPoint convertChildToSelf(const Widget* child, const IntPoint& poi
nt) const | |
| 218 { | |
| 219 IntPoint newPoint = point; | |
| 220 if (!isScrollViewScrollbar(child)) | |
| 221 newPoint = point - scrollOffset(); | |
| 222 newPoint.moveBy(child->location()); | |
| 223 return newPoint; | |
| 224 } | |
| 225 | |
| 226 virtual IntPoint convertSelfToChild(const Widget* child, const IntPoint& poi
nt) const | |
| 227 { | |
| 228 IntPoint newPoint = point; | |
| 229 if (!isScrollViewScrollbar(child)) | |
| 230 newPoint = point + scrollOffset(); | |
| 231 newPoint.moveBy(-child->location()); | |
| 232 return newPoint; | |
| 233 } | |
| 234 | |
| 235 // Widget override. Handles painting of the contents of the view as well as
the scrollbars. | |
| 236 virtual void paint(GraphicsContext*, const IntRect&); | |
| 237 void paintScrollbars(GraphicsContext*, const IntRect&); | |
| 238 | |
| 239 // Widget overrides to ensure that our children's visibility status is kept
up to date when we get shown and hidden. | |
| 240 virtual void show(); | |
| 241 virtual void hide(); | |
| 242 virtual void setParentVisible(bool); | |
| 243 | |
| 244 // Pan scrolling. | |
| 245 static const int noPanScrollRadius = 15; | |
| 246 void addPanScrollIcon(const IntPoint&); | |
| 247 void removePanScrollIcon(); | |
| 248 void paintPanScrollIcon(GraphicsContext*); | |
| 249 | |
| 250 virtual bool isPointInScrollbarCorner(const IntPoint&); | |
| 251 virtual bool scrollbarCornerPresent() const; | |
| 252 virtual IntRect scrollCornerRect() const; | |
| 253 virtual void paintScrollCorner(GraphicsContext*, const IntRect& cornerRect); | |
| 254 virtual void paintScrollbar(GraphicsContext*, Scrollbar*, const IntRect&); | |
| 255 | |
| 256 virtual IntRect convertFromScrollbarToContainingView(const Scrollbar*, const
IntRect&) const OVERRIDE; | |
| 257 virtual IntRect convertFromContainingViewToScrollbar(const Scrollbar*, const
IntRect&) const OVERRIDE; | |
| 258 virtual IntPoint convertFromScrollbarToContainingView(const Scrollbar*, cons
t IntPoint&) const OVERRIDE; | |
| 259 virtual IntPoint convertFromContainingViewToScrollbar(const Scrollbar*, cons
t IntPoint&) const OVERRIDE; | |
| 260 | |
| 261 void calculateAndPaintOverhangAreas(GraphicsContext*, const IntRect& dirtyRe
ct); | |
| 262 void calculateAndPaintOverhangBackground(GraphicsContext*, const IntRect& di
rtyRect); | |
| 263 | |
| 264 virtual bool isScrollView() const OVERRIDE { return true; } | |
| 265 | |
| 266 protected: | |
| 267 ScrollView(); | |
| 268 | |
| 269 virtual void repaintContentRectangle(const IntRect&); | |
| 270 virtual void paintContents(GraphicsContext*, const IntRect& damageRect) = 0; | |
| 271 | |
| 272 virtual void paintOverhangAreas(GraphicsContext*, const IntRect& horizontalO
verhangArea, const IntRect& verticalOverhangArea, const IntRect& dirtyRect); | |
| 273 | |
| 274 virtual void scrollbarExistenceDidChange() = 0; | |
| 275 // These functions are used to create/destroy scrollbars. | |
| 276 void setHasHorizontalScrollbar(bool); | |
| 277 void setHasVerticalScrollbar(bool); | |
| 278 | |
| 279 virtual void updateScrollCorner(); | |
| 280 virtual void invalidateScrollCornerRect(const IntRect&) OVERRIDE; | |
| 281 | |
| 282 // Scroll the content by blitting the pixels. | |
| 283 virtual bool scrollContentsFastPath(const IntSize& scrollDelta, const IntRec
t& rectToScroll, const IntRect& clipRect); | |
| 284 // Scroll the content by invalidating everything. | |
| 285 virtual void scrollContentsSlowPath(const IntRect& updateRect); | |
| 286 | |
| 287 void setScrollOrigin(const IntPoint&, bool updatePositionAtAll, bool updateP
ositionSynchronously); | |
| 288 | |
| 289 // Subclassed by FrameView to check the writing-mode of the document. | |
| 290 virtual bool isVerticalDocument() const { return true; } | |
| 291 virtual bool isFlippedDocument() const { return false; } | |
| 292 | |
| 293 // Called to update the scrollbars to accurately reflect the state of the vi
ew. | |
| 294 void updateScrollbars(const IntSize& desiredOffset); | |
| 295 | |
| 296 IntSize excludeScrollbars(const IntSize&) const; | |
| 297 | |
| 298 private: | |
| 299 RefPtr<Scrollbar> m_horizontalScrollbar; | |
| 300 RefPtr<Scrollbar> m_verticalScrollbar; | |
| 301 ScrollbarMode m_horizontalScrollbarMode; | |
| 302 ScrollbarMode m_verticalScrollbarMode; | |
| 303 | |
| 304 bool m_horizontalScrollbarLock; | |
| 305 bool m_verticalScrollbarLock; | |
| 306 | |
| 307 HashSet<RefPtr<Widget> > m_children; | |
| 308 | |
| 309 // This bool is unused on Mac OS because we directly ask the platform widget | |
| 310 // whether it is safe to blit on scroll. | |
| 311 bool m_canBlitOnScroll; | |
| 312 | |
| 313 IntSize m_scrollOffset; // FIXME: Would rather store this as a position, but
we will wait to make this change until more code is shared. | |
| 314 IntPoint m_cachedScrollPosition; | |
| 315 IntSize m_contentsSize; | |
| 316 | |
| 317 int m_scrollbarsAvoidingResizer; | |
| 318 bool m_scrollbarsSuppressed; | |
| 319 | |
| 320 bool m_inUpdateScrollbars; | |
| 321 unsigned m_updateScrollbarsPass; | |
| 322 | |
| 323 IntPoint m_panScrollIconPoint; | |
| 324 bool m_drawPanScrollIcon; | |
| 325 | |
| 326 bool m_paintsEntireContents; | |
| 327 bool m_clipsRepaints; | |
| 328 | |
| 329 void init(); | |
| 330 void destroy(); | |
| 331 | |
| 332 IntRect rectToCopyOnScroll() const; | |
| 333 | |
| 334 // Called when the scroll position within this view changes. FrameView over
rides this to generate repaint invalidations. | |
| 335 virtual void repaintFixedElementsAfterScrolling() { } | |
| 336 virtual void updateFixedElementsAfterScrolling() { } | |
| 337 | |
| 338 void calculateOverhangAreasForPainting(IntRect& horizontalOverhangRect, IntR
ect& verticalOverhangRect); | |
| 339 void updateOverhangAreas(); | |
| 340 | |
| 341 int pageStep(ScrollbarOrientation) const; | |
| 342 }; // class ScrollView | |
| 343 | |
| 344 inline ScrollView* toScrollView(Widget* widget) | |
| 345 { | |
| 346 ASSERT_WITH_SECURITY_IMPLICATION(!widget || widget->isScrollView()); | |
| 347 return static_cast<ScrollView*>(widget); | |
| 348 } | |
| 349 | |
| 350 inline const ScrollView* toScrollView(const Widget* widget) | |
| 351 { | |
| 352 ASSERT_WITH_SECURITY_IMPLICATION(!widget || widget->isScrollView()); | |
| 353 return static_cast<const ScrollView*>(widget); | |
| 354 } | |
| 355 | |
| 356 // This will catch anyone doing an unnecessary cast. | |
| 357 void toScrollView(const ScrollView*); | |
| 358 | |
| 359 } // namespace WebCore | |
| 360 | |
| 361 #endif // ScrollView_h | |
| OLD | NEW |