Bug 1380471: Move follow-up initialization for emulated windows into a callback invoked by the emulated window's WM_CREATE handler; r=yzen

--HG--
extra : rebase_source : 4bf99168aa2e845437238cf37d838d0d91ffb807
This commit is contained in:
Aaron Klotz 2017-07-12 18:01:43 -06:00
Родитель 80c9890f5c
Коммит a58d6b98b6
4 изменённых файлов: 70 добавлений и 33 удалений

Просмотреть файл

@ -623,26 +623,31 @@ DocAccessibleParent::MaybeInitWindowEmulation()
tab->GetDocShellIsActive(&isActive);
}
IAccessibleHolder hWndAccHolder;
HWND parentWnd = reinterpret_cast<HWND>(rootDocument->GetNativeWindow());
HWND hWnd = nsWinUtils::CreateNativeWindow(kClassNameTabContent,
parentWnd, rect.x, rect.y,
rect.width, rect.height,
isActive);
if (hWnd) {
// Attach accessible document to the emulated native window
::SetPropW(hWnd, kPropNameDocAccParent, (HANDLE)this);
SetEmulatedWindowHandle(hWnd);
nsWinUtils::NativeWindowCreateProc onCreate([this](HWND aHwnd) -> void {
IAccessibleHolder hWndAccHolder;
::SetPropW(aHwnd, kPropNameDocAccParent, reinterpret_cast<HANDLE>(this));
SetEmulatedWindowHandle(aHwnd);
IAccessible* rawHWNDAcc = nullptr;
if (SUCCEEDED(::AccessibleObjectFromWindow(hWnd, OBJID_WINDOW,
if (SUCCEEDED(::AccessibleObjectFromWindow(aHwnd, OBJID_WINDOW,
IID_IAccessible,
(void**)&rawHWNDAcc))) {
hWndAccHolder.Set(IAccessibleHolder::COMPtrType(rawHWNDAcc));
}
}
Unused << SendEmulatedWindow(reinterpret_cast<uintptr_t>(mEmulatedWindowHandle),
hWndAccHolder);
Unused << SendEmulatedWindow(reinterpret_cast<uintptr_t>(mEmulatedWindowHandle),
hWndAccHolder);
});
HWND parentWnd = reinterpret_cast<HWND>(rootDocument->GetNativeWindow());
DebugOnly<HWND> hWnd = nsWinUtils::CreateNativeWindow(kClassNameTabContent,
parentWnd,
rect.x, rect.y,
rect.width, rect.height,
isActive, &onCreate);
MOZ_ASSERT(hWnd);
}
/**

Просмотреть файл

@ -163,13 +163,15 @@ DocAccessibleWrap::DoInitialUpdate()
docShell->GetIsActive(&isActive);
}
nsWinUtils::NativeWindowCreateProc onCreate([this](HWND aHwnd) -> void {
::SetPropW(aHwnd, kPropNameDocAcc, reinterpret_cast<HANDLE>(this));
});
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);
rect.width, rect.height, isActive,
&onCreate);
} else {
DocAccessible* parentDocument = ParentDocument();
if (parentDocument)

Просмотреть файл

@ -110,21 +110,17 @@ nsWinUtils::RegisterNativeWindow(LPCWSTR aWindowClass)
HWND
nsWinUtils::CreateNativeWindow(LPCWSTR aWindowClass, HWND aParentWnd,
int aX, int aY, int aWidth, int aHeight,
bool aIsActive)
bool aIsActive,
NativeWindowCreateProc* aOnCreateProc)
{
HWND hwnd = ::CreateWindowExW(WS_EX_TRANSPARENT, aWindowClass,
L"NetscapeDispatchWnd",
WS_CHILD | (aIsActive ? WS_VISIBLE : 0),
aX, aY, aWidth, aHeight,
aParentWnd,
nullptr,
GetModuleHandle(nullptr),
nullptr);
if (hwnd) {
// Mark this window so that ipc related code can identify it.
::SetPropW(hwnd, kPropNameTabContent, (HANDLE)1);
}
return hwnd;
return ::CreateWindowExW(WS_EX_TRANSPARENT, aWindowClass,
L"NetscapeDispatchWnd",
WS_CHILD | (aIsActive ? WS_VISIBLE : 0),
aX, aY, aWidth, aHeight,
aParentWnd,
nullptr,
GetModuleHandle(nullptr),
aOnCreateProc);
}
void
@ -149,6 +145,21 @@ WindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
// message semantics.
switch (msg) {
case WM_CREATE:
{
// Mark this window so that ipc related code can identify it.
::SetPropW(hWnd, kPropNameTabContent, reinterpret_cast<HANDLE>(1));
auto createStruct = reinterpret_cast<CREATESTRUCT*>(lParam);
auto createProc = reinterpret_cast<nsWinUtils::NativeWindowCreateProc*>(
createStruct->lpCreateParams);
if (createProc && *createProc) {
(*createProc)(hWnd);
}
return 0;
}
case WM_GETOBJECT:
{
// Do explicit casting to make it working on 64bit systems (see bug 649236

Просмотреть файл

@ -8,6 +8,7 @@
#ifndef nsWinUtils_h_
#define nsWinUtils_h_
#include <functional>
#include <windows.h>
#include "nsIDOMCSSStyleDeclaration.h"
@ -57,12 +58,30 @@ public:
*/
static void RegisterNativeWindow(LPCWSTR aWindowClass);
typedef std::function<void(HWND)> NativeWindowCreateProc;
/**
* Helper to create a window.
*
* NB: If additional setup needs to be done once the window has been created,
* you should do so via aOnCreateProc. Hooks will fire during the
* CreateNativeWindow call, thus triggering events in the AT.
* Using aOnCreateProc guarantees that your additional initialization will
* have completed prior to the AT receiving window creation events.
*
* For example:
*
* nsWinUtils::NativeWindowCreateProc onCreate([](HWND aHwnd) -> void {
* DoSomeAwesomeInitializationStuff(aHwnd);
* DoMoreAwesomeInitializationStuff(aHwnd);
* });
* HWND hwnd = nsWinUtils::CreateNativeWindow(..., &onCreate);
* // Doing further initialization work to hwnd on this line is too late!
*/
static HWND CreateNativeWindow(LPCWSTR aWindowClass, HWND aParentWnd,
int aX, int aY, int aWidth, int aHeight,
bool aIsActive);
bool aIsActive,
NativeWindowCreateProc* aOnCreateProc = nullptr);
/**
* Helper to show window.