tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

UiaTextRange.h (4665B)


      1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=2 et sw=2 tw=80: */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
      5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #ifndef mozilla_a11y_UiaTextRange_h__
      8 #define mozilla_a11y_UiaTextRange_h__
      9 
     10 #include "IUnknownImpl.h"
     11 #include "MsaaAccessible.h"
     12 #include "mozilla/RefPtr.h"
     13 #include "nsDirection.h"
     14 #include "objbase.h"
     15 #include "uiautomation.h"
     16 
     17 namespace mozilla::a11y {
     18 class TextLeafRange;
     19 class TextLeafPoint;
     20 
     21 /**
     22 * ITextRangeProvider implementation.
     23 */
     24 class UiaTextRange : public ITextRangeProvider {
     25 public:
     26  explicit UiaTextRange(const TextLeafRange& aRange);
     27  virtual ~UiaTextRange() = default;
     28 
     29  // IUnknown
     30  DECL_IUNKNOWN
     31 
     32  // ITextRangeProvider
     33  virtual HRESULT STDMETHODCALLTYPE Clone(
     34      /* [retval][out] */ __RPC__deref_out_opt ITextRangeProvider** aRetVal);
     35 
     36  virtual HRESULT STDMETHODCALLTYPE Compare(
     37      /* [in] */ __RPC__in_opt ITextRangeProvider* aRange,
     38      /* [retval][out] */ __RPC__out BOOL* aRetVal);
     39 
     40  virtual HRESULT STDMETHODCALLTYPE CompareEndpoints(
     41      /* [in] */ enum TextPatternRangeEndpoint aEndpoint,
     42      /* [in] */ __RPC__in_opt ITextRangeProvider* aTargetRange,
     43      /* [in] */ enum TextPatternRangeEndpoint aTargetEndpoint,
     44      /* [retval][out] */ __RPC__out int* aRetVal);
     45 
     46  virtual HRESULT STDMETHODCALLTYPE ExpandToEnclosingUnit(
     47      /* [in] */ enum TextUnit aUnit);
     48 
     49  virtual HRESULT STDMETHODCALLTYPE FindAttribute(
     50      /* [in] */ TEXTATTRIBUTEID aAttributeId,
     51      /* [in] */ VARIANT aVal,
     52      /* [in] */ BOOL aBackward,
     53      /* [retval][out] */ __RPC__deref_out_opt ITextRangeProvider** aRetVal);
     54 
     55  virtual HRESULT STDMETHODCALLTYPE FindText(
     56      /* [in] */ __RPC__in BSTR aText,
     57      /* [in] */ BOOL aBackward,
     58      /* [in] */ BOOL aIgnoreCase,
     59      /* [retval][out] */ __RPC__deref_out_opt ITextRangeProvider** aRetVal);
     60 
     61  virtual HRESULT STDMETHODCALLTYPE GetAttributeValue(
     62      /* [in] */ TEXTATTRIBUTEID aAttributeId,
     63      /* [retval][out] */ __RPC__out VARIANT* aRetVal);
     64 
     65  virtual HRESULT STDMETHODCALLTYPE GetBoundingRectangles(
     66      /* [retval][out] */ __RPC__deref_out_opt SAFEARRAY** aRetVal);
     67 
     68  virtual HRESULT STDMETHODCALLTYPE GetEnclosingElement(
     69      /* [retval][out] */ __RPC__deref_out_opt IRawElementProviderSimple**
     70          aRetVal);
     71 
     72  virtual HRESULT STDMETHODCALLTYPE GetText(
     73      /* [in] */ int aMaxLength,
     74      /* [retval][out] */ __RPC__deref_out_opt BSTR* aRetVal);
     75 
     76  virtual HRESULT STDMETHODCALLTYPE Move(
     77      /* [in] */ enum TextUnit aUnit,
     78      /* [in] */ int aCount,
     79      /* [retval][out] */ __RPC__out int* aRetVal);
     80 
     81  virtual HRESULT STDMETHODCALLTYPE MoveEndpointByUnit(
     82      /* [in] */ enum TextPatternRangeEndpoint aEndpoint,
     83      /* [in] */ enum TextUnit aUnit,
     84      /* [in] */ int aCount,
     85      /* [retval][out] */ __RPC__out int* aRetVal);
     86 
     87  virtual HRESULT STDMETHODCALLTYPE MoveEndpointByRange(
     88      /* [in] */ enum TextPatternRangeEndpoint aEndpoint,
     89      /* [in] */ __RPC__in_opt ITextRangeProvider* aTargetRange,
     90      /* [in] */ enum TextPatternRangeEndpoint aTargetEndpoint);
     91 
     92  virtual HRESULT STDMETHODCALLTYPE Select(void);
     93 
     94  virtual HRESULT STDMETHODCALLTYPE AddToSelection(void);
     95 
     96  virtual HRESULT STDMETHODCALLTYPE RemoveFromSelection(void);
     97 
     98  virtual HRESULT STDMETHODCALLTYPE ScrollIntoView(
     99      /* [in] */ BOOL aAlignToTop);
    100 
    101  virtual HRESULT STDMETHODCALLTYPE GetChildren(
    102      /* [retval][out] */ __RPC__deref_out_opt SAFEARRAY** aRetVal);
    103 
    104 private:
    105  void SetRange(const TextLeafRange& aRange);
    106  TextLeafRange GetRange() const;
    107  static TextLeafRange GetRangeFrom(ITextRangeProvider* aProvider);
    108  static TextLeafPoint FindBoundary(const TextLeafPoint& aOrigin,
    109                                    enum TextUnit aUnit, nsDirection aDirection,
    110                                    bool aIncludeOrigin = false);
    111  bool MovePoint(TextLeafPoint& aPoint, enum TextUnit aUnit,
    112                 const int aRequestedCount, int& aActualCount);
    113  void SetEndpoint(enum TextPatternRangeEndpoint aEndpoint,
    114                   const TextLeafPoint& aDest);
    115 
    116  // Accessible doesn't support strong references and so neither does
    117  // TextLeafRange. Therefore, we hold strong references to MsaaAccessibles. We
    118  // combine those with offsets to reconstitute the TextLeafRange later.
    119  RefPtr<MsaaAccessible> mStartAcc;
    120  int32_t mStartOffset = -1;
    121  RefPtr<MsaaAccessible> mEndAcc;
    122  int32_t mEndOffset = -1;
    123  bool mIsEndOfLineInsertionPoint = false;
    124 };
    125 
    126 }  // namespace mozilla::a11y
    127 
    128 #endif