embedding/browser/webBrowser/nsDocShellTreeOwner.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/embedding/browser/webBrowser/nsDocShellTreeOwner.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,262 @@
     1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
     1.5 + *
     1.6 + * This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +#ifndef nsDocShellTreeOwner_h__
    1.11 +#define nsDocShellTreeOwner_h__
    1.12 +
    1.13 +// Helper Classes
    1.14 +#include "nsCOMPtr.h"
    1.15 +#include "nsString.h"
    1.16 +
    1.17 +// Interfaces Needed
    1.18 +#include "nsIBaseWindow.h"
    1.19 +#include "nsIDocShellTreeOwner.h"
    1.20 +#include "nsIInterfaceRequestor.h"
    1.21 +#include "nsIInterfaceRequestorUtils.h"
    1.22 +#include "nsIWebBrowserChrome.h"
    1.23 +#include "nsIDOMEventListener.h"
    1.24 +#include "nsIEmbeddingSiteWindow.h"
    1.25 +#include "nsIWebProgressListener.h"
    1.26 +#include "nsWeakReference.h"
    1.27 +#include "nsITimer.h"
    1.28 +#include "nsIPrompt.h"
    1.29 +#include "nsIAuthPrompt.h"
    1.30 +#include "nsITooltipListener.h"
    1.31 +#include "nsITooltipTextProvider.h"
    1.32 +#include "nsCTooltipTextProvider.h"
    1.33 +#include "nsIDroppedLinkHandler.h"
    1.34 +#include "nsCommandHandler.h"
    1.35 +
    1.36 +namespace mozilla {
    1.37 +namespace dom {
    1.38 +class EventTarget;
    1.39 +}
    1.40 +}
    1.41 +
    1.42 +class nsWebBrowser;
    1.43 +class ChromeTooltipListener;
    1.44 +class ChromeContextMenuListener;
    1.45 +
    1.46 +// {6D10C180-6888-11d4-952B-0020183BF181}
    1.47 +#define NS_ICDOCSHELLTREEOWNER_IID \
    1.48 +{ 0x6d10c180, 0x6888, 0x11d4, { 0x95, 0x2b, 0x0, 0x20, 0x18, 0x3b, 0xf1, 0x81 } }
    1.49 +
    1.50 +/*
    1.51 + * This is a fake 'hidden' interface that nsDocShellTreeOwner implements.
    1.52 + * Classes such as nsCommandHandler can QI for this interface to be
    1.53 + * sure that they're dealing with a valid nsDocShellTreeOwner and not some
    1.54 + * other object that implements nsIDocShellTreeOwner.
    1.55 + */
    1.56 +class nsICDocShellTreeOwner : public nsISupports
    1.57 +{
    1.58 +public:
    1.59 +    NS_DECLARE_STATIC_IID_ACCESSOR(NS_ICDOCSHELLTREEOWNER_IID)
    1.60 +};
    1.61 +
    1.62 +NS_DEFINE_STATIC_IID_ACCESSOR(nsICDocShellTreeOwner,
    1.63 +                              NS_ICDOCSHELLTREEOWNER_IID)
    1.64 +
    1.65 +class nsDocShellTreeOwner : public nsIDocShellTreeOwner,
    1.66 +                            public nsIBaseWindow,
    1.67 +                            public nsIInterfaceRequestor,
    1.68 +                            public nsIWebProgressListener,
    1.69 +                            public nsIDOMEventListener,
    1.70 +                            public nsICDocShellTreeOwner,
    1.71 +                            public nsSupportsWeakReference
    1.72 +{
    1.73 +friend class nsWebBrowser;
    1.74 +friend class nsCommandHandler;
    1.75 +
    1.76 +public:
    1.77 +    NS_DECL_ISUPPORTS
    1.78 +
    1.79 +    NS_DECL_NSIBASEWINDOW
    1.80 +    NS_DECL_NSIDOCSHELLTREEOWNER
    1.81 +    NS_DECL_NSIDOMEVENTLISTENER
    1.82 +    NS_DECL_NSIINTERFACEREQUESTOR
    1.83 +    NS_DECL_NSIWEBPROGRESSLISTENER
    1.84 +
    1.85 +protected:
    1.86 +    nsDocShellTreeOwner();
    1.87 +    virtual ~nsDocShellTreeOwner();
    1.88 +
    1.89 +    void WebBrowser(nsWebBrowser* aWebBrowser);
    1.90 +    
    1.91 +    nsWebBrowser* WebBrowser();
    1.92 +    NS_IMETHOD SetTreeOwner(nsIDocShellTreeOwner* aTreeOwner);
    1.93 +    NS_IMETHOD SetWebBrowserChrome(nsIWebBrowserChrome* aWebBrowserChrome);
    1.94 +
    1.95 +    NS_IMETHOD AddChromeListeners();
    1.96 +    NS_IMETHOD RemoveChromeListeners();
    1.97 +
    1.98 +    nsresult   FindItemWithNameAcrossWindows(const char16_t* aName,
    1.99 +                 nsIDocShellTreeItem* aRequestor,
   1.100 +                 nsIDocShellTreeItem* aOriginalRequestor,
   1.101 +                 nsIDocShellTreeItem **aFoundItem);
   1.102 +
   1.103 +    void       EnsurePrompter();
   1.104 +    void       EnsureAuthPrompter();
   1.105 +
   1.106 +    void AddToWatcher();
   1.107 +    void RemoveFromWatcher();
   1.108 +
   1.109 +    // These helper functions return the correct instances of the requested
   1.110 +    // interfaces.  If the object passed to SetWebBrowserChrome() implements
   1.111 +    // nsISupportsWeakReference, then these functions call QueryReferent on
   1.112 +    // that object.  Otherwise, they return an addrefed pointer.  If the
   1.113 +    // WebBrowserChrome object doesn't exist, they return nullptr.
   1.114 +    already_AddRefed<nsIWebBrowserChrome>     GetWebBrowserChrome();
   1.115 +    already_AddRefed<nsIEmbeddingSiteWindow>  GetOwnerWin();
   1.116 +    already_AddRefed<nsIInterfaceRequestor>   GetOwnerRequestor();
   1.117 +
   1.118 +protected:
   1.119 +
   1.120 +   // Weak References
   1.121 +   nsWebBrowser*           mWebBrowser;
   1.122 +   nsIDocShellTreeOwner*   mTreeOwner;
   1.123 +   nsIDocShellTreeItem*    mPrimaryContentShell; 
   1.124 +
   1.125 +   nsIWebBrowserChrome*    mWebBrowserChrome;
   1.126 +   nsIEmbeddingSiteWindow* mOwnerWin;
   1.127 +   nsIInterfaceRequestor*  mOwnerRequestor;
   1.128 +
   1.129 +   nsWeakPtr               mWebBrowserChromeWeak;   // nsIWebBrowserChrome
   1.130 +
   1.131 +    // the objects that listen for chrome events like context menus and tooltips. 
   1.132 +    // They are separate objects to avoid circular references between |this|
   1.133 +    // and the DOM. These are strong, owning refs.
   1.134 +   ChromeTooltipListener*         mChromeTooltipListener;
   1.135 +   ChromeContextMenuListener*     mChromeContextMenuListener;
   1.136 +
   1.137 +   nsCOMPtr<nsIPrompt>     mPrompter;
   1.138 +   nsCOMPtr<nsIAuthPrompt> mAuthPrompter;
   1.139 +};
   1.140 +
   1.141 +
   1.142 +//
   1.143 +// class ChromeTooltipListener
   1.144 +//
   1.145 +// The class that listens to the chrome events and tells the embedding
   1.146 +// chrome to show tooltips, as appropriate. Handles registering itself
   1.147 +// with the DOM with AddChromeListeners() and removing itself with
   1.148 +// RemoveChromeListeners().
   1.149 +//
   1.150 +class ChromeTooltipListener : public nsIDOMEventListener
   1.151 +{
   1.152 +public:
   1.153 +  NS_DECL_ISUPPORTS
   1.154 +  
   1.155 +  ChromeTooltipListener ( nsWebBrowser* inBrowser, nsIWebBrowserChrome* inChrome ) ;
   1.156 +  virtual ~ChromeTooltipListener ( ) ;
   1.157 +
   1.158 +  NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent);
   1.159 +  NS_IMETHOD MouseMove(nsIDOMEvent* aMouseEvent);
   1.160 +
   1.161 +    // Add/remove the relevant listeners, based on what interfaces
   1.162 +    // the embedding chrome implements.
   1.163 +  NS_IMETHOD AddChromeListeners();
   1.164 +  NS_IMETHOD RemoveChromeListeners();
   1.165 +
   1.166 +private:
   1.167 +
   1.168 +    // various delays for tooltips
   1.169 +  enum {
   1.170 +    kTooltipAutoHideTime = 5000        // 5000ms = 5 seconds
   1.171 +  };
   1.172 +
   1.173 +  NS_IMETHOD AddTooltipListener();
   1.174 +  NS_IMETHOD RemoveTooltipListener();
   1.175 +
   1.176 +  NS_IMETHOD ShowTooltip ( int32_t inXCoords, int32_t inYCoords, const nsAString & inTipText ) ;
   1.177 +  NS_IMETHOD HideTooltip ( ) ;
   1.178 +
   1.179 +  nsWebBrowser* mWebBrowser;
   1.180 +  nsCOMPtr<mozilla::dom::EventTarget> mEventTarget;
   1.181 +  nsCOMPtr<nsITooltipTextProvider> mTooltipTextProvider;
   1.182 +
   1.183 +    // This must be a strong ref in order to make sure we can hide the tooltip
   1.184 +    // if the window goes away while we're displaying one. If we don't hold
   1.185 +    // a strong ref, the chrome might have been disposed of before we get a chance
   1.186 +    // to tell it, and no one would ever tell us of that fact.
   1.187 +  nsCOMPtr<nsIWebBrowserChrome> mWebBrowserChrome;
   1.188 +
   1.189 +  bool mTooltipListenerInstalled;
   1.190 +
   1.191 +  nsCOMPtr<nsITimer> mTooltipTimer;
   1.192 +  static void sTooltipCallback ( nsITimer* aTimer, void* aListener ) ;
   1.193 +  int32_t mMouseClientX, mMouseClientY;       // mouse coordinates for last mousemove event we saw
   1.194 +  int32_t mMouseScreenX, mMouseScreenY;       // mouse coordinates for tooltip event
   1.195 +  bool mShowingTooltip;
   1.196 +
   1.197 +    // a timer for auto-hiding the tooltip after a certain delay
   1.198 +  nsCOMPtr<nsITimer> mAutoHideTimer;
   1.199 +  static void sAutoHideCallback ( nsITimer* aTimer, void* aListener ) ;
   1.200 +  void CreateAutoHideTimer ( ) ;
   1.201 +
   1.202 +    // The node hovered over that fired the timer. This may turn into the node that
   1.203 +    // triggered the tooltip, but only if the timer ever gets around to firing.
   1.204 +    // This is a strong reference, because the tooltip content can be destroyed while we're
   1.205 +    // waiting for the tooltip to pup up, and we need to detect that.
   1.206 +    // It's set only when the tooltip timer is created and launched. The timer must
   1.207 +    // either fire or be cancelled (or possibly released?), and we release this
   1.208 +    // reference in each of those cases. So we don't leak.
   1.209 +  nsCOMPtr<nsIDOMNode> mPossibleTooltipNode;
   1.210 +
   1.211 +}; // ChromeTooltipListener
   1.212 +
   1.213 +
   1.214 +//
   1.215 +// class ChromeContextMenuListener
   1.216 +//
   1.217 +// The class that listens to the chrome events and tells the embedding
   1.218 +// chrome to show context menus, as appropriate. Handles registering itself
   1.219 +// with the DOM with AddChromeListeners() and removing itself with
   1.220 +// RemoveChromeListeners().
   1.221 +//
   1.222 +class ChromeContextMenuListener : public nsIDOMEventListener
   1.223 +{
   1.224 +public:
   1.225 +  NS_DECL_ISUPPORTS
   1.226 +  
   1.227 +  ChromeContextMenuListener ( nsWebBrowser* inBrowser, nsIWebBrowserChrome* inChrome ) ;
   1.228 +  virtual ~ChromeContextMenuListener ( ) ;
   1.229 +
   1.230 +  // nsIDOMContextMenuListener
   1.231 +  NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent);
   1.232 +
   1.233 +  // Add/remove the relevant listeners, based on what interfaces
   1.234 +  // the embedding chrome implements.
   1.235 +  NS_IMETHOD AddChromeListeners();
   1.236 +  NS_IMETHOD RemoveChromeListeners();
   1.237 +
   1.238 +private:
   1.239 +
   1.240 +  NS_IMETHOD AddContextMenuListener();
   1.241 +  NS_IMETHOD RemoveContextMenuListener();
   1.242 +
   1.243 +  bool mContextMenuListenerInstalled;
   1.244 +
   1.245 +  nsWebBrowser* mWebBrowser;
   1.246 +  nsCOMPtr<mozilla::dom::EventTarget> mEventTarget;
   1.247 +  nsCOMPtr<nsIWebBrowserChrome> mWebBrowserChrome;
   1.248 +
   1.249 +}; // class ChromeContextMenuListener
   1.250 +
   1.251 +
   1.252 +
   1.253 +#endif /* nsDocShellTreeOwner_h__ */
   1.254 +
   1.255 +
   1.256 +
   1.257 +
   1.258 +
   1.259 +
   1.260 +
   1.261 +
   1.262 +
   1.263 +
   1.264 +
   1.265 +

mercurial