Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 /*
7 * interface that provides scroll APIs implemented by scrollable frames
8 */
10 #ifndef nsIScrollFrame_h___
11 #define nsIScrollFrame_h___
13 #include "nsCoord.h"
14 #include "ScrollbarStyles.h"
15 #include "mozilla/gfx/Point.h"
16 #include "nsIScrollbarOwner.h"
17 #include "Units.h"
19 #define NS_DEFAULT_VERTICAL_SCROLL_DISTANCE 3
20 #define NS_DEFAULT_HORIZONTAL_SCROLL_DISTANCE 5
22 class nsBoxLayoutState;
23 class nsIScrollPositionListener;
24 class nsIFrame;
25 class nsPresContext;
26 class nsIContent;
27 class nsRenderingContext;
28 class nsIAtom;
30 /**
31 * Interface for frames that are scrollable. This interface exposes
32 * APIs for examining scroll state, observing changes to scroll state,
33 * and triggering scrolling.
34 */
35 class nsIScrollableFrame : public nsIScrollbarOwner {
36 public:
37 typedef mozilla::CSSIntPoint CSSIntPoint;
39 NS_DECL_QUERYFRAME_TARGET(nsIScrollableFrame)
41 /**
42 * Get the frame for the content that we are scrolling within
43 * this scrollable frame.
44 */
45 virtual nsIFrame* GetScrolledFrame() const = 0;
47 /**
48 * Get the styles (NS_STYLE_OVERFLOW_SCROLL, NS_STYLE_OVERFLOW_HIDDEN,
49 * or NS_STYLE_OVERFLOW_AUTO) governing the horizontal and vertical
50 * scrollbars for this frame.
51 */
52 virtual mozilla::ScrollbarStyles GetScrollbarStyles() const = 0;
54 enum { HORIZONTAL = 0x01, VERTICAL = 0x02 };
55 /**
56 * Return the scrollbars which are visible. It's OK to call this during reflow
57 * of the scrolled contents, in which case it will reflect the current
58 * assumptions about scrollbar visibility.
59 */
60 virtual uint32_t GetScrollbarVisibility() const = 0;
61 /**
62 * Returns the directions in which scrolling is perceived to be allowed.
63 * A direction is perceived to be allowed if there is a visible scrollbar
64 * for that direction or if the scroll range is at least one device pixel.
65 */
66 uint32_t GetPerceivedScrollingDirections() const;
67 /**
68 * Return the actual sizes of all possible scrollbars. Returns 0 for scrollbar
69 * positions that don't have a scrollbar or where the scrollbar is not visible.
70 * Do not call this while this frame's descendants are being reflowed, it won't be
71 * accurate.
72 */
73 virtual nsMargin GetActualScrollbarSizes() const = 0;
74 /**
75 * Return the sizes of all scrollbars assuming that any scrollbars that could
76 * be visible due to overflowing content, are. This can be called during reflow
77 * of the scrolled contents.
78 */
79 virtual nsMargin GetDesiredScrollbarSizes(nsBoxLayoutState* aState) = 0;
80 /**
81 * Return the sizes of all scrollbars assuming that any scrollbars that could
82 * be visible due to overflowing content, are. This can be called during reflow
83 * of the scrolled contents.
84 */
85 virtual nsMargin GetDesiredScrollbarSizes(nsPresContext* aPresContext,
86 nsRenderingContext* aRC) = 0;
87 /**
88 * Return the width for non-disappearing scrollbars.
89 */
90 virtual nscoord GetNondisappearingScrollbarWidth(nsPresContext* aPresContext,
91 nsRenderingContext* aRC) = 0;
92 /**
93 * GetScrolledRect is designed to encapsulate deciding which
94 * directions of overflow should be reachable by scrolling and which
95 * should not. Callers should NOT depend on it having any particular
96 * behavior (although nsXULScrollFrame currently does).
97 *
98 * This should only be called when the scrolled frame has been
99 * reflowed with the scroll port size given in mScrollPort.
100 *
101 * Currently it allows scrolling down and to the right for
102 * nsHTMLScrollFrames with LTR directionality and for all
103 * nsXULScrollFrames, and allows scrolling down and to the left for
104 * nsHTMLScrollFrames with RTL directionality.
105 */
106 virtual nsRect GetScrolledRect() const = 0;
107 /**
108 * Get the area of the scrollport relative to the origin of this frame's
109 * border-box.
110 * This is the area of this frame minus border and scrollbars.
111 */
112 virtual nsRect GetScrollPortRect() const = 0;
113 /**
114 * Get the offset of the scrollport origin relative to the scrolled
115 * frame origin. Typically the position will be non-negative.
116 * This will always be a multiple of device pixels.
117 */
118 virtual nsPoint GetScrollPosition() const = 0;
119 /**
120 * As GetScrollPosition(), but uses the top-right as origin for RTL frames.
121 */
122 virtual nsPoint GetLogicalScrollPosition() const = 0;
123 /**
124 * Get the area that must contain the scroll position. Typically
125 * (but not always, e.g. for RTL content) x and y will be 0, and
126 * width or height will be nonzero if the content can be scrolled in
127 * that direction. Since scroll positions must be a multiple of
128 * device pixels, the range extrema will also be a multiple of
129 * device pixels.
130 */
131 virtual nsRect GetScrollRange() const = 0;
132 /**
133 * Get the size of the scroll port to use when clamping the scroll
134 * position.
135 */
136 virtual nsSize GetScrollPositionClampingScrollPortSize() const = 0;
137 /**
138 * Get the element resolution.
139 */
140 virtual gfxSize GetResolution() const = 0;
141 /**
142 * Set the element resolution.
143 */
144 virtual void SetResolution(const gfxSize& aResolution) = 0;
145 /**
146 * Return how much we would try to scroll by in each direction if
147 * asked to scroll by one "line" vertically and horizontally.
148 */
149 virtual nsSize GetLineScrollAmount() const = 0;
150 /**
151 * Return how much we would try to scroll by in each direction if
152 * asked to scroll by one "page" vertically and horizontally.
153 */
154 virtual nsSize GetPageScrollAmount() const = 0;
156 /**
157 * When a scroll operation is requested, we ask for instant, smooth or normal
158 * scrolling. SMOOTH will only be smooth if smooth scrolling is actually
159 * enabled. INSTANT is always synchronous, NORMAL can be asynchronous.
160 * If an INSTANT request happens while a smooth or async scroll is already in
161 * progress, the async scroll is interrupted and we instantly scroll to the
162 * destination.
163 */
164 enum ScrollMode { INSTANT, SMOOTH, NORMAL };
165 /**
166 * @note This method might destroy the frame, pres shell and other objects.
167 * Clamps aScrollPosition to GetScrollRange and sets the scroll position
168 * to that value.
169 * @param aRange If non-null, specifies area which contains aScrollPosition
170 * and can be used for choosing a performance-optimized scroll position.
171 * Any point within this area can be chosen.
172 * The choosen point will be as close as possible to aScrollPosition.
173 */
174 virtual void ScrollTo(nsPoint aScrollPosition, ScrollMode aMode,
175 const nsRect* aRange = nullptr) = 0;
176 /**
177 * @note This method might destroy the frame, pres shell and other objects.
178 * Scrolls to a particular position in integer CSS pixels.
179 * Keeps the exact current horizontal or vertical position if the current
180 * position, rounded to CSS pixels, matches aScrollPosition. If
181 * aScrollPosition.x/y is different from the current CSS pixel position,
182 * makes sure we only move in the direction given by the difference.
183 * Ensures that GetScrollPositionCSSPixels (the scroll position after
184 * rounding to CSS pixels) will be exactly aScrollPosition.
185 * The scroll mode is INSTANT.
186 */
187 virtual void ScrollToCSSPixels(const CSSIntPoint& aScrollPosition) = 0;
188 /**
189 * @note This method might destroy the frame, pres shell and other objects.
190 * Scrolls to a particular position in float CSS pixels.
191 * This does not guarantee that GetScrollPositionCSSPixels equals
192 * aScrollPosition afterward. It tries to scroll as close to
193 * aScrollPosition as possible while scrolling by an integer
194 * number of layer pixels (so the operation is fast and looks clean).
195 * The scroll mode is INSTANT.
196 */
197 virtual void ScrollToCSSPixelsApproximate(const mozilla::CSSPoint& aScrollPosition,
198 nsIAtom *aOrigin = nullptr) = 0;
200 /**
201 * Returns the scroll position in integer CSS pixels, rounded to the nearest
202 * pixel.
203 */
204 virtual CSSIntPoint GetScrollPositionCSSPixels() = 0;
205 /**
206 * When scrolling by a relative amount, we can choose various units.
207 */
208 enum ScrollUnit { DEVICE_PIXELS, LINES, PAGES, WHOLE };
209 /**
210 * @note This method might destroy the frame, pres shell and other objects.
211 * Modifies the current scroll position by aDelta units given by aUnit,
212 * clamping it to GetScrollRange. If WHOLE is specified as the unit,
213 * content is scrolled all the way in the direction(s) given by aDelta.
214 * @param aOverflow if non-null, returns the amount that scrolling
215 * was clamped by in each direction (how far we moved the scroll position
216 * to bring it back into the legal range). This is never negative. The
217 * values are in device pixels.
218 */
219 virtual void ScrollBy(nsIntPoint aDelta, ScrollUnit aUnit, ScrollMode aMode,
220 nsIntPoint* aOverflow = nullptr, nsIAtom *aOrigin = nullptr) = 0;
221 /**
222 * @note This method might destroy the frame, pres shell and other objects.
223 * This tells the scroll frame to try scrolling to the scroll
224 * position that was restored from the history. This must be called
225 * at least once after state has been restored. It is called by the
226 * scrolled frame itself during reflow, but sometimes state can be
227 * restored after reflows are done...
228 * XXX should we take an aMode parameter here? Currently it's instant.
229 */
230 virtual void ScrollToRestoredPosition() = 0;
232 /**
233 * Add a scroll position listener. This listener must be removed
234 * before it is destroyed.
235 */
236 virtual void AddScrollPositionListener(nsIScrollPositionListener* aListener) = 0;
237 /**
238 * Remove a scroll position listener.
239 */
240 virtual void RemoveScrollPositionListener(nsIScrollPositionListener* aListener) = 0;
242 /**
243 * Internal method used by scrollbars to notify their scrolling
244 * container of changes.
245 */
246 virtual void CurPosAttributeChanged(nsIContent* aChild) = 0;
248 /**
249 * Allows the docshell to request that the scroll frame post an event
250 * after being restored from history.
251 */
252 NS_IMETHOD PostScrolledAreaEventForCurrentArea() = 0;
254 /**
255 * Returns true if this scrollframe is being "actively scrolled".
256 * This basically means that we should allocate resources in the
257 * expectation that scrolling is going to happen.
258 */
259 virtual bool IsScrollingActive() = 0;
260 /**
261 * Returns true if the scrollframe is currently processing an async
262 * or smooth scroll.
263 */
264 virtual bool IsProcessingAsyncScroll() = 0;
265 /**
266 * Call this when the layer(s) induced by active scrolling are being
267 * completely redrawn.
268 */
269 virtual void ResetScrollPositionForLayerPixelAlignment() = 0;
270 /**
271 * Was the current presentation state for this frame restored from history?
272 */
273 virtual bool DidHistoryRestore() const = 0;
274 /**
275 * Was the current resolution set by the user or just default initialized?
276 */
277 virtual bool IsResolutionSet() const = 0;
278 /**
279 * Clear the flag so that DidHistoryRestore() returns false until the next
280 * RestoreState call.
281 * @see nsIStatefulFrame::RestoreState
282 */
283 virtual void ClearDidHistoryRestore() = 0;
284 /**
285 * Determine if the passed in rect is nearly visible according to the image
286 * visibility heuristics for how close it is to the visible scrollport.
287 */
288 virtual bool IsRectNearlyVisible(const nsRect& aRect) = 0;
289 /**
290 * Returns the origin passed in to the last ScrollToImpl call that took
291 * effect.
292 */
293 virtual nsIAtom* OriginOfLastScroll() = 0;
294 /**
295 * Returns the current generation counter for the scroll. This counter
296 * increments every time the scroll position is set.
297 */
298 virtual uint32_t CurrentScrollGeneration() = 0;
299 /**
300 * Clears the "origin of last scroll" property stored in this frame, if
301 * the generation counter passed in matches the current scroll generation
302 * counter.
303 */
304 virtual void ResetOriginIfScrollAtGeneration(uint32_t aGeneration) = 0;
305 /**
306 * Determine whether it is desirable to be able to asynchronously scroll this
307 * scroll frame.
308 */
309 virtual bool WantAsyncScroll() const = 0;
310 };
312 #endif