Bug 460926 A11y hierachy is broken on Ubuntu 8.10 (GNOME 2.24), r=Evan.Yan sr=roc
[wine-gecko.git] / accessible / src / base / nsCaretAccessible.h
blob40726a1545462df25d270c5e2cc6b6080af2b9c6
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
24 * Alternatively, the contents of this file may be used under the terms of
25 * either of the GNU General Public License Version 2 or later (the "GPL"),
26 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
38 #ifndef __nsCaretAccessible_h__
39 #define __nsCaretAccessible_h__
41 #include "nsIWeakReference.h"
42 #include "nsIAccessibleText.h"
43 #include "nsIDOMNode.h"
44 #include "nsISelectionListener.h"
45 #include "nsISelectionController.h"
46 #include "nsRect.h"
48 class nsRootAccessible;
49 class nsIView;
50 class nsIPresShell;
51 class nsIWidget;
54 * This special accessibility class is for the caret, which is really the currently focused selection.
55 * There is only 1 visible caret per top level window (nsRootAccessible),
56 * However, there may be several visible selections.
58 * The important selections are the one owned by each document, and the one in the currently focused control.
60 * The caret accessible is no longer an accessible object in its own right.
61 * On Windows it is used to move an invisible system caret that shadows the Mozilla caret. Windows will
62 * also automatically map this to the MSAA caret accessible object (via OBJID_CARET).
63 * (as opposed to the root accessible tree for a window which is retrieved with OBJID_CLIENT)
64 * For ATK and Iaccessible2, the caret accessible is used to fire
65 * caret move and selection change events.
67 * The caret accessible is owned by the nsRootAccessible for the top level window that it's in.
68 * The nsRootAccessible needs to tell the nsCaretAccessible about focus changes via
69 * setControlSelectionListener().
70 * Each nsDocAccessible needs to tell the nsCaretAccessible owned by the root to
71 * listen for selection events via addDocSelectionListener() and then needs to remove the
72 * selection listener when the doc goes away via removeDocSelectionListener().
75 class nsCaretAccessible : public nsISelectionListener
77 public:
78 NS_DECL_ISUPPORTS
80 nsCaretAccessible(nsRootAccessible *aRootAccessible);
81 virtual ~nsCaretAccessible();
82 void Shutdown();
84 /* ----- nsISelectionListener ---- */
85 NS_DECL_NSISELECTIONLISTENER
87 /**
88 * Listen to selection events on the focused control.
89 * Only one control's selection events are listened to at a time, per top-level window.
90 * This will remove the previous control's selection listener.
91 * It will fail if aFocusedNode is a document node -- document selection must be listened
92 * to via AddDocSelectionListener().
93 * @param aFocusedNode The node for the focused control
95 nsresult SetControlSelectionListener(nsIDOMNode *aCurrentNode);
97 /**
98 * Stop listening to selection events for any control.
99 * This does not have to be called explicitly in Shutdown() procedures,
100 * because the nsCaretAccessible implementation guarantees that.
102 nsresult ClearControlSelectionListener();
105 * Start listening to selection events for a given document
106 * More than one document's selection events can be listened to
107 * at the same time, by a given nsCaretAccessible
108 * @param aShell PresShell for document to listen to selection events from.
110 nsresult AddDocSelectionListener(nsIPresShell *aShell);
113 * Stop listening to selection events for a given document
114 * If the document goes away, this method needs to be called for
115 * that document by the owner of the caret. We use presShell because
116 * instead of document because it is more direct than getting it from
117 * the document, and in any case it is unavailable from the doc after a pagehide.
118 * @param aShell PresShell for document to no longer listen to selection events from.
120 nsresult RemoveDocSelectionListener(nsIPresShell *aShell);
122 nsRect GetCaretRect(nsIWidget **aOutWidget);
124 protected:
125 nsresult NormalSelectionChanged(nsIDOMDocument *aDoc, nsISelection *aSel);
126 nsresult SpellcheckSelectionChanged(nsIDOMDocument *aDoc, nsISelection *aSel);
128 already_AddRefed<nsISelectionController>
129 GetSelectionControllerForNode(nsIDOMNode *aNode);
131 private:
132 // The currently focused control -- never a document.
133 // We listen to selection for one control at a time (the focused one)
134 // Document selection is handled separately via additional listeners on all active documents
135 // The current control is set via SetControlSelectionListener()
136 nsCOMPtr<nsIDOMNode> mCurrentControl; // Selection controller for the currently focused control
138 // Info for the the last selection event.
139 // If it was on a control, then its control's selection. Otherwise, it's for
140 // a document where the selection changed.
141 nsCOMPtr<nsIWeakReference> mLastUsedSelection; // Weak ref to nsISelection
142 nsCOMPtr<nsIAccessibleText> mLastTextAccessible;
143 PRInt32 mLastCaretOffset;
145 nsRootAccessible *mRootAccessible;
148 #endif