LCOV - code coverage report
Current view: directory - embedding/browser/webBrowser - nsDocShellTreeOwner.h (source / functions) Found Hit Coverage
Test: app.info Lines: 1 0 0.0 %
Date: 2012-06-02 Functions: 1 0 0.0 %

       1                 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
       2                 :  *
       3                 :  * ***** BEGIN LICENSE BLOCK *****
       4                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
       5                 :  *
       6                 :  * The contents of this file are subject to the Mozilla Public License Version
       7                 :  * 1.1 (the "License"); you may not use this file except in compliance with
       8                 :  * the License. You may obtain a copy of the License at
       9                 :  * http://www.mozilla.org/MPL/
      10                 :  *
      11                 :  * Software distributed under the License is distributed on an "AS IS" basis,
      12                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      13                 :  * for the specific language governing rights and limitations under the
      14                 :  * License.
      15                 :  *
      16                 :  * The Original Code is the Mozilla browser.
      17                 :  *
      18                 :  * The Initial Developer of the Original Code is
      19                 :  * Netscape Communications, Inc.
      20                 :  * Portions created by the Initial Developer are Copyright (C) 1999
      21                 :  * the Initial Developer. All Rights Reserved.
      22                 :  *
      23                 :  * Contributor(s):
      24                 :  *   Travis Bogard <travis@netscape.com>
      25                 :  *
      26                 :  * Alternatively, the contents of this file may be used under the terms of
      27                 :  * either the GNU General Public License Version 2 or later (the "GPL"), or
      28                 :  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      29                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      30                 :  * of those above. If you wish to allow use of your version of this file only
      31                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      32                 :  * use your version of this file under the terms of the MPL, indicate your
      33                 :  * decision by deleting the provisions above and replace them with the notice
      34                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      35                 :  * the provisions above, a recipient may use your version of this file under
      36                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      37                 :  *
      38                 :  * ***** END LICENSE BLOCK ***** */
      39                 : 
      40                 : #ifndef nsDocShellTreeOwner_h__
      41                 : #define nsDocShellTreeOwner_h__
      42                 : 
      43                 : // Helper Classes
      44                 : #include "nsCOMPtr.h"
      45                 : #include "nsString.h"
      46                 : 
      47                 : // Interfaces Needed
      48                 : #include "nsIBaseWindow.h"
      49                 : #include "nsIDocShellTreeOwner.h"
      50                 : #include "nsIInterfaceRequestor.h"
      51                 : #include "nsIInterfaceRequestorUtils.h"
      52                 : #include "nsIWebBrowserChrome.h"
      53                 : #include "nsIDOMEventListener.h"
      54                 : #include "nsIDOMDocument.h"
      55                 : #include "nsIEmbeddingSiteWindow.h"
      56                 : #include "nsIWebProgressListener.h"
      57                 : #include "nsWeakReference.h"
      58                 : #include "nsITimer.h"
      59                 : #include "nsIPrompt.h"
      60                 : #include "nsIAuthPrompt.h"
      61                 : #include "nsITooltipListener.h"
      62                 : #include "nsITooltipTextProvider.h"
      63                 : #include "nsCTooltipTextProvider.h"
      64                 : #include "nsIDroppedLinkHandler.h"
      65                 : #include "nsIDOMEventTarget.h"
      66                 : #include "nsCommandHandler.h"
      67                 : 
      68                 : class nsWebBrowser;
      69                 : class ChromeTooltipListener;
      70                 : class ChromeContextMenuListener;
      71                 : 
      72                 : // {6D10C180-6888-11d4-952B-0020183BF181}
      73                 : #define NS_ICDOCSHELLTREEOWNER_IID \
      74                 : { 0x6d10c180, 0x6888, 0x11d4, { 0x95, 0x2b, 0x0, 0x20, 0x18, 0x3b, 0xf1, 0x81 } }
      75                 : 
      76                 : /*
      77                 :  * This is a fake 'hidden' interface that nsDocShellTreeOwner implements.
      78                 :  * Classes such as nsCommandHandler can QI for this interface to be
      79                 :  * sure that they're dealing with a valid nsDocShellTreeOwner and not some
      80                 :  * other object that implements nsIDocShellTreeOwner.
      81                 :  */
      82                 : class nsICDocShellTreeOwner : public nsISupports
      83               0 : {
      84                 : public:
      85                 :     NS_DECLARE_STATIC_IID_ACCESSOR(NS_ICDOCSHELLTREEOWNER_IID)
      86                 : };
      87                 : 
      88                 : NS_DEFINE_STATIC_IID_ACCESSOR(nsICDocShellTreeOwner,
      89                 :                               NS_ICDOCSHELLTREEOWNER_IID)
      90                 : 
      91                 : class nsDocShellTreeOwner : public nsIDocShellTreeOwner,
      92                 :                             public nsIBaseWindow,
      93                 :                             public nsIInterfaceRequestor,
      94                 :                             public nsIWebProgressListener,
      95                 :                             public nsIDOMEventListener,
      96                 :                             public nsICDocShellTreeOwner,
      97                 :                             public nsSupportsWeakReference
      98                 : {
      99                 : friend class nsWebBrowser;
     100                 : friend class nsCommandHandler;
     101                 : 
     102                 : public:
     103                 :     NS_DECL_ISUPPORTS
     104                 : 
     105                 :     NS_DECL_NSIBASEWINDOW
     106                 :     NS_DECL_NSIDOCSHELLTREEOWNER
     107                 :     NS_DECL_NSIDOMEVENTLISTENER
     108                 :     NS_DECL_NSIINTERFACEREQUESTOR
     109                 :     NS_DECL_NSIWEBPROGRESSLISTENER
     110                 : 
     111                 : protected:
     112                 :     nsDocShellTreeOwner();
     113                 :     virtual ~nsDocShellTreeOwner();
     114                 : 
     115                 :     void WebBrowser(nsWebBrowser* aWebBrowser);
     116                 :     
     117                 :     nsWebBrowser* WebBrowser();
     118                 :     NS_IMETHOD SetTreeOwner(nsIDocShellTreeOwner* aTreeOwner);
     119                 :     NS_IMETHOD SetWebBrowserChrome(nsIWebBrowserChrome* aWebBrowserChrome);
     120                 : 
     121                 :     NS_IMETHOD AddChromeListeners();
     122                 :     NS_IMETHOD RemoveChromeListeners();
     123                 : 
     124                 :     nsresult   FindItemWithNameAcrossWindows(const PRUnichar* aName,
     125                 :                  nsIDocShellTreeItem* aRequestor,
     126                 :                  nsIDocShellTreeItem* aOriginalRequestor,
     127                 :                  nsIDocShellTreeItem **aFoundItem);
     128                 : 
     129                 :     void       EnsurePrompter();
     130                 :     void       EnsureAuthPrompter();
     131                 : 
     132                 :     void AddToWatcher();
     133                 :     void RemoveFromWatcher();
     134                 : 
     135                 :     // These helper functions return the correct instances of the requested
     136                 :     // interfaces.  If the object passed to SetWebBrowserChrome() implements
     137                 :     // nsISupportsWeakReference, then these functions call QueryReferent on
     138                 :     // that object.  Otherwise, they return an addrefed pointer.  If the
     139                 :     // WebBrowserChrome object doesn't exist, they return nsnull.
     140                 :     already_AddRefed<nsIWebBrowserChrome>     GetWebBrowserChrome();
     141                 :     already_AddRefed<nsIEmbeddingSiteWindow>  GetOwnerWin();
     142                 :     already_AddRefed<nsIInterfaceRequestor>   GetOwnerRequestor();
     143                 : 
     144                 : protected:
     145                 : 
     146                 :    // Weak References
     147                 :    nsWebBrowser*           mWebBrowser;
     148                 :    nsIDocShellTreeOwner*   mTreeOwner;
     149                 :    nsIDocShellTreeItem*    mPrimaryContentShell; 
     150                 : 
     151                 :    nsIWebBrowserChrome*    mWebBrowserChrome;
     152                 :    nsIEmbeddingSiteWindow* mOwnerWin;
     153                 :    nsIInterfaceRequestor*  mOwnerRequestor;
     154                 : 
     155                 :    nsWeakPtr               mWebBrowserChromeWeak;   // nsIWebBrowserChrome
     156                 : 
     157                 :     // the objects that listen for chrome events like context menus and tooltips. 
     158                 :     // They are separate objects to avoid circular references between |this|
     159                 :     // and the DOM. These are strong, owning refs.
     160                 :    ChromeTooltipListener*         mChromeTooltipListener;
     161                 :    ChromeContextMenuListener*     mChromeContextMenuListener;
     162                 : 
     163                 :    nsCOMPtr<nsIPrompt>     mPrompter;
     164                 :    nsCOMPtr<nsIAuthPrompt> mAuthPrompter;
     165                 : };
     166                 : 
     167                 : 
     168                 : //
     169                 : // class ChromeTooltipListener
     170                 : //
     171                 : // The class that listens to the chrome events and tells the embedding
     172                 : // chrome to show tooltips, as appropriate. Handles registering itself
     173                 : // with the DOM with AddChromeListeners() and removing itself with
     174                 : // RemoveChromeListeners().
     175                 : //
     176                 : class ChromeTooltipListener : public nsIDOMEventListener
     177                 : {
     178                 : public:
     179                 :   NS_DECL_ISUPPORTS
     180                 :   
     181                 :   ChromeTooltipListener ( nsWebBrowser* inBrowser, nsIWebBrowserChrome* inChrome ) ;
     182                 :   virtual ~ChromeTooltipListener ( ) ;
     183                 : 
     184                 :   NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent);
     185                 :   NS_IMETHOD MouseMove(nsIDOMEvent* aMouseEvent);
     186                 : 
     187                 :     // Add/remove the relevant listeners, based on what interfaces
     188                 :     // the embedding chrome implements.
     189                 :   NS_IMETHOD AddChromeListeners();
     190                 :   NS_IMETHOD RemoveChromeListeners();
     191                 : 
     192                 : private:
     193                 : 
     194                 :     // various delays for tooltips
     195                 :   enum {
     196                 :     kTooltipAutoHideTime = 5000        // 5000ms = 5 seconds
     197                 :   };
     198                 : 
     199                 :   NS_IMETHOD AddTooltipListener();
     200                 :   NS_IMETHOD RemoveTooltipListener();
     201                 : 
     202                 :   NS_IMETHOD ShowTooltip ( PRInt32 inXCoords, PRInt32 inYCoords, const nsAString & inTipText ) ;
     203                 :   NS_IMETHOD HideTooltip ( ) ;
     204                 : 
     205                 :   nsWebBrowser* mWebBrowser;
     206                 :   nsCOMPtr<nsIDOMEventTarget> mEventTarget;
     207                 :   nsCOMPtr<nsITooltipTextProvider> mTooltipTextProvider;
     208                 :   
     209                 :     // This must be a strong ref in order to make sure we can hide the tooltip
     210                 :     // if the window goes away while we're displaying one. If we don't hold
     211                 :     // a strong ref, the chrome might have been disposed of before we get a chance
     212                 :     // to tell it, and no one would ever tell us of that fact.
     213                 :   nsCOMPtr<nsIWebBrowserChrome> mWebBrowserChrome;
     214                 : 
     215                 :   bool mTooltipListenerInstalled;
     216                 : 
     217                 :   nsCOMPtr<nsITimer> mTooltipTimer;
     218                 :   static void sTooltipCallback ( nsITimer* aTimer, void* aListener ) ;
     219                 :   PRInt32 mMouseClientX, mMouseClientY;       // mouse coordinates for last mousemove event we saw
     220                 :   PRInt32 mMouseScreenX, mMouseScreenY;       // mouse coordinates for tooltip event
     221                 :   bool mShowingTooltip;
     222                 : 
     223                 :     // a timer for auto-hiding the tooltip after a certain delay
     224                 :   nsCOMPtr<nsITimer> mAutoHideTimer;
     225                 :   static void sAutoHideCallback ( nsITimer* aTimer, void* aListener ) ;
     226                 :   void CreateAutoHideTimer ( ) ;
     227                 : 
     228                 :     // The node hovered over that fired the timer. This may turn into the node that
     229                 :     // triggered the tooltip, but only if the timer ever gets around to firing.
     230                 :     // This is a strong reference, because the tooltip content can be destroyed while we're
     231                 :     // waiting for the tooltip to pup up, and we need to detect that.
     232                 :     // It's set only when the tooltip timer is created and launched. The timer must
     233                 :     // either fire or be cancelled (or possibly released?), and we release this
     234                 :     // reference in each of those cases. So we don't leak.
     235                 :   nsCOMPtr<nsIDOMNode> mPossibleTooltipNode;
     236                 : 
     237                 : }; // ChromeTooltipListener
     238                 : 
     239                 : 
     240                 : //
     241                 : // class ChromeContextMenuListener
     242                 : //
     243                 : // The class that listens to the chrome events and tells the embedding
     244                 : // chrome to show context menus, as appropriate. Handles registering itself
     245                 : // with the DOM with AddChromeListeners() and removing itself with
     246                 : // RemoveChromeListeners().
     247                 : //
     248                 : class ChromeContextMenuListener : public nsIDOMEventListener
     249                 : {
     250                 : public:
     251                 :   NS_DECL_ISUPPORTS
     252                 :   
     253                 :   ChromeContextMenuListener ( nsWebBrowser* inBrowser, nsIWebBrowserChrome* inChrome ) ;
     254                 :   virtual ~ChromeContextMenuListener ( ) ;
     255                 : 
     256                 :   // nsIDOMContextMenuListener
     257                 :   NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent);
     258                 : 
     259                 :   // Add/remove the relevant listeners, based on what interfaces
     260                 :   // the embedding chrome implements.
     261                 :   NS_IMETHOD AddChromeListeners();
     262                 :   NS_IMETHOD RemoveChromeListeners();
     263                 : 
     264                 : private:
     265                 : 
     266                 :   NS_IMETHOD AddContextMenuListener();
     267                 :   NS_IMETHOD RemoveContextMenuListener();
     268                 : 
     269                 :   bool mContextMenuListenerInstalled;
     270                 : 
     271                 :   nsWebBrowser* mWebBrowser;
     272                 :   nsCOMPtr<nsIDOMEventTarget> mEventTarget;
     273                 :   nsCOMPtr<nsIWebBrowserChrome> mWebBrowserChrome;
     274                 : 
     275                 : }; // class ChromeContextMenuListener
     276                 : 
     277                 : 
     278                 : 
     279                 : #endif /* nsDocShellTreeOwner_h__ */
     280                 : 
     281                 : 
     282                 : 
     283                 : 
     284                 : 
     285                 : 
     286                 : 
     287                 : 
     288                 : 
     289                 : 
     290                 : 
     291                 : 

Generated by: LCOV version 1.7