diff --git a/accessible/ipc/DocAccessibleChild.cpp b/accessible/ipc/DocAccessibleChild.cpp index 61c76d8555cc..a88edd32ea33 100644 --- a/accessible/ipc/DocAccessibleChild.cpp +++ b/accessible/ipc/DocAccessibleChild.cpp @@ -294,13 +294,14 @@ bool DocAccessibleChild::RecvTextSubstring(const uint64_t& aID, const int32_t& aStartOffset, const int32_t& aEndOffset, - nsString* aText) + nsString* aText, bool* aValid) { HyperTextAccessible* acc = IdToHyperTextAccessible(aID); if (!acc) { return true; } + *aValid = acc->IsValidRange(aStartOffset, aEndOffset); acc->TextSubstring(aStartOffset, aEndOffset, *aText); return true; } @@ -561,10 +562,11 @@ DocAccessibleChild::RecvReplaceText(const uint64_t& aID, bool DocAccessibleChild::RecvInsertText(const uint64_t& aID, const nsString& aText, - const int32_t& aPosition) + const int32_t& aPosition, bool* aValid) { HyperTextAccessible* acc = IdToHyperTextAccessible(aID); if (acc && acc->IsTextRole()) { + *aValid = acc->IsValidOffset(aPosition); acc->InsertText(aText, aPosition); } @@ -574,7 +576,7 @@ DocAccessibleChild::RecvInsertText(const uint64_t& aID, bool DocAccessibleChild::RecvCopyText(const uint64_t& aID, const int32_t& aStartPos, - const int32_t& aEndPos) + const int32_t& aEndPos, bool* aValid) { HyperTextAccessible* acc = IdToHyperTextAccessible(aID); if (acc && acc->IsTextRole()) { @@ -587,10 +589,11 @@ DocAccessibleChild::RecvCopyText(const uint64_t& aID, bool DocAccessibleChild::RecvCutText(const uint64_t& aID, const int32_t& aStartPos, - const int32_t& aEndPos) + const int32_t& aEndPos, bool* aValid) { HyperTextAccessible* acc = IdToHyperTextAccessible(aID); if (acc && acc->IsTextRole()) { + *aValid = acc->IsValidRange(aStartPos, aEndPos); acc->CutText(aStartPos, aEndPos); } @@ -600,10 +603,11 @@ DocAccessibleChild::RecvCutText(const uint64_t& aID, bool DocAccessibleChild::RecvDeleteText(const uint64_t& aID, const int32_t& aStartPos, - const int32_t& aEndPos) + const int32_t& aEndPos, bool* aValid) { HyperTextAccessible* acc = IdToHyperTextAccessible(aID); if (acc && acc->IsTextRole()) { + *aValid = acc->IsValidRange(aStartPos, aEndPos); acc->DeleteText(aStartPos, aEndPos); } @@ -612,10 +616,11 @@ DocAccessibleChild::RecvDeleteText(const uint64_t& aID, bool DocAccessibleChild::RecvPasteText(const uint64_t& aID, - const int32_t& aPosition) + const int32_t& aPosition, bool* aValid) { HyperTextAccessible* acc = IdToHyperTextAccessible(aID); if (acc && acc->IsTextRole()) { + *aValid = acc->IsValidOffset(aPosition); acc->PasteText(aPosition); } diff --git a/accessible/ipc/DocAccessibleChild.h b/accessible/ipc/DocAccessibleChild.h index 8e8a63537bed..ebd07f44f4c8 100644 --- a/accessible/ipc/DocAccessibleChild.h +++ b/accessible/ipc/DocAccessibleChild.h @@ -75,8 +75,8 @@ public: virtual bool RecvTextSubstring(const uint64_t& aID, const int32_t& aStartOffset, - const int32_t& aEndOffset, nsString* aText) - override; + const int32_t& aEndOffset, nsString* aText, + bool* aValid) override; virtual bool RecvGetTextAfterOffset(const uint64_t& aID, const int32_t& aOffset, @@ -166,22 +166,22 @@ public: virtual bool RecvInsertText(const uint64_t& aID, const nsString& aText, - const int32_t& aPosition) override; + const int32_t& aPosition, bool* aValid) override; virtual bool RecvCopyText(const uint64_t& aID, const int32_t& aStartPos, - const int32_t& aEndPos) override; + const int32_t& aEndPos, bool* aValid) override; virtual bool RecvCutText(const uint64_t& aID, const int32_t& aStartPos, - const int32_t& aEndPos) override; + const int32_t& aEndPos, bool* aValid) override; virtual bool RecvDeleteText(const uint64_t& aID, const int32_t& aStartPos, - const int32_t& aEndPos) override; + const int32_t& aEndPos, bool* aValid) override; virtual bool RecvPasteText(const uint64_t& aID, - const int32_t& aPosition) override; + const int32_t& aPosition, bool* aValid) override; virtual bool RecvImagePosition(const uint64_t& aID, const uint32_t& aCoordType, diff --git a/accessible/ipc/PDocAccessible.ipdl b/accessible/ipc/PDocAccessible.ipdl index 7127a1c4bbd5..689879254d80 100644 --- a/accessible/ipc/PDocAccessible.ipdl +++ b/accessible/ipc/PDocAccessible.ipdl @@ -82,7 +82,7 @@ child: prio(high) sync CharacterCount(uint64_t aID) returns(int32_t aCount); prio(high) sync SelectionCount(uint64_t aID) returns(int32_t aCount); prio(high) sync TextSubstring(uint64_t aID, int32_t aStartOffset, int32_t - aEndOffset) returns(nsString aText); + aEndOffset) returns(nsString aText, bool aValid); prio(high) sync GetTextAfterOffset(uint64_t aID, int32_t aOffset, int32_t aBoundaryType) returns(nsString aText, int32_t aStartOffset, int32_t aEndOffset); prio(high) sync GetTextAtOffset(uint64_t aID, int32_t aOffset, int32_t aBoundaryType) @@ -124,11 +124,16 @@ child: int32_t aX, int32_t aY); prio(high) sync ReplaceText(uint64_t aID, nsString aText); - prio(high) sync InsertText(uint64_t aID, nsString aText, int32_t aPosition); - prio(high) sync CopyText(uint64_t aID, int32_t aStartPos, int32_t aEndPos); - prio(high) sync CutText(uint64_t aID, int32_t aStartPos, int32_t aEndPos); - prio(high) sync DeleteText(uint64_t aID, int32_t aStartPos, int32_t aEndPos); - prio(high) sync PasteText(uint64_t aID, int32_t aPosition); + prio(high) sync InsertText(uint64_t aID, nsString aText, int32_t aPosition) + returns(bool aValid); + prio(high) sync CopyText(uint64_t aID, int32_t aStartPos, int32_t aEndPos) + returns(bool aValid); + prio(high) sync CutText(uint64_t aID, int32_t aStartPos, int32_t aEndPos) + returns(bool aValid); + prio(high) sync DeleteText(uint64_t aID, int32_t aStartPos, int32_t aEndPos) + returns(bool aValid); + prio(high) sync PasteText(uint64_t aID, int32_t aPosition) + returns(bool aValid); prio(high) sync ImagePosition(uint64_t aID, uint32_t aCoordType) returns(nsIntPoint aRetVal); prio(high) sync ImageSize(uint64_t aID) returns(IntSize aRetVal); diff --git a/accessible/ipc/ProxyAccessible.cpp b/accessible/ipc/ProxyAccessible.cpp index f2bf27df2857..be1bc1676736 100644 --- a/accessible/ipc/ProxyAccessible.cpp +++ b/accessible/ipc/ProxyAccessible.cpp @@ -181,11 +181,13 @@ ProxyAccessible::SelectionCount() return count; } -void +bool ProxyAccessible::TextSubstring(int32_t aStartOffset, int32_t aEndOfset, nsString& aText) const { - unused << mDoc->SendTextSubstring(mID, aStartOffset, aEndOfset, &aText); + bool valid; + unused << mDoc->SendTextSubstring(mID, aStartOffset, aEndOfset, &aText, &valid); + return valid; } void @@ -333,34 +335,44 @@ ProxyAccessible::ReplaceText(const nsString& aText) unused << mDoc->SendReplaceText(mID, aText); } -void +bool ProxyAccessible::InsertText(const nsString& aText, int32_t aPosition) { - unused << mDoc->SendInsertText(mID, aText, aPosition); + bool valid; + unused << mDoc->SendInsertText(mID, aText, aPosition, &valid); + return valid; } -void +bool ProxyAccessible::CopyText(int32_t aStartPos, int32_t aEndPos) { - unused << mDoc->SendCopyText(mID, aStartPos, aEndPos); + bool valid; + unused << mDoc->SendCopyText(mID, aStartPos, aEndPos, &valid); + return valid; } -void +bool ProxyAccessible::CutText(int32_t aStartPos, int32_t aEndPos) { - unused << mDoc->SendCutText(mID, aStartPos, aEndPos); + bool valid; + unused << mDoc->SendCutText(mID, aStartPos, aEndPos, &valid); + return valid; } -void +bool ProxyAccessible::DeleteText(int32_t aStartPos, int32_t aEndPos) { - unused << mDoc->SendDeleteText(mID, aStartPos, aEndPos); + bool valid; + unused << mDoc->SendDeleteText(mID, aStartPos, aEndPos, &valid); + return valid; } -void +bool ProxyAccessible::PasteText(int32_t aPosition) { - unused << mDoc->SendPasteText(mID, aPosition); + bool valid; + unused << mDoc->SendPasteText(mID, aPosition, &valid); + return valid; } nsIntPoint diff --git a/accessible/ipc/ProxyAccessible.h b/accessible/ipc/ProxyAccessible.h index 164a301c34a7..b9836b368a82 100644 --- a/accessible/ipc/ProxyAccessible.h +++ b/accessible/ipc/ProxyAccessible.h @@ -114,7 +114,7 @@ public: /** * Get the text between the given offsets. */ - void TextSubstring(int32_t aStartOffset, int32_t aEndOfset, + bool TextSubstring(int32_t aStartOffset, int32_t aEndOfset, nsString& aText) const; void GetTextAfterOffset(int32_t aOffset, AccessibleTextBoundary aBoundaryType, @@ -169,15 +169,15 @@ public: void ReplaceText(const nsString& aText); - void InsertText(const nsString& aText, int32_t aPosition); + bool InsertText(const nsString& aText, int32_t aPosition); - void CopyText(int32_t aStartPos, int32_t aEndPos); + bool CopyText(int32_t aStartPos, int32_t aEndPos); - void CutText(int32_t aStartPos, int32_t aEndPos); + bool CutText(int32_t aStartPos, int32_t aEndPos); - void DeleteText(int32_t aStartPos, int32_t aEndPos); + bool DeleteText(int32_t aStartPos, int32_t aEndPos); - void PasteText(int32_t aPosition); + bool PasteText(int32_t aPosition); nsIntPoint ImagePosition(uint32_t aCoordType); diff --git a/accessible/windows/ProxyWrappers.h b/accessible/windows/ProxyWrappers.h new file mode 100644 index 000000000000..42aa00345176 --- /dev/null +++ b/accessible/windows/ProxyWrappers.h @@ -0,0 +1,52 @@ +/* -*- 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_ProxyWrappers_h +#define MOZILLA_A11Y_ProxyWrappers_h + +#include "HyperTextAccessible.h" + +namespace mozilla { +namespace a11y { + +class ProxyAccessibleWrap : public AccessibleWrap +{ + public: + ProxyAccessibleWrap(ProxyAccessible* aProxy) : + AccessibleWrap(nullptr, nullptr) + { + mType = eProxyType; + mBits.proxy = aProxy; + } + + virtual void Shutdown() override + { + mBits.proxy = nullptr; + } +}; + +class HyperTextProxyAccessibleWrap : public ProxyAccessibleWrap, + public ia2AccessibleEditableText, + public ia2AccessibleHypertext +{ + HyperTextProxyAccessibleWrap(ProxyAccessible* aProxy) : + ProxyAccessibleWrap(aProxy) {} +}; + +template +inline ProxyAccessible* +HyperTextProxyFor(T* aWrapper) +{ + static_assert(mozilla::IsBaseOf::value, "only IAccessible* should be passed in"); + auto wrapper = static_cast(aWrapper); + return wrapper->IsProxy() ? wrapper->Proxy() : nullptr; +} + +} +} + +#endif diff --git a/accessible/windows/ia2/ia2Accessible.cpp b/accessible/windows/ia2/ia2Accessible.cpp index b708300f050d..cd15a963c459 100644 --- a/accessible/windows/ia2/ia2Accessible.cpp +++ b/accessible/windows/ia2/ia2Accessible.cpp @@ -619,22 +619,7 @@ ia2Accessible::get_attributes(BSTR* aAttributes) nsTArray attrs; acc->Proxy()->Attributes(&attrs); - nsString attrStr; - size_t attrCount = attrs.Length(); - for (size_t i = 0; i < attrCount; i++) { - EscapeAttributeChars(attrs[i].Name()); - EscapeAttributeChars(attrs[i].Value()); - AppendUTF8toUTF16(attrs[i].Name(), attrStr); - attrStr.Append(':'); - attrStr.Append(attrs[i].Value()); - attrStr.Append(';'); - } - - if (attrStr.IsEmpty()) - return S_FALSE; - - *aAttributes = ::SysAllocStringLen(attrStr.get(), attrStr.Length()); - return *aAttributes ? S_OK : E_OUTOFMEMORY; + return ConvertToIA2Attributes(&attrs, aAttributes); A11Y_TRYBLOCK_END } @@ -747,6 +732,28 @@ EscapeAttributeChars(String& aStr) } } +HRESULT +ia2Accessible::ConvertToIA2Attributes(nsTArray* aAttributes, + BSTR* aIA2Attributes) +{ + nsString attrStr; + size_t attrCount = aAttributes->Length(); + for (size_t i = 0; i < attrCount; i++) { + EscapeAttributeChars(aAttributes->ElementAt(i).Name()); + EscapeAttributeChars(aAttributes->ElementAt(i).Value()); + AppendUTF8toUTF16(aAttributes->ElementAt(i).Name(), attrStr); + attrStr.Append(':'); + attrStr.Append(aAttributes->ElementAt(i).Value()); + attrStr.Append(';'); + } + + if (attrStr.IsEmpty()) + return S_FALSE; + + *aIA2Attributes = ::SysAllocStringLen(attrStr.get(), attrStr.Length()); + return *aIA2Attributes ? S_OK : E_OUTOFMEMORY; +} + HRESULT ia2Accessible::ConvertToIA2Attributes(nsIPersistentProperties* aAttributes, BSTR* aIA2Attributes) diff --git a/accessible/windows/ia2/ia2Accessible.h b/accessible/windows/ia2/ia2Accessible.h index 7a14f960d8da..0dba1b953706 100644 --- a/accessible/windows/ia2/ia2Accessible.h +++ b/accessible/windows/ia2/ia2Accessible.h @@ -13,6 +13,7 @@ namespace mozilla { namespace a11y { +class Attribute; class ia2Accessible : public IAccessible2_2 { @@ -106,6 +107,8 @@ public: // Helper method static HRESULT ConvertToIA2Attributes(nsIPersistentProperties* aAttributes, BSTR* aIA2Attributes); + static HRESULT ConvertToIA2Attributes(nsTArray* aAttributes, + BSTR* aIA2Attributes); }; } // namespace a11y diff --git a/accessible/windows/ia2/ia2AccessibleEditableText.cpp b/accessible/windows/ia2/ia2AccessibleEditableText.cpp index 668f6ff43f1c..4685a2df9756 100644 --- a/accessible/windows/ia2/ia2AccessibleEditableText.cpp +++ b/accessible/windows/ia2/ia2AccessibleEditableText.cpp @@ -10,6 +10,7 @@ #include "AccessibleEditableText_i.c" #include "HyperTextAccessible-inl.h" #include "HyperTextAccessibleWrap.h" +#include "ProxyWrappers.h" #include "nsCOMPtr.h" #include "nsString.h" @@ -23,6 +24,10 @@ ia2AccessibleEditableText::copyText(long aStartOffset, long aEndOffset) { A11Y_TRYBLOCK_BEGIN + if (ProxyAccessible* proxy = HyperTextProxyFor(this)) { + return proxy->CopyText(aStartOffset, aEndOffset) ? S_OK : E_INVALIDARG; + } + HyperTextAccessible* textAcc = static_cast(this); if (textAcc->IsDefunct()) return CO_E_OBJNOTCONNECTED; @@ -41,6 +46,10 @@ ia2AccessibleEditableText::deleteText(long aStartOffset, long aEndOffset) { A11Y_TRYBLOCK_BEGIN + if (ProxyAccessible* proxy = HyperTextProxyFor(this)) { + return proxy->DeleteText(aStartOffset, aEndOffset) ? S_OK : E_INVALIDARG; + } + HyperTextAccessible* textAcc = static_cast(this); if (textAcc->IsDefunct()) return CO_E_OBJNOTCONNECTED; @@ -59,6 +68,12 @@ ia2AccessibleEditableText::insertText(long aOffset, BSTR *aText) { A11Y_TRYBLOCK_BEGIN + uint32_t length = ::SysStringLen(*aText); + nsAutoString text(*aText, length); + if (ProxyAccessible* proxy = HyperTextProxyFor(this)) { + return proxy->InsertText(text, aOffset) ? S_OK : E_INVALIDARG; + } + HyperTextAccessible* textAcc = static_cast(this); if (textAcc->IsDefunct()) return CO_E_OBJNOTCONNECTED; @@ -66,9 +81,6 @@ ia2AccessibleEditableText::insertText(long aOffset, BSTR *aText) if (!textAcc->IsValidOffset(aOffset)) return E_INVALIDARG; - uint32_t length = ::SysStringLen(*aText); - nsAutoString text(*aText, length); - textAcc->InsertText(text, aOffset); return S_OK; @@ -80,6 +92,10 @@ ia2AccessibleEditableText::cutText(long aStartOffset, long aEndOffset) { A11Y_TRYBLOCK_BEGIN + if (ProxyAccessible* proxy = HyperTextProxyFor(this)) { + return proxy->CutText(aStartOffset, aEndOffset) ? S_OK : E_INVALIDARG; + } + HyperTextAccessible* textAcc = static_cast(this); if (textAcc->IsDefunct()) return CO_E_OBJNOTCONNECTED; @@ -98,6 +114,10 @@ ia2AccessibleEditableText::pasteText(long aOffset) { A11Y_TRYBLOCK_BEGIN + if (ProxyAccessible* proxy = HyperTextProxyFor(this)) { + return proxy->PasteText(aOffset) ? S_OK : E_INVALIDARG; + } + HyperTextAccessible* textAcc = static_cast(this); if (textAcc->IsDefunct()) return CO_E_OBJNOTCONNECTED; diff --git a/accessible/windows/ia2/ia2AccessibleText.cpp b/accessible/windows/ia2/ia2AccessibleText.cpp index e5e8b54c0844..e0fbe3c759bd 100644 --- a/accessible/windows/ia2/ia2AccessibleText.cpp +++ b/accessible/windows/ia2/ia2AccessibleText.cpp @@ -12,6 +12,7 @@ #include "HyperTextAccessibleWrap.h" #include "HyperTextAccessible-inl.h" +#include "ProxyWrappers.h" using namespace mozilla::a11y; @@ -22,6 +23,11 @@ ia2AccessibleText::addSelection(long aStartOffset, long aEndOffset) { A11Y_TRYBLOCK_BEGIN + if (ProxyAccessible* proxy = HyperTextProxyFor(this)) { + return proxy->AddToSelection(aStartOffset, aEndOffset) ? + S_OK : E_INVALIDARG; + } + HyperTextAccessible* textAcc = static_cast(this); if (textAcc->IsDefunct()) return CO_E_OBJNOTCONNECTED; @@ -45,16 +51,23 @@ ia2AccessibleText::get_attributes(long aOffset, long *aStartOffset, *aEndOffset = 0; *aTextAttributes = nullptr; - HyperTextAccessible* textAcc = static_cast(this); - if (textAcc->IsDefunct()) - return CO_E_OBJNOTCONNECTED; - int32_t startOffset = 0, endOffset = 0; - nsCOMPtr attributes = - textAcc->TextAttributes(true, aOffset, &startOffset, &endOffset); + HRESULT hr; + if (ProxyAccessible* proxy = HyperTextProxyFor(this)) { + nsAutoTArray attrs; + proxy->TextAttributes(true, aOffset, &attrs, &startOffset, &endOffset); + hr = AccessibleWrap::ConvertToIA2Attributes(&attrs, aTextAttributes); + } else { + HyperTextAccessible* textAcc = static_cast(this); + if (textAcc->IsDefunct()) + return CO_E_OBJNOTCONNECTED; + + nsCOMPtr attributes = + textAcc->TextAttributes(true, aOffset, &startOffset, &endOffset); + + hr = AccessibleWrap::ConvertToIA2Attributes(attributes, aTextAttributes); + } - HRESULT hr = AccessibleWrap::ConvertToIA2Attributes(attributes, - aTextAttributes); if (FAILED(hr)) return hr; @@ -76,11 +89,16 @@ ia2AccessibleText::get_caretOffset(long *aOffset) *aOffset = -1; - HyperTextAccessible* textAcc = static_cast(this); - if (textAcc->IsDefunct()) - return CO_E_OBJNOTCONNECTED; + if (ProxyAccessible* proxy = HyperTextProxyFor(this)) { + *aOffset = proxy->CaretOffset(); + } else { + HyperTextAccessible* textAcc = static_cast(this); + if (textAcc->IsDefunct()) + return CO_E_OBJNOTCONNECTED; + + *aOffset = textAcc->CaretOffset(); + } - *aOffset = textAcc->CaretOffset(); return *aOffset != -1 ? S_OK : S_FALSE; A11Y_TRYBLOCK_END @@ -98,15 +116,19 @@ ia2AccessibleText::get_characterExtents(long aOffset, return E_INVALIDARG; *aX = *aY = *aWidth = *aHeight = 0; - HyperTextAccessible* textAcc = static_cast(this); - if (textAcc->IsDefunct()) - return CO_E_OBJNOTCONNECTED; - uint32_t geckoCoordType = (aCoordType == IA2_COORDTYPE_SCREEN_RELATIVE) ? nsIAccessibleCoordinateType::COORDTYPE_SCREEN_RELATIVE : nsIAccessibleCoordinateType::COORDTYPE_PARENT_RELATIVE; + nsIntRect rect; + if (ProxyAccessible* proxy = HyperTextProxyFor(this)) { + rect = proxy->CharBounds(aOffset, geckoCoordType); + } else { + HyperTextAccessible* textAcc = static_cast(this); + if (textAcc->IsDefunct()) + return CO_E_OBJNOTCONNECTED; - nsIntRect rect = textAcc->CharBounds(aOffset, geckoCoordType); + rect = textAcc->CharBounds(aOffset, geckoCoordType); + } *aX = rect.x; *aY = rect.y; @@ -126,11 +148,16 @@ ia2AccessibleText::get_nSelections(long* aNSelections) return E_INVALIDARG; *aNSelections = 0; - HyperTextAccessible* textAcc = static_cast(this); - if (textAcc->IsDefunct()) - return CO_E_OBJNOTCONNECTED; + if (ProxyAccessible* proxy = HyperTextProxyFor(this)) { + *aNSelections = proxy->SelectionCount(); + } else { + HyperTextAccessible* textAcc = static_cast(this); + if (textAcc->IsDefunct()) + return CO_E_OBJNOTCONNECTED; + + *aNSelections = textAcc->SelectionCount(); + } - *aNSelections = textAcc->SelectionCount(); return S_OK; A11Y_TRYBLOCK_END @@ -147,15 +174,20 @@ ia2AccessibleText::get_offsetAtPoint(long aX, long aY, return E_INVALIDARG; *aOffset = 0; - HyperTextAccessible* textAcc = static_cast(this); - if (textAcc->IsDefunct()) - return CO_E_OBJNOTCONNECTED; - uint32_t geckoCoordType = (aCoordType == IA2_COORDTYPE_SCREEN_RELATIVE) ? nsIAccessibleCoordinateType::COORDTYPE_SCREEN_RELATIVE : nsIAccessibleCoordinateType::COORDTYPE_PARENT_RELATIVE; - *aOffset = textAcc->OffsetAtPoint(aX, aY, geckoCoordType); + if (ProxyAccessible* proxy = HyperTextProxyFor(this)) { + *aOffset = proxy->OffsetAtPoint(aX, aY, geckoCoordType); + } else { + HyperTextAccessible* textAcc = static_cast(this); + if (textAcc->IsDefunct()) + return CO_E_OBJNOTCONNECTED; + + *aOffset = textAcc->OffsetAtPoint(aX, aY, geckoCoordType); + } + return *aOffset == -1 ? S_FALSE : S_OK; A11Y_TRYBLOCK_END @@ -171,13 +203,20 @@ ia2AccessibleText::get_selection(long aSelectionIndex, long* aStartOffset, return E_INVALIDARG; *aStartOffset = *aEndOffset = 0; - HyperTextAccessible* textAcc = static_cast(this); - if (textAcc->IsDefunct()) - return CO_E_OBJNOTCONNECTED; - int32_t startOffset = 0, endOffset = 0; - if (!textAcc->SelectionBoundsAt(aSelectionIndex, &startOffset, &endOffset)) - return E_INVALIDARG; + if (ProxyAccessible* proxy = HyperTextProxyFor(this)) { + nsString unused; + if (!proxy->SelectionBoundsAt(aSelectionIndex, unused, &startOffset, + &endOffset)) + return E_INVALIDARG; + } else { + HyperTextAccessible* textAcc = static_cast(this); + if (textAcc->IsDefunct()) + return CO_E_OBJNOTCONNECTED; + + if (!textAcc->SelectionBoundsAt(aSelectionIndex, &startOffset, &endOffset)) + return E_INVALIDARG; + } *aStartOffset = startOffset; *aEndOffset = endOffset; @@ -196,15 +235,22 @@ ia2AccessibleText::get_text(long aStartOffset, long aEndOffset, BSTR* aText) *aText = nullptr; - HyperTextAccessible* textAcc = static_cast(this); - if (textAcc->IsDefunct()) - return CO_E_OBJNOTCONNECTED; - - if (!textAcc->IsValidRange(aStartOffset, aEndOffset)) - return E_INVALIDARG; - nsAutoString text; - textAcc->TextSubstring(aStartOffset, aEndOffset, text); + if (ProxyAccessible* proxy = HyperTextProxyFor(this)) { + if (!proxy->TextSubstring(aStartOffset, aEndOffset, text)) { + return E_INVALIDARG; + } + } else { + HyperTextAccessible* textAcc = static_cast(this); + if (textAcc->IsDefunct()) + return CO_E_OBJNOTCONNECTED; + + if (!textAcc->IsValidRange(aStartOffset, aEndOffset)) + return E_INVALIDARG; + + textAcc->TextSubstring(aStartOffset, aEndOffset, text); + } + if (text.IsEmpty()) return S_FALSE; @@ -361,6 +407,10 @@ ia2AccessibleText::removeSelection(long aSelectionIndex) { A11Y_TRYBLOCK_BEGIN + if (ProxyAccessible* proxy = HyperTextProxyFor(this)) { + return proxy->RemoveFromSelection(aSelectionIndex) ? S_OK : E_INVALIDARG; + } + HyperTextAccessible* textAcc = static_cast(this); if (textAcc->IsDefunct()) return CO_E_OBJNOTCONNECTED; @@ -376,6 +426,10 @@ ia2AccessibleText::setCaretOffset(long aOffset) { A11Y_TRYBLOCK_BEGIN + if (ProxyAccessible* proxy = HyperTextProxyFor(this)) { + return proxy->SetCaretOffset(aOffset) ? S_OK : E_INVALIDARG; + } + HyperTextAccessible* textAcc = static_cast(this); if (textAcc->IsDefunct()) return CO_E_OBJNOTCONNECTED; @@ -395,6 +449,11 @@ ia2AccessibleText::setSelection(long aSelectionIndex, long aStartOffset, { A11Y_TRYBLOCK_BEGIN + if (ProxyAccessible* proxy = HyperTextProxyFor(this)) { + return proxy->SetSelectionBoundsAt(aSelectionIndex, aStartOffset, + aEndOffset) ? S_OK : E_INVALIDARG; + } + HyperTextAccessible* textAcc = static_cast(this); if (textAcc->IsDefunct()) return CO_E_OBJNOTCONNECTED; @@ -414,6 +473,11 @@ ia2AccessibleText::get_nCharacters(long* aNCharacters) return E_INVALIDARG; *aNCharacters = 0; + if (ProxyAccessible* proxy = HyperTextProxyFor(this)) { + *aNCharacters = proxy->CharacterCount(); + return S_OK; + } + HyperTextAccessible* textAcc = static_cast(this); if (textAcc->IsDefunct()) return CO_E_OBJNOTCONNECTED; @@ -430,6 +494,11 @@ ia2AccessibleText::scrollSubstringTo(long aStartIndex, long aEndIndex, { A11Y_TRYBLOCK_BEGIN + if (ProxyAccessible* proxy = HyperTextProxyFor(this)) { + proxy->ScrollSubstringTo(aStartIndex, aEndIndex, aScrollType); + return S_OK; + } + HyperTextAccessible* textAcc = static_cast(this); if (textAcc->IsDefunct()) return CO_E_OBJNOTCONNECTED; @@ -450,6 +519,16 @@ ia2AccessibleText::scrollSubstringToPoint(long aStartIndex, long aEndIndex, { A11Y_TRYBLOCK_BEGIN + uint32_t geckoCoordType = (aCoordType == IA2_COORDTYPE_SCREEN_RELATIVE) ? + nsIAccessibleCoordinateType::COORDTYPE_SCREEN_RELATIVE : + nsIAccessibleCoordinateType::COORDTYPE_PARENT_RELATIVE; + + if (ProxyAccessible* proxy = HyperTextProxyFor(this)) { + proxy->ScrollSubstringToPoint(aStartIndex, aEndIndex, geckoCoordType, aX, + aY); + return S_OK; + } + HyperTextAccessible* textAcc = static_cast(this); if (textAcc->IsDefunct()) return CO_E_OBJNOTCONNECTED; @@ -457,10 +536,6 @@ ia2AccessibleText::scrollSubstringToPoint(long aStartIndex, long aEndIndex, if (!textAcc->IsValidRange(aStartIndex, aEndIndex)) return E_INVALIDARG; - uint32_t geckoCoordType = (aCoordType == IA2_COORDTYPE_SCREEN_RELATIVE) ? - nsIAccessibleCoordinateType::COORDTYPE_SCREEN_RELATIVE : - nsIAccessibleCoordinateType::COORDTYPE_PARENT_RELATIVE; - textAcc->ScrollSubstringToPoint(aStartIndex, aEndIndex, geckoCoordType, aX, aY); return S_OK; diff --git a/accessible/windows/ia2/moz.build b/accessible/windows/ia2/moz.build index 1b444004318f..7c593cf85f8a 100644 --- a/accessible/windows/ia2/moz.build +++ b/accessible/windows/ia2/moz.build @@ -39,6 +39,7 @@ LOCAL_INCLUDES += [ '/accessible/base', '/accessible/generic', '/accessible/html', + '/accessible/windows', '/accessible/windows/msaa', '/accessible/xpcom', '/accessible/xul', diff --git a/accessible/windows/msaa/Platform.cpp b/accessible/windows/msaa/Platform.cpp index 9e7e6cf6a3e9..30f8a4dceed5 100644 --- a/accessible/windows/msaa/Platform.cpp +++ b/accessible/windows/msaa/Platform.cpp @@ -11,6 +11,7 @@ #include "HyperTextAccessibleWrap.h" #include "nsWinUtils.h" #include "mozilla/a11y/ProxyAccessible.h" +#include "ProxyWrappers.h" #include "mozilla/ClearOnShutdown.h" @@ -35,22 +36,6 @@ a11y::PlatformShutdown() nsWinUtils::ShutdownWindowEmulation(); } -class ProxyAccessibleWrap : public AccessibleWrap -{ - public: - ProxyAccessibleWrap(ProxyAccessible* aProxy) : - AccessibleWrap(nullptr, nullptr) - { - mType = eProxyType; - mBits.proxy = aProxy; - } - - virtual void Shutdown() override - { - mBits.proxy = nullptr; - } -}; - void a11y::ProxyCreated(ProxyAccessible* aProxy, uint32_t) { diff --git a/accessible/windows/msaa/moz.build b/accessible/windows/msaa/moz.build index dc88de688b79..804f2b4c2fd7 100644 --- a/accessible/windows/msaa/moz.build +++ b/accessible/windows/msaa/moz.build @@ -48,6 +48,7 @@ LOCAL_INCLUDES += [ '/accessible/base', '/accessible/generic', '/accessible/html', + '/accessible/windows', '/accessible/windows/ia2', '/accessible/windows/sdn', '/accessible/windows/uia',