1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 // 8 // nsScrollbarFrame 9 // 10 11 #ifndef nsScrollbarFrame_h__ 12 #define nsScrollbarFrame_h__ 13 14 #include "mozilla/Attributes.h" 15 #include "nsBoxFrame.h" 16 17 class nsIScrollbarMediator; 18 19 nsIFrame* NS_NewScrollbarFrame(nsIPresShell* aPresShell, 20 nsStyleContext* aContext); 21 22 class nsScrollbarFrame final : public nsBoxFrame { 23 public: nsScrollbarFrame(nsStyleContext * aContext)24 explicit nsScrollbarFrame(nsStyleContext* aContext) 25 : nsBoxFrame(aContext, kClassID), 26 mIncrement(0), 27 mSmoothScroll(false), 28 mScrollbarMediator(nullptr) {} 29 30 NS_DECL_QUERYFRAME NS_DECL_FRAMEARENA_HELPERS(nsScrollbarFrame)31 NS_DECL_FRAMEARENA_HELPERS(nsScrollbarFrame) 32 33 #ifdef DEBUG_FRAME_DUMP 34 virtual nsresult GetFrameName(nsAString& aResult) const override { 35 return MakeFrameName(NS_LITERAL_STRING("ScrollbarFrame"), aResult); 36 } 37 #endif 38 39 // nsIFrame overrides 40 virtual nsresult AttributeChanged(int32_t aNameSpaceID, nsAtom* aAttribute, 41 int32_t aModType) override; 42 43 NS_IMETHOD HandlePress(nsPresContext* aPresContext, 44 mozilla::WidgetGUIEvent* aEvent, 45 nsEventStatus* aEventStatus) override; 46 47 NS_IMETHOD HandleMultiplePress(nsPresContext* aPresContext, 48 mozilla::WidgetGUIEvent* aEvent, 49 nsEventStatus* aEventStatus, 50 bool aControlHeld) override; 51 52 NS_IMETHOD HandleDrag(nsPresContext* aPresContext, 53 mozilla::WidgetGUIEvent* aEvent, 54 nsEventStatus* aEventStatus) override; 55 56 NS_IMETHOD HandleRelease(nsPresContext* aPresContext, 57 mozilla::WidgetGUIEvent* aEvent, 58 nsEventStatus* aEventStatus) override; 59 60 virtual void Init(nsIContent* aContent, nsContainerFrame* aParent, 61 nsIFrame* aPrevInFlow) override; 62 63 virtual void Reflow(nsPresContext* aPresContext, ReflowOutput& aDesiredSize, 64 const ReflowInput& aReflowInput, 65 nsReflowStatus& aStatus) override; 66 67 void SetScrollbarMediatorContent(nsIContent* aMediator); 68 nsIScrollbarMediator* GetScrollbarMediator(); 69 70 // nsBox methods 71 72 /** 73 * Treat scrollbars as clipping their children; overflowing children 74 * will not be allowed to set an overflow rect on this 75 * frame. This means that when the scroll code decides to hide a 76 * scrollframe by setting its height or width to zero, that will 77 * hide the children too. 78 */ DoesClipChildren()79 virtual bool DoesClipChildren() override { return true; } 80 81 virtual nsresult GetXULMargin(nsMargin& aMargin) override; 82 83 /** 84 * The following three methods set the value of mIncrement when a 85 * scrollbar button is pressed. 86 */ 87 void SetIncrementToLine(int32_t aDirection); 88 void SetIncrementToPage(int32_t aDirection); 89 void SetIncrementToWhole(int32_t aDirection); 90 /** 91 * MoveToNewPosition() adds mIncrement to the current position and 92 * updates the curpos attribute. 93 * @returns The new position after clamping, in CSS Pixels 94 * @note This method might destroy the frame, pres shell, and other objects. 95 */ 96 int32_t MoveToNewPosition(); GetIncrement()97 int32_t GetIncrement() { return mIncrement; } 98 99 protected: 100 int32_t mIncrement; // Amount to scroll, in CSSPixels 101 bool mSmoothScroll; 102 103 private: 104 nsCOMPtr<nsIContent> mScrollbarMediator; 105 }; // class nsScrollbarFrame 106 107 #endif 108