JSDoc: Namespace: event

# Namespace: event

## event

Source:
  - event.js, line 42

### Methods

#### (static) isKeypressFiredKey()

Returns true if the given key should cause keypress event when widget handles the native key event. Otherwise, false.

The key code should be one of consts of nsIDOMKeyEvent.DOMVK*, or a key name begins with "VK_", or a character.

Source:
  - event.js, line 454

#### (static) sendChar()

Send character to the currently focused element.

This function handles casing of characters (sends the right charcode, and sends a shift key for uppercase chars). No other modifiers are handled at this point.

For now this method only works for English letters (lower and upper case) and the digits 0-9.

Source:
  - event.js, line 155

#### (static) sendKey()

Send the non-character key to the focused element.

The name of the key should be the part that comes after "DOMVK" in the nsIDOMKeyEvent constant name for this key. No modifiers are handled at this point.

Source:
  - event.js, line 180

#### (static) sendKeysToElement(keyString, element, optsopt, windowopt)

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`keyString` | string |  |
`element` | Element |  |
`opts` | Object.<string, boolean> | <optional> |
`window` | Window | <optional> |

Source:
  - event.js, line 1356

#### (static) sendMouseEvent(mouseEvent, target, windowopt)

Sends a mouse event to given target.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`mouseEvent` | nsIDOMMouseEvent |  | Event to send.
`target` | DOMElement | string |  | Target of event. Can either be an element or the ID of an element.
`window` | Window | <optional> | Window object. Defaults to the current window.

Source:
  - event.js, line 85

##### Throws:

If the event is unsupported.

Type
  TypeError

#### (static) sendSingleKey(keyToSend, modifiers, windowopt)

Synthesize a key event for a single key.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`keyToSend` | string |  | Code point or normalized key value
`modifiers` | Object.<string, boolean> |  | Object with properties used in KeyboardEvent (shiftkey, repeat, ...) as well as, the event |type| such as keydown. All properties are optional.
`window` | Window | <optional> | Window object. If |window| is undefined, the event is synthesized in current window.

Source:
  - event.js, line 1318

#### (static) sendString()

Send string to the focused element.

For now this method only works for English letters (lower and upper case) and the digits 0-9.

Source:
  - event.js, line 167

#### (static) synthesizeComposition(ev, windowopt)

Synthesize a composition event.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`ev` | DOMEvent |  | The composition event information. This must have |type| member. The value must be "compositionstart", "compositionend" or "compositionupdate". And also this may have |data| and |locale| which would be used for the value of each property of the composition event. Note that the data would be ignored if the event type were "compositionstart".
`window` | Window | <optional> | Window object. Defaults to the current window.

Source:
  - event.js, line 1012

#### (static) synthesizeKey(key, event, windowopt)

Synthesise a key event.

It is targeted at whatever would be targeted by an actual keypress by the user, typically the focused element.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`key` | string |  | Key to synthesise. Should either be a character or a key code starting with "VK_" such as VK_RETURN, or a normalized key value.
`event` | Object.<string, ?> |  | Object which may contain the properties shiftKey, ctrlKey, altKey, metaKey, accessKey, type. If the type is specified (keydown or keyup), a key event of that type is fired. Otherwise, a keydown, a keypress, and then a keyup event are fired in sequence.
`window` | Window | <optional> | Window object. Defaults to the current window.

Source:
  - event.js, line 503

##### Throws:

If unknown key.

Type
  TypeError

#### (static) synthesizeKeyExpectEvent(key, ev, expectedTarget, expectedEvent, testName, windowopt)

Similar to synthesizeKey except that a test is performed to see if an event is fired at the right target as a result.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`key` | string |  | Key to synthesise.
`ev` | Object.<string, ?> |  | Object which may contain the properties shiftKey, ctrlKey, altKey, metaKey, accessKey, type.
`expectedTarget` | Element |  | Expected originalTarget of the event.
`expectedEvent` | DOMEvent |  | Expected type of the event, such as "select".
`testName` | string |  | Test name when outputing results
`window` | Window | <optional> | Window object. Defaults to the current window. To test that an event is not fired, use an expected type preceded by an exclamation mark, such as "!select". aWindow is optional, and defaults to the current window object.

Source:
  - event.js, line 983

#### (static) synthesizeMouse(element, offsetX, offsetY, opts, windowopt)

Synthesise a mouse event on a target.

The actual client point is determined by taking the aTarget's client box and offseting it by offsetX and offsetY. This allows mouse clicks to be simulated by calling this method.

If the type is specified, an mouse event of that type is fired. Otherwise, a mousedown followed by a mouse up is performed.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`element` | Element |  | Element to click.
`offsetX` | number |  | Horizontal offset to click from the target's bounding box.
`offsetY` | number |  | Vertical offset to click from the target's bounding box.
`opts` | Object.<string, ?> |  | Object which may contain the properties "shiftKey", "ctrlKey", "altKey", "metaKey", "accessKey", "clickCount", "button", and "type".
`window` | Window | <optional> | Window object. Defaults to the current window.

Source:
  - event.js, line 234

#### (static) synthesizeMouseAtCenter()

Call event.synthesizeMouse with coordinates at the centre of the target.

Source:
  - event.js, line 332

#### (static) synthesizeMouseExpectEvent(target, offsetX, offsetY, ev, expectedTarget, expectedEvent, testName, windowopt)

Similar to event.synthesizeMouse except that a test is performed to see if an event is fired at the right target as a result.

To test that an event is not fired, use an expected type preceded by an exclamation mark, such as "!select". This might be used to test that a click on a disabled element doesn't fire certain events for instance.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`target` | Element |  | Synthesise the mouse event on this target.
`offsetX` | number |  | Horizontal offset from the target's bounding box.
`offsetY` | number |  | Vertical offset from the target's bounding box.
`ev` | Object.<string, ?> |  | Object which may contain the properties shiftKey, ctrlKey, altKey, metaKey, accessKey, type.
`expectedTarget` | Element |  | Expected originalTarget of the event.
`expectedEvent` | DOMEvent |  | Expected type of the event, such as "select".
`testName` | string |  | Test name when outputing results.
`window` | Window | <optional> | Window object. Defaults to the current window.

Source:
  - event.js, line 944

#### (static) synthesizeQuerySelectedText(Windowopt) → {nsIQueryContentEventResult|null}

Synthesize a query selected text event.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`Window` | Window | <optional> | object. Defaults to the current window.

Source:
  - event.js, line 1109

##### Returns:

Event's result, or null if it failed.

Type
  nsIQueryContentEventResult | null

#### (static) synthesizeSelectionSet(offset, length, reverse, windowopt)

Synthesize a selection set event.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`offset` | number |  | Character offset. 0 means the first character in the selection root.
`length` | number |  | Length of the text. If the length is too long, the extra length is ignored.
`reverse` | boolean |  | If true, the selection is from |aOffset + aLength| to |aOffset|. Otherwise, from |aOffset| to |aOffset + aLength|.
`window` | Window | <optional> | Window object. Defaults to the current window.

Source:
  - event.js, line 1132

##### Returns:

True, if succeeded. Otherwise false.

#### (static) synthesizeText(ev, windowopt)

Synthesize a text event.

The text event's information, this has |composition| and |caret| members. |composition| has |string| and |clauses| members. |clauses| must be array object. Each object has |length| and |attr|. And |caret| has |start| and |length|. See the following tree image.

    ev
     +-- composition
     |     +-- string
     |     +-- clauses[]
     |           +-- length
     |           +-- attr
     +-- caret
           +-- start
           +-- length

Set the composition string to |composition.string|. Set its clauses information to the |clauses| array.

When it's composing, set the each clauses' length to the |composition.clauses[n].length|. The sum of the all length values must be same as the length of |composition.string|. Set nsIDOMWindowUtils.COMPOSITIONATTR* to the |composition.clauses[n].attr|.

When it's not composing, set 0 to the |composition.clauses[0].length| and |composition.clauses[0].attr|.

Set caret position to the |caret.start|. Its offset from the start of the composition string. Set caret length to |caret.length|. If it's larger than 0, it should be wide caret. However, current nsEditor doesn't support wide caret, therefore, you should always set 0 now.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`ev` | Object.<string, ?> |  | The text event's information,
`window` | Window | <optional> | Window object. Defaults to the current window.

Source:
  - event.js, line 1057