author | Trevor Saunders <trev.saunders@gmail.com> |
Thu, 27 Feb 2014 11:33:09 -0500 | |
changeset 189590 | 97e52c3f95ae810a6c39cbc625374d588823b9c9 |
parent 189589 | 44a165ab16707e4962f8c8a200c32c72d64b7b1d |
child 189591 | 4f08a24e4fb5e6c8cb7032b2bcfbe419125a3076 |
push id | 3503 |
push user | raliiev@mozilla.com |
push date | Mon, 28 Apr 2014 18:51:11 +0000 |
treeherder | mozilla-beta@c95ac01e332e [default view] [failures only] |
perfherder | [talos] [build metrics] [platform microbench] (compared to previous push) |
reviewers | davidb |
bugs | 969532 |
milestone | 30.0a1 |
first release with | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
last release without | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
--- a/accessible/public/moz.build +++ b/accessible/public/moz.build @@ -24,16 +24,17 @@ XPIDL_SOURCES += [ 'nsIAccessibleRole.idl', 'nsIAccessibleSelectable.idl', 'nsIAccessibleStateChangeEvent.idl', 'nsIAccessibleStates.idl', 'nsIAccessibleTable.idl', 'nsIAccessibleTableChangeEvent.idl', 'nsIAccessibleText.idl', 'nsIAccessibleTextChangeEvent.idl', + 'nsIAccessibleTextRange.idl', 'nsIAccessibleTypes.idl', 'nsIAccessibleValue.idl', 'nsIAccessibleVirtualCursorChangeEvent.idl', 'nsIXBLAccessible.idl', ] XPIDL_MODULE = 'accessibility'
--- a/accessible/public/nsIAccessibleText.idl +++ b/accessible/public/nsIAccessibleText.idl @@ -4,19 +4,21 @@ * 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 "nsISupports.idl" typedef long AccessibleTextBoundary; interface nsIAccessible; +interface nsIArray; interface nsIPersistentProperties; +interface nsIAccessibleTextRange; -[scriptable, uuid(1e63dd8b-173d-4a68-8ade-fd671abbe1ee)] +[scriptable, uuid(88789f40-54c9-494a-846d-3acaaf4cf46a)] interface nsIAccessibleText : nsISupports { // In parameters for character offsets: // -1 will be treated as the equal to the end of the text // -2 will be treated as the caret position const int32_t TEXT_OFFSET_END_OF_TEXT = -1; const int32_t TEXT_OFFSET_CARET = -2; @@ -184,16 +186,44 @@ interface nsIAccessibleText : nsISupport * constants refer to nsIAccessibleCoordinateType) * @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); + + /** + * Return a range that encloses this text control or otherwise the document + * this text accessible belongs to. + */ + readonly attribute nsIAccessibleTextRange enclosingRange; + + /** + * Return an array of disjoint ranges for selected text within the text control + * or otherwise the document this accessible belongs to. + */ + readonly attribute nsIArray selectionRanges; + + /** + * Return an array of disjoint ranges of visible text within the text control + * or otherwise the document this accessible belongs to. + */ + readonly attribute nsIArray visibleRanges; + + /** + * Return a range containing the given accessible. + */ + nsIAccessibleTextRange getRangeByChild(in nsIAccessible child); + + /** + * Return a range containing an accessible at the given point. + */ + nsIAccessibleTextRange getRangeAtPoint(in long x, in long y); }; /* Assumptions: Using wstring (UCS2) instead of string encoded in UTF-8. Multibyte encodings (or at least potentially multi-byte encodings) would be preferred for the reasons cited above.
new file mode 100644 --- /dev/null +++ b/accessible/public/nsIAccessibleTextRange.idl @@ -0,0 +1,25 @@ +/* -*- 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 "nsISupports.idl" + +interface nsIAccessible; + +/** + * A range representing a piece of text in the document. + */ +[scriptable, uuid(6fe17c33-6709-4d7a-9ba0-3d448c4b3ef4)] +interface nsIAccessibleTextRange : nsISupports +{ + readonly attribute nsIAccessible startContainer; + readonly attribute long startOffset; + readonly attribute nsIAccessible endContainer; + readonly attribute long endOffset; + + /** + * Return text within the range. + */ + readonly attribute AString text; +};
new file mode 100644 --- /dev/null +++ b/accessible/src/base/TextRange.cpp @@ -0,0 +1,25 @@ +/* -*- 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 "TextRange.h" + +#include "HyperTextAccessible.h" + +using namespace mozilla::a11y; + +TextRange::TextRange(HyperTextAccessible* aRoot, + Accessible* aStartContainer, int32_t aStartOffset, + Accessible* aEndContainer, int32_t aEndOffset) : + mRoot(aRoot), mStartContainer(aStartContainer), mEndContainer(aEndContainer), + mStartOffset(aStartOffset), mEndOffset(aEndOffset) +{ +} + +void +TextRange::Text(nsAString& aText) const +{ + +}
new file mode 100644 --- /dev/null +++ b/accessible/src/base/TextRange.h @@ -0,0 +1,66 @@ +/* -*- 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_TextRange_h__ +#define mozilla_a11y_TextRange_h__ + +#include "mozilla/Move.h" +#include "nsAutoPtr.h" + +namespace mozilla { +namespace a11y { + +class Accessible; +class HyperTextAccessible; + +/** + * Represents a text range within the text control or document. + */ +class TextRange MOZ_FINAL +{ +public: + TextRange(HyperTextAccessible* aRoot, + Accessible* aStartContainer, int32_t aStartOffset, + Accessible* aEndContainer, int32_t aEndOffset); + TextRange() {} + TextRange(TextRange&& aRange) : + mRoot(Move(aRange.mRoot)), mStartContainer(Move(aRange.mStartContainer)), + mEndContainer(Move(aRange.mEndContainer)), + mStartOffset(aRange.mStartOffset), mEndOffset(aRange.mEndOffset) {} + + Accessible* StartContainer() const { return mStartContainer; } + int32_t StartOffset() const { return mStartOffset; } + Accessible* EndContainer() const { return mEndContainer; } + int32_t EndOffset() const { return mEndOffset; } + + /** + * Return text enclosed by the range. + */ + void Text(nsAString& aText) const; + + /** + * Return true if this TextRange object represents an actual range of text. + */ + bool IsValid() const { return mRoot; } + +private: + friend class HyperTextAccessible; + + TextRange(const TextRange&) MOZ_DELETE; + TextRange& operator=(const TextRange&) MOZ_DELETE; + + const nsRefPtr<HyperTextAccessible> mRoot; + nsRefPtr<Accessible> mStartContainer; + nsRefPtr<Accessible> mEndContainer; + int32_t mStartOffset; + int32_t mEndOffset; +}; + + +} // namespace a11y +} // namespace mozilla + +#endif
--- a/accessible/src/base/moz.build +++ b/accessible/src/base/moz.build @@ -42,16 +42,17 @@ UNIFIED_SOURCES += [ 'nsAccessiblePivot.cpp', 'nsAccUtils.cpp', 'nsCoreUtils.cpp', 'nsEventShell.cpp', 'nsTextEquivUtils.cpp', 'SelectionManager.cpp', 'StyleInfo.cpp', 'TextAttrs.cpp', + 'TextRange.cpp', 'TextUpdater.cpp', 'TreeWalker.cpp', ] if CONFIG['A11Y_LOG']: UNIFIED_SOURCES += [ 'Logging.cpp', ]
--- a/accessible/src/generic/HyperTextAccessible.cpp +++ b/accessible/src/generic/HyperTextAccessible.cpp @@ -9,16 +9,17 @@ #include "Accessible-inl.h" #include "nsAccessibilityService.h" #include "nsIAccessibleTypes.h" #include "DocAccessible.h" #include "HTMLListAccessible.h" #include "Role.h" #include "States.h" #include "TextAttrs.h" +#include "TextRange.h" #include "TreeWalker.h" #include "nsCaret.h" #include "nsContentUtils.h" #include "nsFocusManager.h" #include "nsIDOMRange.h" #include "nsIEditingSession.h" #include "nsIFrame.h" @@ -1499,16 +1500,43 @@ HyperTextAccessible::ScrollSubstringToPo // traversed scrollable area. nsCoreUtils::ScrollFrameToPoint(parentFrame, frame, coords); } } frame = parentFrame; } } +void +HyperTextAccessible::EnclosingRange(a11y::TextRange& aRange) const +{ +} + +void +HyperTextAccessible::SelectionRanges(nsTArray<a11y::TextRange>* aRanges) const +{ +} + +void +HyperTextAccessible::VisibleRanges(nsTArray<a11y::TextRange>* aRanges) const +{ +} + +void +HyperTextAccessible::RangeByChild(Accessible* aChild, + a11y::TextRange& aRange) const +{ +} + +void +HyperTextAccessible::RangeAtPoint(int32_t aX, int32_t aY, + a11y::TextRange& aRange) const +{ +} + //////////////////////////////////////////////////////////////////////////////// // Accessible public // Accessible protected ENameValueFlag HyperTextAccessible::NativeName(nsString& aName) { // Check @alt attribute for invalid img elements.
--- a/accessible/src/generic/HyperTextAccessible.h +++ b/accessible/src/generic/HyperTextAccessible.h @@ -11,16 +11,18 @@ #include "xpcAccessibleHyperText.h" #include "nsFrameSelection.h" #include "nsISelectionController.h" namespace mozilla { namespace a11y { +class TextRange; + struct DOMPoint { DOMPoint() : node(nullptr), idx(0) { } DOMPoint(nsINode* aNode, int32_t aIdx) : node(aNode), idx(aIdx) { } nsINode* node; int32_t idx; }; @@ -356,16 +358,44 @@ public: /** * 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); + /** + * 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; + ////////////////////////////////////////////////////////////////////////////// // 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);
--- a/accessible/src/xpcom/moz.build +++ b/accessible/src/xpcom/moz.build @@ -11,16 +11,17 @@ EXPORTS += [ ] UNIFIED_SOURCES += [ 'nsAccessibleRelation.cpp', 'xpcAccessibleHyperText.cpp', 'xpcAccessibleSelectable.cpp', 'xpcAccessibleTable.cpp', 'xpcAccessibleTableCell.cpp', + 'xpcAccessibleTextRange.cpp', 'xpcAccessibleValue.cpp', ] GENERATED_SOURCES += [ 'xpcAccEvents.cpp', ] LOCAL_INCLUDES += [
--- a/accessible/src/xpcom/xpcAccessibleHyperText.cpp +++ b/accessible/src/xpcom/xpcAccessibleHyperText.cpp @@ -2,18 +2,21 @@ /* 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 "TextRange.h" +#include "xpcAccessibleTextRange.h" #include "nsIPersistentProperties2.h" +#include "nsIMutableArray.h" using namespace mozilla::a11y; //////////////////////////////////////////////////////////////////////////////// // nsISupports nsresult xpcAccessibleHyperText::QueryInterface(REFNSIID aIID, void** aInstancePtr) @@ -358,16 +361,129 @@ xpcAccessibleHyperText::ScriptableScroll HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this); if (text->IsDefunct()) return NS_ERROR_FAILURE; text->ScrollSubstringToPoint(aStartOffset, aEndOffset, aCoordinateType, aX, aY); return NS_OK; } +NS_IMETHODIMP +xpcAccessibleHyperText::GetEnclosingRange(nsIAccessibleTextRange** aRange) +{ + NS_ENSURE_ARG_POINTER(aRange); + *aRange = nullptr; + + HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this); + if (text->IsDefunct()) + return NS_ERROR_FAILURE; + + nsRefPtr<xpcAccessibleTextRange> range = new xpcAccessibleTextRange; + text->EnclosingRange(range->mRange); + NS_ASSERTION(range->mRange.IsValid(), + "Should always have an enclosing range!"); + + range.forget(aRange); + + return NS_OK; +} + +NS_IMETHODIMP +xpcAccessibleHyperText::GetSelectionRanges(nsIArray** aRanges) +{ + NS_ENSURE_ARG_POINTER(aRanges); + *aRanges = nullptr; + + HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this); + if (text->IsDefunct()) + return NS_ERROR_FAILURE; + + nsresult rv = NS_OK; + nsCOMPtr<nsIMutableArray> xpcRanges = + do_CreateInstance(NS_ARRAY_CONTRACTID, &rv); + NS_ENSURE_SUCCESS(rv, rv); + + nsAutoTArray<TextRange, 1> ranges; + text->SelectionRanges(&ranges); + uint32_t len = ranges.Length(); + for (uint32_t idx = 0; idx < len; idx++) + xpcRanges->AppendElement(new xpcAccessibleTextRange(Move(ranges[idx])), + false); + + xpcRanges.forget(aRanges); + return NS_OK; +} + +NS_IMETHODIMP +xpcAccessibleHyperText::GetVisibleRanges(nsIArray** aRanges) +{ + NS_ENSURE_ARG_POINTER(aRanges); + *aRanges = nullptr; + + HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this); + if (text->IsDefunct()) + return NS_ERROR_FAILURE; + + nsresult rv = NS_OK; + nsCOMPtr<nsIMutableArray> xpcRanges = + do_CreateInstance(NS_ARRAY_CONTRACTID, &rv); + NS_ENSURE_SUCCESS(rv, rv); + + nsTArray<TextRange> ranges; + text->VisibleRanges(&ranges); + uint32_t len = ranges.Length(); + for (uint32_t idx = 0; idx < len; idx++) + xpcRanges->AppendElement(new xpcAccessibleTextRange(Move(ranges[idx])), + false); + + xpcRanges.forget(aRanges); + return NS_OK; +} + +NS_IMETHODIMP +xpcAccessibleHyperText::GetRangeByChild(nsIAccessible* aChild, + nsIAccessibleTextRange** aRange) +{ + NS_ENSURE_ARG_POINTER(aRange); + *aRange = nullptr; + + HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this); + if (text->IsDefunct()) + return NS_ERROR_FAILURE; + + nsRefPtr<Accessible> child = do_QueryObject(aChild); + if (child) { + nsRefPtr<xpcAccessibleTextRange> range = new xpcAccessibleTextRange; + text->RangeByChild(child, range->mRange); + if (range->mRange.IsValid()) + range.forget(aRange); + } + + return NS_OK; +} + +NS_IMETHODIMP +xpcAccessibleHyperText::GetRangeAtPoint(int32_t aX, int32_t aY, + nsIAccessibleTextRange** aRange) +{ + NS_ENSURE_ARG_POINTER(aRange); + *aRange = nullptr; + + HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this); + if (text->IsDefunct()) + return NS_ERROR_FAILURE; + + nsRefPtr<xpcAccessibleTextRange> range = new xpcAccessibleTextRange; + text->RangeAtPoint(aX, aY, range->mRange); + if (range->mRange.IsValid()) + range.forget(aRange); + + return NS_OK; +} + //////////////////////////////////////////////////////////////////////////////// // nsIAccessibleEditableText NS_IMETHODIMP xpcAccessibleHyperText::SetTextContents(const nsAString& aText) { HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this); if (text->IsDefunct())
new file mode 100644 --- /dev/null +++ b/accessible/src/xpcom/xpcAccessibleTextRange.cpp @@ -0,0 +1,60 @@ +/* -*- 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 "xpcAccessibleTextRange.h" + +#include "HyperTextAccessible.h" +#include "TextRange.h" + +using namespace mozilla; +using namespace mozilla::a11y; + +// nsISupports +NS_IMPL_ISUPPORTS1(xpcAccessibleTextRange, nsIAccessibleTextRange) + +// nsIAccessibleTextRange + +NS_IMETHODIMP +xpcAccessibleTextRange::GetStartContainer(nsIAccessible** aAnchor) +{ + NS_ENSURE_ARG_POINTER(aAnchor); + *aAnchor = static_cast<nsIAccessible*>(mRange.StartContainer()); + return NS_OK; +} + +NS_IMETHODIMP +xpcAccessibleTextRange::GetStartOffset(int32_t* aOffset) +{ + NS_ENSURE_ARG_POINTER(aOffset); + *aOffset = mRange.StartOffset(); + return NS_OK; +} + +NS_IMETHODIMP +xpcAccessibleTextRange::GetEndContainer(nsIAccessible** aAnchor) +{ + NS_ENSURE_ARG_POINTER(aAnchor); + *aAnchor = static_cast<nsIAccessible*>(mRange.EndContainer()); + return NS_OK; +} + +NS_IMETHODIMP +xpcAccessibleTextRange::GetEndOffset(int32_t* aOffset) +{ + NS_ENSURE_ARG_POINTER(aOffset); + *aOffset = mRange.EndOffset(); + return NS_OK; +} + +NS_IMETHODIMP +xpcAccessibleTextRange::GetText(nsAString& aText) +{ + nsAutoString text; + mRange.Text(text); + aText.Assign(text); + + return NS_OK; +}
new file mode 100644 --- /dev/null +++ b/accessible/src/xpcom/xpcAccessibleTextRange.h @@ -0,0 +1,46 @@ +/* -*- 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_xpcAccessibleTextRange_h_ +#define mozilla_a11y_xpcAccessibleTextRange_h_ + +#include "nsIAccessibleTextRange.h" +#include "TextRange.h" + +#include "mozilla/Move.h" + +namespace mozilla { +namespace a11y { + +class TextRange; + +class xpcAccessibleTextRange MOZ_FINAL : public nsIAccessibleTextRange +{ +public: + NS_DECL_ISUPPORTS + + NS_IMETHOD GetStartContainer(nsIAccessible** aAnchor) MOZ_FINAL MOZ_OVERRIDE; + NS_IMETHOD GetStartOffset(int32_t* aOffset) MOZ_FINAL MOZ_OVERRIDE; + NS_IMETHOD GetEndContainer(nsIAccessible** aAnchor) MOZ_FINAL MOZ_OVERRIDE; + NS_IMETHOD GetEndOffset(int32_t* aOffset) MOZ_FINAL MOZ_OVERRIDE; + NS_IMETHOD GetText(nsAString& aText) MOZ_FINAL MOZ_OVERRIDE; + +private: + xpcAccessibleTextRange(TextRange&& aRange) : + mRange(Forward<TextRange>(aRange)) {} + xpcAccessibleTextRange() {} + friend class xpcAccessibleHyperText; + + xpcAccessibleTextRange(const xpcAccessibleTextRange&) MOZ_DELETE; + xpcAccessibleTextRange& operator =(const xpcAccessibleTextRange&) MOZ_DELETE; + + TextRange mRange; +}; + +} // namespace a11y +} // namespace mozilla + +#endif