ia2AccessibleEditableText.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* vim:expandtab:shiftwidth=2:tabstop=2:
  3. */
  4. /* This Source Code Form is subject to the terms of the Mozilla Public
  5. * License, v. 2.0. If a copy of the MPL was not distributed with this
  6. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  7. #include "ia2AccessibleEditableText.h"
  8. #include "AccessibleEditableText_i.c"
  9. #include "HyperTextAccessible-inl.h"
  10. #include "HyperTextAccessibleWrap.h"
  11. #include "ProxyWrappers.h"
  12. #include "nsCOMPtr.h"
  13. #include "nsString.h"
  14. using namespace mozilla::a11y;
  15. // IAccessibleEditableText
  16. STDMETHODIMP
  17. ia2AccessibleEditableText::copyText(long aStartOffset, long aEndOffset)
  18. {
  19. MOZ_ASSERT(!HyperTextProxyFor(this));
  20. HyperTextAccessible* textAcc = static_cast<HyperTextAccessibleWrap*>(this);
  21. if (textAcc->IsDefunct())
  22. return CO_E_OBJNOTCONNECTED;
  23. if (!textAcc->IsValidRange(aStartOffset, aEndOffset))
  24. return E_INVALIDARG;
  25. textAcc->CopyText(aStartOffset, aEndOffset);
  26. return S_OK;
  27. }
  28. STDMETHODIMP
  29. ia2AccessibleEditableText::deleteText(long aStartOffset, long aEndOffset)
  30. {
  31. MOZ_ASSERT(!HyperTextProxyFor(this));
  32. HyperTextAccessible* textAcc = static_cast<HyperTextAccessibleWrap*>(this);
  33. if (textAcc->IsDefunct())
  34. return CO_E_OBJNOTCONNECTED;
  35. if (!textAcc->IsValidRange(aStartOffset, aEndOffset))
  36. return E_INVALIDARG;
  37. textAcc->DeleteText(aStartOffset, aEndOffset);
  38. return S_OK;
  39. }
  40. STDMETHODIMP
  41. ia2AccessibleEditableText::insertText(long aOffset, BSTR *aText)
  42. {
  43. uint32_t length = ::SysStringLen(*aText);
  44. nsAutoString text(*aText, length);
  45. MOZ_ASSERT(!HyperTextProxyFor(this));
  46. HyperTextAccessible* textAcc = static_cast<HyperTextAccessibleWrap*>(this);
  47. if (textAcc->IsDefunct())
  48. return CO_E_OBJNOTCONNECTED;
  49. if (!textAcc->IsValidOffset(aOffset))
  50. return E_INVALIDARG;
  51. textAcc->InsertText(text, aOffset);
  52. return S_OK;
  53. }
  54. STDMETHODIMP
  55. ia2AccessibleEditableText::cutText(long aStartOffset, long aEndOffset)
  56. {
  57. MOZ_ASSERT(!HyperTextProxyFor(this));
  58. HyperTextAccessible* textAcc = static_cast<HyperTextAccessibleWrap*>(this);
  59. if (textAcc->IsDefunct())
  60. return CO_E_OBJNOTCONNECTED;
  61. if (!textAcc->IsValidRange(aStartOffset, aEndOffset))
  62. return E_INVALIDARG;
  63. textAcc->CutText(aStartOffset, aEndOffset);
  64. return S_OK;
  65. }
  66. STDMETHODIMP
  67. ia2AccessibleEditableText::pasteText(long aOffset)
  68. {
  69. MOZ_ASSERT(!HyperTextProxyFor(this));
  70. HyperTextAccessible* textAcc = static_cast<HyperTextAccessibleWrap*>(this);
  71. if (textAcc->IsDefunct())
  72. return CO_E_OBJNOTCONNECTED;
  73. if (!textAcc->IsValidOffset(aOffset))
  74. return E_INVALIDARG;
  75. textAcc->PasteText(aOffset);
  76. return S_OK;
  77. }
  78. STDMETHODIMP
  79. ia2AccessibleEditableText::replaceText(long aStartOffset, long aEndOffset,
  80. BSTR *aText)
  81. {
  82. HyperTextAccessible* textAcc = static_cast<HyperTextAccessibleWrap*>(this);
  83. if (textAcc->IsDefunct())
  84. return CO_E_OBJNOTCONNECTED;
  85. if (!textAcc->IsValidRange(aStartOffset, aEndOffset))
  86. return E_INVALIDARG;
  87. textAcc->DeleteText(aStartOffset, aEndOffset);
  88. uint32_t length = ::SysStringLen(*aText);
  89. nsAutoString text(*aText, length);
  90. textAcc->InsertText(text, aStartOffset);
  91. return S_OK;
  92. }
  93. STDMETHODIMP
  94. ia2AccessibleEditableText::setAttributes(long aStartOffset, long aEndOffset,
  95. BSTR *aAttributes)
  96. {
  97. return E_NOTIMPL;
  98. }