goog.ui.KeyboardShortcutHandler
Provided By | |
---|---|
Extends | |
All Implemented Interfaces |
Component for handling keyboard shortcuts. A shortcut is registered and bound to a specific identifier. Once the shortcut is triggered an event is fired with the identifier for the shortcut. This allows keyboard shortcuts to be customized without modifying the code that listens for them.
Supports keyboard shortcuts triggered by a single key, a stroke stroke (key plus at least one modifier) and a sequence of keys or strokes.
new KeyboardShortcutHandler( keyTarget )
Parameters |
|
---|
Instance Methods
this.addEventListener( type, handler, opt_capture, opt_handlerScope ) → void
void
Adds an event listener to the event target. The same handler can only be added once per the type. Even if you add the same handler multiple times using the same type then it will only be called once when the event is dispatched.
warning Deprecated | Use |
---|
Defined by | |||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Parameters |
|
this.addOnDisposeCallback<T>( callback, opt_scope ) → void
void
Invokes a callback function when this object is disposed. Callbacks are invoked in the order in which they were added. If a callback is added to an already disposed Disposable, it will be called immediately.
Defined by | |||||||||
---|---|---|---|---|---|---|---|---|---|
Parameters |
|
this.clearKeyListener() → void
void
Removes the listener that was added by link #initializeKeyListener
.
this.dispatchEvent( e ) → boolean
boolean
Dispatches an event (or event like object) and calls all listeners listening for events of this type. The type of the event is decided by the type property on the event object.
If any of the listeners returns false OR calls preventDefault then this function will return false. If one of the capture listeners calls stopPropagation, then the bubble listeners won't fire.
Overrides | |||||
---|---|---|---|---|---|
Specified by | |||||
Parameters |
| ||||
Returns |
|
this.dispose() → ?
?
Disposes of the object and its resources.
Overrides | ||
---|---|---|
Specified by | ||
Parameters | None. | |
Returns |
|
this.disposeInternal() → void
void
Removes listeners from this object. Classes that extend EventTarget may need to override this method in order to remove references to DOM Elements and additional listeners.
Overrides | |
---|---|
Parameters | None. |
this.fireListeners<EVENTOBJ>( type, capture, eventObject ) → boolean
boolean
Fires all registered listeners in this listenable for the given type and capture mode, passing them the given eventObject. This does not perform actual capture/bubble. Only implementors of the interface should be using this.
Overrides | |||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Specified by | |||||||||||||
Parameters |
| ||||||||||||
Returns |
|
this.getAllShortcutsAreGlobal() → boolean
boolean
Returns whether all shortcuts (including modifier shortcuts) are treated as if the keys had been passed to the setGlobalKeys function.
Parameters | None. | ||
---|---|---|---|
Returns |
| ||
See Also |
this.getAlwaysPreventDefault() → boolean
boolean
Returns whether the default action will always be prevented when a shortcut event is fired. The default value is true.
Parameters | None. | ||
---|---|---|---|
Returns |
| ||
See Also |
this.getAlwaysStopPropagation() → boolean
boolean
Returns whether the event will always be stopped from propagating beyond its target when a shortcut event is fired. The default value is false.
Parameters | None. | ||
---|---|---|---|
Returns |
| ||
See Also |
this.getDisposed() → boolean
boolean
warning Deprecated | Use |
---|
Defined by | |||
---|---|---|---|
Parameters | None. | ||
Returns |
|
this.getEventType( identifier ) → string
string
this.getListener<SCOPE, EVENTOBJ>( type, listener, capture, opt_listenerScope ) → (goog.events.ListenableKey|null)
(goog.events.ListenableKey|null)
Gets the goog.events.ListenableKey for the event or null if no such listener is in use.
Overrides | |||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Specified by | |||||||||||||||||
Parameters |
| ||||||||||||||||
Returns |
|
this.getListeners<EVENTOBJ>( type, capture ) → Array<goog.events.ListenableKey>
Array<goog.events.ListenableKey>
Gets all listeners in this listenable for the given type and capture mode.
Overrides | |||||||||
---|---|---|---|---|---|---|---|---|---|
Specified by | |||||||||
Parameters |
| ||||||||
Returns |
|
this.getModifierShortcutsAreGlobal() → boolean
boolean
Returns whether shortcuts with modifiers are treated as if the keys had been passed to the setGlobalKeys function. Ignored if you have called setAllShortcutsAreGlobal(true). Applies only to form elements (not content-editable).
Parameters | None. | ||
---|---|---|---|
Returns |
| ||
See Also |
this.getParentEventTarget() → (goog.events.Listenable|null)
(goog.events.Listenable|null)
Returns the parent of this event target to use for capture/bubble mechanism.
NOTE(chrishenry): The name reflects the original implementation of
custom event target (goog.events.EventTarget
). We decided
that changing the name is not worth it.
Overrides | |||
---|---|---|---|
Specified by | |||
Parameters | None. | ||
Returns |
|
this.hasListener<EVENTOBJ>( opt_type, opt_capture ) → boolean
boolean
Whether there is any active listeners matching the specified signature. If either the type or capture parameters are unspecified, the function will match on the remaining criteria.
Overrides | |||||||||
---|---|---|---|---|---|---|---|---|---|
Specified by | |||||||||
Parameters |
| ||||||||
Returns |
|
this.initializeKeyListener( keyTarget ) → void
void
Adds a key event listener that triggers #handleKeyDown_
when keys
are pressed.
Parameters |
|
---|
this.isDisposed() → boolean
boolean
Overrides | |||
---|---|---|---|
Specified by | |||
Parameters | None. | ||
Returns |
|
this.isShortcutRegistered( ...var_args ) → boolean
boolean
Verifies if a particular keyboard shortcut is registered already. It has the same interface as the unregistering of shortcuts.
param {number} keyCode Numeric code for key param {number=} opt_modifiers Bitmap indicating required modifier keys. goog.ui.KeyboardShortcutHandler.Modifiers.SHIFT, CTRL, ALT, or META.
The two parameters can be repeated any number of times to create a shortcut using a sequence of strokes.
A string representation of the shortcut can be supplied instead see
#registerShortcut
for syntax. In that case the method only takes one
argument.
Parameters |
| ||||
---|---|---|---|---|---|
Returns |
|
this.listen<SCOPE, EVENTOBJ>( type, listener, opt_useCapture, opt_listenerScope ) → goog.events.ListenableKey
goog.events.ListenableKey
Adds an event listener. A listener can only be added once to an object and if it is added again the key for the listener is returned. Note that if the existing listener is a one-off listener (registered via listenOnce), it will no longer be a one-off listener after a call to listen().
Overrides | |||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Specified by | |||||||||||||||||
Parameters |
| ||||||||||||||||
Returns |
|
this.listenOnce<SCOPE, EVENTOBJ>( type, listener, opt_useCapture, opt_listenerScope ) → goog.events.ListenableKey
goog.events.ListenableKey
Adds an event listener that is removed automatically after the listener fired once.
If an existing listener already exists, listenOnce will do nothing. In particular, if the listener was previously registered via listen(), listenOnce() will not turn the listener into a one-off listener. Similarly, if there is already an existing one-off listener, listenOnce does not modify the listeners (it is still a once listener).
Overrides | |||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Specified by | |||||||||||||||||
Parameters |
| ||||||||||||||||
Returns |
|
this.registerDisposable( disposable ) → void
void
Associates a disposable object with this object so that they will be disposed together.
Defined by | |||||
---|---|---|---|---|---|
Parameters |
|
this.registerShortcut( identifier, ...var_args ) → void
void
Registers a keyboard shortcut.
Parameters |
|
---|
this.removeAllListeners( opt_type ) → number
number
Removes all listeners from this listenable. If type is specified, it will only remove listeners of the particular type. otherwise all registered listeners will be removed.
Overrides | |||||
---|---|---|---|---|---|
Specified by | |||||
Parameters |
| ||||
Returns |
|
this.removeEventListener( type, handler, opt_capture, opt_handlerScope ) → void
void
Removes an event listener from the event target. The handler must be the same object as the one added. If the handler has not been added then nothing is done.
warning Deprecated | Use |
---|
Defined by | |||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Parameters |
|
this.setAllShortcutsAreGlobal( allShortcutsGlobal ) → void
void
Sets whether to treat all shortcuts (including modifier shortcuts) as if the keys had been passed to the setGlobalKeys function.
Parameters |
|
---|
this.setAllowSpaceKeyOnButtons( allowSpaceKeyOnButtons ) → void
void
Sets whether to treat space key as a shortcut when the focused element is a checkbox, radiobutton or button.
Parameters |
|
---|
this.setAlwaysPreventDefault( alwaysPreventDefault ) → void
void
Sets whether to always prevent the default action when a shortcut event is fired. If false, the default action is prevented only if preventDefault is called on either of the corresponding SHORTCUT_TRIGGERED or SHORTCUT_PREFIX events. If true, the default action is prevented whenever a shortcut event is fired. The default value is true.
Parameters |
|
---|
this.setAlwaysStopPropagation( alwaysStopPropagation ) → void
void
Sets whether to always stop propagation for the event when fired. If false, the propagation is stopped only if stopPropagation is called on either of the corresponding SHORT_CUT_TRIGGERED or SHORTCUT_PREFIX events. If true, the event is prevented from propagating beyond its target whenever it is fired. The default value is false.
Parameters |
|
---|
this.setGlobalKeys( keys ) → void
void
this.setModifierShortcutsAreGlobal( modifierShortcutsGlobal ) → void
void
Sets whether to treat shortcuts with modifiers as if the keys had been passed to the setGlobalKeys function. Ignored if you have called setAllShortcutsAreGlobal(true). Applies only to form elements (not content-editable).
Parameters |
|
---|
this.setParentEventTarget( parent ) → void
void
Sets the parent of this event target to use for capture/bubble mechanism.
Defined by | |||||
---|---|---|---|---|---|
Parameters |
|
this.setTargetForTesting( target ) → void
void
Sets the target to be used for event.target
when firing
event. Mainly used for testing. For example, see
goog.testing.events.mixinListenable
.
Defined by | |||||
---|---|---|---|---|---|
Parameters |
|
this.unlisten<SCOPE, EVENTOBJ>( type, listener, opt_useCapture, opt_listenerScope ) → boolean
boolean
Removes an event listener which was added with listen() or listenOnce().
Overrides | |||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Specified by | |||||||||||||||||
Parameters |
| ||||||||||||||||
Returns |
|
this.unlistenByKey( key ) → boolean
boolean
Removes an event listener which was added with listen() by the key returned by listen().
Overrides | |||||
---|---|---|---|---|---|
Specified by | |||||
Parameters |
| ||||
Returns |
|
this.unregisterAll() → void
void
Unregisters all keyboard shortcuts.
this.unregisterShortcut( ...var_args ) → void
void
Unregisters a keyboard shortcut by keyCode and modifiers or string representation of sequence.
param {number} keyCode Numeric code for key param {number=} opt_modifiers Bitmap indicating required modifier keys. goog.ui.KeyboardShortcutHandler.Modifiers.SHIFT, CTRL, ALT, or META.
The two parameters can be repeated any number of times to create a shortcut using a sequence of strokes.
A string representation of the shortcut can be supplied instead see
#registerShortcut
for syntax. In that case the method only takes one
argument.
Parameters |
|
---|
Instance Properties
this.creationStack → (string|undefined)
(string|undefined)
If monitoring the goog.Disposable instances is enabled, stores the creation stack trace of the Disposable instance.
Static Functions
KeyboardShortcutHandler.getKeyCode( name ) → number
number
Static Properties
KeyboardShortcutHandler.MAX_KEY_SEQUENCE_DELAY → number
number
Maximum allowed delay, in milliseconds, allowed between the first and second key in a key sequence.