Bug 1859059 - increase chunk number for windows debug mochitest-browser-chrome jobs...
[gecko.git] / layout / xul / nsSliderFrame.h
blob311aa59ae438356c7596428c93a61a3bc854549d
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/. */
7 #ifndef nsSliderFrame_h__
8 #define nsSliderFrame_h__
10 #include "mozilla/Attributes.h"
11 #include "nsContainerFrame.h"
12 #include "nsRepeatService.h"
13 #include "nsAtom.h"
14 #include "nsCOMPtr.h"
15 #include "nsITimer.h"
16 #include "nsIDOMEventListener.h"
18 class nsITimer;
19 class nsScrollbarFrame;
20 class nsSliderFrame;
22 namespace mozilla {
23 class nsDisplaySliderMarks;
24 class PresShell;
25 } // namespace mozilla
27 nsIFrame* NS_NewSliderFrame(mozilla::PresShell* aPresShell,
28 mozilla::ComputedStyle* aStyle);
30 class nsSliderMediator final : public nsIDOMEventListener {
31 public:
32 NS_DECL_ISUPPORTS
34 nsSliderFrame* mSlider;
36 explicit nsSliderMediator(nsSliderFrame* aSlider) { mSlider = aSlider; }
38 void SetSlider(nsSliderFrame* aSlider) { mSlider = aSlider; }
40 NS_DECL_NSIDOMEVENTLISTENER
42 protected:
43 virtual ~nsSliderMediator() = default;
46 class nsSliderFrame final : public nsContainerFrame {
47 public:
48 NS_DECL_FRAMEARENA_HELPERS(nsSliderFrame)
49 NS_DECL_QUERYFRAME
51 friend class nsSliderMediator;
52 friend class mozilla::nsDisplaySliderMarks;
54 explicit nsSliderFrame(ComputedStyle* aStyle, nsPresContext* aPresContext);
55 virtual ~nsSliderFrame();
57 // Get the point associated with this event. Returns true if a single valid
58 // point was found. Otherwise false.
59 bool GetEventPoint(mozilla::WidgetGUIEvent* aEvent, nsPoint& aPoint);
60 // Gets the event coordinates relative to the widget associated with this
61 // frame. Return true if a single valid point was found.
62 bool GetEventPoint(mozilla::WidgetGUIEvent* aEvent,
63 mozilla::LayoutDeviceIntPoint& aPoint);
65 #ifdef DEBUG_FRAME_DUMP
66 nsresult GetFrameName(nsAString& aResult) const override {
67 return MakeFrameName(u"SliderFrame"_ns, aResult);
69 #endif
71 void Reflow(nsPresContext* aPresContext, ReflowOutput& aDesiredSize,
72 const ReflowInput& aReflowInput,
73 nsReflowStatus& aStatus) override;
75 // nsIFrame overrides
76 void Destroy(DestroyContext&) override;
78 void BuildDisplayList(nsDisplayListBuilder* aBuilder,
79 const nsDisplayListSet& aLists) override;
81 void BuildDisplayListForThumb(nsDisplayListBuilder* aBuilder,
82 nsIFrame* aThumb,
83 const nsDisplayListSet& aLists);
85 nsresult AttributeChanged(int32_t aNameSpaceID, nsAtom* aAttribute,
86 int32_t aModType) override;
88 void Init(nsIContent* aContent, nsContainerFrame* aParent,
89 nsIFrame* aPrevInFlow) override;
91 nsresult HandleEvent(nsPresContext* aPresContext,
92 mozilla::WidgetGUIEvent* aEvent,
93 nsEventStatus* aEventStatus) override;
95 // nsContainerFrame overrides
96 void SetInitialChildList(ChildListID aListID,
97 nsFrameList&& aChildList) override;
98 void AppendFrames(ChildListID aListID, nsFrameList&& aFrameList) override;
99 void InsertFrames(ChildListID aListID, nsIFrame* aPrevFrame,
100 const nsLineList::iterator* aPrevFrameLine,
101 nsFrameList&& aFrameList) override;
102 void RemoveFrame(DestroyContext&, ChildListID, nsIFrame*) override;
104 nsresult StartDrag(mozilla::dom::Event* aEvent);
105 nsresult StopDrag();
107 void StartAPZDrag(mozilla::WidgetGUIEvent* aEvent);
109 static int32_t GetCurrentPosition(nsIContent* content);
110 static int32_t GetMinPosition(nsIContent* content);
111 static int32_t GetMaxPosition(nsIContent* content);
112 static int32_t GetIncrement(nsIContent* content);
113 static int32_t GetPageIncrement(nsIContent* content);
114 static int32_t GetIntegerAttribute(nsIContent* content, nsAtom* atom,
115 int32_t defaultValue);
117 NS_IMETHOD HandlePress(nsPresContext* aPresContext,
118 mozilla::WidgetGUIEvent* aEvent,
119 nsEventStatus* aEventStatus) override;
121 NS_IMETHOD HandleMultiplePress(nsPresContext* aPresContext,
122 mozilla::WidgetGUIEvent* aEvent,
123 nsEventStatus* aEventStatus,
124 bool aControlHeld) override {
125 return NS_OK;
128 MOZ_CAN_RUN_SCRIPT
129 NS_IMETHOD HandleDrag(nsPresContext* aPresContext,
130 mozilla::WidgetGUIEvent* aEvent,
131 nsEventStatus* aEventStatus) override {
132 return NS_OK;
135 NS_IMETHOD HandleRelease(nsPresContext* aPresContext,
136 mozilla::WidgetGUIEvent* aEvent,
137 nsEventStatus* aEventStatus) override;
139 // Return the ratio the scrollbar thumb should move in proportion to the
140 // scrolled frame.
141 float GetThumbRatio() const;
143 // Notify the slider frame that an async scrollbar drag was started on the
144 // APZ side without consulting the main thread. The block id is the APZ
145 // input block id of the mousedown that started the drag.
146 void AsyncScrollbarDragInitiated(uint64_t aDragBlockId);
148 // Notify the slider frame that an async scrollbar drag requested in
149 // StartAPZDrag() was rejected by APZ, and the slider frame should
150 // fall back to main-thread dragging.
151 void AsyncScrollbarDragRejected();
153 bool OnlySystemGroupDispatch(mozilla::EventMessage aMessage) const override;
155 // Returns the associated scrollframe that contains this slider if any.
156 nsIScrollableFrame* GetScrollFrame();
158 private:
159 bool GetScrollToClick();
160 nsScrollbarFrame* Scrollbar();
161 bool ShouldScrollForEvent(mozilla::WidgetGUIEvent* aEvent);
162 bool ShouldScrollToClickForEvent(mozilla::WidgetGUIEvent* aEvent);
163 bool IsEventOverThumb(mozilla::WidgetGUIEvent* aEvent);
165 void PageUpDown(nscoord change);
166 void SetCurrentThumbPosition(nsIContent* aScrollbar, nscoord aNewPos,
167 bool aIsSmooth, bool aMaySnap);
168 void SetCurrentPosition(nsIContent* aScrollbar, int32_t aNewPos,
169 bool aIsSmooth);
170 void SetCurrentPositionInternal(nsIContent* aScrollbar, int32_t pos,
171 bool aIsSmooth);
172 void CurrentPositionChanged();
174 void DragThumb(bool aGrabMouseEvents);
175 void AddListener();
176 void RemoveListener();
177 bool isDraggingThumb() const;
179 void SuppressDisplayport();
180 void UnsuppressDisplayport();
182 void StartRepeat() {
183 nsRepeatService::GetInstance()->Start(Notify, this, mContent->OwnerDoc(),
184 "nsSliderFrame"_ns);
186 void StopRepeat() {
187 nsRepeatService::GetInstance()->Stop(Notify, this);
188 mCurrentClickHoldDestination = Nothing();
190 void Notify();
191 static void Notify(void* aData) {
192 (static_cast<nsSliderFrame*>(aData))->Notify();
194 void PageScroll(bool aClickAndHold);
196 nsPoint mDestinationPoint;
197 // If we are in a scrollbar track click-and-hold, this is populated with
198 // the destination of the scroll started at the most recent tick of the
199 // repeat timer.
200 Maybe<nsPoint> mCurrentClickHoldDestination;
201 RefPtr<nsSliderMediator> mMediator;
203 float mRatio;
205 nscoord mDragStart;
206 nscoord mThumbStart;
208 int32_t mCurPos;
210 nscoord mRepeatDirection;
212 bool mDragFinished;
214 // true if an attribute change has been caused by the user manipulating the
215 // slider. This allows notifications to tell how a slider's current position
216 // was changed.
217 bool mUserChanged;
219 // true if we've handed off the scrolling to APZ. This means that we should
220 // ignore scrolling events as the position will be updated by APZ. If we were
221 // to process these events then the scroll position update would conflict
222 // causing the scroll position to jump.
223 bool mScrollingWithAPZ;
225 // true if displayport suppression is active, for more performant
226 // scrollbar-dragging behaviour.
227 bool mSuppressionActive;
229 // If APZ initiated a scrollbar drag without main-thread involvement, it
230 // notifies us and this variable stores the input block id of the APZ input
231 // block that started the drag. This lets us handle the corresponding
232 // mousedown event properly, if it arrives after the scroll position has
233 // been shifted due to async scrollbar drag.
234 Maybe<uint64_t> mAPZDragInitiated;
236 nscoord mThumbMinLength;
238 static bool gMiddlePref;
239 }; // class nsSliderFrame
241 #endif