Bug 1769547 - Do not MOZ_CRASH() on missing process r=nika
[gecko.git] / accessible / windows / msaa / nsWinUtils.h
blob7ae0cadc5d8c7d92ce3f6aa8b010a76f9825fe99
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:expandtab:shiftwidth=2:tabstop=2:
3 */
4 /* This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
8 #ifndef nsWinUtils_h_
9 #define nsWinUtils_h_
11 #include <functional>
12 #include <windows.h>
14 #include "nsICSSDeclaration.h"
15 #include "nsCOMPtr.h"
17 class nsIContent;
19 namespace mozilla {
20 namespace a11y {
22 class DocAccessible;
24 const LPCWSTR kClassNameRoot = L"MozillaUIWindowClass";
25 const LPCWSTR kClassNameTabContent = L"MozillaContentWindowClass";
26 const LPCWSTR kPropNameDocAcc = L"MozDocAccessible";
27 const LPCWSTR kPropNameDocAccParent = L"MozDocAccessibleParent";
29 class nsWinUtils {
30 public:
31 /**
32 * Return computed styles declaration for the given node.
34 * @note Please use it carefully since it can shutdown the accessible tree
35 * you operate on.
37 static already_AddRefed<nsICSSDeclaration> GetComputedStyleDeclaration(
38 nsIContent* aContent);
40 /**
41 * Start window emulation if presence of specific AT is detected.
43 static bool MaybeStartWindowEmulation();
45 /**
46 * Free resources used for window emulation.
48 static void ShutdownWindowEmulation();
50 /**
51 * Return true if window emulation is started.
53 static bool IsWindowEmulationStarted() { return sWindowEmulationStarted; }
55 /**
56 * Helper to register window class.
58 static void RegisterNativeWindow(LPCWSTR aWindowClass);
60 typedef std::function<void(HWND)> NativeWindowCreateProc;
62 /**
63 * Helper to create a window.
65 * NB: If additional setup needs to be done once the window has been created,
66 * you should do so via aOnCreateProc. Hooks will fire during the
67 * CreateNativeWindow call, thus triggering events in the AT.
68 * Using aOnCreateProc guarantees that your additional initialization will
69 * have completed prior to the AT receiving window creation events.
71 * For example:
73 * nsWinUtils::NativeWindowCreateProc onCreate([](HWND aHwnd) -> void {
74 * DoSomeAwesomeInitializationStuff(aHwnd);
75 * DoMoreAwesomeInitializationStuff(aHwnd);
76 * });
77 * HWND hwnd = nsWinUtils::CreateNativeWindow(..., &onCreate);
78 * // Doing further initialization work to hwnd on this line is too late!
80 static HWND CreateNativeWindow(
81 LPCWSTR aWindowClass, HWND aParentWnd, int aX, int aY, int aWidth,
82 int aHeight, bool aIsActive,
83 NativeWindowCreateProc* aOnCreateProc = nullptr);
85 /**
86 * Helper to show window.
88 static void ShowNativeWindow(HWND aWnd);
90 /**
91 * Helper to hide window.
93 static void HideNativeWindow(HWND aWnd);
95 private:
96 /**
97 * Flag that indicates if window emulation is started.
99 static bool sWindowEmulationStarted;
102 } // namespace a11y
103 } // namespace mozilla
105 #endif