/src/mozilla-central/layout/xul/nsSliderFrame.h
Line | Count | Source (jump to first uncovered line) |
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 | | #ifndef nsSliderFrame_h__ |
8 | | #define nsSliderFrame_h__ |
9 | | |
10 | | #include "mozilla/Attributes.h" |
11 | | #include "nsRepeatService.h" |
12 | | #include "nsBoxFrame.h" |
13 | | #include "nsAtom.h" |
14 | | #include "nsCOMPtr.h" |
15 | | #include "nsITimer.h" |
16 | | #include "nsIDOMEventListener.h" |
17 | | |
18 | | class nsITimer; |
19 | | class nsSliderFrame; |
20 | | |
21 | | nsIFrame* NS_NewSliderFrame(nsIPresShell* aPresShell, mozilla::ComputedStyle* aStyle); |
22 | | |
23 | | class nsSliderMediator final : public nsIDOMEventListener |
24 | | { |
25 | | public: |
26 | | |
27 | | NS_DECL_ISUPPORTS |
28 | | |
29 | | nsSliderFrame* mSlider; |
30 | | |
31 | 0 | explicit nsSliderMediator(nsSliderFrame* aSlider) { mSlider = aSlider; } |
32 | | |
33 | 0 | virtual void SetSlider(nsSliderFrame* aSlider) { mSlider = aSlider; } |
34 | | |
35 | | NS_DECL_NSIDOMEVENTLISTENER |
36 | | |
37 | | protected: |
38 | 0 | virtual ~nsSliderMediator() {} |
39 | | }; |
40 | | |
41 | | class nsSliderFrame final : public nsBoxFrame |
42 | | { |
43 | | public: |
44 | | NS_DECL_FRAMEARENA_HELPERS(nsSliderFrame) |
45 | | NS_DECL_QUERYFRAME |
46 | | |
47 | | friend class nsSliderMediator; |
48 | | |
49 | | explicit nsSliderFrame(ComputedStyle* aStyle); |
50 | | virtual ~nsSliderFrame(); |
51 | | |
52 | | #ifdef DEBUG_FRAME_DUMP |
53 | | virtual nsresult GetFrameName(nsAString& aResult) const override { |
54 | | return MakeFrameName(NS_LITERAL_STRING("SliderFrame"), aResult); |
55 | | } |
56 | | #endif |
57 | | |
58 | | virtual nsSize GetXULPrefSize(nsBoxLayoutState& aBoxLayoutState) override; |
59 | | virtual nsSize GetXULMinSize(nsBoxLayoutState& aBoxLayoutState) override; |
60 | | virtual nsSize GetXULMaxSize(nsBoxLayoutState& aBoxLayoutState) override; |
61 | | NS_IMETHOD DoXULLayout(nsBoxLayoutState& aBoxLayoutState) override; |
62 | | |
63 | | // nsIFrame overrides |
64 | | virtual void DestroyFrom(nsIFrame* aDestructRoot, PostDestroyData& aPostDestroyData) override; |
65 | | |
66 | | virtual void BuildDisplayListForChildren(nsDisplayListBuilder* aBuilder, |
67 | | const nsDisplayListSet& aLists) override; |
68 | | |
69 | | virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder, |
70 | | const nsDisplayListSet& aLists) override; |
71 | | |
72 | | virtual nsresult AttributeChanged(int32_t aNameSpaceID, |
73 | | nsAtom* aAttribute, |
74 | | int32_t aModType) override; |
75 | | |
76 | | virtual void Init(nsIContent* aContent, |
77 | | nsContainerFrame* aParent, |
78 | | nsIFrame* asPrevInFlow) override; |
79 | | |
80 | | |
81 | | virtual nsresult HandleEvent(nsPresContext* aPresContext, |
82 | | mozilla::WidgetGUIEvent* aEvent, |
83 | | nsEventStatus* aEventStatus) override; |
84 | | |
85 | | // nsContainerFrame overrides |
86 | | virtual void SetInitialChildList(ChildListID aListID, |
87 | | nsFrameList& aChildList) override; |
88 | | virtual void AppendFrames(ChildListID aListID, |
89 | | nsFrameList& aFrameList) override; |
90 | | virtual void InsertFrames(ChildListID aListID, |
91 | | nsIFrame* aPrevFrame, |
92 | | nsFrameList& aFrameList) override; |
93 | | virtual void RemoveFrame(ChildListID aListID, |
94 | | nsIFrame* aOldFrame) override; |
95 | | |
96 | | nsresult StartDrag(mozilla::dom::Event* aEvent); |
97 | | nsresult StopDrag(); |
98 | | |
99 | | void StartAPZDrag(mozilla::WidgetGUIEvent* aEvent); |
100 | | |
101 | | static int32_t GetCurrentPosition(nsIContent* content); |
102 | | static int32_t GetMinPosition(nsIContent* content); |
103 | | static int32_t GetMaxPosition(nsIContent* content); |
104 | | static int32_t GetIncrement(nsIContent* content); |
105 | | static int32_t GetPageIncrement(nsIContent* content); |
106 | | static int32_t GetIntegerAttribute(nsIContent* content, nsAtom* atom, int32_t defaultValue); |
107 | | void EnsureOrient(); |
108 | | |
109 | | NS_IMETHOD HandlePress(nsPresContext* aPresContext, |
110 | | mozilla::WidgetGUIEvent* aEvent, |
111 | | nsEventStatus* aEventStatus) override; |
112 | | |
113 | | NS_IMETHOD HandleMultiplePress(nsPresContext* aPresContext, |
114 | | mozilla::WidgetGUIEvent* aEvent, |
115 | | nsEventStatus* aEventStatus, |
116 | | bool aControlHeld) override |
117 | 0 | { |
118 | 0 | return NS_OK; |
119 | 0 | } |
120 | | |
121 | | NS_IMETHOD HandleDrag(nsPresContext* aPresContext, |
122 | | mozilla::WidgetGUIEvent* aEvent, |
123 | | nsEventStatus* aEventStatus) override |
124 | 0 | { |
125 | 0 | return NS_OK; |
126 | 0 | } |
127 | | |
128 | | NS_IMETHOD HandleRelease(nsPresContext* aPresContext, |
129 | | mozilla::WidgetGUIEvent* aEvent, |
130 | | nsEventStatus* aEventStatus) override; |
131 | | |
132 | | // Return the ratio the scrollbar thumb should move in proportion to the |
133 | | // scrolled frame. |
134 | | float GetThumbRatio() const; |
135 | | |
136 | | // Notify the slider frame than an async scrollbar drag requested in |
137 | | // StartAPZDrag() was rejected by APZ, and the slider frame should |
138 | | // fall back to main-thread dragging. |
139 | | void AsyncScrollbarDragRejected(); |
140 | | |
141 | | bool OnlySystemGroupDispatch(mozilla::EventMessage aMessage) const override; |
142 | | |
143 | | // Returns the associated scrollframe that contains this slider if any. |
144 | | nsIScrollableFrame* GetScrollFrame(); |
145 | | |
146 | | private: |
147 | | |
148 | | bool GetScrollToClick(); |
149 | | nsIFrame* GetScrollbar(); |
150 | | bool ShouldScrollForEvent(mozilla::WidgetGUIEvent* aEvent); |
151 | | bool ShouldScrollToClickForEvent(mozilla::WidgetGUIEvent* aEvent); |
152 | | bool IsEventOverThumb(mozilla::WidgetGUIEvent* aEvent); |
153 | | |
154 | | void PageUpDown(nscoord change); |
155 | | void SetCurrentThumbPosition(nsIContent* aScrollbar, nscoord aNewPos, bool aIsSmooth, |
156 | | bool aMaySnap); |
157 | | void SetCurrentPosition(nsIContent* aScrollbar, int32_t aNewPos, bool aIsSmooth); |
158 | | void SetCurrentPositionInternal(nsIContent* aScrollbar, int32_t pos, |
159 | | bool aIsSmooth); |
160 | | void CurrentPositionChanged(); |
161 | | |
162 | | void DragThumb(bool aGrabMouseEvents); |
163 | | void AddListener(); |
164 | | void RemoveListener(); |
165 | | bool isDraggingThumb() const; |
166 | | |
167 | | void SuppressDisplayport(); |
168 | | void UnsuppressDisplayport(); |
169 | | |
170 | 0 | void StartRepeat() { |
171 | 0 | nsRepeatService::GetInstance()->Start(Notify, this, |
172 | 0 | mContent->OwnerDoc(), |
173 | 0 | NS_LITERAL_CSTRING("nsSliderFrame")); |
174 | 0 | } |
175 | 0 | void StopRepeat() { |
176 | 0 | nsRepeatService::GetInstance()->Stop(Notify, this); |
177 | 0 | } |
178 | | void Notify(); |
179 | 0 | static void Notify(void* aData) { |
180 | 0 | (static_cast<nsSliderFrame*>(aData))->Notify(); |
181 | 0 | } |
182 | | void PageScroll(nscoord aChange); |
183 | | |
184 | | nsPoint mDestinationPoint; |
185 | | RefPtr<nsSliderMediator> mMediator; |
186 | | |
187 | | float mRatio; |
188 | | |
189 | | nscoord mDragStart; |
190 | | nscoord mThumbStart; |
191 | | |
192 | | int32_t mCurPos; |
193 | | |
194 | | nscoord mChange; |
195 | | |
196 | | bool mDragFinished; |
197 | | |
198 | | // true if an attribute change has been caused by the user manipulating the |
199 | | // slider. This allows notifications to tell how a slider's current position |
200 | | // was changed. |
201 | | bool mUserChanged; |
202 | | |
203 | | // true if we've handed off the scrolling to APZ. This means that we should |
204 | | // ignore scrolling events as the position will be updated by APZ. If we were |
205 | | // to process these events then the scroll position update would conflict |
206 | | // causing the scroll position to jump. |
207 | | bool mScrollingWithAPZ; |
208 | | |
209 | | // true if displayport suppression is active, for more performant |
210 | | // scrollbar-dragging behaviour. |
211 | | bool mSuppressionActive; |
212 | | |
213 | | static bool gMiddlePref; |
214 | | static int32_t gSnapMultiplier; |
215 | | }; // class nsSliderFrame |
216 | | |
217 | | #endif |