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()
|
|
|
|
{
|
2015-03-05 10:16:12 -08:00
|
|
|
a11y::role r = GetAccService()->MarkupRole(mContent);
|
|
|
|
return r != roles::NOTHING ? r : roles::LIST;
|
2012-05-07 22:16:40 -07:00
|
|
|
}
|
|
|
|
|
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()
|
|
|
|
{
|
2015-03-05 10:16:12 -08:00
|
|
|
a11y::role r = GetAccService()->MarkupRole(mContent);
|
|
|
|
return r != roles::NOTHING ? r : roles::LISTITEM;
|
2012-05-07 22:16:40 -07:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-09-16 10:30:23 -07:00
|
|
|
nsIntRect
|
|
|
|
HTMLLIAccessible::Bounds() const
|
2012-05-07 22:16:40 -07:00
|
|
|
{
|
2014-09-16 10:30:23 -07:00
|
|
|
nsIntRect rect = AccessibleWrap::Bounds();
|
|
|
|
if (rect.IsEmpty() || !mBullet || mBullet->IsInside())
|
|
|
|
return rect;
|
2012-05-07 22:16:40 -07:00
|
|
|
|
2014-09-16 10:30:23 -07:00
|
|
|
nsIntRect bulletRect = mBullet->Bounds();
|
2012-05-07 22:16:40 -07:00
|
|
|
|
2014-09-16 10:30:23 -07:00
|
|
|
rect.width += rect.x - bulletRect.x;
|
|
|
|
rect.x = bulletRect.x; // Move x coordinate of list item over to cover bullet as well
|
|
|
|
return rect;
|
2012-05-07 22:16:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// HTMLLIAccessible: public
|
|
|
|
|
|
|
|
void
|
|
|
|
HTMLLIAccessible::UpdateBullet(bool aHasBullet)
|
|
|
|
{
|
|
|
|
if (aHasBullet == !!mBullet) {
|
|
|
|
NS_NOTREACHED("Bullet and accessible are in sync already!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-07-14 08:10:30 -07:00
|
|
|
nsRefPtr<AccReorderEvent> reorderEvent = new AccReorderEvent(this);
|
|
|
|
AutoTreeMutation mut(this);
|
|
|
|
|
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);
|
2015-07-14 08:10:30 -07:00
|
|
|
|
|
|
|
nsRefPtr<AccShowEvent> event = new AccShowEvent(mBullet, mBullet->GetContent());
|
|
|
|
mDoc->FireDelayedEvent(event);
|
|
|
|
reorderEvent->AddSubMutationEvent(event);
|
2012-05-07 22:16:40 -07:00
|
|
|
} else {
|
2015-07-14 08:10:30 -07:00
|
|
|
nsRefPtr<AccHideEvent> event = new AccHideEvent(mBullet, mBullet->GetContent());
|
|
|
|
mDoc->FireDelayedEvent(event);
|
|
|
|
reorderEvent->AddSubMutationEvent(event);
|
|
|
|
|
2012-05-07 22:16:40 -07:00
|
|
|
RemoveChild(mBullet);
|
2012-07-30 07:20:58 -07:00
|
|
|
mBullet = nullptr;
|
2012-05-07 22:16:40 -07:00
|
|
|
}
|
|
|
|
|
2015-07-14 08:10:30 -07:00
|
|
|
mDoc->FireDelayedEvent(reorderEvent);
|
2012-05-07 22:16:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
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;
|
|
|
|
}
|