Bumping manifests a=b2g-bump
[gecko.git] / layout / generic / nsGfxScrollFrame.h
blobdeafbab502ca0db82ffdf4e27dcebe657c51bea2
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 /* rendering object to wrap rendering objects that should be scrollable */
8 #ifndef nsGfxScrollFrame_h___
9 #define nsGfxScrollFrame_h___
11 #include "mozilla/Attributes.h"
12 #include "nsContainerFrame.h"
13 #include "nsIAnonymousContentCreator.h"
14 #include "nsBoxFrame.h"
15 #include "nsIScrollableFrame.h"
16 #include "nsIScrollbarMediator.h"
17 #include "nsIStatefulFrame.h"
18 #include "nsThreadUtils.h"
19 #include "nsIReflowCallback.h"
20 #include "nsBoxLayoutState.h"
21 #include "nsQueryFrame.h"
22 #include "nsExpirationTracker.h"
23 #include "TextOverflow.h"
25 class nsPresContext;
26 class nsIPresShell;
27 class nsIContent;
28 class nsIAtom;
29 class nsIScrollFrameInternal;
30 class nsPresState;
31 class nsIScrollPositionListener;
32 struct ScrollReflowState;
34 namespace mozilla {
35 namespace layers {
36 class Layer;
38 namespace layout {
39 class ScrollbarActivity;
43 namespace mozilla {
45 class ScrollFrameHelper : public nsIReflowCallback {
46 public:
47 typedef nsIFrame::Sides Sides;
48 typedef mozilla::CSSIntPoint CSSIntPoint;
49 typedef mozilla::layout::ScrollbarActivity ScrollbarActivity;
50 typedef mozilla::layers::FrameMetrics FrameMetrics;
51 typedef mozilla::layers::Layer Layer;
53 class AsyncScroll;
54 class AsyncSmoothMSDScroll;
56 ScrollFrameHelper(nsContainerFrame* aOuter, bool aIsRoot);
57 ~ScrollFrameHelper();
59 mozilla::ScrollbarStyles GetScrollbarStylesFromFrame() const;
61 // If a child frame was added or removed on the scrollframe,
62 // reload our child frame list.
63 // We need this if a scrollbar frame is recreated.
64 void ReloadChildFrames();
66 nsresult CreateAnonymousContent(
67 nsTArray<nsIAnonymousContentCreator::ContentInfo>& aElements);
68 void AppendAnonymousContentTo(nsTArray<nsIContent*>& aElements, uint32_t aFilter);
69 nsresult FireScrollPortEvent();
70 void PostOverflowEvent();
71 void Destroy();
73 void BuildDisplayList(nsDisplayListBuilder* aBuilder,
74 const nsRect& aDirtyRect,
75 const nsDisplayListSet& aLists);
77 void AppendScrollPartsTo(nsDisplayListBuilder* aBuilder,
78 const nsRect& aDirtyRect,
79 const nsDisplayListSet& aLists,
80 bool aUsingDisplayPort,
81 bool aCreateLayer,
82 bool aPositioned);
84 bool GetBorderRadii(const nsSize& aFrameSize, const nsSize& aBorderArea,
85 Sides aSkipSides, nscoord aRadii[8]) const;
87 // nsIReflowCallback
88 virtual bool ReflowFinished() MOZ_OVERRIDE;
89 virtual void ReflowCallbackCanceled() MOZ_OVERRIDE;
91 /**
92 * @note This method might destroy the frame, pres shell and other objects.
93 * Called when the 'curpos' attribute on one of the scrollbars changes.
95 void CurPosAttributeChanged(nsIContent* aChild);
97 void PostScrollEvent();
98 void FireScrollEvent();
99 void PostScrolledAreaEvent();
100 void FireScrolledAreaEvent();
102 bool IsSmoothScrollingEnabled();
104 class ScrollEvent : public nsRunnable {
105 public:
106 NS_DECL_NSIRUNNABLE
107 explicit ScrollEvent(ScrollFrameHelper *helper) : mHelper(helper) {}
108 void Revoke() { mHelper = nullptr; }
109 private:
110 ScrollFrameHelper *mHelper;
113 class AsyncScrollPortEvent : public nsRunnable {
114 public:
115 NS_DECL_NSIRUNNABLE
116 explicit AsyncScrollPortEvent(ScrollFrameHelper *helper) : mHelper(helper) {}
117 void Revoke() { mHelper = nullptr; }
118 private:
119 ScrollFrameHelper *mHelper;
122 class ScrolledAreaEvent : public nsRunnable {
123 public:
124 NS_DECL_NSIRUNNABLE
125 explicit ScrolledAreaEvent(ScrollFrameHelper *helper) : mHelper(helper) {}
126 void Revoke() { mHelper = nullptr; }
127 private:
128 ScrollFrameHelper *mHelper;
132 * @note This method might destroy the frame, pres shell and other objects.
134 void FinishReflowForScrollbar(nsIContent* aContent, nscoord aMinXY,
135 nscoord aMaxXY, nscoord aCurPosXY,
136 nscoord aPageIncrement,
137 nscoord aIncrement);
139 * @note This method might destroy the frame, pres shell and other objects.
141 void SetScrollbarEnabled(nsIContent* aContent, nscoord aMaxPos);
143 * @note This method might destroy the frame, pres shell and other objects.
145 void SetCoordAttribute(nsIContent* aContent, nsIAtom* aAtom, nscoord aSize);
147 nscoord GetCoordAttribute(nsIFrame* aFrame, nsIAtom* aAtom, nscoord aDefaultValue,
148 nscoord* aRangeStart, nscoord* aRangeLength);
151 * @note This method might destroy the frame, pres shell and other objects.
152 * Update scrollbar curpos attributes to reflect current scroll position
154 void UpdateScrollbarPosition();
156 nsRect GetScrollPortRect() const { return mScrollPort; }
157 nsPoint GetScrollPosition() const {
158 return mScrollPort.TopLeft() - mScrolledFrame->GetPosition();
161 * For LTR frames, the logical scroll position is the offset of the top left
162 * corner of the frame from the top left corner of the scroll port (same as
163 * GetScrollPosition).
164 * For RTL frames, it is the offset of the top right corner of the frame from
165 * the top right corner of the scroll port
167 nsPoint GetLogicalScrollPosition() const {
168 nsPoint pt;
169 pt.x = IsLTR() ?
170 mScrollPort.x - mScrolledFrame->GetPosition().x :
171 mScrollPort.XMost() - mScrolledFrame->GetRect().XMost();
172 pt.y = mScrollPort.y - mScrolledFrame->GetPosition().y;
173 return pt;
175 nsRect GetScrollRange() const;
176 // Get the scroll range assuming the scrollport has size (aWidth, aHeight).
177 nsRect GetScrollRange(nscoord aWidth, nscoord aHeight) const;
178 nsSize GetScrollPositionClampingScrollPortSize() const;
179 gfxSize GetResolution() const;
180 void SetResolution(const gfxSize& aResolution);
181 void SetResolutionAndScaleTo(const gfxSize& aResolution);
183 protected:
184 nsRect GetScrollRangeForClamping() const;
186 public:
187 static void AsyncScrollCallback(ScrollFrameHelper* aInstance,
188 mozilla::TimeStamp aTime);
189 static void AsyncSmoothMSDScrollCallback(ScrollFrameHelper* aInstance,
190 mozilla::TimeDuration aDeltaTime);
192 * @note This method might destroy the frame, pres shell and other objects.
193 * aRange is the range of allowable scroll positions around the desired
194 * aScrollPosition. Null means only aScrollPosition is allowed.
195 * This is a closed-ended range --- aRange.XMost()/aRange.YMost() are allowed.
197 void ScrollTo(nsPoint aScrollPosition, nsIScrollableFrame::ScrollMode aMode,
198 const nsRect* aRange = nullptr) {
199 ScrollToWithOrigin(aScrollPosition, aMode, nsGkAtoms::other, aRange);
202 * @note This method might destroy the frame, pres shell and other objects.
204 void ScrollToCSSPixels(const CSSIntPoint& aScrollPosition,
205 nsIScrollableFrame::ScrollMode aMode
206 = nsIScrollableFrame::INSTANT);
208 * @note This method might destroy the frame, pres shell and other objects.
210 void ScrollToCSSPixelsApproximate(const mozilla::CSSPoint& aScrollPosition,
211 nsIAtom* aOrigin = nullptr);
213 CSSIntPoint GetScrollPositionCSSPixels();
215 * @note This method might destroy the frame, pres shell and other objects.
217 void ScrollToImpl(nsPoint aScrollPosition, const nsRect& aRange, nsIAtom* aOrigin = nullptr);
218 void ScrollVisual(nsPoint aOldScrolledFramePosition);
220 * @note This method might destroy the frame, pres shell and other objects.
222 void ScrollBy(nsIntPoint aDelta, nsIScrollableFrame::ScrollUnit aUnit,
223 nsIScrollableFrame::ScrollMode aMode, nsIntPoint* aOverflow,
224 nsIAtom* aOrigin = nullptr, bool aIsMomentum = false);
226 * @note This method might destroy the frame, pres shell and other objects.
228 void ScrollToRestoredPosition();
230 nsSize GetLineScrollAmount() const;
231 nsSize GetPageScrollAmount() const;
233 nsPresState* SaveState() const;
234 void RestoreState(nsPresState* aState);
236 nsIFrame* GetScrolledFrame() const { return mScrolledFrame; }
237 nsIFrame* GetScrollbarBox(bool aVertical) const {
238 return aVertical ? mVScrollbarBox : mHScrollbarBox;
241 void AddScrollPositionListener(nsIScrollPositionListener* aListener) {
242 mListeners.AppendElement(aListener);
244 void RemoveScrollPositionListener(nsIScrollPositionListener* aListener) {
245 mListeners.RemoveElement(aListener);
248 static void SetScrollbarVisibility(nsIFrame* aScrollbar, bool aVisible);
251 * GetScrolledRect is designed to encapsulate deciding which
252 * directions of overflow should be reachable by scrolling and which
253 * should not. Callers should NOT depend on it having any particular
254 * behavior (although nsXULScrollFrame currently does).
256 * This should only be called when the scrolled frame has been
257 * reflowed with the scroll port size given in mScrollPort.
259 * Currently it allows scrolling down and to the right for
260 * nsHTMLScrollFrames with LTR directionality and for all
261 * nsXULScrollFrames, and allows scrolling down and to the left for
262 * nsHTMLScrollFrames with RTL directionality.
264 nsRect GetScrolledRect() const;
267 * GetScrolledRectInternal is designed to encapsulate deciding which
268 * directions of overflow should be reachable by scrolling and which
269 * should not. Callers should NOT depend on it having any particular
270 * behavior (although nsXULScrollFrame currently does).
272 * Currently it allows scrolling down and to the right for
273 * nsHTMLScrollFrames with LTR directionality and for all
274 * nsXULScrollFrames, and allows scrolling down and to the left for
275 * nsHTMLScrollFrames with RTL directionality.
277 nsRect GetScrolledRectInternal(const nsRect& aScrolledOverflowArea,
278 const nsSize& aScrollPortSize) const;
280 uint32_t GetScrollbarVisibility() const {
281 return (mHasVerticalScrollbar ? nsIScrollableFrame::VERTICAL : 0) |
282 (mHasHorizontalScrollbar ? nsIScrollableFrame::HORIZONTAL : 0);
284 nsMargin GetActualScrollbarSizes() const;
285 nsMargin GetDesiredScrollbarSizes(nsBoxLayoutState* aState);
286 nscoord GetNondisappearingScrollbarWidth(nsBoxLayoutState* aState);
287 bool IsLTR() const;
288 bool IsScrollbarOnRight() const;
289 bool IsScrollingActive(nsDisplayListBuilder* aBuilder) const;
290 bool IsMaybeScrollingActive() const;
291 bool IsProcessingAsyncScroll() const {
292 return mAsyncScroll != nullptr || mAsyncSmoothMSDScroll != nullptr;
294 void ResetScrollPositionForLayerPixelAlignment()
296 mScrollPosForLayerPixelAlignment = GetScrollPosition();
299 bool UpdateOverflow();
301 void UpdateSticky();
303 void UpdatePrevScrolledRect();
305 bool IsRectNearlyVisible(const nsRect& aRect) const;
306 nsRect ExpandRectToNearlyVisible(const nsRect& aRect) const;
308 // adjust the scrollbar rectangle aRect to account for any visible resizer.
309 // aHasResizer specifies if there is a content resizer, however this method
310 // will also check if a widget resizer is present as well.
311 void AdjustScrollbarRectForResizer(nsIFrame* aFrame, nsPresContext* aPresContext,
312 nsRect& aRect, bool aHasResizer, bool aVertical);
313 // returns true if a resizer should be visible
314 bool HasResizer() { return mResizerBox && !mCollapsedResizer; }
315 void LayoutScrollbars(nsBoxLayoutState& aState,
316 const nsRect& aContentArea,
317 const nsRect& aOldScrollArea);
319 bool IsIgnoringViewportClipping() const;
321 void MarkScrollbarsDirtyForReflow() const;
323 bool ShouldClampScrollPosition() const;
325 bool IsAlwaysActive() const;
326 void MarkRecentlyScrolled();
327 void MarkNotRecentlyScrolled();
328 nsExpirationState* GetExpirationState() { return &mActivityExpirationState; }
330 void SetTransformingByAPZ(bool aTransforming) {
331 mTransformingByAPZ = aTransforming;
332 if (!mozilla::css::TextOverflow::HasClippedOverflow(mOuter)) {
333 // If the block has some text-overflow stuff we should kick off a paint
334 // because we have special behaviour for it when APZ scrolling is active.
335 mOuter->SchedulePaint();
338 bool IsTransformingByAPZ() const {
339 return mTransformingByAPZ;
342 void ScheduleSyntheticMouseMove();
343 static void ScrollActivityCallback(nsITimer *aTimer, void* anInstance);
345 void HandleScrollbarStyleSwitching();
347 nsIAtom* LastScrollOrigin() const { return mLastScrollOrigin; }
348 nsIAtom* LastSmoothScrollOrigin() const { return mLastSmoothScrollOrigin; }
349 uint32_t CurrentScrollGeneration() const { return mScrollGeneration; }
350 nsPoint LastScrollDestination() const { return mDestination; }
351 void ResetScrollInfoIfGeneration(uint32_t aGeneration) {
352 if (aGeneration == mScrollGeneration) {
353 mLastScrollOrigin = nullptr;
354 mLastSmoothScrollOrigin = nullptr;
357 bool WantAsyncScroll() const;
358 void ComputeFrameMetrics(Layer* aLayer, nsIFrame* aContainerReferenceFrame,
359 const ContainerLayerParameters& aParameters,
360 nsRect* aClipRect,
361 nsTArray<FrameMetrics>* aOutput) const;
363 // nsIScrollbarMediator
364 void ScrollByPage(nsScrollbarFrame* aScrollbar, int32_t aDirection);
365 void ScrollByWhole(nsScrollbarFrame* aScrollbar, int32_t aDirection);
366 void ScrollByLine(nsScrollbarFrame* aScrollbar, int32_t aDirection);
367 void RepeatButtonScroll(nsScrollbarFrame* aScrollbar);
368 void ThumbMoved(nsScrollbarFrame* aScrollbar,
369 nscoord aOldPos,
370 nscoord aNewPos);
371 void ScrollByUnit(nsScrollbarFrame* aScrollbar,
372 nsIScrollableFrame::ScrollMode aMode,
373 int32_t aDirection,
374 nsIScrollableFrame::ScrollUnit aUnit);
376 // owning references to the nsIAnonymousContentCreator-built content
377 nsCOMPtr<nsIContent> mHScrollbarContent;
378 nsCOMPtr<nsIContent> mVScrollbarContent;
379 nsCOMPtr<nsIContent> mScrollCornerContent;
380 nsCOMPtr<nsIContent> mResizerContent;
382 nsRevocableEventPtr<ScrollEvent> mScrollEvent;
383 nsRevocableEventPtr<AsyncScrollPortEvent> mAsyncScrollPortEvent;
384 nsRevocableEventPtr<ScrolledAreaEvent> mScrolledAreaEvent;
385 nsIFrame* mHScrollbarBox;
386 nsIFrame* mVScrollbarBox;
387 nsIFrame* mScrolledFrame;
388 nsIFrame* mScrollCornerBox;
389 nsIFrame* mResizerBox;
390 nsContainerFrame* mOuter;
391 nsRefPtr<AsyncScroll> mAsyncScroll;
392 nsRefPtr<AsyncSmoothMSDScroll> mAsyncSmoothMSDScroll;
393 nsRefPtr<ScrollbarActivity> mScrollbarActivity;
394 nsTArray<nsIScrollPositionListener*> mListeners;
395 nsIAtom* mLastScrollOrigin;
396 nsIAtom* mLastSmoothScrollOrigin;
397 uint32_t mScrollGeneration;
398 nsRect mScrollPort;
399 // Where we're currently scrolling to, if we're scrolling asynchronously.
400 // If we're not in the middle of an asynchronous scroll then this is
401 // just the current scroll position. ScrollBy will choose its
402 // destination based on this value.
403 nsPoint mDestination;
404 nsPoint mScrollPosAtLastPaint;
406 // A goal position to try to scroll to as content loads. As long as mLastPos
407 // matches the current logical scroll position, we try to scroll to mRestorePos
408 // after every reflow --- because after each time content is loaded/added to the
409 // scrollable element, there will be a reflow.
410 nsPoint mRestorePos;
411 // The last logical position we scrolled to while trying to restore mRestorePos, or
412 // 0,0 when this is a new frame. Set to -1,-1 once we've scrolled for any reason
413 // other than trying to restore mRestorePos.
414 nsPoint mLastPos;
416 // The current resolution derived from the zoom level and device pixel ratio.
417 gfxSize mResolution;
419 nsExpirationState mActivityExpirationState;
421 nsCOMPtr<nsITimer> mScrollActivityTimer;
422 nsPoint mScrollPosForLayerPixelAlignment;
424 // The scroll position where we last updated image visibility.
425 nsPoint mLastUpdateImagesPos;
427 nsRect mPrevScrolledRect;
429 FrameMetrics::ViewID mScrollParentID;
431 bool mNeverHasVerticalScrollbar:1;
432 bool mNeverHasHorizontalScrollbar:1;
433 bool mHasVerticalScrollbar:1;
434 bool mHasHorizontalScrollbar:1;
435 bool mFrameIsUpdatingScrollbar:1;
436 bool mDidHistoryRestore:1;
437 // Is this the scrollframe for the document's viewport?
438 bool mIsRoot:1;
439 // True if we should clip all descendants, false if we should only clip
440 // descendants for which we are the containing block.
441 bool mClipAllDescendants:1;
442 // If true, don't try to layout the scrollbars in Reflow(). This can be
443 // useful if multiple passes are involved, because we don't want to place the
444 // scrollbars at the wrong size.
445 bool mSupppressScrollbarUpdate:1;
446 // If true, we skipped a scrollbar layout due to mSupppressScrollbarUpdate
447 // being set at some point. That means we should lay out scrollbars even if
448 // it might not strictly be needed next time mSupppressScrollbarUpdate is
449 // false.
450 bool mSkippedScrollbarLayout:1;
452 bool mHadNonInitialReflow:1;
453 // State used only by PostScrollEvents so we know
454 // which overflow states have changed.
455 bool mHorizontalOverflow:1;
456 bool mVerticalOverflow:1;
457 bool mPostedReflowCallback:1;
458 bool mMayHaveDirtyFixedChildren:1;
459 // If true, need to actually update our scrollbar attributes in the
460 // reflow callback.
461 bool mUpdateScrollbarAttributes:1;
462 // If true, we should be prepared to scroll using this scrollframe
463 // by placing descendant content into its own layer(s)
464 bool mHasBeenScrolledRecently:1;
465 // If true, the resizer is collapsed and not displayed
466 bool mCollapsedResizer:1;
468 // If true, the layer should always be active because we always build a
469 // scrollable layer. Used for asynchronous scrolling.
470 bool mShouldBuildScrollableLayer:1;
472 // If true, add clipping in ScrollFrameHelper::ComputeFrameMetrics.
473 bool mAddClipRectToLayer:1;
475 // True if this frame has been scrolled at least once
476 bool mHasBeenScrolled:1;
478 // True if the frame's resolution has been set via SetResolution or
479 // SetResolutionAndScaleTo or restored via RestoreState.
480 bool mIsResolutionSet:1;
482 // True if the frame's resolution has been set via SetResolutionAndScaleTo.
483 // Only meaningful for root scroll frames.
484 bool mScaleToResolution:1;
486 // True if the APZ is in the process of async-transforming this scrollframe,
487 // (as best as we can tell on the main thread, anyway).
488 bool mTransformingByAPZ:1;
490 protected:
492 * @note This method might destroy the frame, pres shell and other objects.
494 void ScrollToWithOrigin(nsPoint aScrollPosition,
495 nsIScrollableFrame::ScrollMode aMode,
496 nsIAtom *aOrigin, // nullptr indicates "other" origin
497 const nsRect* aRange);
499 void CompleteAsyncScroll(const nsRect &aRange, nsIAtom* aOrigin = nullptr);
501 static void EnsureImageVisPrefsCached();
502 static bool sImageVisPrefsCached;
503 // The number of scrollports wide/high to expand when looking for images.
504 static uint32_t sHorzExpandScrollPort;
505 static uint32_t sVertExpandScrollPort;
506 // The fraction of the scrollport we allow to scroll by before we schedule
507 // an update of image visibility.
508 static int32_t sHorzScrollFraction;
509 static int32_t sVertScrollFraction;
515 * The scroll frame creates and manages the scrolling view
517 * It only supports having a single child frame that typically is an area
518 * frame, but doesn't have to be. The child frame must have a view, though
520 * Scroll frames don't support incremental changes, i.e. you can't replace
521 * or remove the scrolled frame
523 class nsHTMLScrollFrame : public nsContainerFrame,
524 public nsIScrollableFrame,
525 public nsIAnonymousContentCreator,
526 public nsIStatefulFrame {
527 public:
528 typedef mozilla::ScrollFrameHelper ScrollFrameHelper;
529 typedef mozilla::CSSIntPoint CSSIntPoint;
530 friend nsHTMLScrollFrame* NS_NewHTMLScrollFrame(nsIPresShell* aPresShell,
531 nsStyleContext* aContext,
532 bool aIsRoot);
534 NS_DECL_QUERYFRAME
535 NS_DECL_FRAMEARENA_HELPERS
537 virtual mozilla::WritingMode GetWritingMode() const MOZ_OVERRIDE
539 if (mHelper.mScrolledFrame) {
540 return mHelper.mScrolledFrame->GetWritingMode();
542 return nsIFrame::GetWritingMode();
545 virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder,
546 const nsRect& aDirtyRect,
547 const nsDisplayListSet& aLists) MOZ_OVERRIDE {
548 mHelper.BuildDisplayList(aBuilder, aDirtyRect, aLists);
551 bool TryLayout(ScrollReflowState* aState,
552 nsHTMLReflowMetrics* aKidMetrics,
553 bool aAssumeVScroll, bool aAssumeHScroll,
554 bool aForce);
555 bool ScrolledContentDependsOnHeight(ScrollReflowState* aState);
556 void ReflowScrolledFrame(ScrollReflowState* aState,
557 bool aAssumeHScroll,
558 bool aAssumeVScroll,
559 nsHTMLReflowMetrics* aMetrics,
560 bool aFirstPass);
561 void ReflowContents(ScrollReflowState* aState,
562 const nsHTMLReflowMetrics& aDesiredSize);
563 void PlaceScrollArea(const ScrollReflowState& aState,
564 const nsPoint& aScrollPosition);
565 nscoord GetIntrinsicVScrollbarWidth(nsRenderingContext *aRenderingContext);
567 virtual bool GetBorderRadii(const nsSize& aFrameSize, const nsSize& aBorderArea,
568 Sides aSkipSides, nscoord aRadii[8]) const MOZ_OVERRIDE {
569 return mHelper.GetBorderRadii(aFrameSize, aBorderArea, aSkipSides, aRadii);
572 virtual nscoord GetMinISize(nsRenderingContext *aRenderingContext) MOZ_OVERRIDE;
573 virtual nscoord GetPrefISize(nsRenderingContext *aRenderingContext) MOZ_OVERRIDE;
574 virtual nsresult GetPadding(nsMargin& aPadding) MOZ_OVERRIDE;
575 virtual bool IsCollapsed() MOZ_OVERRIDE;
577 virtual void Reflow(nsPresContext* aPresContext,
578 nsHTMLReflowMetrics& aDesiredSize,
579 const nsHTMLReflowState& aReflowState,
580 nsReflowStatus& aStatus) MOZ_OVERRIDE;
582 virtual bool UpdateOverflow() MOZ_OVERRIDE {
583 return mHelper.UpdateOverflow();
586 // Called to set the child frames. We typically have three: the scroll area,
587 // the vertical scrollbar, and the horizontal scrollbar.
588 virtual void SetInitialChildList(ChildListID aListID,
589 nsFrameList& aChildList) MOZ_OVERRIDE;
590 virtual void AppendFrames(ChildListID aListID,
591 nsFrameList& aFrameList) MOZ_OVERRIDE;
592 virtual void InsertFrames(ChildListID aListID,
593 nsIFrame* aPrevFrame,
594 nsFrameList& aFrameList) MOZ_OVERRIDE;
595 virtual void RemoveFrame(ChildListID aListID,
596 nsIFrame* aOldFrame) MOZ_OVERRIDE;
598 virtual void DestroyFrom(nsIFrame* aDestructRoot) MOZ_OVERRIDE;
600 virtual nsIScrollableFrame* GetScrollTargetFrame() MOZ_OVERRIDE {
601 return this;
604 virtual nsContainerFrame* GetContentInsertionFrame() MOZ_OVERRIDE {
605 return mHelper.GetScrolledFrame()->GetContentInsertionFrame();
608 virtual bool DoesClipChildren() MOZ_OVERRIDE { return true; }
609 virtual nsSplittableType GetSplittableType() const MOZ_OVERRIDE;
611 virtual nsPoint GetPositionOfChildIgnoringScrolling(nsIFrame* aChild) MOZ_OVERRIDE
612 { nsPoint pt = aChild->GetPosition();
613 if (aChild == mHelper.GetScrolledFrame()) pt += GetScrollPosition();
614 return pt;
617 // nsIAnonymousContentCreator
618 virtual nsresult CreateAnonymousContent(nsTArray<ContentInfo>& aElements) MOZ_OVERRIDE;
619 virtual void AppendAnonymousContentTo(nsTArray<nsIContent*>& aElements,
620 uint32_t aFilter) MOZ_OVERRIDE;
622 // nsIScrollableFrame
623 virtual nsIFrame* GetScrolledFrame() const MOZ_OVERRIDE {
624 return mHelper.GetScrolledFrame();
626 virtual mozilla::ScrollbarStyles GetScrollbarStyles() const MOZ_OVERRIDE {
627 return mHelper.GetScrollbarStylesFromFrame();
629 virtual uint32_t GetScrollbarVisibility() const MOZ_OVERRIDE {
630 return mHelper.GetScrollbarVisibility();
632 virtual nsMargin GetActualScrollbarSizes() const MOZ_OVERRIDE {
633 return mHelper.GetActualScrollbarSizes();
635 virtual nsMargin GetDesiredScrollbarSizes(nsBoxLayoutState* aState) MOZ_OVERRIDE {
636 return mHelper.GetDesiredScrollbarSizes(aState);
638 virtual nsMargin GetDesiredScrollbarSizes(nsPresContext* aPresContext,
639 nsRenderingContext* aRC) MOZ_OVERRIDE {
640 nsBoxLayoutState bls(aPresContext, aRC, 0);
641 return GetDesiredScrollbarSizes(&bls);
643 virtual nscoord GetNondisappearingScrollbarWidth(nsPresContext* aPresContext,
644 nsRenderingContext* aRC) MOZ_OVERRIDE {
645 nsBoxLayoutState bls(aPresContext, aRC, 0);
646 return mHelper.GetNondisappearingScrollbarWidth(&bls);
648 virtual nsRect GetScrolledRect() const MOZ_OVERRIDE {
649 return mHelper.GetScrolledRect();
651 virtual nsRect GetScrollPortRect() const MOZ_OVERRIDE {
652 return mHelper.GetScrollPortRect();
654 virtual nsPoint GetScrollPosition() const MOZ_OVERRIDE {
655 return mHelper.GetScrollPosition();
657 virtual nsPoint GetLogicalScrollPosition() const MOZ_OVERRIDE {
658 return mHelper.GetLogicalScrollPosition();
660 virtual nsRect GetScrollRange() const MOZ_OVERRIDE {
661 return mHelper.GetScrollRange();
663 virtual nsSize GetScrollPositionClampingScrollPortSize() const MOZ_OVERRIDE {
664 return mHelper.GetScrollPositionClampingScrollPortSize();
666 virtual gfxSize GetResolution() const MOZ_OVERRIDE {
667 return mHelper.GetResolution();
669 virtual void SetResolution(const gfxSize& aResolution) MOZ_OVERRIDE {
670 return mHelper.SetResolution(aResolution);
672 virtual void SetResolutionAndScaleTo(const gfxSize& aResolution) MOZ_OVERRIDE {
673 return mHelper.SetResolutionAndScaleTo(aResolution);
675 virtual nsSize GetLineScrollAmount() const MOZ_OVERRIDE {
676 return mHelper.GetLineScrollAmount();
678 virtual nsSize GetPageScrollAmount() const MOZ_OVERRIDE {
679 return mHelper.GetPageScrollAmount();
682 * @note This method might destroy the frame, pres shell and other objects.
684 virtual void ScrollTo(nsPoint aScrollPosition, ScrollMode aMode,
685 const nsRect* aRange = nullptr) MOZ_OVERRIDE {
686 mHelper.ScrollTo(aScrollPosition, aMode, aRange);
689 * @note This method might destroy the frame, pres shell and other objects.
691 virtual void ScrollToCSSPixels(const CSSIntPoint& aScrollPosition,
692 nsIScrollableFrame::ScrollMode aMode
693 = nsIScrollableFrame::INSTANT) MOZ_OVERRIDE {
694 mHelper.ScrollToCSSPixels(aScrollPosition, aMode);
696 virtual void ScrollToCSSPixelsApproximate(const mozilla::CSSPoint& aScrollPosition,
697 nsIAtom* aOrigin = nullptr) MOZ_OVERRIDE {
698 mHelper.ScrollToCSSPixelsApproximate(aScrollPosition, aOrigin);
701 * @note This method might destroy the frame, pres shell and other objects.
703 virtual CSSIntPoint GetScrollPositionCSSPixels() MOZ_OVERRIDE {
704 return mHelper.GetScrollPositionCSSPixels();
707 * @note This method might destroy the frame, pres shell and other objects.
709 virtual void ScrollBy(nsIntPoint aDelta, ScrollUnit aUnit, ScrollMode aMode,
710 nsIntPoint* aOverflow, nsIAtom* aOrigin = nullptr,
711 bool aIsMomentum = false) MOZ_OVERRIDE {
712 mHelper.ScrollBy(aDelta, aUnit, aMode, aOverflow, aOrigin, aIsMomentum);
715 * @note This method might destroy the frame, pres shell and other objects.
717 virtual void ScrollToRestoredPosition() MOZ_OVERRIDE {
718 mHelper.ScrollToRestoredPosition();
720 virtual void AddScrollPositionListener(nsIScrollPositionListener* aListener) MOZ_OVERRIDE {
721 mHelper.AddScrollPositionListener(aListener);
723 virtual void RemoveScrollPositionListener(nsIScrollPositionListener* aListener) MOZ_OVERRIDE {
724 mHelper.RemoveScrollPositionListener(aListener);
727 * @note This method might destroy the frame, pres shell and other objects.
729 virtual void CurPosAttributeChanged(nsIContent* aChild) MOZ_OVERRIDE {
730 mHelper.CurPosAttributeChanged(aChild);
732 NS_IMETHOD PostScrolledAreaEventForCurrentArea() MOZ_OVERRIDE {
733 mHelper.PostScrolledAreaEvent();
734 return NS_OK;
736 virtual bool IsScrollingActive(nsDisplayListBuilder* aBuilder) MOZ_OVERRIDE {
737 return mHelper.IsScrollingActive(aBuilder);
739 virtual bool IsProcessingAsyncScroll() MOZ_OVERRIDE {
740 return mHelper.IsProcessingAsyncScroll();
742 virtual void ResetScrollPositionForLayerPixelAlignment() MOZ_OVERRIDE {
743 mHelper.ResetScrollPositionForLayerPixelAlignment();
745 virtual bool IsResolutionSet() const MOZ_OVERRIDE {
746 return mHelper.mIsResolutionSet;
748 virtual bool DidHistoryRestore() const MOZ_OVERRIDE {
749 return mHelper.mDidHistoryRestore;
751 virtual void ClearDidHistoryRestore() MOZ_OVERRIDE {
752 mHelper.mDidHistoryRestore = false;
754 virtual bool IsRectNearlyVisible(const nsRect& aRect) MOZ_OVERRIDE {
755 return mHelper.IsRectNearlyVisible(aRect);
757 virtual nsRect ExpandRectToNearlyVisible(const nsRect& aRect) const MOZ_OVERRIDE {
758 return mHelper.ExpandRectToNearlyVisible(aRect);
760 virtual nsIAtom* LastScrollOrigin() MOZ_OVERRIDE {
761 return mHelper.LastScrollOrigin();
763 virtual nsIAtom* LastSmoothScrollOrigin() MOZ_OVERRIDE {
764 return mHelper.LastSmoothScrollOrigin();
766 virtual uint32_t CurrentScrollGeneration() MOZ_OVERRIDE {
767 return mHelper.CurrentScrollGeneration();
769 virtual nsPoint LastScrollDestination() MOZ_OVERRIDE {
770 return mHelper.LastScrollDestination();
772 virtual void ResetScrollInfoIfGeneration(uint32_t aGeneration) MOZ_OVERRIDE {
773 mHelper.ResetScrollInfoIfGeneration(aGeneration);
775 virtual bool WantAsyncScroll() const MOZ_OVERRIDE {
776 return mHelper.WantAsyncScroll();
778 virtual void ComputeFrameMetrics(Layer* aLayer, nsIFrame* aContainerReferenceFrame,
779 const ContainerLayerParameters& aParameters,
780 nsRect* aClipRect,
781 nsTArray<FrameMetrics>* aOutput) const MOZ_OVERRIDE {
782 mHelper.ComputeFrameMetrics(aLayer, aContainerReferenceFrame,
783 aParameters, aClipRect, aOutput);
785 virtual bool IsIgnoringViewportClipping() const MOZ_OVERRIDE {
786 return mHelper.IsIgnoringViewportClipping();
788 virtual void MarkScrollbarsDirtyForReflow() const MOZ_OVERRIDE {
789 mHelper.MarkScrollbarsDirtyForReflow();
792 // nsIStatefulFrame
793 NS_IMETHOD SaveState(nsPresState** aState) MOZ_OVERRIDE {
794 NS_ENSURE_ARG_POINTER(aState);
795 *aState = mHelper.SaveState();
796 return NS_OK;
798 NS_IMETHOD RestoreState(nsPresState* aState) MOZ_OVERRIDE {
799 NS_ENSURE_ARG_POINTER(aState);
800 mHelper.RestoreState(aState);
801 return NS_OK;
805 * Get the "type" of the frame
807 * @see nsGkAtoms::scrollFrame
809 virtual nsIAtom* GetType() const MOZ_OVERRIDE;
811 // nsIScrollbarMediator
812 virtual void ScrollByPage(nsScrollbarFrame* aScrollbar, int32_t aDirection) MOZ_OVERRIDE {
813 mHelper.ScrollByPage(aScrollbar, aDirection);
815 virtual void ScrollByWhole(nsScrollbarFrame* aScrollbar, int32_t aDirection) MOZ_OVERRIDE {
816 mHelper.ScrollByWhole(aScrollbar, aDirection);
818 virtual void ScrollByLine(nsScrollbarFrame* aScrollbar, int32_t aDirection) MOZ_OVERRIDE {
819 mHelper.ScrollByLine(aScrollbar, aDirection);
821 virtual void RepeatButtonScroll(nsScrollbarFrame* aScrollbar) MOZ_OVERRIDE {
822 mHelper.RepeatButtonScroll(aScrollbar);
824 virtual void ThumbMoved(nsScrollbarFrame* aScrollbar,
825 nscoord aOldPos,
826 nscoord aNewPos) MOZ_OVERRIDE {
827 mHelper.ThumbMoved(aScrollbar, aOldPos, aNewPos);
829 virtual void VisibilityChanged(bool aVisible) MOZ_OVERRIDE {}
830 virtual nsIFrame* GetScrollbarBox(bool aVertical) MOZ_OVERRIDE {
831 return mHelper.GetScrollbarBox(aVertical);
833 virtual void ScrollbarActivityStarted() const MOZ_OVERRIDE;
834 virtual void ScrollbarActivityStopped() const MOZ_OVERRIDE;
836 virtual bool IsScrollbarOnRight() const MOZ_OVERRIDE {
837 return mHelper.IsScrollbarOnRight();
840 virtual void SetTransformingByAPZ(bool aTransforming) MOZ_OVERRIDE {
841 mHelper.SetTransformingByAPZ(aTransforming);
843 bool IsTransformingByAPZ() const MOZ_OVERRIDE {
844 return mHelper.IsTransformingByAPZ();
847 #ifdef DEBUG_FRAME_DUMP
848 virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE;
849 #endif
851 #ifdef ACCESSIBILITY
852 virtual mozilla::a11y::AccType AccessibleType() MOZ_OVERRIDE;
853 #endif
855 protected:
856 nsHTMLScrollFrame(nsStyleContext* aContext, bool aIsRoot);
857 void SetSuppressScrollbarUpdate(bool aSuppress) {
858 mHelper.mSupppressScrollbarUpdate = aSuppress;
860 bool GuessHScrollbarNeeded(const ScrollReflowState& aState);
861 bool GuessVScrollbarNeeded(const ScrollReflowState& aState);
863 bool IsScrollbarUpdateSuppressed() const {
864 return mHelper.mSupppressScrollbarUpdate;
867 // Return whether we're in an "initial" reflow. Some reflows with
868 // NS_FRAME_FIRST_REFLOW set are NOT "initial" as far as we're concerned.
869 bool InInitialReflow() const;
872 * Override this to return false if computed height/min-height/max-height
873 * should NOT be propagated to child content.
874 * nsListControlFrame uses this.
876 virtual bool ShouldPropagateComputedHeightToScrolledContent() const { return true; }
878 private:
879 friend class mozilla::ScrollFrameHelper;
880 ScrollFrameHelper mHelper;
884 * The scroll frame creates and manages the scrolling view
886 * It only supports having a single child frame that typically is an area
887 * frame, but doesn't have to be. The child frame must have a view, though
889 * Scroll frames don't support incremental changes, i.e. you can't replace
890 * or remove the scrolled frame
892 class nsXULScrollFrame MOZ_FINAL : public nsBoxFrame,
893 public nsIScrollableFrame,
894 public nsIAnonymousContentCreator,
895 public nsIStatefulFrame {
896 public:
897 typedef mozilla::ScrollFrameHelper ScrollFrameHelper;
898 typedef mozilla::CSSIntPoint CSSIntPoint;
900 NS_DECL_QUERYFRAME
901 NS_DECL_FRAMEARENA_HELPERS
903 friend nsXULScrollFrame* NS_NewXULScrollFrame(nsIPresShell* aPresShell,
904 nsStyleContext* aContext,
905 bool aIsRoot,
906 bool aClipAllDescendants);
908 virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder,
909 const nsRect& aDirtyRect,
910 const nsDisplayListSet& aLists) MOZ_OVERRIDE {
911 mHelper.BuildDisplayList(aBuilder, aDirtyRect, aLists);
914 // XXXldb Is this actually used?
915 #if 0
916 virtual nscoord GetMinISize(nsRenderingContext *aRenderingContext) MOZ_OVERRIDE;
917 #endif
919 virtual bool UpdateOverflow() MOZ_OVERRIDE {
920 return mHelper.UpdateOverflow();
923 // Called to set the child frames. We typically have three: the scroll area,
924 // the vertical scrollbar, and the horizontal scrollbar.
925 virtual void SetInitialChildList(ChildListID aListID,
926 nsFrameList& aChildList) MOZ_OVERRIDE;
927 virtual void AppendFrames(ChildListID aListID,
928 nsFrameList& aFrameList) MOZ_OVERRIDE;
929 virtual void InsertFrames(ChildListID aListID,
930 nsIFrame* aPrevFrame,
931 nsFrameList& aFrameList) MOZ_OVERRIDE;
932 virtual void RemoveFrame(ChildListID aListID,
933 nsIFrame* aOldFrame) MOZ_OVERRIDE;
935 virtual void DestroyFrom(nsIFrame* aDestructRoot) MOZ_OVERRIDE;
938 virtual nsIScrollableFrame* GetScrollTargetFrame() MOZ_OVERRIDE {
939 return this;
942 virtual nsContainerFrame* GetContentInsertionFrame() MOZ_OVERRIDE {
943 return mHelper.GetScrolledFrame()->GetContentInsertionFrame();
946 virtual bool DoesClipChildren() MOZ_OVERRIDE { return true; }
947 virtual nsSplittableType GetSplittableType() const MOZ_OVERRIDE;
949 virtual nsPoint GetPositionOfChildIgnoringScrolling(nsIFrame* aChild) MOZ_OVERRIDE
950 { nsPoint pt = aChild->GetPosition();
951 if (aChild == mHelper.GetScrolledFrame())
952 pt += mHelper.GetLogicalScrollPosition();
953 return pt;
956 // nsIAnonymousContentCreator
957 virtual nsresult CreateAnonymousContent(nsTArray<ContentInfo>& aElements) MOZ_OVERRIDE;
958 virtual void AppendAnonymousContentTo(nsTArray<nsIContent*>& aElements,
959 uint32_t aFilter) MOZ_OVERRIDE;
961 virtual nsSize GetMinSize(nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE;
962 virtual nsSize GetPrefSize(nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE;
963 virtual nsSize GetMaxSize(nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE;
964 virtual nscoord GetBoxAscent(nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE;
966 NS_IMETHOD DoLayout(nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE;
967 virtual nsresult GetPadding(nsMargin& aPadding) MOZ_OVERRIDE;
969 virtual bool GetBorderRadii(const nsSize& aFrameSize, const nsSize& aBorderArea,
970 Sides aSkipSides, nscoord aRadii[8]) const MOZ_OVERRIDE {
971 return mHelper.GetBorderRadii(aFrameSize, aBorderArea, aSkipSides, aRadii);
974 nsresult Layout(nsBoxLayoutState& aState);
975 void LayoutScrollArea(nsBoxLayoutState& aState, const nsPoint& aScrollPosition);
977 static bool AddRemoveScrollbar(bool& aHasScrollbar,
978 nscoord& aXY,
979 nscoord& aSize,
980 nscoord aSbSize,
981 bool aOnRightOrBottom,
982 bool aAdd);
984 bool AddRemoveScrollbar(nsBoxLayoutState& aState,
985 bool aOnRightOrBottom,
986 bool aHorizontal,
987 bool aAdd);
989 bool AddHorizontalScrollbar (nsBoxLayoutState& aState, bool aOnBottom);
990 bool AddVerticalScrollbar (nsBoxLayoutState& aState, bool aOnRight);
991 void RemoveHorizontalScrollbar(nsBoxLayoutState& aState, bool aOnBottom);
992 void RemoveVerticalScrollbar (nsBoxLayoutState& aState, bool aOnRight);
994 static void AdjustReflowStateForPrintPreview(nsBoxLayoutState& aState, bool& aSetBack);
995 static void AdjustReflowStateBack(nsBoxLayoutState& aState, bool aSetBack);
997 // nsIScrollableFrame
998 virtual nsIFrame* GetScrolledFrame() const MOZ_OVERRIDE {
999 return mHelper.GetScrolledFrame();
1001 virtual mozilla::ScrollbarStyles GetScrollbarStyles() const MOZ_OVERRIDE {
1002 return mHelper.GetScrollbarStylesFromFrame();
1004 virtual uint32_t GetScrollbarVisibility() const MOZ_OVERRIDE {
1005 return mHelper.GetScrollbarVisibility();
1007 virtual nsMargin GetActualScrollbarSizes() const MOZ_OVERRIDE {
1008 return mHelper.GetActualScrollbarSizes();
1010 virtual nsMargin GetDesiredScrollbarSizes(nsBoxLayoutState* aState) MOZ_OVERRIDE {
1011 return mHelper.GetDesiredScrollbarSizes(aState);
1013 virtual nsMargin GetDesiredScrollbarSizes(nsPresContext* aPresContext,
1014 nsRenderingContext* aRC) MOZ_OVERRIDE {
1015 nsBoxLayoutState bls(aPresContext, aRC, 0);
1016 return GetDesiredScrollbarSizes(&bls);
1018 virtual nscoord GetNondisappearingScrollbarWidth(nsPresContext* aPresContext,
1019 nsRenderingContext* aRC) MOZ_OVERRIDE {
1020 nsBoxLayoutState bls(aPresContext, aRC, 0);
1021 return mHelper.GetNondisappearingScrollbarWidth(&bls);
1023 virtual nsRect GetScrolledRect() const MOZ_OVERRIDE {
1024 return mHelper.GetScrolledRect();
1026 virtual nsRect GetScrollPortRect() const MOZ_OVERRIDE {
1027 return mHelper.GetScrollPortRect();
1029 virtual nsPoint GetScrollPosition() const MOZ_OVERRIDE {
1030 return mHelper.GetScrollPosition();
1032 virtual nsPoint GetLogicalScrollPosition() const MOZ_OVERRIDE {
1033 return mHelper.GetLogicalScrollPosition();
1035 virtual nsRect GetScrollRange() const MOZ_OVERRIDE {
1036 return mHelper.GetScrollRange();
1038 virtual nsSize GetScrollPositionClampingScrollPortSize() const MOZ_OVERRIDE {
1039 return mHelper.GetScrollPositionClampingScrollPortSize();
1041 virtual gfxSize GetResolution() const MOZ_OVERRIDE {
1042 return mHelper.GetResolution();
1044 virtual void SetResolution(const gfxSize& aResolution) MOZ_OVERRIDE {
1045 return mHelper.SetResolution(aResolution);
1047 virtual void SetResolutionAndScaleTo(const gfxSize& aResolution) MOZ_OVERRIDE {
1048 return mHelper.SetResolutionAndScaleTo(aResolution);
1050 virtual nsSize GetLineScrollAmount() const MOZ_OVERRIDE {
1051 return mHelper.GetLineScrollAmount();
1053 virtual nsSize GetPageScrollAmount() const MOZ_OVERRIDE {
1054 return mHelper.GetPageScrollAmount();
1057 * @note This method might destroy the frame, pres shell and other objects.
1059 virtual void ScrollTo(nsPoint aScrollPosition, ScrollMode aMode,
1060 const nsRect* aRange = nullptr) MOZ_OVERRIDE {
1061 mHelper.ScrollTo(aScrollPosition, aMode, aRange);
1064 * @note This method might destroy the frame, pres shell and other objects.
1066 virtual void ScrollToCSSPixels(const CSSIntPoint& aScrollPosition,
1067 nsIScrollableFrame::ScrollMode aMode
1068 = nsIScrollableFrame::INSTANT) MOZ_OVERRIDE {
1069 mHelper.ScrollToCSSPixels(aScrollPosition, aMode);
1071 virtual void ScrollToCSSPixelsApproximate(const mozilla::CSSPoint& aScrollPosition,
1072 nsIAtom* aOrigin = nullptr) MOZ_OVERRIDE {
1073 mHelper.ScrollToCSSPixelsApproximate(aScrollPosition, aOrigin);
1075 virtual CSSIntPoint GetScrollPositionCSSPixels() MOZ_OVERRIDE {
1076 return mHelper.GetScrollPositionCSSPixels();
1079 * @note This method might destroy the frame, pres shell and other objects.
1081 virtual void ScrollBy(nsIntPoint aDelta, ScrollUnit aUnit, ScrollMode aMode,
1082 nsIntPoint* aOverflow, nsIAtom* aOrigin = nullptr,
1083 bool aIsMomentum = false) MOZ_OVERRIDE {
1084 mHelper.ScrollBy(aDelta, aUnit, aMode, aOverflow, aOrigin, aIsMomentum);
1087 * @note This method might destroy the frame, pres shell and other objects.
1089 virtual void ScrollToRestoredPosition() MOZ_OVERRIDE {
1090 mHelper.ScrollToRestoredPosition();
1092 virtual void AddScrollPositionListener(nsIScrollPositionListener* aListener) MOZ_OVERRIDE {
1093 mHelper.AddScrollPositionListener(aListener);
1095 virtual void RemoveScrollPositionListener(nsIScrollPositionListener* aListener) MOZ_OVERRIDE {
1096 mHelper.RemoveScrollPositionListener(aListener);
1099 * @note This method might destroy the frame, pres shell and other objects.
1101 virtual void CurPosAttributeChanged(nsIContent* aChild) MOZ_OVERRIDE {
1102 mHelper.CurPosAttributeChanged(aChild);
1104 NS_IMETHOD PostScrolledAreaEventForCurrentArea() MOZ_OVERRIDE {
1105 mHelper.PostScrolledAreaEvent();
1106 return NS_OK;
1108 virtual bool IsScrollingActive(nsDisplayListBuilder* aBuilder) MOZ_OVERRIDE {
1109 return mHelper.IsScrollingActive(aBuilder);
1111 virtual bool IsProcessingAsyncScroll() MOZ_OVERRIDE {
1112 return mHelper.IsProcessingAsyncScroll();
1114 virtual void ResetScrollPositionForLayerPixelAlignment() MOZ_OVERRIDE {
1115 mHelper.ResetScrollPositionForLayerPixelAlignment();
1117 virtual bool IsResolutionSet() const MOZ_OVERRIDE {
1118 return mHelper.mIsResolutionSet;
1120 virtual bool DidHistoryRestore() const MOZ_OVERRIDE {
1121 return mHelper.mDidHistoryRestore;
1123 virtual void ClearDidHistoryRestore() MOZ_OVERRIDE {
1124 mHelper.mDidHistoryRestore = false;
1126 virtual bool IsRectNearlyVisible(const nsRect& aRect) MOZ_OVERRIDE {
1127 return mHelper.IsRectNearlyVisible(aRect);
1129 virtual nsRect ExpandRectToNearlyVisible(const nsRect& aRect) const MOZ_OVERRIDE {
1130 return mHelper.ExpandRectToNearlyVisible(aRect);
1132 virtual nsIAtom* LastScrollOrigin() MOZ_OVERRIDE {
1133 return mHelper.LastScrollOrigin();
1135 virtual nsIAtom* LastSmoothScrollOrigin() MOZ_OVERRIDE {
1136 return mHelper.LastSmoothScrollOrigin();
1138 virtual uint32_t CurrentScrollGeneration() MOZ_OVERRIDE {
1139 return mHelper.CurrentScrollGeneration();
1141 virtual nsPoint LastScrollDestination() MOZ_OVERRIDE {
1142 return mHelper.LastScrollDestination();
1144 virtual void ResetScrollInfoIfGeneration(uint32_t aGeneration) MOZ_OVERRIDE {
1145 mHelper.ResetScrollInfoIfGeneration(aGeneration);
1147 virtual bool WantAsyncScroll() const MOZ_OVERRIDE {
1148 return mHelper.WantAsyncScroll();
1150 virtual void ComputeFrameMetrics(Layer* aLayer, nsIFrame* aContainerReferenceFrame,
1151 const ContainerLayerParameters& aParameters,
1152 nsRect* aClipRect,
1153 nsTArray<FrameMetrics>* aOutput) const MOZ_OVERRIDE {
1154 mHelper.ComputeFrameMetrics(aLayer, aContainerReferenceFrame,
1155 aParameters, aClipRect, aOutput);
1157 virtual bool IsIgnoringViewportClipping() const MOZ_OVERRIDE {
1158 return mHelper.IsIgnoringViewportClipping();
1160 virtual void MarkScrollbarsDirtyForReflow() const MOZ_OVERRIDE {
1161 mHelper.MarkScrollbarsDirtyForReflow();
1164 // nsIStatefulFrame
1165 NS_IMETHOD SaveState(nsPresState** aState) MOZ_OVERRIDE {
1166 NS_ENSURE_ARG_POINTER(aState);
1167 *aState = mHelper.SaveState();
1168 return NS_OK;
1170 NS_IMETHOD RestoreState(nsPresState* aState) MOZ_OVERRIDE {
1171 NS_ENSURE_ARG_POINTER(aState);
1172 mHelper.RestoreState(aState);
1173 return NS_OK;
1177 * Get the "type" of the frame
1179 * @see nsGkAtoms::scrollFrame
1181 virtual nsIAtom* GetType() const MOZ_OVERRIDE;
1183 virtual bool IsFrameOfType(uint32_t aFlags) const MOZ_OVERRIDE
1185 // Override bogus IsFrameOfType in nsBoxFrame.
1186 if (aFlags & (nsIFrame::eReplacedContainsBlock | nsIFrame::eReplaced))
1187 return false;
1188 return nsBoxFrame::IsFrameOfType(aFlags);
1191 virtual void ScrollByPage(nsScrollbarFrame* aScrollbar, int32_t aDirection) MOZ_OVERRIDE {
1192 mHelper.ScrollByPage(aScrollbar, aDirection);
1194 virtual void ScrollByWhole(nsScrollbarFrame* aScrollbar, int32_t aDirection) MOZ_OVERRIDE {
1195 mHelper.ScrollByWhole(aScrollbar, aDirection);
1197 virtual void ScrollByLine(nsScrollbarFrame* aScrollbar, int32_t aDirection) MOZ_OVERRIDE {
1198 mHelper.ScrollByLine(aScrollbar, aDirection);
1200 virtual void RepeatButtonScroll(nsScrollbarFrame* aScrollbar) MOZ_OVERRIDE {
1201 mHelper.RepeatButtonScroll(aScrollbar);
1203 virtual void ThumbMoved(nsScrollbarFrame* aScrollbar,
1204 nscoord aOldPos,
1205 nscoord aNewPos) MOZ_OVERRIDE {
1206 mHelper.ThumbMoved(aScrollbar, aOldPos, aNewPos);
1208 virtual void VisibilityChanged(bool aVisible) MOZ_OVERRIDE {}
1209 virtual nsIFrame* GetScrollbarBox(bool aVertical) MOZ_OVERRIDE {
1210 return mHelper.GetScrollbarBox(aVertical);
1213 virtual void ScrollbarActivityStarted() const MOZ_OVERRIDE;
1214 virtual void ScrollbarActivityStopped() const MOZ_OVERRIDE;
1216 virtual bool IsScrollbarOnRight() const MOZ_OVERRIDE {
1217 return mHelper.IsScrollbarOnRight();
1220 virtual void SetTransformingByAPZ(bool aTransforming) MOZ_OVERRIDE {
1221 mHelper.SetTransformingByAPZ(aTransforming);
1223 bool IsTransformingByAPZ() const MOZ_OVERRIDE {
1224 return mHelper.IsTransformingByAPZ();
1227 #ifdef DEBUG_FRAME_DUMP
1228 virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE;
1229 #endif
1231 protected:
1232 nsXULScrollFrame(nsStyleContext* aContext, bool aIsRoot,
1233 bool aClipAllDescendants);
1235 void ClampAndSetBounds(nsBoxLayoutState& aState,
1236 nsRect& aRect,
1237 nsPoint aScrollPosition,
1238 bool aRemoveOverflowAreas = false) {
1240 * For RTL frames, restore the original scrolled position of the right
1241 * edge, then subtract the current width to find the physical position.
1243 if (!mHelper.IsLTR()) {
1244 aRect.x = mHelper.mScrollPort.XMost() - aScrollPosition.x - aRect.width;
1246 mHelper.mScrolledFrame->SetBounds(aState, aRect, aRemoveOverflowAreas);
1249 private:
1250 friend class mozilla::ScrollFrameHelper;
1251 ScrollFrameHelper mHelper;
1254 #endif /* nsGfxScrollFrame_h___ */