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/. */ 7 8 #ifndef nsWinUtils_h_ 9 #define nsWinUtils_h_ 10 11 #include <functional> 12 #include <windows.h> 13 14 #include "nsICSSDeclaration.h" 15 #include "nsCOMPtr.h" 16 17 class nsIContent; 18 19 namespace mozilla { 20 namespace a11y { 21 22 class DocAccessible; 23 24 const LPCWSTR kClassNameRoot = L"MozillaUIWindowClass"; 25 const LPCWSTR kClassNameTabContent = L"MozillaContentWindowClass"; 26 const LPCWSTR kPropNameDocAcc = L"MozDocAccessible"; 27 const LPCWSTR kPropNameDocAccParent = L"MozDocAccessibleParent"; 28 29 class nsWinUtils { 30 public: 31 /** 32 * Return computed styles declaration for the given node. 33 * 34 * @note Please use it carefully since it can shutdown the accessible tree 35 * you operate on. 36 */ 37 static already_AddRefed<nsICSSDeclaration> GetComputedStyleDeclaration( 38 nsIContent* aContent); 39 40 /** 41 * Start window emulation if presence of specific AT is detected. 42 */ 43 static bool MaybeStartWindowEmulation(); 44 45 /** 46 * Free resources used for window emulation. 47 */ 48 static void ShutdownWindowEmulation(); 49 50 /** 51 * Return true if window emulation is started. 52 */ IsWindowEmulationStarted()53 static bool IsWindowEmulationStarted() { return sWindowEmulationStarted; } 54 55 /** 56 * Helper to register window class. 57 */ 58 static void RegisterNativeWindow(LPCWSTR aWindowClass); 59 60 typedef std::function<void(HWND)> NativeWindowCreateProc; 61 62 /** 63 * Helper to create a window. 64 * 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. 70 * 71 * For example: 72 * 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! 79 */ 80 static HWND CreateNativeWindow( 81 LPCWSTR aWindowClass, HWND aParentWnd, int aX, int aY, int aWidth, 82 int aHeight, bool aIsActive, 83 NativeWindowCreateProc* aOnCreateProc = nullptr); 84 85 /** 86 * Helper to show window. 87 */ 88 static void ShowNativeWindow(HWND aWnd); 89 90 /** 91 * Helper to hide window. 92 */ 93 static void HideNativeWindow(HWND aWnd); 94 95 private: 96 /** 97 * Flag that indicates if window emulation is started. 98 */ 99 static bool sWindowEmulationStarted; 100 }; 101 102 } // namespace a11y 103 } // namespace mozilla 104 105 #endif 106