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 "mozilla/ScrollTypes.h" 16 #include "nsIAnonymousContentCreator.h" 17 #include "nsBoxFrame.h" 18 19 class nsIScrollbarMediator; 20 21 namespace mozilla { 22 class PresShell; 23 namespace dom { 24 class Element; 25 } 26 } // namespace mozilla 27 28 nsIFrame* NS_NewScrollbarFrame(mozilla::PresShell* aPresShell, 29 mozilla::ComputedStyle* aStyle); 30 31 class nsScrollbarFrame final : public nsBoxFrame, 32 public nsIAnonymousContentCreator { 33 using Element = mozilla::dom::Element; 34 35 public: nsScrollbarFrame(ComputedStyle * aStyle,nsPresContext * aPresContext)36 explicit nsScrollbarFrame(ComputedStyle* aStyle, nsPresContext* aPresContext) 37 : nsBoxFrame(aStyle, aPresContext, kClassID), 38 mSmoothScroll(false), 39 mScrollUnit(mozilla::ScrollUnit::DEVICE_PIXELS), 40 mDirection(0), 41 mIncrement(0), 42 mScrollbarMediator(nullptr), 43 mUpTopButton(nullptr), 44 mDownTopButton(nullptr), 45 mSlider(nullptr), 46 mThumb(nullptr), 47 mUpBottomButton(nullptr), 48 mDownBottomButton(nullptr) {} 49 50 NS_DECL_QUERYFRAME NS_DECL_FRAMEARENA_HELPERS(nsScrollbarFrame)51 NS_DECL_FRAMEARENA_HELPERS(nsScrollbarFrame) 52 53 #ifdef DEBUG_FRAME_DUMP 54 virtual nsresult GetFrameName(nsAString& aResult) const override { 55 return MakeFrameName(u"ScrollbarFrame"_ns, aResult); 56 } 57 #endif 58 59 // nsIFrame overrides 60 virtual nsresult AttributeChanged(int32_t aNameSpaceID, nsAtom* aAttribute, 61 int32_t aModType) override; 62 63 NS_IMETHOD HandlePress(nsPresContext* aPresContext, 64 mozilla::WidgetGUIEvent* aEvent, 65 nsEventStatus* aEventStatus) override; 66 67 NS_IMETHOD HandleMultiplePress(nsPresContext* aPresContext, 68 mozilla::WidgetGUIEvent* aEvent, 69 nsEventStatus* aEventStatus, 70 bool aControlHeld) override; 71 72 MOZ_CAN_RUN_SCRIPT 73 NS_IMETHOD HandleDrag(nsPresContext* aPresContext, 74 mozilla::WidgetGUIEvent* aEvent, 75 nsEventStatus* aEventStatus) override; 76 77 NS_IMETHOD HandleRelease(nsPresContext* aPresContext, 78 mozilla::WidgetGUIEvent* aEvent, 79 nsEventStatus* aEventStatus) override; 80 81 virtual void DestroyFrom(nsIFrame* aDestructRoot, 82 PostDestroyData& aPostDestroyData) override; 83 84 virtual void Init(nsIContent* aContent, nsContainerFrame* aParent, 85 nsIFrame* aPrevInFlow) override; 86 87 virtual void Reflow(nsPresContext* aPresContext, ReflowOutput& aDesiredSize, 88 const ReflowInput& aReflowInput, 89 nsReflowStatus& aStatus) override; 90 91 void SetScrollbarMediatorContent(nsIContent* aMediator); 92 nsIScrollbarMediator* GetScrollbarMediator(); 93 94 // nsBox methods 95 96 /** 97 * Treat scrollbars as clipping their children; overflowing children 98 * will not be allowed to set an overflow rect on this 99 * frame. This means that when the scroll code decides to hide a 100 * scrollframe by setting its height or width to zero, that will 101 * hide the children too. 102 */ DoesClipChildrenInBothAxes()103 virtual bool DoesClipChildrenInBothAxes() override { return true; } 104 105 virtual nsresult GetXULMargin(nsMargin& aMargin) override; 106 107 /** 108 * The following three methods set the value of mIncrement when a 109 * scrollbar button is pressed. 110 */ 111 void SetIncrementToLine(int32_t aDirection); 112 void SetIncrementToPage(int32_t aDirection); 113 void SetIncrementToWhole(int32_t aDirection); 114 /** 115 * If aImplementsScrollByUnit is Yes then this uses mSmoothScroll, 116 * mScrollUnit, and mDirection and calls ScrollByUnit on the 117 * nsIScrollbarMediator. The return value is 0. This is better because it is 118 * more modern and the scroll frame can perform the scroll via apz for 119 * example. The old way below is still supported for xul trees. If 120 * aImplementsScrollByUnit is No this adds mIncrement to the current 121 * position and updates the curpos attribute obeying mSmoothScroll. 122 * @returns The new position after clamping, in CSS Pixels 123 * @note This method might destroy the frame, pres shell, and other objects. 124 */ 125 enum class ImplementsScrollByUnit { Yes, No }; 126 int32_t MoveToNewPosition(ImplementsScrollByUnit aImplementsScrollByUnit); GetIncrement()127 int32_t GetIncrement() { return mIncrement; } 128 129 // nsIAnonymousContentCreator 130 virtual nsresult CreateAnonymousContent( 131 nsTArray<ContentInfo>& aElements) override; 132 virtual void AppendAnonymousContentTo(nsTArray<nsIContent*>& aElements, 133 uint32_t aFilter) override; 134 135 void UpdateChildrenAttributeValue(nsAtom* aAttribute, bool aNotify); 136 137 protected: 138 bool mSmoothScroll; 139 mozilla::ScrollUnit mScrollUnit; 140 // Direction and multiple to scroll 141 int32_t mDirection; 142 143 // Amount to scroll, in CSSPixels 144 // Ignored in favour of mScrollUnit/mDirection for regular scroll frames. 145 // Trees use this though. 146 int32_t mIncrement; 147 148 private: 149 nsCOMPtr<nsIContent> mScrollbarMediator; 150 151 nsCOMPtr<Element> mUpTopButton; 152 nsCOMPtr<Element> mDownTopButton; 153 nsCOMPtr<Element> mSlider; 154 nsCOMPtr<Element> mThumb; 155 nsCOMPtr<Element> mUpBottomButton; 156 nsCOMPtr<Element> mDownBottomButton; 157 }; // class nsScrollbarFrame 158 159 #endif 160