2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2009-09-10 18:07:56 -07:00
|
|
|
/* vim:expandtab:shiftwidth=2:tabstop=2:
|
|
|
|
*/
|
2012-05-21 04:12:37 -07:00
|
|
|
/* 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/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-09-10 18:07:56 -07:00
|
|
|
#include "nsWinUtils.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-12-05 22:07:46 -08:00
|
|
|
#include "Compatibility.h"
|
2012-05-27 02:01:40 -07:00
|
|
|
#include "DocAccessible.h"
|
2015-04-06 03:33:09 -07:00
|
|
|
#include "nsAccessibilityService.h"
|
2012-05-03 23:09:22 -07:00
|
|
|
#include "nsCoreUtils.h"
|
2011-03-02 06:41:42 -08:00
|
|
|
|
2011-11-24 03:31:49 -08:00
|
|
|
#include "mozilla/Preferences.h"
|
2009-09-10 18:07:56 -07:00
|
|
|
#include "nsArrayUtils.h"
|
2012-07-01 16:45:59 -07:00
|
|
|
#include "nsIArray.h"
|
|
|
|
#include "nsIDocument.h"
|
2010-09-16 20:23:17 -07:00
|
|
|
#include "nsIDocShellTreeItem.h"
|
2014-08-16 12:35:48 -07:00
|
|
|
#include "nsIDOMElement.h"
|
2014-02-11 09:01:08 -08:00
|
|
|
#include "nsXULAppAPI.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-11-24 03:31:49 -08:00
|
|
|
using namespace mozilla;
|
2011-12-05 22:07:46 -08:00
|
|
|
using namespace mozilla::a11y;
|
2011-11-24 03:31:49 -08:00
|
|
|
|
2011-10-11 09:11:35 -07:00
|
|
|
// Window property used by ipc related code in identifying accessible
|
|
|
|
// tab windows.
|
2013-12-03 07:09:50 -08:00
|
|
|
const wchar_t* kPropNameTabContent = L"AccessibleTabWindow";
|
2011-10-11 09:11:35 -07:00
|
|
|
|
2013-05-04 22:38:14 -07:00
|
|
|
/**
|
|
|
|
* WindowProc to process WM_GETOBJECT messages, used in windows emulation mode.
|
|
|
|
*/
|
|
|
|
static LRESULT CALLBACK WindowProc(HWND hWnd, UINT msg,
|
|
|
|
WPARAM wParam, LPARAM lParam);
|
|
|
|
|
2013-09-02 01:41:57 -07:00
|
|
|
nsRefPtrHashtable<nsPtrHashKey<void>, DocAccessible>* nsWinUtils::sHWNDCache = nullptr;
|
2013-05-04 22:38:14 -07:00
|
|
|
|
2012-03-12 18:08:06 -07:00
|
|
|
already_AddRefed<nsIDOMCSSStyleDeclaration>
|
|
|
|
nsWinUtils::GetComputedStyleDeclaration(nsIContent* aContent)
|
|
|
|
{
|
|
|
|
nsIContent* elm = nsCoreUtils::GetDOMElementFor(aContent);
|
|
|
|
if (!elm)
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2012-03-12 18:08:06 -07:00
|
|
|
|
|
|
|
// Returns number of items in style declaration
|
|
|
|
nsCOMPtr<nsIDOMWindow> window =
|
|
|
|
do_QueryInterface(elm->OwnerDoc()->GetWindow());
|
|
|
|
if (!window)
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2012-03-12 18:08:06 -07:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMCSSStyleDeclaration> cssDecl;
|
|
|
|
nsCOMPtr<nsIDOMElement> domElement(do_QueryInterface(elm));
|
|
|
|
window->GetComputedStyle(domElement, EmptyString(), getter_AddRefs(cssDecl));
|
|
|
|
return cssDecl.forget();
|
|
|
|
}
|
|
|
|
|
2011-03-28 06:59:36 -07:00
|
|
|
bool
|
|
|
|
nsWinUtils::MaybeStartWindowEmulation()
|
|
|
|
{
|
|
|
|
// Register window class that'll be used for document accessibles associated
|
|
|
|
// with tabs.
|
2015-04-06 03:33:09 -07:00
|
|
|
if (IPCAccessibilityActive())
|
|
|
|
return false;
|
|
|
|
|
2011-12-05 22:07:46 -08:00
|
|
|
if (Compatibility::IsJAWS() || Compatibility::IsWE() ||
|
|
|
|
Compatibility::IsDolphin() ||
|
2015-06-25 16:48:42 -07:00
|
|
|
XRE_GetProcessType() == GeckoProcessType_Content) {
|
2011-03-28 06:59:36 -07:00
|
|
|
RegisterNativeWindow(kClassNameTabContent);
|
2014-08-06 06:31:21 -07:00
|
|
|
sHWNDCache = new nsRefPtrHashtable<nsPtrHashKey<void>, DocAccessible>(2);
|
2011-03-28 06:59:36 -07:00
|
|
|
return true;
|
|
|
|
}
|
2011-12-05 22:07:46 -08:00
|
|
|
|
2011-03-28 06:59:36 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsWinUtils::ShutdownWindowEmulation()
|
|
|
|
{
|
|
|
|
// Unregister window call that's used for document accessibles associated
|
|
|
|
// with tabs.
|
2011-12-05 22:07:46 -08:00
|
|
|
if (IsWindowEmulationStarted())
|
2013-04-02 17:33:43 -07:00
|
|
|
::UnregisterClassW(kClassNameTabContent, GetModuleHandle(nullptr));
|
2011-03-28 06:59:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsWinUtils::IsWindowEmulationStarted()
|
|
|
|
{
|
2013-09-02 01:41:57 -07:00
|
|
|
return sHWNDCache != nullptr;
|
2011-03-28 06:59:36 -07:00
|
|
|
}
|
|
|
|
|
2010-09-16 20:23:17 -07:00
|
|
|
void
|
|
|
|
nsWinUtils::RegisterNativeWindow(LPCWSTR aWindowClass)
|
|
|
|
{
|
|
|
|
WNDCLASSW wc;
|
|
|
|
wc.style = CS_GLOBALCLASS;
|
2013-05-04 22:38:14 -07:00
|
|
|
wc.lpfnWndProc = WindowProc;
|
2010-09-16 20:23:17 -07:00
|
|
|
wc.cbClsExtra = 0;
|
|
|
|
wc.cbWndExtra = 0;
|
2013-04-02 17:33:43 -07:00
|
|
|
wc.hInstance = GetModuleHandle(nullptr);
|
|
|
|
wc.hIcon = nullptr;
|
|
|
|
wc.hCursor = nullptr;
|
|
|
|
wc.hbrBackground = nullptr;
|
|
|
|
wc.lpszMenuName = nullptr;
|
2010-09-16 20:23:17 -07:00
|
|
|
wc.lpszClassName = aWindowClass;
|
|
|
|
::RegisterClassW(&wc);
|
|
|
|
}
|
|
|
|
|
|
|
|
HWND
|
2011-03-02 06:41:42 -08:00
|
|
|
nsWinUtils::CreateNativeWindow(LPCWSTR aWindowClass, HWND aParentWnd,
|
|
|
|
int aX, int aY, int aWidth, int aHeight,
|
|
|
|
bool aIsActive)
|
|
|
|
{
|
2011-10-11 09:11:35 -07:00
|
|
|
HWND hwnd = ::CreateWindowExW(WS_EX_TRANSPARENT, aWindowClass,
|
|
|
|
L"NetscapeDispatchWnd",
|
|
|
|
WS_CHILD | (aIsActive ? WS_VISIBLE : 0),
|
|
|
|
aX, aY, aWidth, aHeight,
|
|
|
|
aParentWnd,
|
2013-04-02 17:33:43 -07:00
|
|
|
nullptr,
|
|
|
|
GetModuleHandle(nullptr),
|
|
|
|
nullptr);
|
2011-10-11 09:11:35 -07:00
|
|
|
if (hwnd) {
|
|
|
|
// Mark this window so that ipc related code can identify it.
|
|
|
|
::SetPropW(hwnd, kPropNameTabContent, (HANDLE)1);
|
|
|
|
}
|
|
|
|
return hwnd;
|
2011-03-02 06:41:42 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsWinUtils::ShowNativeWindow(HWND aWnd)
|
|
|
|
{
|
|
|
|
::ShowWindow(aWnd, SW_SHOW);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsWinUtils::HideNativeWindow(HWND aWnd)
|
2010-09-16 20:23:17 -07:00
|
|
|
{
|
2013-04-02 17:33:43 -07:00
|
|
|
::SetWindowPos(aWnd, nullptr, 0, 0, 0, 0,
|
2011-03-02 06:41:42 -08:00
|
|
|
SWP_HIDEWINDOW | SWP_NOSIZE | SWP_NOMOVE |
|
|
|
|
SWP_NOZORDER | SWP_NOACTIVATE);
|
2010-09-16 20:23:17 -07:00
|
|
|
}
|
2013-05-04 22:38:14 -07:00
|
|
|
|
|
|
|
LRESULT CALLBACK
|
|
|
|
WindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
|
|
|
// Note, this window's message handling should not invoke any call that
|
|
|
|
// may result in a cross-process ipc call. Doing so may violate RPC
|
|
|
|
// message semantics.
|
|
|
|
|
|
|
|
switch (msg) {
|
|
|
|
case WM_GETOBJECT:
|
|
|
|
{
|
2015-05-12 09:43:38 -07:00
|
|
|
// Do explicit casting to make it working on 64bit systems (see bug 649236
|
|
|
|
// for details).
|
|
|
|
int32_t objId = static_cast<DWORD>(lParam);
|
|
|
|
if (objId == OBJID_CLIENT) {
|
2013-05-04 22:38:14 -07:00
|
|
|
DocAccessible* document =
|
2013-09-02 01:41:57 -07:00
|
|
|
nsWinUtils::sHWNDCache->GetWeak(static_cast<void*>(hWnd));
|
2013-05-04 22:38:14 -07:00
|
|
|
if (document) {
|
|
|
|
IAccessible* msaaAccessible = nullptr;
|
|
|
|
document->GetNativeInterface((void**)&msaaAccessible); // does an addref
|
|
|
|
if (msaaAccessible) {
|
|
|
|
LRESULT result = ::LresultFromObject(IID_IAccessible, wParam,
|
|
|
|
msaaAccessible); // does an addref
|
|
|
|
msaaAccessible->Release(); // release extra addref
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
case WM_NCHITTEST:
|
|
|
|
{
|
|
|
|
LRESULT lRet = ::DefWindowProc(hWnd, msg, wParam, lParam);
|
|
|
|
if (HTCLIENT == lRet)
|
|
|
|
lRet = HTTRANSPARENT;
|
|
|
|
return lRet;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ::DefWindowProcW(hWnd, msg, wParam, lParam);
|
|
|
|
}
|