2014-03-07 21:35:19 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=2 et sw=2 tw=80: */
|
|
|
|
/* 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/. */
|
|
|
|
|
|
|
|
#include "DocAccessibleChild.h"
|
|
|
|
|
|
|
|
#include "Accessible-inl.h"
|
2015-01-09 20:01:39 +00:00
|
|
|
#include "ProxyAccessible.h"
|
2014-03-07 21:35:19 +00:00
|
|
|
|
2014-10-24 09:29:48 +00:00
|
|
|
#include "nsIPersistentProperties2.h"
|
|
|
|
#include "nsISimpleEnumerator.h"
|
|
|
|
|
2014-03-07 21:35:19 +00:00
|
|
|
namespace mozilla {
|
|
|
|
namespace a11y {
|
|
|
|
|
2015-01-09 20:01:39 +00:00
|
|
|
static uint32_t
|
|
|
|
InterfacesFor(Accessible* aAcc)
|
|
|
|
{
|
|
|
|
uint32_t interfaces = 0;
|
|
|
|
if (aAcc->IsHyperText() && aAcc->AsHyperText()->IsTextRole())
|
|
|
|
interfaces |= Interfaces::HYPERTEXT;
|
|
|
|
|
|
|
|
return interfaces;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-03-07 21:35:19 +00:00
|
|
|
SerializeTree(Accessible* aRoot, nsTArray<AccessibleData>& aTree)
|
|
|
|
{
|
|
|
|
uint64_t id = reinterpret_cast<uint64_t>(aRoot->UniqueID());
|
|
|
|
uint32_t role = aRoot->Role();
|
|
|
|
uint32_t childCount = aRoot->ChildCount();
|
2015-01-09 20:01:39 +00:00
|
|
|
uint32_t interfaces = InterfacesFor(aRoot);
|
2014-03-07 21:35:19 +00:00
|
|
|
|
2014-10-28 18:18:03 +00:00
|
|
|
// OuterDocAccessibles are special because we don't want to serialize the
|
|
|
|
// child doc here, we'll call PDocAccessibleConstructor in
|
|
|
|
// NotificationController.
|
|
|
|
if (childCount == 1 && aRoot->GetChildAt(0)->IsDoc())
|
|
|
|
childCount = 0;
|
|
|
|
|
2015-01-09 20:01:39 +00:00
|
|
|
aTree.AppendElement(AccessibleData(id, role, childCount, interfaces));
|
2014-03-07 21:35:19 +00:00
|
|
|
for (uint32_t i = 0; i < childCount; i++)
|
|
|
|
SerializeTree(aRoot->GetChildAt(i), aTree);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DocAccessibleChild::ShowEvent(AccShowEvent* aShowEvent)
|
|
|
|
{
|
|
|
|
Accessible* parent = aShowEvent->Parent();
|
|
|
|
uint64_t parentID = parent->IsDoc() ? 0 : reinterpret_cast<uint64_t>(parent->UniqueID());
|
|
|
|
uint32_t idxInParent = aShowEvent->GetAccessible()->IndexInParent();
|
|
|
|
nsTArray<AccessibleData> shownTree;
|
|
|
|
ShowEventData data(parentID, idxInParent, shownTree);
|
|
|
|
SerializeTree(aShowEvent->GetAccessible(), data.NewTree());
|
|
|
|
SendShowEvent(data);
|
|
|
|
}
|
2014-09-23 08:35:33 +00:00
|
|
|
|
|
|
|
bool
|
|
|
|
DocAccessibleChild::RecvState(const uint64_t& aID, uint64_t* aState)
|
|
|
|
{
|
|
|
|
Accessible* acc = mDoc->GetAccessibleByUniqueID((void*)aID);
|
|
|
|
if (!acc) {
|
|
|
|
*aState = states::DEFUNCT;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
*aState = acc->State();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2014-09-23 09:53:03 +00:00
|
|
|
|
|
|
|
bool
|
|
|
|
DocAccessibleChild::RecvName(const uint64_t& aID, nsString* aName)
|
|
|
|
{
|
|
|
|
Accessible* acc = mDoc->GetAccessibleByUniqueID((void*)aID);
|
|
|
|
if (!acc)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
acc->Name(*aName);
|
|
|
|
return true;
|
|
|
|
}
|
2014-10-24 03:21:44 +00:00
|
|
|
|
2015-02-11 20:00:11 +00:00
|
|
|
bool
|
|
|
|
DocAccessibleChild::RecvValue(const uint64_t& aID, nsString* aValue)
|
|
|
|
{
|
|
|
|
Accessible* acc =
|
|
|
|
mDoc->GetAccessibleByUniqueID(reinterpret_cast<void*>(aID));
|
|
|
|
if (!acc) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
acc->Value(*aValue);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-10-24 03:21:44 +00:00
|
|
|
bool
|
|
|
|
DocAccessibleChild::RecvDescription(const uint64_t& aID, nsString* aDesc)
|
|
|
|
{
|
|
|
|
Accessible* acc = mDoc->GetAccessibleByUniqueID((void*)aID);
|
|
|
|
if (!acc)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
acc->Description(*aDesc);
|
|
|
|
return true;
|
|
|
|
}
|
2014-10-24 09:29:48 +00:00
|
|
|
|
|
|
|
bool
|
|
|
|
DocAccessibleChild::RecvAttributes(const uint64_t& aID, nsTArray<Attribute>* aAttributes)
|
|
|
|
{
|
|
|
|
Accessible* acc = mDoc->GetAccessibleByUniqueID((void*)aID);
|
|
|
|
if (!acc)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPersistentProperties> props = acc->Attributes();
|
|
|
|
if (!props)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
nsCOMPtr<nsISimpleEnumerator> propEnum;
|
|
|
|
nsresult rv = props->Enumerate(getter_AddRefs(propEnum));
|
|
|
|
NS_ENSURE_SUCCESS(rv, false);
|
|
|
|
|
|
|
|
bool hasMore;
|
|
|
|
while (NS_SUCCEEDED(propEnum->HasMoreElements(&hasMore)) && hasMore) {
|
|
|
|
nsCOMPtr<nsISupports> sup;
|
|
|
|
rv = propEnum->GetNext(getter_AddRefs(sup));
|
|
|
|
NS_ENSURE_SUCCESS(rv, false);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPropertyElement> propElem(do_QueryInterface(sup));
|
|
|
|
NS_ENSURE_TRUE(propElem, false);
|
|
|
|
|
|
|
|
nsAutoCString name;
|
|
|
|
rv = propElem->GetKey(name);
|
|
|
|
NS_ENSURE_SUCCESS(rv, false);
|
|
|
|
|
|
|
|
nsAutoString value;
|
|
|
|
rv = propElem->GetValue(value);
|
|
|
|
NS_ENSURE_SUCCESS(rv, false);
|
|
|
|
|
|
|
|
aAttributes->AppendElement(Attribute(name, value));
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2015-01-09 20:01:39 +00:00
|
|
|
|
|
|
|
bool
|
|
|
|
DocAccessibleChild::RecvTextSubstring(const uint64_t& aID,
|
|
|
|
const int32_t& aStartOffset,
|
|
|
|
const int32_t& aEndOffset,
|
|
|
|
nsString* aText)
|
|
|
|
{
|
|
|
|
Accessible* acc = mDoc->GetAccessibleByUniqueID((void*)aID);
|
|
|
|
if (!acc || !acc->IsHyperText())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
acc->AsHyperText()->TextSubstring(aStartOffset, aEndOffset, *aText);
|
|
|
|
return true;
|
|
|
|
}
|
2014-03-07 21:35:19 +00:00
|
|
|
}
|
|
|
|
}
|