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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
|
/* -*- 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 "DocAccessibleWrap.h"
#include "Compatibility.h"
#include "DocAccessibleChild.h"
#include "nsWinUtils.h"
#include "Role.h"
#include "RootAccessible.h"
#include "sdnDocAccessible.h"
#include "Statistics.h"
#include "nsIDocShell.h"
#include "nsIInterfaceRequestorUtils.h"
using namespace mozilla;
using namespace mozilla::a11y;
////////////////////////////////////////////////////////////////////////////////
// DocAccessibleWrap
////////////////////////////////////////////////////////////////////////////////
DocAccessibleWrap::
DocAccessibleWrap(nsIDocument* aDocument, nsIPresShell* aPresShell) :
DocAccessible(aDocument, aPresShell), mHWND(nullptr)
{
}
DocAccessibleWrap::~DocAccessibleWrap()
{
}
IMPL_IUNKNOWN_QUERY_HEAD(DocAccessibleWrap)
if (aIID == IID_ISimpleDOMDocument) {
statistics::ISimpleDOMUsed();
*aInstancePtr = static_cast<ISimpleDOMDocument*>(new sdnDocAccessible(this));
static_cast<IUnknown*>(*aInstancePtr)->AddRef();
return S_OK;
}
IMPL_IUNKNOWN_QUERY_TAIL_INHERITED(HyperTextAccessibleWrap)
STDMETHODIMP
DocAccessibleWrap::get_accParent(
/* [retval][out] */ IDispatch __RPC_FAR *__RPC_FAR *ppdispParent)
{
// We might be a top-level document in a content process.
DocAccessibleChild* ipcDoc = IPCDoc();
if (!ipcDoc) {
return DocAccessible::get_accParent(ppdispParent);
}
IAccessible* dispParent = ipcDoc->GetParentIAccessible();
if (!dispParent) {
return S_FALSE;
}
dispParent->AddRef();
*ppdispParent = static_cast<IDispatch*>(dispParent);
return S_OK;
}
STDMETHODIMP
DocAccessibleWrap::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 = AccessibleWrap::get_accValue(aVarChild, aValue);
if (FAILED(hr) || *aValue || aVarChild.lVal != CHILDID_SELF)
return hr;
// If document is being used to create a widget, don't use the URL hack
roles::Role role = Role();
if (role != roles::DOCUMENT && role != roles::APPLICATION &&
role != roles::DIALOG && role != roles::ALERT)
return hr;
nsAutoString url;
URL(url);
if (url.IsEmpty())
return S_FALSE;
*aValue = ::SysAllocStringLen(url.get(), url.Length());
return *aValue ? S_OK : E_OUTOFMEMORY;
}
////////////////////////////////////////////////////////////////////////////////
// Accessible
void
DocAccessibleWrap::Shutdown()
{
// Do window emulation specific shutdown if emulation was started.
if (nsWinUtils::IsWindowEmulationStarted()) {
// Destroy window created for root document.
if (mDocFlags & eTabDocument) {
HWND hWnd = static_cast<HWND>(mHWND);
::RemovePropW(hWnd, kPropNameDocAcc);
::DestroyWindow(hWnd);
}
mHWND = nullptr;
}
DocAccessible::Shutdown();
}
////////////////////////////////////////////////////////////////////////////////
// DocAccessible public
void*
DocAccessibleWrap::GetNativeWindow() const
{
return mHWND ? mHWND : DocAccessible::GetNativeWindow();
}
////////////////////////////////////////////////////////////////////////////////
// DocAccessible protected
void
DocAccessibleWrap::DoInitialUpdate()
{
DocAccessible::DoInitialUpdate();
if (nsWinUtils::IsWindowEmulationStarted()) {
// Create window for tab document.
if (mDocFlags & eTabDocument) {
a11y::RootAccessible* rootDocument = RootAccessible();
bool isActive = true;
nsIntRect rect(CW_USEDEFAULT, CW_USEDEFAULT, 0, 0);
if (Compatibility::IsDolphin()) {
rect = Bounds();
nsIntRect rootRect = rootDocument->Bounds();
rect.x = rootRect.x - rect.x;
rect.y -= rootRect.y;
nsCOMPtr<nsISupports> container = mDocumentNode->GetContainer();
nsCOMPtr<nsIDocShell> docShell = do_QueryInterface(container);
docShell->GetIsActive(&isActive);
}
HWND parentWnd = reinterpret_cast<HWND>(rootDocument->GetNativeWindow());
mHWND = nsWinUtils::CreateNativeWindow(kClassNameTabContent, parentWnd,
rect.x, rect.y,
rect.width, rect.height, isActive);
::SetPropW(static_cast<HWND>(mHWND), kPropNameDocAcc, (HANDLE)this);
} else {
DocAccessible* parentDocument = ParentDocument();
if (parentDocument)
mHWND = parentDocument->GetNativeWindow();
}
}
}
|