Bug 1758813 [wpt PR 33142] - Implement RP sign out, a=testonly
[gecko.git] / layout / generic / nsIScrollableFrame.h
bloba69205d12d871d7e0e0012f4aa406b1bcfea9969
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 /*
8 * interface that provides scroll APIs implemented by scrollable frames
9 */
11 #ifndef nsIScrollFrame_h___
12 #define nsIScrollFrame_h___
14 #include "nsCoord.h"
15 #include "mozilla/dom/WindowBinding.h" // for mozilla::dom::ScrollBehavior
16 #include "mozilla/Maybe.h"
17 #include "mozilla/ScrollOrigin.h"
18 #include "mozilla/ScrollPositionUpdate.h"
19 #include "mozilla/ScrollStyles.h"
20 #include "mozilla/ScrollTypes.h"
21 #include "mozilla/gfx/Point.h"
22 #include "nsIScrollbarMediator.h"
23 #include "Units.h"
24 #include "FrameMetrics.h"
26 #define NS_DEFAULT_VERTICAL_SCROLL_DISTANCE 3
27 #define NS_DEFAULT_HORIZONTAL_SCROLL_DISTANCE 5
29 class gfxContext;
30 class nsBoxLayoutState;
31 class nsIScrollPositionListener;
32 class nsIFrame;
33 class nsPresContext;
34 class nsIContent;
36 namespace mozilla {
37 class DisplayItemClip;
38 class nsDisplayListBuilder;
40 namespace layers {
41 struct ScrollMetadata;
42 class Layer;
43 class WebRenderLayerManager;
44 } // namespace layers
45 namespace layout {
46 class ScrollAnchorContainer;
47 } // namespace layout
48 } // namespace mozilla
50 /**
51 * Interface for frames that are scrollable. This interface exposes
52 * APIs for examining scroll state, observing changes to scroll state,
53 * and triggering scrolling.
55 class nsIScrollableFrame : public nsIScrollbarMediator {
56 public:
57 typedef mozilla::CSSIntPoint CSSIntPoint;
58 typedef mozilla::layers::ScrollSnapInfo ScrollSnapInfo;
59 typedef mozilla::layout::ScrollAnchorContainer ScrollAnchorContainer;
60 typedef mozilla::ScrollMode ScrollMode;
61 typedef mozilla::ScrollOrigin ScrollOrigin;
63 NS_DECL_QUERYFRAME_TARGET(nsIScrollableFrame)
65 /**
66 * Get the frame for the content that we are scrolling within
67 * this scrollable frame.
69 virtual nsIFrame* GetScrolledFrame() const = 0;
71 /**
72 * Get the overflow styles (StyleOverflow::Scroll, StyleOverflow::Hidden, or
73 * StyleOverflow::Auto) governing the horizontal and vertical scrollbars for
74 * this frame.
76 * This is special because they can be propagated from the <body> element,
77 * unlike other styles.
79 virtual mozilla::ScrollStyles GetScrollStyles() const = 0;
81 /**
82 * Returns whether this scroll frame is for a text control element with no
83 * scrollbars (for <input>, basically).
85 virtual bool IsForTextControlWithNoScrollbars() const = 0;
87 /**
88 * Returns whether we already have anonymous content nodes for all our needed
89 * scrollbar parts (or a superset thereof).
91 virtual bool HasAllNeededScrollbars() const = 0;
93 /**
94 * Get the overscroll-behavior styles.
96 virtual mozilla::layers::OverscrollBehaviorInfo GetOverscrollBehaviorInfo()
97 const = 0;
99 /**
100 * Return the scrollbars which are visible. It's OK to call this during reflow
101 * of the scrolled contents, in which case it will reflect the current
102 * assumptions about scrollbar visibility.
104 virtual mozilla::layers::ScrollDirections GetScrollbarVisibility() const = 0;
106 * Returns the directions in which scrolling is allowed (if the scroll range
107 * is at least one device pixel in that direction).
109 mozilla::layers::ScrollDirections GetAvailableScrollingDirections() const;
111 * Returns the directions in which scrolling is allowed when taking into
112 * account the visual viewport size and overflow hidden. (An (apz) zoomed in
113 * overflow hidden scrollframe is actually user scrollable.)
115 virtual mozilla::layers::ScrollDirections
116 GetAvailableScrollingDirectionsForUserInputEvents() const = 0;
118 * Return the actual sizes of all possible scrollbars. Returns 0 for scrollbar
119 * positions that don't have a scrollbar or where the scrollbar is not
120 * visible. Do not call this while this frame's descendants are being
121 * reflowed, it won't be accurate.
122 * INCLUDE_VISUAL_VIEWPORT_SCROLLBARS means we include the size of layout
123 * scrollbars that are only visible to scroll the visual viewport inside the
124 * layout viewport (ie the layout viewport cannot be scrolled) even though
125 * there is no layout space set aside for these scrollbars.
127 enum class ScrollbarSizesOptions { NONE, INCLUDE_VISUAL_VIEWPORT_SCROLLBARS };
128 virtual nsMargin GetActualScrollbarSizes(
129 ScrollbarSizesOptions aOptions = ScrollbarSizesOptions::NONE) const = 0;
131 * Return the sizes of all scrollbars assuming that any scrollbars that could
132 * be visible due to overflowing content, are. This can be called during
133 * reflow of the scrolled contents.
135 virtual nsMargin GetDesiredScrollbarSizes(nsBoxLayoutState* aState) = 0;
137 * Return the sizes of all scrollbars assuming that any scrollbars that could
138 * be visible due to overflowing content, are. This can be called during
139 * reflow of the scrolled contents.
141 virtual nsMargin GetDesiredScrollbarSizes(nsPresContext* aPresContext,
142 gfxContext* aRC) = 0;
144 * Return the width for non-disappearing scrollbars.
146 static nscoord GetNondisappearingScrollbarWidth(nsPresContext*,
147 mozilla::WritingMode);
149 * Get the layout size of this frame.
150 * Note that this is a value which is not expanded by the minimum scale size.
151 * For scroll frames other than the root content document's scroll frame, this
152 * value will be the same as GetScrollPortRect().Size().
154 * This value is used for Element.clientWidth and clientHeight.
156 virtual nsSize GetLayoutSize() const = 0;
158 * GetScrolledRect is designed to encapsulate deciding which
159 * directions of overflow should be reachable by scrolling and which
160 * should not. Callers should NOT depend on it having any particular
161 * behavior (although nsXULScrollFrame currently does).
163 * This should only be called when the scrolled frame has been
164 * reflowed with the scroll port size given in mScrollPort.
166 * Currently it allows scrolling down and to the right for
167 * nsHTMLScrollFrames with LTR directionality and for all
168 * nsXULScrollFrames, and allows scrolling down and to the left for
169 * nsHTMLScrollFrames with RTL directionality.
171 virtual nsRect GetScrolledRect() const = 0;
173 * Get the area of the scrollport relative to the origin of this frame's
174 * border-box.
175 * This is the area of this frame minus border and scrollbars.
177 virtual nsRect GetScrollPortRect() const = 0;
179 * Get the offset of the scrollport origin relative to the scrolled
180 * frame origin. Typically the position will be non-negative.
181 * This will always be a multiple of device pixels.
183 virtual nsPoint GetScrollPosition() const = 0;
185 * As GetScrollPosition(), but uses the top-right as origin for RTL frames.
187 virtual nsPoint GetLogicalScrollPosition() const = 0;
190 * Get the area that must contain the scroll position. Typically
191 * (but not always, e.g. for RTL content) x and y will be 0, and
192 * width or height will be nonzero if the content can be scrolled in
193 * that direction. Since scroll positions must be a multiple of
194 * device pixels, the range extrema will also be a multiple of
195 * device pixels.
197 virtual nsRect GetScrollRange() const = 0;
199 * Get the size of the view port to use when clamping the scroll
200 * position.
202 virtual nsSize GetVisualViewportSize() const = 0;
204 * Returns the offset of the visual viewport relative to
205 * the origin of the scrolled content. Note that only the RCD-RSF
206 * has a distinct visual viewport; for other scroll frames, the
207 * visual viewport always coincides with the layout viewport, and
208 * consequently the offset this function returns is equal to
209 * GetScrollPosition().
211 virtual nsPoint GetVisualViewportOffset() const = 0;
213 * Set the visual viewport offset associated with a root scroll frame. This is
214 * only valid when called on a root scroll frame and will assert otherwise.
215 * aRepaint indicates if we need to ask for a main thread paint if this
216 * changes scrollbar positions or not. For example, if the compositor has
217 * already put the scrollbars at this position then they don't need to move so
218 * we can skip the repaint. Returns true if the offset changed and the scroll
219 * frame is still alive after this call.
221 virtual bool SetVisualViewportOffset(const nsPoint& aOffset,
222 bool aRepaint) = 0;
224 * Get the area that must contain the visual viewport offset.
226 virtual nsRect GetVisualScrollRange() const = 0;
228 * Like GetVisualScrollRange but also takes into account overflow: hidden.
230 virtual nsRect GetScrollRangeForUserInputEvents() const = 0;
232 * Return how much we would try to scroll by in each direction if
233 * asked to scroll by one "line" vertically and horizontally.
235 virtual nsSize GetLineScrollAmount() const = 0;
237 * Return how much we would try to scroll by in each direction if
238 * asked to scroll by one "page" vertically and horizontally.
240 virtual nsSize GetPageScrollAmount() const = 0;
243 * Return scroll-padding value of this frame.
245 virtual nsMargin GetScrollPadding() const = 0;
247 * Some platforms (OSX) may generate additional scrolling events even
248 * after the user has stopped scrolling, simulating a momentum scrolling
249 * effect resulting from fling gestures.
250 * SYNTHESIZED_MOMENTUM_EVENT indicates that the scrolling is being requested
251 * by such a synthesized event and may be ignored if another scroll has
252 * been started since the last actual user input.
254 enum ScrollMomentum { NOT_MOMENTUM, SYNTHESIZED_MOMENTUM_EVENT };
256 * @note This method might destroy the frame, pres shell and other objects.
257 * Clamps aScrollPosition to GetScrollRange and sets the scroll position
258 * to that value.
259 * @param aRange If non-null, specifies area which contains aScrollPosition
260 * and can be used for choosing a performance-optimized scroll position.
261 * Any point within this area can be chosen.
262 * The choosen point will be as close as possible to aScrollPosition.
264 virtual void ScrollTo(nsPoint aScrollPosition, ScrollMode aMode,
265 const nsRect* aRange = nullptr,
266 nsIScrollbarMediator::ScrollSnapMode aSnap =
267 nsIScrollbarMediator::DISABLE_SNAP,
268 mozilla::ScrollTriggeredByScript aTriggeredByScript =
269 mozilla::ScrollTriggeredByScript::No) = 0;
271 * @note This method might destroy the frame, pres shell and other objects.
272 * Scrolls to a particular position in integer CSS pixels.
273 * Keeps the exact current horizontal or vertical position if the current
274 * position, rounded to CSS pixels, matches aScrollPosition. If
275 * aScrollPosition.x/y is different from the current CSS pixel position,
276 * makes sure we only move in the direction given by the difference.
278 * When aMode is SMOOTH, INSTANT, or NORMAL, GetScrollPositionCSSPixels (the
279 * scroll position after rounding to CSS pixels) will be exactly
280 * aScrollPosition at the end of the scroll animation.
282 * When aMode is SMOOTH_MSD, intermediate animation frames may be outside the
283 * range and / or moving in any direction; GetScrollPositionCSSPixels will be
284 * exactly aScrollPosition at the end of the scroll animation unless the
285 * SMOOTH_MSD animation is interrupted.
287 virtual void ScrollToCSSPixels(const CSSIntPoint& aScrollPosition,
288 ScrollMode aMode = ScrollMode::Instant) = 0;
290 * @note This method might destroy the frame, pres shell and other objects.
291 * Scrolls to a particular position in float CSS pixels.
292 * This does not guarantee that GetScrollPositionCSSPixels equals
293 * aScrollPosition afterward. It tries to scroll as close to
294 * aScrollPosition as possible while scrolling by an integer
295 * number of layer pixels (so the operation is fast and looks clean).
297 virtual void ScrollToCSSPixelsForApz(
298 const mozilla::CSSPoint& aScrollPosition) = 0;
301 * Returns the scroll position in integer CSS pixels, rounded to the nearest
302 * pixel.
304 virtual CSSIntPoint GetScrollPositionCSSPixels() = 0;
306 * @note This method might destroy the frame, pres shell and other objects.
307 * Modifies the current scroll position by aDelta units given by aUnit,
308 * clamping it to GetScrollRange. If WHOLE is specified as the unit,
309 * content is scrolled all the way in the direction(s) given by aDelta.
310 * @param aOverflow if non-null, returns the amount that scrolling
311 * was clamped by in each direction (how far we moved the scroll position
312 * to bring it back into the legal range). This is never negative. The
313 * values are in device pixels.
315 virtual void ScrollBy(nsIntPoint aDelta, mozilla::ScrollUnit aUnit,
316 ScrollMode aMode, nsIntPoint* aOverflow = nullptr,
317 ScrollOrigin aOrigin = ScrollOrigin::NotSpecified,
318 ScrollMomentum aMomentum = NOT_MOMENTUM,
319 nsIScrollbarMediator::ScrollSnapMode aSnap =
320 nsIScrollbarMediator::DISABLE_SNAP) = 0;
322 virtual void ScrollByCSSPixels(const CSSIntPoint& aDelta,
323 ScrollMode aMode = ScrollMode::Instant) = 0;
326 * Perform scroll snapping, possibly resulting in a smooth scroll to
327 * maintain the scroll snap position constraints. Velocity sampled from
328 * main thread scrolling is used to determine best matching snap point
329 * when called after a fling gesture on a trackpad or mouse wheel.
331 virtual void ScrollSnap() = 0;
334 * @note This method might destroy the frame, pres shell and other objects.
335 * This tells the scroll frame to try scrolling to the scroll
336 * position that was restored from the history. This must be called
337 * at least once after state has been restored. It is called by the
338 * scrolled frame itself during reflow, but sometimes state can be
339 * restored after reflows are done...
340 * XXX should we take an aMode parameter here? Currently it's instant.
342 virtual void ScrollToRestoredPosition() = 0;
345 * Add a scroll position listener. This listener must be removed
346 * before it is destroyed.
348 virtual void AddScrollPositionListener(
349 nsIScrollPositionListener* aListener) = 0;
351 * Remove a scroll position listener.
353 virtual void RemoveScrollPositionListener(
354 nsIScrollPositionListener* aListener) = 0;
357 * Internal method used by scrollbars to notify their scrolling
358 * container of changes.
360 virtual void CurPosAttributeChanged(nsIContent* aChild) = 0;
363 * Allows the docshell to request that the scroll frame post an event
364 * after being restored from history.
366 NS_IMETHOD PostScrolledAreaEventForCurrentArea() = 0;
369 * Returns true if this scrollframe is being "actively scrolled".
370 * This basically means that we should allocate resources in the
371 * expectation that scrolling is going to happen.
373 virtual bool IsScrollingActive() = 0;
376 * Returns true if this scroll frame might be scrolled
377 * asynchronously by the compositor.
379 virtual bool IsMaybeAsynchronouslyScrolled() = 0;
382 * Was the current presentation state for this frame restored from history?
384 virtual bool DidHistoryRestore() const = 0;
386 * Clear the flag so that DidHistoryRestore() returns false until the next
387 * RestoreState call.
388 * @see nsIStatefulFrame::RestoreState
390 virtual void ClearDidHistoryRestore() = 0;
392 * Mark the frame as having been scrolled at least once, so that it remains
393 * active and we can also start storing its scroll position when saving state.
395 virtual void MarkEverScrolled() = 0;
397 * Determine if the passed in rect is nearly visible according to the frame
398 * visibility heuristics for how close it is to the visible scrollport.
400 virtual bool IsRectNearlyVisible(const nsRect& aRect) = 0;
402 * Expand the given rect taking into account which directions we can scroll
403 * and how far we want to expand for frame visibility purposes.
405 virtual nsRect ExpandRectToNearlyVisible(const nsRect& aRect) const = 0;
407 * Returns the origin that triggered the last instant scroll. Will equal
408 * ScrollOrigin::Apz when the compositor's replica frame metrics includes the
409 * latest instant scroll.
411 virtual ScrollOrigin LastScrollOrigin() = 0;
414 * Gets the async scroll animation state of this scroll frame.
416 * There are four possible kinds that can overlap.
417 * MainThread means async scroll animated by the main thread.
418 * APZ scroll animations that are requested from the main thread go through
419 * three states: 1) pending, when the main thread has recorded that it wants
420 * apz to do a scroll animation, 2) requested, when the main thread has sent
421 * the request to the compositor (but it hasn't necessarily arrived yet), and
422 * 3) in progress, after apz has responded to the main thread that it got the
423 * request.
425 enum class AnimationState {
426 MainThread, // mAsyncScroll || mAsyncSmoothMSDScroll
427 APZPending, // mScrollUpdates.LastElement() is Smooth or SmoothMsd
428 APZRequested, // mApzAnimationRequested
429 APZInProgress // mCurrentAPZScrollAnimationType !=
430 // APZScrollAniationType::No
432 virtual mozilla::EnumSet<AnimationState> ScrollAnimationState() const = 0;
435 * Returns the current generation counter for the scrollframe. This counter
436 * increments every time the scroll position is set.
438 virtual mozilla::MainThreadScrollGeneration CurrentScrollGeneration()
439 const = 0;
441 * The APZ scroll generation associated with the last APZ scroll offset for
442 * which we processed a repaint request.
444 virtual mozilla::APZScrollGeneration ScrollGenerationOnApz() const = 0;
446 * LastScrollDestination returns the destination of the most recently
447 * requested smooth scroll animation.
449 virtual nsPoint LastScrollDestination() = 0;
451 * Returns the list of scroll position updates since the last call to
452 * NotifyApzTransaction().
454 virtual nsTArray<mozilla::ScrollPositionUpdate> GetScrollUpdates() const = 0;
456 * Returns true if the scroll frame has any scroll position updates since
457 * the last call to NotifyApzTransaction().
459 virtual bool HasScrollUpdates() const = 0;
461 * Clears the "origin of last scroll" property stored in this frame, if
462 * the generation counter passed in matches the current scroll generation
463 * counter, and clears the "origin of last smooth scroll" property if the
464 * generation counter matches. It also resets whether there's an ongoing apz
465 * animation.
467 virtual void ResetScrollInfoIfNeeded(
468 const mozilla::MainThreadScrollGeneration& aGeneration,
469 const mozilla::APZScrollGeneration& aGenerationOnApz,
470 mozilla::APZScrollAnimationType aAPZScrollAnimationType) = 0;
472 * Determine whether it is desirable to be able to asynchronously scroll this
473 * scroll frame.
475 virtual bool WantAsyncScroll() const = 0;
477 * Returns the ScrollMetadata contributed by this frame, if there is one.
479 virtual mozilla::Maybe<mozilla::layers::ScrollMetadata> ComputeScrollMetadata(
480 mozilla::layers::WebRenderLayerManager* aLayerManager,
481 const nsIFrame* aItemFrame,
482 const nsPoint& aOffsetToReferenceFrame) const = 0;
485 * Mark the scrollbar frames for reflow.
487 virtual void MarkScrollbarsDirtyForReflow() const = 0;
490 * Invalidate the scrollbar after the marks have been changed.
492 virtual void InvalidateScrollbars() const = 0;
494 virtual void UpdateScrollbarPosition() = 0;
496 virtual void SetTransformingByAPZ(bool aTransforming) = 0;
497 virtual bool IsTransformingByAPZ() const = 0;
500 * Notify this scroll frame that it can be scrolled by APZ. In particular,
501 * this is called *after* the APZ code has created an APZC for this scroll
502 * frame and verified that it is not a scrollinfo layer. Therefore, setting an
503 * async transform on it is actually user visible.
505 virtual void SetScrollableByAPZ(bool aScrollable) = 0;
508 * Notify this scroll frame that it can be zoomed by APZ.
510 virtual void SetZoomableByAPZ(bool aZoomable) = 0;
513 * Mark this scroll frame as having out-of-flow content inside a CSS filter.
514 * Such content will move incorrectly during async-scrolling; to mitigate
515 * this, paint skipping is disabled for such scroll frames.
517 virtual void SetHasOutOfFlowContentInsideFilter() = 0;
520 * Determine if we should build a scrollable layer for this scroll frame and
521 * return the result. It will also record this result on the scroll frame.
522 * Pass the visible rect in aVisibleRect. On return it will be set to the
523 * displayport if there is one.
524 * Pass the dirty rect in aDirtyRect. On return it will be set to the
525 * dirty rect inside the displayport (ie the dirty rect that should be used).
526 * This function will set the display port base rect if aSetBase is true.
527 * aSetBase is only allowed to be false if there has been a call with it
528 * set to true before on the same paint.
530 virtual bool DecideScrollableLayer(mozilla::nsDisplayListBuilder* aBuilder,
531 nsRect* aVisibleRect, nsRect* aDirtyRect,
532 bool aSetBase) = 0;
535 * Notify the scrollframe that the current scroll offset and origin have been
536 * sent over in a layers transaction.
538 * This sets a flag on the scrollframe that indicates subsequent changes
539 * to the scroll position by "weaker" origins are permitted to overwrite the
540 * the scroll origin. Scroll origins that
541 * nsLayoutUtils::CanScrollOriginClobberApz returns false for are considered
542 * "weaker" than scroll origins for which that function returns true.
544 * This function must be called for a scrollframe after all calls to
545 * ComputeScrollMetadata in a layers transaction have been completed.
548 virtual void NotifyApzTransaction() = 0;
551 * Notification that this scroll frame is getting its frame visibility
552 * updated. aIgnoreDisplayPort indicates that the display port was ignored
553 * (because there was no suitable base rect)
555 virtual void NotifyApproximateFrameVisibilityUpdate(
556 bool aIgnoreDisplayPort) = 0;
559 * Returns true if this scroll frame had a display port at the last frame
560 * visibility update and fills in aDisplayPort with that displayport. Returns
561 * false otherwise, and doesn't touch aDisplayPort.
563 virtual bool GetDisplayPortAtLastApproximateFrameVisibilityUpdate(
564 nsRect* aDisplayPort) = 0;
567 * This is called when a descendant scrollframe's has its displayport expired.
568 * This function will check to see if this scrollframe may safely expire its
569 * own displayport and schedule a timer to do that if it is safe.
571 virtual void TriggerDisplayPortExpiration() = 0;
574 * Returns information required to determine where to snap to after a scroll.
576 virtual ScrollSnapInfo GetScrollSnapInfo() const = 0;
579 * Given the drag event aEvent, determine whether the mouse is near the edge
580 * of the scrollable area, and scroll the view in the direction of that edge
581 * if so. If scrolling occurred, true is returned. When false is returned, the
582 * caller should look for an ancestor to scroll.
584 virtual bool DragScroll(mozilla::WidgetEvent* aEvent) = 0;
586 virtual void AsyncScrollbarDragInitiated(
587 uint64_t aDragBlockId, mozilla::layers::ScrollDirection aDirection) = 0;
588 virtual void AsyncScrollbarDragRejected() = 0;
591 * Returns whether this scroll frame is the root scroll frame of the document
592 * that it is in. Note that some documents don't have root scroll frames at
593 * all (ie XUL documents) even though they may contain other scroll frames.
595 virtual bool IsRootScrollFrameOfDocument() const = 0;
598 * Returns the scroll anchor associated with this scrollable frame. This is
599 * never null.
601 virtual const ScrollAnchorContainer* Anchor() const = 0;
602 virtual ScrollAnchorContainer* Anchor() = 0;
604 virtual bool SmoothScrollVisual(
605 const nsPoint& aVisualViewportOffset,
606 mozilla::layers::FrameMetrics::ScrollOffsetUpdateType aUpdateType) = 0;
609 * Returns true if this scroll frame should perform smooth scroll with the
610 * given |aBehavior|.
612 virtual bool IsSmoothScroll(mozilla::dom::ScrollBehavior aBehavior =
613 mozilla::dom::ScrollBehavior::Auto) const = 0;
616 #endif