File: MsaaDocAccessible.cpp

package info (click to toggle)
firefox 147.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,683,484 kB
  • sloc: cpp: 7,607,246; javascript: 6,533,185; ansic: 3,775,227; python: 1,415,393; xml: 634,561; asm: 438,951; java: 186,241; sh: 62,752; makefile: 18,079; objc: 13,092; perl: 12,808; yacc: 4,583; cs: 3,846; pascal: 3,448; lex: 1,720; ruby: 1,003; php: 436; lisp: 258; awk: 247; sql: 66; sed: 54; csh: 10; exp: 6
file content (125 lines) | stat: -rw-r--r-- 4,155 bytes parent folder | download | duplicates (13)
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/* -*- 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 "MsaaDocAccessible.h"

#include "MsaaDocAccessible.h"
#include "DocAccessibleChild.h"
#include "mozilla/a11y/DocAccessibleParent.h"
#include "nsAccessibilityService.h"
#include "nsAccUtils.h"
#include "nsWinUtils.h"
#include "mozilla/a11y/Role.h"
#include "ISimpleDOM.h"

using namespace mozilla;
using namespace mozilla::a11y;

DocAccessible* MsaaDocAccessible::DocAcc() {
  return static_cast<DocAccessible*>(LocalAcc());
}

/* static */
MsaaDocAccessible* MsaaDocAccessible::GetFrom(DocAccessible* aDoc) {
  return static_cast<MsaaDocAccessible*>(MsaaAccessible::GetFrom(aDoc));
}

/* static */
MsaaDocAccessible* MsaaDocAccessible::GetFrom(DocAccessibleParent* aDoc) {
  return static_cast<MsaaDocAccessible*>(
      reinterpret_cast<MsaaAccessible*>(aDoc->GetWrapper()));
}

/* static */
MsaaDocAccessible* MsaaDocAccessible::GetFromOwned(Accessible* aAcc) {
  if (RemoteAccessible* remoteAcc = aAcc->AsRemote()) {
    DocAccessibleParent* doc = remoteAcc->Document();
    if (!doc) {
      return nullptr;
    }
    return MsaaDocAccessible::GetFrom(doc);
  }
  DocAccessible* doc = aAcc->AsLocal()->Document();
  if (!doc) {
    return nullptr;
  }
  return MsaaDocAccessible::GetFrom(doc);
}

// IUnknown
IMPL_IUNKNOWN_QUERY_HEAD(MsaaDocAccessible)
IMPL_IUNKNOWN_QUERY_TAIL_INHERITED(ia2AccessibleHypertext)

STDMETHODIMP
MsaaDocAccessible::get_accParent(
    /* [retval][out] */ IDispatch __RPC_FAR* __RPC_FAR* ppdispParent) {
  if (!mAcc) {
    return CO_E_OBJNOTCONNECTED;
  }

  if (mAcc->IsRemote()) {
    DocAccessibleParent* remoteDoc = mAcc->AsRemote()->AsDoc();
    if (nsWinUtils::IsWindowEmulationStarted() && remoteDoc->IsTopLevel()) {
      // Window emulation is enabled and this is a top level document. Return
      // window system accessible object.
      HWND hwnd = remoteDoc->GetEmulatedWindowHandle();
      MOZ_ASSERT(hwnd);
      if (hwnd &&
          SUCCEEDED(::CreateStdAccessibleObject(
              hwnd, OBJID_WINDOW, IID_IAccessible, (void**)ppdispParent))) {
        return S_OK;
      }
    }
    return MsaaAccessible::get_accParent(ppdispParent);
  }

  DocAccessible* docAcc = DocAcc();
  MOZ_ASSERT(docAcc);

  // Return window system accessible object for root document accessibles, as
  // well as tab document accessibles if window emulation is enabled.
  MOZ_ASSERT(XRE_IsParentProcess());
  if ((!docAcc->ParentDocument() ||
       (nsWinUtils::IsWindowEmulationStarted() &&
        nsCoreUtils::IsTopLevelContentDocInProcess(docAcc->DocumentNode())))) {
    HWND hwnd = static_cast<HWND>(docAcc->GetNativeWindow());
    if (hwnd &&
        SUCCEEDED(::CreateStdAccessibleObject(
            hwnd, OBJID_WINDOW, IID_IAccessible, (void**)ppdispParent))) {
      return S_OK;
    }
  }

  return MsaaAccessible::get_accParent(ppdispParent);
}

STDMETHODIMP
MsaaDocAccessible::get_accValue(VARIANT aVarChild, BSTR __RPC_FAR* aValue) {
  if (!aValue) return E_INVALIDARG;
  *aValue = nullptr;

  // For backwards-compat, we still support old MSAA hack to provide URL in
  // accValue Check for real value first
  HRESULT hr = MsaaAccessible::get_accValue(aVarChild, aValue);
  if (FAILED(hr) || *aValue || aVarChild.lVal != CHILDID_SELF) return hr;

  // MsaaAccessible::get_accValue should have failed (and thus we should have
  // returned early) if the Accessible is dead.
  MOZ_ASSERT(mAcc);
  // If document is being used to create a widget, don't use the URL hack
  roles::Role role = mAcc->Role();
  if (role != roles::DOCUMENT && role != roles::APPLICATION &&
      role != roles::DIALOG && role != roles::ALERT &&
      role != roles::NON_NATIVE_DOCUMENT)
    return hr;

  nsAutoString url;
  nsAccUtils::DocumentURL(mAcc, url);
  if (url.IsEmpty()) return S_FALSE;

  *aValue = ::SysAllocStringLen(url.get(), url.Length());
  return *aValue ? S_OK : E_OUTOFMEMORY;
}