1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* ***** BEGIN LICENSE BLOCK *****
3 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 : *
5 : * The contents of this file are subject to the Mozilla Public License Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * the License. You may obtain a copy of the License at
8 : * http://www.mozilla.org/MPL/
9 : *
10 : * Software distributed under the License is distributed on an "AS IS" basis,
11 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : * for the specific language governing rights and limitations under the
13 : * License.
14 : *
15 : * The Original Code is mozilla.org code.
16 : *
17 : * The Initial Developer of the Original Code is
18 : * Netscape Communications Corporation.
19 : * Portions created by the Initial Developer are Copyright (C) 1998
20 : * the Initial Developer. All Rights Reserved.
21 : *
22 : * Contributor(s):
23 : *
24 : * Alternatively, the contents of this file may be used under the terms of
25 : * either of the GNU General Public License Version 2 or later (the "GPL"),
26 : * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 : * in which case the provisions of the GPL or the LGPL are applicable instead
28 : * of those above. If you wish to allow use of your version of this file only
29 : * under the terms of either the GPL or the LGPL, and not to allow others to
30 : * use your version of this file under the terms of the MPL, indicate your
31 : * decision by deleting the provisions above and replace them with the notice
32 : * and other provisions required by the GPL or the LGPL. If you do not delete
33 : * the provisions above, a recipient may use your version of this file under
34 : * the terms of any one of the MPL, the GPL or the LGPL.
35 : *
36 : * ***** END LICENSE BLOCK ***** */
37 :
38 : #ifndef nsSliderFrame_h__
39 : #define nsSliderFrame_h__
40 :
41 : #include "nsRepeatService.h"
42 : #include "nsBoxFrame.h"
43 : #include "prtypes.h"
44 : #include "nsIAtom.h"
45 : #include "nsCOMPtr.h"
46 : #include "nsITimer.h"
47 : #include "nsIDOMEventListener.h"
48 :
49 : class nsString;
50 : class nsITimer;
51 : class nsSliderFrame;
52 :
53 : nsIFrame* NS_NewSliderFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
54 :
55 : class nsSliderMediator : public nsIDOMEventListener
56 : {
57 : public:
58 :
59 : NS_DECL_ISUPPORTS
60 :
61 : nsSliderFrame* mSlider;
62 :
63 0 : nsSliderMediator(nsSliderFrame* aSlider) { mSlider = aSlider; }
64 0 : virtual ~nsSliderMediator() {}
65 :
66 0 : virtual void SetSlider(nsSliderFrame* aSlider) { mSlider = aSlider; }
67 :
68 : NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent);
69 : };
70 :
71 : class nsSliderFrame : public nsBoxFrame
72 : {
73 : public:
74 : NS_DECL_FRAMEARENA_HELPERS
75 :
76 : friend class nsSliderMediator;
77 :
78 : nsSliderFrame(nsIPresShell* aShell, nsStyleContext* aContext);
79 : virtual ~nsSliderFrame();
80 :
81 : #ifdef DEBUG
82 0 : NS_IMETHOD GetFrameName(nsAString& aResult) const {
83 0 : return MakeFrameName(NS_LITERAL_STRING("SliderFrame"), aResult);
84 : }
85 : #endif
86 :
87 : // nsIBox
88 : virtual nsSize GetPrefSize(nsBoxLayoutState& aBoxLayoutState);
89 : virtual nsSize GetMinSize(nsBoxLayoutState& aBoxLayoutState);
90 : virtual nsSize GetMaxSize(nsBoxLayoutState& aBoxLayoutState);
91 : NS_IMETHOD DoLayout(nsBoxLayoutState& aBoxLayoutState);
92 :
93 : // nsIFrame overrides
94 : NS_IMETHOD AppendFrames(ChildListID aListID,
95 : nsFrameList& aFrameList);
96 :
97 : NS_IMETHOD InsertFrames(ChildListID aListID,
98 : nsIFrame* aPrevFrame,
99 : nsFrameList& aFrameList);
100 :
101 : NS_IMETHOD RemoveFrame(ChildListID aListID,
102 : nsIFrame* aOldFrame);
103 :
104 : virtual void DestroyFrom(nsIFrame* aDestructRoot);
105 :
106 : NS_IMETHOD BuildDisplayListForChildren(nsDisplayListBuilder* aBuilder,
107 : const nsRect& aDirtyRect,
108 : const nsDisplayListSet& aLists);
109 :
110 : NS_IMETHOD BuildDisplayList(nsDisplayListBuilder* aBuilder,
111 : const nsRect& aDirtyRect,
112 : const nsDisplayListSet& aLists);
113 :
114 : NS_IMETHOD AttributeChanged(PRInt32 aNameSpaceID,
115 : nsIAtom* aAttribute,
116 : PRInt32 aModType);
117 :
118 : NS_IMETHOD Init(nsIContent* aContent,
119 : nsIFrame* aParent,
120 : nsIFrame* asPrevInFlow);
121 :
122 :
123 : NS_IMETHOD HandleEvent(nsPresContext* aPresContext,
124 : nsGUIEvent* aEvent,
125 : nsEventStatus* aEventStatus);
126 :
127 : NS_IMETHOD SetInitialChildList(ChildListID aListID,
128 : nsFrameList& aChildList);
129 :
130 : virtual nsIAtom* GetType() const;
131 :
132 : nsresult MouseDown(nsIDOMEvent* aMouseEvent);
133 :
134 : static PRInt32 GetCurrentPosition(nsIContent* content);
135 : static PRInt32 GetMinPosition(nsIContent* content);
136 : static PRInt32 GetMaxPosition(nsIContent* content);
137 : static PRInt32 GetIncrement(nsIContent* content);
138 : static PRInt32 GetPageIncrement(nsIContent* content);
139 : static PRInt32 GetIntegerAttribute(nsIContent* content, nsIAtom* atom, PRInt32 defaultValue);
140 : void EnsureOrient();
141 :
142 : NS_IMETHOD HandlePress(nsPresContext* aPresContext,
143 : nsGUIEvent * aEvent,
144 : nsEventStatus* aEventStatus);
145 :
146 0 : NS_IMETHOD HandleMultiplePress(nsPresContext* aPresContext,
147 : nsGUIEvent * aEvent,
148 : nsEventStatus* aEventStatus,
149 0 : bool aControlHeld) { return NS_OK; }
150 :
151 0 : NS_IMETHOD HandleDrag(nsPresContext* aPresContext,
152 : nsGUIEvent * aEvent,
153 0 : nsEventStatus* aEventStatus) { return NS_OK; }
154 :
155 : NS_IMETHOD HandleRelease(nsPresContext* aPresContext,
156 : nsGUIEvent * aEvent,
157 : nsEventStatus* aEventStatus);
158 :
159 : private:
160 :
161 : bool GetScrollToClick();
162 : nsIBox* GetScrollbar();
163 :
164 : void PageUpDown(nscoord change);
165 : void SetCurrentThumbPosition(nsIContent* aScrollbar, nscoord aNewPos, bool aIsSmooth,
166 : bool aImmediateRedraw, bool aMaySnap);
167 : void SetCurrentPosition(nsIContent* aScrollbar, PRInt32 aNewPos, bool aIsSmooth,
168 : bool aImmediateRedraw);
169 : void SetCurrentPositionInternal(nsIContent* aScrollbar, PRInt32 pos,
170 : bool aIsSmooth, bool aImmediateRedraw);
171 : nsresult CurrentPositionChanged(nsPresContext* aPresContext,
172 : bool aImmediateRedraw);
173 : void DragThumb(bool aGrabMouseEvents);
174 : void AddListener();
175 : void RemoveListener();
176 : bool isDraggingThumb();
177 :
178 0 : void StartRepeat() {
179 0 : nsRepeatService::GetInstance()->Start(Notify, this);
180 0 : }
181 0 : void StopRepeat() {
182 0 : nsRepeatService::GetInstance()->Stop(Notify, this);
183 0 : }
184 : void Notify();
185 0 : static void Notify(void* aData) {
186 0 : (static_cast<nsSliderFrame*>(aData))->Notify();
187 0 : }
188 :
189 : nsPoint mDestinationPoint;
190 : nsRefPtr<nsSliderMediator> mMediator;
191 :
192 : float mRatio;
193 :
194 : nscoord mDragStart;
195 : nscoord mThumbStart;
196 :
197 : PRInt32 mCurPos;
198 :
199 : nscoord mChange;
200 :
201 : // true if an attribute change has been caused by the user manipulating the
202 : // slider. This allows notifications to tell how a slider's current position
203 : // was changed.
204 : bool mUserChanged;
205 :
206 : static bool gMiddlePref;
207 : static PRInt32 gSnapMultiplier;
208 : }; // class nsSliderFrame
209 :
210 : #endif
|