Bug 934039 - isolate XPCOM text interfaces implementation, r=tbsaunde

This commit is contained in:
Alexander Surkov 2013-11-18 08:19:33 -05:00
parent 4b74788f31
commit 5a56c15068
20 changed files with 1242 additions and 969 deletions

View File

@ -6,24 +6,9 @@
#include "nsISupports.idl"
interface nsIEditor;
[scriptable, uuid(e242d495-5cde-4b1c-8c84-2525b14939f5)]
[scriptable, uuid(93d0ba57-0d20-49d1-aede-8fde6699855d)]
interface nsIAccessibleEditableText : nsISupports
{
/**
* Sets the attributes for the text between the two given indices. The old
* attributes are replaced by the new list of attributes. For example,
* sets font styles, such as italic, bold...
*
* @param startPos - start index of the text whose attributes are modified.
* @param endPos - end index of the text whose attributes are modified.
* @param attributes - set of attributes that replaces the old list of
* attributes of the specified text portion.
*/
void setAttributes (in long startPos, in long endPos,
in nsISupports attributes);
/**
* Replaces the text represented by this object by the given text.
*/
@ -35,7 +20,8 @@ interface nsIAccessibleEditableText : nsISupports
* @param text - text that is inserted.
* @param position - index at which to insert the text.
*/
void insertText (in AString text, in long position);
[binaryname(ScriptableInsertText)]
void insertText(in AString text, in long position);
/**
* Copies the text range into the clipboard.
@ -43,7 +29,8 @@ interface nsIAccessibleEditableText : nsISupports
* @param startPos - start index of the text to moved into the clipboard.
* @param endPos - end index of the text to moved into the clipboard.
*/
void copyText (in long startPos, in long endPos);
[binaryname(ScriptableCopyText)]
void copyText(in long startPos, in long endPos);
/**
* Deletes a range of text and copies it to the clipboard.
@ -51,7 +38,8 @@ interface nsIAccessibleEditableText : nsISupports
* @param startPos - start index of the text to be deleted.
* @param endOffset - end index of the text to be deleted.
*/
void cutText (in long startPos, in long endPos);
[binaryname(ScriptableCutText)]
void cutText(in long startPos, in long endPos);
/**
* Deletes a range of text.
@ -59,7 +47,8 @@ interface nsIAccessibleEditableText : nsISupports
* @param startPos - start index of the text to be deleted.
* @param endPos - end index of the text to be deleted.
*/
void deleteText (in long startPos, in long endPos);
[binaryname(ScriptableDeleteText)]
void deleteText(in long startPos, in long endPos);
/**
* Pastes text from the clipboard.
@ -67,5 +56,6 @@ interface nsIAccessibleEditableText : nsISupports
* @param position - index at which to insert the text from the system
* clipboard into the text represented by this object.
*/
void pasteText (in long position);
[binaryname(ScriptablePasteText)]
void pasteText(in long position);
};

View File

@ -11,7 +11,7 @@ typedef long AccessibleTextBoundary;
interface nsIAccessible;
interface nsIPersistentProperties;
[scriptable, uuid(43d81eb0-1215-4dc4-9226-a4355bd2d20d)]
[scriptable, uuid(1e63dd8b-173d-4a68-8ade-fd671abbe1ee)]
interface nsIAccessibleText : nsISupports
{
// In parameters for character offsets:
@ -32,6 +32,7 @@ interface nsIAccessibleText : nsISupports
* The current current caret offset.
* If set < 0 then caret will be placed at the end of the text
*/
[binaryname(ScriptableCaretOffset)]
attribute long caretOffset;
readonly attribute long characterCount;
@ -168,6 +169,7 @@ interface nsIAccessibleText : nsISupports
* @param scrollType defines how to scroll (see nsIAccessibleScrollType for
* available constants)
*/
[binaryname(ScriptableScrollSubstringTo)]
void scrollSubstringTo(in long startIndex, in long endIndex,
in unsigned long scrollType);
@ -183,6 +185,7 @@ interface nsIAccessibleText : nsISupports
* @param x defines the x coordinate
* @param y defines the y coordinate
*/
[binaryname(ScriptableScrollSubstringToPoint)]
void scrollSubstringToPoint(in long startIndex, in long endIndex,
in unsigned long coordinateType,
in long x, in long y);

View File

@ -7,7 +7,7 @@
#include "InterfaceInitFuncs.h"
#include "Accessible-inl.h"
#include "HyperTextAccessible.h"
#include "HyperTextAccessible-inl.h"
#include "nsMai.h"
#include "nsString.h"
@ -28,7 +28,7 @@ setTextContentsCB(AtkEditableText *aText, const gchar *aString)
return;
NS_ConvertUTF8toUTF16 strContent(aString);
text->SetTextContents(strContent);
text->ReplaceText(strContent);
}
static void

View File

@ -26,7 +26,7 @@ getLinkCB(AtkHypertext *aText, gint aLinkIndex)
HyperTextAccessible* hyperText = accWrap->AsHyperText();
NS_ENSURE_TRUE(hyperText, nullptr);
Accessible* hyperLink = hyperText->GetLinkAt(aLinkIndex);
Accessible* hyperLink = hyperText->LinkAt(aLinkIndex);
if (!hyperLink)
return nullptr;
@ -49,7 +49,7 @@ getLinkCountCB(AtkHypertext *aText)
HyperTextAccessible* hyperText = accWrap->AsHyperText();
NS_ENSURE_TRUE(hyperText, -1);
return hyperText->GetLinkCount();
return hyperText->LinkCount();
}
static gint
@ -62,11 +62,7 @@ getLinkIndexCB(AtkHypertext *aText, gint aCharIndex)
HyperTextAccessible* hyperText = accWrap->AsHyperText();
NS_ENSURE_TRUE(hyperText, -1);
int32_t index = -1;
nsresult rv = hyperText->GetLinkIndexAtOffset(aCharIndex, &index);
NS_ENSURE_SUCCESS(rv, -1);
return index;
return hyperText->LinkIndexAtOffset(aCharIndex);
}
}

View File

@ -7,7 +7,7 @@
#include "InterfaceInitFuncs.h"
#include "Accessible-inl.h"
#include "HyperTextAccessible.h"
#include "HyperTextAccessible-inl.h"
#include "nsMai.h"
#include "nsIAccessibleTypes.h"
@ -43,8 +43,7 @@ getTextCB(AtkText *aText, gint aStartOffset, gint aEndOffset)
return nullptr;
nsAutoString autoStr;
nsresult rv = text->GetText(aStartOffset, aEndOffset, autoStr);
NS_ENSURE_SUCCESS(rv, nullptr);
text->TextSubstring(aStartOffset, aEndOffset, autoStr);
ConvertTexttoAsterisks(accWrap, autoStr);
NS_ConvertUTF16toUTF8 cautoStr(autoStr);
@ -68,18 +67,14 @@ getTextAfterOffsetCB(AtkText *aText, gint aOffset,
nsAutoString autoStr;
int32_t startOffset = 0, endOffset = 0;
nsresult rv =
text->GetTextAfterOffset(aOffset, aBoundaryType,
&startOffset, &endOffset, autoStr);
text->TextAfterOffset(aOffset, aBoundaryType, &startOffset, &endOffset, autoStr);
*aStartOffset = startOffset;
*aEndOffset = endOffset;
NS_ENSURE_SUCCESS(rv, nullptr);
ConvertTexttoAsterisks(accWrap, autoStr);
NS_ConvertUTF16toUTF8 cautoStr(autoStr);
return (cautoStr.get()) ? g_strdup(cautoStr.get()) : nullptr;
ConvertTexttoAsterisks(accWrap, autoStr);
NS_ConvertUTF16toUTF8 cautoStr(autoStr);
return (cautoStr.get()) ? g_strdup(cautoStr.get()) : nullptr;
}
static gchar*
@ -97,14 +92,10 @@ getTextAtOffsetCB(AtkText *aText, gint aOffset,
nsAutoString autoStr;
int32_t startOffset = 0, endOffset = 0;
nsresult rv =
text->GetTextAtOffset(aOffset, aBoundaryType,
&startOffset, &endOffset, autoStr);
text->TextAtOffset(aOffset, aBoundaryType, &startOffset, &endOffset, autoStr);
*aStartOffset = startOffset;
*aEndOffset = endOffset;
NS_ENSURE_SUCCESS(rv, nullptr);
ConvertTexttoAsterisks(accWrap, autoStr);
NS_ConvertUTF16toUTF8 cautoStr(autoStr);
return (cautoStr.get()) ? g_strdup(cautoStr.get()) : nullptr;
@ -148,19 +139,16 @@ getTextBeforeOffsetCB(AtkText *aText, gint aOffset,
if (!text || !text->IsTextRole())
return nullptr;
nsAutoString autoStr;
int32_t startOffset = 0, endOffset = 0;
nsresult rv =
text->GetTextBeforeOffset(aOffset, aBoundaryType,
&startOffset, &endOffset, autoStr);
*aStartOffset = startOffset;
*aEndOffset = endOffset;
nsAutoString autoStr;
int32_t startOffset = 0, endOffset = 0;
text->TextBeforeOffset(aOffset, aBoundaryType,
&startOffset, &endOffset, autoStr);
*aStartOffset = startOffset;
*aEndOffset = endOffset;
NS_ENSURE_SUCCESS(rv, nullptr);
ConvertTexttoAsterisks(accWrap, autoStr);
NS_ConvertUTF16toUTF8 cautoStr(autoStr);
return (cautoStr.get()) ? g_strdup(cautoStr.get()) : nullptr;
ConvertTexttoAsterisks(accWrap, autoStr);
NS_ConvertUTF16toUTF8 cautoStr(autoStr);
return (cautoStr.get()) ? g_strdup(cautoStr.get()) : nullptr;
}
static gint
@ -174,9 +162,7 @@ getCaretOffsetCB(AtkText *aText)
if (!text || !text->IsTextRole())
return 0;
int32_t offset;
nsresult rv = text->GetCaretOffset(&offset);
return (NS_FAILED(rv)) ? 0 : static_cast<gint>(offset);
return static_cast<gint>(text->CaretOffset());
}
static AtkAttributeSet*
@ -195,17 +181,14 @@ getRunAttributesCB(AtkText *aText, gint aOffset,
if (!text || !text->IsTextRole())
return nullptr;
nsCOMPtr<nsIPersistentProperties> attributes;
int32_t startOffset = 0, endOffset = 0;
nsresult rv = text->GetTextAttributes(false, aOffset,
&startOffset, &endOffset,
getter_AddRefs(attributes));
NS_ENSURE_SUCCESS(rv, nullptr);
int32_t startOffset = 0, endOffset = 0;
nsCOMPtr<nsIPersistentProperties> attributes =
text->TextAttributes(false, aOffset, &startOffset, &endOffset);
*aStartOffset = startOffset;
*aEndOffset = endOffset;
*aStartOffset = startOffset;
*aEndOffset = endOffset;
return ConvertToAtkAttributeSet(attributes);
return ConvertToAtkAttributeSet(attributes);
}
static AtkAttributeSet*
@ -219,12 +202,8 @@ getDefaultAttributesCB(AtkText *aText)
if (!text || !text->IsTextRole())
return nullptr;
nsCOMPtr<nsIPersistentProperties> attributes;
nsresult rv = text->GetDefaultTextAttributes(getter_AddRefs(attributes));
if (NS_FAILED(rv))
return nullptr;
return ConvertToAtkAttributeSet(attributes);
nsCOMPtr<nsIPersistentProperties> attributes = text->DefaultTextAttributes();
return ConvertToAtkAttributeSet(attributes);
}
static void
@ -241,27 +220,17 @@ getCharacterExtentsCB(AtkText *aText, gint aOffset,
if (!text || !text->IsTextRole())
return;
int32_t extY = 0, extX = 0;
int32_t extWidth = 0, extHeight = 0;
uint32_t geckoCoordType;
if (aCoords == ATK_XY_SCREEN)
geckoCoordType = nsIAccessibleCoordinateType::COORDTYPE_SCREEN_RELATIVE;
else
geckoCoordType = nsIAccessibleCoordinateType::COORDTYPE_WINDOW_RELATIVE;
#ifdef DEBUG
nsresult rv =
#endif
text->GetCharacterExtents(aOffset, &extX, &extY,
&extWidth, &extHeight,
geckoCoordType);
*aX = extX;
*aY = extY;
*aWidth = extWidth;
*aHeight = extHeight;
NS_ASSERTION(NS_SUCCEEDED(rv),
"MaiInterfaceText::GetCharacterExtents, failed\n");
nsIntRect rect = text->CharBounds(aOffset, geckoCoordType);
*aX = rect.x;
*aY = rect.y;
*aWidth = rect.width;
*aHeight = rect.height;
}
static void
@ -276,28 +245,17 @@ getRangeExtentsCB(AtkText *aText, gint aStartOffset, gint aEndOffset,
if (!text || !text->IsTextRole())
return;
int32_t extY = 0, extX = 0;
int32_t extWidth = 0, extHeight = 0;
uint32_t geckoCoordType;
if (aCoords == ATK_XY_SCREEN)
geckoCoordType = nsIAccessibleCoordinateType::COORDTYPE_SCREEN_RELATIVE;
else
geckoCoordType = nsIAccessibleCoordinateType::COORDTYPE_WINDOW_RELATIVE;
#ifdef DEBUG
nsresult rv =
#endif
text->GetRangeExtents(aStartOffset, aEndOffset,
&extX, &extY,
&extWidth, &extHeight,
geckoCoordType);
aRect->x = extX;
aRect->y = extY;
aRect->width = extWidth;
aRect->height = extHeight;
NS_ASSERTION(NS_SUCCEEDED(rv),
"MaiInterfaceText::GetRangeExtents, failed\n");
nsIntRect rect = text->TextBounds(aStartOffset, aEndOffset, geckoCoordType);
aRect->x = rect.x;
aRect->y = rect.y;
aRect->width = rect.width;
aRect->height = rect.height;
}
static gint
@ -325,15 +283,11 @@ getOffsetAtPointCB(AtkText *aText,
if (!text || !text->IsTextRole())
return -1;
int32_t offset = 0;
uint32_t geckoCoordType;
if (aCoords == ATK_XY_SCREEN)
geckoCoordType = nsIAccessibleCoordinateType::COORDTYPE_SCREEN_RELATIVE;
else
geckoCoordType = nsIAccessibleCoordinateType::COORDTYPE_WINDOW_RELATIVE;
text->GetOffsetAtPoint(aX, aY, geckoCoordType, &offset);
return static_cast<gint>(offset);
return static_cast<gint>(
text->OffsetAtPoint(aX, aY,
(aCoords == ATK_XY_SCREEN ?
nsIAccessibleCoordinateType::COORDTYPE_SCREEN_RELATIVE :
nsIAccessibleCoordinateType::COORDTYPE_WINDOW_RELATIVE)));
}
static gint
@ -347,10 +301,7 @@ getTextSelectionCountCB(AtkText *aText)
if (!text || !text->IsTextRole())
return 0;
int32_t selectionCount;
nsresult rv = text->GetSelectionCount(&selectionCount);
return NS_FAILED(rv) ? 0 : selectionCount;
return text->SelectionCount();
}
static gchar*
@ -365,15 +316,12 @@ getTextSelectionCB(AtkText *aText, gint aSelectionNum,
if (!text || !text->IsTextRole())
return nullptr;
int32_t startOffset = 0, endOffset = 0;
nsresult rv = text->GetSelectionBounds(aSelectionNum,
&startOffset, &endOffset);
int32_t startOffset = 0, endOffset = 0;
text->SelectionBoundsAt(aSelectionNum, &startOffset, &endOffset);
*aStartOffset = startOffset;
*aEndOffset = endOffset;
NS_ENSURE_SUCCESS(rv, nullptr);
return getTextCB(aText, *aStartOffset, *aEndOffset);
}
@ -389,11 +337,9 @@ addTextSelectionCB(AtkText *aText,
HyperTextAccessible* text = accWrap->AsHyperText();
if (!text || !text->IsTextRole())
return false;
return FALSE;
nsresult rv = text->AddSelection(aStartOffset, aEndOffset);
return NS_SUCCEEDED(rv) ? TRUE : FALSE;
return text->AddToSelection(aStartOffset, aEndOffset);
}
static gboolean
@ -406,11 +352,9 @@ removeTextSelectionCB(AtkText *aText,
HyperTextAccessible* text = accWrap->AsHyperText();
if (!text || !text->IsTextRole())
return false;
return FALSE;
nsresult rv = text->RemoveSelection(aSelectionNum);
return NS_SUCCEEDED(rv) ? TRUE : FALSE;
return text->RemoveFromSelection(aSelectionNum);
}
static gboolean
@ -423,11 +367,9 @@ setTextSelectionCB(AtkText *aText, gint aSelectionNum,
HyperTextAccessible* text = accWrap->AsHyperText();
if (!text || !text->IsTextRole())
return false;
return FALSE;
nsresult rv = text->SetSelectionBounds(aSelectionNum,
aStartOffset, aEndOffset);
return NS_SUCCEEDED(rv) ? TRUE : FALSE;
return text->SetSelectionBoundsAt(aSelectionNum, aStartOffset, aEndOffset);
}
static gboolean
@ -438,11 +380,11 @@ setCaretOffsetCB(AtkText *aText, gint aOffset)
return FALSE;
HyperTextAccessible* text = accWrap->AsHyperText();
if (!text || !text->IsTextRole())
return false;
if (!text || !text->IsTextRole() || !text->IsValidOffset(aOffset))
return FALSE;
nsresult rv = text->SetCaretOffset(aOffset);
return NS_SUCCEEDED(rv) ? TRUE : FALSE;
text->SetCaretOffset(aOffset);
return TRUE;
}
}

View File

@ -130,8 +130,8 @@ SelectionManager::ProcessTextSelChangeEvent(AccEvent* aEvent)
if (!caretCntr)
return;
int32_t caretOffset = -1;
if (NS_SUCCEEDED(caretCntr->GetCaretOffset(&caretOffset)) && caretOffset != -1) {
int32_t caretOffset = caretCntr->CaretOffset();
if (caretOffset != -1) {
nsRefPtr<AccCaretMoveEvent> caretMoveEvent =
new AccCaretMoveEvent(caretCntr, caretOffset, aEvent->FromUserInput());
nsEventShell::FireEvent(caretMoveEvent);

View File

@ -305,7 +305,7 @@ nsAccessiblePivot::MoveNextByText(TextBoundaryType aBoundary, bool* aResult)
Accessible* root = GetActiveRoot();
while (true) {
Accessible* curPosition = tempPosition;
HyperTextAccessible* text;
HyperTextAccessible* text = nullptr;
// Find the nearest text node using a preorder traversal starting from
// the current node.
if (!(text = tempPosition->AsHyperText())) {
@ -370,9 +370,8 @@ nsAccessiblePivot::MoveNextByText(TextBoundaryType aBoundary, bool* aResult)
nsAutoString unusedText;
int32_t newStart = 0, newEnd = 0, currentEnd = tempEnd;
text->GetTextAtOffset(tempEnd, endBoundary, &newStart, &tempEnd, unusedText);
text->GetTextBeforeOffset(tempEnd, startBoundary, &newStart, &newEnd,
unusedText);
text->TextAtOffset(tempEnd, endBoundary, &newStart, &tempEnd, unusedText);
text->TextBeforeOffset(tempEnd, startBoundary, &newStart, &newEnd, unusedText);
int32_t potentialStart = newEnd == tempEnd ? newStart : newEnd;
tempStart = potentialStart > tempStart ? potentialStart : currentEnd;
@ -494,15 +493,14 @@ nsAccessiblePivot::MovePreviousByText(TextBoundaryType aBoundary, bool* aResult)
nsAutoString unusedText;
int32_t newStart = 0, newEnd = 0, currentStart = tempStart, potentialEnd = 0;
text->GetTextBeforeOffset(tempStart, startBoundary, &newStart, &newEnd,
unusedText);
text->TextBeforeOffset(tempStart, startBoundary, &newStart, &newEnd, unusedText);
if (newStart < tempStart)
tempStart = newEnd >= currentStart ? newStart : newEnd;
else // XXX: In certain odd cases newStart is equal to tempStart
text->GetTextBeforeOffset(tempStart - 1, startBoundary, &newStart,
&tempStart, unusedText);
text->GetTextAtOffset(tempStart, endBoundary, &newStart, &potentialEnd,
unusedText);
text->TextBeforeOffset(tempStart - 1, startBoundary, &newStart,
&tempStart, unusedText);
text->TextAtOffset(tempStart, endBoundary, &newStart, &potentialEnd,
unusedText);
tempEnd = potentialEnd < tempEnd ? potentialEnd : currentStart;
// The offset range we've obtained might have embedded characters in it,

View File

@ -0,0 +1,164 @@
/* -*- 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/. */
#ifndef mozilla_a11y_HyperTextAccessible_inl_h__
#define mozilla_a11y_HyperTextAccessible_inl_h__
#include "HyperTextAccessible.h"
#include "nsAccUtils.h"
#include "nsIClipboard.h"
#include "nsIEditor.h"
#include "nsIPersistentProperties2.h"
#include "nsIPlaintextEditor.h"
namespace mozilla {
namespace a11y {
inline bool
HyperTextAccessible::IsValidOffset(int32_t aOffset)
{
int32_t offset = ConvertMagicOffset(aOffset);
return offset >= 0 && offset <= static_cast<int32_t>(CharacterCount());
}
inline bool
HyperTextAccessible::IsValidRange(int32_t aStartOffset, int32_t aEndOffset)
{
int32_t startOffset = ConvertMagicOffset(aStartOffset);
if (startOffset < 0)
return false;
int32_t endOffset = ConvertMagicOffset(aEndOffset);
if (endOffset < 0 || startOffset > endOffset)
return false;
return endOffset <= static_cast<int32_t>(CharacterCount());
}
inline nsIntRect
HyperTextAccessible::TextBounds(int32_t aStartOffset, int32_t aEndOffset,
uint32_t aCoordType)
{
nsIntRect bounds;
GetPosAndText(aStartOffset, aEndOffset, nullptr, nullptr, &bounds);
nsAccUtils::ConvertScreenCoordsTo(&bounds.x, &bounds.y, aCoordType, this);
return bounds;
}
inline bool
HyperTextAccessible::AddToSelection(int32_t aStartOffset, int32_t aEndOffset)
{
Selection* domSel = DOMSelection();
return domSel &&
SetSelectionBoundsAt(domSel->GetRangeCount(), aStartOffset, aEndOffset);
}
inline void
HyperTextAccessible::ReplaceText(const nsAString& aText)
{
int32_t numChars = CharacterCount();
if (numChars != 0)
DeleteText(0, numChars);
InsertText(aText, 0);
}
inline void
HyperTextAccessible::InsertText(const nsAString& aText, int32_t aPosition)
{
nsCOMPtr<nsIEditor> editor = GetEditor();
nsCOMPtr<nsIPlaintextEditor> peditor(do_QueryInterface(editor));
if (peditor) {
SetSelectionRange(aPosition, aPosition);
peditor->InsertText(aText);
}
}
inline void
HyperTextAccessible::CopyText(int32_t aStartPos, int32_t aEndPos)
{
nsCOMPtr<nsIEditor> editor = GetEditor();
if (editor) {
SetSelectionRange(aStartPos, aEndPos);
editor->Copy();
}
}
inline void
HyperTextAccessible::CutText(int32_t aStartPos, int32_t aEndPos)
{
nsCOMPtr<nsIEditor> editor = GetEditor();
if (editor) {
SetSelectionRange(aStartPos, aEndPos);
editor->Cut();
}
}
inline void
HyperTextAccessible::DeleteText(int32_t aStartPos, int32_t aEndPos)
{
nsCOMPtr<nsIEditor> editor = GetEditor();
if (editor) {
SetSelectionRange(aStartPos, aEndPos);
editor->DeleteSelection(nsIEditor::eNone, nsIEditor::eStrip);
}
}
inline void
HyperTextAccessible::PasteText(int32_t aPosition)
{
nsCOMPtr<nsIEditor> editor = GetEditor();
if (editor) {
SetSelectionRange(aPosition, aPosition);
editor->Paste(nsIClipboard::kGlobalClipboard);
}
}
inline int32_t
HyperTextAccessible::ConvertMagicOffset(int32_t aOffset)
{
if (aOffset == nsIAccessibleText::TEXT_OFFSET_END_OF_TEXT)
return CharacterCount();
if (aOffset == nsIAccessibleText::TEXT_OFFSET_CARET)
return CaretOffset();
return aOffset;
}
inline int32_t
HyperTextAccessible::AdjustCaretOffset(int32_t aOffset) const
{
// It is the same character offset when the caret is visually at the very
// end of a line or the start of a new line (soft line break). Getting text
// at the line should provide the line with the visual caret, otherwise
// screen readers will announce the wrong line as the user presses up or
// down arrow and land at the end of a line.
if (aOffset > 0) {
nsRefPtr<nsFrameSelection> frameSelection = FrameSelection();
if (frameSelection &&
frameSelection->GetHint() == nsFrameSelection::HINTLEFT) {
return aOffset - 1;
}
}
return aOffset;
}
inline Selection*
HyperTextAccessible::DOMSelection() const
{
nsRefPtr<nsFrameSelection> frameSelection = FrameSelection();
return frameSelection ?
frameSelection->GetSelection(nsISelectionController::SELECTION_NORMAL) :
nullptr;
}
} // namespace a11y
} // namespace mozilla
#endif

File diff suppressed because it is too large Load Diff

View File

@ -6,11 +6,9 @@
#ifndef mozilla_a11y_HyperTextAccessible_h__
#define mozilla_a11y_HyperTextAccessible_h__
#include "nsIAccessibleText.h"
#include "nsIAccessibleHyperText.h"
#include "nsIAccessibleEditableText.h"
#include "AccessibleWrap.h"
#include "nsIAccessibleTypes.h"
#include "xpcAccessibleHyperText.h"
#include "nsFrameSelection.h"
#include "nsISelectionController.h"
@ -35,18 +33,13 @@ const PRUnichar kForcedNewLineChar = '\n';
* Special Accessible that knows how contain both text and embedded objects
*/
class HyperTextAccessible : public AccessibleWrap,
public nsIAccessibleText,
public nsIAccessibleHyperText,
public nsIAccessibleEditableText
public xpcAccessibleHyperText
{
public:
HyperTextAccessible(nsIContent* aContent, DocAccessible* aDoc);
virtual ~HyperTextAccessible() { }
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_NSIACCESSIBLETEXT
NS_DECL_NSIACCESSIBLEHYPERTEXT
NS_DECL_NSIACCESSIBLEEDITABLETEXT
// Accessible
virtual int32_t GetLevelInternal();
@ -59,13 +52,13 @@ public:
// HyperTextAccessible (static helper method)
// Convert content offset to rendered text offset
// Convert content offset to rendered text offset
nsresult ContentToRenderedOffset(nsIFrame *aFrame, int32_t aContentOffset,
uint32_t *aRenderedOffset);
uint32_t *aRenderedOffset) const;
// Convert rendered text offset to content offset
nsresult RenderedToContentOffset(nsIFrame *aFrame, uint32_t aRenderedOffset,
int32_t *aContentOffset);
int32_t *aContentOffset) const;
//////////////////////////////////////////////////////////////////////////////
// HyperLinkAccessible
@ -73,15 +66,13 @@ public:
/**
* Return link count within this hypertext accessible.
*/
uint32_t GetLinkCount()
{
return EmbeddedChildCount();
}
uint32_t LinkCount()
{ return EmbeddedChildCount(); }
/**
* Return link accessible at the given index.
*/
Accessible* GetLinkAt(uint32_t aIndex)
Accessible* LinkAt(uint32_t aIndex)
{
return GetEmbeddedChildAt(aIndex);
}
@ -89,7 +80,7 @@ public:
/**
* Return index for the given link accessible.
*/
int32_t GetLinkIndex(Accessible* aLink)
int32_t LinkIndexOf(Accessible* aLink)
{
return GetIndexOfEmbeddedChild(aLink);
}
@ -97,10 +88,10 @@ public:
/**
* Return link accessible at the given text offset.
*/
int32_t GetLinkIndexAtOffset(uint32_t aOffset)
int32_t LinkIndexAtOffset(uint32_t aOffset)
{
Accessible* child = GetChildAtOffset(aOffset);
return child ? GetLinkIndex(child) : -1;
return child ? LinkIndexOf(child) : -1;
}
//////////////////////////////////////////////////////////////////////////////
@ -134,7 +125,7 @@ public:
Accessible* DOMPointToHypertextOffset(nsINode *aNode,
int32_t aNodeOffset,
int32_t* aHypertextOffset,
bool aIsEndOffset = false);
bool aIsEndOffset = false) const;
/**
* Turn a start and end hypertext offsets into DOM range.
@ -208,6 +199,37 @@ public:
bool GetCharAt(int32_t aOffset, EGetTextType aShift, nsAString& aChar,
int32_t* aStartOffset = nullptr, int32_t* aEndOffset = nullptr);
/**
* Return text between given offsets.
*/
void TextSubstring(int32_t aStartOffset, int32_t aEndOffset, nsAString& aText);
/**
* Return text before/at/after the given offset corresponding to
* the boundary type.
*/
void TextBeforeOffset(int32_t aOffset, AccessibleTextBoundary aBoundaryType,
int32_t* aStartOffset, int32_t* aEndOffset,
nsAString& aText);
void TextAtOffset(int32_t aOffset, AccessibleTextBoundary aBoundaryType,
int32_t* aStartOffset, int32_t* aEndOffset,
nsAString& aText);
void TextAfterOffset(int32_t aOffset, AccessibleTextBoundary aBoundaryType,
int32_t* aStartOffset, int32_t* aEndOffset,
nsAString& aText);
/**
* Return text attributes for the given text range.
*/
already_AddRefed<nsIPersistentProperties>
TextAttributes(bool aIncludeDefAttrs, int32_t aOffset,
int32_t* aStartOffset, int32_t* aEndOffset);
/**
* Return text attributes applied to the accessible.
*/
already_AddRefed<nsIPersistentProperties> DefaultTextAttributes();
/**
* Return text offset of the given child accessible within hypertext
* accessible.
@ -247,14 +269,34 @@ public:
}
/**
* Return the bounds of the text between given start and end offset.
* Return true if the given offset/range is valid.
*/
nsIntRect GetTextBounds(int32_t aStartOffset, int32_t aEndOffset)
{
nsIntRect bounds;
GetPosAndText(aStartOffset, aEndOffset, nullptr, nullptr, &bounds);
return bounds;
}
bool IsValidOffset(int32_t aOffset);
bool IsValidRange(int32_t aStartOffset, int32_t aEndOffset);
/**
* Return an offset at the given point.
*/
int32_t OffsetAtPoint(int32_t aX, int32_t aY, uint32_t aCoordType);
/**
* Return a rect of the given text range relative given coordinate system.
*/
nsIntRect TextBounds(int32_t aStartOffset, int32_t aEndOffset,
uint32_t aCoordType = nsIAccessibleCoordinateType::COORDTYPE_SCREEN_RELATIVE);
/**
* Return a rect for character at given offset relative given coordinate
* system.
*/
nsIntRect CharBounds(int32_t aOffset, uint32_t aCoordType)
{ return TextBounds(aOffset, aOffset + 1, aCoordType); }
/**
* Get/set caret offset, if no caret then -1.
*/
int32_t CaretOffset() const;
void SetCaretOffset(int32_t aOffset) { SetSelectionRange(aOffset, aOffset); }
/**
* Provide the line number for the caret.
@ -271,9 +313,60 @@ public:
*/
nsIntRect GetCaretRect(nsIWidget** aWidget);
/**
* Return selected regions count within the accessible.
*/
int32_t SelectionCount();
/**
* Return the start and end offset of the specified selection.
*/
bool SelectionBoundsAt(int32_t aSelectionNum,
int32_t* aStartOffset, int32_t* aEndOffset);
/*
* Changes the start and end offset of the specified selection.
* @return true if succeeded
*/
bool SetSelectionBoundsAt(int32_t aSelectionNum,
int32_t aStartOffset, int32_t aEndOffset);
/**
* Adds a selection bounded by the specified offsets.
* @return true if succeeded
*/
bool AddToSelection(int32_t aStartOffset, int32_t aEndOffset);
/*
* Removes the specified selection.
* @return true if succeeded
*/
bool RemoveFromSelection(int32_t aSelectionNum);
/**
* Scroll the given text range into view.
*/
void ScrollSubstringTo(int32_t aStartOffset, int32_t aEndOffset,
uint32_t aScrollType);
/**
* Scroll the given text range to the given point.
*/
void ScrollSubstringToPoint(int32_t aStartOffset,
int32_t aEndOffset,
uint32_t aCoordinateType,
int32_t aX, int32_t aY);
//////////////////////////////////////////////////////////////////////////////
// EditableTextAccessible
void ReplaceText(const nsAString& aText);
void InsertText(const nsAString& aText, int32_t aPosition);
void CopyText(int32_t aStartPos, int32_t aEndPos);
void CutText(int32_t aStartPos, int32_t aEndPos);
void DeleteText(int32_t aStartPos, int32_t aEndPos);
void PasteText(int32_t aPosition);
/**
* Return the editor associated with the accessible.
*/
@ -289,39 +382,12 @@ protected:
/**
* Transform magic offset into text offset.
*/
int32_t ConvertMagicOffset(int32_t aOffset)
{
if (aOffset == nsIAccessibleText::TEXT_OFFSET_END_OF_TEXT)
return CharacterCount();
if (aOffset == nsIAccessibleText::TEXT_OFFSET_CARET) {
int32_t caretOffset = -1;
GetCaretOffset(&caretOffset);
return caretOffset;
}
return aOffset;
}
int32_t ConvertMagicOffset(int32_t aOffset);
/**
* Adjust an offset the caret stays at to get a text by line boundary.
*/
int32_t AdjustCaretOffset(int32_t aOffset)
{
// It is the same character offset when the caret is visually at the very
// end of a line or the start of a new line (soft line break). Getting text
// at the line should provide the line with the visual caret, otherwise
// screen readers will announce the wrong line as the user presses up or
// down arrow and land at the end of a line.
if (aOffset > 0) {
nsRefPtr<nsFrameSelection> frameSelection = FrameSelection();
if (frameSelection &&
frameSelection->GetHint() == nsFrameSelection::HINTLEFT) {
return aOffset - 1;
}
}
return aOffset;
}
int32_t AdjustCaretOffset(int32_t aOffset) const;
/**
* Return true if the given offset points to terminal empty line if any.
@ -427,9 +493,10 @@ protected:
// Selection helpers
/**
* Return frame selection object for the accessible.
* Return frame/DOM selection object for the accessible.
*/
virtual already_AddRefed<nsFrameSelection> FrameSelection();
virtual already_AddRefed<nsFrameSelection> FrameSelection() const;
Selection* DOMSelection() const;
/**
* Return selection ranges within the accessible subtree.
@ -443,7 +510,7 @@ protected:
Accessible* aAccessible,
mozilla::a11y::DOMPoint* aPoint);
/**
* Return hyper text offset for the specified bound of the given DOM range.
* If the bound is outside of the hyper text then offset value is either
@ -466,7 +533,7 @@ protected:
* Set 'misspelled' text attribute and return range offsets where the
* attibute is stretched. If the text is not misspelled at the given offset
* then we expose only range offsets where text is not misspelled. The method
* is used by GetTextAttributes() method.
* is used by TextAttributes() method.
*
* @param aIncludeDefAttrs [in] points whether text attributes having default
* values of attributes should be included

View File

@ -4,9 +4,8 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "Accessible-inl.h"
#include "AccessibleWrap.h"
#include "HyperTextAccessible-inl.h"
#include "TextLeafAccessible.h"
#include "nsIAccessibleTypes.h"
#include "nsCocoaUtils.h"
#include "nsObjCExceptions.h"
@ -213,10 +212,10 @@ ToNSString(id aValue)
#endif
return nil;
}
int32_t start = range.location;
int32_t end = start + range.length;
nsIntRect bounds = mGeckoTextAccessible->GetTextBounds(start, end);
nsIntRect bounds = mGeckoTextAccessible->TextBounds(start, end);
return [NSValue valueWithRect:nsCocoaUtils::GeckoRectToCocoaRect(bounds)];
}
@ -263,21 +262,13 @@ ToNSString(id aValue)
if (!stringValue)
return;
int32_t start = 0;
int32_t end = 0;
nsresult rv = mGeckoTextAccessible->GetSelectionBounds(0, &start, &end);
NS_ENSURE_SUCCESS(rv,);
rv = mGeckoTextAccessible->DeleteText(start, end - start);
NS_ENSURE_SUCCESS(rv,);
int32_t start = 0, end = 0;
mGeckoTextAccessible->SelectionBoundsAt(0, &start, &end);
mGeckoTextAccessible->DeleteText(start, end - start);
nsString text;
nsCocoaUtils::GetStringForNSString(stringValue, text);
rv = mGeckoTextAccessible->InsertText(text, start);
NS_ENSURE_SUCCESS(rv,);
return;
mGeckoTextAccessible->InsertText(text, start);
}
if ([attribute isEqualToString:NSAccessibilitySelectedTextRangeAttribute]) {
@ -285,10 +276,8 @@ ToNSString(id aValue)
if (!ToNSRange(value, &range))
return;
nsresult rv = mGeckoTextAccessible->SetSelectionBounds(0, range.location,
range.location + range.length);
NS_ENSURE_SUCCESS(rv,);
mGeckoTextAccessible->SetSelectionBoundsAt(0, range.location,
range.location + range.length);
return;
}
@ -374,10 +363,9 @@ ToNSString(id aValue)
return @"";
nsAutoString text;
nsresult rv = mGeckoTextAccessible->
GetText(0, nsIAccessibleText::TEXT_OFFSET_END_OF_TEXT, text);
NS_ENSURE_SUCCESS(rv, @"");
mGeckoTextAccessible->TextSubstring(0,
nsIAccessibleText::TEXT_OFFSET_END_OF_TEXT,
text);
return nsCocoaUtils::ToNSString(text);
}
@ -398,11 +386,8 @@ ToNSString(id aValue)
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
if (mGeckoTextAccessible) {
int32_t start, end;
start = end = 0;
nsresult rv = mGeckoTextAccessible->GetSelectionBounds(0, &start, &end);
NS_ENSURE_SUCCESS(rv, 0);
int32_t start = 0, end = 0;
mGeckoTextAccessible->SelectionBoundsAt(0, &start, &end);
return (end - start);
}
return 0;
@ -415,12 +400,11 @@ ToNSString(id aValue)
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
if (mGeckoTextAccessible) {
int32_t start, end;
start = end = 0;
mGeckoTextAccessible->GetSelectionBounds(0, &start, &end);
int32_t start = 0, end = 0;
mGeckoTextAccessible->SelectionBoundsAt(0, &start, &end);
if (start != end) {
nsAutoString selText;
mGeckoTextAccessible->GetText(start, end, selText);
mGeckoTextAccessible->TextSubstring(start, end, selText);
return nsCocoaUtils::ToNSString(selText);
}
}
@ -436,21 +420,14 @@ ToNSString(id aValue)
if (mGeckoTextAccessible) {
int32_t start = 0;
int32_t end = 0;
int32_t count = 0;
nsresult rv = mGeckoTextAccessible->GetSelectionCount(&count);
NS_ENSURE_SUCCESS(rv, nil);
int32_t count = mGeckoTextAccessible->SelectionCount();
if (count) {
rv = mGeckoTextAccessible->GetSelectionBounds(0, &start, &end);
NS_ENSURE_SUCCESS(rv, nil);
mGeckoTextAccessible->SelectionBoundsAt(0, &start, &end);
return [NSValue valueWithRange:NSMakeRange(start, end - start)];
}
rv = mGeckoTextAccessible->GetCaretOffset(&start);
NS_ENSURE_SUCCESS(rv, nil);
start = mGeckoTextAccessible->CaretOffset();
return [NSValue valueWithRange:NSMakeRange(start != -1 ? start : 0, 0)];
}
return [NSValue valueWithRange:NSMakeRange(0, 0)];
@ -488,8 +465,8 @@ ToNSString(id aValue)
NS_PRECONDITION(mGeckoTextAccessible && range, "no Gecko text accessible or range");
nsAutoString text;
mGeckoTextAccessible->GetText(range->location,
range->location + range->length, text);
mGeckoTextAccessible->TextSubstring(range->location,
range->location + range->length, text);
return nsCocoaUtils::ToNSString(text);
}

View File

@ -8,6 +8,7 @@
#include "ia2AccessibleEditableText.h"
#include "AccessibleEditableText_i.c"
#include "HyperTextAccessible-inl.h"
#include "HyperTextAccessibleWrap.h"
#include "nsCOMPtr.h"
@ -26,8 +27,11 @@ ia2AccessibleEditableText::copyText(long aStartOffset, long aEndOffset)
if (textAcc->IsDefunct())
return CO_E_OBJNOTCONNECTED;
nsresult rv = textAcc->CopyText(aStartOffset, aEndOffset);
return GetHRESULT(rv);
if (!textAcc->IsValidRange(aStartOffset, aEndOffset))
return E_INVALIDARG;
textAcc->CopyText(aStartOffset, aEndOffset);
return S_OK;
A11Y_TRYBLOCK_END
}
@ -41,8 +45,11 @@ ia2AccessibleEditableText::deleteText(long aStartOffset, long aEndOffset)
if (textAcc->IsDefunct())
return CO_E_OBJNOTCONNECTED;
nsresult rv = textAcc->DeleteText(aStartOffset, aEndOffset);
return GetHRESULT(rv);
if (!textAcc->IsValidRange(aStartOffset, aEndOffset))
return E_INVALIDARG;
textAcc->DeleteText(aStartOffset, aEndOffset);
return S_OK;
A11Y_TRYBLOCK_END
}
@ -56,11 +63,14 @@ ia2AccessibleEditableText::insertText(long aOffset, BSTR *aText)
if (textAcc->IsDefunct())
return CO_E_OBJNOTCONNECTED;
if (!textAcc->IsValidOffset(aOffset))
return E_INVALIDARG;
uint32_t length = ::SysStringLen(*aText);
nsAutoString text(*aText, length);
nsresult rv = textAcc->InsertText(text, aOffset);
return GetHRESULT(rv);
textAcc->InsertText(text, aOffset);
return S_OK;
A11Y_TRYBLOCK_END
}
@ -74,8 +84,11 @@ ia2AccessibleEditableText::cutText(long aStartOffset, long aEndOffset)
if (textAcc->IsDefunct())
return CO_E_OBJNOTCONNECTED;
nsresult rv = textAcc->CutText(aStartOffset, aEndOffset);
return GetHRESULT(rv);
if (!textAcc->IsValidRange(aStartOffset, aEndOffset))
return E_INVALIDARG;
textAcc->CutText(aStartOffset, aEndOffset);
return S_OK;
A11Y_TRYBLOCK_END
}
@ -89,8 +102,11 @@ ia2AccessibleEditableText::pasteText(long aOffset)
if (textAcc->IsDefunct())
return CO_E_OBJNOTCONNECTED;
nsresult rv = textAcc->PasteText(aOffset);
return GetHRESULT(rv);
if (!textAcc->IsValidOffset(aOffset))
return E_INVALIDARG;
textAcc->PasteText(aOffset);
return S_OK;
A11Y_TRYBLOCK_END
}
@ -105,15 +121,16 @@ ia2AccessibleEditableText::replaceText(long aStartOffset, long aEndOffset,
if (textAcc->IsDefunct())
return CO_E_OBJNOTCONNECTED;
nsresult rv = textAcc->DeleteText(aStartOffset, aEndOffset);
if (NS_FAILED(rv))
return GetHRESULT(rv);
if (!textAcc->IsValidRange(aStartOffset, aEndOffset))
return E_INVALIDARG;
textAcc->DeleteText(aStartOffset, aEndOffset);
uint32_t length = ::SysStringLen(*aText);
nsAutoString text(*aText, length);
textAcc->InsertText(text, aStartOffset);
rv = textAcc->InsertText(text, aStartOffset);
return GetHRESULT(rv);
return S_OK;
A11Y_TRYBLOCK_END
}

View File

@ -30,7 +30,7 @@ ia2AccessibleHypertext::get_nHyperlinks(long* aHyperlinkCount)
if (hyperText->IsDefunct())
return CO_E_OBJNOTCONNECTED;
*aHyperlinkCount = hyperText->GetLinkCount();
*aHyperlinkCount = hyperText->LinkCount();
return S_OK;
A11Y_TRYBLOCK_END
@ -51,7 +51,7 @@ ia2AccessibleHypertext::get_hyperlink(long aLinkIndex,
if (hyperText->IsDefunct())
return CO_E_OBJNOTCONNECTED;
Accessible* hyperLink = hyperText->GetLinkAt(aLinkIndex);
Accessible* hyperLink = hyperText->LinkAt(aLinkIndex);
if (!hyperLink)
return E_FAIL;
@ -77,7 +77,7 @@ ia2AccessibleHypertext::get_hyperlinkIndex(long aCharIndex, long* aHyperlinkInde
if (hyperAcc->IsDefunct())
return CO_E_OBJNOTCONNECTED;
*aHyperlinkIndex = hyperAcc->GetLinkIndexAtOffset(aCharIndex);
*aHyperlinkIndex = hyperAcc->LinkIndexAtOffset(aCharIndex);
return S_OK;
A11Y_TRYBLOCK_END

View File

@ -11,9 +11,7 @@
#include "AccessibleText_i.c"
#include "HyperTextAccessibleWrap.h"
#include "nsIPersistentProperties2.h"
#include "nsIAccessibleTypes.h"
#include "HyperTextAccessible-inl.h"
using namespace mozilla::a11y;
@ -28,8 +26,8 @@ ia2AccessibleText::addSelection(long aStartOffset, long aEndOffset)
if (textAcc->IsDefunct())
return CO_E_OBJNOTCONNECTED;
nsresult rv = textAcc->AddSelection(aStartOffset, aEndOffset);
return GetHRESULT(rv);
return textAcc->AddToSelection(aStartOffset, aEndOffset) ?
S_OK : E_INVALIDARG;
A11Y_TRYBLOCK_END
}
@ -52,13 +50,9 @@ ia2AccessibleText::get_attributes(long aOffset, long *aStartOffset,
return CO_E_OBJNOTCONNECTED;
int32_t startOffset = 0, endOffset = 0;
nsCOMPtr<nsIPersistentProperties> attributes;
nsresult rv = textAcc->GetTextAttributes(true, aOffset,
&startOffset, &endOffset,
getter_AddRefs(attributes));
if (NS_FAILED(rv))
return GetHRESULT(rv);
nsCOMPtr<nsIPersistentProperties> attributes =
textAcc->TextAttributes(true, aOffset, &startOffset, &endOffset);
HRESULT hr = AccessibleWrap::ConvertToIA2Attributes(attributes,
aTextAttributes);
if (FAILED(hr))
@ -86,13 +80,8 @@ ia2AccessibleText::get_caretOffset(long *aOffset)
if (textAcc->IsDefunct())
return CO_E_OBJNOTCONNECTED;
int32_t offset = 0;
nsresult rv = textAcc->GetCaretOffset(&offset);
if (NS_FAILED(rv))
return GetHRESULT(rv);
*aOffset = offset;
return offset != -1 ? S_OK : S_FALSE;
*aOffset = textAcc->CaretOffset();
return *aOffset != -1 ? S_OK : S_FALSE;
A11Y_TRYBLOCK_END
}
@ -100,18 +89,14 @@ ia2AccessibleText::get_caretOffset(long *aOffset)
STDMETHODIMP
ia2AccessibleText::get_characterExtents(long aOffset,
enum IA2CoordinateType aCoordType,
long *aX, long *aY,
long *aWidth, long *aHeight)
long* aX, long* aY,
long* aWidth, long* aHeight)
{
A11Y_TRYBLOCK_BEGIN
if (!aX || !aY || !aWidth || !aHeight)
return E_INVALIDARG;
*aX = 0;
*aY = 0;
*aWidth = 0;
*aHeight = 0;
*aX = *aY = *aWidth = *aHeight = 0;
HyperTextAccessible* textAcc = static_cast<HyperTextAccessibleWrap*>(this);
if (textAcc->IsDefunct())
@ -121,41 +106,31 @@ ia2AccessibleText::get_characterExtents(long aOffset,
nsIAccessibleCoordinateType::COORDTYPE_SCREEN_RELATIVE :
nsIAccessibleCoordinateType::COORDTYPE_PARENT_RELATIVE;
int32_t x = 0, y =0, width = 0, height = 0;
nsresult rv = textAcc->GetCharacterExtents (aOffset, &x, &y, &width, &height,
geckoCoordType);
if (NS_FAILED(rv))
return GetHRESULT(rv);
nsIntRect rect = textAcc->CharBounds(aOffset, geckoCoordType);
*aX = x;
*aY = y;
*aWidth = width;
*aHeight = height;
*aX = rect.x;
*aY = rect.y;
*aWidth = rect.width;
*aHeight = rect.height;
return S_OK;
A11Y_TRYBLOCK_END
}
STDMETHODIMP
ia2AccessibleText::get_nSelections(long *aNSelections)
ia2AccessibleText::get_nSelections(long* aNSelections)
{
A11Y_TRYBLOCK_BEGIN
if (!aNSelections)
return E_INVALIDARG;
*aNSelections = 0;
HyperTextAccessible* textAcc = static_cast<HyperTextAccessibleWrap*>(this);
if (textAcc->IsDefunct())
return CO_E_OBJNOTCONNECTED;
int32_t selCount = 0;
nsresult rv = textAcc->GetSelectionCount(&selCount);
if (NS_FAILED(rv))
return GetHRESULT(rv);
*aNSelections = selCount;
*aNSelections = textAcc->SelectionCount();
return S_OK;
A11Y_TRYBLOCK_END
@ -164,13 +139,12 @@ ia2AccessibleText::get_nSelections(long *aNSelections)
STDMETHODIMP
ia2AccessibleText::get_offsetAtPoint(long aX, long aY,
enum IA2CoordinateType aCoordType,
long *aOffset)
long* aOffset)
{
A11Y_TRYBLOCK_BEGIN
if (!aOffset)
return E_INVALIDARG;
*aOffset = 0;
HyperTextAccessible* textAcc = static_cast<HyperTextAccessibleWrap*>(this);
@ -181,38 +155,29 @@ ia2AccessibleText::get_offsetAtPoint(long aX, long aY,
nsIAccessibleCoordinateType::COORDTYPE_SCREEN_RELATIVE :
nsIAccessibleCoordinateType::COORDTYPE_PARENT_RELATIVE;
int32_t offset = 0;
nsresult rv = textAcc->GetOffsetAtPoint(aX, aY, geckoCoordType, &offset);
if (NS_FAILED(rv))
return GetHRESULT(rv);
*aOffset = offset;
return S_OK;
*aOffset = textAcc->OffsetAtPoint(aX, aY, geckoCoordType);
return *aOffset == -1 ? S_FALSE : S_OK;
A11Y_TRYBLOCK_END
}
STDMETHODIMP
ia2AccessibleText::get_selection(long aSelectionIndex, long *aStartOffset,
long *aEndOffset)
ia2AccessibleText::get_selection(long aSelectionIndex, long* aStartOffset,
long* aEndOffset)
{
A11Y_TRYBLOCK_BEGIN
if (!aStartOffset || !aEndOffset)
return E_INVALIDARG;
*aStartOffset = 0;
*aEndOffset = 0;
*aStartOffset = *aEndOffset = 0;
HyperTextAccessible* textAcc = static_cast<HyperTextAccessibleWrap*>(this);
if (textAcc->IsDefunct())
return CO_E_OBJNOTCONNECTED;
int32_t startOffset = 0, endOffset = 0;
nsresult rv = textAcc->GetSelectionBounds(aSelectionIndex,
&startOffset, &endOffset);
if (NS_FAILED(rv))
return GetHRESULT(rv);
if (!textAcc->SelectionBoundsAt(aSelectionIndex, &startOffset, &endOffset))
return E_INVALIDARG;
*aStartOffset = startOffset;
*aEndOffset = endOffset;
@ -222,7 +187,7 @@ ia2AccessibleText::get_selection(long aSelectionIndex, long *aStartOffset,
}
STDMETHODIMP
ia2AccessibleText::get_text(long aStartOffset, long aEndOffset, BSTR *aText)
ia2AccessibleText::get_text(long aStartOffset, long aEndOffset, BSTR* aText)
{
A11Y_TRYBLOCK_BEGIN
@ -235,11 +200,11 @@ ia2AccessibleText::get_text(long aStartOffset, long aEndOffset, BSTR *aText)
if (textAcc->IsDefunct())
return CO_E_OBJNOTCONNECTED;
nsAutoString text;
nsresult rv = textAcc->GetText(aStartOffset, aEndOffset, text);
if (NS_FAILED(rv))
return GetHRESULT(rv);
if (!textAcc->IsValidRange(aStartOffset, aEndOffset))
return E_INVALIDARG;
nsAutoString text;
textAcc->TextSubstring(aStartOffset, aEndOffset, text);
if (text.IsEmpty())
return S_FALSE;
@ -252,40 +217,38 @@ ia2AccessibleText::get_text(long aStartOffset, long aEndOffset, BSTR *aText)
STDMETHODIMP
ia2AccessibleText::get_textBeforeOffset(long aOffset,
enum IA2TextBoundaryType aBoundaryType,
long *aStartOffset, long *aEndOffset,
BSTR *aText)
long* aStartOffset, long* aEndOffset,
BSTR* aText)
{
A11Y_TRYBLOCK_BEGIN
if (!aStartOffset || !aEndOffset || !aText)
return E_INVALIDARG;
*aStartOffset = 0;
*aEndOffset = 0;
*aStartOffset = *aEndOffset = 0;
*aText = nullptr;
HyperTextAccessible* textAcc = static_cast<HyperTextAccessibleWrap*>(this);
if (textAcc->IsDefunct())
return CO_E_OBJNOTCONNECTED;
nsresult rv = NS_OK;
if (textAcc->IsValidOffset(aOffset))
return E_INVALIDARG;
nsAutoString text;
int32_t startOffset = 0, endOffset = 0;
if (aBoundaryType == IA2_TEXT_BOUNDARY_ALL) {
startOffset = 0;
endOffset = textAcc->CharacterCount();
rv = textAcc->GetText(startOffset, endOffset, text);
textAcc->TextSubstring(startOffset, endOffset, text);
} else {
AccessibleTextBoundary boundaryType = GetGeckoTextBoundary(aBoundaryType);
if (boundaryType == -1)
return S_FALSE;
rv = textAcc->GetTextBeforeOffset(aOffset, boundaryType,
&startOffset, &endOffset, text);
}
if (NS_FAILED(rv))
return GetHRESULT(rv);
textAcc->TextBeforeOffset(aOffset, boundaryType, &startOffset, &endOffset, text);
}
*aStartOffset = startOffset;
*aEndOffset = endOffset;
@ -302,8 +265,8 @@ ia2AccessibleText::get_textBeforeOffset(long aOffset,
STDMETHODIMP
ia2AccessibleText::get_textAfterOffset(long aOffset,
enum IA2TextBoundaryType aBoundaryType,
long *aStartOffset, long *aEndOffset,
BSTR *aText)
long* aStartOffset, long* aEndOffset,
BSTR* aText)
{
A11Y_TRYBLOCK_BEGIN
@ -318,25 +281,23 @@ ia2AccessibleText::get_textAfterOffset(long aOffset,
if (textAcc->IsDefunct())
return CO_E_OBJNOTCONNECTED;
nsresult rv = NS_OK;
if (textAcc->IsValidOffset(aOffset))
return E_INVALIDARG;
nsAutoString text;
int32_t startOffset = 0, endOffset = 0;
if (aBoundaryType == IA2_TEXT_BOUNDARY_ALL) {
startOffset = 0;
endOffset = textAcc->CharacterCount();
rv = textAcc->GetText(startOffset, endOffset, text);
textAcc->TextSubstring(startOffset, endOffset, text);
} else {
AccessibleTextBoundary boundaryType = GetGeckoTextBoundary(aBoundaryType);
if (boundaryType == -1)
return S_FALSE;
rv = textAcc->GetTextAfterOffset(aOffset, boundaryType,
&startOffset, &endOffset, text);
textAcc->TextAfterOffset(aOffset, boundaryType, &startOffset, &endOffset, text);
}
if (NS_FAILED(rv))
return GetHRESULT(rv);
*aStartOffset = startOffset;
*aEndOffset = endOffset;
@ -352,41 +313,37 @@ ia2AccessibleText::get_textAfterOffset(long aOffset,
STDMETHODIMP
ia2AccessibleText::get_textAtOffset(long aOffset,
enum IA2TextBoundaryType aBoundaryType,
long *aStartOffset, long *aEndOffset,
BSTR *aText)
long* aStartOffset, long* aEndOffset,
BSTR* aText)
{
A11Y_TRYBLOCK_BEGIN
if (!aStartOffset || !aEndOffset || !aText)
return E_INVALIDARG;
*aStartOffset = 0;
*aEndOffset = 0;
*aStartOffset = *aEndOffset = 0;
*aText = nullptr;
HyperTextAccessible* textAcc = static_cast<HyperTextAccessibleWrap*>(this);
if (textAcc->IsDefunct())
return CO_E_OBJNOTCONNECTED;
nsresult rv = NS_OK;
if (textAcc->IsValidOffset(aOffset))
return E_INVALIDARG;
nsAutoString text;
int32_t startOffset = 0, endOffset = 0;
if (aBoundaryType == IA2_TEXT_BOUNDARY_ALL) {
startOffset = 0;
endOffset = textAcc->CharacterCount();
rv = textAcc->GetText(startOffset, endOffset, text);
textAcc->TextSubstring(startOffset, endOffset, text);
} else {
AccessibleTextBoundary boundaryType = GetGeckoTextBoundary(aBoundaryType);
if (boundaryType == -1)
return S_FALSE;
rv = textAcc->GetTextAtOffset(aOffset, boundaryType,
&startOffset, &endOffset, text);
textAcc->TextAtOffset(aOffset, boundaryType, &startOffset, &endOffset, text);
}
if (NS_FAILED(rv))
return GetHRESULT(rv);
*aStartOffset = startOffset;
*aEndOffset = endOffset;
@ -408,8 +365,8 @@ ia2AccessibleText::removeSelection(long aSelectionIndex)
if (textAcc->IsDefunct())
return CO_E_OBJNOTCONNECTED;
nsresult rv = textAcc->RemoveSelection(aSelectionIndex);
return GetHRESULT(rv);
return textAcc->RemoveFromSelection(aSelectionIndex) ?
S_OK : E_INVALIDARG;
A11Y_TRYBLOCK_END
}
@ -423,8 +380,11 @@ ia2AccessibleText::setCaretOffset(long aOffset)
if (textAcc->IsDefunct())
return CO_E_OBJNOTCONNECTED;
nsresult rv = textAcc->SetCaretOffset(aOffset);
return GetHRESULT(rv);
if (!textAcc->IsValidOffset(aOffset))
return E_INVALIDARG;
textAcc->SetCaretOffset(aOffset);
return S_OK;
A11Y_TRYBLOCK_END
}
@ -439,21 +399,19 @@ ia2AccessibleText::setSelection(long aSelectionIndex, long aStartOffset,
if (textAcc->IsDefunct())
return CO_E_OBJNOTCONNECTED;
nsresult rv = textAcc->SetSelectionBounds(aSelectionIndex,
aStartOffset, aEndOffset);
return GetHRESULT(rv);
return textAcc->SetSelectionBoundsAt(aSelectionIndex, aStartOffset, aEndOffset) ?
S_OK : E_INVALIDARG;
A11Y_TRYBLOCK_END
}
STDMETHODIMP
ia2AccessibleText::get_nCharacters(long *aNCharacters)
ia2AccessibleText::get_nCharacters(long* aNCharacters)
{
A11Y_TRYBLOCK_BEGIN
if (!aNCharacters)
return E_INVALIDARG;
*aNCharacters = 0;
HyperTextAccessible* textAcc = static_cast<HyperTextAccessibleWrap*>(this);
@ -476,8 +434,11 @@ ia2AccessibleText::scrollSubstringTo(long aStartIndex, long aEndIndex,
if (textAcc->IsDefunct())
return CO_E_OBJNOTCONNECTED;
nsresult rv = textAcc->ScrollSubstringTo(aStartIndex, aEndIndex, aScrollType);
return GetHRESULT(rv);
if (!textAcc->IsValidRange(aStartIndex, aEndIndex))
return E_INVALIDARG;
textAcc->ScrollSubstringTo(aStartIndex, aEndIndex, aScrollType);
return S_OK;
A11Y_TRYBLOCK_END
}
@ -493,13 +454,16 @@ ia2AccessibleText::scrollSubstringToPoint(long aStartIndex, long aEndIndex,
if (textAcc->IsDefunct())
return CO_E_OBJNOTCONNECTED;
if (!textAcc->IsValidRange(aStartIndex, aEndIndex))
return E_INVALIDARG;
uint32_t geckoCoordType = (aCoordType == IA2_COORDTYPE_SCREEN_RELATIVE) ?
nsIAccessibleCoordinateType::COORDTYPE_SCREEN_RELATIVE :
nsIAccessibleCoordinateType::COORDTYPE_PARENT_RELATIVE;
nsresult rv = textAcc->ScrollSubstringToPoint(aStartIndex, aEndIndex,
geckoCoordType, aX, aY);
return GetHRESULT(rv);
textAcc->ScrollSubstringToPoint(aStartIndex, aEndIndex,
geckoCoordType, aX, aY);
return S_OK;
A11Y_TRYBLOCK_END
}

View File

@ -7,11 +7,13 @@
MODULE = 'accessibility'
EXPORTS += [
'xpcAccessibleHyperText.h',
'xpcAccessibleSelectable.h',
]
SOURCES += [
'nsAccessibleRelation.cpp',
'xpcAccessibleHyperText.cpp',
'xpcAccessibleSelectable.cpp',
'xpcAccessibleTable.cpp',
'xpcAccessibleTableCell.cpp',

View File

@ -0,0 +1,507 @@
/* -*- 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 "xpcAccessibleHyperText.h"
#include "HyperTextAccessible-inl.h"
#include "nsIPersistentProperties2.h"
using namespace mozilla::a11y;
////////////////////////////////////////////////////////////////////////////////
// nsISupports
nsresult
xpcAccessibleHyperText::QueryInterface(REFNSIID aIID, void** aInstancePtr)
{
*aInstancePtr = nullptr;
HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this);
if (!text->IsTextRole())
return NS_ERROR_NO_INTERFACE;
if (aIID.Equals(NS_GET_IID(nsIAccessibleText)))
*aInstancePtr = static_cast<nsIAccessibleText*>(text);
else if (aIID.Equals(NS_GET_IID(nsIAccessibleEditableText)))
*aInstancePtr = static_cast<nsIAccessibleEditableText*>(text);
else if (aIID.Equals(NS_GET_IID(nsIAccessibleHyperText)))
*aInstancePtr = static_cast<nsIAccessibleHyperText*>(text);
else
return NS_ERROR_NO_INTERFACE;
NS_ADDREF(text);
return NS_OK;
}
////////////////////////////////////////////////////////////////////////////////
// nsIAccessibleText
NS_IMETHODIMP
xpcAccessibleHyperText::GetCharacterCount(int32_t* aCharacterCount)
{
NS_ENSURE_ARG_POINTER(aCharacterCount);
*aCharacterCount = 0;
HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this);
if (text->IsDefunct())
return NS_ERROR_FAILURE;
*aCharacterCount = text->CharacterCount();
return NS_OK;
}
NS_IMETHODIMP
xpcAccessibleHyperText::GetText(int32_t aStartOffset, int32_t aEndOffset,
nsAString& aText)
{
aText.Truncate();
HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this);
if (text->IsDefunct())
return NS_ERROR_FAILURE;
text->TextSubstring(aStartOffset, aEndOffset, aText);
return NS_OK;
}
NS_IMETHODIMP
xpcAccessibleHyperText::GetTextBeforeOffset(int32_t aOffset,
AccessibleTextBoundary aBoundaryType,
int32_t* aStartOffset,
int32_t* aEndOffset,
nsAString& aText)
{
NS_ENSURE_ARG_POINTER(aStartOffset);
NS_ENSURE_ARG_POINTER(aEndOffset);
*aStartOffset = *aEndOffset = 0;
aText.Truncate();
HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this);
if (text->IsDefunct())
return NS_ERROR_FAILURE;
text->TextBeforeOffset(aOffset, aBoundaryType, aStartOffset, aEndOffset, aText);
return NS_OK;
}
NS_IMETHODIMP
xpcAccessibleHyperText::GetTextAtOffset(int32_t aOffset,
AccessibleTextBoundary aBoundaryType,
int32_t* aStartOffset,
int32_t* aEndOffset, nsAString& aText)
{
NS_ENSURE_ARG_POINTER(aStartOffset);
NS_ENSURE_ARG_POINTER(aEndOffset);
*aStartOffset = *aEndOffset = 0;
aText.Truncate();
HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this);
if (text->IsDefunct())
return NS_ERROR_FAILURE;
text->TextAtOffset(aOffset, aBoundaryType, aStartOffset, aEndOffset, aText);
return NS_OK;
}
NS_IMETHODIMP
xpcAccessibleHyperText::GetTextAfterOffset(int32_t aOffset,
AccessibleTextBoundary aBoundaryType,
int32_t* aStartOffset,
int32_t* aEndOffset, nsAString& aText)
{
NS_ENSURE_ARG_POINTER(aStartOffset);
NS_ENSURE_ARG_POINTER(aEndOffset);
*aStartOffset = *aEndOffset = 0;
aText.Truncate();
HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this);
if (text->IsDefunct())
return NS_ERROR_FAILURE;
text->TextAfterOffset(aOffset, aBoundaryType, aStartOffset, aEndOffset, aText);
return NS_OK;
}
NS_IMETHODIMP
xpcAccessibleHyperText::GetCharacterAtOffset(int32_t aOffset,
PRUnichar* aCharacter)
{
NS_ENSURE_ARG_POINTER(aCharacter);
*aCharacter = L'\0';
HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this);
if (text->IsDefunct())
return NS_ERROR_FAILURE;
nsAutoString character;
if (text->GetCharAt(aOffset, eGetAt, character)) {
*aCharacter = character.First();
return NS_OK;
}
return NS_ERROR_INVALID_ARG;
}
NS_IMETHODIMP
xpcAccessibleHyperText::GetTextAttributes(bool aIncludeDefAttrs,
int32_t aOffset,
int32_t* aStartOffset,
int32_t* aEndOffset,
nsIPersistentProperties** aAttributes)
{
NS_ENSURE_ARG_POINTER(aStartOffset);
NS_ENSURE_ARG_POINTER(aEndOffset);
NS_ENSURE_ARG_POINTER(aAttributes);
*aStartOffset = *aEndOffset = 0;
*aAttributes = nullptr;
HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this);
if (text->IsDefunct())
return NS_ERROR_FAILURE;
nsCOMPtr<nsIPersistentProperties> attrs =
text->TextAttributes(aIncludeDefAttrs, aOffset, aStartOffset, aEndOffset);
attrs.swap(*aAttributes);
return NS_OK;
}
NS_IMETHODIMP
xpcAccessibleHyperText::GetDefaultTextAttributes(nsIPersistentProperties** aAttributes)
{
NS_ENSURE_ARG_POINTER(aAttributes);
*aAttributes = nullptr;
HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this);
if (text->IsDefunct())
return NS_ERROR_FAILURE;
nsCOMPtr<nsIPersistentProperties> attrs = text->DefaultTextAttributes();
attrs.swap(*aAttributes);
return NS_OK;
}
NS_IMETHODIMP
xpcAccessibleHyperText::GetCharacterExtents(int32_t aOffset,
int32_t* aX, int32_t* aY,
int32_t* aWidth, int32_t* aHeight,
uint32_t aCoordType)
{
NS_ENSURE_ARG_POINTER(aX);
NS_ENSURE_ARG_POINTER(aY);
NS_ENSURE_ARG_POINTER(aWidth);
NS_ENSURE_ARG_POINTER(aHeight);
*aX = *aY = *aWidth = *aHeight;
HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this);
if (text->IsDefunct())
return NS_ERROR_FAILURE;
nsIntRect rect = text->CharBounds(aOffset, aCoordType);
*aX = rect.x; *aY = rect.y;
*aWidth = rect.width; *aHeight = rect.height;
return NS_OK;
}
NS_IMETHODIMP
xpcAccessibleHyperText::GetRangeExtents(int32_t aStartOffset, int32_t aEndOffset,
int32_t* aX, int32_t* aY,
int32_t* aWidth, int32_t* aHeight,
uint32_t aCoordType)
{
NS_ENSURE_ARG_POINTER(aX);
NS_ENSURE_ARG_POINTER(aY);
NS_ENSURE_ARG_POINTER(aWidth);
NS_ENSURE_ARG_POINTER(aHeight);
*aX = *aY = *aWidth = *aHeight = 0;
HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this);
if (text->IsDefunct())
return NS_ERROR_FAILURE;
nsIntRect rect = text->TextBounds(aStartOffset, aEndOffset, aCoordType);
*aX = rect.x; *aY = rect.y;
*aWidth = rect.width; *aHeight = rect.height;
return NS_OK;
}
NS_IMETHODIMP
xpcAccessibleHyperText::GetOffsetAtPoint(int32_t aX, int32_t aY,
uint32_t aCoordType, int32_t* aOffset)
{
NS_ENSURE_ARG_POINTER(aOffset);
*aOffset = -1;
HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this);
if (text->IsDefunct())
return NS_ERROR_FAILURE;
*aOffset = text->OffsetAtPoint(aX, aY, aCoordType);
return NS_OK;
}
NS_IMETHODIMP
xpcAccessibleHyperText::GetScriptableCaretOffset(int32_t* aCaretOffset)
{
NS_ENSURE_ARG_POINTER(aCaretOffset);
*aCaretOffset = -1;
HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this);
if (text->IsDefunct())
return NS_ERROR_FAILURE;
*aCaretOffset = text->CaretOffset();
return NS_OK;
}
NS_IMETHODIMP
xpcAccessibleHyperText::SetScriptableCaretOffset(int32_t aCaretOffset)
{
HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this);
if (text->IsDefunct())
return NS_ERROR_FAILURE;
text->SetCaretOffset(aCaretOffset);
return NS_OK;
}
NS_IMETHODIMP
xpcAccessibleHyperText::GetSelectionCount(int32_t* aSelectionCount)
{
NS_ENSURE_ARG_POINTER(aSelectionCount);
*aSelectionCount = 0;
HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this);
if (text->IsDefunct())
return NS_ERROR_FAILURE;
*aSelectionCount = text->SelectionCount();
return NS_OK;
}
NS_IMETHODIMP
xpcAccessibleHyperText::GetSelectionBounds(int32_t aSelectionNum,
int32_t* aStartOffset,
int32_t* aEndOffset)
{
NS_ENSURE_ARG_POINTER(aStartOffset);
NS_ENSURE_ARG_POINTER(aEndOffset);
*aStartOffset = *aEndOffset = 0;
HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this);
if (text->IsDefunct())
return NS_ERROR_FAILURE;
if (aSelectionNum < 0 || aSelectionNum >= text->SelectionCount())
return NS_ERROR_INVALID_ARG;
text->SelectionBoundsAt(aSelectionNum, aStartOffset, aEndOffset);
return NS_OK;
}
NS_IMETHODIMP
xpcAccessibleHyperText::SetSelectionBounds(int32_t aSelectionNum,
int32_t aStartOffset,
int32_t aEndOffset)
{
HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this);
if (text->IsDefunct())
return NS_ERROR_FAILURE;
if (aSelectionNum < 0 ||
!text->SetSelectionBoundsAt(aSelectionNum, aStartOffset, aEndOffset))
return NS_ERROR_INVALID_ARG;
return NS_OK;
}
NS_IMETHODIMP
xpcAccessibleHyperText::AddSelection(int32_t aStartOffset, int32_t aEndOffset)
{
HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this);
if (text->IsDefunct())
return NS_ERROR_FAILURE;
text->AddToSelection(aStartOffset, aEndOffset);
return NS_OK;
}
NS_IMETHODIMP
xpcAccessibleHyperText::RemoveSelection(int32_t aSelectionNum)
{
HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this);
if (text->IsDefunct())
return NS_ERROR_FAILURE;
text->RemoveFromSelection(aSelectionNum);
return NS_OK;
}
NS_IMETHODIMP
xpcAccessibleHyperText::ScriptableScrollSubstringTo(int32_t aStartOffset,
int32_t aEndOffset,
uint32_t aScrollType)
{
HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this);
if (text->IsDefunct())
return NS_ERROR_FAILURE;
text->ScrollSubstringTo(aStartOffset, aEndOffset, aScrollType);
return NS_OK;
}
NS_IMETHODIMP
xpcAccessibleHyperText::ScriptableScrollSubstringToPoint(int32_t aStartOffset,
int32_t aEndOffset,
uint32_t aCoordinateType,
int32_t aX, int32_t aY)
{
HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this);
if (text->IsDefunct())
return NS_ERROR_FAILURE;
text->ScrollSubstringToPoint(aStartOffset, aEndOffset, aCoordinateType, aX, aY);
return NS_OK;
}
////////////////////////////////////////////////////////////////////////////////
// nsIAccessibleEditableText
NS_IMETHODIMP
xpcAccessibleHyperText::SetTextContents(const nsAString& aText)
{
HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this);
if (text->IsDefunct())
return NS_ERROR_FAILURE;
text->ReplaceText(aText);
return NS_OK;
}
NS_IMETHODIMP
xpcAccessibleHyperText::ScriptableInsertText(const nsAString& aText,
int32_t aOffset)
{
HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this);
if (text->IsDefunct())
return NS_ERROR_FAILURE;
text->InsertText(aText, aOffset);
return NS_OK;
}
NS_IMETHODIMP
xpcAccessibleHyperText::ScriptableCopyText(int32_t aStartOffset,
int32_t aEndOffset)
{
HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this);
if (text->IsDefunct())
return NS_ERROR_FAILURE;
text->CopyText(aStartOffset, aEndOffset);
return NS_OK;
}
NS_IMETHODIMP
xpcAccessibleHyperText::ScriptableCutText(int32_t aStartOffset,
int32_t aEndOffset)
{
HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this);
if (text->IsDefunct())
return NS_ERROR_FAILURE;
text->CutText(aStartOffset, aEndOffset);
return NS_OK;
}
NS_IMETHODIMP
xpcAccessibleHyperText::ScriptableDeleteText(int32_t aStartOffset,
int32_t aEndOffset)
{
HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this);
if (text->IsDefunct())
return NS_ERROR_FAILURE;
text->DeleteText(aStartOffset, aEndOffset);
return NS_OK;
}
NS_IMETHODIMP
xpcAccessibleHyperText::ScriptablePasteText(int32_t aOffset)
{
HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this);
if (text->IsDefunct())
return NS_ERROR_FAILURE;
text->PasteText(aOffset);
return NS_OK;
}
////////////////////////////////////////////////////////////////////////////////
// nsIAccessibleHyperText
NS_IMETHODIMP
xpcAccessibleHyperText::GetLinkCount(int32_t* aLinkCount)
{
NS_ENSURE_ARG_POINTER(aLinkCount);
*aLinkCount = 0;
HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this);
if (text->IsDefunct())
return NS_ERROR_FAILURE;
*aLinkCount = text->LinkCount();
return NS_OK;
}
NS_IMETHODIMP
xpcAccessibleHyperText::GetLinkAt(int32_t aIndex, nsIAccessibleHyperLink** aLink)
{
NS_ENSURE_ARG_POINTER(aLink);
*aLink = nullptr;
HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this);
if (text->IsDefunct())
return NS_ERROR_FAILURE;
nsCOMPtr<nsIAccessibleHyperLink> link = text->LinkAt(aIndex);
link.forget(aLink);
return NS_OK;
}
NS_IMETHODIMP
xpcAccessibleHyperText::GetLinkIndex(nsIAccessibleHyperLink* aLink,
int32_t* aIndex)
{
NS_ENSURE_ARG_POINTER(aLink);
NS_ENSURE_ARG_POINTER(aIndex);
*aIndex = -1;
HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this);
if (text->IsDefunct())
return NS_ERROR_FAILURE;
nsRefPtr<Accessible> link(do_QueryObject(aLink));
*aIndex = text->LinkIndexOf(link);
return NS_OK;
}
NS_IMETHODIMP
xpcAccessibleHyperText::GetLinkIndexAtOffset(int32_t aOffset,
int32_t* aLinkIndex)
{
NS_ENSURE_ARG_POINTER(aLinkIndex);
*aLinkIndex = -1; // API says this magic value means 'not found'
HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this);
if (text->IsDefunct())
return NS_ERROR_FAILURE;
*aLinkIndex = text->LinkIndexAtOffset(aOffset);
return NS_OK;
}

View File

@ -0,0 +1,39 @@
/* -*- 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_xpcAccessibleHyperText_h_
#define mozilla_a11y_xpcAccessibleHyperText_h_
#include "nsIAccessibleText.h"
#include "nsIAccessibleHyperText.h"
#include "nsIAccessibleEditableText.h"
namespace mozilla {
namespace a11y {
class xpcAccessibleHyperText : public nsIAccessibleText,
public nsIAccessibleEditableText,
public nsIAccessibleHyperText
{
public:
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
NS_DECL_NSIACCESSIBLETEXT
NS_DECL_NSIACCESSIBLEHYPERTEXT
NS_DECL_NSIACCESSIBLEEDITABLETEXT
private:
xpcAccessibleHyperText() { }
friend class HyperTextAccessible;
xpcAccessibleHyperText(const xpcAccessibleHyperText&) MOZ_DELETE;
xpcAccessibleHyperText& operator =(const xpcAccessibleHyperText&) MOZ_DELETE;
};
} // namespace a11y
} // namespace mozilla
#endif // mozilla_a11y_xpcAccessibleHyperText_h_

View File

@ -811,7 +811,7 @@ XULTextFieldAccessible::CacheChildren()
// XULTextFieldAccessible: HyperTextAccessible protected
already_AddRefed<nsFrameSelection>
XULTextFieldAccessible::FrameSelection()
XULTextFieldAccessible::FrameSelection() const
{
nsCOMPtr<nsIContent> inputContent(GetInputField());
NS_ASSERTION(inputContent, "No input content");

View File

@ -250,7 +250,7 @@ protected:
virtual void CacheChildren();
// HyperTextAccessible
virtual already_AddRefed<nsFrameSelection> FrameSelection();
virtual already_AddRefed<nsFrameSelection> FrameSelection() const;
// nsXULTextFieldAccessible
already_AddRefed<nsIContent> GetInputField() const;

View File

@ -415,7 +415,7 @@ function testTextSetSelection(aID, aStartOffset, aEndOffset,
var text = acc.getText(0, -1);
acc.setSelectionBounds(aSelectionIndex, aStartOffset, aEndOffset);
is(acc.selectionCount, aSelectionsCount,
text + ": failed to set selection at index '" +
aSelectionIndex + "': selectionCount after");