1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* ***** BEGIN LICENSE BLOCK *****
3 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 : *
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/
9 : *
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.
14 : *
15 : * The Original Code is mozilla.org code.
16 : *
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.
21 : *
22 : * Contributor(s):
23 : * Author: John Gaunt (jgaunt@netscape.com)
24 : *
25 : * Alternatively, the contents of this file may be used under the terms of
26 : * either of the GNU General Public License Version 2 or later (the "GPL"),
27 : * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 : * in which case the provisions of the GPL or the LGPL are applicable instead
29 : * of those above. If you wish to allow use of your version of this file only
30 : * under the terms of either the GPL or the LGPL, and not to allow others to
31 : * use your version of this file under the terms of the MPL, indicate your
32 : * decision by deleting the provisions above and replace them with the notice
33 : * and other provisions required by the GPL or the LGPL. If you do not delete
34 : * the provisions above, a recipient may use your version of this file under
35 : * the terms of any one of the MPL, the GPL or the LGPL.
36 : *
37 : * ***** END LICENSE BLOCK ***** */
38 :
39 : #include "nsXULTabAccessible.h"
40 :
41 : #include "nsAccUtils.h"
42 : #include "Relation.h"
43 : #include "Role.h"
44 : #include "States.h"
45 :
46 : // NOTE: alphabetically ordered
47 : #include "nsIAccessibleRelation.h"
48 : #include "nsIDocument.h"
49 : #include "nsIFrame.h"
50 : #include "nsIDOMDocument.h"
51 : #include "nsIDOMXULSelectCntrlEl.h"
52 : #include "nsIDOMXULSelectCntrlItemEl.h"
53 : #include "nsIDOMXULRelatedElement.h"
54 :
55 : using namespace mozilla::a11y;
56 :
57 : ////////////////////////////////////////////////////////////////////////////////
58 : // nsXULTabAccessible
59 : ////////////////////////////////////////////////////////////////////////////////
60 :
61 0 : nsXULTabAccessible::
62 : nsXULTabAccessible(nsIContent* aContent, nsDocAccessible* aDoc) :
63 0 : nsAccessibleWrap(aContent, aDoc)
64 : {
65 0 : }
66 :
67 : ////////////////////////////////////////////////////////////////////////////////
68 : // nsXULTabAccessible: nsIAccessible
69 :
70 : PRUint8
71 0 : nsXULTabAccessible::ActionCount()
72 : {
73 0 : return 1;
74 : }
75 :
76 : /** Return the name of our only action */
77 0 : NS_IMETHODIMP nsXULTabAccessible::GetActionName(PRUint8 aIndex, nsAString& aName)
78 : {
79 0 : if (aIndex == eAction_Switch) {
80 0 : aName.AssignLiteral("switch");
81 0 : return NS_OK;
82 : }
83 0 : return NS_ERROR_INVALID_ARG;
84 : }
85 :
86 : /** Tell the tab to do its action */
87 0 : NS_IMETHODIMP nsXULTabAccessible::DoAction(PRUint8 index)
88 : {
89 0 : if (index == eAction_Switch) {
90 0 : nsCOMPtr<nsIDOMXULElement> tab(do_QueryInterface(mContent));
91 0 : if ( tab )
92 : {
93 0 : tab->Click();
94 0 : return NS_OK;
95 : }
96 0 : return NS_ERROR_FAILURE;
97 : }
98 0 : return NS_ERROR_INVALID_ARG;
99 : }
100 :
101 : ////////////////////////////////////////////////////////////////////////////////
102 : // nsXULTabAccessible: nsAccessible
103 :
104 : role
105 0 : nsXULTabAccessible::NativeRole()
106 : {
107 0 : return roles::PAGETAB;
108 : }
109 :
110 : PRUint64
111 0 : nsXULTabAccessible::NativeState()
112 : {
113 : // Possible states: focused, focusable, unavailable(disabled), offscreen.
114 :
115 : // get focus and disable status from base class
116 0 : PRUint64 state = nsAccessibleWrap::NativeState();
117 :
118 : // In the past, tabs have been focusable in classic theme
119 : // They may be again in the future
120 : // Check style for -moz-user-focus: normal to see if it's focusable
121 0 : state &= ~states::FOCUSABLE;
122 :
123 0 : nsIFrame *frame = mContent->GetPrimaryFrame();
124 0 : if (frame) {
125 0 : const nsStyleUserInterface* ui = frame->GetStyleUserInterface();
126 0 : if (ui->mUserFocus == NS_STYLE_USER_FOCUS_NORMAL)
127 0 : state |= states::FOCUSABLE;
128 : }
129 :
130 : // Check whether the tab is selected
131 0 : state |= states::SELECTABLE;
132 0 : state &= ~states::SELECTED;
133 0 : nsCOMPtr<nsIDOMXULSelectControlItemElement> tab(do_QueryInterface(mContent));
134 0 : if (tab) {
135 0 : bool selected = false;
136 0 : if (NS_SUCCEEDED(tab->GetSelected(&selected)) && selected)
137 0 : state |= states::SELECTED;
138 : }
139 0 : return state;
140 : }
141 :
142 : // nsIAccessible
143 : Relation
144 0 : nsXULTabAccessible::RelationByType(PRUint32 aType)
145 : {
146 0 : Relation rel = nsAccessibleWrap::RelationByType(aType);
147 0 : if (aType != nsIAccessibleRelation::RELATION_LABEL_FOR)
148 0 : return rel;
149 :
150 : // Expose 'LABEL_FOR' relation on tab accessible for tabpanel accessible.
151 : nsCOMPtr<nsIDOMXULRelatedElement> tabsElm =
152 0 : do_QueryInterface(mContent->GetParent());
153 0 : if (!tabsElm)
154 : return rel;
155 :
156 0 : nsCOMPtr<nsIDOMNode> domNode(DOMNode());
157 0 : nsCOMPtr<nsIDOMNode> tabpanelNode;
158 0 : tabsElm->GetRelatedElement(domNode, getter_AddRefs(tabpanelNode));
159 0 : if (!tabpanelNode)
160 : return rel;
161 :
162 0 : nsCOMPtr<nsIContent> tabpanelContent(do_QueryInterface(tabpanelNode));
163 0 : rel.AppendTarget(tabpanelContent);
164 : return rel;
165 : }
166 :
167 : void
168 0 : nsXULTabAccessible::GetPositionAndSizeInternal(PRInt32 *aPosInSet,
169 : PRInt32 *aSetSize)
170 : {
171 : nsAccUtils::GetPositionAndSizeForXULSelectControlItem(mContent, aPosInSet,
172 0 : aSetSize);
173 0 : }
174 :
175 :
176 : ////////////////////////////////////////////////////////////////////////////////
177 : // nsXULTabsAccessible
178 : ////////////////////////////////////////////////////////////////////////////////
179 :
180 0 : nsXULTabsAccessible::
181 : nsXULTabsAccessible(nsIContent* aContent, nsDocAccessible* aDoc) :
182 0 : XULSelectControlAccessible(aContent, aDoc)
183 : {
184 0 : }
185 :
186 : role
187 0 : nsXULTabsAccessible::NativeRole()
188 : {
189 0 : return roles::PAGETABLIST;
190 : }
191 :
192 : PRUint8
193 0 : nsXULTabsAccessible::ActionCount()
194 : {
195 0 : return 0;
196 : }
197 :
198 : /** no value */
199 0 : NS_IMETHODIMP nsXULTabsAccessible::GetValue(nsAString& _retval)
200 : {
201 0 : return NS_OK;
202 : }
203 :
204 : nsresult
205 0 : nsXULTabsAccessible::GetNameInternal(nsAString& aName)
206 : {
207 : // no name
208 0 : return NS_OK;
209 : }
210 :
211 :
212 : ////////////////////////////////////////////////////////////////////////////////
213 : // nsXULTabpanelsAccessible
214 : ////////////////////////////////////////////////////////////////////////////////
215 :
216 0 : nsXULTabpanelsAccessible::
217 : nsXULTabpanelsAccessible(nsIContent* aContent, nsDocAccessible* aDoc) :
218 0 : nsAccessibleWrap(aContent, aDoc)
219 : {
220 0 : }
221 :
222 : role
223 0 : nsXULTabpanelsAccessible::NativeRole()
224 : {
225 0 : return roles::PANE;
226 : }
227 :
228 :
229 : ////////////////////////////////////////////////////////////////////////////////
230 : // nsXULTabpanelAccessible
231 : ////////////////////////////////////////////////////////////////////////////////
232 :
233 0 : nsXULTabpanelAccessible::
234 : nsXULTabpanelAccessible(nsIContent* aContent, nsDocAccessible* aDoc) :
235 0 : nsAccessibleWrap(aContent, aDoc)
236 : {
237 0 : }
238 :
239 : role
240 0 : nsXULTabpanelAccessible::NativeRole()
241 : {
242 0 : return roles::PROPERTYPAGE;
243 : }
244 :
245 : Relation
246 0 : nsXULTabpanelAccessible::RelationByType(PRUint32 aType)
247 : {
248 0 : Relation rel = nsAccessibleWrap::RelationByType(aType);
249 0 : if (aType != nsIAccessibleRelation::RELATION_LABELLED_BY)
250 0 : return rel;
251 :
252 : // Expose 'LABELLED_BY' relation on tabpanel accessible for tab accessible.
253 : nsCOMPtr<nsIDOMXULRelatedElement> tabpanelsElm =
254 0 : do_QueryInterface(mContent->GetParent());
255 0 : if (!tabpanelsElm)
256 : return rel;
257 :
258 0 : nsCOMPtr<nsIDOMNode> domNode(DOMNode());
259 0 : nsCOMPtr<nsIDOMNode> tabNode;
260 0 : tabpanelsElm->GetRelatedElement(domNode, getter_AddRefs(tabNode));
261 0 : if (!tabNode)
262 : return rel;
263 :
264 0 : nsCOMPtr<nsIContent> tabContent(do_QueryInterface(tabNode));
265 0 : rel.AppendTarget(tabContent);
266 : return rel;
267 : }
|