Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/base/nsWindowRoot.h
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
3
/* This Source Code Form is subject to the terms of the Mozilla Public
4
 * License, v. 2.0. If a copy of the MPL was not distributed with this
5
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
#ifndef nsWindowRoot_h__
8
#define nsWindowRoot_h__
9
10
class nsIGlobalObject;
11
12
#include "mozilla/Attributes.h"
13
#include "mozilla/EventListenerManager.h"
14
#include "nsIWeakReferenceUtils.h"
15
#include "nsPIWindowRoot.h"
16
#include "nsCycleCollectionParticipant.h"
17
#include "nsTHashtable.h"
18
#include "nsHashKeys.h"
19
20
class nsWindowRoot final : public nsPIWindowRoot
21
{
22
public:
23
  explicit nsWindowRoot(nsPIDOMWindowOuter* aWindow);
24
25
  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
26
27
  virtual mozilla::EventListenerManager*
28
    GetExistingListenerManager() const override;
29
  virtual mozilla::EventListenerManager*
30
    GetOrCreateListenerManager() override;
31
32
  bool ComputeDefaultWantsUntrusted(mozilla::ErrorResult& aRv) final;
33
34
  bool DispatchEvent(mozilla::dom::Event& aEvent,
35
                     mozilla::dom::CallerType aCallerType,
36
                     mozilla::ErrorResult& aRv) override;
37
38
  void GetEventTargetParent(mozilla::EventChainPreVisitor& aVisitor) override;
39
40
  nsresult PostHandleEvent(mozilla::EventChainPostVisitor& aVisitor) override;
41
42
  // nsPIWindowRoot
43
44
  virtual nsPIDOMWindowOuter* GetWindow() override;
45
46
  virtual nsresult GetControllers(bool aForVisibleWindow,
47
                                  nsIControllers** aResult) override;
48
  virtual nsresult GetControllerForCommand(const char * aCommand,
49
                                           bool aForVisibleWindow,
50
                                           nsIController** _retval) override;
51
52
  virtual void GetEnabledDisabledCommands(nsTArray<nsCString>& aEnabledCommands,
53
                                          nsTArray<nsCString>& aDisabledCommands) override;
54
55
  virtual already_AddRefed<nsINode> GetPopupNode() override;
56
  virtual void SetPopupNode(nsINode* aNode) override;
57
58
  virtual void SetParentTarget(mozilla::dom::EventTarget* aTarget) override
59
0
  {
60
0
    mParent = aTarget;
61
0
  }
62
0
  virtual mozilla::dom::EventTarget* GetParentTarget() override { return mParent; }
63
  virtual nsPIDOMWindowOuter* GetOwnerGlobalForBindings() override;
64
  virtual nsIGlobalObject* GetOwnerGlobal() const override;
65
66
  nsIGlobalObject* GetParentObject();
67
68
  virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
69
70
  NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(nsWindowRoot)
71
72
  virtual void AddBrowser(mozilla::dom::TabParent* aBrowser) override;
73
  virtual void RemoveBrowser(mozilla::dom::TabParent* aBrowser) override;
74
  virtual void EnumerateBrowsers(BrowserEnumerator aEnumFunc, void *aArg) override;
75
76
  virtual bool ShowAccelerators() override
77
0
  {
78
0
    return mShowAccelerators;
79
0
  }
80
81
  virtual bool ShowFocusRings() override
82
0
  {
83
0
    return mShowFocusRings;
84
0
  }
85
86
  virtual void SetShowAccelerators(bool aEnable) override
87
0
  {
88
0
    mShowAccelerators = aEnable;
89
0
  }
90
91
  virtual void SetShowFocusRings(bool aEnable) override
92
0
  {
93
0
    mShowFocusRings = aEnable;
94
0
  }
95
96
protected:
97
  virtual ~nsWindowRoot();
98
99
  void GetEnabledDisabledCommandsForControllers(nsIControllers* aControllers,
100
                                                nsTHashtable<nsCharPtrHashKey>& aCommandsHandled,
101
                                                nsTArray<nsCString>& aEnabledCommands,
102
                                                nsTArray<nsCString>& aDisabledCommands);
103
104
  // Members
105
  nsCOMPtr<nsPIDOMWindowOuter> mWindow;
106
  // We own the manager, which owns event listeners attached to us.
107
  RefPtr<mozilla::EventListenerManager> mListenerManager; // [Strong]
108
  nsWeakPtr mPopupNode;
109
110
  // True if focus rings and accelerators are enabled for this
111
  // window hierarchy.
112
  bool mShowAccelerators;
113
  bool mShowFocusRings;
114
115
  nsCOMPtr<mozilla::dom::EventTarget> mParent;
116
117
  // The TabParents that are currently registered with this top-level window.
118
  typedef nsTHashtable<nsRefPtrHashKey<nsIWeakReference>> WeakBrowserTable;
119
  WeakBrowserTable mWeakBrowsers;
120
};
121
122
extern already_AddRefed<mozilla::dom::EventTarget>
123
NS_NewWindowRoot(nsPIDOMWindowOuter* aWindow);
124
125
#endif