2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-05-27 02:01:40 -07:00
|
|
|
#include "DocAccessible.h"
|
2008-02-22 12:13:17 -08:00
|
|
|
#include "nsObjCExceptions.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-04-13 07:17:03 -07:00
|
|
|
#include "Accessible-inl.h"
|
2012-07-27 21:21:40 -07:00
|
|
|
#include "nsAccUtils.h"
|
2012-01-11 19:07:35 -08:00
|
|
|
#include "Role.h"
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#import "mozAccessible.h"
|
|
|
|
#import "mozActionElements.h"
|
2012-01-23 14:37:21 -08:00
|
|
|
#import "mozHTMLAccessible.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#import "mozTextAccessible.h"
|
|
|
|
|
2012-01-11 19:07:35 -08:00
|
|
|
using namespace mozilla::a11y;
|
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
AccessibleWrap::
|
|
|
|
AccessibleWrap(nsIContent* aContent, DocAccessible* aDoc) :
|
|
|
|
Accessible(aContent, aDoc), mNativeObject(nil),
|
2011-12-15 06:47:04 -08:00
|
|
|
mNativeInited(false)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
AccessibleWrap::~AccessibleWrap()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-12-15 06:47:04 -08:00
|
|
|
mozAccessible*
|
2012-05-28 18:18:45 -07:00
|
|
|
AccessibleWrap::GetNativeObject()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-12-13 06:17:59 -08:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
|
2011-12-15 06:47:04 -08:00
|
|
|
|
|
|
|
if (!mNativeInited && !mNativeObject && !IsDefunct() && !AncestorIsFlat())
|
2011-12-13 06:17:59 -08:00
|
|
|
mNativeObject = [[GetNativeType() alloc] initWithAccessible:this];
|
|
|
|
|
2011-12-15 06:47:04 -08:00
|
|
|
mNativeInited = true;
|
|
|
|
|
|
|
|
return mNativeObject;
|
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2014-10-21 17:49:28 -07:00
|
|
|
void
|
|
|
|
AccessibleWrap::GetNativeInterface(void** aOutInterface)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-12-15 06:47:04 -08:00
|
|
|
*aOutInterface = static_cast<void*>(GetNativeObject());
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// overridden in subclasses to create the right kind of object. by default we create a generic
|
|
|
|
// 'mozAccessible' node.
|
2011-05-17 07:00:30 -07:00
|
|
|
Class
|
2012-05-28 18:18:45 -07:00
|
|
|
AccessibleWrap::GetNativeType ()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-02-22 12:13:17 -08:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
|
|
|
|
|
2012-12-28 00:15:02 -08:00
|
|
|
if (IsXULTabpanels())
|
2012-06-28 16:04:50 -07:00
|
|
|
return [mozPaneAccessible class];
|
2012-12-28 00:15:02 -08:00
|
|
|
|
2012-01-11 19:07:35 -08:00
|
|
|
roles::Role role = Role();
|
2007-03-22 10:30:00 -07:00
|
|
|
switch (role) {
|
2015-05-29 08:41:54 -07:00
|
|
|
case roles::COMBOBOX:
|
2012-01-11 19:07:35 -08:00
|
|
|
case roles::PUSHBUTTON:
|
|
|
|
case roles::SPLITBUTTON:
|
|
|
|
case roles::TOGGLE_BUTTON:
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// if this button may show a popup, let's make it of the popupbutton type.
|
2015-05-29 08:41:54 -07:00
|
|
|
return [mozButtonAccessible class];
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-01-26 22:14:09 -08:00
|
|
|
case roles::PAGETAB:
|
|
|
|
return [mozButtonAccessible class];
|
|
|
|
|
2012-01-11 19:07:35 -08:00
|
|
|
case roles::CHECKBUTTON:
|
2007-03-22 10:30:00 -07:00
|
|
|
return [mozCheckboxAccessible class];
|
|
|
|
|
2012-01-23 14:37:21 -08:00
|
|
|
case roles::HEADING:
|
|
|
|
return [mozHeadingAccessible class];
|
|
|
|
|
2012-01-26 22:14:09 -08:00
|
|
|
case roles::PAGETABLIST:
|
|
|
|
return [mozTabsAccessible class];
|
2012-06-28 16:04:50 -07:00
|
|
|
|
2012-01-11 19:07:35 -08:00
|
|
|
case roles::ENTRY:
|
|
|
|
case roles::STATICTEXT:
|
|
|
|
case roles::CAPTION:
|
|
|
|
case roles::ACCEL_LABEL:
|
2012-04-12 11:02:25 -07:00
|
|
|
case roles::PASSWORD_TEXT:
|
2007-03-22 10:30:00 -07:00
|
|
|
// normal textfield (static or editable)
|
2012-06-29 14:12:16 -07:00
|
|
|
return [mozTextAccessible class];
|
|
|
|
|
|
|
|
case roles::TEXT_LEAF:
|
|
|
|
return [mozTextLeafAccessible class];
|
2012-01-27 07:50:04 -08:00
|
|
|
|
|
|
|
case roles::LINK:
|
|
|
|
return [mozLinkAccessible class];
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
default:
|
|
|
|
return [mozAccessible class];
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil;
|
2008-02-22 12:13:17 -08:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// this method is very important. it is fired when an accessible object "dies". after this point
|
|
|
|
// the object might still be around (because some 3rd party still has a ref to it), but it is
|
|
|
|
// in fact 'dead'.
|
2010-06-11 21:04:35 -07:00
|
|
|
void
|
2012-05-28 18:18:45 -07:00
|
|
|
AccessibleWrap::Shutdown ()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-12-15 06:47:04 -08:00
|
|
|
// this ensure we will not try to re-create the native object.
|
|
|
|
mNativeInited = true;
|
|
|
|
|
|
|
|
// we really intend to access the member directly.
|
2011-12-13 06:17:59 -08:00
|
|
|
if (mNativeObject) {
|
|
|
|
[mNativeObject expire];
|
|
|
|
[mNativeObject release];
|
|
|
|
mNativeObject = nil;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2011-12-15 06:47:04 -08:00
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::Shutdown();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-06-18 00:37:38 -07:00
|
|
|
nsresult
|
2012-05-28 18:18:45 -07:00
|
|
|
AccessibleWrap::HandleAccEvent(AccEvent* aEvent)
|
2007-07-05 09:02:55 -07:00
|
|
|
{
|
2008-02-22 12:13:17 -08:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
nsresult rv = Accessible::HandleAccEvent(aEvent);
|
2007-07-05 09:02:55 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t eventType = aEvent->GetEventType();
|
2007-07-05 09:02:55 -07:00
|
|
|
|
2012-04-02 10:15:00 -07:00
|
|
|
// ignore everything but focus-changed, value-changed, caret and selection
|
|
|
|
// events for now.
|
2007-07-05 09:02:55 -07:00
|
|
|
if (eventType != nsIAccessibleEvent::EVENT_FOCUS &&
|
2012-04-02 10:15:00 -07:00
|
|
|
eventType != nsIAccessibleEvent::EVENT_VALUE_CHANGE &&
|
|
|
|
eventType != nsIAccessibleEvent::EVENT_TEXT_CARET_MOVED &&
|
|
|
|
eventType != nsIAccessibleEvent::EVENT_TEXT_SELECTION_CHANGED)
|
2007-07-05 09:02:55 -07:00
|
|
|
return NS_OK;
|
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* accessible = aEvent->GetAccessible();
|
2007-07-05 09:02:55 -07:00
|
|
|
NS_ENSURE_STATE(accessible);
|
|
|
|
|
|
|
|
mozAccessible *nativeAcc = nil;
|
|
|
|
accessible->GetNativeInterface((void**)&nativeAcc);
|
|
|
|
if (!nativeAcc)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
switch (eventType) {
|
|
|
|
case nsIAccessibleEvent::EVENT_FOCUS:
|
|
|
|
[nativeAcc didReceiveFocus];
|
|
|
|
break;
|
|
|
|
case nsIAccessibleEvent::EVENT_VALUE_CHANGE:
|
|
|
|
[nativeAcc valueDidChange];
|
|
|
|
break;
|
2012-04-02 10:15:00 -07:00
|
|
|
case nsIAccessibleEvent::EVENT_TEXT_CARET_MOVED:
|
|
|
|
case nsIAccessibleEvent::EVENT_TEXT_SELECTION_CHANGED:
|
|
|
|
[nativeAcc selectedTextDidChange];
|
|
|
|
break;
|
2007-07-05 09:02:55 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
2008-02-22 12:13:17 -08:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
2007-07-05 09:02:55 -07:00
|
|
|
}
|
|
|
|
|
2009-06-18 00:37:38 -07:00
|
|
|
void
|
2012-05-28 18:18:45 -07:00
|
|
|
AccessibleWrap::InvalidateChildren()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-06-18 01:14:16 -07:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
2008-02-22 12:13:17 -08:00
|
|
|
|
2011-12-15 06:47:04 -08:00
|
|
|
[GetNativeObject() invalidateChildren];
|
2011-12-13 06:17:59 -08:00
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::InvalidateChildren();
|
2008-02-22 12:13:17 -08:00
|
|
|
|
2009-06-18 01:14:16 -07:00
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-12-22 14:31:06 -08:00
|
|
|
bool
|
2013-03-13 21:53:28 -07:00
|
|
|
AccessibleWrap::InsertChildAt(uint32_t aIdx, Accessible* aAccessible)
|
2011-12-22 14:31:06 -08:00
|
|
|
{
|
2013-03-13 21:53:28 -07:00
|
|
|
bool inserted = Accessible::InsertChildAt(aIdx, aAccessible);
|
|
|
|
if (inserted && mNativeObject)
|
2011-12-22 14:31:06 -08:00
|
|
|
[mNativeObject appendChild:aAccessible];
|
|
|
|
|
2013-03-13 21:53:28 -07:00
|
|
|
return inserted;
|
2011-12-22 14:31:06 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2012-05-28 18:18:45 -07:00
|
|
|
AccessibleWrap::RemoveChild(Accessible* aAccessible)
|
2011-12-22 14:31:06 -08:00
|
|
|
{
|
2012-05-28 18:18:45 -07:00
|
|
|
bool removed = Accessible::RemoveChild(aAccessible);
|
2011-12-22 14:31:06 -08:00
|
|
|
|
|
|
|
if (removed && mNativeObject)
|
|
|
|
[mNativeObject invalidateChildren];
|
|
|
|
|
|
|
|
return removed;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// if we for some reason have no native accessible, we should be skipped over (and traversed)
|
|
|
|
// when fetching all unignored children, etc. when counting unignored children, we will not be counted.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2012-05-28 18:18:45 -07:00
|
|
|
AccessibleWrap::IsIgnored()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-12-13 06:17:59 -08:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
|
|
|
|
|
2011-12-15 06:47:04 -08:00
|
|
|
mozAccessible* nativeObject = GetNativeObject();
|
|
|
|
return (!nativeObject) || [nativeObject accessibilityIsIgnored];
|
2011-12-13 06:17:59 -08:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(false);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-05-28 18:18:45 -07:00
|
|
|
AccessibleWrap::GetUnignoredChildren(nsTArray<Accessible*>* aChildrenArray)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// we're flat; there are no children.
|
2008-10-17 03:10:43 -07:00
|
|
|
if (nsAccUtils::MustPrune(this))
|
2007-03-22 10:30:00 -07:00
|
|
|
return;
|
2010-04-19 06:39:57 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t childCount = ChildCount();
|
|
|
|
for (uint32_t childIdx = 0; childIdx < childCount; childIdx++) {
|
2012-05-28 18:18:45 -07:00
|
|
|
AccessibleWrap* childAcc =
|
|
|
|
static_cast<AccessibleWrap*>(GetChildAt(childIdx));
|
2010-04-19 06:39:57 -07:00
|
|
|
|
2012-04-03 02:54:07 -07:00
|
|
|
// If element is ignored, then add its children as substitutes.
|
2010-04-19 06:39:57 -07:00
|
|
|
if (childAcc->IsIgnored()) {
|
2012-04-03 02:54:07 -07:00
|
|
|
childAcc->GetUnignoredChildren(aChildrenArray);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
aChildrenArray->AppendElement(childAcc);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible*
|
|
|
|
AccessibleWrap::GetUnignoredParent() const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-04-02 01:25:29 -07:00
|
|
|
// Go up the chain to find a parent that is not ignored.
|
2012-05-28 18:18:45 -07:00
|
|
|
AccessibleWrap* parentWrap = static_cast<AccessibleWrap*>(Parent());
|
2012-04-02 01:25:29 -07:00
|
|
|
while (parentWrap && parentWrap->IsIgnored())
|
2012-05-28 18:18:45 -07:00
|
|
|
parentWrap = static_cast<AccessibleWrap*>(parentWrap->Parent());
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-04-02 01:25:29 -07:00
|
|
|
return parentWrap;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-04-26 23:52:03 -07:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-05-28 18:18:45 -07:00
|
|
|
// AccessibleWrap protected
|
2010-04-26 23:52:03 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2012-05-28 18:18:45 -07:00
|
|
|
AccessibleWrap::AncestorIsFlat()
|
2010-04-26 23:52:03 -07:00
|
|
|
{
|
|
|
|
// We don't create a native object if we're child of a "flat" accessible;
|
|
|
|
// for example, on OS X buttons shouldn't have any children, because that
|
|
|
|
// makes the OS confused.
|
|
|
|
//
|
|
|
|
// To maintain a scripting environment where the XPCOM accessible hierarchy
|
|
|
|
// look the same on all platforms, we still let the C++ objects be created
|
|
|
|
// though.
|
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* parent = Parent();
|
2010-04-26 23:52:03 -07:00
|
|
|
while (parent) {
|
|
|
|
if (nsAccUtils::MustPrune(parent))
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2010-04-26 23:52:03 -07:00
|
|
|
|
2011-07-23 01:38:33 -07:00
|
|
|
parent = parent->Parent();
|
2010-04-26 23:52:03 -07:00
|
|
|
}
|
|
|
|
// no parent was flat
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-04-26 23:52:03 -07:00
|
|
|
}
|