Bug 745428 - densify nsTextAccessible, r=surkov, f=tbsaunde

--HG--
rename : accessible/src/atk/nsTextAccessibleWrap.h => accessible/src/atk/TextLeafAccessibleWrap.h
rename : accessible/src/base/nsTextAccessible.cpp => accessible/src/generic/TextLeafAccessible.cpp
rename : accessible/src/base/nsTextAccessible.h => accessible/src/generic/TextLeafAccessible.h
rename : accessible/src/mac/nsTextAccessibleWrap.h => accessible/src/mac/TextLeafAccessibleWrap.h
rename : accessible/src/msaa/nsTextAccessibleWrap.cpp => accessible/src/msaa/TextLeafAccessibleWrap.cpp
rename : accessible/src/msaa/nsTextAccessibleWrap.h => accessible/src/msaa/TextLeafAccessibleWrap.h
rename : accessible/src/other/nsTextAccessibleWrap.h => accessible/src/other/TextLeafAccessibleWrap.h
This commit is contained in:
Mark Capella 2012-05-23 14:05:57 -04:00
parent 42cdef250d
commit 0c51655fe0
21 changed files with 183 additions and 166 deletions

View File

@ -4,11 +4,17 @@
* 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 _nsTextAccessibleWrap_H_
#define _nsTextAccessibleWrap_H_
#ifndef mozilla_a11y_TextLeafAccessibleWrap_h__
#define mozilla_a11y_TextLeafAccessibleWrap_h__
#include "nsTextAccessible.h"
#include "TextLeafAccessible.h"
typedef class nsTextAccessible nsTextAccessibleWrap;
namespace mozilla {
namespace a11y {
typedef class TextLeafAccessible TextLeafAccessibleWrap;
} // namespace a11y
} // namespace mozilla
#endif

View File

@ -36,7 +36,6 @@ CPPSRCS = \
nsBaseWidgetAccessible.cpp \
nsEventShell.cpp \
nsCaretAccessible.cpp \
nsTextAccessible.cpp \
nsTextEquivUtils.cpp \
RoleAsserts.cpp \
StyleInfo.cpp \

View File

@ -11,9 +11,9 @@
#include "nsCoreUtils.h"
#include "nsDocAccessible.h"
#include "nsEventShell.h"
#include "nsTextAccessible.h"
#include "FocusManager.h"
#include "Role.h"
#include "TextLeafAccessible.h"
#include "TextUpdater.h"
#include "mozilla/dom/Element.h"

View File

@ -7,10 +7,12 @@
#include "Accessible-inl.h"
#include "nsDocAccessible.h"
#include "nsTextAccessible.h"
#include "TextLeafAccessible.h"
using namespace mozilla::a11y;
void
TextUpdater::Run(nsDocAccessible* aDocument, nsTextAccessible* aTextLeaf,
TextUpdater::Run(nsDocAccessible* aDocument, TextLeafAccessible* aTextLeaf,
const nsAString& aNewText)
{
NS_ASSERTION(aTextLeaf, "No text leaf accessible?");

View File

@ -19,11 +19,13 @@ public:
/**
* Start text of the text leaf update.
*/
static void Run(nsDocAccessible* aDocument, nsTextAccessible* aTextLeaf,
static void Run(nsDocAccessible* aDocument,
mozilla::a11y::TextLeafAccessible* aTextLeaf,
const nsAString& aNewText);
private:
TextUpdater(nsDocAccessible* aDocument, nsTextAccessible* aTextLeaf) :
TextUpdater(nsDocAccessible* aDocument,
mozilla::a11y::TextLeafAccessible* aTextLeaf) :
mDocument(aDocument), mTextLeaf(aTextLeaf), mHyperText(nsnull),
mTextOffset(-1) { }
@ -82,7 +84,7 @@ private:
private:
nsDocAccessible* mDocument;
nsTextAccessible* mTextLeaf;
mozilla::a11y::TextLeafAccessible* mTextLeaf;
nsHyperTextAccessible* mHyperText;
PRInt32 mTextOffset;
};

View File

@ -12,9 +12,9 @@
#include "nsDocAccessible.h"
#include "nsHyperTextAccessible.h"
#include "nsIAccessibleTypes.h"
#include "nsTextAccessible.h"
#include "Role.h"
#include "States.h"
#include "TextLeafAccessible.h"
#include "nsIDOMXULContainerElement.h"
#include "nsIDOMXULSelectCntrlEl.h"
@ -447,7 +447,7 @@ nsAccUtils::TextLength(nsAccessible *aAccessible)
if (!IsText(aAccessible))
return 1;
nsTextAccessible* textLeaf = aAccessible->AsTextLeaf();
TextLeafAccessible* textLeaf = aAccessible->AsTextLeaf();
if (textLeaf)
return textLeaf->Text().Length();

View File

@ -35,6 +35,7 @@
#ifdef XP_WIN
#include "nsHTMLWin32ObjectAccessible.h"
#endif
#include "TextLeafAccessible.h"
#ifdef DEBUG
#include "Logging.h"
@ -409,11 +410,11 @@ nsAccessibilityService::CreateHTMLTableRowAccessible(nsIContent* aContent,
}
already_AddRefed<nsAccessible>
nsAccessibilityService::CreateHTMLTextAccessible(nsIContent* aContent,
nsAccessibilityService::CreateTextLeafAccessible(nsIContent* aContent,
nsIPresShell* aPresShell)
{
nsAccessible* accessible =
new nsHTMLTextAccessible(aContent, GetDocAccessible(aPresShell));
new TextLeafAccessible(aContent, GetDocAccessible(aPresShell));
NS_ADDREF(accessible);
return accessible;
}

View File

@ -101,7 +101,7 @@ public:
already_AddRefed<nsAccessible>
CreateHTMLTableRowAccessible(nsIContent* aContent, nsIPresShell* aPresShell);
already_AddRefed<nsAccessible>
CreateHTMLTextAccessible(nsIContent* aContent, nsIPresShell* aPresShell);
CreateTextLeafAccessible(nsIContent* aContent, nsIPresShell* aPresShell);
already_AddRefed<nsAccessible>
CreateHTMLTextFieldAccessible(nsIContent* aContent, nsIPresShell* aPresShell);
already_AddRefed<nsAccessible>

View File

@ -37,6 +37,7 @@ namespace a11y {
class HTMLLIAccessible;
class TableAccessible;
class TextLeafAccessible;
/**
* Name type flags.
@ -54,7 +55,7 @@ enum ENameValueFlag {
}
}
class nsTextAccessible;
class nsXULTreeAccessible;
struct nsRect;
@ -482,7 +483,7 @@ public:
virtual mozilla::a11y::TableAccessible* AsTable() { return nsnull; }
inline bool IsTextLeaf() const { return mFlags & eTextLeafAccessible; }
nsTextAccessible* AsTextLeaf();
mozilla::a11y::TextLeafAccessible* AsTextLeaf();
//////////////////////////////////////////////////////////////////////////////
// ActionAccessible

View File

@ -1,40 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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 "nsTextAccessible.h"
#include "Role.h"
using namespace mozilla::a11y;
////////////////////////////////////////////////////////////////////////////////
// nsTextAccessible
////////////////////////////////////////////////////////////////////////////////
nsTextAccessible::
nsTextAccessible(nsIContent* aContent, nsDocAccessible* aDoc) :
nsLinkableAccessible(aContent, aDoc)
{
mFlags |= eTextLeafAccessible;
}
role
nsTextAccessible::NativeRole()
{
return roles::TEXT_LEAF;
}
void
nsTextAccessible::AppendTextTo(nsAString& aText, PRUint32 aStartOffset,
PRUint32 aLength)
{
aText.Append(Substring(mText, aStartOffset, aLength));
}
void
nsTextAccessible::CacheChildren()
{
// No children for text accessible.
}

View File

@ -20,6 +20,7 @@ CPPSRCS = \
FormControlAccessible.cpp \
OuterDocAccessible.cpp \
RootAccessible.cpp \
TextLeafAccessible.cpp \
$(NULL)
# we don't want the shared lib, but we want to force the creation of a static lib.

View File

@ -0,0 +1,70 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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 "TextLeafAccessible.h"
#include "nsAccUtils.h"
#include "nsDocAccessible.h"
#include "Role.h"
using namespace mozilla::a11y;
////////////////////////////////////////////////////////////////////////////////
// TextLeafAccessible
////////////////////////////////////////////////////////////////////////////////
TextLeafAccessible::
TextLeafAccessible(nsIContent* aContent, nsDocAccessible* aDoc) :
nsLinkableAccessible(aContent, aDoc)
{
mFlags |= eTextLeafAccessible;
}
TextLeafAccessible::~TextLeafAccessible()
{
}
role
TextLeafAccessible::NativeRole()
{
nsIFrame* frame = GetFrame();
if (frame && frame->IsGeneratedContentFrame())
return roles::STATICTEXT;
return roles::TEXT_LEAF;
}
void
TextLeafAccessible::AppendTextTo(nsAString& aText, PRUint32 aStartOffset,
PRUint32 aLength)
{
aText.Append(Substring(mText, aStartOffset, aLength));
}
ENameValueFlag
TextLeafAccessible::Name(nsString& aName)
{
// Text node, ARIA can't be used.
aName = mText;
return eNameOK;
}
nsresult
TextLeafAccessible::GetAttributesInternal(nsIPersistentProperties *aAttributes)
{
if (NativeRole() == roles::STATICTEXT) {
nsAutoString oldValueUnused;
aAttributes->SetStringProperty(NS_LITERAL_CSTRING("auto-generated"),
NS_LITERAL_STRING("true"), oldValueUnused);
}
return NS_OK;
}
void
TextLeafAccessible::CacheChildren()
{
// No children for text accessible.
}

View File

@ -3,25 +3,31 @@
* 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 _nsTextAccessible_H_
#define _nsTextAccessible_H_
#ifndef mozilla_a11y_TextLeafAccessible_h__
#define mozilla_a11y_TextLeafAccessible_h__
#include "nsBaseWidgetAccessible.h"
namespace mozilla {
namespace a11y {
/**
* Generic class used for text nodes.
*/
class nsTextAccessible : public nsLinkableAccessible
class TextLeafAccessible : public nsLinkableAccessible
{
public:
nsTextAccessible(nsIContent* aContent, nsDocAccessible* aDoc);
TextLeafAccessible(nsIContent* aContent, nsDocAccessible* aDoc);
virtual ~TextLeafAccessible();
// nsAccessible
virtual mozilla::a11y::role NativeRole();
virtual void AppendTextTo(nsAString& aText, PRUint32 aStartOffset = 0,
PRUint32 aLength = PR_UINT32_MAX);
virtual ENameValueFlag Name(nsString& aName);
virtual nsresult GetAttributesInternal(nsIPersistentProperties* aAttributes);
// nsTextAccessible
// TextLeafAccessible
void SetText(const nsAString& aText) { mText = aText; }
const nsString& Text() const { return mText; }
@ -33,15 +39,17 @@ protected:
nsString mText;
};
} // namespace a11y
} // namespace mozilla
////////////////////////////////////////////////////////////////////////////////
// nsAccessible downcast method
inline nsTextAccessible*
inline mozilla::a11y::TextLeafAccessible*
nsAccessible::AsTextLeaf()
{
return mFlags & eTextLeafAccessible ?
static_cast<nsTextAccessible*>(this) : nsnull;
static_cast<mozilla::a11y::TextLeafAccessible*>(this) : nsnull;
}
#endif

View File

@ -15,51 +15,6 @@
using namespace mozilla::a11y;
////////////////////////////////////////////////////////////////////////////////
// nsHTMLTextAccessible
////////////////////////////////////////////////////////////////////////////////
nsHTMLTextAccessible::
nsHTMLTextAccessible(nsIContent* aContent, nsDocAccessible* aDoc) :
nsTextAccessibleWrap(aContent, aDoc)
{
}
NS_IMPL_ISUPPORTS_INHERITED0(nsHTMLTextAccessible, nsTextAccessible)
ENameValueFlag
nsHTMLTextAccessible::Name(nsString& aName)
{
// Text node, ARIA can't be used.
aName = mText;
return eNameOK;
}
role
nsHTMLTextAccessible::NativeRole()
{
nsIFrame *frame = GetFrame();
// Don't return on null frame -- we still return a role
// after accessible is shutdown/DEFUNCT
if (frame && frame->IsGeneratedContentFrame())
return roles::STATICTEXT;
return nsTextAccessible::NativeRole();
}
nsresult
nsHTMLTextAccessible::GetAttributesInternal(nsIPersistentProperties *aAttributes)
{
if (NativeRole() == roles::STATICTEXT) {
nsAutoString oldValueUnused;
aAttributes->SetStringProperty(NS_LITERAL_CSTRING("auto-generated"),
NS_LITERAL_STRING("true"), oldValueUnused);
}
return NS_OK;
}
////////////////////////////////////////////////////////////////////////////////
// nsHTMLHRAccessible
////////////////////////////////////////////////////////////////////////////////

View File

@ -6,27 +6,9 @@
#ifndef _nsHTMLTextAccessible_H_
#define _nsHTMLTextAccessible_H_
#include "nsTextAccessibleWrap.h"
#include "nsAutoPtr.h"
#include "nsBaseWidgetAccessible.h"
/**
* Used for text nodes within HTML document.
*/
class nsHTMLTextAccessible : public nsTextAccessibleWrap
{
public:
nsHTMLTextAccessible(nsIContent* aContent, nsDocAccessible* aDoc);
// nsISupports
NS_DECL_ISUPPORTS_INHERITED
// nsAccessible
virtual mozilla::a11y::ENameValueFlag Name(nsString& aName);
virtual nsresult GetAttributesInternal(nsIPersistentProperties *aAttributes);
virtual mozilla::a11y::role NativeRole();
};
/**
* Used for HTML hr element.
*/

View File

@ -3,11 +3,17 @@
* 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 _nsTextAccessibleWrap_H_
#define _nsTextAccessibleWrap_H_
#ifndef mozilla_a11y_TextLeafAccessibleWrap_h__
#define mozilla_a11y_TextLeafAccessibleWrap_h__
#include "nsTextAccessible.h"
#include "TextLeafAccessible.h"
typedef class nsTextAccessible nsTextAccessibleWrap;
namespace mozilla {
namespace a11y {
typedef class TextLeafAccessible TextLeafAccessibleWrap;
} // namespace a11y
} // namespace mozilla
#endif

View File

@ -20,7 +20,6 @@ CPPSRCS = \
ARIAGridAccessibleWrap.cpp \
nsAccessNodeWrap.cpp \
nsAccessibleWrap.cpp \
nsTextAccessibleWrap.cpp \
nsDocAccessibleWrap.cpp \
nsHTMLWin32ObjectAccessible.cpp \
nsXULMenuAccessibleWrap.cpp \
@ -43,6 +42,7 @@ CPPSRCS = \
CAccessibleValue.cpp \
Compatibility.cpp \
RootAccessibleWrap.cpp \
TextLeafAccessibleWrap.cpp \
$(NULL)
EXPORTS = \

View File

@ -3,7 +3,7 @@
* 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 "nsTextAccessibleWrap.h"
#include "TextLeafAccessibleWrap.h"
#include "ISimpleDOMText_i.c"
#include "nsCoreUtils.h"
@ -19,26 +19,29 @@
using namespace mozilla::a11y;
////////////////////////////////////////////////////////////////////////////////
// nsTextAccessibleWrap Accessible
// TextLeafAccessibleWrap
////////////////////////////////////////////////////////////////////////////////
nsTextAccessibleWrap::
nsTextAccessibleWrap(nsIContent* aContent, nsDocAccessible* aDoc) :
nsTextAccessible(aContent, aDoc)
TextLeafAccessibleWrap::
TextLeafAccessibleWrap(nsIContent* aContent, nsDocAccessible* aDoc) :
TextLeafAccessible(aContent, aDoc)
{
}
STDMETHODIMP_(ULONG) nsTextAccessibleWrap::AddRef()
STDMETHODIMP_(ULONG)
TextLeafAccessibleWrap::AddRef()
{
return nsAccessNode::AddRef();
}
STDMETHODIMP_(ULONG) nsTextAccessibleWrap::Release()
STDMETHODIMP_(ULONG)
TextLeafAccessibleWrap::Release()
{
return nsAccessNode::Release();
}
STDMETHODIMP nsTextAccessibleWrap::QueryInterface(REFIID iid, void** ppv)
STDMETHODIMP
TextLeafAccessibleWrap::QueryInterface(REFIID iid, void** ppv)
{
*ppv = nsnull;
@ -55,7 +58,8 @@ STDMETHODIMP nsTextAccessibleWrap::QueryInterface(REFIID iid, void** ppv)
return S_OK;
}
STDMETHODIMP nsTextAccessibleWrap::get_domText(
STDMETHODIMP
TextLeafAccessibleWrap::get_domText(
/* [retval][out] */ BSTR __RPC_FAR *aDomText)
{
__try {
@ -80,7 +84,8 @@ __try {
return S_OK;
}
STDMETHODIMP nsTextAccessibleWrap::get_clippedSubstringBounds(
STDMETHODIMP
TextLeafAccessibleWrap::get_clippedSubstringBounds(
/* [in] */ unsigned int aStartIndex,
/* [in] */ unsigned int aEndIndex,
/* [out] */ int __RPC_FAR *aX,
@ -117,7 +122,8 @@ __try {
return S_OK;
}
STDMETHODIMP nsTextAccessibleWrap::get_unclippedSubstringBounds(
STDMETHODIMP
TextLeafAccessibleWrap::get_unclippedSubstringBounds(
/* [in] */ unsigned int aStartIndex,
/* [in] */ unsigned int aEndIndex,
/* [out] */ int __RPC_FAR *aX,
@ -140,8 +146,8 @@ __try {
return S_OK;
}
STDMETHODIMP nsTextAccessibleWrap::scrollToSubstring(
STDMETHODIMP
TextLeafAccessibleWrap::scrollToSubstring(
/* [in] */ unsigned int aStartIndex,
/* [in] */ unsigned int aEndIndex)
{
@ -160,10 +166,11 @@ __try {
return S_OK;
}
nsIFrame* nsTextAccessibleWrap::GetPointFromOffset(nsIFrame *aContainingFrame,
PRInt32 aOffset,
bool aPreferNext,
nsPoint& aOutPoint)
nsIFrame*
TextLeafAccessibleWrap::GetPointFromOffset(nsIFrame* aContainingFrame,
PRInt32 aOffset,
bool aPreferNext,
nsPoint& aOutPoint)
{
nsIFrame *textFrame = nsnull;
PRInt32 outOffset;
@ -179,9 +186,13 @@ nsIFrame* nsTextAccessibleWrap::GetPointFromOffset(nsIFrame *aContainingFrame,
/*
* Given an offset, the x, y, width, and height values are filled appropriately.
*/
nsresult nsTextAccessibleWrap::GetCharacterExtents(PRInt32 aStartOffset, PRInt32 aEndOffset,
PRInt32* aX, PRInt32* aY,
PRInt32* aWidth, PRInt32* aHeight)
nsresult
TextLeafAccessibleWrap::GetCharacterExtents(PRInt32 aStartOffset,
PRInt32 aEndOffset,
PRInt32* aX,
PRInt32* aY,
PRInt32* aWidth,
PRInt32* aHeight)
{
*aX = *aY = *aWidth = *aHeight = 0;
@ -221,7 +232,8 @@ nsresult nsTextAccessibleWrap::GetCharacterExtents(PRInt32 aStartOffset, PRInt32
return NS_OK;
}
STDMETHODIMP nsTextAccessibleWrap::get_fontFamily(
STDMETHODIMP
TextLeafAccessibleWrap::get_fontFamily(
/* [retval][out] */ BSTR __RPC_FAR *aFontFamily)
{
__try {

View File

@ -3,22 +3,25 @@
* 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 _nsTextAccessibleWrap_H_
#define _nsTextAccessibleWrap_H_
#ifndef mozilla_a11y_TextLeafAccessibleWrap_h__
#define mozilla_a11y_TextLeafAccessibleWrap_h__
#include "nsTextAccessible.h"
#include "TextLeafAccessible.h"
#include "ISimpleDOMText.h"
#include "nsRect.h"
class nsIFrame;
class nsRenderingContext;
class nsTextAccessibleWrap : public nsTextAccessible,
public ISimpleDOMText
namespace mozilla {
namespace a11y {
class TextLeafAccessibleWrap : public TextLeafAccessible,
public ISimpleDOMText
{
public:
nsTextAccessibleWrap(nsIContent* aContent, nsDocAccessible* aDoc);
virtual ~nsTextAccessibleWrap() {}
TextLeafAccessibleWrap(nsIContent* aContent, nsDocAccessible* aDoc);
virtual ~TextLeafAccessibleWrap() {}
// IUnknown methods - see iunknown.h for documentation
STDMETHODIMP_(ULONG) AddRef();
@ -61,5 +64,8 @@ public:
PRInt32 aOffset, bool aPreferNext, nsPoint& aOutPoint);
};
} // namespace a11y
} // namespace mozilla
#endif

View File

@ -3,11 +3,17 @@
* 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 _nsTextAccessibleWrap_H_
#define _nsTextAccessibleWrap_H_
#ifndef mozilla_a11y_TextLeafAccessibleWrap_h__
#define mozilla_a11y_TextLeafAccessibleWrap_h__
#include "nsTextAccessible.h"
#include "TextLeafAccessible.h"
typedef class nsTextAccessible nsTextAccessibleWrap;
namespace mozilla {
namespace a11y {
typedef class TextLeafAccessible TextLeafAccessibleWrap;
} // namespace a11y
} // namespace mozilla
#endif

View File

@ -3754,7 +3754,7 @@ nsTextFrame::CreateAccessible()
nsAccessibilityService* accService = nsIPresShell::AccService();
if (accService) {
return accService->CreateHTMLTextAccessible(mContent,
return accService->CreateTextLeafAccessible(mContent,
PresContext()->PresShell());
}
return nsnull;