import { ISequence } from '../algorithm/sequence'; import { IDisposable } from '../core/disposable'; import { ISignal } from '../core/signaling'; import { Widget } from './widget'; /** * A class which tracks focus among a set of widgets. * * This class is useful when code needs to keep track of the most * recently focused widget(s) among a set of related widgets. */ export declare class FocusTracker implements IDisposable { /** * Construct a new focus tracker. */ constructor(); /** * Dispose of the resources held by the tracker. */ dispose(): void; /** * A signal emitted when the current widget has changed. */ currentChanged: ISignal, FocusTracker.ICurrentChangedArgs>; /** * A flag indicated whether the tracker is disposed. * * #### Notes * This is a read-only property. */ readonly isDisposed: boolean; /** * The current widget in the tracker. * * #### Notes * The current widget is the widget among the tracked widgets which * has the *descendant node* which has most recently been focused. * * The current widget will not be updated if the node loses focus. It * will only be updated when a different tracked widget gains focus. * * If the current widget is removed from the tracker, the previous * current widget will be restored. * * This behavior is intended to follow a user's conceptual model of * a semantically "active" widget, where the "last thing of type X" * to be interacted with is the "active instance of X", regardless * of whether that instance still has focus. * * This will be `null` if there is no current widget. * * This is a read-only property. */ readonly currentWidget: T; /** * A read only sequence of the widgets being tracked. * * #### Notes * This is a read-only property. */ readonly widgets: ISequence; /** * Get the focus number for a particular widget in the tracker. * * @param widget - The widget of interest. * * @returns The focus number for the given widget, or `-1` if the * widget has not had focus since being added to the tracker. * * #### Notes * The focus number indicates the relative order in which the widgets * have gained focus. A widget with a larger number has gained focus * more recently than a widget with a smaller number. * * The `currentWidget` will always have the largest focus number. * * All widgets start with a focus number of `-1`, which indicates that * the widget has not been focused since being added to the tracker. * * #### Undefined Behavior * A `widget` which is not contained in the tracker. */ focusNumber(widget: T): number; /** * Test whether the focus tracker contains a given widget. * * @param widget - The widget of interest. * * @returns `true` if the widget is tracked, `false` otherwise. */ has(widget: T): boolean; /** * Add a widget to the focus tracker. * * @param widget - The widget of interest. * * #### Notes * If the widget is currently focused, it will automatically become * the new `currentWidget`. * * A widget will be automatically removed from the tracker if it * is disposed after being added. * * If the widget is already tracked, this is a no-op. */ add(widget: T): void; /** * Remove a widget from the focus tracker. * * #### Notes * If the widget is the `currentWidget`, the previous current widget * will become the new `currentWidget`. * * A widget will be automatically removed from the tracker if it * is disposed after being added. * * If the widget is not tracked, this is a no-op. */ remove(widget: T): void; /** * Handle the DOM events for the focus tracker. * * @param event - The DOM event sent to the panel. * * #### Notes * This method implements the DOM `EventListener` interface and is * called in response to events on the tracked nodes. It should * not be called directly by user code. */ handleEvent(event: Event): void; /** * Set the current widget for the tracker. */ private _setCurrentWidget(widget); /** * Handle the `'focus'` event for a tracked widget. */ private _evtFocus(event); /** * Handle the `disposed` signal for a tracked widget. */ private _onWidgetDisposed(sender); private _counter; private _currentWidget; private _widgets; private _numbers; private _nodes; } /** * The namespace for the `FocusTracker` class statics. */ export declare namespace FocusTracker { /** * An arguments object for the `currentChanged` signal. */ interface ICurrentChangedArgs { /** * The old value for the `currentWidget`, or `null`. */ oldValue: T; /** * The new value for the `currentWidget`, or `null`. */ newValue: T; } }