Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dist/include/mozilla/a11y/FocusManager.h
Line
Count
Source (jump to first uncovered line)
1
/* This Source Code Form is subject to the terms of the Mozilla Public
2
 * License, v. 2.0. If a copy of the MPL was not distributed with this
3
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5
#ifndef mozilla_a11y_FocusManager_h_
6
#define mozilla_a11y_FocusManager_h_
7
8
#include "mozilla/RefPtr.h"
9
10
class nsINode;
11
class nsIDocument;
12
class nsISupports;
13
14
namespace mozilla {
15
namespace a11y {
16
17
class AccEvent;
18
class Accessible;
19
class DocAccessible;
20
21
/**
22
 * Manage the accessible focus. Used to fire and process accessible events.
23
 */
24
class FocusManager
25
{
26
public:
27
  virtual ~FocusManager();
28
29
  /**
30
   * Return a focused accessible.
31
   */
32
  Accessible* FocusedAccessible() const;
33
34
  /**
35
   * Return true if given accessible is focused.
36
   */
37
  bool IsFocused(const Accessible* aAccessible) const;
38
39
  /**
40
   * Return true if the given accessible is an active item, i.e. an item that
41
   * is current within the active widget.
42
   */
43
  inline bool IsActiveItem(const Accessible* aAccessible)
44
0
    { return aAccessible == mActiveItem; }
45
46
  /**
47
   * Return DOM node having DOM focus.
48
   */
49
  nsINode* FocusedDOMNode() const;
50
51
  /**
52
   * Return true if given DOM node has DOM focus.
53
   */
54
  inline bool HasDOMFocus(const nsINode* aNode) const
55
0
    { return aNode == FocusedDOMNode(); }
56
57
  /**
58
   * Return true if focused accessible is within the given container.
59
   */
60
  bool IsFocusWithin(const Accessible* aContainer) const;
61
62
  /**
63
   * Return whether the given accessible is focused or contains the focus or
64
   * contained by focused accessible.
65
   */
66
  enum FocusDisposition {
67
    eNone,
68
    eFocused,
69
    eContainsFocus,
70
    eContainedByFocus
71
  };
72
  FocusDisposition IsInOrContainsFocus(const Accessible* aAccessible) const;
73
74
  //////////////////////////////////////////////////////////////////////////////
75
  // Focus notifications and processing (don't use until you know what you do).
76
77
  /**
78
   * Called when DOM focus event is fired.
79
   */
80
  void NotifyOfDOMFocus(nsISupports* aTarget);
81
82
  /**
83
   * Called when DOM blur event is fired.
84
   */
85
  void NotifyOfDOMBlur(nsISupports* aTarget);
86
87
  /**
88
   * Called when active item is changed. Note: must be called when accessible
89
   * tree is up to date.
90
   */
91
  void ActiveItemChanged(Accessible* aItem, bool aCheckIfActive = true);
92
93
  /**
94
   * Dispatch delayed focus event for the current focus accessible.
95
   */
96
  void ForceFocusEvent();
97
98
  /**
99
   * Dispatch delayed focus event for the given target.
100
   */
101
  void DispatchFocusEvent(DocAccessible* aDocument, Accessible* aTarget);
102
103
  /**
104
   * Process DOM focus notification.
105
   */
106
  void ProcessDOMFocus(nsINode* aTarget);
107
108
  /**
109
   * Process the delayed accessible event.
110
   * do.
111
   */
112
  void ProcessFocusEvent(AccEvent* aEvent);
113
114
protected:
115
  FocusManager();
116
117
private:
118
  FocusManager(const FocusManager&);
119
  FocusManager& operator =(const FocusManager&);
120
121
  /**
122
   * Return DOM document having DOM focus.
123
   */
124
  nsIDocument* FocusedDOMDocument() const;
125
126
private:
127
  RefPtr<Accessible> mActiveItem;
128
  RefPtr<Accessible> mActiveARIAMenubar;
129
};
130
131
} // namespace a11y
132
} // namespace mozilla
133
134
#endif