Skip to content

Commit 7270661

Browse files
authored
Merge pull request #313 from tindzk/keyboardevent-location
Improve DOM_KEY_LOCATION_* bindings
2 parents 9f681a9 + 7e1b4b8 commit 7270661

File tree

2 files changed

+53
-7
lines changed

2 files changed

+53
-7
lines changed

src/main/scala/org/scalajs/dom/ext/Extensions.scala

+9-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import scala.scalajs.js.typedarray.TypedArrayBufferOps._
1111

1212
import org.scalajs.dom
1313
import org.scalajs.dom.{FormData, html, raw}
14-
import org.scalajs.dom.raw.Blob
14+
import org.scalajs.dom.raw.{Blob, KeyboardEvent}
1515

1616
/**
1717
* Used to extend out javascript *Collections to make them usable as normal
@@ -228,6 +228,14 @@ object KeyCode {
228228
// format: on
229229
}
230230

231+
/** Aliases for DOM_KEY_LOCATION_* constants from [[KeyboardEvent]] */
232+
object KeyLocation {
233+
final val Standard = KeyboardEvent.DOM_KEY_LOCATION_STANDARD
234+
final val Left = KeyboardEvent.DOM_KEY_LOCATION_LEFT
235+
final val Right = KeyboardEvent.DOM_KEY_LOCATION_RIGHT
236+
final val NumPad = KeyboardEvent.DOM_KEY_LOCATION_NUMPAD
237+
}
238+
231239
/**
232240
* Thrown when `Ajax.get` or `Ajax.post` receives a non-20X response code.
233241
* Contains the XMLHttpRequest that resulted in that response

src/main/scala/org/scalajs/dom/raw/lib.scala

+44-6
Original file line numberDiff line numberDiff line change
@@ -2699,7 +2699,7 @@ class KeyboardEvent(typeArg: String, keyboardEventInit: KeyboardEventInit)
26992699

27002700
/**
27012701
* The location of the key on the keyboard or other input device.
2702-
* See the constants in the KeyboardEvent object.
2702+
* See the constants in the [[KeyboardEvent]] object.
27032703
*
27042704
* MDN
27052705
*/
@@ -2771,17 +2771,55 @@ trait KeyboardEventInit extends js.Object {
27712771
@js.native
27722772
@JSGlobal
27732773
object KeyboardEvent extends js.Object {
2774-
def DOM_KEY_LOCATION_RIGHT: Int = js.native
27752774

2775+
/**
2776+
* The key has only one version, or can't be distinguished between the left
2777+
* and right versions of the key, and was not pressed on the numeric keypad
2778+
* or a key that is considered to be part of the keypad.
2779+
*
2780+
* MDN
2781+
*/
27762782
def DOM_KEY_LOCATION_STANDARD: Int = js.native
27772783

2784+
/**
2785+
* The key was the left-hand version of the key; for example, the left-hand
2786+
* Control key was pressed on a standard 101 key US keyboard. This value is
2787+
* only used for keys that have more that one possible location on the
2788+
* keyboard.
2789+
*
2790+
* MDN
2791+
*/
27782792
def DOM_KEY_LOCATION_LEFT: Int = js.native
27792793

2780-
def DOM_KEY_LOCATION_NUMPAD: Int = js.native
2781-
2782-
def DOM_KEY_LOCATION_JOYSTICK: Int = js.native
2794+
/**
2795+
* The key was the right-hand version of the key; for example, the right-hand
2796+
* Control key is pressed on a standard 101 key US keyboard. This value is
2797+
* only used for keys that have more that one possible location on the
2798+
* keyboard.
2799+
*
2800+
* MDN
2801+
*/
2802+
def DOM_KEY_LOCATION_RIGHT: Int = js.native
27832803

2784-
def DOM_KEY_LOCATION_MOBILE: Int = js.native
2804+
/**
2805+
* The key was on the numeric keypad, or has a virtual key code that
2806+
* corresponds to the numeric keypad.
2807+
*
2808+
* @note When NumLock is locked, Gecko always returns
2809+
* [[DOM_KEY_LOCATION_NUMPAD]] for the keys on the numeric pad.
2810+
* Otherwise, when NumLock is unlocked and the keyboard actually has
2811+
* a numeric keypad, Gecko always returns [[DOM_KEY_LOCATION_NUMPAD]]
2812+
* too. On the other hand, if the keyboard doesn't have a keypad, such
2813+
* as on a notebook computer, some keys become Numpad only when NumLock
2814+
* is locked. When such keys fires key events, the location attribute
2815+
* value depends on the key. That is, it must not be
2816+
* [[DOM_KEY_LOCATION_NUMPAD]].
2817+
* @note NumLock key's key events indicate [[DOM_KEY_LOCATION_STANDARD]] both
2818+
* on Gecko and Internet Explorer.
2819+
*
2820+
* MDN
2821+
*/
2822+
def DOM_KEY_LOCATION_NUMPAD: Int = js.native
27852823
}
27862824

27872825
/**

0 commit comments

Comments
 (0)