Back to index

lightning-sunbird  0.9+nobinonly
nsXULTooltipListener.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 nsXULTooltipListener_h__
00039 #define nsXULTooltipListener_h__
00040 
00041 #include "nsIDOMMouseListener.h"
00042 #include "nsIDOMMouseMotionListener.h"
00043 #include "nsIDOMKeyListener.h"
00044 #include "nsIDOMMouseEvent.h"
00045 #include "nsIDOMXULListener.h"
00046 #include "nsIContent.h"
00047 #include "nsIDOMElement.h"
00048 #include "nsITimer.h"
00049 #include "nsIRootBox.h"
00050 #include "nsCOMPtr.h"
00051 #include "nsString.h"
00052 #ifdef MOZ_XUL
00053 #include "nsITreeBoxObject.h"
00054 #include "nsITreeColumns.h"
00055 #endif
00056 
00057 class nsXULTooltipListener : public nsIDOMMouseListener,
00058                              public nsIDOMMouseMotionListener,
00059                              public nsIDOMKeyListener,
00060                              public nsIDOMXULListener
00061 {
00062 public:
00063 
00064   nsXULTooltipListener();
00065   virtual ~nsXULTooltipListener();
00066 
00067   // nsISupports
00068   NS_DECL_ISUPPORTS
00069 
00070   // nsIDOMMouseListener
00071   NS_IMETHOD MouseDown(nsIDOMEvent* aMouseEvent);
00072   NS_IMETHOD MouseUp(nsIDOMEvent* aMouseEvent);
00073   NS_IMETHOD MouseClick(nsIDOMEvent* aMouseEvent) { return NS_OK; };
00074   NS_IMETHOD MouseDblClick(nsIDOMEvent* aMouseEvent) { return NS_OK; };
00075   NS_IMETHOD MouseOver(nsIDOMEvent* aMouseEvent) { return NS_OK; };
00076   NS_IMETHOD MouseOut(nsIDOMEvent* aMouseEvent);
00077 
00078   // nsIDOMMouseMotionListener
00079   NS_IMETHOD DragMove(nsIDOMEvent* aMouseEvent) { return NS_OK; };
00080   NS_IMETHOD MouseMove(nsIDOMEvent* aMouseEvent);
00081 
00082   // nsIDOMKeyListener
00083   NS_IMETHOD KeyDown(nsIDOMEvent* aKeyEvent);
00084   NS_IMETHOD KeyUp(nsIDOMEvent* aKeyEvent) { return NS_OK; };
00085   NS_IMETHOD KeyPress(nsIDOMEvent* aKeyEvent) { return NS_OK; };
00086 
00087   // nsIDOMXULListener
00088   NS_IMETHOD PopupShowing(nsIDOMEvent* aEvent) { return NS_OK; };
00089   NS_IMETHOD PopupShown(nsIDOMEvent* aEvent) { return NS_OK; };
00090   NS_IMETHOD PopupHiding(nsIDOMEvent* aEvent);
00091   NS_IMETHOD PopupHidden(nsIDOMEvent* aEvent) { return NS_OK; };
00092   NS_IMETHOD Close(nsIDOMEvent* aEvent) { return NS_OK; };
00093   NS_IMETHOD Command(nsIDOMEvent* aEvent) { return NS_OK; };
00094   NS_IMETHOD Broadcast(nsIDOMEvent* aEvent) { return NS_OK; };
00095   NS_IMETHOD CommandUpdate(nsIDOMEvent* aEvent) { return NS_OK; };
00096 
00097   // nsIDOMEventListener
00098   NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent);
00099 
00100   nsresult Init(nsIContent* aSourceNode, nsIRootBox* aRootBox);
00101   nsresult SetDefaultTooltip(nsIContent* aDefaultTooltip);
00102   nsresult GetDefaultTooltip(nsIContent** aDefaultTooltip);
00103   nsresult AddTooltipSupport(nsIContent* aNode);
00104   nsresult RemoveTooltipSupport(nsIContent* aNode);
00105 
00106 protected:
00107 
00108   // pref callback for when the "show tooltips" pref changes
00109   static int sTooltipPrefChanged (const char* aPref, void* aData);
00110   static PRBool sShowTooltips;
00111   static PRUint32 sTooltipListenerCount;
00112 
00113   void KillTooltipTimer();
00114   void CreateAutoHideTimer();
00115 
00116 #ifdef MOZ_XUL
00117   void CheckTreeBodyMove(nsIDOMMouseEvent* aMouseEvent);
00118   nsresult GetSourceTreeBoxObject(nsITreeBoxObject** aBoxObject);
00119 #endif
00120 
00121   nsresult ShowTooltip();
00122   nsresult LaunchTooltip(nsIContent* aTarget, PRInt32 aX, PRInt32 aY);
00123   nsresult HideTooltip();
00124   nsresult DestroyTooltip();
00125   nsresult GetTooltipFor(nsIContent* aTarget, nsIContent** aTooltip);
00126 
00127   static int ToolbarTipsPrefChanged(const char *aPref, void *aClosure);
00128 
00129   nsIRootBox* mRootBox;
00130   nsIContent* mSourceNode;
00131   nsCOMPtr<nsIContent> mTargetNode;
00132   nsCOMPtr<nsIContent> mCurrentTooltip;
00133 
00134   // a timer for showing the tooltip
00135   nsCOMPtr<nsITimer> mTooltipTimer;
00136   static void sTooltipCallback (nsITimer* aTimer, void* aListener);
00137   PRInt32 mMouseClientX, mMouseClientY;
00138 
00139   // a timer for auto-hiding the tooltip after a certain delay
00140   nsCOMPtr<nsITimer> mAutoHideTimer;
00141   static void sAutoHideCallback (nsITimer* aTimer, void* aListener);
00142   
00143   // various delays for tooltips
00144   enum {
00145     kTooltipAutoHideTime = 5000,       // 5000ms = 5 seconds
00146     kTooltipShowTime = 500             // 500ms = 0.5 seconds
00147   };
00148 
00149 #ifdef MOZ_XUL
00150   // special members for handling trees
00151   PRBool mIsSourceTree;
00152   PRBool mNeedTitletip;
00153   PRInt32 mLastTreeRow;
00154   nsCOMPtr<nsITreeColumn> mLastTreeCol;
00155 #endif
00156 };
00157 
00158 #endif // nsXULTooltipListener