2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* 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/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-05-31 01:04:41 -07:00
|
|
|
#ifndef mozilla_a11y_HyperTextAccessible_h__
|
|
|
|
#define mozilla_a11y_HyperTextAccessible_h__
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
#include "AccessibleWrap.h"
|
2014-10-21 17:49:28 -07:00
|
|
|
#include "nsIAccessibleText.h"
|
2013-11-18 05:19:33 -08:00
|
|
|
#include "nsIAccessibleTypes.h"
|
2014-08-05 22:19:27 -07:00
|
|
|
#include "nsDirection.h"
|
|
|
|
#include "WordMovementType.h"
|
|
|
|
#include "nsIFrame.h"
|
2008-07-17 05:06:24 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsISelectionController.h"
|
|
|
|
|
2014-08-05 22:19:27 -07:00
|
|
|
class nsFrameSelection;
|
|
|
|
class nsRange;
|
|
|
|
class nsIWidget;
|
|
|
|
|
2012-04-06 11:08:24 -07:00
|
|
|
namespace mozilla {
|
2014-08-05 22:19:27 -07:00
|
|
|
|
|
|
|
namespace dom {
|
|
|
|
class Selection;
|
|
|
|
}
|
|
|
|
|
2012-04-06 11:08:24 -07:00
|
|
|
namespace a11y {
|
2012-11-17 18:01:44 -08:00
|
|
|
|
2014-02-27 08:33:09 -08:00
|
|
|
class TextRange;
|
|
|
|
|
2012-04-06 11:08:24 -07:00
|
|
|
struct DOMPoint {
|
2013-12-13 08:26:35 -08:00
|
|
|
DOMPoint() : node(nullptr), idx(0) { }
|
|
|
|
DOMPoint(nsINode* aNode, int32_t aIdx) : node(aNode), idx(aIdx) { }
|
|
|
|
|
2012-04-06 11:08:24 -07:00
|
|
|
nsINode* node;
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t idx;
|
2012-04-06 11:08:24 -07:00
|
|
|
};
|
|
|
|
|
2014-10-21 17:49:28 -07:00
|
|
|
// This character marks where in the text returned via Text interface,
|
2007-03-22 10:30:00 -07:00
|
|
|
// that embedded object characters exist
|
2014-01-04 07:02:17 -08:00
|
|
|
const char16_t kEmbeddedObjectChar = 0xfffc;
|
|
|
|
const char16_t kImaginaryEmbeddedObjectChar = ' ';
|
|
|
|
const char16_t kForcedNewLineChar = '\n';
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Special Accessible that knows how contain both text and embedded objects
|
|
|
|
*/
|
2014-10-21 17:49:28 -07:00
|
|
|
class HyperTextAccessible : public AccessibleWrap
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
public:
|
2012-05-31 01:04:41 -07:00
|
|
|
HyperTextAccessible(nsIContent* aContent, DocAccessible* aDoc);
|
2012-02-07 14:38:54 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
// Accessible
|
2015-03-21 09:28:04 -07:00
|
|
|
virtual nsIAtom* LandmarkRole() const override;
|
|
|
|
virtual int32_t GetLevelInternal() override;
|
|
|
|
virtual already_AddRefed<nsIPersistentProperties> NativeAttributes() override;
|
|
|
|
virtual mozilla::a11y::role NativeRole() override;
|
|
|
|
virtual uint64_t NativeState() override;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2015-03-21 09:28:04 -07:00
|
|
|
virtual void InvalidateChildren() override;
|
|
|
|
virtual bool RemoveChild(Accessible* aAccessible) override;
|
2015-06-24 06:40:00 -07:00
|
|
|
virtual Relation RelationByType(RelationType aType) override;
|
2010-06-21 06:08:27 -07:00
|
|
|
|
2012-05-31 01:04:41 -07:00
|
|
|
// HyperTextAccessible (static helper method)
|
2010-06-21 06:08:27 -07:00
|
|
|
|
2013-11-18 05:19:33 -08:00
|
|
|
// Convert content offset to rendered text offset
|
2013-04-05 01:15:26 -07:00
|
|
|
nsresult ContentToRenderedOffset(nsIFrame *aFrame, int32_t aContentOffset,
|
2013-11-18 05:19:33 -08:00
|
|
|
uint32_t *aRenderedOffset) const;
|
|
|
|
|
2007-08-03 18:12:24 -07:00
|
|
|
// Convert rendered text offset to content offset
|
2013-04-05 01:15:26 -07:00
|
|
|
nsresult RenderedToContentOffset(nsIFrame *aFrame, uint32_t aRenderedOffset,
|
2013-11-18 05:19:33 -08:00
|
|
|
int32_t *aContentOffset) const;
|
2007-08-03 18:12:24 -07:00
|
|
|
|
2011-01-24 19:33:47 -08:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
// HyperLinkAccessible
|
|
|
|
|
2010-06-21 06:08:27 -07:00
|
|
|
/**
|
|
|
|
* Return link count within this hypertext accessible.
|
|
|
|
*/
|
2013-11-18 05:19:33 -08:00
|
|
|
uint32_t LinkCount()
|
|
|
|
{ return EmbeddedChildCount(); }
|
2010-06-21 06:08:27 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return link accessible at the given index.
|
|
|
|
*/
|
2013-11-18 05:19:33 -08:00
|
|
|
Accessible* LinkAt(uint32_t aIndex)
|
2010-06-21 06:08:27 -07:00
|
|
|
{
|
2010-08-15 04:28:49 -07:00
|
|
|
return GetEmbeddedChildAt(aIndex);
|
2010-06-21 06:08:27 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return index for the given link accessible.
|
|
|
|
*/
|
2013-11-18 05:19:33 -08:00
|
|
|
int32_t LinkIndexOf(Accessible* aLink)
|
2010-06-21 06:08:27 -07:00
|
|
|
{
|
2010-08-15 04:28:49 -07:00
|
|
|
return GetIndexOfEmbeddedChild(aLink);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return link accessible at the given text offset.
|
|
|
|
*/
|
2013-11-18 05:19:33 -08:00
|
|
|
int32_t LinkIndexAtOffset(uint32_t aOffset)
|
2010-08-15 04:28:49 -07:00
|
|
|
{
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* child = GetChildAtOffset(aOffset);
|
2013-11-18 05:19:33 -08:00
|
|
|
return child ? LinkIndexOf(child) : -1;
|
2010-06-21 06:08:27 -07:00
|
|
|
}
|
|
|
|
|
2011-01-24 19:33:47 -08:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
2012-05-31 01:04:41 -07:00
|
|
|
// HyperTextAccessible: DOM point to text offset conversions.
|
2011-01-24 19:33:47 -08:00
|
|
|
|
2007-07-25 04:54:15 -07:00
|
|
|
/**
|
2014-02-03 16:56:45 -08:00
|
|
|
* Turn a DOM point (node and offset) into a character offset of this
|
|
|
|
* hypertext. Will look for closest match when the DOM node does not have
|
|
|
|
* an accessible object associated with it. Will return an offset for the end
|
|
|
|
* of the string if the node is not found.
|
|
|
|
*
|
|
|
|
* @param aNode [in] the node to look for
|
|
|
|
* @param aNodeOffset [in] the offset to look for
|
|
|
|
* if -1 just look directly for the node
|
|
|
|
* if >=0 and aNode is text, this represents a char offset
|
|
|
|
* if >=0 and aNode is not text, this represents a child node offset
|
|
|
|
* @param aIsEndOffset [in] if true, then then this offset is not inclusive. The character
|
|
|
|
* indicated by the offset returned is at [offset - 1]. This means
|
|
|
|
* if the passed-in offset is really in a descendant, then the offset returned
|
|
|
|
* will come just after the relevant embedded object characer.
|
|
|
|
* If false, then the offset is inclusive. The character indicated
|
|
|
|
* by the offset returned is at [offset]. If the passed-in offset in inside a
|
|
|
|
* descendant, then the returned offset will be on the relevant embedded object char.
|
|
|
|
*/
|
2014-04-25 19:42:19 -07:00
|
|
|
uint32_t DOMPointToOffset(nsINode* aNode, int32_t aNodeOffset,
|
|
|
|
bool aIsEndOffset = false) const;
|
2007-07-25 04:54:15 -07:00
|
|
|
|
2014-02-05 07:21:32 -08:00
|
|
|
/**
|
|
|
|
* Transform the given a11y point into the offset relative this hypertext.
|
|
|
|
*/
|
2014-04-25 19:42:19 -07:00
|
|
|
uint32_t TransformOffset(Accessible* aDescendant, uint32_t aOffset,
|
|
|
|
bool aIsEndOffset) const;
|
2014-02-05 07:21:32 -08:00
|
|
|
|
2007-09-24 22:48:51 -07:00
|
|
|
/**
|
2015-03-03 11:25:52 -08:00
|
|
|
* Convert start and end hypertext offsets into DOM range. Note that if
|
|
|
|
* aStartOffset and/or aEndOffset is in generated content such as ::before or
|
|
|
|
* ::after, the result range excludes the generated content. See also
|
|
|
|
* ClosestNotGeneratedDOMPoint() for more information.
|
2013-12-13 08:26:35 -08:00
|
|
|
*
|
|
|
|
* @param aStartOffset [in] the given start hypertext offset
|
|
|
|
* @param aEndOffset [in] the given end hypertext offset
|
|
|
|
* @param aRange [in, out] the range whose bounds to set
|
|
|
|
* @return true if conversion was successful
|
|
|
|
*/
|
|
|
|
bool OffsetsToDOMRange(int32_t aStartOffset, int32_t aEndOffset,
|
|
|
|
nsRange* aRange);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert the given offset into DOM point.
|
2007-09-24 22:48:51 -07:00
|
|
|
*
|
2013-12-13 08:26:35 -08:00
|
|
|
* If offset is at text leaf then DOM point is (text node, offsetInTextNode),
|
|
|
|
* if before embedded object then (parent node, indexInParent), if after then
|
|
|
|
* (parent node, indexInParent + 1).
|
2007-09-24 22:48:51 -07:00
|
|
|
*/
|
2013-12-13 08:26:35 -08:00
|
|
|
DOMPoint OffsetToDOMPoint(int32_t aOffset);
|
2007-09-24 22:48:51 -07:00
|
|
|
|
2012-04-13 18:19:41 -07:00
|
|
|
/**
|
|
|
|
* Return true if the used ARIA role (if any) allows the hypertext accessible
|
|
|
|
* to expose text interfaces.
|
|
|
|
*/
|
|
|
|
bool IsTextRole();
|
|
|
|
|
2011-01-24 19:33:47 -08:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
// TextAccessible
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return character count within the hypertext accessible.
|
|
|
|
*/
|
2014-01-25 06:07:37 -08:00
|
|
|
uint32_t CharacterCount() const
|
|
|
|
{ return GetChildOffset(ChildCount()); }
|
2011-01-24 19:33:47 -08:00
|
|
|
|
2013-07-24 11:11:02 -07:00
|
|
|
/**
|
|
|
|
* Get a character at the given offset (don't support magic offsets).
|
|
|
|
*/
|
2013-12-19 11:28:51 -08:00
|
|
|
bool CharAt(int32_t aOffset, nsAString& aChar,
|
|
|
|
int32_t* aStartOffset = nullptr, int32_t* aEndOffset = nullptr)
|
2013-07-24 11:11:02 -07:00
|
|
|
{
|
2013-12-19 11:28:51 -08:00
|
|
|
NS_ASSERTION(!aStartOffset == !aEndOffset,
|
|
|
|
"Offsets should be both defined or both undefined!");
|
|
|
|
|
2013-07-24 11:11:02 -07:00
|
|
|
int32_t childIdx = GetChildIndexAtOffset(aOffset);
|
|
|
|
if (childIdx == -1)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
Accessible* child = GetChildAt(childIdx);
|
|
|
|
child->AppendTextTo(aChar, aOffset - GetChildOffset(childIdx), 1);
|
2013-12-19 11:28:51 -08:00
|
|
|
|
|
|
|
if (aStartOffset && aEndOffset) {
|
|
|
|
*aStartOffset = aOffset;
|
|
|
|
*aEndOffset = aOffset + aChar.Length();
|
|
|
|
}
|
2013-07-24 11:11:02 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-01-04 07:02:17 -08:00
|
|
|
char16_t CharAt(int32_t aOffset)
|
2013-07-24 11:11:02 -07:00
|
|
|
{
|
|
|
|
nsAutoString charAtOffset;
|
|
|
|
CharAt(aOffset, charAtOffset);
|
2013-12-19 11:28:51 -08:00
|
|
|
return charAtOffset.CharAt(0);
|
2013-07-24 11:11:02 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-12-19 11:28:51 -08:00
|
|
|
* Return true if char at the given offset equals to given char.
|
2013-07-24 11:11:02 -07:00
|
|
|
*/
|
2014-01-04 07:02:17 -08:00
|
|
|
bool IsCharAt(int32_t aOffset, char16_t aChar)
|
2013-12-19 11:28:51 -08:00
|
|
|
{ return CharAt(aOffset) == aChar; }
|
2013-07-24 11:11:02 -07:00
|
|
|
|
2011-02-03 06:29:12 -08:00
|
|
|
/**
|
2013-12-19 11:28:51 -08:00
|
|
|
* Return true if terminal char is at the given offset.
|
2011-02-03 06:29:12 -08:00
|
|
|
*/
|
2013-12-19 11:28:51 -08:00
|
|
|
bool IsLineEndCharAt(int32_t aOffset)
|
|
|
|
{ return IsCharAt(aOffset, '\n'); }
|
2011-02-03 06:29:12 -08:00
|
|
|
|
2013-11-18 05:19:33 -08:00
|
|
|
/**
|
|
|
|
* 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();
|
|
|
|
|
2010-07-01 18:50:03 -07:00
|
|
|
/**
|
2010-08-15 04:28:49 -07:00
|
|
|
* Return text offset of the given child accessible within hypertext
|
|
|
|
* accessible.
|
2010-07-01 18:50:03 -07:00
|
|
|
*
|
|
|
|
* @param aChild [in] accessible child to get text offset for
|
|
|
|
* @param aInvalidateAfter [in, optional] indicates whether invalidate
|
|
|
|
* cached offsets for next siblings of the child
|
|
|
|
*/
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t GetChildOffset(Accessible* aChild,
|
2014-01-25 06:07:37 -08:00
|
|
|
bool aInvalidateAfter = false) const
|
2010-08-15 04:28:49 -07:00
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t index = GetIndexOf(aChild);
|
2010-08-15 04:28:49 -07:00
|
|
|
return index == -1 ? -1 : GetChildOffset(index, aInvalidateAfter);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return text offset for the child accessible index.
|
|
|
|
*/
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t GetChildOffset(uint32_t aChildIndex,
|
2014-01-25 06:07:37 -08:00
|
|
|
bool aInvalidateAfter = false) const;
|
2010-07-01 18:50:03 -07:00
|
|
|
|
2010-08-15 04:28:49 -07:00
|
|
|
/**
|
|
|
|
* Return child accessible at the given text offset.
|
|
|
|
*
|
|
|
|
* @param aOffset [in] the given text offset
|
|
|
|
*/
|
2014-01-25 06:07:37 -08:00
|
|
|
int32_t GetChildIndexAtOffset(uint32_t aOffset) const;
|
2009-12-10 11:12:19 -08:00
|
|
|
|
2010-06-21 06:08:27 -07:00
|
|
|
/**
|
2010-08-15 04:28:49 -07:00
|
|
|
* Return child accessible at the given text offset.
|
|
|
|
*
|
|
|
|
* @param aOffset [in] the given text offset
|
2010-06-21 06:08:27 -07:00
|
|
|
*/
|
2014-01-25 06:07:37 -08:00
|
|
|
Accessible* GetChildAtOffset(uint32_t aOffset) const
|
2010-08-15 04:28:49 -07:00
|
|
|
{
|
|
|
|
return GetChildAt(GetChildIndexAtOffset(aOffset));
|
|
|
|
}
|
|
|
|
|
2012-03-23 11:54:55 -07:00
|
|
|
/**
|
2013-11-18 05:19:33 -08:00
|
|
|
* Return true if the given offset/range is valid.
|
2012-03-23 11:54:55 -07:00
|
|
|
*/
|
2013-11-18 05:19:33 -08:00
|
|
|
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)
|
2014-05-16 16:16:34 -07:00
|
|
|
{
|
|
|
|
int32_t endOffset = aOffset == static_cast<int32_t>(CharacterCount()) ?
|
|
|
|
aOffset : aOffset + 1;
|
|
|
|
return TextBounds(aOffset, endOffset, aCoordType);
|
|
|
|
}
|
2013-11-18 05:19:33 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get/set caret offset, if no caret then -1.
|
|
|
|
*/
|
|
|
|
int32_t CaretOffset() const;
|
2014-05-01 08:45:40 -07:00
|
|
|
void SetCaretOffset(int32_t aOffset);
|
2012-03-23 11:54:55 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Provide the line number for the caret.
|
|
|
|
* @return 1-based index for the line number with the caret
|
|
|
|
*/
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t CaretLineNumber();
|
2012-03-23 11:54:55 -07:00
|
|
|
|
2013-10-26 07:58:53 -07:00
|
|
|
/**
|
|
|
|
* Return the caret rect and the widget containing the caret within this
|
|
|
|
* text accessible.
|
|
|
|
*
|
|
|
|
* @param [out] the widget containing the caret
|
|
|
|
* @return the caret rect
|
|
|
|
*/
|
|
|
|
nsIntRect GetCaretRect(nsIWidget** aWidget);
|
|
|
|
|
2013-11-18 05:19:33 -08:00
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
|
2014-02-27 08:33:09 -08:00
|
|
|
/**
|
|
|
|
* Return a range that encloses the text control or the document this
|
|
|
|
* accessible belongs to.
|
|
|
|
*/
|
|
|
|
void EnclosingRange(TextRange& aRange) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return an array of disjoint ranges for selected text within the text control
|
|
|
|
* or the document this accessible belongs to.
|
|
|
|
*/
|
|
|
|
void SelectionRanges(nsTArray<TextRange>* aRanges) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return an array of disjoint ranges of visible text within the text control
|
|
|
|
* or the document this accessible belongs to.
|
|
|
|
*/
|
|
|
|
void VisibleRanges(nsTArray<TextRange>* aRanges) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a range containing the given accessible.
|
|
|
|
*/
|
|
|
|
void RangeByChild(Accessible* aChild, TextRange& aRange) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a range containing an accessible at the given point.
|
|
|
|
*/
|
|
|
|
void RangeAtPoint(int32_t aX, int32_t aY, TextRange& aRange) const;
|
|
|
|
|
2012-03-07 19:28:38 -08:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
// EditableTextAccessible
|
|
|
|
|
2013-11-18 05:19:33 -08:00
|
|
|
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);
|
|
|
|
|
2012-03-07 19:28:38 -08:00
|
|
|
/**
|
|
|
|
* Return the editor associated with the accessible.
|
|
|
|
*/
|
|
|
|
virtual already_AddRefed<nsIEditor> GetEditor() const;
|
|
|
|
|
2014-05-01 08:45:40 -07:00
|
|
|
/**
|
|
|
|
* Return DOM selection object for the accessible.
|
|
|
|
*/
|
|
|
|
dom::Selection* DOMSelection() const;
|
|
|
|
|
2010-08-15 04:28:49 -07:00
|
|
|
protected:
|
2014-07-08 14:23:18 -07:00
|
|
|
virtual ~HyperTextAccessible() { }
|
|
|
|
|
2012-10-13 21:18:39 -07:00
|
|
|
// Accessible
|
2015-03-21 09:28:04 -07:00
|
|
|
virtual ENameValueFlag NativeName(nsString& aName) override;
|
|
|
|
virtual void CacheChildren() override;
|
2012-10-13 21:18:39 -07:00
|
|
|
|
2012-05-31 01:04:41 -07:00
|
|
|
// HyperTextAccessible
|
2010-06-21 06:08:27 -07:00
|
|
|
|
2011-02-03 06:29:12 -08:00
|
|
|
/**
|
|
|
|
* Transform magic offset into text offset.
|
|
|
|
*/
|
2014-05-16 16:16:34 -07:00
|
|
|
index_t ConvertMagicOffset(int32_t aOffset) const;
|
2011-02-03 06:29:12 -08:00
|
|
|
|
2013-07-09 10:32:07 -07:00
|
|
|
/**
|
|
|
|
* Adjust an offset the caret stays at to get a text by line boundary.
|
|
|
|
*/
|
2014-04-25 19:42:19 -07:00
|
|
|
uint32_t AdjustCaretOffset(uint32_t aOffset) const;
|
2013-07-09 10:32:07 -07:00
|
|
|
|
2013-12-28 11:14:08 -08:00
|
|
|
/**
|
|
|
|
* Return true if caret is at end of line.
|
|
|
|
*/
|
|
|
|
bool IsCaretAtEndOfLine() const;
|
|
|
|
|
2013-07-12 10:34:13 -07:00
|
|
|
/**
|
|
|
|
* Return true if the given offset points to terminal empty line if any.
|
|
|
|
*/
|
|
|
|
bool IsEmptyLastLineOffset(int32_t aOffset)
|
|
|
|
{
|
2013-07-24 11:11:02 -07:00
|
|
|
return aOffset == static_cast<int32_t>(CharacterCount()) &&
|
|
|
|
IsLineEndCharAt(aOffset - 1);
|
2013-07-12 10:34:13 -07:00
|
|
|
}
|
|
|
|
|
2013-03-31 06:39:29 -07:00
|
|
|
/**
|
|
|
|
* Return an offset of the found word boundary.
|
|
|
|
*/
|
2014-04-25 19:42:19 -07:00
|
|
|
uint32_t FindWordBoundary(uint32_t aOffset, nsDirection aDirection,
|
2013-07-02 05:57:29 -07:00
|
|
|
EWordMovementType aWordMovementType)
|
|
|
|
{
|
2013-07-16 10:13:34 -07:00
|
|
|
return FindOffset(aOffset, aDirection, eSelectWord, aWordMovementType);
|
2013-07-02 05:57:29 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-07-16 10:13:34 -07:00
|
|
|
* Used to get begin/end of previous/this/next line. Note: end of line
|
|
|
|
* is an offset right before '\n' character if any, the offset is right after
|
|
|
|
* '\n' character is begin of line. In case of wrap word breaks these offsets
|
|
|
|
* are equal.
|
2013-07-02 05:57:29 -07:00
|
|
|
*/
|
2013-07-16 10:13:34 -07:00
|
|
|
enum EWhichLineBoundary {
|
|
|
|
ePrevLineBegin,
|
|
|
|
ePrevLineEnd,
|
|
|
|
eThisLineBegin,
|
|
|
|
eThisLineEnd,
|
|
|
|
eNextLineBegin,
|
|
|
|
eNextLineEnd
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return an offset for requested line boundary. See constants above.
|
|
|
|
*/
|
2014-04-25 19:42:19 -07:00
|
|
|
uint32_t FindLineBoundary(uint32_t aOffset,
|
|
|
|
EWhichLineBoundary aWhichLineBoundary);
|
2013-07-02 05:57:29 -07:00
|
|
|
|
|
|
|
/**
|
2013-07-16 10:13:34 -07:00
|
|
|
* Return an offset corresponding to the given direction and selection amount
|
|
|
|
* relative the given offset. A helper used to find word or line boundaries.
|
2013-07-02 05:57:29 -07:00
|
|
|
*/
|
2014-04-25 19:42:19 -07:00
|
|
|
uint32_t FindOffset(uint32_t aOffset, nsDirection aDirection,
|
|
|
|
nsSelectionAmount aAmount,
|
|
|
|
EWordMovementType aWordMovementType = eDefaultBehavior);
|
2013-03-31 06:39:29 -07:00
|
|
|
|
2013-11-25 10:28:27 -08:00
|
|
|
/**
|
|
|
|
* Return the boundaries of the substring in case of textual frame or
|
|
|
|
* frame boundaries in case of non textual frame, offsets are ignored.
|
|
|
|
*/
|
|
|
|
nsIntRect GetBoundsInFrame(nsIFrame* aFrame,
|
|
|
|
uint32_t aStartRenderedOffset,
|
|
|
|
uint32_t aEndRenderedOffset);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Selection helpers
|
2007-09-18 15:28:26 -07:00
|
|
|
|
2011-10-12 00:39:58 -07:00
|
|
|
/**
|
2014-05-01 08:45:40 -07:00
|
|
|
* Return frame selection object for the accessible.
|
2011-10-12 00:39:58 -07:00
|
|
|
*/
|
2014-02-05 14:46:05 -08:00
|
|
|
already_AddRefed<nsFrameSelection> FrameSelection() const;
|
2011-10-12 00:39:58 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return selection ranges within the accessible subtree.
|
2007-09-18 15:28:26 -07:00
|
|
|
*/
|
2012-08-22 08:56:38 -07:00
|
|
|
void GetSelectionDOMRanges(int16_t aType, nsTArray<nsRange*>* aRanges);
|
2008-07-17 05:06:24 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
nsresult SetSelectionRange(int32_t aStartPos, int32_t aEndPos);
|
2007-09-24 22:48:51 -07:00
|
|
|
|
2015-03-03 11:25:52 -08:00
|
|
|
/**
|
|
|
|
* Convert the given DOM point to a DOM point in non-generated contents.
|
|
|
|
*
|
|
|
|
* If aDOMPoint is in ::before, the result is immediately after it.
|
|
|
|
* If aDOMPoint is in ::after, the result is immediately before it.
|
|
|
|
*
|
|
|
|
* @param aDOMPoint [in] A DOM node and an index of its child. This may
|
|
|
|
* be in a generated content such as ::before or
|
|
|
|
* ::after.
|
|
|
|
* @param aElementContent [in] An nsIContent representing an element of
|
|
|
|
* aDOMPoint.node.
|
|
|
|
* @return An DOM point which must not be in generated
|
|
|
|
* contents.
|
|
|
|
*/
|
|
|
|
DOMPoint ClosestNotGeneratedDOMPoint(const DOMPoint& aDOMPoint,
|
|
|
|
nsIContent* aElementContent);
|
|
|
|
|
2007-09-24 22:48:51 -07:00
|
|
|
// Helpers
|
2012-08-22 08:56:38 -07:00
|
|
|
nsresult GetDOMPointByFrameOffset(nsIFrame* aFrame, int32_t aOffset,
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* aAccessible,
|
2012-04-06 11:08:24 -07:00
|
|
|
mozilla::a11y::DOMPoint* aPoint);
|
2008-07-17 05:06:24 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
2013-11-18 05:19:33 -08:00
|
|
|
* is used by TextAttributes() method.
|
2008-07-17 05:06:24 -07:00
|
|
|
*
|
|
|
|
* @param aIncludeDefAttrs [in] points whether text attributes having default
|
|
|
|
* values of attributes should be included
|
|
|
|
* @param aSourceNode [in] the node we start to traverse from
|
|
|
|
* @param aStartOffset [in, out] the start offset
|
|
|
|
* @param aEndOffset [in, out] the end offset
|
2008-07-24 08:20:39 -07:00
|
|
|
* @param aAttributes [out, optional] result attributes
|
2008-07-17 05:06:24 -07:00
|
|
|
*/
|
2014-04-25 19:42:19 -07:00
|
|
|
void GetSpellTextAttr(nsINode* aNode, int32_t aNodeOffset,
|
|
|
|
uint32_t* aStartOffset, uint32_t* aEndOffset,
|
|
|
|
nsIPersistentProperties* aAttributes);
|
2010-06-21 06:08:27 -07:00
|
|
|
|
2015-07-16 02:43:00 -07:00
|
|
|
/**
|
|
|
|
* Set xml-roles attributes for MathML elements.
|
|
|
|
* @param aAttributes
|
|
|
|
*/
|
|
|
|
void SetMathMLXMLRoles(nsIPersistentProperties* aAttributes);
|
|
|
|
|
2010-06-21 06:08:27 -07:00
|
|
|
private:
|
2010-07-01 18:50:03 -07:00
|
|
|
/**
|
|
|
|
* End text offsets array.
|
|
|
|
*/
|
2014-01-25 06:07:37 -08:00
|
|
|
mutable nsTArray<uint32_t> mOffsets;
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
2007-04-16 23:52:52 -07:00
|
|
|
|
2011-01-27 21:15:13 -08:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-05-28 18:18:45 -07:00
|
|
|
// Accessible downcasting method
|
2011-01-27 21:15:13 -08:00
|
|
|
|
2012-05-31 01:04:41 -07:00
|
|
|
inline HyperTextAccessible*
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::AsHyperText()
|
2011-01-27 21:15:13 -08:00
|
|
|
{
|
2012-12-17 21:22:26 -08:00
|
|
|
return IsHyperText() ? static_cast<HyperTextAccessible*>(this) : nullptr;
|
2011-01-27 21:15:13 -08:00
|
|
|
}
|
|
|
|
|
2012-11-17 18:01:44 -08:00
|
|
|
} // namespace a11y
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2012-05-31 01:04:41 -07:00
|
|
|
#endif
|
2007-07-25 04:54:15 -07:00
|
|
|
|