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/. */
11 #ifndef nsScrollbarFrame_h__
12 #define nsScrollbarFrame_h__
14 #include "mozilla/Attributes.h"
15 #include "mozilla/ScrollTypes.h"
16 #include "nsContainerFrame.h"
17 #include "nsIAnonymousContentCreator.h"
19 class nsIScrollbarMediator
;
26 } // namespace mozilla
28 nsIFrame
* NS_NewScrollbarFrame(mozilla::PresShell
* aPresShell
,
29 mozilla::ComputedStyle
* aStyle
);
31 class nsScrollbarFrame final
: public nsContainerFrame
,
32 public nsIAnonymousContentCreator
{
33 using Element
= mozilla::dom::Element
;
36 explicit nsScrollbarFrame(ComputedStyle
* aStyle
, nsPresContext
* aPresContext
)
37 : nsContainerFrame(aStyle
, aPresContext
, kClassID
),
39 mScrollUnit(mozilla::ScrollUnit::DEVICE_PIXELS
),
42 mScrollbarMediator(nullptr),
43 mUpTopButton(nullptr),
44 mDownTopButton(nullptr),
47 mUpBottomButton(nullptr),
48 mDownBottomButton(nullptr) {}
51 NS_DECL_FRAMEARENA_HELPERS(nsScrollbarFrame
)
53 #ifdef DEBUG_FRAME_DUMP
54 nsresult
GetFrameName(nsAString
& aResult
) const override
{
55 return MakeFrameName(u
"ScrollbarFrame"_ns
, aResult
);
60 nsresult
AttributeChanged(int32_t aNameSpaceID
, nsAtom
* aAttribute
,
61 int32_t aModType
) override
;
63 NS_IMETHOD
HandlePress(nsPresContext
* aPresContext
,
64 mozilla::WidgetGUIEvent
* aEvent
,
65 nsEventStatus
* aEventStatus
) override
;
67 NS_IMETHOD
HandleMultiplePress(nsPresContext
* aPresContext
,
68 mozilla::WidgetGUIEvent
* aEvent
,
69 nsEventStatus
* aEventStatus
,
70 bool aControlHeld
) override
;
73 NS_IMETHOD
HandleDrag(nsPresContext
* aPresContext
,
74 mozilla::WidgetGUIEvent
* aEvent
,
75 nsEventStatus
* aEventStatus
) override
;
77 NS_IMETHOD
HandleRelease(nsPresContext
* aPresContext
,
78 mozilla::WidgetGUIEvent
* aEvent
,
79 nsEventStatus
* aEventStatus
) override
;
81 mozilla::StyleScrollbarWidth
ScrollbarWidth() const;
82 nscoord
ScrollbarTrackSize() const;
83 nsSize
ScrollbarMinSize() const;
84 bool IsHorizontal() const;
86 void Destroy(DestroyContext
&) override
;
88 void Init(nsIContent
* aContent
, nsContainerFrame
* aParent
,
89 nsIFrame
* aPrevInFlow
) override
;
91 void Reflow(nsPresContext
* aPresContext
, ReflowOutput
& aDesiredSize
,
92 const ReflowInput
& aReflowInput
,
93 nsReflowStatus
& aStatus
) override
;
95 void SetScrollbarMediatorContent(nsIContent
* aMediator
);
96 nsIScrollbarMediator
* GetScrollbarMediator();
99 * The following three methods set the value of mIncrement when a
100 * scrollbar button is pressed.
102 void SetIncrementToLine(int32_t aDirection
);
103 void SetIncrementToPage(int32_t aDirection
);
104 void SetIncrementToWhole(int32_t aDirection
);
107 * If aImplementsScrollByUnit is Yes then this uses mSmoothScroll,
108 * mScrollUnit, and mDirection and calls ScrollByUnit on the
109 * nsIScrollbarMediator. The return value is 0. This is better because it is
110 * more modern and the scroll frame can perform the scroll via apz for
111 * example. The old way below is still supported for xul trees. If
112 * aImplementsScrollByUnit is No this adds mIncrement to the current
113 * position and updates the curpos attribute obeying mSmoothScroll.
114 * @returns The new position after clamping, in CSS Pixels
115 * @note This method might destroy the frame, pres shell, and other objects.
117 enum class ImplementsScrollByUnit
{ Yes
, No
};
118 int32_t MoveToNewPosition(ImplementsScrollByUnit aImplementsScrollByUnit
);
119 int32_t GetIncrement() { return mIncrement
; }
121 // nsIAnonymousContentCreator
122 nsresult
CreateAnonymousContent(nsTArray
<ContentInfo
>& aElements
) override
;
123 void AppendAnonymousContentTo(nsTArray
<nsIContent
*>& aElements
,
124 uint32_t aFilter
) override
;
126 void UpdateChildrenAttributeValue(nsAtom
* aAttribute
, bool aNotify
);
130 mozilla::ScrollUnit mScrollUnit
;
131 // Direction and multiple to scroll
134 // Amount to scroll, in CSSPixels
135 // Ignored in favour of mScrollUnit/mDirection for regular scroll frames.
136 // Trees use this though.
140 nsCOMPtr
<nsIContent
> mScrollbarMediator
;
142 nsCOMPtr
<Element
> mUpTopButton
;
143 nsCOMPtr
<Element
> mDownTopButton
;
144 nsCOMPtr
<Element
> mSlider
;
145 nsCOMPtr
<Element
> mThumb
;
146 nsCOMPtr
<Element
> mUpBottomButton
;
147 nsCOMPtr
<Element
> mDownBottomButton
;
148 }; // class nsScrollbarFrame