1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/accessible/src/base/FocusManager.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,134 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +#ifndef mozilla_a11y_FocusManager_h_ 1.9 +#define mozilla_a11y_FocusManager_h_ 1.10 + 1.11 +#include "nsAutoPtr.h" 1.12 + 1.13 +class nsINode; 1.14 +class nsIDocument; 1.15 +class nsISupports; 1.16 + 1.17 +namespace mozilla { 1.18 +namespace a11y { 1.19 + 1.20 +class AccEvent; 1.21 +class Accessible; 1.22 +class DocAccessible; 1.23 + 1.24 +/** 1.25 + * Manage the accessible focus. Used to fire and process accessible events. 1.26 + */ 1.27 +class FocusManager 1.28 +{ 1.29 +public: 1.30 + virtual ~FocusManager(); 1.31 + 1.32 + /** 1.33 + * Return a focused accessible. 1.34 + */ 1.35 + Accessible* FocusedAccessible() const; 1.36 + 1.37 + /** 1.38 + * Return true if given accessible is focused. 1.39 + */ 1.40 + bool IsFocused(const Accessible* aAccessible) const; 1.41 + 1.42 + /** 1.43 + * Return true if the given accessible is an active item, i.e. an item that 1.44 + * is current within the active widget. 1.45 + */ 1.46 + inline bool IsActiveItem(const Accessible* aAccessible) 1.47 + { return aAccessible == mActiveItem; } 1.48 + 1.49 + /** 1.50 + * Return true if given DOM node has DOM focus. 1.51 + */ 1.52 + inline bool HasDOMFocus(const nsINode* aNode) const 1.53 + { return aNode == FocusedDOMNode(); } 1.54 + 1.55 + /** 1.56 + * Return true if focused accessible is within the given container. 1.57 + */ 1.58 + bool IsFocusWithin(const Accessible* aContainer) const; 1.59 + 1.60 + /** 1.61 + * Return whether the given accessible is focused or contains the focus or 1.62 + * contained by focused accessible. 1.63 + */ 1.64 + enum FocusDisposition { 1.65 + eNone, 1.66 + eFocused, 1.67 + eContainsFocus, 1.68 + eContainedByFocus 1.69 + }; 1.70 + FocusDisposition IsInOrContainsFocus(const Accessible* aAccessible) const; 1.71 + 1.72 + ////////////////////////////////////////////////////////////////////////////// 1.73 + // Focus notifications and processing (don't use until you know what you do). 1.74 + 1.75 + /** 1.76 + * Called when DOM focus event is fired. 1.77 + */ 1.78 + void NotifyOfDOMFocus(nsISupports* aTarget); 1.79 + 1.80 + /** 1.81 + * Called when DOM blur event is fired. 1.82 + */ 1.83 + void NotifyOfDOMBlur(nsISupports* aTarget); 1.84 + 1.85 + /** 1.86 + * Called when active item is changed. Note: must be called when accessible 1.87 + * tree is up to date. 1.88 + */ 1.89 + void ActiveItemChanged(Accessible* aItem, bool aCheckIfActive = true); 1.90 + 1.91 + /** 1.92 + * Dispatch delayed focus event for the current focus accessible. 1.93 + */ 1.94 + void ForceFocusEvent(); 1.95 + 1.96 + /** 1.97 + * Dispatch delayed focus event for the given target. 1.98 + */ 1.99 + void DispatchFocusEvent(DocAccessible* aDocument, Accessible* aTarget); 1.100 + 1.101 + /** 1.102 + * Process DOM focus notification. 1.103 + */ 1.104 + void ProcessDOMFocus(nsINode* aTarget); 1.105 + 1.106 + /** 1.107 + * Process the delayed accessible event. 1.108 + * do. 1.109 + */ 1.110 + void ProcessFocusEvent(AccEvent* aEvent); 1.111 + 1.112 +protected: 1.113 + FocusManager(); 1.114 + 1.115 +private: 1.116 + FocusManager(const FocusManager&); 1.117 + FocusManager& operator =(const FocusManager&); 1.118 + 1.119 + /** 1.120 + * Return DOM node having DOM focus. 1.121 + */ 1.122 + nsINode* FocusedDOMNode() const; 1.123 + 1.124 + /** 1.125 + * Return DOM document having DOM focus. 1.126 + */ 1.127 + nsIDocument* FocusedDOMDocument() const; 1.128 + 1.129 +private: 1.130 + nsRefPtr<Accessible> mActiveItem; 1.131 + nsRefPtr<Accessible> mActiveARIAMenubar; 1.132 +}; 1.133 + 1.134 +} // namespace a11y 1.135 +} // namespace mozilla 1.136 + 1.137 +#endif