Back to index

lightning-sunbird  0.9+nobinonly
nsSliderFrame.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #ifndef nsSliderFrame_h__
00039 #define nsSliderFrame_h__
00040 
00041 
00042 #include "nsBoxFrame.h"
00043 #include "prtypes.h"
00044 #include "nsIAtom.h"
00045 #include "nsCOMPtr.h"
00046 #include "nsITimer.h"
00047 #include "nsIDOMMouseListener.h"
00048 
00049 class nsString;
00050 class nsIScrollbarListener;
00051 class nsISupportsArray;
00052 class nsITimer;
00053 class nsSliderFrame;
00054 
00055 nsresult NS_NewSliderFrame(nsIPresShell* aPresShell, nsIFrame** aResult) ;
00056 
00057 
00058 class nsSliderMediator : public nsIDOMMouseListener, 
00059                          public nsITimerCallback
00060 {
00061 public:
00062 
00063   NS_DECL_ISUPPORTS
00064 
00065   nsSliderFrame* mSlider;
00066 
00067   nsSliderMediator(nsSliderFrame* aSlider) {  mSlider = aSlider; }
00068   virtual ~nsSliderMediator() {}
00069 
00070   virtual void SetSlider(nsSliderFrame* aSlider) { mSlider = aSlider; }
00071 
00077   NS_IMETHOD MouseDown(nsIDOMEvent* aMouseEvent);
00078 
00084   NS_IMETHOD MouseUp(nsIDOMEvent* aMouseEvent);
00085 
00092   NS_IMETHOD MouseClick(nsIDOMEvent* aMouseEvent) { return NS_OK; }
00093 
00100   NS_IMETHOD MouseDblClick(nsIDOMEvent* aMouseEvent) { return NS_OK; }
00101 
00107   NS_IMETHOD MouseOver(nsIDOMEvent* aMouseEvent) { return NS_OK; }
00108 
00114   NS_IMETHOD MouseOut(nsIDOMEvent* aMouseEvent) { return NS_OK; }
00115 
00116   NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent) { return NS_OK; }
00117 
00118   NS_DECL_NSITIMERCALLBACK
00119 
00120 
00121 }; // class nsSliderFrame
00122 
00123 class nsSliderFrame : public nsBoxFrame
00124 {
00125 public:
00126   friend class nsSliderMediator;
00127 
00128   nsSliderFrame(nsIPresShell* aShell);
00129   virtual ~nsSliderFrame();
00130 
00131 #ifdef DEBUG
00132   NS_IMETHOD GetFrameName(nsAString& aResult) const {
00133     return MakeFrameName(NS_LITERAL_STRING("SliderFrame"), aResult);
00134   }
00135 #endif
00136 
00137   // nsIBox
00138   NS_IMETHOD GetPrefSize(nsBoxLayoutState& aBoxLayoutState, nsSize& aSize);
00139   NS_IMETHOD GetMinSize(nsBoxLayoutState& aBoxLayoutState, nsSize& aSize);
00140   NS_IMETHOD GetMaxSize(nsBoxLayoutState& aBoxLayoutState, nsSize& aSize);
00141   NS_IMETHOD DoLayout(nsBoxLayoutState& aBoxLayoutState);
00142 
00143   // nsIFrame overrides
00144   NS_IMETHOD  AppendFrames(nsIAtom*        aListName,
00145                            nsIFrame*       aFrameList);
00146 
00147   NS_IMETHOD  InsertFrames(nsIAtom*        aListName,
00148                            nsIFrame*       aPrevFrame,
00149                            nsIFrame*       aFrameList);
00150 
00151   NS_IMETHOD  RemoveFrame(nsIAtom*        aListName,
00152                           nsIFrame*       aOldFrame);
00153 
00154   NS_IMETHOD Destroy(nsPresContext* aPresContext);
00155 
00156   NS_IMETHOD Paint(nsPresContext*      aPresContext,
00157                    nsIRenderingContext& aRenderingContext,
00158                    const nsRect&        aDirtyRect,
00159                    nsFramePaintLayer    aWhichLayer,
00160                    PRUint32             aFlags = 0);
00161  
00162   NS_IMETHOD AttributeChanged(nsIContent* aChild,
00163                               PRInt32 aNameSpaceID,
00164                               nsIAtom* aAttribute,
00165                               PRInt32 aModType);
00166 
00167   NS_IMETHOD  Init(nsPresContext*  aPresContext,
00168                    nsIContent*      aContent,
00169                    nsIFrame*        aParent,
00170                    nsStyleContext*  aContext,
00171                    nsIFrame*        asPrevInFlow);
00172 
00173 
00174   NS_IMETHOD HandleEvent(nsPresContext* aPresContext, 
00175                          nsGUIEvent* aEvent,
00176                          nsEventStatus* aEventStatus);
00177 
00178   NS_IMETHOD GetFrameForPoint(const nsPoint& aPoint,
00179                               nsFramePaintLayer aWhichLayer,    
00180                               nsIFrame**     aFrame);
00181 
00182   NS_IMETHOD SetInitialChildList(nsPresContext* aPresContext,
00183                                  nsIAtom*        aListName,
00184                                  nsIFrame*       aChildList);
00185 
00186   virtual nsIAtom* GetType() const;
00187 
00188   NS_IMETHOD MouseDown(nsIDOMEvent* aMouseEvent);
00189   NS_IMETHOD MouseUp(nsIDOMEvent* aMouseEvent);
00190 
00191   NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent) { return NS_OK; }
00192 
00193   static PRInt32 GetCurrentPosition(nsIContent* content);
00194   static PRInt32 GetMaxPosition(nsIContent* content);
00195   static PRInt32 GetIncrement(nsIContent* content);
00196   static PRInt32 GetPageIncrement(nsIContent* content);
00197   static PRInt32 GetIntegerAttribute(nsIContent* content, nsIAtom* atom, PRInt32 defaultValue);
00198   void EnsureOrient();
00199 
00200   void SetScrollbarListener(nsIScrollbarListener* aListener);
00201 
00202   virtual nsIView* GetMouseCapturer() const { return GetView(); }
00203 
00204   NS_IMETHOD HandlePress(nsPresContext* aPresContext,
00205                          nsGUIEvent *    aEvent,
00206                          nsEventStatus*  aEventStatus);
00207 
00208   NS_IMETHOD HandleMultiplePress(nsPresContext* aPresContext,
00209                          nsGUIEvent *    aEvent,
00210                          nsEventStatus*  aEventStatus)  { return NS_OK; }
00211 
00212   NS_IMETHOD HandleDrag(nsPresContext* aPresContext,
00213                         nsGUIEvent *    aEvent,
00214                         nsEventStatus*  aEventStatus)  { return NS_OK; }
00215 
00216   NS_IMETHOD HandleRelease(nsPresContext* aPresContext,
00217                            nsGUIEvent *    aEvent,
00218                            nsEventStatus*  aEventStatus);
00219 
00220   NS_IMETHOD_(void) Notify(nsITimer *timer);
00221  
00222 private:
00223 
00224   nsIBox* GetScrollbar();
00225 
00226   void PageUpDown(nsIFrame* aThumbFrame, nscoord change);
00227   nsresult CurrentPositionChanged(nsPresContext* aPresContext,
00228                                   PRBool aImmediateRedraw);
00229   void SetCurrentPosition(nsIContent* scrollbar,
00230                           nsIFrame* aThumbFrame, nscoord pos, PRBool aIsSmooth,
00231                           PRBool aImmediateRedraw);
00232   void DragThumb(PRBool aGrabMouseEvents);
00233   void AddListener();
00234   void RemoveListener();
00235   PRBool isDraggingThumb();
00236 
00237   // Convert aEvent->point into our coordinate system
00238   nsPoint EventPointInOurCoords(nsEvent* aEvent);
00239 
00240   float mRatio;
00241 
00242   nscoord mDragStart;
00243   nscoord mThumbStart;
00244 
00245   PRInt32 mCurPos;
00246 
00247   nsIScrollbarListener* mScrollbarListener;
00248 
00249   nscoord mChange;
00250   nsPoint mDestinationPoint;
00251   nsSliderMediator* mMediator;
00252 
00253   static PRBool gMiddlePref;
00254   static PRInt32 gSnapMultiplier;
00255 }; // class nsSliderFrame
00256 
00257 #endif