2012-05-07 22:16:40 -07: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 "HTMLListAccessible.h"
|
|
|
|
|
2012-05-27 02:01:40 -07:00
|
|
|
#include "DocAccessible.h"
|
2013-12-10 04:40:54 -08:00
|
|
|
#include "nsAccUtils.h"
|
2012-05-07 22:16:40 -07:00
|
|
|
#include "Role.h"
|
|
|
|
#include "States.h"
|
|
|
|
|
|
|
|
#include "nsBlockFrame.h"
|
2012-05-13 21:51:45 -07:00
|
|
|
#include "nsBulletFrame.h"
|
2012-05-07 22:16:40 -07:00
|
|
|
|
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::a11y;
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// HTMLListAccessible
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2012-05-31 01:04:41 -07:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED0(HTMLListAccessible, HyperTextAccessible)
|
2012-05-07 22:16:40 -07:00
|
|
|
|
|
|
|
role
|
|
|
|
HTMLListAccessible::NativeRole()
|
|
|
|
{
|
|
|
|
if (mContent->Tag() == nsGkAtoms::dl)
|
|
|
|
return roles::DEFINITION_LIST;
|
|
|
|
|
|
|
|
return roles::LIST;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint64_t
|
2012-05-07 22:16:40 -07:00
|
|
|
HTMLListAccessible::NativeState()
|
|
|
|
{
|
2012-05-31 01:04:41 -07:00
|
|
|
return HyperTextAccessibleWrap::NativeState() | states::READONLY;
|
2012-05-07 22:16:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// HTMLLIAccessible
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
HTMLLIAccessible::
|
2012-05-27 02:01:40 -07:00
|
|
|
HTMLLIAccessible(nsIContent* aContent, DocAccessible* aDoc) :
|
2012-07-30 07:20:58 -07:00
|
|
|
HyperTextAccessibleWrap(aContent, aDoc), mBullet(nullptr)
|
2012-05-07 22:16:40 -07:00
|
|
|
{
|
2012-12-17 21:22:26 -08:00
|
|
|
mType = eHTMLLiType;
|
2012-05-07 22:16:40 -07:00
|
|
|
|
|
|
|
nsBlockFrame* blockFrame = do_QueryFrame(GetFrame());
|
|
|
|
if (blockFrame && blockFrame->HasBullet()) {
|
|
|
|
mBullet = new HTMLListBulletAccessible(mContent, mDoc);
|
2013-09-06 12:27:07 -07:00
|
|
|
Document()->BindToDocument(mBullet, nullptr);
|
2012-05-07 22:16:40 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-31 01:04:41 -07:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED0(HTMLLIAccessible, HyperTextAccessible)
|
2012-05-07 22:16:40 -07:00
|
|
|
|
|
|
|
void
|
|
|
|
HTMLLIAccessible::Shutdown()
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
mBullet = nullptr;
|
2012-05-07 22:16:40 -07:00
|
|
|
|
2012-05-31 01:04:41 -07:00
|
|
|
HyperTextAccessibleWrap::Shutdown();
|
2012-05-07 22:16:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
role
|
|
|
|
HTMLLIAccessible::NativeRole()
|
|
|
|
{
|
|
|
|
if (mContent->Tag() == nsGkAtoms::dt)
|
|
|
|
return roles::TERM;
|
|
|
|
|
|
|
|
return roles::LISTITEM;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint64_t
|
2012-05-07 22:16:40 -07:00
|
|
|
HTMLLIAccessible::NativeState()
|
|
|
|
{
|
2012-05-31 01:04:41 -07:00
|
|
|
return HyperTextAccessibleWrap::NativeState() | states::READONLY;
|
2012-05-07 22:16:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
HTMLLIAccessible::GetBounds(int32_t* aX, int32_t* aY,
|
|
|
|
int32_t* aWidth, int32_t* aHeight)
|
2012-05-07 22:16:40 -07:00
|
|
|
{
|
2012-05-28 18:18:45 -07:00
|
|
|
nsresult rv = AccessibleWrap::GetBounds(aX, aY, aWidth, aHeight);
|
2012-05-13 21:51:45 -07:00
|
|
|
if (NS_FAILED(rv) || !mBullet || mBullet->IsInside())
|
2012-05-07 22:16:40 -07:00
|
|
|
return rv;
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t bulletX = 0, bulletY = 0, bulletWidth = 0, bulletHeight = 0;
|
2012-05-07 22:16:40 -07:00
|
|
|
rv = mBullet->GetBounds(&bulletX, &bulletY, &bulletWidth, &bulletHeight);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2012-05-13 21:51:45 -07:00
|
|
|
*aWidth += *aX - bulletX;
|
2012-05-07 22:16:40 -07:00
|
|
|
*aX = bulletX; // Move x coordinate of list item over to cover bullet as well
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// HTMLLIAccessible: public
|
|
|
|
|
|
|
|
void
|
|
|
|
HTMLLIAccessible::UpdateBullet(bool aHasBullet)
|
|
|
|
{
|
|
|
|
if (aHasBullet == !!mBullet) {
|
|
|
|
NS_NOTREACHED("Bullet and accessible are in sync already!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-05-27 02:01:40 -07:00
|
|
|
DocAccessible* document = Document();
|
2012-05-07 22:16:40 -07:00
|
|
|
if (aHasBullet) {
|
|
|
|
mBullet = new HTMLListBulletAccessible(mContent, mDoc);
|
2013-09-06 12:27:07 -07:00
|
|
|
document->BindToDocument(mBullet, nullptr);
|
|
|
|
InsertChildAt(0, mBullet);
|
2012-05-07 22:16:40 -07:00
|
|
|
} else {
|
|
|
|
RemoveChild(mBullet);
|
|
|
|
document->UnbindFromDocument(mBullet);
|
2012-07-30 07:20:58 -07:00
|
|
|
mBullet = nullptr;
|
2012-05-07 22:16:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// XXXtodo: fire show/hide and reorder events. That's hard to make it
|
|
|
|
// right now because coalescence happens by DOM node.
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-05-28 18:18:45 -07:00
|
|
|
// HTMLLIAccessible: Accessible protected
|
2012-05-07 22:16:40 -07:00
|
|
|
|
|
|
|
void
|
|
|
|
HTMLLIAccessible::CacheChildren()
|
|
|
|
{
|
|
|
|
if (mBullet)
|
|
|
|
AppendChild(mBullet);
|
|
|
|
|
|
|
|
// Cache children from subtree.
|
2012-05-28 18:18:45 -07:00
|
|
|
AccessibleWrap::CacheChildren();
|
2012-05-07 22:16:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// HTMLListBulletAccessible
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-09-03 23:06:10 -07:00
|
|
|
HTMLListBulletAccessible::
|
|
|
|
HTMLListBulletAccessible(nsIContent* aContent, DocAccessible* aDoc) :
|
|
|
|
LeafAccessible(aContent, aDoc)
|
|
|
|
{
|
2012-12-10 19:31:42 -08:00
|
|
|
mStateFlags |= eSharedNode;
|
2012-09-03 23:06:10 -07:00
|
|
|
}
|
2012-05-07 22:16:40 -07:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2013-10-28 20:30:55 -07:00
|
|
|
// HTMLListBulletAccessible: Accessible
|
2012-05-07 22:16:40 -07:00
|
|
|
|
2012-05-13 21:51:45 -07:00
|
|
|
nsIFrame*
|
|
|
|
HTMLListBulletAccessible::GetFrame() const
|
|
|
|
{
|
|
|
|
nsBlockFrame* blockFrame = do_QueryFrame(mContent->GetPrimaryFrame());
|
2012-07-30 07:20:58 -07:00
|
|
|
return blockFrame ? blockFrame->GetBullet() : nullptr;
|
2012-05-13 21:51:45 -07:00
|
|
|
}
|
|
|
|
|
2012-05-07 22:16:40 -07:00
|
|
|
ENameValueFlag
|
|
|
|
HTMLListBulletAccessible::Name(nsString &aName)
|
|
|
|
{
|
|
|
|
aName.Truncate();
|
|
|
|
|
|
|
|
// Native anonymous content, ARIA can't be used. Get list bullet text.
|
|
|
|
nsBlockFrame* blockFrame = do_QueryFrame(mContent->GetPrimaryFrame());
|
|
|
|
if (blockFrame) {
|
2014-06-11 18:12:00 -07:00
|
|
|
blockFrame->GetSpokenBulletText(aName);
|
2012-05-07 22:16:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return eNameOK;
|
|
|
|
}
|
|
|
|
|
|
|
|
role
|
|
|
|
HTMLListBulletAccessible::NativeRole()
|
|
|
|
{
|
|
|
|
return roles::STATICTEXT;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint64_t
|
2012-05-07 22:16:40 -07:00
|
|
|
HTMLListBulletAccessible::NativeState()
|
|
|
|
{
|
2012-06-04 05:32:29 -07:00
|
|
|
return LeafAccessible::NativeState() | states::READONLY;
|
2012-05-07 22:16:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-08-22 08:56:38 -07:00
|
|
|
HTMLListBulletAccessible::AppendTextTo(nsAString& aText, uint32_t aStartOffset,
|
|
|
|
uint32_t aLength)
|
2012-05-07 22:16:40 -07:00
|
|
|
{
|
|
|
|
nsAutoString bulletText;
|
|
|
|
nsBlockFrame* blockFrame = do_QueryFrame(mContent->GetPrimaryFrame());
|
|
|
|
if (blockFrame)
|
2014-06-11 18:12:00 -07:00
|
|
|
blockFrame->GetSpokenBulletText(bulletText);
|
2012-05-07 22:16:40 -07:00
|
|
|
|
|
|
|
aText.Append(Substring(bulletText, aStartOffset, aLength));
|
|
|
|
}
|
2012-05-13 21:51:45 -07:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// HTMLListBulletAccessible: public
|
|
|
|
|
|
|
|
bool
|
|
|
|
HTMLListBulletAccessible::IsInside() const
|
|
|
|
{
|
|
|
|
nsBlockFrame* blockFrame = do_QueryFrame(mContent->GetPrimaryFrame());
|
|
|
|
return blockFrame ? blockFrame->HasInsideBullet() : false;
|
|
|
|
}
|