Thu, 15 Jan 2015 21:03:48 +0100
Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)
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/. */
6 #ifndef nsSliderFrame_h__
7 #define nsSliderFrame_h__
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"
17 class nsString;
18 class nsITimer;
19 class nsSliderFrame;
21 nsIFrame* NS_NewSliderFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
23 class nsSliderMediator : public nsIDOMEventListener
24 {
25 public:
27 NS_DECL_ISUPPORTS
29 nsSliderFrame* mSlider;
31 nsSliderMediator(nsSliderFrame* aSlider) { mSlider = aSlider; }
32 virtual ~nsSliderMediator() {}
34 virtual void SetSlider(nsSliderFrame* aSlider) { mSlider = aSlider; }
36 NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent) MOZ_OVERRIDE;
37 };
39 class nsSliderFrame : public nsBoxFrame
40 {
41 public:
42 NS_DECL_FRAMEARENA_HELPERS
44 friend class nsSliderMediator;
46 nsSliderFrame(nsIPresShell* aShell, nsStyleContext* aContext);
47 virtual ~nsSliderFrame();
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
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;
60 // nsIFrame overrides
61 virtual nsresult AppendFrames(ChildListID aListID,
62 nsFrameList& aFrameList) MOZ_OVERRIDE;
64 virtual nsresult InsertFrames(ChildListID aListID,
65 nsIFrame* aPrevFrame,
66 nsFrameList& aFrameList) MOZ_OVERRIDE;
68 virtual nsresult RemoveFrame(ChildListID aListID,
69 nsIFrame* aOldFrame) MOZ_OVERRIDE;
71 virtual void DestroyFrom(nsIFrame* aDestructRoot) MOZ_OVERRIDE;
73 virtual void BuildDisplayListForChildren(nsDisplayListBuilder* aBuilder,
74 const nsRect& aDirtyRect,
75 const nsDisplayListSet& aLists) MOZ_OVERRIDE;
77 virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder,
78 const nsRect& aDirtyRect,
79 const nsDisplayListSet& aLists) MOZ_OVERRIDE;
81 virtual nsresult AttributeChanged(int32_t aNameSpaceID,
82 nsIAtom* aAttribute,
83 int32_t aModType) MOZ_OVERRIDE;
85 virtual void Init(nsIContent* aContent,
86 nsIFrame* aParent,
87 nsIFrame* asPrevInFlow) MOZ_OVERRIDE;
90 virtual nsresult HandleEvent(nsPresContext* aPresContext,
91 mozilla::WidgetGUIEvent* aEvent,
92 nsEventStatus* aEventStatus) MOZ_OVERRIDE;
94 virtual nsresult SetInitialChildList(ChildListID aListID,
95 nsFrameList& aChildList) MOZ_OVERRIDE;
97 virtual nsIAtom* GetType() const MOZ_OVERRIDE;
99 nsresult StartDrag(nsIDOMEvent* aEvent);
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();
109 NS_IMETHOD HandlePress(nsPresContext* aPresContext,
110 mozilla::WidgetGUIEvent* aEvent,
111 nsEventStatus* aEventStatus) MOZ_OVERRIDE;
113 NS_IMETHOD HandleMultiplePress(nsPresContext* aPresContext,
114 mozilla::WidgetGUIEvent* aEvent,
115 nsEventStatus* aEventStatus,
116 bool aControlHeld) MOZ_OVERRIDE
117 {
118 return NS_OK;
119 }
121 NS_IMETHOD HandleDrag(nsPresContext* aPresContext,
122 mozilla::WidgetGUIEvent* aEvent,
123 nsEventStatus* aEventStatus) MOZ_OVERRIDE
124 {
125 return NS_OK;
126 }
128 NS_IMETHOD HandleRelease(nsPresContext* aPresContext,
129 mozilla::WidgetGUIEvent* aEvent,
130 nsEventStatus* aEventStatus) MOZ_OVERRIDE;
132 private:
134 bool GetScrollToClick();
135 nsIFrame* GetScrollbar();
136 bool ShouldScrollForEvent(mozilla::WidgetGUIEvent* aEvent);
137 bool ShouldScrollToClickForEvent(mozilla::WidgetGUIEvent* aEvent);
138 bool IsEventOverThumb(mozilla::WidgetGUIEvent* aEvent);
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();
148 void DragThumb(bool aGrabMouseEvents);
149 void AddListener();
150 void RemoveListener();
151 bool isDraggingThumb();
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 }
164 nsPoint mDestinationPoint;
165 nsRefPtr<nsSliderMediator> mMediator;
167 float mRatio;
169 nscoord mDragStart;
170 nscoord mThumbStart;
172 int32_t mCurPos;
174 nscoord mChange;
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;
181 static bool gMiddlePref;
182 static int32_t gSnapMultiplier;
183 }; // class nsSliderFrame
185 #endif