Bug 751828 - densify nsHTMLListAccessible, r=tbsaunde

--HG--
rename : accessible/src/html/nsHTMLTextAccessible.cpp => accessible/src/html/HTMLListAccessible.cpp
rename : accessible/src/html/nsHTMLTextAccessible.h => accessible/src/html/HTMLListAccessible.h
This commit is contained in:
Alexander Surkov 2012-05-08 14:16:40 +09:00
parent 22886df192
commit 5789cb848e
7 changed files with 315 additions and 283 deletions

View File

@ -46,6 +46,7 @@
#include "AtkSocketAccessible.h"
#endif
#include "FocusManager.h"
#include "HTMLListAccessible.h"
#include "nsAccessiblePivot.h"
#include "nsAccUtils.h"
#include "nsARIAMap.h"
@ -222,7 +223,7 @@ nsAccessibilityService::CreateHTMLLIAccessible(nsIContent* aContent,
nsIPresShell* aPresShell)
{
nsAccessible* accessible =
new nsHTMLLIAccessible(aContent, GetDocAccessible(aPresShell));
new HTMLLIAccessible(aContent, GetDocAccessible(aPresShell));
NS_ADDREF(accessible);
return accessible;
}
@ -599,7 +600,7 @@ nsAccessibilityService::UpdateListBullet(nsIPresShell* aPresShell,
if (document) {
nsAccessible* accessible = document->GetAccessible(aHTMLListItemContent);
if (accessible) {
nsHTMLLIAccessible* listItem = accessible->AsHTMLListItem();
HTMLLIAccessible* listItem = accessible->AsHTMLListItem();
if (listItem)
listItem->UpdateBullet(aHasBullet);
}
@ -1658,7 +1659,7 @@ nsAccessibilityService::CreateHTMLAccessibleByMarkup(nsIFrame* aFrame,
if (tag == nsGkAtoms::ul || tag == nsGkAtoms::ol ||
tag == nsGkAtoms::dl) {
nsAccessible* accessible = new nsHTMLListAccessible(aContent, aDoc);
nsAccessible* accessible = new HTMLListAccessible(aContent, aDoc);
NS_IF_ADDREF(accessible);
return accessible;
}
@ -1685,7 +1686,7 @@ nsAccessibilityService::CreateHTMLAccessibleByMarkup(nsIFrame* aFrame,
// Normally for li, it is created by the list item frame (in nsBlockFrame)
// which knows about the bullet frame; however, in this case the list item
// must have been styled using display: foo
nsAccessible* accessible = new nsHTMLLIAccessible(aContent, aDoc);
nsAccessible* accessible = new HTMLLIAccessible(aContent, aDoc);
NS_IF_ADDREF(accessible);
return accessible;
}

View File

@ -62,12 +62,13 @@ class nsAccessible;
class nsHyperTextAccessible;
class nsHTMLImageAccessible;
class nsHTMLImageMapAccessible;
class nsHTMLLIAccessible;
struct nsRoleMapEntry;
class Relation;
namespace mozilla {
namespace a11y {
class HTMLLIAccessible;
class TableAccessible;
/**
@ -476,7 +477,7 @@ public:
inline bool IsHTMLFileInput() const { return mFlags & eHTMLFileInputAccessible; }
inline bool IsHTMLListItem() const { return mFlags & eHTMLListItemAccessible; }
nsHTMLLIAccessible* AsHTMLListItem();
mozilla::a11y::HTMLLIAccessible* AsHTMLListItem();
inline bool IsImageAccessible() const { return mFlags & eImageAccessible; }
nsHTMLImageAccessible* AsImage();

View File

@ -0,0 +1,201 @@
/* -*- 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"
#include "nsDocAccessible.h"
#include "Role.h"
#include "States.h"
#include "nsBlockFrame.h"
using namespace mozilla;
using namespace mozilla::a11y;
////////////////////////////////////////////////////////////////////////////////
// HTMLListAccessible
////////////////////////////////////////////////////////////////////////////////
NS_IMPL_ISUPPORTS_INHERITED0(HTMLListAccessible, nsHyperTextAccessible)
role
HTMLListAccessible::NativeRole()
{
if (mContent->Tag() == nsGkAtoms::dl)
return roles::DEFINITION_LIST;
return roles::LIST;
}
PRUint64
HTMLListAccessible::NativeState()
{
return nsHyperTextAccessibleWrap::NativeState() | states::READONLY;
}
////////////////////////////////////////////////////////////////////////////////
// HTMLLIAccessible
////////////////////////////////////////////////////////////////////////////////
HTMLLIAccessible::
HTMLLIAccessible(nsIContent* aContent, nsDocAccessible* aDoc) :
nsHyperTextAccessibleWrap(aContent, aDoc), mBullet(nsnull)
{
mFlags |= eHTMLListItemAccessible;
nsBlockFrame* blockFrame = do_QueryFrame(GetFrame());
if (blockFrame && blockFrame->HasBullet()) {
mBullet = new HTMLListBulletAccessible(mContent, mDoc);
if (!Document()->BindToDocument(mBullet, nsnull))
mBullet = nsnull;
}
}
NS_IMPL_ISUPPORTS_INHERITED0(HTMLLIAccessible, nsHyperTextAccessible)
void
HTMLLIAccessible::Shutdown()
{
mBullet = nsnull;
nsHyperTextAccessibleWrap::Shutdown();
}
role
HTMLLIAccessible::NativeRole()
{
if (mContent->Tag() == nsGkAtoms::dt)
return roles::TERM;
return roles::LISTITEM;
}
PRUint64
HTMLLIAccessible::NativeState()
{
return nsHyperTextAccessibleWrap::NativeState() | states::READONLY;
}
NS_IMETHODIMP
HTMLLIAccessible::GetBounds(PRInt32* aX, PRInt32* aY,
PRInt32* aWidth, PRInt32* aHeight)
{
nsresult rv = nsAccessibleWrap::GetBounds(aX, aY, aWidth, aHeight);
if (NS_FAILED(rv) || !mBullet)
return rv;
PRInt32 bulletX = 0, bulletY = 0, bulletWidth = 0, bulletHeight = 0;
rv = mBullet->GetBounds(&bulletX, &bulletY, &bulletWidth, &bulletHeight);
NS_ENSURE_SUCCESS(rv, rv);
*aX = bulletX; // Move x coordinate of list item over to cover bullet as well
*aWidth += bulletWidth;
return NS_OK;
}
////////////////////////////////////////////////////////////////////////////////
// HTMLLIAccessible: public
void
HTMLLIAccessible::UpdateBullet(bool aHasBullet)
{
if (aHasBullet == !!mBullet) {
NS_NOTREACHED("Bullet and accessible are in sync already!");
return;
}
nsDocAccessible* document = Document();
if (aHasBullet) {
mBullet = new HTMLListBulletAccessible(mContent, mDoc);
if (document->BindToDocument(mBullet, nsnull)) {
InsertChildAt(0, mBullet);
}
} else {
RemoveChild(mBullet);
document->UnbindFromDocument(mBullet);
mBullet = nsnull;
}
// XXXtodo: fire show/hide and reorder events. That's hard to make it
// right now because coalescence happens by DOM node.
}
////////////////////////////////////////////////////////////////////////////////
// HTMLLIAccessible: nsAccessible protected
void
HTMLLIAccessible::CacheChildren()
{
if (mBullet)
AppendChild(mBullet);
// Cache children from subtree.
nsAccessibleWrap::CacheChildren();
}
////////////////////////////////////////////////////////////////////////////////
// HTMLListBulletAccessible
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// HTMLListBulletAccessible: nsAccessNode
bool
HTMLListBulletAccessible::IsPrimaryForNode() const
{
return false;
}
////////////////////////////////////////////////////////////////////////////////
// HTMLListBulletAccessible: nsAccessible
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());
NS_ASSERTION(blockFrame, "No frame for list item!");
if (blockFrame) {
blockFrame->GetBulletText(aName);
// Append space otherwise bullets are jammed up against list text.
aName.Append(' ');
}
return eNameOK;
}
role
HTMLListBulletAccessible::NativeRole()
{
return roles::STATICTEXT;
}
PRUint64
HTMLListBulletAccessible::NativeState()
{
PRUint64 state = nsLeafAccessible::NativeState();
state &= ~states::FOCUSABLE;
state |= states::READONLY;
return state;
}
void
HTMLListBulletAccessible::AppendTextTo(nsAString& aText, PRUint32 aStartOffset,
PRUint32 aLength)
{
nsAutoString bulletText;
nsBlockFrame* blockFrame = do_QueryFrame(mContent->GetPrimaryFrame());
NS_ASSERTION(blockFrame, "No frame for list item!");
if (blockFrame)
blockFrame->GetBulletText(bulletText);
aText.Append(Substring(bulletText, aStartOffset, aLength));
}

View File

@ -0,0 +1,104 @@
/* -*- 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/. */
#ifndef mozilla_a11y_HTMLListAccessible_h__
#define mozilla_a11y_HTMLListAccessible_h__
#include "nsHyperTextAccessibleWrap.h"
#include "nsBaseWidgetAccessible.h"
namespace mozilla {
namespace a11y {
class HTMLListBulletAccessible;
/**
* Used for HTML list (like HTML ul).
*/
class HTMLListAccessible : public nsHyperTextAccessibleWrap
{
public:
HTMLListAccessible(nsIContent* aContent, nsDocAccessible* aDoc) :
nsHyperTextAccessibleWrap(aContent, aDoc) { }
virtual ~HTMLListAccessible() { }
// nsISupports
NS_DECL_ISUPPORTS_INHERITED
// nsAccessible
virtual a11y::role NativeRole();
virtual PRUint64 NativeState();
};
/**
* Used for HTML list item (e.g. HTML li).
*/
class HTMLLIAccessible : public nsHyperTextAccessibleWrap
{
public:
HTMLLIAccessible(nsIContent* aContent, nsDocAccessible* aDoc);
virtual ~HTMLLIAccessible() { }
// nsISupports
NS_DECL_ISUPPORTS_INHERITED
// nsAccessNode
virtual void Shutdown();
// nsIAccessible
NS_IMETHOD GetBounds(PRInt32* aX, PRInt32* aY,
PRInt32* aWidth, PRInt32* aHeight);
// nsAccessible
virtual a11y::role NativeRole();
virtual PRUint64 NativeState();
// nsHTMLLIAccessible
void UpdateBullet(bool aHasBullet);
protected:
// nsAccessible
virtual void CacheChildren();
private:
nsRefPtr<HTMLListBulletAccessible> mBullet;
};
/**
* Used for bullet of HTML list item element (for example, HTML li).
*/
class HTMLListBulletAccessible : public nsLeafAccessible
{
public:
HTMLListBulletAccessible(nsIContent* aContent, nsDocAccessible* aDoc) :
nsLeafAccessible(aContent, aDoc) { }
virtual ~HTMLListBulletAccessible() { }
// nsAccessNode
virtual bool IsPrimaryForNode() const;
// nsAccessible
virtual ENameValueFlag Name(nsString& aName);
virtual a11y::role NativeRole();
virtual PRUint64 NativeState();
virtual void AppendTextTo(nsAString& aText, PRUint32 aStartOffset = 0,
PRUint32 aLength = PR_UINT32_MAX);
};
} // namespace a11y
} // namespace mozilla
inline mozilla::a11y::HTMLLIAccessible*
nsAccessible::AsHTMLListItem()
{
return mFlags & eHTMLListItemAccessible ?
static_cast<mozilla::a11y::HTMLLIAccessible*>(this) : nsnull;
}
#endif

View File

@ -52,6 +52,7 @@ LIBXUL_LIBRARY = 1
CPPSRCS = \
nsHTMLCanvasAccessible.cpp \
HTMLFormControlAccessible.cpp \
HTMLListAccessible.cpp \
nsHTMLImageAccessible.cpp \
nsHTMLImageMapAccessible.cpp \
nsHTMLLinkAccessible.cpp \

View File

@ -41,19 +41,12 @@
#include "nsDocAccessible.h"
#include "nsAccUtils.h"
#include "nsIAccessibleRelation.h"
#include "nsTextEquivUtils.h"
#include "Relation.h"
#include "Role.h"
#include "States.h"
#include "nsIAccessibleRelation.h"
#include "nsIFrame.h"
#include "nsPresContext.h"
#include "nsBlockFrame.h"
#include "nsISelection.h"
#include "nsISelectionController.h"
#include "nsComponentManagerUtils.h"
using namespace mozilla::a11y;
////////////////////////////////////////////////////////////////////////////////
@ -227,198 +220,3 @@ nsHTMLOutputAccessible::GetAttributesInternal(nsIPersistentProperties* aAttribut
return NS_OK;
}
////////////////////////////////////////////////////////////////////////////////
// nsHTMLLIAccessible
////////////////////////////////////////////////////////////////////////////////
nsHTMLLIAccessible::
nsHTMLLIAccessible(nsIContent* aContent, nsDocAccessible* aDoc) :
nsHyperTextAccessibleWrap(aContent, aDoc), mBullet(nsnull)
{
mFlags |= eHTMLListItemAccessible;
nsBlockFrame* blockFrame = do_QueryFrame(GetFrame());
if (blockFrame && blockFrame->HasBullet()) {
mBullet = new nsHTMLListBulletAccessible(mContent, mDoc);
if (!Document()->BindToDocument(mBullet, nsnull))
mBullet = nsnull;
}
}
NS_IMPL_ISUPPORTS_INHERITED0(nsHTMLLIAccessible, nsHyperTextAccessible)
void
nsHTMLLIAccessible::Shutdown()
{
mBullet = nsnull;
nsHyperTextAccessibleWrap::Shutdown();
}
role
nsHTMLLIAccessible::NativeRole()
{
if (mContent->Tag() == nsGkAtoms::dt)
return roles::TERM;
return roles::LISTITEM;
}
PRUint64
nsHTMLLIAccessible::NativeState()
{
return nsHyperTextAccessibleWrap::NativeState() | states::READONLY;
}
NS_IMETHODIMP nsHTMLLIAccessible::GetBounds(PRInt32 *x, PRInt32 *y, PRInt32 *width, PRInt32 *height)
{
nsresult rv = nsAccessibleWrap::GetBounds(x, y, width, height);
if (NS_FAILED(rv) || !mBullet)
return rv;
PRInt32 bulletX, bulletY, bulletWidth, bulletHeight;
rv = mBullet->GetBounds(&bulletX, &bulletY, &bulletWidth, &bulletHeight);
NS_ENSURE_SUCCESS(rv, rv);
*x = bulletX; // Move x coordinate of list item over to cover bullet as well
*width += bulletWidth;
return NS_OK;
}
////////////////////////////////////////////////////////////////////////////////
// nsHTMLLIAccessible: public
void
nsHTMLLIAccessible::UpdateBullet(bool aHasBullet)
{
if (aHasBullet == !!mBullet) {
NS_NOTREACHED("Bullet and accessible are in sync already!");
return;
}
nsDocAccessible* document = Document();
if (aHasBullet) {
mBullet = new nsHTMLListBulletAccessible(mContent, mDoc);
if (document->BindToDocument(mBullet, nsnull)) {
InsertChildAt(0, mBullet);
}
} else {
RemoveChild(mBullet);
document->UnbindFromDocument(mBullet);
mBullet = nsnull;
}
// XXXtodo: fire show/hide and reorder events. That's hard to make it
// right now because coalescence happens by DOM node.
}
////////////////////////////////////////////////////////////////////////////////
// nsHTMLLIAccessible: nsAccessible protected
void
nsHTMLLIAccessible::CacheChildren()
{
if (mBullet)
AppendChild(mBullet);
// Cache children from subtree.
nsAccessibleWrap::CacheChildren();
}
////////////////////////////////////////////////////////////////////////////////
// nsHTMLListBulletAccessible
////////////////////////////////////////////////////////////////////////////////
nsHTMLListBulletAccessible::
nsHTMLListBulletAccessible(nsIContent* aContent, nsDocAccessible* aDoc) :
nsLeafAccessible(aContent, aDoc)
{
}
////////////////////////////////////////////////////////////////////////////////
// nsHTMLListBulletAccessible: nsAccessNode
bool
nsHTMLListBulletAccessible::IsPrimaryForNode() const
{
return false;
}
////////////////////////////////////////////////////////////////////////////////
// nsHTMLListBulletAccessible: nsAccessible
ENameValueFlag
nsHTMLListBulletAccessible::Name(nsString &aName)
{
aName.Truncate();
// Native anonymous content, ARIA can't be used. Get list bullet text.
nsBlockFrame* blockFrame = do_QueryFrame(mContent->GetPrimaryFrame());
NS_ASSERTION(blockFrame, "No frame for list item!");
if (blockFrame) {
blockFrame->GetBulletText(aName);
// Append space otherwise bullets are jammed up against list text.
aName.Append(' ');
}
return eNameOK;
}
role
nsHTMLListBulletAccessible::NativeRole()
{
return roles::STATICTEXT;
}
PRUint64
nsHTMLListBulletAccessible::NativeState()
{
PRUint64 state = nsLeafAccessible::NativeState();
state &= ~states::FOCUSABLE;
state |= states::READONLY;
return state;
}
void
nsHTMLListBulletAccessible::AppendTextTo(nsAString& aText, PRUint32 aStartOffset,
PRUint32 aLength)
{
nsAutoString bulletText;
nsBlockFrame* blockFrame = do_QueryFrame(mContent->GetPrimaryFrame());
NS_ASSERTION(blockFrame, "No frame for list item!");
if (blockFrame)
blockFrame->GetBulletText(bulletText);
aText.Append(Substring(bulletText, aStartOffset, aLength));
}
////////////////////////////////////////////////////////////////////////////////
// nsHTMLListAccessible
////////////////////////////////////////////////////////////////////////////////
nsHTMLListAccessible::
nsHTMLListAccessible(nsIContent* aContent, nsDocAccessible* aDoc) :
nsHyperTextAccessibleWrap(aContent, aDoc)
{
}
NS_IMPL_ISUPPORTS_INHERITED0(nsHTMLListAccessible, nsHyperTextAccessible)
role
nsHTMLListAccessible::NativeRole()
{
if (mContent->Tag() == nsGkAtoms::dl)
return roles::DEFINITION_LIST;
return roles::LIST;
}
PRUint64
nsHTMLListAccessible::NativeState()
{
return nsHyperTextAccessibleWrap::NativeState() | states::READONLY;
}

View File

@ -119,78 +119,4 @@ public:
virtual Relation RelationByType(PRUint32 aType);
};
/**
* Used for bullet of HTML list item element (for example, HTML li).
*/
class nsHTMLListBulletAccessible : public nsLeafAccessible
{
public:
nsHTMLListBulletAccessible(nsIContent* aContent, nsDocAccessible* aDoc);
// nsAccessNode
virtual bool IsPrimaryForNode() const;
// nsAccessible
virtual mozilla::a11y::ENameValueFlag Name(nsString& aName);
virtual mozilla::a11y::role NativeRole();
virtual PRUint64 NativeState();
virtual void AppendTextTo(nsAString& aText, PRUint32 aStartOffset = 0,
PRUint32 aLength = PR_UINT32_MAX);
};
/**
* Used for HTML list (like HTML ul).
*/
class nsHTMLListAccessible : public nsHyperTextAccessibleWrap
{
public:
nsHTMLListAccessible(nsIContent* aContent, nsDocAccessible* aDoc);
// nsISupports
NS_DECL_ISUPPORTS_INHERITED
// nsAccessible
virtual mozilla::a11y::role NativeRole();
virtual PRUint64 NativeState();
};
/**
* Used for HTML list item (e.g. HTML li).
*/
class nsHTMLLIAccessible : public nsHyperTextAccessibleWrap
{
public:
nsHTMLLIAccessible(nsIContent* aContent, nsDocAccessible* aDoc);
// nsISupports
NS_DECL_ISUPPORTS_INHERITED
// nsAccessNode
virtual void Shutdown();
// nsIAccessible
NS_IMETHOD GetBounds(PRInt32 *x, PRInt32 *y, PRInt32 *width, PRInt32 *height);
// nsAccessible
virtual mozilla::a11y::role NativeRole();
virtual PRUint64 NativeState();
// nsHTMLLIAccessible
void UpdateBullet(bool aHasBullet);
protected:
// nsAccessible
virtual void CacheChildren();
private:
nsRefPtr<nsHTMLListBulletAccessible> mBullet;
};
inline nsHTMLLIAccessible*
nsAccessible::AsHTMLListItem()
{
return mFlags & eHTMLListItemAccessible ?
static_cast<nsHTMLLIAccessible*>(this) : nsnull;
}
#endif