Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dist/include/mozilla/a11y/SelectionManager.h
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* This Source Code Form is subject to the terms of the Mozilla Public
3
 * License, v. 2.0. If a copy of the MPL was not distributed with this
4
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6
#ifndef mozilla_a11y_SelectionManager_h__
7
#define mozilla_a11y_SelectionManager_h__
8
9
#include "nsIFrame.h"
10
#include "nsISelectionListener.h"
11
#include "mozilla/WeakPtr.h"
12
13
class nsIPresShell;
14
15
namespace mozilla {
16
17
namespace dom {
18
class Element;
19
class Selection;
20
}
21
22
namespace a11y {
23
24
class AccEvent;
25
class HyperTextAccessible;
26
27
/**
28
 * This special accessibility class is for the caret and selection management.
29
 * There is only 1 visible caret per top level window. However, there may be
30
 * several visible selections.
31
 *
32
 * The important selections are the one owned by each document, and the one in
33
 * the currently focused control.
34
 *
35
 * On Windows this class is used to move an invisible system caret that
36
 * shadows the Mozilla caret. Windows will also automatically map this to
37
 * the MSAA caret accessible object (via OBJID_CARET) (as opposed to the root
38
 * accessible tree for a window which is retrieved with OBJID_CLIENT).
39
 *
40
 * For ATK and IAccessible2, this class is used to fire caret move and
41
 * selection change events.
42
 */
43
44
struct SelData;
45
46
class SelectionManager : public nsISelectionListener
47
{
48
public:
49
  // nsISupports
50
  // implemented by derived nsAccessibilityService
51
52
  // nsISelectionListener
53
  NS_DECL_NSISELECTIONLISTENER
54
55
  // SelectionManager
56
0
  void Shutdown() { ClearControlSelectionListener(); }
57
58
  /**
59
   * Listen to selection events on the focused control.
60
   *
61
   * Note: only one control's selection events are listened to at a time. This
62
   * will remove the previous control's selection listener.
63
   */
64
  void SetControlSelectionListener(dom::Element* aFocusedElm);
65
66
  /**
67
   * Stop listening to selection events on the control.
68
   */
69
  void ClearControlSelectionListener();
70
71
  /**
72
   * Listen to selection events on the document.
73
   */
74
  void AddDocSelectionListener(nsIPresShell* aPresShell);
75
76
  /**
77
   * Stop listening to selection events for a given document
78
   */
79
  void RemoveDocSelectionListener(nsIPresShell* aShell);
80
81
  /**
82
   * Process delayed event, results in caret move and text selection change
83
   * events.
84
   */
85
  void ProcessTextSelChangeEvent(AccEvent* aEvent);
86
87
  /**
88
   * Gets the current caret offset/hypertext accessible pair. If there is no
89
   * current pair, then returns -1 for the offset and a nullptr for the
90
   * accessible.
91
   */
92
  inline HyperTextAccessible* AccessibleWithCaret(int32_t* aCaret)
93
0
  {
94
0
    if (aCaret)
95
0
      *aCaret = mCaretOffset;
96
0
97
0
    return mAccWithCaret;
98
0
  }
99
100
  /**
101
   * Update caret offset when it doesn't go through a caret move event.
102
   */
103
  inline void UpdateCaretOffset(HyperTextAccessible* aItem, int32_t aOffset)
104
0
  {
105
0
    mAccWithCaret = aItem;
106
0
    mCaretOffset = aOffset;
107
0
  }
108
109
  inline void ResetCaretOffset()
110
0
  {
111
0
    mCaretOffset = -1;
112
0
    mAccWithCaret = nullptr;
113
0
  }
114
115
protected:
116
117
  SelectionManager();
118
119
  /**
120
   * Process DOM selection change. Fire selection and caret move events.
121
   */
122
  void ProcessSelectionChanged(SelData* aSelData);
123
124
private:
125
  // Currently focused control.
126
  int32_t mCaretOffset;
127
  HyperTextAccessible* mAccWithCaret;
128
  WeakPtr<dom::Selection> mCurrCtrlNormalSel;
129
  WeakPtr<dom::Selection> mCurrCtrlSpellSel;
130
};
131
132
} // namespace a11y
133
} // namespace mozilla
134
135
#endif