Back to index

lightning-sunbird  0.9+nobinonly
nsScrollBoxFrame.cpp
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  *   Author: Eric D Vaughan <evaughan@netscape.com>
00024  *   Pierre Phaneuf <pp@ludusdesign.com>
00025  *   Dan Rosen <dr@netscape.com>
00026  *
00027  * Alternatively, the contents of this file may be used under the terms of
00028  * either of the GNU General Public License Version 2 or later (the "GPL"),
00029  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00030  * in which case the provisions of the GPL or the LGPL are applicable instead
00031  * of those above. If you wish to allow use of your version of this file only
00032  * under the terms of either the GPL or the LGPL, and not to allow others to
00033  * use your version of this file under the terms of the MPL, indicate your
00034  * decision by deleting the provisions above and replace them with the notice
00035  * and other provisions required by the GPL or the LGPL. If you do not delete
00036  * the provisions above, a recipient may use your version of this file under
00037  * the terms of any one of the MPL, the GPL or the LGPL.
00038  *
00039  * ***** END LICENSE BLOCK ***** */
00040 
00041 #include "nsCOMPtr.h"
00042 #include "nsHTMLParts.h"
00043 #include "nsPresContext.h"
00044 #include "nsIDeviceContext.h"
00045 #include "nsPageFrame.h"
00046 #include "nsIView.h"
00047 #include "nsIViewManager.h"
00048 #include "nsHTMLContainerFrame.h"
00049 #include "nsCSSRendering.h"
00050 #include "nsIScrollableView.h"
00051 #include "nsWidgetsCID.h"
00052 #include "nsLayoutAtoms.h"
00053 #include "nsBoxLayoutState.h"
00054 #include "nsIScrollbarMediator.h"
00055 #include "nsIFormControlFrame.h"
00056 #include "nsGfxScrollFrame.h"
00057 #include "nsXPCOM.h"
00058 #include "nsISupportsPrimitives.h"
00059 #include "nsButtonBoxFrame.h"
00060 #include "nsITimer.h"
00061 #include "nsRepeatService.h"
00062 
00063 class nsAutoRepeatBoxFrame : public nsButtonBoxFrame, 
00064                              public nsITimerCallback
00065 {
00066 public:
00067   NS_DECL_ISUPPORTS_INHERITED
00068 
00069   nsAutoRepeatBoxFrame(nsIPresShell* aPresShell);
00070   friend nsresult NS_NewAutoRepeatBoxFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame);
00071 
00072   NS_IMETHOD Destroy(nsPresContext* aPresContext);
00073 
00074   NS_IMETHOD HandleEvent(nsPresContext* aPresContext, 
00075                          nsGUIEvent* aEvent,
00076                          nsEventStatus* aEventStatus);
00077 
00078   NS_DECL_NSITIMERCALLBACK
00079 
00080 protected:
00081   PRPackedBool mTrustedEvent;
00082 };
00083 
00084 nsresult
00085 NS_NewAutoRepeatBoxFrame ( nsIPresShell* aPresShell, nsIFrame** aNewFrame )
00086 {
00087   NS_PRECONDITION(aNewFrame, "null OUT ptr");
00088   if (nsnull == aNewFrame) {
00089     return NS_ERROR_NULL_POINTER;
00090   }
00091   nsAutoRepeatBoxFrame* it = new (aPresShell) nsAutoRepeatBoxFrame (aPresShell);
00092   if (nsnull == it)
00093     return NS_ERROR_OUT_OF_MEMORY;
00094 
00095   *aNewFrame = it;
00096   return NS_OK;
00097   
00098 } // NS_NewScrollBarButtonFrame
00099 
00100 
00101 nsAutoRepeatBoxFrame::nsAutoRepeatBoxFrame(nsIPresShell* aPresShell)
00102 :nsButtonBoxFrame(aPresShell)
00103 {
00104 }
00105 
00106 NS_INTERFACE_MAP_BEGIN(nsAutoRepeatBoxFrame)
00107   NS_INTERFACE_MAP_ENTRY(nsITimerCallback)
00108 NS_INTERFACE_MAP_END_INHERITING(nsButtonBoxFrame)
00109 
00110 NS_IMPL_ADDREF_INHERITED(nsAutoRepeatBoxFrame, nsButtonBoxFrame)
00111 NS_IMPL_RELEASE_INHERITED(nsAutoRepeatBoxFrame, nsButtonBoxFrame)
00112 
00113 NS_IMETHODIMP
00114 nsAutoRepeatBoxFrame::HandleEvent(nsPresContext* aPresContext, 
00115                                       nsGUIEvent* aEvent,
00116                                       nsEventStatus* aEventStatus)
00117 {  
00118   switch(aEvent->message)
00119   {
00120     case NS_MOUSE_ENTER:
00121     case NS_MOUSE_ENTER_SYNTH:
00122       nsRepeatService::GetInstance()->Start(this);
00123       mTrustedEvent = NS_IS_TRUSTED_EVENT(aEvent);
00124       break;
00125 
00126     case NS_MOUSE_EXIT:
00127     case NS_MOUSE_EXIT_SYNTH:
00128       nsRepeatService::GetInstance()->Stop();
00129       // Not really necessary but do this to be safe
00130       mTrustedEvent = PR_FALSE;
00131       break;
00132   }
00133      
00134   return nsButtonBoxFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
00135 }
00136 
00137 NS_IMETHODIMP
00138 nsAutoRepeatBoxFrame::Notify(nsITimer *timer)
00139 {
00140   DoMouseClick(nsnull, mTrustedEvent);
00141   return NS_OK;
00142 }
00143 
00144 NS_IMETHODIMP
00145 nsAutoRepeatBoxFrame::Destroy(nsPresContext* aPresContext)
00146 {
00147   // Ensure our repeat service isn't going... it's possible that a scrollbar can disappear out
00148   // from under you while you're in the process of scrolling.
00149   nsRepeatService::GetInstance()->Stop();
00150   return nsButtonBoxFrame::Destroy(aPresContext);
00151 }