Bug 1738926 Part 1: Check if sublayers need to be rebuilt. r=mstange
[gecko.git] / accessible / base / SelectionManager.h
blob34a841d525fb59a3001d0258cfee8df2c8cebbf2
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/. */
6 #ifndef mozilla_a11y_SelectionManager_h__
7 #define mozilla_a11y_SelectionManager_h__
9 #include "nsISelectionListener.h"
10 #include "mozilla/WeakPtr.h"
12 namespace mozilla {
14 class PresShell;
16 namespace dom {
17 class Element;
18 class Selection;
19 } // namespace dom
21 namespace a11y {
23 class AccEvent;
24 class HyperTextAccessible;
26 /**
27 * This special accessibility class is for the caret and selection management.
28 * There is only 1 visible caret per top level window. However, there may be
29 * several visible selections.
31 * The important selections are the one owned by each document, and the one in
32 * the currently focused control.
34 * On Windows this class is used to move an invisible system caret that
35 * shadows the Mozilla caret. Windows will also automatically map this to
36 * the MSAA caret accessible object (via OBJID_CARET) (as opposed to the root
37 * accessible tree for a window which is retrieved with OBJID_CLIENT).
39 * For ATK and IAccessible2, this class is used to fire caret move and
40 * selection change events.
43 struct SelData;
45 class SelectionManager : public nsISelectionListener {
46 public:
47 // nsISupports
48 // implemented by derived nsAccessibilityService
50 // nsISelectionListener
51 NS_DECL_NSISELECTIONLISTENER
53 // SelectionManager
54 void Shutdown() { ClearControlSelectionListener(); }
56 /**
57 * Listen to selection events on the focused control.
59 * Note: only one control's selection events are listened to at a time. This
60 * will remove the previous control's selection listener.
62 void SetControlSelectionListener(dom::Element* aFocusedElm);
64 /**
65 * Stop listening to selection events on the control.
67 void ClearControlSelectionListener();
69 /**
70 * Listen to selection events on the document.
72 void AddDocSelectionListener(PresShell* aPresShell);
74 /**
75 * Stop listening to selection events for a given document
77 void RemoveDocSelectionListener(PresShell* aPresShell);
79 /**
80 * Process delayed event, results in caret move and text selection change
81 * events.
83 void ProcessTextSelChangeEvent(AccEvent* aEvent);
85 /**
86 * Gets the current caret offset/hypertext accessible pair. If there is no
87 * current pair, then returns -1 for the offset and a nullptr for the
88 * accessible.
90 inline HyperTextAccessible* AccessibleWithCaret(int32_t* aCaret) {
91 if (aCaret) *aCaret = mCaretOffset;
93 return mAccWithCaret;
96 /**
97 * Update caret offset when it doesn't go through a caret move event.
99 inline void UpdateCaretOffset(HyperTextAccessible* aItem, int32_t aOffset) {
100 mAccWithCaret = aItem;
101 mCaretOffset = aOffset;
104 inline void ResetCaretOffset() {
105 mCaretOffset = -1;
106 mAccWithCaret = nullptr;
109 ~SelectionManager();
111 protected:
112 SelectionManager();
115 * Process DOM selection change. Fire selection and caret move events.
117 void ProcessSelectionChanged(SelData* aSelData);
119 private:
120 // Currently focused control.
121 int32_t mCaretOffset;
122 HyperTextAccessible* mAccWithCaret;
123 WeakPtr<dom::Selection> mCurrCtrlNormalSel;
124 WeakPtr<dom::Selection> mCurrCtrlSpellSel;
127 } // namespace a11y
128 } // namespace mozilla
130 #endif