2006-09-11 19:44:00 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04: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/. */
|
2006-09-11 19:44:00 +04:00
|
|
|
|
2012-05-27 13:01:40 +04:00
|
|
|
#include "DocAccessible.h"
|
2008-02-22 23:13:17 +03:00
|
|
|
#include "nsObjCExceptions.h"
|
2006-11-15 14:08:14 +03:00
|
|
|
|
2012-04-13 18:17:03 +04:00
|
|
|
#include "Accessible-inl.h"
|
2012-07-28 08:21:40 +04:00
|
|
|
#include "nsAccUtils.h"
|
2012-01-12 07:07:35 +04:00
|
|
|
#include "Role.h"
|
|
|
|
|
2006-09-11 19:44:00 +04:00
|
|
|
#import "mozAccessible.h"
|
2006-11-15 14:08:14 +03:00
|
|
|
#import "mozActionElements.h"
|
2012-01-24 02:37:21 +04:00
|
|
|
#import "mozHTMLAccessible.h"
|
2015-10-01 17:00:00 +03:00
|
|
|
#import "mozTableAccessible.h"
|
2006-11-15 14:08:14 +03:00
|
|
|
#import "mozTextAccessible.h"
|
2006-09-11 19:44:00 +04:00
|
|
|
|
2015-05-29 20:42:23 +03:00
|
|
|
using namespace mozilla;
|
2012-01-12 07:07:35 +04:00
|
|
|
using namespace mozilla::a11y;
|
|
|
|
|
2012-05-29 05:18:45 +04:00
|
|
|
AccessibleWrap::
|
|
|
|
AccessibleWrap(nsIContent* aContent, DocAccessible* aDoc) :
|
2015-06-08 17:59:19 +03:00
|
|
|
Accessible(aContent, aDoc), mNativeObject(nil),
|
2011-12-15 18:47:04 +04:00
|
|
|
mNativeInited(false)
|
2006-09-11 19:44:00 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-05-29 05:18:45 +04:00
|
|
|
AccessibleWrap::~AccessibleWrap()
|
2006-09-11 19:44:00 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-06-08 17:59:19 +03:00
|
|
|
mozAccessible*
|
2012-05-29 05:18:45 +04:00
|
|
|
AccessibleWrap::GetNativeObject()
|
2006-09-11 19:44:00 +04:00
|
|
|
{
|
2011-12-13 18:17:59 +04:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
|
2015-06-08 17:59:19 +03:00
|
|
|
|
2015-05-29 20:42:23 +03:00
|
|
|
if (!mNativeInited && !mNativeObject && !IsDefunct() && !AncestorIsFlat()) {
|
|
|
|
uintptr_t accWrap = reinterpret_cast<uintptr_t>(this);
|
|
|
|
mNativeObject = [[GetNativeType() alloc] initWithAccessible:accWrap];
|
|
|
|
}
|
2015-06-08 17:59:19 +03:00
|
|
|
|
2011-12-15 18:47:04 +04:00
|
|
|
mNativeInited = true;
|
2015-06-08 17:59:19 +03:00
|
|
|
|
2011-12-15 18:47:04 +04:00
|
|
|
return mNativeObject;
|
2015-06-08 17:59:19 +03:00
|
|
|
|
2011-12-15 18:47:04 +04:00
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
|
2006-09-11 19:44:00 +04:00
|
|
|
}
|
|
|
|
|
2014-10-22 04:49:28 +04:00
|
|
|
void
|
|
|
|
AccessibleWrap::GetNativeInterface(void** aOutInterface)
|
2006-09-11 19:44:00 +04:00
|
|
|
{
|
2011-12-15 18:47:04 +04:00
|
|
|
*aOutInterface = static_cast<void*>(GetNativeObject());
|
2006-09-11 19:44:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// overridden in subclasses to create the right kind of object. by default we create a generic
|
|
|
|
// 'mozAccessible' node.
|
2011-05-17 18:00:30 +04:00
|
|
|
Class
|
2015-06-08 17:59:19 +03:00
|
|
|
AccessibleWrap::GetNativeType ()
|
2006-09-11 19:44:00 +04:00
|
|
|
{
|
2008-02-22 23:13:17 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
|
|
|
|
|
2012-12-28 12:15:02 +04:00
|
|
|
if (IsXULTabpanels())
|
2012-06-29 03:04:50 +04:00
|
|
|
return [mozPaneAccessible class];
|
2012-12-28 12:15:02 +04:00
|
|
|
|
2015-10-01 17:00:00 +03:00
|
|
|
if (IsTable())
|
|
|
|
return [mozTableAccessible class];
|
|
|
|
|
|
|
|
if (IsTableRow())
|
|
|
|
return [mozTableRowAccessible class];
|
|
|
|
|
|
|
|
if (IsTableCell())
|
|
|
|
return [mozTableCellAccessible class];
|
|
|
|
|
2015-05-29 20:42:23 +03:00
|
|
|
return GetTypeFromRole(Role());
|
2008-02-22 23:13:17 +03:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
|
2006-09-11 19:44:00 +04: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-12 08:04:35 +04:00
|
|
|
void
|
2012-05-29 05:18:45 +04:00
|
|
|
AccessibleWrap::Shutdown ()
|
2006-09-11 19:44:00 +04:00
|
|
|
{
|
2011-12-15 18:47:04 +04: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 18:17:59 +04:00
|
|
|
if (mNativeObject) {
|
|
|
|
[mNativeObject expire];
|
|
|
|
[mNativeObject release];
|
|
|
|
mNativeObject = nil;
|
2006-09-11 19:44:00 +04:00
|
|
|
}
|
2011-12-15 18:47:04 +04:00
|
|
|
|
2012-05-29 05:18:45 +04:00
|
|
|
Accessible::Shutdown();
|
2006-09-11 19:44:00 +04:00
|
|
|
}
|
|
|
|
|
2009-06-18 11:37:38 +04:00
|
|
|
nsresult
|
2012-05-29 05:18:45 +04:00
|
|
|
AccessibleWrap::HandleAccEvent(AccEvent* aEvent)
|
2007-07-05 20:02:55 +04:00
|
|
|
{
|
2008-02-22 23:13:17 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
|
2012-05-29 05:18:45 +04:00
|
|
|
nsresult rv = Accessible::HandleAccEvent(aEvent);
|
2007-07-05 20:02:55 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2015-08-05 16:57:13 +03:00
|
|
|
if (IPCAccessibilityActive()) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t eventType = aEvent->GetEventType();
|
2007-07-05 20:02:55 +04:00
|
|
|
|
2015-10-02 06:42:00 +03:00
|
|
|
// ignore everything but focus-changed, value-changed, caret, selection
|
|
|
|
// and document load complete events for now.
|
2007-07-05 20:02:55 +04:00
|
|
|
if (eventType != nsIAccessibleEvent::EVENT_FOCUS &&
|
2012-04-02 21:15:00 +04:00
|
|
|
eventType != nsIAccessibleEvent::EVENT_VALUE_CHANGE &&
|
2015-11-02 23:34:51 +03:00
|
|
|
eventType != nsIAccessibleEvent::EVENT_TEXT_VALUE_CHANGE &&
|
2012-04-02 21:15:00 +04:00
|
|
|
eventType != nsIAccessibleEvent::EVENT_TEXT_CARET_MOVED &&
|
2015-10-02 06:42:00 +03:00
|
|
|
eventType != nsIAccessibleEvent::EVENT_TEXT_SELECTION_CHANGED &&
|
|
|
|
eventType != nsIAccessibleEvent::EVENT_DOCUMENT_LOAD_COMPLETE)
|
2007-07-05 20:02:55 +04:00
|
|
|
return NS_OK;
|
|
|
|
|
2012-05-29 05:18:45 +04:00
|
|
|
Accessible* accessible = aEvent->GetAccessible();
|
2007-07-05 20:02:55 +04:00
|
|
|
NS_ENSURE_STATE(accessible);
|
|
|
|
|
|
|
|
mozAccessible *nativeAcc = nil;
|
|
|
|
accessible->GetNativeInterface((void**)&nativeAcc);
|
|
|
|
if (!nativeAcc)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2015-05-29 20:50:26 +03:00
|
|
|
FireNativeEvent(nativeAcc, eventType);
|
2007-07-05 20:02:55 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
2008-02-22 23:13:17 +03:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
2007-07-05 20:02:55 +04:00
|
|
|
}
|
|
|
|
|
2011-12-23 02:31:06 +04:00
|
|
|
bool
|
2013-03-14 08:53:28 +04:00
|
|
|
AccessibleWrap::InsertChildAt(uint32_t aIdx, Accessible* aAccessible)
|
2011-12-23 02:31:06 +04:00
|
|
|
{
|
2013-03-14 08:53:28 +04:00
|
|
|
bool inserted = Accessible::InsertChildAt(aIdx, aAccessible);
|
|
|
|
if (inserted && mNativeObject)
|
2011-12-23 02:31:06 +04:00
|
|
|
[mNativeObject appendChild:aAccessible];
|
|
|
|
|
2013-03-14 08:53:28 +04:00
|
|
|
return inserted;
|
2011-12-23 02:31:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2012-05-29 05:18:45 +04:00
|
|
|
AccessibleWrap::RemoveChild(Accessible* aAccessible)
|
2011-12-23 02:31:06 +04:00
|
|
|
{
|
2012-05-29 05:18:45 +04:00
|
|
|
bool removed = Accessible::RemoveChild(aAccessible);
|
2011-12-23 02:31:06 +04:00
|
|
|
|
|
|
|
if (removed && mNativeObject)
|
|
|
|
[mNativeObject invalidateChildren];
|
|
|
|
|
|
|
|
return removed;
|
|
|
|
}
|
|
|
|
|
2010-04-27 10:52:03 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-05-29 05:18:45 +04:00
|
|
|
// AccessibleWrap protected
|
2010-04-27 10:52:03 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2012-05-29 05:18:45 +04:00
|
|
|
AccessibleWrap::AncestorIsFlat()
|
2010-04-27 10:52:03 +04: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
|
2015-06-08 17:59:19 +03:00
|
|
|
// makes the OS confused.
|
2010-04-27 10:52:03 +04:00
|
|
|
//
|
|
|
|
// 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-29 05:18:45 +04:00
|
|
|
Accessible* parent = Parent();
|
2010-04-27 10:52:03 +04:00
|
|
|
while (parent) {
|
|
|
|
if (nsAccUtils::MustPrune(parent))
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2010-04-27 10:52:03 +04:00
|
|
|
|
2011-07-23 12:38:33 +04:00
|
|
|
parent = parent->Parent();
|
2010-04-27 10:52:03 +04:00
|
|
|
}
|
|
|
|
// no parent was flat
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2010-04-27 10:52:03 +04:00
|
|
|
}
|
2015-05-29 20:42:23 +03:00
|
|
|
|
2015-05-29 20:50:26 +03:00
|
|
|
void
|
|
|
|
a11y::FireNativeEvent(mozAccessible* aNativeAcc, uint32_t aEventType)
|
|
|
|
{
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
|
|
|
switch (aEventType) {
|
|
|
|
case nsIAccessibleEvent::EVENT_FOCUS:
|
|
|
|
[aNativeAcc didReceiveFocus];
|
|
|
|
break;
|
|
|
|
case nsIAccessibleEvent::EVENT_VALUE_CHANGE:
|
2015-11-02 23:34:51 +03:00
|
|
|
case nsIAccessibleEvent::EVENT_TEXT_VALUE_CHANGE:
|
2015-05-29 20:50:26 +03:00
|
|
|
[aNativeAcc valueDidChange];
|
|
|
|
break;
|
|
|
|
case nsIAccessibleEvent::EVENT_TEXT_CARET_MOVED:
|
|
|
|
case nsIAccessibleEvent::EVENT_TEXT_SELECTION_CHANGED:
|
|
|
|
[aNativeAcc selectedTextDidChange];
|
|
|
|
break;
|
2015-10-02 06:42:00 +03:00
|
|
|
case nsIAccessibleEvent::EVENT_DOCUMENT_LOAD_COMPLETE:
|
|
|
|
[aNativeAcc documentLoadComplete];
|
|
|
|
break;
|
2015-05-29 20:50:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
|
|
|
}
|
|
|
|
|
2015-05-29 20:42:23 +03:00
|
|
|
Class
|
2015-06-08 17:59:19 +03:00
|
|
|
a11y::GetTypeFromRole(roles::Role aRole)
|
2015-05-29 20:42:23 +03:00
|
|
|
{
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
|
|
|
|
|
|
|
|
switch (aRole) {
|
|
|
|
case roles::COMBOBOX:
|
|
|
|
case roles::PUSHBUTTON:
|
|
|
|
case roles::SPLITBUTTON:
|
|
|
|
case roles::TOGGLE_BUTTON:
|
|
|
|
{
|
|
|
|
return [mozButtonAccessible class];
|
|
|
|
}
|
2015-06-08 17:59:19 +03:00
|
|
|
|
2015-05-29 20:42:23 +03:00
|
|
|
case roles::PAGETAB:
|
|
|
|
return [mozButtonAccessible class];
|
|
|
|
|
|
|
|
case roles::CHECKBUTTON:
|
|
|
|
return [mozCheckboxAccessible class];
|
2015-06-08 17:59:19 +03:00
|
|
|
|
2015-05-29 20:42:23 +03:00
|
|
|
case roles::HEADING:
|
|
|
|
return [mozHeadingAccessible class];
|
|
|
|
|
|
|
|
case roles::PAGETABLIST:
|
|
|
|
return [mozTabsAccessible class];
|
|
|
|
|
|
|
|
case roles::ENTRY:
|
|
|
|
case roles::STATICTEXT:
|
|
|
|
case roles::CAPTION:
|
|
|
|
case roles::ACCEL_LABEL:
|
|
|
|
case roles::PASSWORD_TEXT:
|
|
|
|
// normal textfield (static or editable)
|
|
|
|
return [mozTextAccessible class];
|
|
|
|
|
|
|
|
case roles::TEXT_LEAF:
|
|
|
|
return [mozTextLeafAccessible class];
|
|
|
|
|
|
|
|
case roles::LINK:
|
|
|
|
return [mozLinkAccessible class];
|
2015-06-08 17:59:19 +03:00
|
|
|
|
2015-05-29 20:42:23 +03:00
|
|
|
default:
|
|
|
|
return [mozAccessible class];
|
|
|
|
}
|
2015-06-08 17:59:19 +03:00
|
|
|
|
2015-05-29 20:42:23 +03:00
|
|
|
return nil;
|
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
|
|
|
|
}
|