tor-browser

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

FocusManager.h (4313B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 #ifndef mozilla_a11y_FocusManager_h_
      6 #define mozilla_a11y_FocusManager_h_
      7 
      8 #include "mozilla/RefPtr.h"
      9 
     10 class nsINode;
     11 class nsISupports;
     12 
     13 namespace mozilla {
     14 namespace dom {
     15 class Document;
     16 }
     17 
     18 namespace a11y {
     19 
     20 class Accessible;
     21 class AccEvent;
     22 class LocalAccessible;
     23 class DocAccessible;
     24 class DocAccessibleParent;
     25 
     26 /**
     27 * Manage the accessible focus. Used to fire and process accessible events.
     28 */
     29 class FocusManager {
     30 public:
     31  virtual ~FocusManager();
     32 
     33  /**
     34   * Return the currently focused LocalAccessible. If a remote document has
     35   * focus, this will return null.
     36   */
     37  LocalAccessible* FocusedLocalAccessible() const;
     38 
     39  /**
     40   * Return the currently focused Accessible, local or remote.
     41   */
     42  Accessible* FocusedAccessible() const;
     43 
     44  /**
     45   * Return true if given accessible is focused.
     46   */
     47  bool IsFocused(const Accessible* aAccessible) const {
     48    return FocusedAccessible() == aAccessible;
     49  }
     50 
     51  /**
     52   * Return true if the given accessible is an active item, i.e. an item that
     53   * is current within the active widget.
     54   */
     55  inline bool IsActiveItem(const LocalAccessible* aAccessible) {
     56    return aAccessible == mActiveItem;
     57  }
     58 
     59  /**
     60   * Return DOM node having DOM focus.
     61   */
     62  nsINode* FocusedDOMNode() const;
     63 
     64  /**
     65   * Return true if given DOM node has DOM focus.
     66   */
     67  inline bool HasDOMFocus(const nsINode* aNode) const {
     68    return aNode == FocusedDOMNode();
     69  }
     70 
     71  /**
     72   * Return true if focused accessible is within the given container.
     73   */
     74  bool IsFocusWithin(const Accessible* aContainer) const;
     75 
     76  /**
     77   * Return whether the given accessible is focused or contains the focus or
     78   * contained by focused accessible.
     79   */
     80  enum FocusDisposition { eNone, eFocused, eContainsFocus, eContainedByFocus };
     81  FocusDisposition IsInOrContainsFocus(
     82      const LocalAccessible* aAccessible) const;
     83 
     84  /**
     85   * Return true if the given accessible was the last accessible focused.
     86   * This is useful to detect the case where the last focused accessible was
     87   * removed before something else was focused. This can happen in one of two
     88   * ways:
     89   * 1. The DOM focus was removed. DOM doesn't fire a blur event when this
     90   *    happens; see bug 559561.
     91   * 2. The accessibility focus was an active item (e.g. aria-activedescendant)
     92   *    and that item was removed.
     93   */
     94  bool WasLastFocused(const LocalAccessible* aAccessible) const;
     95 
     96  //////////////////////////////////////////////////////////////////////////////
     97  // Focus notifications and processing (don't use until you know what you do).
     98 
     99  /**
    100   * Called when DOM focus event is fired.
    101   */
    102  void NotifyOfDOMFocus(nsISupports* aTarget);
    103 
    104  /**
    105   * Called when DOM blur event is fired.
    106   */
    107  void NotifyOfDOMBlur(nsISupports* aTarget);
    108 
    109  /**
    110   * Called when active item is changed. Note: must be called when accessible
    111   * tree is up to date.
    112   */
    113  void ActiveItemChanged(LocalAccessible* aItem, bool aCheckIfActive = true);
    114 
    115  /**
    116   * Dispatch delayed focus event for the current focus accessible.
    117   */
    118  void ForceFocusEvent();
    119 
    120  /**
    121   * Dispatch delayed focus event for the given target.
    122   */
    123  void DispatchFocusEvent(DocAccessible* aDocument, LocalAccessible* aTarget);
    124 
    125  /**
    126   * Process DOM focus notification.
    127   */
    128  void ProcessDOMFocus(nsINode* aTarget);
    129 
    130  /**
    131   * Process the delayed accessible event.
    132   * do.
    133   */
    134  void ProcessFocusEvent(AccEvent* aEvent);
    135 
    136 #ifdef ANDROID
    137  void SetFocusedRemoteDoc(DocAccessibleParent* aDoc) {
    138    mFocusedRemoteDoc = aDoc;
    139  }
    140  bool IsFocusedRemoteDoc(DocAccessibleParent* aDoc) {
    141    return mFocusedRemoteDoc == aDoc;
    142  }
    143 #endif
    144 
    145 protected:
    146  FocusManager();
    147 
    148 private:
    149  FocusManager(const FocusManager&);
    150  FocusManager& operator=(const FocusManager&);
    151 
    152  /**
    153   * Return DOM document having DOM focus.
    154   */
    155  dom::Document* FocusedDOMDocument() const;
    156 
    157 private:
    158  RefPtr<LocalAccessible> mActiveItem;
    159  RefPtr<LocalAccessible> mLastFocus;
    160  RefPtr<LocalAccessible> mActiveARIAMenubar;
    161 #ifdef ANDROID
    162  DocAccessibleParent* mFocusedRemoteDoc = nullptr;
    163 #endif
    164 };
    165 
    166 }  // namespace a11y
    167 }  // namespace mozilla
    168 
    169 #endif