tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

nsWinUtils.h (2699B)


      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   * Start window emulation if presence of specific AT is detected.
     33   */
     34  static bool MaybeStartWindowEmulation();
     35 
     36  /**
     37   * Free resources used for window emulation.
     38   */
     39  static void ShutdownWindowEmulation();
     40 
     41  /**
     42   * Return true if window emulation is started.
     43   */
     44  static bool IsWindowEmulationStarted() { return sWindowEmulationStarted; }
     45 
     46  /**
     47   * Helper to register window class.
     48   */
     49  static void RegisterNativeWindow(LPCWSTR aWindowClass);
     50 
     51  typedef std::function<void(HWND)> NativeWindowCreateProc;
     52 
     53  /**
     54   * Helper to create a window.
     55   *
     56   * NB: If additional setup needs to be done once the window has been created,
     57   *     you should do so via aOnCreateProc. Hooks will fire during the
     58   *     CreateNativeWindow call, thus triggering events in the AT.
     59   *     Using aOnCreateProc guarantees that your additional initialization will
     60   *     have completed prior to the AT receiving window creation events.
     61   *
     62   *     For example:
     63   *
     64   *     nsWinUtils::NativeWindowCreateProc onCreate([](HWND aHwnd) -> void {
     65   *       DoSomeAwesomeInitializationStuff(aHwnd);
     66   *       DoMoreAwesomeInitializationStuff(aHwnd);
     67   *     });
     68   *     HWND hwnd = nsWinUtils::CreateNativeWindow(..., &onCreate);
     69   *     // Doing further initialization work to hwnd on this line is too late!
     70   */
     71  static HWND CreateNativeWindow(
     72      LPCWSTR aWindowClass, HWND aParentWnd, int aX, int aY, int aWidth,
     73      int aHeight, bool aIsActive,
     74      NativeWindowCreateProc* aOnCreateProc = nullptr);
     75 
     76  /**
     77   * Helper to show window.
     78   */
     79  static void ShowNativeWindow(HWND aWnd);
     80 
     81  /**
     82   * Helper to hide window.
     83   */
     84  static void HideNativeWindow(HWND aWnd);
     85 
     86 private:
     87  /**
     88   * Flag that indicates if window emulation is started.
     89   */
     90  static bool sWindowEmulationStarted;
     91 };
     92 
     93 }  // namespace a11y
     94 }  // namespace mozilla
     95 
     96 #endif