2012-05-08 09:16:40 +04: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 13:01:40 +04:00
|
|
|
#include "DocAccessible.h"
|
2013-12-10 16:40:54 +04:00
|
|
|
#include "nsAccUtils.h"
|
2012-05-08 09:16:40 +04:00
|
|
|
#include "Role.h"
|
|
|
|
#include "States.h"
|
|
|
|
|
|
|
|
#include "nsBlockFrame.h"
|
2012-05-14 08:51:45 +04:00
|
|
|
#include "nsBulletFrame.h"
|
2012-05-08 09:16:40 +04:00
|
|
|
|
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::a11y;
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// HTMLListAccessible
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2012-05-31 12:04:41 +04:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED0(HTMLListAccessible, HyperTextAccessible)
|
2012-05-08 09:16:40 +04:00
|
|
|
|
|
|
|
role
|
|
|
|
HTMLListAccessible::NativeRole()
|
|
|
|
{
|
2015-03-05 21:16:12 +03:00
|
|
|
a11y::role r = GetAccService()->MarkupRole(mContent);
|
|
|
|
return r != roles::NOTHING ? r : roles::LIST;
|
2012-05-08 09:16:40 +04:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint64_t
|
2012-05-08 09:16:40 +04:00
|
|
|
HTMLListAccessible::NativeState()
|
|
|
|
{
|
2012-05-31 12:04:41 +04:00
|
|
|
return HyperTextAccessibleWrap::NativeState() | states::READONLY;
|
2012-05-08 09:16:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// HTMLLIAccessible
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
HTMLLIAccessible::
|
2012-05-27 13:01:40 +04:00
|
|
|
HTMLLIAccessible(nsIContent* aContent, DocAccessible* aDoc) :
|
2012-07-30 18:20:58 +04:00
|
|
|
HyperTextAccessibleWrap(aContent, aDoc), mBullet(nullptr)
|
2012-05-08 09:16:40 +04:00
|
|
|
{
|
2012-12-18 09:22:26 +04:00
|
|
|
mType = eHTMLLiType;
|
2012-05-08 09:16:40 +04:00
|
|
|
|
|
|
|
nsBlockFrame* blockFrame = do_QueryFrame(GetFrame());
|
|
|
|
if (blockFrame && blockFrame->HasBullet()) {
|
|
|
|
mBullet = new HTMLListBulletAccessible(mContent, mDoc);
|
2013-09-06 23:27:07 +04:00
|
|
|
Document()->BindToDocument(mBullet, nullptr);
|
2016-04-01 18:07:57 +03:00
|
|
|
AppendChild(mBullet);
|
2012-05-08 09:16:40 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-31 12:04:41 +04:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED0(HTMLLIAccessible, HyperTextAccessible)
|
2012-05-08 09:16:40 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
HTMLLIAccessible::Shutdown()
|
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
mBullet = nullptr;
|
2012-05-08 09:16:40 +04:00
|
|
|
|
2012-05-31 12:04:41 +04:00
|
|
|
HyperTextAccessibleWrap::Shutdown();
|
2012-05-08 09:16:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
role
|
|
|
|
HTMLLIAccessible::NativeRole()
|
|
|
|
{
|
2015-03-05 21:16:12 +03:00
|
|
|
a11y::role r = GetAccService()->MarkupRole(mContent);
|
|
|
|
return r != roles::NOTHING ? r : roles::LISTITEM;
|
2012-05-08 09:16:40 +04:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint64_t
|
2012-05-08 09:16:40 +04:00
|
|
|
HTMLLIAccessible::NativeState()
|
|
|
|
{
|
2012-05-31 12:04:41 +04:00
|
|
|
return HyperTextAccessibleWrap::NativeState() | states::READONLY;
|
2012-05-08 09:16:40 +04:00
|
|
|
}
|
|
|
|
|
2014-09-16 21:30:23 +04:00
|
|
|
nsIntRect
|
|
|
|
HTMLLIAccessible::Bounds() const
|
2012-05-08 09:16:40 +04:00
|
|
|
{
|
2014-09-16 21:30:23 +04:00
|
|
|
nsIntRect rect = AccessibleWrap::Bounds();
|
|
|
|
if (rect.IsEmpty() || !mBullet || mBullet->IsInside())
|
|
|
|
return rect;
|
2012-05-08 09:16:40 +04:00
|
|
|
|
2014-09-16 21:30:23 +04:00
|
|
|
nsIntRect bulletRect = mBullet->Bounds();
|
2012-05-08 09:16:40 +04:00
|
|
|
|
2018-01-12 20:07:29 +03:00
|
|
|
// Move x coordinate of list item over to cover bullet as well
|
|
|
|
rect.SetLeftEdge(bulletRect.X());
|
2014-09-16 21:30:23 +04:00
|
|
|
return rect;
|
2012-05-08 09:16:40 +04:00
|
|
|
}
|
|
|
|
|
2016-05-31 21:46:31 +03:00
|
|
|
bool
|
|
|
|
HTMLLIAccessible::InsertChildAt(uint32_t aIndex, Accessible* aChild)
|
|
|
|
{
|
|
|
|
// Adjust index if there's a bullet.
|
|
|
|
if (mBullet && aIndex == 0 && aChild != mBullet) {
|
|
|
|
return HyperTextAccessible::InsertChildAt(aIndex + 1, aChild);
|
|
|
|
}
|
|
|
|
|
|
|
|
return HyperTextAccessible::InsertChildAt(aIndex, aChild);
|
|
|
|
}
|
|
|
|
|
2012-05-08 09:16:40 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// HTMLLIAccessible: public
|
|
|
|
|
|
|
|
void
|
|
|
|
HTMLLIAccessible::UpdateBullet(bool aHasBullet)
|
|
|
|
{
|
|
|
|
if (aHasBullet == !!mBullet) {
|
|
|
|
NS_NOTREACHED("Bullet and accessible are in sync already!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-04-07 16:30:22 +03:00
|
|
|
TreeMutation mt(this);
|
2012-05-08 09:16:40 +04:00
|
|
|
if (aHasBullet) {
|
|
|
|
mBullet = new HTMLListBulletAccessible(mContent, mDoc);
|
2016-04-07 16:30:22 +03:00
|
|
|
mDoc->BindToDocument(mBullet, nullptr);
|
2013-09-06 23:27:07 +04:00
|
|
|
InsertChildAt(0, mBullet);
|
2016-04-01 17:53:52 +03:00
|
|
|
mt.AfterInsertion(mBullet);
|
2016-04-07 16:30:22 +03:00
|
|
|
}
|
|
|
|
else {
|
2016-04-01 17:53:52 +03:00
|
|
|
mt.BeforeRemoval(mBullet);
|
2012-05-08 09:16:40 +04:00
|
|
|
RemoveChild(mBullet);
|
2012-07-30 18:20:58 +04:00
|
|
|
mBullet = nullptr;
|
2012-05-08 09:16:40 +04:00
|
|
|
}
|
2016-04-01 17:53:52 +03:00
|
|
|
mt.Done();
|
2012-05-08 09:16:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// HTMLListBulletAccessible
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-09-04 10:06:10 +04:00
|
|
|
HTMLListBulletAccessible::
|
|
|
|
HTMLListBulletAccessible(nsIContent* aContent, DocAccessible* aDoc) :
|
|
|
|
LeafAccessible(aContent, aDoc)
|
|
|
|
{
|
2016-04-08 15:35:11 +03:00
|
|
|
mGenericTypes |= eText;
|
2012-12-11 07:31:42 +04:00
|
|
|
mStateFlags |= eSharedNode;
|
2012-09-04 10:06:10 +04:00
|
|
|
}
|
2012-05-08 09:16:40 +04:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2013-10-29 07:30:55 +04:00
|
|
|
// HTMLListBulletAccessible: Accessible
|
2012-05-08 09:16:40 +04:00
|
|
|
|
2012-05-14 08:51:45 +04:00
|
|
|
nsIFrame*
|
|
|
|
HTMLListBulletAccessible::GetFrame() const
|
|
|
|
{
|
|
|
|
nsBlockFrame* blockFrame = do_QueryFrame(mContent->GetPrimaryFrame());
|
2012-07-30 18:20:58 +04:00
|
|
|
return blockFrame ? blockFrame->GetBullet() : nullptr;
|
2012-05-14 08:51:45 +04:00
|
|
|
}
|
|
|
|
|
2012-05-08 09:16:40 +04: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-12 05:12:00 +04:00
|
|
|
blockFrame->GetSpokenBulletText(aName);
|
2012-05-08 09:16:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return eNameOK;
|
|
|
|
}
|
|
|
|
|
|
|
|
role
|
|
|
|
HTMLListBulletAccessible::NativeRole()
|
|
|
|
{
|
|
|
|
return roles::STATICTEXT;
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint64_t
|
2012-05-08 09:16:40 +04:00
|
|
|
HTMLListBulletAccessible::NativeState()
|
|
|
|
{
|
2012-06-04 16:32:29 +04:00
|
|
|
return LeafAccessible::NativeState() | states::READONLY;
|
2012-05-08 09:16:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-08-22 19:56:38 +04:00
|
|
|
HTMLListBulletAccessible::AppendTextTo(nsAString& aText, uint32_t aStartOffset,
|
|
|
|
uint32_t aLength)
|
2012-05-08 09:16:40 +04:00
|
|
|
{
|
|
|
|
nsAutoString bulletText;
|
|
|
|
nsBlockFrame* blockFrame = do_QueryFrame(mContent->GetPrimaryFrame());
|
|
|
|
if (blockFrame)
|
2014-06-12 05:12:00 +04:00
|
|
|
blockFrame->GetSpokenBulletText(bulletText);
|
2012-05-08 09:16:40 +04:00
|
|
|
|
|
|
|
aText.Append(Substring(bulletText, aStartOffset, aLength));
|
|
|
|
}
|
2012-05-14 08:51:45 +04:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// HTMLListBulletAccessible: public
|
|
|
|
|
|
|
|
bool
|
|
|
|
HTMLListBulletAccessible::IsInside() const
|
|
|
|
{
|
|
|
|
nsBlockFrame* blockFrame = do_QueryFrame(mContent->GetPrimaryFrame());
|
|
|
|
return blockFrame ? blockFrame->HasInsideBullet() : false;
|
|
|
|
}
|