layout/generic/nsGfxScrollFrame.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 /* rendering object to wrap rendering objects that should be scrollable */
michael@0 7
michael@0 8 #ifndef nsGfxScrollFrame_h___
michael@0 9 #define nsGfxScrollFrame_h___
michael@0 10
michael@0 11 #include "mozilla/Attributes.h"
michael@0 12 #include "nsContainerFrame.h"
michael@0 13 #include "nsIAnonymousContentCreator.h"
michael@0 14 #include "nsBoxFrame.h"
michael@0 15 #include "nsIScrollableFrame.h"
michael@0 16 #include "nsIStatefulFrame.h"
michael@0 17 #include "nsThreadUtils.h"
michael@0 18 #include "nsIReflowCallback.h"
michael@0 19 #include "nsBoxLayoutState.h"
michael@0 20 #include "nsQueryFrame.h"
michael@0 21 #include "nsExpirationTracker.h"
michael@0 22
michael@0 23 class nsPresContext;
michael@0 24 class nsIPresShell;
michael@0 25 class nsIContent;
michael@0 26 class nsIAtom;
michael@0 27 class nsIScrollFrameInternal;
michael@0 28 class nsPresState;
michael@0 29 class nsIScrollPositionListener;
michael@0 30 struct ScrollReflowState;
michael@0 31
michael@0 32 namespace mozilla {
michael@0 33 namespace layout {
michael@0 34 class ScrollbarActivity;
michael@0 35 }
michael@0 36 }
michael@0 37
michael@0 38 namespace mozilla {
michael@0 39
michael@0 40 class ScrollFrameHelper : public nsIReflowCallback {
michael@0 41 public:
michael@0 42 typedef mozilla::CSSIntPoint CSSIntPoint;
michael@0 43 typedef mozilla::layout::ScrollbarActivity ScrollbarActivity;
michael@0 44
michael@0 45 class AsyncScroll;
michael@0 46
michael@0 47 ScrollFrameHelper(nsContainerFrame* aOuter, bool aIsRoot);
michael@0 48 ~ScrollFrameHelper();
michael@0 49
michael@0 50 mozilla::ScrollbarStyles GetScrollbarStylesFromFrame() const;
michael@0 51
michael@0 52 // If a child frame was added or removed on the scrollframe,
michael@0 53 // reload our child frame list.
michael@0 54 // We need this if a scrollbar frame is recreated.
michael@0 55 void ReloadChildFrames();
michael@0 56
michael@0 57 nsresult CreateAnonymousContent(
michael@0 58 nsTArray<nsIAnonymousContentCreator::ContentInfo>& aElements);
michael@0 59 void AppendAnonymousContentTo(nsBaseContentList& aElements, uint32_t aFilter);
michael@0 60 nsresult FireScrollPortEvent();
michael@0 61 void PostOverflowEvent();
michael@0 62 void Destroy();
michael@0 63
michael@0 64 void BuildDisplayList(nsDisplayListBuilder* aBuilder,
michael@0 65 const nsRect& aDirtyRect,
michael@0 66 const nsDisplayListSet& aLists);
michael@0 67
michael@0 68 void AppendScrollPartsTo(nsDisplayListBuilder* aBuilder,
michael@0 69 const nsRect& aDirtyRect,
michael@0 70 const nsDisplayListSet& aLists,
michael@0 71 bool& aCreateLayer,
michael@0 72 bool aPositioned);
michael@0 73
michael@0 74 bool GetBorderRadii(nscoord aRadii[8]) const;
michael@0 75
michael@0 76 // nsIReflowCallback
michael@0 77 virtual bool ReflowFinished() MOZ_OVERRIDE;
michael@0 78 virtual void ReflowCallbackCanceled() MOZ_OVERRIDE;
michael@0 79
michael@0 80 /**
michael@0 81 * @note This method might destroy the frame, pres shell and other objects.
michael@0 82 * Called when the 'curpos' attribute on one of the scrollbars changes.
michael@0 83 */
michael@0 84 void CurPosAttributeChanged(nsIContent* aChild);
michael@0 85
michael@0 86 void PostScrollEvent();
michael@0 87 void FireScrollEvent();
michael@0 88 void PostScrolledAreaEvent();
michael@0 89 void FireScrolledAreaEvent();
michael@0 90
michael@0 91 class ScrollEvent : public nsRunnable {
michael@0 92 public:
michael@0 93 NS_DECL_NSIRUNNABLE
michael@0 94 ScrollEvent(ScrollFrameHelper *helper) : mHelper(helper) {}
michael@0 95 void Revoke() { mHelper = nullptr; }
michael@0 96 private:
michael@0 97 ScrollFrameHelper *mHelper;
michael@0 98 };
michael@0 99
michael@0 100 class AsyncScrollPortEvent : public nsRunnable {
michael@0 101 public:
michael@0 102 NS_DECL_NSIRUNNABLE
michael@0 103 AsyncScrollPortEvent(ScrollFrameHelper *helper) : mHelper(helper) {}
michael@0 104 void Revoke() { mHelper = nullptr; }
michael@0 105 private:
michael@0 106 ScrollFrameHelper *mHelper;
michael@0 107 };
michael@0 108
michael@0 109 class ScrolledAreaEvent : public nsRunnable {
michael@0 110 public:
michael@0 111 NS_DECL_NSIRUNNABLE
michael@0 112 ScrolledAreaEvent(ScrollFrameHelper *helper) : mHelper(helper) {}
michael@0 113 void Revoke() { mHelper = nullptr; }
michael@0 114 private:
michael@0 115 ScrollFrameHelper *mHelper;
michael@0 116 };
michael@0 117
michael@0 118 /**
michael@0 119 * @note This method might destroy the frame, pres shell and other objects.
michael@0 120 */
michael@0 121 void FinishReflowForScrollbar(nsIContent* aContent, nscoord aMinXY,
michael@0 122 nscoord aMaxXY, nscoord aCurPosXY,
michael@0 123 nscoord aPageIncrement,
michael@0 124 nscoord aIncrement);
michael@0 125 /**
michael@0 126 * @note This method might destroy the frame, pres shell and other objects.
michael@0 127 */
michael@0 128 void SetScrollbarEnabled(nsIContent* aContent, nscoord aMaxPos);
michael@0 129 /**
michael@0 130 * @note This method might destroy the frame, pres shell and other objects.
michael@0 131 */
michael@0 132 void SetCoordAttribute(nsIContent* aContent, nsIAtom* aAtom, nscoord aSize);
michael@0 133
michael@0 134 nscoord GetCoordAttribute(nsIFrame* aFrame, nsIAtom* aAtom, nscoord aDefaultValue,
michael@0 135 nscoord* aRangeStart, nscoord* aRangeLength);
michael@0 136
michael@0 137 /**
michael@0 138 * @note This method might destroy the frame, pres shell and other objects.
michael@0 139 * Update scrollbar curpos attributes to reflect current scroll position
michael@0 140 */
michael@0 141 void UpdateScrollbarPosition();
michael@0 142
michael@0 143 nsRect GetScrollPortRect() const { return mScrollPort; }
michael@0 144 nsPoint GetScrollPosition() const {
michael@0 145 return mScrollPort.TopLeft() - mScrolledFrame->GetPosition();
michael@0 146 }
michael@0 147 /**
michael@0 148 * For LTR frames, the logical scroll position is the offset of the top left
michael@0 149 * corner of the frame from the top left corner of the scroll port (same as
michael@0 150 * GetScrollPosition).
michael@0 151 * For RTL frames, it is the offset of the top right corner of the frame from
michael@0 152 * the top right corner of the scroll port
michael@0 153 */
michael@0 154 nsPoint GetLogicalScrollPosition() const {
michael@0 155 nsPoint pt;
michael@0 156 pt.x = IsLTR() ?
michael@0 157 mScrollPort.x - mScrolledFrame->GetPosition().x :
michael@0 158 mScrollPort.XMost() - mScrolledFrame->GetRect().XMost();
michael@0 159 pt.y = mScrollPort.y - mScrolledFrame->GetPosition().y;
michael@0 160 return pt;
michael@0 161 }
michael@0 162 nsRect GetScrollRange() const;
michael@0 163 // Get the scroll range assuming the scrollport has size (aWidth, aHeight).
michael@0 164 nsRect GetScrollRange(nscoord aWidth, nscoord aHeight) const;
michael@0 165 nsSize GetScrollPositionClampingScrollPortSize() const;
michael@0 166 gfxSize GetResolution() const;
michael@0 167 void SetResolution(const gfxSize& aResolution);
michael@0 168
michael@0 169 protected:
michael@0 170 nsRect GetScrollRangeForClamping() const;
michael@0 171
michael@0 172 public:
michael@0 173 static void AsyncScrollCallback(void* anInstance, mozilla::TimeStamp aTime);
michael@0 174 /**
michael@0 175 * @note This method might destroy the frame, pres shell and other objects.
michael@0 176 * aRange is the range of allowable scroll positions around the desired
michael@0 177 * aScrollPosition. Null means only aScrollPosition is allowed.
michael@0 178 * This is a closed-ended range --- aRange.XMost()/aRange.YMost() are allowed.
michael@0 179 */
michael@0 180 void ScrollTo(nsPoint aScrollPosition, nsIScrollableFrame::ScrollMode aMode,
michael@0 181 const nsRect* aRange = nullptr) {
michael@0 182 ScrollToWithOrigin(aScrollPosition, aMode, nsGkAtoms::other, aRange);
michael@0 183 }
michael@0 184 /**
michael@0 185 * @note This method might destroy the frame, pres shell and other objects.
michael@0 186 */
michael@0 187 void ScrollToCSSPixels(const CSSIntPoint& aScrollPosition);
michael@0 188 /**
michael@0 189 * @note This method might destroy the frame, pres shell and other objects.
michael@0 190 */
michael@0 191 void ScrollToCSSPixelsApproximate(const mozilla::CSSPoint& aScrollPosition,
michael@0 192 nsIAtom* aOrigin = nullptr);
michael@0 193
michael@0 194 CSSIntPoint GetScrollPositionCSSPixels();
michael@0 195 /**
michael@0 196 * @note This method might destroy the frame, pres shell and other objects.
michael@0 197 */
michael@0 198 void ScrollToImpl(nsPoint aScrollPosition, const nsRect& aRange, nsIAtom* aOrigin = nullptr);
michael@0 199 void ScrollVisual(nsPoint aOldScrolledFramePosition);
michael@0 200 /**
michael@0 201 * @note This method might destroy the frame, pres shell and other objects.
michael@0 202 */
michael@0 203 void ScrollBy(nsIntPoint aDelta, nsIScrollableFrame::ScrollUnit aUnit,
michael@0 204 nsIScrollableFrame::ScrollMode aMode, nsIntPoint* aOverflow, nsIAtom *aOrigin = nullptr);
michael@0 205 /**
michael@0 206 * @note This method might destroy the frame, pres shell and other objects.
michael@0 207 */
michael@0 208 void ScrollToRestoredPosition();
michael@0 209
michael@0 210 nsSize GetLineScrollAmount() const;
michael@0 211 nsSize GetPageScrollAmount() const;
michael@0 212
michael@0 213 nsPresState* SaveState() const;
michael@0 214 void RestoreState(nsPresState* aState);
michael@0 215
michael@0 216 nsIFrame* GetScrolledFrame() const { return mScrolledFrame; }
michael@0 217 nsIFrame* GetScrollbarBox(bool aVertical) const {
michael@0 218 return aVertical ? mVScrollbarBox : mHScrollbarBox;
michael@0 219 }
michael@0 220
michael@0 221 void AddScrollPositionListener(nsIScrollPositionListener* aListener) {
michael@0 222 mListeners.AppendElement(aListener);
michael@0 223 }
michael@0 224 void RemoveScrollPositionListener(nsIScrollPositionListener* aListener) {
michael@0 225 mListeners.RemoveElement(aListener);
michael@0 226 }
michael@0 227
michael@0 228 static void SetScrollbarVisibility(nsIFrame* aScrollbar, bool aVisible);
michael@0 229
michael@0 230 /**
michael@0 231 * GetScrolledRect is designed to encapsulate deciding which
michael@0 232 * directions of overflow should be reachable by scrolling and which
michael@0 233 * should not. Callers should NOT depend on it having any particular
michael@0 234 * behavior (although nsXULScrollFrame currently does).
michael@0 235 *
michael@0 236 * This should only be called when the scrolled frame has been
michael@0 237 * reflowed with the scroll port size given in mScrollPort.
michael@0 238 *
michael@0 239 * Currently it allows scrolling down and to the right for
michael@0 240 * nsHTMLScrollFrames with LTR directionality and for all
michael@0 241 * nsXULScrollFrames, and allows scrolling down and to the left for
michael@0 242 * nsHTMLScrollFrames with RTL directionality.
michael@0 243 */
michael@0 244 nsRect GetScrolledRect() const;
michael@0 245
michael@0 246 /**
michael@0 247 * GetScrolledRectInternal is designed to encapsulate deciding which
michael@0 248 * directions of overflow should be reachable by scrolling and which
michael@0 249 * should not. Callers should NOT depend on it having any particular
michael@0 250 * behavior (although nsXULScrollFrame currently does).
michael@0 251 *
michael@0 252 * Currently it allows scrolling down and to the right for
michael@0 253 * nsHTMLScrollFrames with LTR directionality and for all
michael@0 254 * nsXULScrollFrames, and allows scrolling down and to the left for
michael@0 255 * nsHTMLScrollFrames with RTL directionality.
michael@0 256 */
michael@0 257 nsRect GetScrolledRectInternal(const nsRect& aScrolledOverflowArea,
michael@0 258 const nsSize& aScrollPortSize) const;
michael@0 259
michael@0 260 uint32_t GetScrollbarVisibility() const {
michael@0 261 return (mHasVerticalScrollbar ? nsIScrollableFrame::VERTICAL : 0) |
michael@0 262 (mHasHorizontalScrollbar ? nsIScrollableFrame::HORIZONTAL : 0);
michael@0 263 }
michael@0 264 nsMargin GetActualScrollbarSizes() const;
michael@0 265 nsMargin GetDesiredScrollbarSizes(nsBoxLayoutState* aState);
michael@0 266 nscoord GetNondisappearingScrollbarWidth(nsBoxLayoutState* aState);
michael@0 267 bool IsLTR() const;
michael@0 268 bool IsScrollbarOnRight() const;
michael@0 269 bool IsScrollingActive() const { return mScrollingActive || mShouldBuildScrollableLayer; }
michael@0 270 bool IsProcessingAsyncScroll() const { return mAsyncScroll != nullptr; }
michael@0 271 void ResetScrollPositionForLayerPixelAlignment()
michael@0 272 {
michael@0 273 mScrollPosForLayerPixelAlignment = GetScrollPosition();
michael@0 274 }
michael@0 275
michael@0 276 bool UpdateOverflow();
michael@0 277
michael@0 278 void UpdateSticky();
michael@0 279
michael@0 280 bool IsRectNearlyVisible(const nsRect& aRect) const;
michael@0 281
michael@0 282 // adjust the scrollbar rectangle aRect to account for any visible resizer.
michael@0 283 // aHasResizer specifies if there is a content resizer, however this method
michael@0 284 // will also check if a widget resizer is present as well.
michael@0 285 void AdjustScrollbarRectForResizer(nsIFrame* aFrame, nsPresContext* aPresContext,
michael@0 286 nsRect& aRect, bool aHasResizer, bool aVertical);
michael@0 287 // returns true if a resizer should be visible
michael@0 288 bool HasResizer() { return mResizerBox && !mCollapsedResizer; }
michael@0 289 void LayoutScrollbars(nsBoxLayoutState& aState,
michael@0 290 const nsRect& aContentArea,
michael@0 291 const nsRect& aOldScrollArea);
michael@0 292
michael@0 293 bool IsIgnoringViewportClipping() const;
michael@0 294
michael@0 295 bool ShouldClampScrollPosition() const;
michael@0 296
michael@0 297 bool IsAlwaysActive() const;
michael@0 298 void MarkActive();
michael@0 299 void MarkInactive();
michael@0 300 nsExpirationState* GetExpirationState() { return &mActivityExpirationState; }
michael@0 301
michael@0 302 void ScheduleSyntheticMouseMove();
michael@0 303 static void ScrollActivityCallback(nsITimer *aTimer, void* anInstance);
michael@0 304
michael@0 305 void HandleScrollbarStyleSwitching();
michael@0 306
michael@0 307 nsIAtom* OriginOfLastScroll() const { return mOriginOfLastScroll; }
michael@0 308 uint32_t CurrentScrollGeneration() const { return mScrollGeneration; }
michael@0 309 void ResetOriginIfScrollAtGeneration(uint32_t aGeneration) {
michael@0 310 if (aGeneration == mScrollGeneration) {
michael@0 311 mOriginOfLastScroll = nullptr;
michael@0 312 }
michael@0 313 }
michael@0 314 bool WantAsyncScroll() const;
michael@0 315
michael@0 316 // owning references to the nsIAnonymousContentCreator-built content
michael@0 317 nsCOMPtr<nsIContent> mHScrollbarContent;
michael@0 318 nsCOMPtr<nsIContent> mVScrollbarContent;
michael@0 319 nsCOMPtr<nsIContent> mScrollCornerContent;
michael@0 320 nsCOMPtr<nsIContent> mResizerContent;
michael@0 321
michael@0 322 nsRevocableEventPtr<ScrollEvent> mScrollEvent;
michael@0 323 nsRevocableEventPtr<AsyncScrollPortEvent> mAsyncScrollPortEvent;
michael@0 324 nsRevocableEventPtr<ScrolledAreaEvent> mScrolledAreaEvent;
michael@0 325 nsIFrame* mHScrollbarBox;
michael@0 326 nsIFrame* mVScrollbarBox;
michael@0 327 nsIFrame* mScrolledFrame;
michael@0 328 nsIFrame* mScrollCornerBox;
michael@0 329 nsIFrame* mResizerBox;
michael@0 330 nsContainerFrame* mOuter;
michael@0 331 nsRefPtr<AsyncScroll> mAsyncScroll;
michael@0 332 nsRefPtr<ScrollbarActivity> mScrollbarActivity;
michael@0 333 nsTArray<nsIScrollPositionListener*> mListeners;
michael@0 334 nsIAtom* mOriginOfLastScroll;
michael@0 335 uint32_t mScrollGeneration;
michael@0 336 nsRect mScrollPort;
michael@0 337 // Where we're currently scrolling to, if we're scrolling asynchronously.
michael@0 338 // If we're not in the middle of an asynchronous scroll then this is
michael@0 339 // just the current scroll position. ScrollBy will choose its
michael@0 340 // destination based on this value.
michael@0 341 nsPoint mDestination;
michael@0 342 nsPoint mScrollPosAtLastPaint;
michael@0 343
michael@0 344 // A goal position to try to scroll to as content loads. As long as mLastPos
michael@0 345 // matches the current logical scroll position, we try to scroll to mRestorePos
michael@0 346 // after every reflow --- because after each time content is loaded/added to the
michael@0 347 // scrollable element, there will be a reflow.
michael@0 348 nsPoint mRestorePos;
michael@0 349 // The last logical position we scrolled to while trying to restore mRestorePos, or
michael@0 350 // 0,0 when this is a new frame. Set to -1,-1 once we've scrolled for any reason
michael@0 351 // other than trying to restore mRestorePos.
michael@0 352 nsPoint mLastPos;
michael@0 353
michael@0 354 // The current resolution derived from the zoom level and device pixel ratio.
michael@0 355 gfxSize mResolution;
michael@0 356
michael@0 357 nsExpirationState mActivityExpirationState;
michael@0 358
michael@0 359 nsCOMPtr<nsITimer> mScrollActivityTimer;
michael@0 360 nsPoint mScrollPosForLayerPixelAlignment;
michael@0 361
michael@0 362 // The scroll position where we last updated image visibility.
michael@0 363 nsPoint mLastUpdateImagesPos;
michael@0 364
michael@0 365 bool mNeverHasVerticalScrollbar:1;
michael@0 366 bool mNeverHasHorizontalScrollbar:1;
michael@0 367 bool mHasVerticalScrollbar:1;
michael@0 368 bool mHasHorizontalScrollbar:1;
michael@0 369 bool mFrameIsUpdatingScrollbar:1;
michael@0 370 bool mDidHistoryRestore:1;
michael@0 371 // Is this the scrollframe for the document's viewport?
michael@0 372 bool mIsRoot:1;
michael@0 373 // True if we should clip all descendants, false if we should only clip
michael@0 374 // descendants for which we are the containing block.
michael@0 375 bool mClipAllDescendants:1;
michael@0 376 // If true, don't try to layout the scrollbars in Reflow(). This can be
michael@0 377 // useful if multiple passes are involved, because we don't want to place the
michael@0 378 // scrollbars at the wrong size.
michael@0 379 bool mSupppressScrollbarUpdate:1;
michael@0 380 // If true, we skipped a scrollbar layout due to mSupppressScrollbarUpdate
michael@0 381 // being set at some point. That means we should lay out scrollbars even if
michael@0 382 // it might not strictly be needed next time mSupppressScrollbarUpdate is
michael@0 383 // false.
michael@0 384 bool mSkippedScrollbarLayout:1;
michael@0 385
michael@0 386 bool mHadNonInitialReflow:1;
michael@0 387 // State used only by PostScrollEvents so we know
michael@0 388 // which overflow states have changed.
michael@0 389 bool mHorizontalOverflow:1;
michael@0 390 bool mVerticalOverflow:1;
michael@0 391 bool mPostedReflowCallback:1;
michael@0 392 bool mMayHaveDirtyFixedChildren:1;
michael@0 393 // If true, need to actually update our scrollbar attributes in the
michael@0 394 // reflow callback.
michael@0 395 bool mUpdateScrollbarAttributes:1;
michael@0 396 // If true, we should be prepared to scroll using this scrollframe
michael@0 397 // by placing descendant content into its own layer(s)
michael@0 398 bool mScrollingActive:1;
michael@0 399 // If true, the resizer is collapsed and not displayed
michael@0 400 bool mCollapsedResizer:1;
michael@0 401
michael@0 402 // If true, the layer should always be active because we always build a
michael@0 403 // scrollable layer. Used for asynchronous scrolling.
michael@0 404 bool mShouldBuildScrollableLayer:1;
michael@0 405
michael@0 406 // True if this frame has been scrolled at least once
michael@0 407 bool mHasBeenScrolled:1;
michael@0 408
michael@0 409 // True if the frame's resolution has been set via SetResolution or restored
michael@0 410 // via RestoreState.
michael@0 411 bool mIsResolutionSet:1;
michael@0 412
michael@0 413 protected:
michael@0 414 /**
michael@0 415 * @note This method might destroy the frame, pres shell and other objects.
michael@0 416 */
michael@0 417 void ScrollToWithOrigin(nsPoint aScrollPosition,
michael@0 418 nsIScrollableFrame::ScrollMode aMode,
michael@0 419 nsIAtom *aOrigin, // nullptr indicates "other" origin
michael@0 420 const nsRect* aRange);
michael@0 421
michael@0 422 nsRect ExpandRect(const nsRect& aRect) const;
michael@0 423 static void EnsureImageVisPrefsCached();
michael@0 424 static bool sImageVisPrefsCached;
michael@0 425 // The number of scrollports wide/high to expand when looking for images.
michael@0 426 static uint32_t sHorzExpandScrollPort;
michael@0 427 static uint32_t sVertExpandScrollPort;
michael@0 428 // The fraction of the scrollport we allow to scroll by before we schedule
michael@0 429 // an update of image visibility.
michael@0 430 static int32_t sHorzScrollFraction;
michael@0 431 static int32_t sVertScrollFraction;
michael@0 432 };
michael@0 433
michael@0 434 }
michael@0 435
michael@0 436 /**
michael@0 437 * The scroll frame creates and manages the scrolling view
michael@0 438 *
michael@0 439 * It only supports having a single child frame that typically is an area
michael@0 440 * frame, but doesn't have to be. The child frame must have a view, though
michael@0 441 *
michael@0 442 * Scroll frames don't support incremental changes, i.e. you can't replace
michael@0 443 * or remove the scrolled frame
michael@0 444 */
michael@0 445 class nsHTMLScrollFrame : public nsContainerFrame,
michael@0 446 public nsIScrollableFrame,
michael@0 447 public nsIAnonymousContentCreator,
michael@0 448 public nsIStatefulFrame {
michael@0 449 public:
michael@0 450 typedef mozilla::ScrollFrameHelper ScrollFrameHelper;
michael@0 451 typedef mozilla::CSSIntPoint CSSIntPoint;
michael@0 452 friend nsIFrame* NS_NewHTMLScrollFrame(nsIPresShell* aPresShell, nsStyleContext* aContext, bool aIsRoot);
michael@0 453
michael@0 454 NS_DECL_QUERYFRAME
michael@0 455 NS_DECL_FRAMEARENA_HELPERS
michael@0 456
michael@0 457 // Called to set the child frames. We typically have three: the scroll area,
michael@0 458 // the vertical scrollbar, and the horizontal scrollbar.
michael@0 459 virtual nsresult SetInitialChildList(ChildListID aListID,
michael@0 460 nsFrameList& aChildList) MOZ_OVERRIDE;
michael@0 461
michael@0 462 virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder,
michael@0 463 const nsRect& aDirtyRect,
michael@0 464 const nsDisplayListSet& aLists) MOZ_OVERRIDE {
michael@0 465 mHelper.BuildDisplayList(aBuilder, aDirtyRect, aLists);
michael@0 466 }
michael@0 467
michael@0 468 bool TryLayout(ScrollReflowState* aState,
michael@0 469 nsHTMLReflowMetrics* aKidMetrics,
michael@0 470 bool aAssumeVScroll, bool aAssumeHScroll,
michael@0 471 bool aForce, nsresult* aResult);
michael@0 472 bool ScrolledContentDependsOnHeight(ScrollReflowState* aState);
michael@0 473 nsresult ReflowScrolledFrame(ScrollReflowState* aState,
michael@0 474 bool aAssumeHScroll,
michael@0 475 bool aAssumeVScroll,
michael@0 476 nsHTMLReflowMetrics* aMetrics,
michael@0 477 bool aFirstPass);
michael@0 478 nsresult ReflowContents(ScrollReflowState* aState,
michael@0 479 const nsHTMLReflowMetrics& aDesiredSize);
michael@0 480 void PlaceScrollArea(const ScrollReflowState& aState,
michael@0 481 const nsPoint& aScrollPosition);
michael@0 482 nscoord GetIntrinsicVScrollbarWidth(nsRenderingContext *aRenderingContext);
michael@0 483
michael@0 484 virtual bool GetBorderRadii(nscoord aRadii[8]) const MOZ_OVERRIDE {
michael@0 485 return mHelper.GetBorderRadii(aRadii);
michael@0 486 }
michael@0 487
michael@0 488 virtual nscoord GetMinWidth(nsRenderingContext *aRenderingContext) MOZ_OVERRIDE;
michael@0 489 virtual nscoord GetPrefWidth(nsRenderingContext *aRenderingContext) MOZ_OVERRIDE;
michael@0 490 virtual nsresult GetPadding(nsMargin& aPadding) MOZ_OVERRIDE;
michael@0 491 virtual bool IsCollapsed() MOZ_OVERRIDE;
michael@0 492
michael@0 493 virtual nsresult Reflow(nsPresContext* aPresContext,
michael@0 494 nsHTMLReflowMetrics& aDesiredSize,
michael@0 495 const nsHTMLReflowState& aReflowState,
michael@0 496 nsReflowStatus& aStatus) MOZ_OVERRIDE;
michael@0 497
michael@0 498 virtual bool UpdateOverflow() MOZ_OVERRIDE {
michael@0 499 return mHelper.UpdateOverflow();
michael@0 500 }
michael@0 501
michael@0 502 // Because there can be only one child frame, these two function return
michael@0 503 // NS_ERROR_FAILURE
michael@0 504 virtual nsresult AppendFrames(ChildListID aListID,
michael@0 505 nsFrameList& aFrameList) MOZ_OVERRIDE;
michael@0 506 virtual nsresult InsertFrames(ChildListID aListID,
michael@0 507 nsIFrame* aPrevFrame,
michael@0 508 nsFrameList& aFrameList) MOZ_OVERRIDE;
michael@0 509
michael@0 510 virtual void DestroyFrom(nsIFrame* aDestructRoot) MOZ_OVERRIDE;
michael@0 511
michael@0 512
michael@0 513 virtual nsresult RemoveFrame(ChildListID aListID,
michael@0 514 nsIFrame* aOldFrame) MOZ_OVERRIDE;
michael@0 515
michael@0 516 virtual nsIScrollableFrame* GetScrollTargetFrame() MOZ_OVERRIDE {
michael@0 517 return this;
michael@0 518 }
michael@0 519
michael@0 520 virtual nsIFrame* GetContentInsertionFrame() MOZ_OVERRIDE {
michael@0 521 return mHelper.GetScrolledFrame()->GetContentInsertionFrame();
michael@0 522 }
michael@0 523
michael@0 524 virtual bool DoesClipChildren() MOZ_OVERRIDE { return true; }
michael@0 525 virtual nsSplittableType GetSplittableType() const MOZ_OVERRIDE;
michael@0 526
michael@0 527 virtual nsPoint GetPositionOfChildIgnoringScrolling(nsIFrame* aChild) MOZ_OVERRIDE
michael@0 528 { nsPoint pt = aChild->GetPosition();
michael@0 529 if (aChild == mHelper.GetScrolledFrame()) pt += GetScrollPosition();
michael@0 530 return pt;
michael@0 531 }
michael@0 532
michael@0 533 // nsIAnonymousContentCreator
michael@0 534 virtual nsresult CreateAnonymousContent(nsTArray<ContentInfo>& aElements) MOZ_OVERRIDE;
michael@0 535 virtual void AppendAnonymousContentTo(nsBaseContentList& aElements,
michael@0 536 uint32_t aFilter) MOZ_OVERRIDE;
michael@0 537
michael@0 538 // nsIScrollbarOwner
michael@0 539 virtual nsIFrame* GetScrollbarBox(bool aVertical) MOZ_OVERRIDE {
michael@0 540 return mHelper.GetScrollbarBox(aVertical);
michael@0 541 }
michael@0 542
michael@0 543 virtual void ScrollbarActivityStarted() const MOZ_OVERRIDE;
michael@0 544 virtual void ScrollbarActivityStopped() const MOZ_OVERRIDE;
michael@0 545
michael@0 546 // nsIScrollableFrame
michael@0 547 virtual nsIFrame* GetScrolledFrame() const MOZ_OVERRIDE {
michael@0 548 return mHelper.GetScrolledFrame();
michael@0 549 }
michael@0 550 virtual mozilla::ScrollbarStyles GetScrollbarStyles() const MOZ_OVERRIDE {
michael@0 551 return mHelper.GetScrollbarStylesFromFrame();
michael@0 552 }
michael@0 553 virtual uint32_t GetScrollbarVisibility() const MOZ_OVERRIDE {
michael@0 554 return mHelper.GetScrollbarVisibility();
michael@0 555 }
michael@0 556 virtual nsMargin GetActualScrollbarSizes() const MOZ_OVERRIDE {
michael@0 557 return mHelper.GetActualScrollbarSizes();
michael@0 558 }
michael@0 559 virtual nsMargin GetDesiredScrollbarSizes(nsBoxLayoutState* aState) MOZ_OVERRIDE {
michael@0 560 return mHelper.GetDesiredScrollbarSizes(aState);
michael@0 561 }
michael@0 562 virtual nsMargin GetDesiredScrollbarSizes(nsPresContext* aPresContext,
michael@0 563 nsRenderingContext* aRC) MOZ_OVERRIDE {
michael@0 564 nsBoxLayoutState bls(aPresContext, aRC, 0);
michael@0 565 return GetDesiredScrollbarSizes(&bls);
michael@0 566 }
michael@0 567 virtual nscoord GetNondisappearingScrollbarWidth(nsPresContext* aPresContext,
michael@0 568 nsRenderingContext* aRC) MOZ_OVERRIDE {
michael@0 569 nsBoxLayoutState bls(aPresContext, aRC, 0);
michael@0 570 return mHelper.GetNondisappearingScrollbarWidth(&bls);
michael@0 571 }
michael@0 572 virtual nsRect GetScrolledRect() const MOZ_OVERRIDE {
michael@0 573 return mHelper.GetScrolledRect();
michael@0 574 }
michael@0 575 virtual nsRect GetScrollPortRect() const MOZ_OVERRIDE {
michael@0 576 return mHelper.GetScrollPortRect();
michael@0 577 }
michael@0 578 virtual nsPoint GetScrollPosition() const MOZ_OVERRIDE {
michael@0 579 return mHelper.GetScrollPosition();
michael@0 580 }
michael@0 581 virtual nsPoint GetLogicalScrollPosition() const MOZ_OVERRIDE {
michael@0 582 return mHelper.GetLogicalScrollPosition();
michael@0 583 }
michael@0 584 virtual nsRect GetScrollRange() const MOZ_OVERRIDE {
michael@0 585 return mHelper.GetScrollRange();
michael@0 586 }
michael@0 587 virtual nsSize GetScrollPositionClampingScrollPortSize() const MOZ_OVERRIDE {
michael@0 588 return mHelper.GetScrollPositionClampingScrollPortSize();
michael@0 589 }
michael@0 590 virtual gfxSize GetResolution() const MOZ_OVERRIDE {
michael@0 591 return mHelper.GetResolution();
michael@0 592 }
michael@0 593 virtual void SetResolution(const gfxSize& aResolution) MOZ_OVERRIDE {
michael@0 594 return mHelper.SetResolution(aResolution);
michael@0 595 }
michael@0 596 virtual nsSize GetLineScrollAmount() const MOZ_OVERRIDE {
michael@0 597 return mHelper.GetLineScrollAmount();
michael@0 598 }
michael@0 599 virtual nsSize GetPageScrollAmount() const MOZ_OVERRIDE {
michael@0 600 return mHelper.GetPageScrollAmount();
michael@0 601 }
michael@0 602 /**
michael@0 603 * @note This method might destroy the frame, pres shell and other objects.
michael@0 604 */
michael@0 605 virtual void ScrollTo(nsPoint aScrollPosition, ScrollMode aMode,
michael@0 606 const nsRect* aRange = nullptr) MOZ_OVERRIDE {
michael@0 607 mHelper.ScrollTo(aScrollPosition, aMode, aRange);
michael@0 608 }
michael@0 609 /**
michael@0 610 * @note This method might destroy the frame, pres shell and other objects.
michael@0 611 */
michael@0 612 virtual void ScrollToCSSPixels(const CSSIntPoint& aScrollPosition) MOZ_OVERRIDE {
michael@0 613 mHelper.ScrollToCSSPixels(aScrollPosition);
michael@0 614 }
michael@0 615 virtual void ScrollToCSSPixelsApproximate(const mozilla::CSSPoint& aScrollPosition,
michael@0 616 nsIAtom* aOrigin = nullptr) MOZ_OVERRIDE {
michael@0 617 mHelper.ScrollToCSSPixelsApproximate(aScrollPosition, aOrigin);
michael@0 618 }
michael@0 619 /**
michael@0 620 * @note This method might destroy the frame, pres shell and other objects.
michael@0 621 */
michael@0 622 virtual CSSIntPoint GetScrollPositionCSSPixels() MOZ_OVERRIDE {
michael@0 623 return mHelper.GetScrollPositionCSSPixels();
michael@0 624 }
michael@0 625 /**
michael@0 626 * @note This method might destroy the frame, pres shell and other objects.
michael@0 627 */
michael@0 628 virtual void ScrollBy(nsIntPoint aDelta, ScrollUnit aUnit, ScrollMode aMode,
michael@0 629 nsIntPoint* aOverflow, nsIAtom *aOrigin = nullptr) MOZ_OVERRIDE {
michael@0 630 mHelper.ScrollBy(aDelta, aUnit, aMode, aOverflow, aOrigin);
michael@0 631 }
michael@0 632 /**
michael@0 633 * @note This method might destroy the frame, pres shell and other objects.
michael@0 634 */
michael@0 635 virtual void ScrollToRestoredPosition() MOZ_OVERRIDE {
michael@0 636 mHelper.ScrollToRestoredPosition();
michael@0 637 }
michael@0 638 virtual void AddScrollPositionListener(nsIScrollPositionListener* aListener) MOZ_OVERRIDE {
michael@0 639 mHelper.AddScrollPositionListener(aListener);
michael@0 640 }
michael@0 641 virtual void RemoveScrollPositionListener(nsIScrollPositionListener* aListener) MOZ_OVERRIDE {
michael@0 642 mHelper.RemoveScrollPositionListener(aListener);
michael@0 643 }
michael@0 644 /**
michael@0 645 * @note This method might destroy the frame, pres shell and other objects.
michael@0 646 */
michael@0 647 virtual void CurPosAttributeChanged(nsIContent* aChild) MOZ_OVERRIDE {
michael@0 648 mHelper.CurPosAttributeChanged(aChild);
michael@0 649 }
michael@0 650 NS_IMETHOD PostScrolledAreaEventForCurrentArea() MOZ_OVERRIDE {
michael@0 651 mHelper.PostScrolledAreaEvent();
michael@0 652 return NS_OK;
michael@0 653 }
michael@0 654 virtual bool IsScrollingActive() MOZ_OVERRIDE {
michael@0 655 return mHelper.IsScrollingActive();
michael@0 656 }
michael@0 657 virtual bool IsProcessingAsyncScroll() MOZ_OVERRIDE {
michael@0 658 return mHelper.IsProcessingAsyncScroll();
michael@0 659 }
michael@0 660 virtual void ResetScrollPositionForLayerPixelAlignment() MOZ_OVERRIDE {
michael@0 661 mHelper.ResetScrollPositionForLayerPixelAlignment();
michael@0 662 }
michael@0 663 virtual bool IsResolutionSet() const MOZ_OVERRIDE {
michael@0 664 return mHelper.mIsResolutionSet;
michael@0 665 }
michael@0 666 virtual bool DidHistoryRestore() const MOZ_OVERRIDE {
michael@0 667 return mHelper.mDidHistoryRestore;
michael@0 668 }
michael@0 669 virtual void ClearDidHistoryRestore() MOZ_OVERRIDE {
michael@0 670 mHelper.mDidHistoryRestore = false;
michael@0 671 }
michael@0 672 virtual bool IsRectNearlyVisible(const nsRect& aRect) MOZ_OVERRIDE {
michael@0 673 return mHelper.IsRectNearlyVisible(aRect);
michael@0 674 }
michael@0 675 virtual nsIAtom* OriginOfLastScroll() MOZ_OVERRIDE {
michael@0 676 return mHelper.OriginOfLastScroll();
michael@0 677 }
michael@0 678 virtual uint32_t CurrentScrollGeneration() MOZ_OVERRIDE {
michael@0 679 return mHelper.CurrentScrollGeneration();
michael@0 680 }
michael@0 681 virtual void ResetOriginIfScrollAtGeneration(uint32_t aGeneration) MOZ_OVERRIDE {
michael@0 682 mHelper.ResetOriginIfScrollAtGeneration(aGeneration);
michael@0 683 }
michael@0 684 virtual bool WantAsyncScroll() const MOZ_OVERRIDE {
michael@0 685 return mHelper.WantAsyncScroll();
michael@0 686 }
michael@0 687
michael@0 688 // nsIStatefulFrame
michael@0 689 NS_IMETHOD SaveState(nsPresState** aState) MOZ_OVERRIDE {
michael@0 690 NS_ENSURE_ARG_POINTER(aState);
michael@0 691 *aState = mHelper.SaveState();
michael@0 692 return NS_OK;
michael@0 693 }
michael@0 694 NS_IMETHOD RestoreState(nsPresState* aState) MOZ_OVERRIDE {
michael@0 695 NS_ENSURE_ARG_POINTER(aState);
michael@0 696 mHelper.RestoreState(aState);
michael@0 697 return NS_OK;
michael@0 698 }
michael@0 699
michael@0 700 /**
michael@0 701 * Get the "type" of the frame
michael@0 702 *
michael@0 703 * @see nsGkAtoms::scrollFrame
michael@0 704 */
michael@0 705 virtual nsIAtom* GetType() const MOZ_OVERRIDE;
michael@0 706
michael@0 707 #ifdef DEBUG_FRAME_DUMP
michael@0 708 virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE;
michael@0 709 #endif
michael@0 710
michael@0 711 #ifdef ACCESSIBILITY
michael@0 712 virtual mozilla::a11y::AccType AccessibleType() MOZ_OVERRIDE;
michael@0 713 #endif
michael@0 714
michael@0 715 protected:
michael@0 716 nsHTMLScrollFrame(nsIPresShell* aShell, nsStyleContext* aContext, bool aIsRoot);
michael@0 717 void SetSuppressScrollbarUpdate(bool aSuppress) {
michael@0 718 mHelper.mSupppressScrollbarUpdate = aSuppress;
michael@0 719 }
michael@0 720 bool GuessHScrollbarNeeded(const ScrollReflowState& aState);
michael@0 721 bool GuessVScrollbarNeeded(const ScrollReflowState& aState);
michael@0 722
michael@0 723 bool IsScrollbarUpdateSuppressed() const {
michael@0 724 return mHelper.mSupppressScrollbarUpdate;
michael@0 725 }
michael@0 726
michael@0 727 // Return whether we're in an "initial" reflow. Some reflows with
michael@0 728 // NS_FRAME_FIRST_REFLOW set are NOT "initial" as far as we're concerned.
michael@0 729 bool InInitialReflow() const;
michael@0 730
michael@0 731 /**
michael@0 732 * Override this to return false if computed height/min-height/max-height
michael@0 733 * should NOT be propagated to child content.
michael@0 734 * nsListControlFrame uses this.
michael@0 735 */
michael@0 736 virtual bool ShouldPropagateComputedHeightToScrolledContent() const { return true; }
michael@0 737
michael@0 738 private:
michael@0 739 friend class mozilla::ScrollFrameHelper;
michael@0 740 ScrollFrameHelper mHelper;
michael@0 741 };
michael@0 742
michael@0 743 /**
michael@0 744 * The scroll frame creates and manages the scrolling view
michael@0 745 *
michael@0 746 * It only supports having a single child frame that typically is an area
michael@0 747 * frame, but doesn't have to be. The child frame must have a view, though
michael@0 748 *
michael@0 749 * Scroll frames don't support incremental changes, i.e. you can't replace
michael@0 750 * or remove the scrolled frame
michael@0 751 */
michael@0 752 class nsXULScrollFrame : public nsBoxFrame,
michael@0 753 public nsIScrollableFrame,
michael@0 754 public nsIAnonymousContentCreator,
michael@0 755 public nsIStatefulFrame {
michael@0 756 public:
michael@0 757 typedef mozilla::ScrollFrameHelper ScrollFrameHelper;
michael@0 758 typedef mozilla::CSSIntPoint CSSIntPoint;
michael@0 759
michael@0 760 NS_DECL_QUERYFRAME
michael@0 761 NS_DECL_FRAMEARENA_HELPERS
michael@0 762
michael@0 763 friend nsIFrame* NS_NewXULScrollFrame(nsIPresShell* aPresShell, nsStyleContext* aContext,
michael@0 764 bool aIsRoot, bool aClipAllDescendants);
michael@0 765
michael@0 766 // Called to set the child frames. We typically have three: the scroll area,
michael@0 767 // the vertical scrollbar, and the horizontal scrollbar.
michael@0 768 virtual nsresult SetInitialChildList(ChildListID aListID,
michael@0 769 nsFrameList& aChildList) MOZ_OVERRIDE;
michael@0 770
michael@0 771 virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder,
michael@0 772 const nsRect& aDirtyRect,
michael@0 773 const nsDisplayListSet& aLists) MOZ_OVERRIDE {
michael@0 774 mHelper.BuildDisplayList(aBuilder, aDirtyRect, aLists);
michael@0 775 }
michael@0 776
michael@0 777 // XXXldb Is this actually used?
michael@0 778 #if 0
michael@0 779 virtual nscoord GetMinWidth(nsRenderingContext *aRenderingContext) MOZ_OVERRIDE;
michael@0 780 #endif
michael@0 781
michael@0 782 virtual bool UpdateOverflow() MOZ_OVERRIDE {
michael@0 783 return mHelper.UpdateOverflow();
michael@0 784 }
michael@0 785
michael@0 786 // Because there can be only one child frame, these two function return
michael@0 787 // NS_ERROR_FAILURE
michael@0 788 virtual nsresult AppendFrames(ChildListID aListID,
michael@0 789 nsFrameList& aFrameList) MOZ_OVERRIDE;
michael@0 790 virtual nsresult InsertFrames(ChildListID aListID,
michael@0 791 nsIFrame* aPrevFrame,
michael@0 792 nsFrameList& aFrameList) MOZ_OVERRIDE;
michael@0 793
michael@0 794 virtual void DestroyFrom(nsIFrame* aDestructRoot) MOZ_OVERRIDE;
michael@0 795
michael@0 796 virtual nsresult RemoveFrame(ChildListID aListID,
michael@0 797 nsIFrame* aOldFrame) MOZ_OVERRIDE;
michael@0 798
michael@0 799 virtual nsIScrollableFrame* GetScrollTargetFrame() MOZ_OVERRIDE {
michael@0 800 return this;
michael@0 801 }
michael@0 802
michael@0 803 virtual nsIFrame* GetContentInsertionFrame() MOZ_OVERRIDE {
michael@0 804 return mHelper.GetScrolledFrame()->GetContentInsertionFrame();
michael@0 805 }
michael@0 806
michael@0 807 virtual bool DoesClipChildren() MOZ_OVERRIDE { return true; }
michael@0 808 virtual nsSplittableType GetSplittableType() const MOZ_OVERRIDE;
michael@0 809
michael@0 810 virtual nsPoint GetPositionOfChildIgnoringScrolling(nsIFrame* aChild) MOZ_OVERRIDE
michael@0 811 { nsPoint pt = aChild->GetPosition();
michael@0 812 if (aChild == mHelper.GetScrolledFrame())
michael@0 813 pt += mHelper.GetLogicalScrollPosition();
michael@0 814 return pt;
michael@0 815 }
michael@0 816
michael@0 817 // nsIAnonymousContentCreator
michael@0 818 virtual nsresult CreateAnonymousContent(nsTArray<ContentInfo>& aElements) MOZ_OVERRIDE;
michael@0 819 virtual void AppendAnonymousContentTo(nsBaseContentList& aElements,
michael@0 820 uint32_t aFilter) MOZ_OVERRIDE;
michael@0 821
michael@0 822 virtual nsSize GetMinSize(nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE;
michael@0 823 virtual nsSize GetPrefSize(nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE;
michael@0 824 virtual nsSize GetMaxSize(nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE;
michael@0 825 virtual nscoord GetBoxAscent(nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE;
michael@0 826
michael@0 827 NS_IMETHOD DoLayout(nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE;
michael@0 828 virtual nsresult GetPadding(nsMargin& aPadding) MOZ_OVERRIDE;
michael@0 829
michael@0 830 virtual bool GetBorderRadii(nscoord aRadii[8]) const MOZ_OVERRIDE {
michael@0 831 return mHelper.GetBorderRadii(aRadii);
michael@0 832 }
michael@0 833
michael@0 834 nsresult Layout(nsBoxLayoutState& aState);
michael@0 835 void LayoutScrollArea(nsBoxLayoutState& aState, const nsPoint& aScrollPosition);
michael@0 836
michael@0 837 static bool AddRemoveScrollbar(bool& aHasScrollbar,
michael@0 838 nscoord& aXY,
michael@0 839 nscoord& aSize,
michael@0 840 nscoord aSbSize,
michael@0 841 bool aOnRightOrBottom,
michael@0 842 bool aAdd);
michael@0 843
michael@0 844 bool AddRemoveScrollbar(nsBoxLayoutState& aState,
michael@0 845 bool aOnRightOrBottom,
michael@0 846 bool aHorizontal,
michael@0 847 bool aAdd);
michael@0 848
michael@0 849 bool AddHorizontalScrollbar (nsBoxLayoutState& aState, bool aOnBottom);
michael@0 850 bool AddVerticalScrollbar (nsBoxLayoutState& aState, bool aOnRight);
michael@0 851 void RemoveHorizontalScrollbar(nsBoxLayoutState& aState, bool aOnBottom);
michael@0 852 void RemoveVerticalScrollbar (nsBoxLayoutState& aState, bool aOnRight);
michael@0 853
michael@0 854 static void AdjustReflowStateForPrintPreview(nsBoxLayoutState& aState, bool& aSetBack);
michael@0 855 static void AdjustReflowStateBack(nsBoxLayoutState& aState, bool aSetBack);
michael@0 856
michael@0 857 // nsIScrollbarOwner
michael@0 858 virtual nsIFrame* GetScrollbarBox(bool aVertical) MOZ_OVERRIDE {
michael@0 859 return mHelper.GetScrollbarBox(aVertical);
michael@0 860 }
michael@0 861
michael@0 862 virtual void ScrollbarActivityStarted() const MOZ_OVERRIDE;
michael@0 863 virtual void ScrollbarActivityStopped() const MOZ_OVERRIDE;
michael@0 864
michael@0 865 // nsIScrollableFrame
michael@0 866 virtual nsIFrame* GetScrolledFrame() const MOZ_OVERRIDE {
michael@0 867 return mHelper.GetScrolledFrame();
michael@0 868 }
michael@0 869 virtual mozilla::ScrollbarStyles GetScrollbarStyles() const MOZ_OVERRIDE {
michael@0 870 return mHelper.GetScrollbarStylesFromFrame();
michael@0 871 }
michael@0 872 virtual uint32_t GetScrollbarVisibility() const MOZ_OVERRIDE {
michael@0 873 return mHelper.GetScrollbarVisibility();
michael@0 874 }
michael@0 875 virtual nsMargin GetActualScrollbarSizes() const MOZ_OVERRIDE {
michael@0 876 return mHelper.GetActualScrollbarSizes();
michael@0 877 }
michael@0 878 virtual nsMargin GetDesiredScrollbarSizes(nsBoxLayoutState* aState) MOZ_OVERRIDE {
michael@0 879 return mHelper.GetDesiredScrollbarSizes(aState);
michael@0 880 }
michael@0 881 virtual nsMargin GetDesiredScrollbarSizes(nsPresContext* aPresContext,
michael@0 882 nsRenderingContext* aRC) MOZ_OVERRIDE {
michael@0 883 nsBoxLayoutState bls(aPresContext, aRC, 0);
michael@0 884 return GetDesiredScrollbarSizes(&bls);
michael@0 885 }
michael@0 886 virtual nscoord GetNondisappearingScrollbarWidth(nsPresContext* aPresContext,
michael@0 887 nsRenderingContext* aRC) MOZ_OVERRIDE {
michael@0 888 nsBoxLayoutState bls(aPresContext, aRC, 0);
michael@0 889 return mHelper.GetNondisappearingScrollbarWidth(&bls);
michael@0 890 }
michael@0 891 virtual nsRect GetScrolledRect() const MOZ_OVERRIDE {
michael@0 892 return mHelper.GetScrolledRect();
michael@0 893 }
michael@0 894 virtual nsRect GetScrollPortRect() const MOZ_OVERRIDE {
michael@0 895 return mHelper.GetScrollPortRect();
michael@0 896 }
michael@0 897 virtual nsPoint GetScrollPosition() const MOZ_OVERRIDE {
michael@0 898 return mHelper.GetScrollPosition();
michael@0 899 }
michael@0 900 virtual nsPoint GetLogicalScrollPosition() const MOZ_OVERRIDE {
michael@0 901 return mHelper.GetLogicalScrollPosition();
michael@0 902 }
michael@0 903 virtual nsRect GetScrollRange() const MOZ_OVERRIDE {
michael@0 904 return mHelper.GetScrollRange();
michael@0 905 }
michael@0 906 virtual nsSize GetScrollPositionClampingScrollPortSize() const MOZ_OVERRIDE {
michael@0 907 return mHelper.GetScrollPositionClampingScrollPortSize();
michael@0 908 }
michael@0 909 virtual gfxSize GetResolution() const MOZ_OVERRIDE {
michael@0 910 return mHelper.GetResolution();
michael@0 911 }
michael@0 912 virtual void SetResolution(const gfxSize& aResolution) MOZ_OVERRIDE {
michael@0 913 return mHelper.SetResolution(aResolution);
michael@0 914 }
michael@0 915 virtual nsSize GetLineScrollAmount() const MOZ_OVERRIDE {
michael@0 916 return mHelper.GetLineScrollAmount();
michael@0 917 }
michael@0 918 virtual nsSize GetPageScrollAmount() const MOZ_OVERRIDE {
michael@0 919 return mHelper.GetPageScrollAmount();
michael@0 920 }
michael@0 921 /**
michael@0 922 * @note This method might destroy the frame, pres shell and other objects.
michael@0 923 */
michael@0 924 virtual void ScrollTo(nsPoint aScrollPosition, ScrollMode aMode,
michael@0 925 const nsRect* aRange = nullptr) MOZ_OVERRIDE {
michael@0 926 mHelper.ScrollTo(aScrollPosition, aMode, aRange);
michael@0 927 }
michael@0 928 /**
michael@0 929 * @note This method might destroy the frame, pres shell and other objects.
michael@0 930 */
michael@0 931 virtual void ScrollToCSSPixels(const CSSIntPoint& aScrollPosition) MOZ_OVERRIDE {
michael@0 932 mHelper.ScrollToCSSPixels(aScrollPosition);
michael@0 933 }
michael@0 934 virtual void ScrollToCSSPixelsApproximate(const mozilla::CSSPoint& aScrollPosition,
michael@0 935 nsIAtom* aOrigin = nullptr) MOZ_OVERRIDE {
michael@0 936 mHelper.ScrollToCSSPixelsApproximate(aScrollPosition, aOrigin);
michael@0 937 }
michael@0 938 virtual CSSIntPoint GetScrollPositionCSSPixels() MOZ_OVERRIDE {
michael@0 939 return mHelper.GetScrollPositionCSSPixels();
michael@0 940 }
michael@0 941 /**
michael@0 942 * @note This method might destroy the frame, pres shell and other objects.
michael@0 943 */
michael@0 944 virtual void ScrollBy(nsIntPoint aDelta, ScrollUnit aUnit, ScrollMode aMode,
michael@0 945 nsIntPoint* aOverflow, nsIAtom* aOrigin = nullptr) MOZ_OVERRIDE {
michael@0 946 mHelper.ScrollBy(aDelta, aUnit, aMode, aOverflow, aOrigin);
michael@0 947 }
michael@0 948 /**
michael@0 949 * @note This method might destroy the frame, pres shell and other objects.
michael@0 950 */
michael@0 951 virtual void ScrollToRestoredPosition() MOZ_OVERRIDE {
michael@0 952 mHelper.ScrollToRestoredPosition();
michael@0 953 }
michael@0 954 virtual void AddScrollPositionListener(nsIScrollPositionListener* aListener) MOZ_OVERRIDE {
michael@0 955 mHelper.AddScrollPositionListener(aListener);
michael@0 956 }
michael@0 957 virtual void RemoveScrollPositionListener(nsIScrollPositionListener* aListener) MOZ_OVERRIDE {
michael@0 958 mHelper.RemoveScrollPositionListener(aListener);
michael@0 959 }
michael@0 960 /**
michael@0 961 * @note This method might destroy the frame, pres shell and other objects.
michael@0 962 */
michael@0 963 virtual void CurPosAttributeChanged(nsIContent* aChild) MOZ_OVERRIDE {
michael@0 964 mHelper.CurPosAttributeChanged(aChild);
michael@0 965 }
michael@0 966 NS_IMETHOD PostScrolledAreaEventForCurrentArea() MOZ_OVERRIDE {
michael@0 967 mHelper.PostScrolledAreaEvent();
michael@0 968 return NS_OK;
michael@0 969 }
michael@0 970 virtual bool IsScrollingActive() MOZ_OVERRIDE {
michael@0 971 return mHelper.IsScrollingActive();
michael@0 972 }
michael@0 973 virtual bool IsProcessingAsyncScroll() MOZ_OVERRIDE {
michael@0 974 return mHelper.IsProcessingAsyncScroll();
michael@0 975 }
michael@0 976 virtual void ResetScrollPositionForLayerPixelAlignment() MOZ_OVERRIDE {
michael@0 977 mHelper.ResetScrollPositionForLayerPixelAlignment();
michael@0 978 }
michael@0 979 virtual bool IsResolutionSet() const MOZ_OVERRIDE {
michael@0 980 return mHelper.mIsResolutionSet;
michael@0 981 }
michael@0 982 virtual bool DidHistoryRestore() const MOZ_OVERRIDE {
michael@0 983 return mHelper.mDidHistoryRestore;
michael@0 984 }
michael@0 985 virtual void ClearDidHistoryRestore() MOZ_OVERRIDE {
michael@0 986 mHelper.mDidHistoryRestore = false;
michael@0 987 }
michael@0 988 virtual bool IsRectNearlyVisible(const nsRect& aRect) MOZ_OVERRIDE {
michael@0 989 return mHelper.IsRectNearlyVisible(aRect);
michael@0 990 }
michael@0 991 virtual nsIAtom* OriginOfLastScroll() MOZ_OVERRIDE {
michael@0 992 return mHelper.OriginOfLastScroll();
michael@0 993 }
michael@0 994 virtual uint32_t CurrentScrollGeneration() MOZ_OVERRIDE {
michael@0 995 return mHelper.CurrentScrollGeneration();
michael@0 996 }
michael@0 997 virtual void ResetOriginIfScrollAtGeneration(uint32_t aGeneration) MOZ_OVERRIDE {
michael@0 998 mHelper.ResetOriginIfScrollAtGeneration(aGeneration);
michael@0 999 }
michael@0 1000 virtual bool WantAsyncScroll() const MOZ_OVERRIDE {
michael@0 1001 return mHelper.WantAsyncScroll();
michael@0 1002 }
michael@0 1003
michael@0 1004 // nsIStatefulFrame
michael@0 1005 NS_IMETHOD SaveState(nsPresState** aState) MOZ_OVERRIDE {
michael@0 1006 NS_ENSURE_ARG_POINTER(aState);
michael@0 1007 *aState = mHelper.SaveState();
michael@0 1008 return NS_OK;
michael@0 1009 }
michael@0 1010 NS_IMETHOD RestoreState(nsPresState* aState) MOZ_OVERRIDE {
michael@0 1011 NS_ENSURE_ARG_POINTER(aState);
michael@0 1012 mHelper.RestoreState(aState);
michael@0 1013 return NS_OK;
michael@0 1014 }
michael@0 1015
michael@0 1016 /**
michael@0 1017 * Get the "type" of the frame
michael@0 1018 *
michael@0 1019 * @see nsGkAtoms::scrollFrame
michael@0 1020 */
michael@0 1021 virtual nsIAtom* GetType() const MOZ_OVERRIDE;
michael@0 1022
michael@0 1023 virtual bool IsFrameOfType(uint32_t aFlags) const MOZ_OVERRIDE
michael@0 1024 {
michael@0 1025 // Override bogus IsFrameOfType in nsBoxFrame.
michael@0 1026 if (aFlags & (nsIFrame::eReplacedContainsBlock | nsIFrame::eReplaced))
michael@0 1027 return false;
michael@0 1028 return nsBoxFrame::IsFrameOfType(aFlags);
michael@0 1029 }
michael@0 1030
michael@0 1031 #ifdef DEBUG_FRAME_DUMP
michael@0 1032 virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE;
michael@0 1033 #endif
michael@0 1034
michael@0 1035 protected:
michael@0 1036 nsXULScrollFrame(nsIPresShell* aShell, nsStyleContext* aContext, bool aIsRoot,
michael@0 1037 bool aClipAllDescendants);
michael@0 1038
michael@0 1039 void ClampAndSetBounds(nsBoxLayoutState& aState,
michael@0 1040 nsRect& aRect,
michael@0 1041 nsPoint aScrollPosition,
michael@0 1042 bool aRemoveOverflowAreas = false) {
michael@0 1043 /*
michael@0 1044 * For RTL frames, restore the original scrolled position of the right
michael@0 1045 * edge, then subtract the current width to find the physical position.
michael@0 1046 */
michael@0 1047 if (!mHelper.IsLTR()) {
michael@0 1048 aRect.x = mHelper.mScrollPort.XMost() - aScrollPosition.x - aRect.width;
michael@0 1049 }
michael@0 1050 mHelper.mScrolledFrame->SetBounds(aState, aRect, aRemoveOverflowAreas);
michael@0 1051 }
michael@0 1052
michael@0 1053 private:
michael@0 1054 friend class mozilla::ScrollFrameHelper;
michael@0 1055 ScrollFrameHelper mHelper;
michael@0 1056 };
michael@0 1057
michael@0 1058 #endif /* nsGfxScrollFrame_h___ */

mercurial