michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef mozilla_a11y_FocusManager_h_ michael@0: #define mozilla_a11y_FocusManager_h_ michael@0: michael@0: #include "nsAutoPtr.h" michael@0: michael@0: class nsINode; michael@0: class nsIDocument; michael@0: class nsISupports; michael@0: michael@0: namespace mozilla { michael@0: namespace a11y { michael@0: michael@0: class AccEvent; michael@0: class Accessible; michael@0: class DocAccessible; michael@0: michael@0: /** michael@0: * Manage the accessible focus. Used to fire and process accessible events. michael@0: */ michael@0: class FocusManager michael@0: { michael@0: public: michael@0: virtual ~FocusManager(); michael@0: michael@0: /** michael@0: * Return a focused accessible. michael@0: */ michael@0: Accessible* FocusedAccessible() const; michael@0: michael@0: /** michael@0: * Return true if given accessible is focused. michael@0: */ michael@0: bool IsFocused(const Accessible* aAccessible) const; michael@0: michael@0: /** michael@0: * Return true if the given accessible is an active item, i.e. an item that michael@0: * is current within the active widget. michael@0: */ michael@0: inline bool IsActiveItem(const Accessible* aAccessible) michael@0: { return aAccessible == mActiveItem; } michael@0: michael@0: /** michael@0: * Return true if given DOM node has DOM focus. michael@0: */ michael@0: inline bool HasDOMFocus(const nsINode* aNode) const michael@0: { return aNode == FocusedDOMNode(); } michael@0: michael@0: /** michael@0: * Return true if focused accessible is within the given container. michael@0: */ michael@0: bool IsFocusWithin(const Accessible* aContainer) const; michael@0: michael@0: /** michael@0: * Return whether the given accessible is focused or contains the focus or michael@0: * contained by focused accessible. michael@0: */ michael@0: enum FocusDisposition { michael@0: eNone, michael@0: eFocused, michael@0: eContainsFocus, michael@0: eContainedByFocus michael@0: }; michael@0: FocusDisposition IsInOrContainsFocus(const Accessible* aAccessible) const; michael@0: michael@0: ////////////////////////////////////////////////////////////////////////////// michael@0: // Focus notifications and processing (don't use until you know what you do). michael@0: michael@0: /** michael@0: * Called when DOM focus event is fired. michael@0: */ michael@0: void NotifyOfDOMFocus(nsISupports* aTarget); michael@0: michael@0: /** michael@0: * Called when DOM blur event is fired. michael@0: */ michael@0: void NotifyOfDOMBlur(nsISupports* aTarget); michael@0: michael@0: /** michael@0: * Called when active item is changed. Note: must be called when accessible michael@0: * tree is up to date. michael@0: */ michael@0: void ActiveItemChanged(Accessible* aItem, bool aCheckIfActive = true); michael@0: michael@0: /** michael@0: * Dispatch delayed focus event for the current focus accessible. michael@0: */ michael@0: void ForceFocusEvent(); michael@0: michael@0: /** michael@0: * Dispatch delayed focus event for the given target. michael@0: */ michael@0: void DispatchFocusEvent(DocAccessible* aDocument, Accessible* aTarget); michael@0: michael@0: /** michael@0: * Process DOM focus notification. michael@0: */ michael@0: void ProcessDOMFocus(nsINode* aTarget); michael@0: michael@0: /** michael@0: * Process the delayed accessible event. michael@0: * do. michael@0: */ michael@0: void ProcessFocusEvent(AccEvent* aEvent); michael@0: michael@0: protected: michael@0: FocusManager(); michael@0: michael@0: private: michael@0: FocusManager(const FocusManager&); michael@0: FocusManager& operator =(const FocusManager&); michael@0: michael@0: /** michael@0: * Return DOM node having DOM focus. michael@0: */ michael@0: nsINode* FocusedDOMNode() const; michael@0: michael@0: /** michael@0: * Return DOM document having DOM focus. michael@0: */ michael@0: nsIDocument* FocusedDOMDocument() const; michael@0: michael@0: private: michael@0: nsRefPtr mActiveItem; michael@0: nsRefPtr mActiveARIAMenubar; michael@0: }; michael@0: michael@0: } // namespace a11y michael@0: } // namespace mozilla michael@0: michael@0: #endif