michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* michael@0: * interface that provides scroll APIs implemented by scrollable frames michael@0: */ michael@0: michael@0: #ifndef nsIScrollFrame_h___ michael@0: #define nsIScrollFrame_h___ michael@0: michael@0: #include "nsCoord.h" michael@0: #include "ScrollbarStyles.h" michael@0: #include "mozilla/gfx/Point.h" michael@0: #include "nsIScrollbarOwner.h" michael@0: #include "Units.h" michael@0: michael@0: #define NS_DEFAULT_VERTICAL_SCROLL_DISTANCE 3 michael@0: #define NS_DEFAULT_HORIZONTAL_SCROLL_DISTANCE 5 michael@0: michael@0: class nsBoxLayoutState; michael@0: class nsIScrollPositionListener; michael@0: class nsIFrame; michael@0: class nsPresContext; michael@0: class nsIContent; michael@0: class nsRenderingContext; michael@0: class nsIAtom; michael@0: michael@0: /** michael@0: * Interface for frames that are scrollable. This interface exposes michael@0: * APIs for examining scroll state, observing changes to scroll state, michael@0: * and triggering scrolling. michael@0: */ michael@0: class nsIScrollableFrame : public nsIScrollbarOwner { michael@0: public: michael@0: typedef mozilla::CSSIntPoint CSSIntPoint; michael@0: michael@0: NS_DECL_QUERYFRAME_TARGET(nsIScrollableFrame) michael@0: michael@0: /** michael@0: * Get the frame for the content that we are scrolling within michael@0: * this scrollable frame. michael@0: */ michael@0: virtual nsIFrame* GetScrolledFrame() const = 0; michael@0: michael@0: /** michael@0: * Get the styles (NS_STYLE_OVERFLOW_SCROLL, NS_STYLE_OVERFLOW_HIDDEN, michael@0: * or NS_STYLE_OVERFLOW_AUTO) governing the horizontal and vertical michael@0: * scrollbars for this frame. michael@0: */ michael@0: virtual mozilla::ScrollbarStyles GetScrollbarStyles() const = 0; michael@0: michael@0: enum { HORIZONTAL = 0x01, VERTICAL = 0x02 }; michael@0: /** michael@0: * Return the scrollbars which are visible. It's OK to call this during reflow michael@0: * of the scrolled contents, in which case it will reflect the current michael@0: * assumptions about scrollbar visibility. michael@0: */ michael@0: virtual uint32_t GetScrollbarVisibility() const = 0; michael@0: /** michael@0: * Returns the directions in which scrolling is perceived to be allowed. michael@0: * A direction is perceived to be allowed if there is a visible scrollbar michael@0: * for that direction or if the scroll range is at least one device pixel. michael@0: */ michael@0: uint32_t GetPerceivedScrollingDirections() const; michael@0: /** michael@0: * Return the actual sizes of all possible scrollbars. Returns 0 for scrollbar michael@0: * positions that don't have a scrollbar or where the scrollbar is not visible. michael@0: * Do not call this while this frame's descendants are being reflowed, it won't be michael@0: * accurate. michael@0: */ michael@0: virtual nsMargin GetActualScrollbarSizes() const = 0; michael@0: /** michael@0: * Return the sizes of all scrollbars assuming that any scrollbars that could michael@0: * be visible due to overflowing content, are. This can be called during reflow michael@0: * of the scrolled contents. michael@0: */ michael@0: virtual nsMargin GetDesiredScrollbarSizes(nsBoxLayoutState* aState) = 0; michael@0: /** michael@0: * Return the sizes of all scrollbars assuming that any scrollbars that could michael@0: * be visible due to overflowing content, are. This can be called during reflow michael@0: * of the scrolled contents. michael@0: */ michael@0: virtual nsMargin GetDesiredScrollbarSizes(nsPresContext* aPresContext, michael@0: nsRenderingContext* aRC) = 0; michael@0: /** michael@0: * Return the width for non-disappearing scrollbars. michael@0: */ michael@0: virtual nscoord GetNondisappearingScrollbarWidth(nsPresContext* aPresContext, michael@0: nsRenderingContext* aRC) = 0; michael@0: /** michael@0: * GetScrolledRect is designed to encapsulate deciding which michael@0: * directions of overflow should be reachable by scrolling and which michael@0: * should not. Callers should NOT depend on it having any particular michael@0: * behavior (although nsXULScrollFrame currently does). michael@0: * michael@0: * This should only be called when the scrolled frame has been michael@0: * reflowed with the scroll port size given in mScrollPort. michael@0: * michael@0: * Currently it allows scrolling down and to the right for michael@0: * nsHTMLScrollFrames with LTR directionality and for all michael@0: * nsXULScrollFrames, and allows scrolling down and to the left for michael@0: * nsHTMLScrollFrames with RTL directionality. michael@0: */ michael@0: virtual nsRect GetScrolledRect() const = 0; michael@0: /** michael@0: * Get the area of the scrollport relative to the origin of this frame's michael@0: * border-box. michael@0: * This is the area of this frame minus border and scrollbars. michael@0: */ michael@0: virtual nsRect GetScrollPortRect() const = 0; michael@0: /** michael@0: * Get the offset of the scrollport origin relative to the scrolled michael@0: * frame origin. Typically the position will be non-negative. michael@0: * This will always be a multiple of device pixels. michael@0: */ michael@0: virtual nsPoint GetScrollPosition() const = 0; michael@0: /** michael@0: * As GetScrollPosition(), but uses the top-right as origin for RTL frames. michael@0: */ michael@0: virtual nsPoint GetLogicalScrollPosition() const = 0; michael@0: /** michael@0: * Get the area that must contain the scroll position. Typically michael@0: * (but not always, e.g. for RTL content) x and y will be 0, and michael@0: * width or height will be nonzero if the content can be scrolled in michael@0: * that direction. Since scroll positions must be a multiple of michael@0: * device pixels, the range extrema will also be a multiple of michael@0: * device pixels. michael@0: */ michael@0: virtual nsRect GetScrollRange() const = 0; michael@0: /** michael@0: * Get the size of the scroll port to use when clamping the scroll michael@0: * position. michael@0: */ michael@0: virtual nsSize GetScrollPositionClampingScrollPortSize() const = 0; michael@0: /** michael@0: * Get the element resolution. michael@0: */ michael@0: virtual gfxSize GetResolution() const = 0; michael@0: /** michael@0: * Set the element resolution. michael@0: */ michael@0: virtual void SetResolution(const gfxSize& aResolution) = 0; michael@0: /** michael@0: * Return how much we would try to scroll by in each direction if michael@0: * asked to scroll by one "line" vertically and horizontally. michael@0: */ michael@0: virtual nsSize GetLineScrollAmount() const = 0; michael@0: /** michael@0: * Return how much we would try to scroll by in each direction if michael@0: * asked to scroll by one "page" vertically and horizontally. michael@0: */ michael@0: virtual nsSize GetPageScrollAmount() const = 0; michael@0: michael@0: /** michael@0: * When a scroll operation is requested, we ask for instant, smooth or normal michael@0: * scrolling. SMOOTH will only be smooth if smooth scrolling is actually michael@0: * enabled. INSTANT is always synchronous, NORMAL can be asynchronous. michael@0: * If an INSTANT request happens while a smooth or async scroll is already in michael@0: * progress, the async scroll is interrupted and we instantly scroll to the michael@0: * destination. michael@0: */ michael@0: enum ScrollMode { INSTANT, SMOOTH, NORMAL }; michael@0: /** michael@0: * @note This method might destroy the frame, pres shell and other objects. michael@0: * Clamps aScrollPosition to GetScrollRange and sets the scroll position michael@0: * to that value. michael@0: * @param aRange If non-null, specifies area which contains aScrollPosition michael@0: * and can be used for choosing a performance-optimized scroll position. michael@0: * Any point within this area can be chosen. michael@0: * The choosen point will be as close as possible to aScrollPosition. michael@0: */ michael@0: virtual void ScrollTo(nsPoint aScrollPosition, ScrollMode aMode, michael@0: const nsRect* aRange = nullptr) = 0; michael@0: /** michael@0: * @note This method might destroy the frame, pres shell and other objects. michael@0: * Scrolls to a particular position in integer CSS pixels. michael@0: * Keeps the exact current horizontal or vertical position if the current michael@0: * position, rounded to CSS pixels, matches aScrollPosition. If michael@0: * aScrollPosition.x/y is different from the current CSS pixel position, michael@0: * makes sure we only move in the direction given by the difference. michael@0: * Ensures that GetScrollPositionCSSPixels (the scroll position after michael@0: * rounding to CSS pixels) will be exactly aScrollPosition. michael@0: * The scroll mode is INSTANT. michael@0: */ michael@0: virtual void ScrollToCSSPixels(const CSSIntPoint& aScrollPosition) = 0; michael@0: /** michael@0: * @note This method might destroy the frame, pres shell and other objects. michael@0: * Scrolls to a particular position in float CSS pixels. michael@0: * This does not guarantee that GetScrollPositionCSSPixels equals michael@0: * aScrollPosition afterward. It tries to scroll as close to michael@0: * aScrollPosition as possible while scrolling by an integer michael@0: * number of layer pixels (so the operation is fast and looks clean). michael@0: * The scroll mode is INSTANT. michael@0: */ michael@0: virtual void ScrollToCSSPixelsApproximate(const mozilla::CSSPoint& aScrollPosition, michael@0: nsIAtom *aOrigin = nullptr) = 0; michael@0: michael@0: /** michael@0: * Returns the scroll position in integer CSS pixels, rounded to the nearest michael@0: * pixel. michael@0: */ michael@0: virtual CSSIntPoint GetScrollPositionCSSPixels() = 0; michael@0: /** michael@0: * When scrolling by a relative amount, we can choose various units. michael@0: */ michael@0: enum ScrollUnit { DEVICE_PIXELS, LINES, PAGES, WHOLE }; michael@0: /** michael@0: * @note This method might destroy the frame, pres shell and other objects. michael@0: * Modifies the current scroll position by aDelta units given by aUnit, michael@0: * clamping it to GetScrollRange. If WHOLE is specified as the unit, michael@0: * content is scrolled all the way in the direction(s) given by aDelta. michael@0: * @param aOverflow if non-null, returns the amount that scrolling michael@0: * was clamped by in each direction (how far we moved the scroll position michael@0: * to bring it back into the legal range). This is never negative. The michael@0: * values are in device pixels. michael@0: */ michael@0: virtual void ScrollBy(nsIntPoint aDelta, ScrollUnit aUnit, ScrollMode aMode, michael@0: nsIntPoint* aOverflow = nullptr, nsIAtom *aOrigin = nullptr) = 0; michael@0: /** michael@0: * @note This method might destroy the frame, pres shell and other objects. michael@0: * This tells the scroll frame to try scrolling to the scroll michael@0: * position that was restored from the history. This must be called michael@0: * at least once after state has been restored. It is called by the michael@0: * scrolled frame itself during reflow, but sometimes state can be michael@0: * restored after reflows are done... michael@0: * XXX should we take an aMode parameter here? Currently it's instant. michael@0: */ michael@0: virtual void ScrollToRestoredPosition() = 0; michael@0: michael@0: /** michael@0: * Add a scroll position listener. This listener must be removed michael@0: * before it is destroyed. michael@0: */ michael@0: virtual void AddScrollPositionListener(nsIScrollPositionListener* aListener) = 0; michael@0: /** michael@0: * Remove a scroll position listener. michael@0: */ michael@0: virtual void RemoveScrollPositionListener(nsIScrollPositionListener* aListener) = 0; michael@0: michael@0: /** michael@0: * Internal method used by scrollbars to notify their scrolling michael@0: * container of changes. michael@0: */ michael@0: virtual void CurPosAttributeChanged(nsIContent* aChild) = 0; michael@0: michael@0: /** michael@0: * Allows the docshell to request that the scroll frame post an event michael@0: * after being restored from history. michael@0: */ michael@0: NS_IMETHOD PostScrolledAreaEventForCurrentArea() = 0; michael@0: michael@0: /** michael@0: * Returns true if this scrollframe is being "actively scrolled". michael@0: * This basically means that we should allocate resources in the michael@0: * expectation that scrolling is going to happen. michael@0: */ michael@0: virtual bool IsScrollingActive() = 0; michael@0: /** michael@0: * Returns true if the scrollframe is currently processing an async michael@0: * or smooth scroll. michael@0: */ michael@0: virtual bool IsProcessingAsyncScroll() = 0; michael@0: /** michael@0: * Call this when the layer(s) induced by active scrolling are being michael@0: * completely redrawn. michael@0: */ michael@0: virtual void ResetScrollPositionForLayerPixelAlignment() = 0; michael@0: /** michael@0: * Was the current presentation state for this frame restored from history? michael@0: */ michael@0: virtual bool DidHistoryRestore() const = 0; michael@0: /** michael@0: * Was the current resolution set by the user or just default initialized? michael@0: */ michael@0: virtual bool IsResolutionSet() const = 0; michael@0: /** michael@0: * Clear the flag so that DidHistoryRestore() returns false until the next michael@0: * RestoreState call. michael@0: * @see nsIStatefulFrame::RestoreState michael@0: */ michael@0: virtual void ClearDidHistoryRestore() = 0; michael@0: /** michael@0: * Determine if the passed in rect is nearly visible according to the image michael@0: * visibility heuristics for how close it is to the visible scrollport. michael@0: */ michael@0: virtual bool IsRectNearlyVisible(const nsRect& aRect) = 0; michael@0: /** michael@0: * Returns the origin passed in to the last ScrollToImpl call that took michael@0: * effect. michael@0: */ michael@0: virtual nsIAtom* OriginOfLastScroll() = 0; michael@0: /** michael@0: * Returns the current generation counter for the scroll. This counter michael@0: * increments every time the scroll position is set. michael@0: */ michael@0: virtual uint32_t CurrentScrollGeneration() = 0; michael@0: /** michael@0: * Clears the "origin of last scroll" property stored in this frame, if michael@0: * the generation counter passed in matches the current scroll generation michael@0: * counter. michael@0: */ michael@0: virtual void ResetOriginIfScrollAtGeneration(uint32_t aGeneration) = 0; michael@0: /** michael@0: * Determine whether it is desirable to be able to asynchronously scroll this michael@0: * scroll frame. michael@0: */ michael@0: virtual bool WantAsyncScroll() const = 0; michael@0: }; michael@0: michael@0: #endif