|
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 #ifndef nsSliderFrame_h__ |
|
7 #define nsSliderFrame_h__ |
|
8 |
|
9 #include "mozilla/Attributes.h" |
|
10 #include "nsRepeatService.h" |
|
11 #include "nsBoxFrame.h" |
|
12 #include "nsIAtom.h" |
|
13 #include "nsCOMPtr.h" |
|
14 #include "nsITimer.h" |
|
15 #include "nsIDOMEventListener.h" |
|
16 |
|
17 class nsString; |
|
18 class nsITimer; |
|
19 class nsSliderFrame; |
|
20 |
|
21 nsIFrame* NS_NewSliderFrame(nsIPresShell* aPresShell, nsStyleContext* aContext); |
|
22 |
|
23 class nsSliderMediator : public nsIDOMEventListener |
|
24 { |
|
25 public: |
|
26 |
|
27 NS_DECL_ISUPPORTS |
|
28 |
|
29 nsSliderFrame* mSlider; |
|
30 |
|
31 nsSliderMediator(nsSliderFrame* aSlider) { mSlider = aSlider; } |
|
32 virtual ~nsSliderMediator() {} |
|
33 |
|
34 virtual void SetSlider(nsSliderFrame* aSlider) { mSlider = aSlider; } |
|
35 |
|
36 NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent) MOZ_OVERRIDE; |
|
37 }; |
|
38 |
|
39 class nsSliderFrame : public nsBoxFrame |
|
40 { |
|
41 public: |
|
42 NS_DECL_FRAMEARENA_HELPERS |
|
43 |
|
44 friend class nsSliderMediator; |
|
45 |
|
46 nsSliderFrame(nsIPresShell* aShell, nsStyleContext* aContext); |
|
47 virtual ~nsSliderFrame(); |
|
48 |
|
49 #ifdef DEBUG_FRAME_DUMP |
|
50 virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE { |
|
51 return MakeFrameName(NS_LITERAL_STRING("SliderFrame"), aResult); |
|
52 } |
|
53 #endif |
|
54 |
|
55 virtual nsSize GetPrefSize(nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE; |
|
56 virtual nsSize GetMinSize(nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE; |
|
57 virtual nsSize GetMaxSize(nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE; |
|
58 NS_IMETHOD DoLayout(nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE; |
|
59 |
|
60 // nsIFrame overrides |
|
61 virtual nsresult AppendFrames(ChildListID aListID, |
|
62 nsFrameList& aFrameList) MOZ_OVERRIDE; |
|
63 |
|
64 virtual nsresult InsertFrames(ChildListID aListID, |
|
65 nsIFrame* aPrevFrame, |
|
66 nsFrameList& aFrameList) MOZ_OVERRIDE; |
|
67 |
|
68 virtual nsresult RemoveFrame(ChildListID aListID, |
|
69 nsIFrame* aOldFrame) MOZ_OVERRIDE; |
|
70 |
|
71 virtual void DestroyFrom(nsIFrame* aDestructRoot) MOZ_OVERRIDE; |
|
72 |
|
73 virtual void BuildDisplayListForChildren(nsDisplayListBuilder* aBuilder, |
|
74 const nsRect& aDirtyRect, |
|
75 const nsDisplayListSet& aLists) MOZ_OVERRIDE; |
|
76 |
|
77 virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder, |
|
78 const nsRect& aDirtyRect, |
|
79 const nsDisplayListSet& aLists) MOZ_OVERRIDE; |
|
80 |
|
81 virtual nsresult AttributeChanged(int32_t aNameSpaceID, |
|
82 nsIAtom* aAttribute, |
|
83 int32_t aModType) MOZ_OVERRIDE; |
|
84 |
|
85 virtual void Init(nsIContent* aContent, |
|
86 nsIFrame* aParent, |
|
87 nsIFrame* asPrevInFlow) MOZ_OVERRIDE; |
|
88 |
|
89 |
|
90 virtual nsresult HandleEvent(nsPresContext* aPresContext, |
|
91 mozilla::WidgetGUIEvent* aEvent, |
|
92 nsEventStatus* aEventStatus) MOZ_OVERRIDE; |
|
93 |
|
94 virtual nsresult SetInitialChildList(ChildListID aListID, |
|
95 nsFrameList& aChildList) MOZ_OVERRIDE; |
|
96 |
|
97 virtual nsIAtom* GetType() const MOZ_OVERRIDE; |
|
98 |
|
99 nsresult StartDrag(nsIDOMEvent* 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, nsIAtom* atom, int32_t defaultValue); |
|
107 void EnsureOrient(); |
|
108 |
|
109 NS_IMETHOD HandlePress(nsPresContext* aPresContext, |
|
110 mozilla::WidgetGUIEvent* aEvent, |
|
111 nsEventStatus* aEventStatus) MOZ_OVERRIDE; |
|
112 |
|
113 NS_IMETHOD HandleMultiplePress(nsPresContext* aPresContext, |
|
114 mozilla::WidgetGUIEvent* aEvent, |
|
115 nsEventStatus* aEventStatus, |
|
116 bool aControlHeld) MOZ_OVERRIDE |
|
117 { |
|
118 return NS_OK; |
|
119 } |
|
120 |
|
121 NS_IMETHOD HandleDrag(nsPresContext* aPresContext, |
|
122 mozilla::WidgetGUIEvent* aEvent, |
|
123 nsEventStatus* aEventStatus) MOZ_OVERRIDE |
|
124 { |
|
125 return NS_OK; |
|
126 } |
|
127 |
|
128 NS_IMETHOD HandleRelease(nsPresContext* aPresContext, |
|
129 mozilla::WidgetGUIEvent* aEvent, |
|
130 nsEventStatus* aEventStatus) MOZ_OVERRIDE; |
|
131 |
|
132 private: |
|
133 |
|
134 bool GetScrollToClick(); |
|
135 nsIFrame* GetScrollbar(); |
|
136 bool ShouldScrollForEvent(mozilla::WidgetGUIEvent* aEvent); |
|
137 bool ShouldScrollToClickForEvent(mozilla::WidgetGUIEvent* aEvent); |
|
138 bool IsEventOverThumb(mozilla::WidgetGUIEvent* aEvent); |
|
139 |
|
140 void PageUpDown(nscoord change); |
|
141 void SetCurrentThumbPosition(nsIContent* aScrollbar, nscoord aNewPos, bool aIsSmooth, |
|
142 bool aMaySnap); |
|
143 void SetCurrentPosition(nsIContent* aScrollbar, int32_t aNewPos, bool aIsSmooth); |
|
144 void SetCurrentPositionInternal(nsIContent* aScrollbar, int32_t pos, |
|
145 bool aIsSmooth); |
|
146 void CurrentPositionChanged(); |
|
147 |
|
148 void DragThumb(bool aGrabMouseEvents); |
|
149 void AddListener(); |
|
150 void RemoveListener(); |
|
151 bool isDraggingThumb(); |
|
152 |
|
153 void StartRepeat() { |
|
154 nsRepeatService::GetInstance()->Start(Notify, this); |
|
155 } |
|
156 void StopRepeat() { |
|
157 nsRepeatService::GetInstance()->Stop(Notify, this); |
|
158 } |
|
159 void Notify(); |
|
160 static void Notify(void* aData) { |
|
161 (static_cast<nsSliderFrame*>(aData))->Notify(); |
|
162 } |
|
163 |
|
164 nsPoint mDestinationPoint; |
|
165 nsRefPtr<nsSliderMediator> mMediator; |
|
166 |
|
167 float mRatio; |
|
168 |
|
169 nscoord mDragStart; |
|
170 nscoord mThumbStart; |
|
171 |
|
172 int32_t mCurPos; |
|
173 |
|
174 nscoord mChange; |
|
175 |
|
176 // true if an attribute change has been caused by the user manipulating the |
|
177 // slider. This allows notifications to tell how a slider's current position |
|
178 // was changed. |
|
179 bool mUserChanged; |
|
180 |
|
181 static bool gMiddlePref; |
|
182 static int32_t gSnapMultiplier; |
|
183 }; // class nsSliderFrame |
|
184 |
|
185 #endif |