Bumping manifests a=b2g-bump
[gecko.git] / layout / generic / nsGfxScrollFrame.h
blob1bb05ecab0622710a70c4ba8a8997910175fe214
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"
24 class nsPresContext;
25 class nsIPresShell;
26 class nsIContent;
27 class nsIAtom;
28 class nsIScrollFrameInternal;
29 class nsPresState;
30 class nsIScrollPositionListener;
31 struct ScrollReflowState;
33 namespace mozilla {
34 namespace layers {
35 class Layer;
37 namespace layout {
38 class ScrollbarActivity;
42 namespace mozilla {
44 class ScrollFrameHelper : public nsIReflowCallback {
45 public:
46 typedef nsIFrame::Sides Sides;
47 typedef mozilla::CSSIntPoint CSSIntPoint;
48 typedef mozilla::layout::ScrollbarActivity ScrollbarActivity;
49 typedef mozilla::layers::FrameMetrics FrameMetrics;
50 typedef mozilla::layers::Layer Layer;
52 class AsyncScroll;
53 class AsyncSmoothMSDScroll;
55 ScrollFrameHelper(nsContainerFrame* aOuter, bool aIsRoot);
56 ~ScrollFrameHelper();
58 mozilla::ScrollbarStyles GetScrollbarStylesFromFrame() const;
60 // If a child frame was added or removed on the scrollframe,
61 // reload our child frame list.
62 // We need this if a scrollbar frame is recreated.
63 void ReloadChildFrames();
65 nsresult CreateAnonymousContent(
66 nsTArray<nsIAnonymousContentCreator::ContentInfo>& aElements);
67 void AppendAnonymousContentTo(nsTArray<nsIContent*>& aElements, uint32_t aFilter);
68 nsresult FireScrollPortEvent();
69 void PostOverflowEvent();
70 void Destroy();
72 void BuildDisplayList(nsDisplayListBuilder* aBuilder,
73 const nsRect& aDirtyRect,
74 const nsDisplayListSet& aLists);
76 void AppendScrollPartsTo(nsDisplayListBuilder* aBuilder,
77 const nsRect& aDirtyRect,
78 const nsDisplayListSet& aLists,
79 bool aUsingDisplayPort,
80 bool aCreateLayer,
81 bool aPositioned);
83 bool GetBorderRadii(const nsSize& aFrameSize, const nsSize& aBorderArea,
84 Sides aSkipSides, nscoord aRadii[8]) const;
86 // nsIReflowCallback
87 virtual bool ReflowFinished() MOZ_OVERRIDE;
88 virtual void ReflowCallbackCanceled() MOZ_OVERRIDE;
90 /**
91 * @note This method might destroy the frame, pres shell and other objects.
92 * Called when the 'curpos' attribute on one of the scrollbars changes.
94 void CurPosAttributeChanged(nsIContent* aChild);
96 void PostScrollEvent();
97 void FireScrollEvent();
98 void PostScrolledAreaEvent();
99 void FireScrolledAreaEvent();
101 class ScrollEvent : public nsRunnable {
102 public:
103 NS_DECL_NSIRUNNABLE
104 explicit ScrollEvent(ScrollFrameHelper *helper) : mHelper(helper) {}
105 void Revoke() { mHelper = nullptr; }
106 private:
107 ScrollFrameHelper *mHelper;
110 class AsyncScrollPortEvent : public nsRunnable {
111 public:
112 NS_DECL_NSIRUNNABLE
113 explicit AsyncScrollPortEvent(ScrollFrameHelper *helper) : mHelper(helper) {}
114 void Revoke() { mHelper = nullptr; }
115 private:
116 ScrollFrameHelper *mHelper;
119 class ScrolledAreaEvent : public nsRunnable {
120 public:
121 NS_DECL_NSIRUNNABLE
122 explicit ScrolledAreaEvent(ScrollFrameHelper *helper) : mHelper(helper) {}
123 void Revoke() { mHelper = nullptr; }
124 private:
125 ScrollFrameHelper *mHelper;
129 * @note This method might destroy the frame, pres shell and other objects.
131 void FinishReflowForScrollbar(nsIContent* aContent, nscoord aMinXY,
132 nscoord aMaxXY, nscoord aCurPosXY,
133 nscoord aPageIncrement,
134 nscoord aIncrement);
136 * @note This method might destroy the frame, pres shell and other objects.
138 void SetScrollbarEnabled(nsIContent* aContent, nscoord aMaxPos);
140 * @note This method might destroy the frame, pres shell and other objects.
142 void SetCoordAttribute(nsIContent* aContent, nsIAtom* aAtom, nscoord aSize);
144 nscoord GetCoordAttribute(nsIFrame* aFrame, nsIAtom* aAtom, nscoord aDefaultValue,
145 nscoord* aRangeStart, nscoord* aRangeLength);
148 * @note This method might destroy the frame, pres shell and other objects.
149 * Update scrollbar curpos attributes to reflect current scroll position
151 void UpdateScrollbarPosition();
153 nsRect GetScrollPortRect() const { return mScrollPort; }
154 nsPoint GetScrollPosition() const {
155 return mScrollPort.TopLeft() - mScrolledFrame->GetPosition();
158 * For LTR frames, the logical scroll position is the offset of the top left
159 * corner of the frame from the top left corner of the scroll port (same as
160 * GetScrollPosition).
161 * For RTL frames, it is the offset of the top right corner of the frame from
162 * the top right corner of the scroll port
164 nsPoint GetLogicalScrollPosition() const {
165 nsPoint pt;
166 pt.x = IsLTR() ?
167 mScrollPort.x - mScrolledFrame->GetPosition().x :
168 mScrollPort.XMost() - mScrolledFrame->GetRect().XMost();
169 pt.y = mScrollPort.y - mScrolledFrame->GetPosition().y;
170 return pt;
172 nsRect GetScrollRange() const;
173 // Get the scroll range assuming the scrollport has size (aWidth, aHeight).
174 nsRect GetScrollRange(nscoord aWidth, nscoord aHeight) const;
175 nsSize GetScrollPositionClampingScrollPortSize() const;
176 gfxSize GetResolution() const;
177 void SetResolution(const gfxSize& aResolution);
179 protected:
180 nsRect GetScrollRangeForClamping() const;
182 public:
183 static void AsyncScrollCallback(ScrollFrameHelper* aInstance,
184 mozilla::TimeStamp aTime);
185 static void AsyncSmoothMSDScrollCallback(ScrollFrameHelper* aInstance,
186 mozilla::TimeDuration aDeltaTime);
188 * @note This method might destroy the frame, pres shell and other objects.
189 * aRange is the range of allowable scroll positions around the desired
190 * aScrollPosition. Null means only aScrollPosition is allowed.
191 * This is a closed-ended range --- aRange.XMost()/aRange.YMost() are allowed.
193 void ScrollTo(nsPoint aScrollPosition, nsIScrollableFrame::ScrollMode aMode,
194 const nsRect* aRange = nullptr) {
195 ScrollToWithOrigin(aScrollPosition, aMode, nsGkAtoms::other, aRange);
198 * @note This method might destroy the frame, pres shell and other objects.
200 void ScrollToCSSPixels(const CSSIntPoint& aScrollPosition,
201 nsIScrollableFrame::ScrollMode aMode
202 = nsIScrollableFrame::INSTANT);
204 * @note This method might destroy the frame, pres shell and other objects.
206 void ScrollToCSSPixelsApproximate(const mozilla::CSSPoint& aScrollPosition,
207 nsIAtom* aOrigin = nullptr);
209 CSSIntPoint GetScrollPositionCSSPixels();
211 * @note This method might destroy the frame, pres shell and other objects.
213 void ScrollToImpl(nsPoint aScrollPosition, const nsRect& aRange, nsIAtom* aOrigin = nullptr);
214 void ScrollVisual(nsPoint aOldScrolledFramePosition);
216 * @note This method might destroy the frame, pres shell and other objects.
218 void ScrollBy(nsIntPoint aDelta, nsIScrollableFrame::ScrollUnit aUnit,
219 nsIScrollableFrame::ScrollMode aMode, nsIntPoint* aOverflow,
220 nsIAtom* aOrigin = nullptr, bool aIsMomentum = false);
222 * @note This method might destroy the frame, pres shell and other objects.
224 void ScrollToRestoredPosition();
226 nsSize GetLineScrollAmount() const;
227 nsSize GetPageScrollAmount() const;
229 nsPresState* SaveState() const;
230 void RestoreState(nsPresState* aState);
232 nsIFrame* GetScrolledFrame() const { return mScrolledFrame; }
233 nsIFrame* GetScrollbarBox(bool aVertical) const {
234 return aVertical ? mVScrollbarBox : mHScrollbarBox;
237 void AddScrollPositionListener(nsIScrollPositionListener* aListener) {
238 mListeners.AppendElement(aListener);
240 void RemoveScrollPositionListener(nsIScrollPositionListener* aListener) {
241 mListeners.RemoveElement(aListener);
244 static void SetScrollbarVisibility(nsIFrame* aScrollbar, bool aVisible);
247 * GetScrolledRect is designed to encapsulate deciding which
248 * directions of overflow should be reachable by scrolling and which
249 * should not. Callers should NOT depend on it having any particular
250 * behavior (although nsXULScrollFrame currently does).
252 * This should only be called when the scrolled frame has been
253 * reflowed with the scroll port size given in mScrollPort.
255 * Currently it allows scrolling down and to the right for
256 * nsHTMLScrollFrames with LTR directionality and for all
257 * nsXULScrollFrames, and allows scrolling down and to the left for
258 * nsHTMLScrollFrames with RTL directionality.
260 nsRect GetScrolledRect() const;
263 * GetScrolledRectInternal is designed to encapsulate deciding which
264 * directions of overflow should be reachable by scrolling and which
265 * should not. Callers should NOT depend on it having any particular
266 * behavior (although nsXULScrollFrame currently does).
268 * Currently it allows scrolling down and to the right for
269 * nsHTMLScrollFrames with LTR directionality and for all
270 * nsXULScrollFrames, and allows scrolling down and to the left for
271 * nsHTMLScrollFrames with RTL directionality.
273 nsRect GetScrolledRectInternal(const nsRect& aScrolledOverflowArea,
274 const nsSize& aScrollPortSize) const;
276 uint32_t GetScrollbarVisibility() const {
277 return (mHasVerticalScrollbar ? nsIScrollableFrame::VERTICAL : 0) |
278 (mHasHorizontalScrollbar ? nsIScrollableFrame::HORIZONTAL : 0);
280 nsMargin GetActualScrollbarSizes() const;
281 nsMargin GetDesiredScrollbarSizes(nsBoxLayoutState* aState);
282 nscoord GetNondisappearingScrollbarWidth(nsBoxLayoutState* aState);
283 bool IsLTR() const;
284 bool IsScrollbarOnRight() const;
285 bool IsScrollingActive() const { return mScrollingActive || mShouldBuildScrollableLayer; }
286 bool IsProcessingAsyncScroll() const {
287 return mAsyncScroll != nullptr || mAsyncSmoothMSDScroll != nullptr;
289 void ResetScrollPositionForLayerPixelAlignment()
291 mScrollPosForLayerPixelAlignment = GetScrollPosition();
294 bool UpdateOverflow();
296 void UpdateSticky();
298 bool IsRectNearlyVisible(const nsRect& aRect) const;
299 nsRect ExpandRectToNearlyVisible(const nsRect& aRect) const;
301 // adjust the scrollbar rectangle aRect to account for any visible resizer.
302 // aHasResizer specifies if there is a content resizer, however this method
303 // will also check if a widget resizer is present as well.
304 void AdjustScrollbarRectForResizer(nsIFrame* aFrame, nsPresContext* aPresContext,
305 nsRect& aRect, bool aHasResizer, bool aVertical);
306 // returns true if a resizer should be visible
307 bool HasResizer() { return mResizerBox && !mCollapsedResizer; }
308 void LayoutScrollbars(nsBoxLayoutState& aState,
309 const nsRect& aContentArea,
310 const nsRect& aOldScrollArea);
312 bool IsIgnoringViewportClipping() const;
314 void MarkScrollbarsDirtyForReflow() const;
316 bool ShouldClampScrollPosition() const;
318 bool IsAlwaysActive() const;
319 void MarkActive();
320 void MarkInactive();
321 nsExpirationState* GetExpirationState() { return &mActivityExpirationState; }
323 void ScheduleSyntheticMouseMove();
324 static void ScrollActivityCallback(nsITimer *aTimer, void* anInstance);
326 void HandleScrollbarStyleSwitching();
328 nsIAtom* OriginOfLastScroll() const { return mOriginOfLastScroll; }
329 uint32_t CurrentScrollGeneration() const { return mScrollGeneration; }
330 void ResetOriginIfScrollAtGeneration(uint32_t aGeneration) {
331 if (aGeneration == mScrollGeneration) {
332 mOriginOfLastScroll = nullptr;
335 bool WantAsyncScroll() const;
336 void ComputeFrameMetrics(Layer* aLayer, nsIFrame* aContainerReferenceFrame,
337 const ContainerLayerParameters& aParameters,
338 nsRect* aClipRect,
339 nsTArray<FrameMetrics>* aOutput) const;
341 // nsIScrollbarMediator
342 void ScrollByPage(nsScrollbarFrame* aScrollbar, int32_t aDirection);
343 void ScrollByWhole(nsScrollbarFrame* aScrollbar, int32_t aDirection);
344 void ScrollByLine(nsScrollbarFrame* aScrollbar, int32_t aDirection);
345 void RepeatButtonScroll(nsScrollbarFrame* aScrollbar);
346 void ThumbMoved(nsScrollbarFrame* aScrollbar,
347 nscoord aOldPos,
348 nscoord aNewPos);
349 void ScrollByUnit(nsScrollbarFrame* aScrollbar,
350 nsIScrollableFrame::ScrollMode aMode,
351 int32_t aDirection,
352 nsIScrollableFrame::ScrollUnit aUnit);
354 // owning references to the nsIAnonymousContentCreator-built content
355 nsCOMPtr<nsIContent> mHScrollbarContent;
356 nsCOMPtr<nsIContent> mVScrollbarContent;
357 nsCOMPtr<nsIContent> mScrollCornerContent;
358 nsCOMPtr<nsIContent> mResizerContent;
360 nsRevocableEventPtr<ScrollEvent> mScrollEvent;
361 nsRevocableEventPtr<AsyncScrollPortEvent> mAsyncScrollPortEvent;
362 nsRevocableEventPtr<ScrolledAreaEvent> mScrolledAreaEvent;
363 nsIFrame* mHScrollbarBox;
364 nsIFrame* mVScrollbarBox;
365 nsIFrame* mScrolledFrame;
366 nsIFrame* mScrollCornerBox;
367 nsIFrame* mResizerBox;
368 nsContainerFrame* mOuter;
369 nsRefPtr<AsyncScroll> mAsyncScroll;
370 nsRefPtr<AsyncSmoothMSDScroll> mAsyncSmoothMSDScroll;
371 nsRefPtr<ScrollbarActivity> mScrollbarActivity;
372 nsTArray<nsIScrollPositionListener*> mListeners;
373 nsIAtom* mOriginOfLastScroll;
374 uint32_t mScrollGeneration;
375 nsRect mScrollPort;
376 // Where we're currently scrolling to, if we're scrolling asynchronously.
377 // If we're not in the middle of an asynchronous scroll then this is
378 // just the current scroll position. ScrollBy will choose its
379 // destination based on this value.
380 nsPoint mDestination;
381 nsPoint mScrollPosAtLastPaint;
383 // A goal position to try to scroll to as content loads. As long as mLastPos
384 // matches the current logical scroll position, we try to scroll to mRestorePos
385 // after every reflow --- because after each time content is loaded/added to the
386 // scrollable element, there will be a reflow.
387 nsPoint mRestorePos;
388 // The last logical position we scrolled to while trying to restore mRestorePos, or
389 // 0,0 when this is a new frame. Set to -1,-1 once we've scrolled for any reason
390 // other than trying to restore mRestorePos.
391 nsPoint mLastPos;
393 // The current resolution derived from the zoom level and device pixel ratio.
394 gfxSize mResolution;
396 nsExpirationState mActivityExpirationState;
398 nsCOMPtr<nsITimer> mScrollActivityTimer;
399 nsPoint mScrollPosForLayerPixelAlignment;
401 // The scroll position where we last updated image visibility.
402 nsPoint mLastUpdateImagesPos;
404 FrameMetrics::ViewID mScrollParentID;
406 bool mNeverHasVerticalScrollbar:1;
407 bool mNeverHasHorizontalScrollbar:1;
408 bool mHasVerticalScrollbar:1;
409 bool mHasHorizontalScrollbar:1;
410 bool mFrameIsUpdatingScrollbar:1;
411 bool mDidHistoryRestore:1;
412 // Is this the scrollframe for the document's viewport?
413 bool mIsRoot:1;
414 // True if we should clip all descendants, false if we should only clip
415 // descendants for which we are the containing block.
416 bool mClipAllDescendants:1;
417 // If true, don't try to layout the scrollbars in Reflow(). This can be
418 // useful if multiple passes are involved, because we don't want to place the
419 // scrollbars at the wrong size.
420 bool mSupppressScrollbarUpdate:1;
421 // If true, we skipped a scrollbar layout due to mSupppressScrollbarUpdate
422 // being set at some point. That means we should lay out scrollbars even if
423 // it might not strictly be needed next time mSupppressScrollbarUpdate is
424 // false.
425 bool mSkippedScrollbarLayout:1;
427 bool mHadNonInitialReflow:1;
428 // State used only by PostScrollEvents so we know
429 // which overflow states have changed.
430 bool mHorizontalOverflow:1;
431 bool mVerticalOverflow:1;
432 bool mPostedReflowCallback:1;
433 bool mMayHaveDirtyFixedChildren:1;
434 // If true, need to actually update our scrollbar attributes in the
435 // reflow callback.
436 bool mUpdateScrollbarAttributes:1;
437 // If true, we should be prepared to scroll using this scrollframe
438 // by placing descendant content into its own layer(s)
439 bool mScrollingActive:1;
440 // If true, the resizer is collapsed and not displayed
441 bool mCollapsedResizer:1;
443 // If true, the layer should always be active because we always build a
444 // scrollable layer. Used for asynchronous scrolling.
445 bool mShouldBuildScrollableLayer:1;
446 // If true, add clipping in ScrollFrameHelper::ComputeFrameMetrics.
447 bool mAddClipRectToLayer:1;
449 // True if this frame has been scrolled at least once
450 bool mHasBeenScrolled:1;
452 // True if the frame's resolution has been set via SetResolution or restored
453 // via RestoreState.
454 bool mIsResolutionSet:1;
456 protected:
458 * @note This method might destroy the frame, pres shell and other objects.
460 void ScrollToWithOrigin(nsPoint aScrollPosition,
461 nsIScrollableFrame::ScrollMode aMode,
462 nsIAtom *aOrigin, // nullptr indicates "other" origin
463 const nsRect* aRange);
465 void CompleteAsyncScroll(const nsRect &aRange, nsIAtom* aOrigin = nullptr);
467 static void EnsureImageVisPrefsCached();
468 static bool sImageVisPrefsCached;
469 // The number of scrollports wide/high to expand when looking for images.
470 static uint32_t sHorzExpandScrollPort;
471 static uint32_t sVertExpandScrollPort;
472 // The fraction of the scrollport we allow to scroll by before we schedule
473 // an update of image visibility.
474 static int32_t sHorzScrollFraction;
475 static int32_t sVertScrollFraction;
481 * The scroll frame creates and manages the scrolling view
483 * It only supports having a single child frame that typically is an area
484 * frame, but doesn't have to be. The child frame must have a view, though
486 * Scroll frames don't support incremental changes, i.e. you can't replace
487 * or remove the scrolled frame
489 class nsHTMLScrollFrame : public nsContainerFrame,
490 public nsIScrollableFrame,
491 public nsIAnonymousContentCreator,
492 public nsIStatefulFrame {
493 public:
494 typedef mozilla::ScrollFrameHelper ScrollFrameHelper;
495 typedef mozilla::CSSIntPoint CSSIntPoint;
496 friend nsHTMLScrollFrame* NS_NewHTMLScrollFrame(nsIPresShell* aPresShell,
497 nsStyleContext* aContext,
498 bool aIsRoot);
500 NS_DECL_QUERYFRAME
501 NS_DECL_FRAMEARENA_HELPERS
503 virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder,
504 const nsRect& aDirtyRect,
505 const nsDisplayListSet& aLists) MOZ_OVERRIDE {
506 mHelper.BuildDisplayList(aBuilder, aDirtyRect, aLists);
509 bool TryLayout(ScrollReflowState* aState,
510 nsHTMLReflowMetrics* aKidMetrics,
511 bool aAssumeVScroll, bool aAssumeHScroll,
512 bool aForce);
513 bool ScrolledContentDependsOnHeight(ScrollReflowState* aState);
514 void ReflowScrolledFrame(ScrollReflowState* aState,
515 bool aAssumeHScroll,
516 bool aAssumeVScroll,
517 nsHTMLReflowMetrics* aMetrics,
518 bool aFirstPass);
519 void ReflowContents(ScrollReflowState* aState,
520 const nsHTMLReflowMetrics& aDesiredSize);
521 void PlaceScrollArea(const ScrollReflowState& aState,
522 const nsPoint& aScrollPosition);
523 nscoord GetIntrinsicVScrollbarWidth(nsRenderingContext *aRenderingContext);
525 virtual bool GetBorderRadii(const nsSize& aFrameSize, const nsSize& aBorderArea,
526 Sides aSkipSides, nscoord aRadii[8]) const MOZ_OVERRIDE {
527 return mHelper.GetBorderRadii(aFrameSize, aBorderArea, aSkipSides, aRadii);
530 virtual nscoord GetMinISize(nsRenderingContext *aRenderingContext) MOZ_OVERRIDE;
531 virtual nscoord GetPrefISize(nsRenderingContext *aRenderingContext) MOZ_OVERRIDE;
532 virtual nsresult GetPadding(nsMargin& aPadding) MOZ_OVERRIDE;
533 virtual bool IsCollapsed() MOZ_OVERRIDE;
535 virtual void Reflow(nsPresContext* aPresContext,
536 nsHTMLReflowMetrics& aDesiredSize,
537 const nsHTMLReflowState& aReflowState,
538 nsReflowStatus& aStatus) MOZ_OVERRIDE;
540 virtual bool UpdateOverflow() MOZ_OVERRIDE {
541 return mHelper.UpdateOverflow();
544 // Called to set the child frames. We typically have three: the scroll area,
545 // the vertical scrollbar, and the horizontal scrollbar.
546 virtual void SetInitialChildList(ChildListID aListID,
547 nsFrameList& aChildList) MOZ_OVERRIDE;
548 virtual void AppendFrames(ChildListID aListID,
549 nsFrameList& aFrameList) MOZ_OVERRIDE;
550 virtual void InsertFrames(ChildListID aListID,
551 nsIFrame* aPrevFrame,
552 nsFrameList& aFrameList) MOZ_OVERRIDE;
553 virtual void RemoveFrame(ChildListID aListID,
554 nsIFrame* aOldFrame) MOZ_OVERRIDE;
556 virtual void DestroyFrom(nsIFrame* aDestructRoot) MOZ_OVERRIDE;
558 virtual nsIScrollableFrame* GetScrollTargetFrame() MOZ_OVERRIDE {
559 return this;
562 virtual nsContainerFrame* GetContentInsertionFrame() MOZ_OVERRIDE {
563 return mHelper.GetScrolledFrame()->GetContentInsertionFrame();
566 virtual bool DoesClipChildren() MOZ_OVERRIDE { return true; }
567 virtual nsSplittableType GetSplittableType() const MOZ_OVERRIDE;
569 virtual nsPoint GetPositionOfChildIgnoringScrolling(nsIFrame* aChild) MOZ_OVERRIDE
570 { nsPoint pt = aChild->GetPosition();
571 if (aChild == mHelper.GetScrolledFrame()) pt += GetScrollPosition();
572 return pt;
575 // nsIAnonymousContentCreator
576 virtual nsresult CreateAnonymousContent(nsTArray<ContentInfo>& aElements) MOZ_OVERRIDE;
577 virtual void AppendAnonymousContentTo(nsTArray<nsIContent*>& aElements,
578 uint32_t aFilter) MOZ_OVERRIDE;
580 // nsIScrollableFrame
581 virtual nsIFrame* GetScrolledFrame() const MOZ_OVERRIDE {
582 return mHelper.GetScrolledFrame();
584 virtual mozilla::ScrollbarStyles GetScrollbarStyles() const MOZ_OVERRIDE {
585 return mHelper.GetScrollbarStylesFromFrame();
587 virtual uint32_t GetScrollbarVisibility() const MOZ_OVERRIDE {
588 return mHelper.GetScrollbarVisibility();
590 virtual nsMargin GetActualScrollbarSizes() const MOZ_OVERRIDE {
591 return mHelper.GetActualScrollbarSizes();
593 virtual nsMargin GetDesiredScrollbarSizes(nsBoxLayoutState* aState) MOZ_OVERRIDE {
594 return mHelper.GetDesiredScrollbarSizes(aState);
596 virtual nsMargin GetDesiredScrollbarSizes(nsPresContext* aPresContext,
597 nsRenderingContext* aRC) MOZ_OVERRIDE {
598 nsBoxLayoutState bls(aPresContext, aRC, 0);
599 return GetDesiredScrollbarSizes(&bls);
601 virtual nscoord GetNondisappearingScrollbarWidth(nsPresContext* aPresContext,
602 nsRenderingContext* aRC) MOZ_OVERRIDE {
603 nsBoxLayoutState bls(aPresContext, aRC, 0);
604 return mHelper.GetNondisappearingScrollbarWidth(&bls);
606 virtual nsRect GetScrolledRect() const MOZ_OVERRIDE {
607 return mHelper.GetScrolledRect();
609 virtual nsRect GetScrollPortRect() const MOZ_OVERRIDE {
610 return mHelper.GetScrollPortRect();
612 virtual nsPoint GetScrollPosition() const MOZ_OVERRIDE {
613 return mHelper.GetScrollPosition();
615 virtual nsPoint GetLogicalScrollPosition() const MOZ_OVERRIDE {
616 return mHelper.GetLogicalScrollPosition();
618 virtual nsRect GetScrollRange() const MOZ_OVERRIDE {
619 return mHelper.GetScrollRange();
621 virtual nsSize GetScrollPositionClampingScrollPortSize() const MOZ_OVERRIDE {
622 return mHelper.GetScrollPositionClampingScrollPortSize();
624 virtual gfxSize GetResolution() const MOZ_OVERRIDE {
625 return mHelper.GetResolution();
627 virtual void SetResolution(const gfxSize& aResolution) MOZ_OVERRIDE {
628 return mHelper.SetResolution(aResolution);
630 virtual nsSize GetLineScrollAmount() const MOZ_OVERRIDE {
631 return mHelper.GetLineScrollAmount();
633 virtual nsSize GetPageScrollAmount() const MOZ_OVERRIDE {
634 return mHelper.GetPageScrollAmount();
637 * @note This method might destroy the frame, pres shell and other objects.
639 virtual void ScrollTo(nsPoint aScrollPosition, ScrollMode aMode,
640 const nsRect* aRange = nullptr) MOZ_OVERRIDE {
641 mHelper.ScrollTo(aScrollPosition, aMode, aRange);
644 * @note This method might destroy the frame, pres shell and other objects.
646 virtual void ScrollToCSSPixels(const CSSIntPoint& aScrollPosition,
647 nsIScrollableFrame::ScrollMode aMode
648 = nsIScrollableFrame::INSTANT) MOZ_OVERRIDE {
649 mHelper.ScrollToCSSPixels(aScrollPosition, aMode);
651 virtual void ScrollToCSSPixelsApproximate(const mozilla::CSSPoint& aScrollPosition,
652 nsIAtom* aOrigin = nullptr) MOZ_OVERRIDE {
653 mHelper.ScrollToCSSPixelsApproximate(aScrollPosition, aOrigin);
656 * @note This method might destroy the frame, pres shell and other objects.
658 virtual CSSIntPoint GetScrollPositionCSSPixels() MOZ_OVERRIDE {
659 return mHelper.GetScrollPositionCSSPixels();
662 * @note This method might destroy the frame, pres shell and other objects.
664 virtual void ScrollBy(nsIntPoint aDelta, ScrollUnit aUnit, ScrollMode aMode,
665 nsIntPoint* aOverflow, nsIAtom* aOrigin = nullptr,
666 bool aIsMomentum = false) MOZ_OVERRIDE {
667 mHelper.ScrollBy(aDelta, aUnit, aMode, aOverflow, aOrigin, aIsMomentum);
670 * @note This method might destroy the frame, pres shell and other objects.
672 virtual void ScrollToRestoredPosition() MOZ_OVERRIDE {
673 mHelper.ScrollToRestoredPosition();
675 virtual void AddScrollPositionListener(nsIScrollPositionListener* aListener) MOZ_OVERRIDE {
676 mHelper.AddScrollPositionListener(aListener);
678 virtual void RemoveScrollPositionListener(nsIScrollPositionListener* aListener) MOZ_OVERRIDE {
679 mHelper.RemoveScrollPositionListener(aListener);
682 * @note This method might destroy the frame, pres shell and other objects.
684 virtual void CurPosAttributeChanged(nsIContent* aChild) MOZ_OVERRIDE {
685 mHelper.CurPosAttributeChanged(aChild);
687 NS_IMETHOD PostScrolledAreaEventForCurrentArea() MOZ_OVERRIDE {
688 mHelper.PostScrolledAreaEvent();
689 return NS_OK;
691 virtual bool IsScrollingActive() MOZ_OVERRIDE {
692 return mHelper.IsScrollingActive();
694 virtual bool IsProcessingAsyncScroll() MOZ_OVERRIDE {
695 return mHelper.IsProcessingAsyncScroll();
697 virtual void ResetScrollPositionForLayerPixelAlignment() MOZ_OVERRIDE {
698 mHelper.ResetScrollPositionForLayerPixelAlignment();
700 virtual bool IsResolutionSet() const MOZ_OVERRIDE {
701 return mHelper.mIsResolutionSet;
703 virtual bool DidHistoryRestore() const MOZ_OVERRIDE {
704 return mHelper.mDidHistoryRestore;
706 virtual void ClearDidHistoryRestore() MOZ_OVERRIDE {
707 mHelper.mDidHistoryRestore = false;
709 virtual bool IsRectNearlyVisible(const nsRect& aRect) MOZ_OVERRIDE {
710 return mHelper.IsRectNearlyVisible(aRect);
712 virtual nsRect ExpandRectToNearlyVisible(const nsRect& aRect) const MOZ_OVERRIDE {
713 return mHelper.ExpandRectToNearlyVisible(aRect);
715 virtual nsIAtom* OriginOfLastScroll() MOZ_OVERRIDE {
716 return mHelper.OriginOfLastScroll();
718 virtual uint32_t CurrentScrollGeneration() MOZ_OVERRIDE {
719 return mHelper.CurrentScrollGeneration();
721 virtual void ResetOriginIfScrollAtGeneration(uint32_t aGeneration) MOZ_OVERRIDE {
722 mHelper.ResetOriginIfScrollAtGeneration(aGeneration);
724 virtual bool WantAsyncScroll() const MOZ_OVERRIDE {
725 return mHelper.WantAsyncScroll();
727 virtual void ComputeFrameMetrics(Layer* aLayer, nsIFrame* aContainerReferenceFrame,
728 const ContainerLayerParameters& aParameters,
729 nsRect* aClipRect,
730 nsTArray<FrameMetrics>* aOutput) const MOZ_OVERRIDE {
731 mHelper.ComputeFrameMetrics(aLayer, aContainerReferenceFrame,
732 aParameters, aClipRect, aOutput);
734 virtual void MarkScrollbarsDirtyForReflow() const MOZ_OVERRIDE {
735 mHelper.MarkScrollbarsDirtyForReflow();
738 // nsIStatefulFrame
739 NS_IMETHOD SaveState(nsPresState** aState) MOZ_OVERRIDE {
740 NS_ENSURE_ARG_POINTER(aState);
741 *aState = mHelper.SaveState();
742 return NS_OK;
744 NS_IMETHOD RestoreState(nsPresState* aState) MOZ_OVERRIDE {
745 NS_ENSURE_ARG_POINTER(aState);
746 mHelper.RestoreState(aState);
747 return NS_OK;
751 * Get the "type" of the frame
753 * @see nsGkAtoms::scrollFrame
755 virtual nsIAtom* GetType() const MOZ_OVERRIDE;
757 // nsIScrollbarMediator
758 virtual void ScrollByPage(nsScrollbarFrame* aScrollbar, int32_t aDirection) MOZ_OVERRIDE {
759 mHelper.ScrollByPage(aScrollbar, aDirection);
761 virtual void ScrollByWhole(nsScrollbarFrame* aScrollbar, int32_t aDirection) MOZ_OVERRIDE {
762 mHelper.ScrollByWhole(aScrollbar, aDirection);
764 virtual void ScrollByLine(nsScrollbarFrame* aScrollbar, int32_t aDirection) MOZ_OVERRIDE {
765 mHelper.ScrollByLine(aScrollbar, aDirection);
767 virtual void RepeatButtonScroll(nsScrollbarFrame* aScrollbar) MOZ_OVERRIDE {
768 mHelper.RepeatButtonScroll(aScrollbar);
770 virtual void ThumbMoved(nsScrollbarFrame* aScrollbar,
771 nscoord aOldPos,
772 nscoord aNewPos) MOZ_OVERRIDE {
773 mHelper.ThumbMoved(aScrollbar, aOldPos, aNewPos);
775 virtual void VisibilityChanged(bool aVisible) {}
776 virtual nsIFrame* GetScrollbarBox(bool aVertical) MOZ_OVERRIDE {
777 return mHelper.GetScrollbarBox(aVertical);
779 virtual void ScrollbarActivityStarted() const MOZ_OVERRIDE;
780 virtual void ScrollbarActivityStopped() const MOZ_OVERRIDE;
782 #ifdef DEBUG_FRAME_DUMP
783 virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE;
784 #endif
786 #ifdef ACCESSIBILITY
787 virtual mozilla::a11y::AccType AccessibleType() MOZ_OVERRIDE;
788 #endif
790 protected:
791 nsHTMLScrollFrame(nsIPresShell* aShell, nsStyleContext* aContext, bool aIsRoot);
792 void SetSuppressScrollbarUpdate(bool aSuppress) {
793 mHelper.mSupppressScrollbarUpdate = aSuppress;
795 bool GuessHScrollbarNeeded(const ScrollReflowState& aState);
796 bool GuessVScrollbarNeeded(const ScrollReflowState& aState);
798 bool IsScrollbarUpdateSuppressed() const {
799 return mHelper.mSupppressScrollbarUpdate;
802 // Return whether we're in an "initial" reflow. Some reflows with
803 // NS_FRAME_FIRST_REFLOW set are NOT "initial" as far as we're concerned.
804 bool InInitialReflow() const;
807 * Override this to return false if computed height/min-height/max-height
808 * should NOT be propagated to child content.
809 * nsListControlFrame uses this.
811 virtual bool ShouldPropagateComputedHeightToScrolledContent() const { return true; }
813 private:
814 friend class mozilla::ScrollFrameHelper;
815 ScrollFrameHelper mHelper;
819 * The scroll frame creates and manages the scrolling view
821 * It only supports having a single child frame that typically is an area
822 * frame, but doesn't have to be. The child frame must have a view, though
824 * Scroll frames don't support incremental changes, i.e. you can't replace
825 * or remove the scrolled frame
827 class nsXULScrollFrame MOZ_FINAL : public nsBoxFrame,
828 public nsIScrollableFrame,
829 public nsIAnonymousContentCreator,
830 public nsIStatefulFrame {
831 public:
832 typedef mozilla::ScrollFrameHelper ScrollFrameHelper;
833 typedef mozilla::CSSIntPoint CSSIntPoint;
835 NS_DECL_QUERYFRAME
836 NS_DECL_FRAMEARENA_HELPERS
838 friend nsXULScrollFrame* NS_NewXULScrollFrame(nsIPresShell* aPresShell,
839 nsStyleContext* aContext,
840 bool aIsRoot,
841 bool aClipAllDescendants);
843 virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder,
844 const nsRect& aDirtyRect,
845 const nsDisplayListSet& aLists) MOZ_OVERRIDE {
846 mHelper.BuildDisplayList(aBuilder, aDirtyRect, aLists);
849 // XXXldb Is this actually used?
850 #if 0
851 virtual nscoord GetMinISize(nsRenderingContext *aRenderingContext) MOZ_OVERRIDE;
852 #endif
854 virtual bool UpdateOverflow() MOZ_OVERRIDE {
855 return mHelper.UpdateOverflow();
858 // Called to set the child frames. We typically have three: the scroll area,
859 // the vertical scrollbar, and the horizontal scrollbar.
860 virtual void SetInitialChildList(ChildListID aListID,
861 nsFrameList& aChildList) MOZ_OVERRIDE;
862 virtual void AppendFrames(ChildListID aListID,
863 nsFrameList& aFrameList) MOZ_OVERRIDE;
864 virtual void InsertFrames(ChildListID aListID,
865 nsIFrame* aPrevFrame,
866 nsFrameList& aFrameList) MOZ_OVERRIDE;
867 virtual void RemoveFrame(ChildListID aListID,
868 nsIFrame* aOldFrame) MOZ_OVERRIDE;
870 virtual void DestroyFrom(nsIFrame* aDestructRoot) MOZ_OVERRIDE;
873 virtual nsIScrollableFrame* GetScrollTargetFrame() MOZ_OVERRIDE {
874 return this;
877 virtual nsContainerFrame* GetContentInsertionFrame() MOZ_OVERRIDE {
878 return mHelper.GetScrolledFrame()->GetContentInsertionFrame();
881 virtual bool DoesClipChildren() MOZ_OVERRIDE { return true; }
882 virtual nsSplittableType GetSplittableType() const MOZ_OVERRIDE;
884 virtual nsPoint GetPositionOfChildIgnoringScrolling(nsIFrame* aChild) MOZ_OVERRIDE
885 { nsPoint pt = aChild->GetPosition();
886 if (aChild == mHelper.GetScrolledFrame())
887 pt += mHelper.GetLogicalScrollPosition();
888 return pt;
891 // nsIAnonymousContentCreator
892 virtual nsresult CreateAnonymousContent(nsTArray<ContentInfo>& aElements) MOZ_OVERRIDE;
893 virtual void AppendAnonymousContentTo(nsTArray<nsIContent*>& aElements,
894 uint32_t aFilter) MOZ_OVERRIDE;
896 virtual nsSize GetMinSize(nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE;
897 virtual nsSize GetPrefSize(nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE;
898 virtual nsSize GetMaxSize(nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE;
899 virtual nscoord GetBoxAscent(nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE;
901 NS_IMETHOD DoLayout(nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE;
902 virtual nsresult GetPadding(nsMargin& aPadding) MOZ_OVERRIDE;
904 virtual bool GetBorderRadii(const nsSize& aFrameSize, const nsSize& aBorderArea,
905 Sides aSkipSides, nscoord aRadii[8]) const MOZ_OVERRIDE {
906 return mHelper.GetBorderRadii(aFrameSize, aBorderArea, aSkipSides, aRadii);
909 nsresult Layout(nsBoxLayoutState& aState);
910 void LayoutScrollArea(nsBoxLayoutState& aState, const nsPoint& aScrollPosition);
912 static bool AddRemoveScrollbar(bool& aHasScrollbar,
913 nscoord& aXY,
914 nscoord& aSize,
915 nscoord aSbSize,
916 bool aOnRightOrBottom,
917 bool aAdd);
919 bool AddRemoveScrollbar(nsBoxLayoutState& aState,
920 bool aOnRightOrBottom,
921 bool aHorizontal,
922 bool aAdd);
924 bool AddHorizontalScrollbar (nsBoxLayoutState& aState, bool aOnBottom);
925 bool AddVerticalScrollbar (nsBoxLayoutState& aState, bool aOnRight);
926 void RemoveHorizontalScrollbar(nsBoxLayoutState& aState, bool aOnBottom);
927 void RemoveVerticalScrollbar (nsBoxLayoutState& aState, bool aOnRight);
929 static void AdjustReflowStateForPrintPreview(nsBoxLayoutState& aState, bool& aSetBack);
930 static void AdjustReflowStateBack(nsBoxLayoutState& aState, bool aSetBack);
932 // nsIScrollableFrame
933 virtual nsIFrame* GetScrolledFrame() const MOZ_OVERRIDE {
934 return mHelper.GetScrolledFrame();
936 virtual mozilla::ScrollbarStyles GetScrollbarStyles() const MOZ_OVERRIDE {
937 return mHelper.GetScrollbarStylesFromFrame();
939 virtual uint32_t GetScrollbarVisibility() const MOZ_OVERRIDE {
940 return mHelper.GetScrollbarVisibility();
942 virtual nsMargin GetActualScrollbarSizes() const MOZ_OVERRIDE {
943 return mHelper.GetActualScrollbarSizes();
945 virtual nsMargin GetDesiredScrollbarSizes(nsBoxLayoutState* aState) MOZ_OVERRIDE {
946 return mHelper.GetDesiredScrollbarSizes(aState);
948 virtual nsMargin GetDesiredScrollbarSizes(nsPresContext* aPresContext,
949 nsRenderingContext* aRC) MOZ_OVERRIDE {
950 nsBoxLayoutState bls(aPresContext, aRC, 0);
951 return GetDesiredScrollbarSizes(&bls);
953 virtual nscoord GetNondisappearingScrollbarWidth(nsPresContext* aPresContext,
954 nsRenderingContext* aRC) MOZ_OVERRIDE {
955 nsBoxLayoutState bls(aPresContext, aRC, 0);
956 return mHelper.GetNondisappearingScrollbarWidth(&bls);
958 virtual nsRect GetScrolledRect() const MOZ_OVERRIDE {
959 return mHelper.GetScrolledRect();
961 virtual nsRect GetScrollPortRect() const MOZ_OVERRIDE {
962 return mHelper.GetScrollPortRect();
964 virtual nsPoint GetScrollPosition() const MOZ_OVERRIDE {
965 return mHelper.GetScrollPosition();
967 virtual nsPoint GetLogicalScrollPosition() const MOZ_OVERRIDE {
968 return mHelper.GetLogicalScrollPosition();
970 virtual nsRect GetScrollRange() const MOZ_OVERRIDE {
971 return mHelper.GetScrollRange();
973 virtual nsSize GetScrollPositionClampingScrollPortSize() const MOZ_OVERRIDE {
974 return mHelper.GetScrollPositionClampingScrollPortSize();
976 virtual gfxSize GetResolution() const MOZ_OVERRIDE {
977 return mHelper.GetResolution();
979 virtual void SetResolution(const gfxSize& aResolution) MOZ_OVERRIDE {
980 return mHelper.SetResolution(aResolution);
982 virtual nsSize GetLineScrollAmount() const MOZ_OVERRIDE {
983 return mHelper.GetLineScrollAmount();
985 virtual nsSize GetPageScrollAmount() const MOZ_OVERRIDE {
986 return mHelper.GetPageScrollAmount();
989 * @note This method might destroy the frame, pres shell and other objects.
991 virtual void ScrollTo(nsPoint aScrollPosition, ScrollMode aMode,
992 const nsRect* aRange = nullptr) MOZ_OVERRIDE {
993 mHelper.ScrollTo(aScrollPosition, aMode, aRange);
996 * @note This method might destroy the frame, pres shell and other objects.
998 virtual void ScrollToCSSPixels(const CSSIntPoint& aScrollPosition,
999 nsIScrollableFrame::ScrollMode aMode
1000 = nsIScrollableFrame::INSTANT) MOZ_OVERRIDE {
1001 mHelper.ScrollToCSSPixels(aScrollPosition, aMode);
1003 virtual void ScrollToCSSPixelsApproximate(const mozilla::CSSPoint& aScrollPosition,
1004 nsIAtom* aOrigin = nullptr) MOZ_OVERRIDE {
1005 mHelper.ScrollToCSSPixelsApproximate(aScrollPosition, aOrigin);
1007 virtual CSSIntPoint GetScrollPositionCSSPixels() MOZ_OVERRIDE {
1008 return mHelper.GetScrollPositionCSSPixels();
1011 * @note This method might destroy the frame, pres shell and other objects.
1013 virtual void ScrollBy(nsIntPoint aDelta, ScrollUnit aUnit, ScrollMode aMode,
1014 nsIntPoint* aOverflow, nsIAtom* aOrigin = nullptr,
1015 bool aIsMomentum = false) MOZ_OVERRIDE {
1016 mHelper.ScrollBy(aDelta, aUnit, aMode, aOverflow, aOrigin, aIsMomentum);
1019 * @note This method might destroy the frame, pres shell and other objects.
1021 virtual void ScrollToRestoredPosition() MOZ_OVERRIDE {
1022 mHelper.ScrollToRestoredPosition();
1024 virtual void AddScrollPositionListener(nsIScrollPositionListener* aListener) MOZ_OVERRIDE {
1025 mHelper.AddScrollPositionListener(aListener);
1027 virtual void RemoveScrollPositionListener(nsIScrollPositionListener* aListener) MOZ_OVERRIDE {
1028 mHelper.RemoveScrollPositionListener(aListener);
1031 * @note This method might destroy the frame, pres shell and other objects.
1033 virtual void CurPosAttributeChanged(nsIContent* aChild) MOZ_OVERRIDE {
1034 mHelper.CurPosAttributeChanged(aChild);
1036 NS_IMETHOD PostScrolledAreaEventForCurrentArea() MOZ_OVERRIDE {
1037 mHelper.PostScrolledAreaEvent();
1038 return NS_OK;
1040 virtual bool IsScrollingActive() MOZ_OVERRIDE {
1041 return mHelper.IsScrollingActive();
1043 virtual bool IsProcessingAsyncScroll() MOZ_OVERRIDE {
1044 return mHelper.IsProcessingAsyncScroll();
1046 virtual void ResetScrollPositionForLayerPixelAlignment() MOZ_OVERRIDE {
1047 mHelper.ResetScrollPositionForLayerPixelAlignment();
1049 virtual bool IsResolutionSet() const MOZ_OVERRIDE {
1050 return mHelper.mIsResolutionSet;
1052 virtual bool DidHistoryRestore() const MOZ_OVERRIDE {
1053 return mHelper.mDidHistoryRestore;
1055 virtual void ClearDidHistoryRestore() MOZ_OVERRIDE {
1056 mHelper.mDidHistoryRestore = false;
1058 virtual bool IsRectNearlyVisible(const nsRect& aRect) MOZ_OVERRIDE {
1059 return mHelper.IsRectNearlyVisible(aRect);
1061 virtual nsRect ExpandRectToNearlyVisible(const nsRect& aRect) const MOZ_OVERRIDE {
1062 return mHelper.ExpandRectToNearlyVisible(aRect);
1064 virtual nsIAtom* OriginOfLastScroll() MOZ_OVERRIDE {
1065 return mHelper.OriginOfLastScroll();
1067 virtual uint32_t CurrentScrollGeneration() MOZ_OVERRIDE {
1068 return mHelper.CurrentScrollGeneration();
1070 virtual void ResetOriginIfScrollAtGeneration(uint32_t aGeneration) MOZ_OVERRIDE {
1071 mHelper.ResetOriginIfScrollAtGeneration(aGeneration);
1073 virtual bool WantAsyncScroll() const MOZ_OVERRIDE {
1074 return mHelper.WantAsyncScroll();
1076 virtual void ComputeFrameMetrics(Layer* aLayer, nsIFrame* aContainerReferenceFrame,
1077 const ContainerLayerParameters& aParameters,
1078 nsRect* aClipRect,
1079 nsTArray<FrameMetrics>* aOutput) const MOZ_OVERRIDE {
1080 mHelper.ComputeFrameMetrics(aLayer, aContainerReferenceFrame,
1081 aParameters, aClipRect, aOutput);
1083 virtual void MarkScrollbarsDirtyForReflow() const MOZ_OVERRIDE {
1084 mHelper.MarkScrollbarsDirtyForReflow();
1087 // nsIStatefulFrame
1088 NS_IMETHOD SaveState(nsPresState** aState) MOZ_OVERRIDE {
1089 NS_ENSURE_ARG_POINTER(aState);
1090 *aState = mHelper.SaveState();
1091 return NS_OK;
1093 NS_IMETHOD RestoreState(nsPresState* aState) MOZ_OVERRIDE {
1094 NS_ENSURE_ARG_POINTER(aState);
1095 mHelper.RestoreState(aState);
1096 return NS_OK;
1100 * Get the "type" of the frame
1102 * @see nsGkAtoms::scrollFrame
1104 virtual nsIAtom* GetType() const MOZ_OVERRIDE;
1106 virtual bool IsFrameOfType(uint32_t aFlags) const MOZ_OVERRIDE
1108 // Override bogus IsFrameOfType in nsBoxFrame.
1109 if (aFlags & (nsIFrame::eReplacedContainsBlock | nsIFrame::eReplaced))
1110 return false;
1111 return nsBoxFrame::IsFrameOfType(aFlags);
1114 virtual void ScrollByPage(nsScrollbarFrame* aScrollbar, int32_t aDirection) MOZ_OVERRIDE {
1115 mHelper.ScrollByPage(aScrollbar, aDirection);
1117 virtual void ScrollByWhole(nsScrollbarFrame* aScrollbar, int32_t aDirection) MOZ_OVERRIDE {
1118 mHelper.ScrollByWhole(aScrollbar, aDirection);
1120 virtual void ScrollByLine(nsScrollbarFrame* aScrollbar, int32_t aDirection) MOZ_OVERRIDE {
1121 mHelper.ScrollByLine(aScrollbar, aDirection);
1123 virtual void RepeatButtonScroll(nsScrollbarFrame* aScrollbar) MOZ_OVERRIDE {
1124 mHelper.RepeatButtonScroll(aScrollbar);
1126 virtual void ThumbMoved(nsScrollbarFrame* aScrollbar,
1127 nscoord aOldPos,
1128 nscoord aNewPos) MOZ_OVERRIDE {
1129 mHelper.ThumbMoved(aScrollbar, aOldPos, aNewPos);
1131 virtual void VisibilityChanged(bool aVisible) {}
1132 virtual nsIFrame* GetScrollbarBox(bool aVertical) MOZ_OVERRIDE {
1133 return mHelper.GetScrollbarBox(aVertical);
1136 virtual void ScrollbarActivityStarted() const MOZ_OVERRIDE;
1137 virtual void ScrollbarActivityStopped() const MOZ_OVERRIDE;
1139 #ifdef DEBUG_FRAME_DUMP
1140 virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE;
1141 #endif
1143 protected:
1144 nsXULScrollFrame(nsIPresShell* aShell, nsStyleContext* aContext, bool aIsRoot,
1145 bool aClipAllDescendants);
1147 void ClampAndSetBounds(nsBoxLayoutState& aState,
1148 nsRect& aRect,
1149 nsPoint aScrollPosition,
1150 bool aRemoveOverflowAreas = false) {
1152 * For RTL frames, restore the original scrolled position of the right
1153 * edge, then subtract the current width to find the physical position.
1155 if (!mHelper.IsLTR()) {
1156 aRect.x = mHelper.mScrollPort.XMost() - aScrollPosition.x - aRect.width;
1158 mHelper.mScrolledFrame->SetBounds(aState, aRect, aRemoveOverflowAreas);
1161 private:
1162 friend class mozilla::ScrollFrameHelper;
1163 ScrollFrameHelper mHelper;
1166 #endif /* nsGfxScrollFrame_h___ */