Chromium Code Reviews| Index: sdk/lib/html/src/dart2js_KeyEvent.dart |
| diff --git a/sdk/lib/html/src/dart2js_KeyEvent.dart b/sdk/lib/html/src/dart2js_KeyEvent.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..cbedcaecc409766e586ef0c6a11ecd482b738ad4 |
| --- /dev/null |
| +++ b/sdk/lib/html/src/dart2js_KeyEvent.dart |
| @@ -0,0 +1,101 @@ |
| +/** |
| + * A custom KeyboardEvent that attempts to eliminate cross-browser |
| + * inconsistencies, and also provide both keyCode and charCode information |
| + * for all key events (when such information can be determined). |
| + * |
| + * This class is very much a work in progress, and we'd love to get information |
| + * on how we can make this class work with as many international keyboards as |
| + * possible. Bugs welcome! |
| + */ |
| +class KeyEvent implements KeyboardEvent { |
| + /** The parent KeyboardEvent that this KeyEvent is wrapping and "fixing". */ |
| + KeyboardEvent _parent; |
| + |
| + /** The "fixed" value of whether the alt key is being pressed. */ |
| + bool _shadowAltKey; |
| + |
| + /** Caculated value of what the estimated charCode is for this event. */ |
| + int _shadowCharCode; |
| + |
| + /** Caculated value of what the estimated keyCode is for this event. */ |
| + int _shadowKeyCode; |
| + |
| + /** Caculated value of what the estimated keyCode is for this event. */ |
| + int get keyCode => _shadowKeyCode; |
| + |
| + /** Caculated value of what the estimated charCode is for this event. */ |
| + int get charCode => this.type == 'keypress' ? _shadowCharCode : 0; |
| + |
| + /** Caculated value of whether the alt key is pressed is for this event. */ |
| + bool get altKey => _shadowAltKey; |
| + |
| + /** Caculated value of what the estimated keyCode is for this event. */ |
| + int get which => keyCode; |
| + |
| + /** Accessor to the underlying keyCode value is the parent event. */ |
| + int get _realKeyCode => JS('int', '#.keyCode', _parent); |
| + |
| + /** Accessor to the underlying charCode value is the parent event. */ |
| + int get _realCharCode => JS('int', '#.charCode', _parent); |
| + |
| + /** Accessor to the underlying altKey value is the parent event. */ |
| + bool get _realAltKey => JS('int', '#.altKey', _parent); |
| + |
| + /** Construct a KeyEvent with [parent] as event we're emulating. */ |
| + KeyEvent(KeyboardEvent parent) { |
| + _parent = parent; |
| + _shadowAltKey = _realAltKey; |
| + _shadowCharCode = _realCharCode; |
| + _shadowKeyCode = _realKeyCode; |
| + } |
| + |
| + /** True if the altGraphKey is pressed during this event. */ |
| + bool get altGraphKey => _parent.altGraphKey; |
| + bool get bubbles => _parent.bubbles; |
| + /** True if this event can be cancelled. */ |
| + bool get cancelable => _parent.cancelable; |
| + bool get cancelBubble => _parent.cancelBubble; |
|
blois
2012/11/29 17:06:34
I believe that this should have a setter as well.
Emily Fortuna
2012/11/29 19:19:50
oops, good catch!
|
| + /** Accessor to the clipboardData available for this event. */ |
| + Clipboard get clipboardData => _parent.clipboardData; |
| + /** True if the ctrl key is pressed during this event. */ |
| + bool get ctrlKey => _parent.ctrlKey; |
| + /** Accessor to the target this event is listening to for changes. */ |
| + EventTarget get currentTarget => _parent.currentTarget; |
| + bool get defaultPrevented => _parent.defaultPrevented; |
| + int get detail => _parent.detail; |
| + int get eventPhase => _parent.eventPhase; |
| + /** |
| + * Accessor to the part of the keyboard that the key was pressed from (one of |
| + * KeyLocation.STANDARD, KeyLocation.RIGHT, KeyLocation.LEFT, |
| + * KeyLocation.NUMPAD, KeyLocation.MOBILE, KeyLocation.JOYSTICK). |
| + */ |
| + int get keyLocation => _parent.keyLocation; |
| + int get layerX => _parent.layerX; |
| + int get layerY => _parent.layerY; |
| + /** True if the Meta (or Mac command) key is pressed during this event. */ |
| + bool get metaKey => _parent.metaKey; |
| + int get pageX => _parent.pageX; |
| + int get pageY => _parent.pageY; |
| + bool get returnValue => _parent.returnValue; |
|
blois
2012/11/29 17:06:34
Should have a setter too.
Emily Fortuna
2012/11/29 19:19:50
Done.
|
| + /** True if the shift key was pressed during this event. */ |
| + bool get shiftKey => _parent.shiftKey; |
| + int get timeStamp => _parent.timeStamp; |
| + /** |
| + * The type of key event that occurred. One of "keydown", "keyup", or |
| + * "keypress". |
| + */ |
| + String get type => _parent.type; |
| + Window get view => _parent.view; |
| + void preventDefault() => _parent.preventDefault(); |
| + void stopImmediatePropagation() => _parent.stopImmediatePropagation(); |
| + void stopPropagation() => _parent.stopPropagation(); |
| + void $dom_initUIEvent(String type, bool canBubble, bool cancelable, |
|
blois
2012/11/29 17:06:34
Probably just throw an exception from these $dom m
Emily Fortuna
2012/11/29 19:19:50
Done.
|
| + LocalWindow view, int detail) { |
| + _parent.$dom_initUIEvent(type, canBubble, cancelable, view, detail); |
| + } |
| + void $dom_initEvent(String eventTypeArg, bool canBubbleArg, |
| + bool cancelableArg) { |
| + _parent.$dom_initEvent(eventTypeArg, canBubbleArg, cancelableArg); |
| + } |
| + String get _shadowKeyIdentifier => JS('String', '#.keyIdentifier', _parent); |
| +} |