summaryrefslogtreecommitdiffstats
path: root/accessible/windows/msaa/AccessibleWrap.h
blob: 8f9c944c9253a93ccfb81effe55db6fcf60895e7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/* -*- 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_AccessibleWrap_h_
#define mozilla_a11y_AccessibleWrap_h_

#include "nsCOMPtr.h"
#include "LocalAccessible.h"
#include "MsaaAccessible.h"
#include "mozilla/a11y/AccessibleHandler.h"
#include "mozilla/a11y/RemoteAccessible.h"
#include "mozilla/Attributes.h"
#include "mozilla/mscom/Utils.h"
#include "mozilla/StaticPtr.h"
#include "nsXULAppAPI.h"
#include "Units.h"

namespace mozilla {
namespace a11y {
class DocRemoteAccessibleWrap;

/**
 * Windows specific functionality for an accessibility tree node that originated
 * in mDoc's content process.
 */
class AccessibleWrap : public LocalAccessible {
 public:  // construction, destruction
  AccessibleWrap(nsIContent* aContent, DocAccessible* aDoc);

  // nsISupports
  NS_DECL_ISUPPORTS_INHERITED

 public:
  // LocalAccessible
  virtual nsresult HandleAccEvent(AccEvent* aEvent) override;
  virtual void Shutdown() override;

  // Helper methods
  /**
   * System caret support: update the Windows caret position.
   * The system caret works more universally than the MSAA caret
   * For example, Window-Eyes, JAWS, ZoomText and Windows Tablet Edition use it
   * We will use an invisible system caret.
   * Gecko is still responsible for drawing its own caret
   */
  void UpdateSystemCaretFor(LocalAccessible* aAccessible);
  static void UpdateSystemCaretFor(RemoteAccessible* aProxy,
                                   const LayoutDeviceIntRect& aCaretRect);

 private:
  static void UpdateSystemCaretFor(HWND aCaretWnd,
                                   const LayoutDeviceIntRect& aCaretRect);

 public:
  /**
   * Determine whether this is the root accessible for its HWND.
   */
  bool IsRootForHWND();

  MsaaAccessible* GetMsaa();
  virtual void GetNativeInterface(void** aOutAccessible) override;

  static void SetHandlerControl(DWORD aPid, RefPtr<IHandlerControl> aCtrl);

  static void InvalidateHandlers();

  static bool DispatchTextChangeToHandler(Accessible* aAcc, bool aIsInsert,
                                          const nsAString& aText,
                                          int32_t aStart, uint32_t aLen);

  static void SuppressHandlerA11yForClipboardCopy();

 protected:
  virtual ~AccessibleWrap() = default;

  RefPtr<MsaaAccessible> mMsaa;

  struct HandlerControllerData final {
    HandlerControllerData(DWORD aPid, RefPtr<IHandlerControl>&& aCtrl)
        : mPid(aPid), mCtrl(std::move(aCtrl)) {
      mIsProxy = mozilla::mscom::IsProxy(mCtrl);
    }

    HandlerControllerData(HandlerControllerData&& aOther)
        : mPid(aOther.mPid),
          mIsProxy(aOther.mIsProxy),
          mCtrl(std::move(aOther.mCtrl)) {}

    bool operator==(const HandlerControllerData& aOther) const {
      return mPid == aOther.mPid;
    }

    bool operator==(const DWORD& aPid) const { return mPid == aPid; }

    DWORD mPid;
    bool mIsProxy;
    RefPtr<IHandlerControl> mCtrl;
  };

  static StaticAutoPtr<nsTArray<HandlerControllerData>> sHandlerControllers;
};

}  // namespace a11y
}  // namespace mozilla

#endif