Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(166)

Side by Side Diff: sdk/lib/html/dartium/html_dartium.dart

Issue 11416249: Make KeyboardEvent cross-browser consistent. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: addressing second round of comments Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 library html; 1 library html;
2 2
3 import 'dart:isolate'; 3 import 'dart:isolate';
4 import 'dart:json'; 4 import 'dart:json';
5 import 'dart:nativewrappers'; 5 import 'dart:nativewrappers';
6 import 'dart:svg' as svg; 6 import 'dart:svg' as svg;
7 import 'dart:web_audio' as web_audio; 7 import 'dart:web_audio' as web_audio;
8 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 8 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
9 // for details. All rights reserved. Use of this source code is governed by a 9 // for details. All rights reserved. Use of this source code is governed by a
10 // BSD-style license that can be found in the LICENSE file. 10 // BSD-style license that can be found in the LICENSE file.
(...skipping 13839 matching lines...) Expand 10 before | Expand all | Expand 10 after
13850 13850
13851 13851
13852 /** @domName JavaScriptCallFrame.scopeType */ 13852 /** @domName JavaScriptCallFrame.scopeType */
13853 int scopeType(int scopeIndex) native "JavaScriptCallFrame_scopeType_Callback"; 13853 int scopeType(int scopeIndex) native "JavaScriptCallFrame_scopeType_Callback";
13854 13854
13855 } 13855 }
13856 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 13856 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
13857 // for details. All rights reserved. Use of this source code is governed by a 13857 // for details. All rights reserved. Use of this source code is governed by a
13858 // BSD-style license that can be found in the LICENSE file. 13858 // BSD-style license that can be found in the LICENSE file.
13859 13859
13860 // WARNING: Do not edit - generated code.
13861 13860
13861 /// @domName KeyboardEvent; @docsEditable true
13862 class KeyboardEvent extends UIEvent {
13862 13863
13863 /// @domName KeyboardEvent 13864 factory KeyboardEvent(String type, Window view,
13864 class KeyboardEvent extends UIEvent { 13865 [bool canBubble = true, bool cancelable = true,
13866 String keyIdentifier = null, int keyLocation = 1, bool ctrlKey = false,
13867 bool altKey = false, bool shiftKey = false, bool metaKey = false,
13868 bool altGraphKey = false]) {
13869 final e = document.$dom_createEvent("KeyboardEvent");
13870 e.$dom_initKeyboardEvent(type, canBubble, cancelable, view, keyIdentifier,
13871 keyLocation, ctrlKey, altKey, shiftKey, metaKey, altGraphKey);
13872 return e;
13873 }
13874
13875 /** @domName KeyboardEvent.initKeyboardEvent */
13876 void $dom_initKeyboardEvent(String type, bool canBubble, bool cancelable,
13877 LocalWindow view, String keyIdentifier, int keyLocation, bool ctrlKey,
13878 bool altKey, bool shiftKey, bool metaKey,
13879 bool altGraphKey) native "KeyboardEvent_initKeyboardEvent_Callback";
13880
13881 /** @domName KeyboardEvent.keyCode */
13882 int get keyCode => $dom_keyCode;
13883
13884 /** @domName KeyboardEvent.charCode */
13885 int get charCode => $dom_charCode;
13865 KeyboardEvent.internal(): super.internal(); 13886 KeyboardEvent.internal(): super.internal();
13866 13887
13867 13888
13868 /** @domName KeyboardEvent.altGraphKey */ 13889 /** @domName KeyboardEvent.altGraphKey */
13869 bool get altGraphKey native "KeyboardEvent_altGraphKey_Getter"; 13890 bool get altGraphKey native "KeyboardEvent_altGraphKey_Getter";
13870 13891
13871 13892
13872 /** @domName KeyboardEvent.altKey */ 13893 /** @domName KeyboardEvent.altKey */
13873 bool get altKey native "KeyboardEvent_altKey_Getter"; 13894 bool get altKey native "KeyboardEvent_altKey_Getter";
13874 13895
13875 13896
13876 /** @domName KeyboardEvent.ctrlKey */ 13897 /** @domName KeyboardEvent.ctrlKey */
13877 bool get ctrlKey native "KeyboardEvent_ctrlKey_Getter"; 13898 bool get ctrlKey native "KeyboardEvent_ctrlKey_Getter";
13878 13899
13879 13900
13880 /** @domName KeyboardEvent.keyIdentifier */ 13901 /** @domName KeyboardEvent.keyIdentifier */
13881 String get keyIdentifier native "KeyboardEvent_keyIdentifier_Getter"; 13902 String get $dom_keyIdentifier native "KeyboardEvent_keyIdentifier_Getter";
13882 13903
13883 13904
13884 /** @domName KeyboardEvent.keyLocation */ 13905 /** @domName KeyboardEvent.keyLocation */
13885 int get keyLocation native "KeyboardEvent_keyLocation_Getter"; 13906 int get keyLocation native "KeyboardEvent_keyLocation_Getter";
13886 13907
13887 13908
13888 /** @domName KeyboardEvent.metaKey */ 13909 /** @domName KeyboardEvent.metaKey */
13889 bool get metaKey native "KeyboardEvent_metaKey_Getter"; 13910 bool get metaKey native "KeyboardEvent_metaKey_Getter";
13890 13911
13891 13912
13892 /** @domName KeyboardEvent.shiftKey */ 13913 /** @domName KeyboardEvent.shiftKey */
13893 bool get shiftKey native "KeyboardEvent_shiftKey_Getter"; 13914 bool get shiftKey native "KeyboardEvent_shiftKey_Getter";
13894 13915
13895
13896 /** @domName KeyboardEvent.initKeyboardEvent */
13897 void initKeyboardEvent(String type, bool canBubble, bool cancelable, LocalWind ow view, String keyIdentifier, int keyLocation, bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, bool altGraphKey) native "KeyboardEvent_initKeyboardEven t_Callback";
13898
13899 } 13916 }
13900 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 13917 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
13901 // for details. All rights reserved. Use of this source code is governed by a 13918 // for details. All rights reserved. Use of this source code is governed by a
13902 // BSD-style license that can be found in the LICENSE file. 13919 // BSD-style license that can be found in the LICENSE file.
13903 13920
13904 // WARNING: Do not edit - generated code. 13921 // WARNING: Do not edit - generated code.
13905 13922
13906 13923
13907 /// @domName HTMLKeygenElement 13924 /// @domName HTMLKeygenElement
13908 class KeygenElement extends _Element_Merged { 13925 class KeygenElement extends _Element_Merged {
(...skipping 8450 matching lines...) Expand 10 before | Expand all | Expand 10 after
22359 Node previousSibling() native "TreeWalker_previousSibling_Callback"; 22376 Node previousSibling() native "TreeWalker_previousSibling_Callback";
22360 22377
22361 } 22378 }
22362 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 22379 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
22363 // for details. All rights reserved. Use of this source code is governed by a 22380 // for details. All rights reserved. Use of this source code is governed by a
22364 // BSD-style license that can be found in the LICENSE file. 22381 // BSD-style license that can be found in the LICENSE file.
22365 22382
22366 // WARNING: Do not edit - generated code. 22383 // WARNING: Do not edit - generated code.
22367 22384
22368 22385
22369 /// @domName UIEvent 22386 /// @domName UIEvent; @docsEditable true
22370 class UIEvent extends Event { 22387 class UIEvent extends Event {
22388 // In JS, canBubble and cancelable are technically required parameters to
22389 // init*Event. In practice, though, if they aren't provided they simply
22390 // default to false (since that's Boolean(undefined)).
22391 //
22392 // Contrary to JS, we default canBubble and cancelable to true, since that's
22393 // what people want most of the time anyway.
22394 factory UIEvent(String type, Window view, int detail,
22395 [bool canBubble = true, bool cancelable = true]) {
22396 final e = document.$dom_createEvent("UIEvent");
22397 e.$dom_initUIEvent(type, canBubble, cancelable, view, detail);
22398 return e;
22399 }
22371 UIEvent.internal(): super.internal(); 22400 UIEvent.internal(): super.internal();
22372 22401
22373 22402
22374 /** @domName UIEvent.charCode */ 22403 /** @domName UIEvent.charCode */
22375 int get charCode native "UIEvent_charCode_Getter"; 22404 int get $dom_charCode native "UIEvent_charCode_Getter";
22376 22405
22377 22406
22378 /** @domName UIEvent.detail */ 22407 /** @domName UIEvent.detail */
22379 int get detail native "UIEvent_detail_Getter"; 22408 int get detail native "UIEvent_detail_Getter";
22380 22409
22381 22410
22382 /** @domName UIEvent.keyCode */ 22411 /** @domName UIEvent.keyCode */
22383 int get keyCode native "UIEvent_keyCode_Getter"; 22412 int get $dom_keyCode native "UIEvent_keyCode_Getter";
22384 22413
22385 22414
22386 /** @domName UIEvent.layerX */ 22415 /** @domName UIEvent.layerX */
22387 int get layerX native "UIEvent_layerX_Getter"; 22416 int get layerX native "UIEvent_layerX_Getter";
22388 22417
22389 22418
22390 /** @domName UIEvent.layerY */ 22419 /** @domName UIEvent.layerY */
22391 int get layerY native "UIEvent_layerY_Getter"; 22420 int get layerY native "UIEvent_layerY_Getter";
22392 22421
22393 22422
22394 /** @domName UIEvent.pageX */ 22423 /** @domName UIEvent.pageX */
22395 int get pageX native "UIEvent_pageX_Getter"; 22424 int get pageX native "UIEvent_pageX_Getter";
22396 22425
22397 22426
22398 /** @domName UIEvent.pageY */ 22427 /** @domName UIEvent.pageY */
22399 int get pageY native "UIEvent_pageY_Getter"; 22428 int get pageY native "UIEvent_pageY_Getter";
22400 22429
22401 22430
22402 /** @domName UIEvent.view */ 22431 /** @domName UIEvent.view */
22403 Window get view native "UIEvent_view_Getter"; 22432 Window get view native "UIEvent_view_Getter";
22404 22433
22405 22434
22406 /** @domName UIEvent.which */ 22435 /** @domName UIEvent.which */
22407 int get which native "UIEvent_which_Getter"; 22436 int get which native "UIEvent_which_Getter";
22408 22437
22409 22438
22410 /** @domName UIEvent.initUIEvent */ 22439 /** @domName UIEvent.initUIEvent */
22411 void initUIEvent(String type, bool canBubble, bool cancelable, LocalWindow vie w, int detail) native "UIEvent_initUIEvent_Callback"; 22440 void $dom_initUIEvent(String type, bool canBubble, bool cancelable, LocalWindo w view, int detail) native "UIEvent_initUIEvent_Callback";
22412 22441
22413 } 22442 }
22414 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 22443 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
22415 // for details. All rights reserved. Use of this source code is governed by a 22444 // for details. All rights reserved. Use of this source code is governed by a
22416 // BSD-style license that can be found in the LICENSE file. 22445 // BSD-style license that can be found in the LICENSE file.
22417 22446
22418 // WARNING: Do not edit - generated code. 22447 // WARNING: Do not edit - generated code.
22419 22448
22420 22449
22421 /// @domName HTMLUListElement 22450 /// @domName HTMLUListElement
(...skipping 5395 matching lines...) Expand 10 before | Expand all | Expand 10 after
27817 Element get first => _filtered.first; 27846 Element get first => _filtered.first;
27818 27847
27819 Element get last => _filtered.last; 27848 Element get last => _filtered.last;
27820 } 27849 }
27821 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 27850 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
27822 // for details. All rights reserved. Use of this source code is governed by a 27851 // for details. All rights reserved. Use of this source code is governed by a
27823 // BSD-style license that can be found in the LICENSE file. 27852 // BSD-style license that can be found in the LICENSE file.
27824 27853
27825 27854
27826 /** 27855 /**
27856 * Works with KeyboardEvent and KeyEvent to determine how to expose information
27857 * about Key(board)Events. This class functions like an EventListenerList, and
27858 * provides a consistent interface for the Dart
27859 * user, despite the fact that a multitude of browsers that have varying
27860 * keyboard default behavior.
27861 *
27862 * This class is very much a work in progress, and we'd love to get information
27863 * on how we can make this class work with as many international keyboards as
27864 * possible. Bugs welcome!
27865 */
27866 class KeyboardEventController {
27867 // This code inspired by Closure's KeyHandling library.
27868 // http://closure-library.googlecode.com/svn/docs/closure_goog_events_keyhandl er.js.source.html
27869
27870 /**
27871 * The set of keys that have been pressed down without seeing their
27872 * corresponding keyup event.
27873 */
27874 List<KeyboardEvent> keyDownList;
27875
27876 /** The set of functions that wish to be notified when a KeyEvent happens. */
27877 List<Function> _callbacks;
27878
27879 /** The type of KeyEvent we are tracking (keyup, keydown, keypress). */
27880 String _type;
27881
27882 /** The element we are watching for events to happen on. */
27883 EventTarget _target;
27884
27885 // The distance to shift from upper case alphabet Roman letters to lower case.
27886 const int _ROMAN_ALPHABET_OFFSET = "a".charCodes[0] - "A".charCodes[0];
27887
27888 /**
27889 * An enumeration of key identifiers currently part of the W3C draft for DOM3
27890 * and their mappings to keyCodes.
27891 * http://www.w3.org/TR/DOM-Level-3-Events/keyset.html#KeySet-Set
27892 */
27893 static Map<String, int> _keyIdentifier = {
27894 'Up': KeyCode.UP,
27895 'Down': KeyCode.DOWN,
27896 'Left': KeyCode.LEFT,
27897 'Right': KeyCode.RIGHT,
27898 'Enter': KeyCode.ENTER,
27899 'F1': KeyCode.F1,
27900 'F2': KeyCode.F2,
27901 'F3': KeyCode.F3,
27902 'F4': KeyCode.F4,
27903 'F5': KeyCode.F5,
27904 'F6': KeyCode.F6,
27905 'F7': KeyCode.F7,
27906 'F8': KeyCode.F8,
27907 'F9': KeyCode.F9,
27908 'F10': KeyCode.F10,
27909 'F11': KeyCode.F11,
27910 'F12': KeyCode.F12,
27911 'U+007F': KeyCode.DELETE,
27912 'Home': KeyCode.HOME,
27913 'End': KeyCode.END,
27914 'PageUp': KeyCode.PAGE_UP,
27915 'PageDown': KeyCode.PAGE_DOWN,
27916 'Insert': KeyCode.INSERT
27917 };
27918
27919 /** Named constructor to add an onKeyPress event listener to our handler. */
27920 KeyboardEventController.keypress(EventTarget target) {
27921 _KeyboardEventController(target, 'keypress');
27922 }
27923
27924 /** Named constructor to add an onKeyUp event listener to our handler. */
27925 KeyboardEventController.keyup(EventTarget target) {
27926 _KeyboardEventController(target, 'keyup');
27927 }
27928
27929 /** Named constructor to add an onKeyDown event listener to our handler. */
27930 KeyboardEventController.keydown(EventTarget target) {
27931 _KeyboardEventController(target, 'keydown');
27932 }
27933
27934 /**
27935 * General constructor, performs basic initialization for our improved
27936 * KeyboardEvent controller.
27937 */
27938 _KeyboardEventController(EventTarget target, String type) {
27939 _callbacks = [];
27940 _type = type;
27941 _target = target;
27942 _initializeAllEventListeners();
27943 }
27944
27945 /**
27946 * Hook up all event listeners under the covers so we can estimate keycodes
27947 * and charcodes when they are not provided.
27948 */
27949 void _initializeAllEventListeners() {
27950 keyDownList = [];
27951 _target.on.keyDown.add(processKeyDown, true);
27952 _target.on.keyPress.add(processKeyPress, true);
27953 _target.on.keyUp.add(processKeyUp, true);
27954 }
27955
27956 /** Add a callback that wishes to be notified when a KeyEvent occurs. */
27957 void add(void callback(KeyEvent)) {
27958 if (_callbacks.length == 0) {
27959 _initializeAllEventListeners();
27960 }
27961 _callbacks.add(callback);
27962 }
27963
27964 /**
27965 * Notify all callback listeners that a KeyEvent of the relevant type has
27966 * occurred.
27967 */
27968 bool _dispatch(KeyEvent event) {
27969 if (event.type == _type) {
27970 // Make a copy of the listeners in case a callback gets removed while
27971 // dispatching from the list.
27972 List callbacksCopy = new List.from(_callbacks);
27973 for(var callback in callbacksCopy) {
27974 callback(event);
27975 }
27976 }
27977 }
27978
27979 /** Remove the given callback from the listeners list. */
27980 void remove(void callback(KeyEvent)) {
27981 var index = _callbacks.indexOf(callback);
27982 if (index != -1) {
27983 _callbacks.removeAd(index);
27984 }
27985 if (_callbacks.length == 0) {
27986 // If we have no listeners, don't bother keeping track of keypresses.
27987 target.on.keyDown.remove(processKeyDown);
27988 target.on.keyPress.remove(processKeyPress);
27989 target.on.keyUp.remove(processKeyUp);
27990 }
27991 }
27992
27993 /** Determine if caps lock is one of the currently depressed keys. */
27994 bool get _capsLockOn() =>
27995 keyDownList.some((var element) => element.keyCode == KeyCode.CAPS_LOCK);
27996
27997 /**
27998 * Given the previously recorded keydown key codes, see if we can determine
27999 * the keycode of this keypress [event]. (Generally browsers only provide
28000 * charCode information for keypress events, but with a little
28001 * reverse-engineering, we can also determine the keyCode.) Returns
28002 * KeyCode.UNKNOWN if the keycode could not be determined.
28003 */
28004 int _determineKeyCodeForKeypress(KeyboardEvent event) {
28005 // Note: This function is a work in progress. We'll expand this function
28006 // once we get more information about other keyboards.
28007 for (var prevEvent in keyDownList) {
28008 if (prevEvent._shadowCharCode == event.charCode) {
28009 return prevEvent.keyCode;
28010 }
28011 if ((event.shiftKey || _capsLockOn) && event.charCode >= "A".charCodes[0]
28012 && event.charCode <= "Z".charCodes[0] && event.charCode +
28013 _ROMAN_ALPHABET_OFFSET == prevEvent._shadowCharCode) {
28014 return prevEvent.keyCode;
28015 }
28016 }
28017 return KeyCode.UNKNOWN;
28018 }
28019
28020 /**
28021 * Given the charater code returned from a keyDown [event], try to ascertain
28022 * and return the corresponding charCode for the character that was pressed.
28023 * This information is not shown to the user, but used to help polyfill
28024 * keypress events.
28025 */
28026 int _findCharCodeKeyDown(KeyboardEvent event) {
28027 if (event.keyLocation == 3) { // Numpad keys.
28028 switch (event.keyCode) {
28029 case KeyCode.NUM_ZERO:
28030 // Even though this function returns _charCodes_, for some cases the
28031 // KeyCode == the charCode we want, in which case we use the keycode
28032 // constant for readability.
28033 return KeyCode.ZERO;
28034 case KeyCode.NUM_ONE:
28035 return KeyCode.ONE;
28036 case KeyCode.NUM_TWO:
28037 return KeyCode.TWO;
28038 case KeyCode.NUM_THREE:
28039 return KeyCode.THREE;
28040 case KeyCode.NUM_FOUR:
28041 return KeyCode.FOUR;
28042 case KeyCode.NUM_FIVE:
28043 return KeyCode.FIVE;
28044 case KeyCode.NUM_SIX:
28045 return KeyCode.SIX;
28046 case KeyCode.NUM_SEVEN:
28047 return KeyCode.SEVEN;
28048 case KeyCode.NUM_EIGHT:
28049 return KeyCode.EIGHT;
28050 case KeyCode.NUM_NINE:
28051 return KeyCode.NINE;
28052 case KeyCode.NUM_MULTIPLY:
28053 return 42; // Char code for *
28054 case KeyCode.NUM_PLUS:
28055 return 43; // +
28056 case KeyCode.NUM_MINUS:
28057 return 45; // -
28058 case KeyCode.NUM_PERIOD:
28059 return 46; // .
28060 case KeyCode.NUM_DIVISION:
28061 return 47; // /
28062 }
28063 } else if (event.keyCode >= 65 && event.keyCode <= 90) {
28064 // Set the "char code" for key down as the lower case letter. Again, this
28065 // will not show up for the user, but will be helpful in estimating
28066 // keyCode locations and other information during the keyPress event.
28067 return event.keyCode + _ROMAN_ALPHABET_OFFSET;
28068 }
28069 switch(event.keyCode) {
28070 case KeyCode.SEMICOLON:
28071 return KeyCode.FF_SEMICOLON;
28072 case KeyCode.EQUALS:
28073 return KeyCode.FF_EQUALS;
28074 case KeyCode.COMMA:
28075 return 44; // Ascii value for ,
28076 case KeyCode.DASH:
28077 return 45; // -
28078 case KeyCode.PERIOD:
28079 return 46; // .
28080 case KeyCode.SLASH:
28081 return 47; // /
28082 case KeyCode.APOSTROPHE:
28083 return 96; // `
28084 case KeyCode.OPEN_SQUARE_BRACKET:
28085 return 91; // [
28086 case KeyCode.BACKSLASH:
28087 return 92; // \
28088 case KeyCode.CLOSE_SQUARE_BRACKET:
28089 return 93; // ]
28090 case KeyCode.SINGLE_QUOTE:
28091 return 39; // '
28092 }
28093 return event.keyCode;
28094 }
28095
28096 /**
28097 * Returns true if the key fires a keypress event in the current browser.
28098 */
28099 bool _firesKeyPressEvent(KeyEvent event) {
28100 if (!_Device.isIE && !_Device.isWebKit) {
28101 return true;
28102 }
28103
28104 if (_Device.userAgent.contains('Mac') && event.altKey) {
28105 return KeyCode.isCharacterKey(event.keyCode);
28106 }
28107
28108 // Alt but not AltGr which is represented as Alt+Ctrl.
28109 if (event.altKey && !event.ctrlKey) {
28110 return false;
28111 }
28112
28113 // Saves Ctrl or Alt + key for IE and WebKit, which won't fire keypress.
28114 if (!event.shiftKey &&
28115 (keyDownList.last.keyCode == KeyCode.CTRL ||
28116 keyDownList.last.keyCode == KeyCode.ALT ||
28117 _Device.userAgent.contains('Mac') &&
28118 keyDownList.last.keyCode == KeyCode.META)) {
28119 return false;
28120 }
28121
28122 // Some keys with Ctrl/Shift do not issue keypress in WebKit.
28123 if (_Device.isWebKit && event.ctrlKey && event.shiftKey && (
28124 event.keycode == KeyCode.BACKSLASH ||
28125 event.keycode == KeyCode.OPEN_SQUARE_BRACKET ||
28126 event.keycode == KeyCode.CLOSE_SQUARE_BRACKET ||
28127 event.keycode == KeyCode.TILDE ||
28128 event.keycode == KeyCode.SEMICOLON || event.keycode == KeyCode.DASH ||
28129 event.keycode == KeyCode.EQUALS || event.keycode == KeyCode.COMMA ||
28130 event.keycode == KeyCode.PERIOD || event.keycode == KeyCode.SLASH ||
28131 event.keycode == KeyCode.APOSTROPHE ||
28132 event.keycode == KeyCode.SINGLE_QUOTE)) {
28133 return false;
28134 }
28135
28136 switch (event.keyCode) {
28137 case KeyCode.ENTER:
28138 // IE9 does not fire keypress on ENTER.
28139 return !_Device.isIE;
28140 case KeyCode.ESC:
28141 return !_Device.isWebKit;
28142 }
28143
28144 return KeyCode.isCharacterKey(event.keyCode);
28145 }
28146
28147 /**
28148 * Normalize the keycodes to the IE KeyCodes (this is what Chrome, IE, and
28149 * Opera all use).
28150 */
28151 int _normalizeKeyCodes(KeyboardEvent event) {
28152 // Note: This may change once we get input about non-US keyboards.
28153 if (_Device.isFirefox) {
28154 switch(event.keyCode) {
28155 case KeyCode.FF_EQUALS:
28156 return KeyCode.EQUALS;
28157 case KeyCode.FF_SEMICOLON:
28158 return KeyCode.SEMICOLON;
28159 case KeyCode.MAC_FF_META:
28160 return KeyCode.META;
28161 case KeyCode.WIN_KEY_FF_LINUX:
28162 return KeyCode.WIN_KEY;
28163 }
28164 }
28165 return event.keyCode;
28166 }
28167
28168 /** Handle keydown events. */
28169 void processKeyDown(KeyboardEvent e) {
28170 // Ctrl-Tab and Alt-Tab can cause the focus to be moved to another window
28171 // before we've caught a key-up event. If the last-key was one of these
28172 // we reset the state.
28173 if (keyDownList.length > 0 &&
28174 (keyDownList.last.keyCode == KeyCode.CTRL && !e.ctrlKey ||
28175 keyDownList.last.keyCode == KeyCode.ALT && !e.altKey ||
28176 _Device.userAgent.contains('Mac') &&
28177 keyDownList.last.keyCode == KeyCode.META && !e.metaKey)) {
28178 keyDownList = [];
28179 }
28180
28181 var event = new KeyEvent(e);
28182 event._shadowKeyCode = _normalizeKeyCodes(event);
28183 // Technically a "keydown" event doesn't have a charCode. This is
28184 // calculated nonetheless to provide us with more information in giving
28185 // as much information as possible on keypress about keycode and also
28186 // charCode.
28187 event._shadowCharCode = _findCharCodeKeyDown(event);
28188 if (keyDownList.length > 0 && event.keyCode != keyDownList.last.keyCode &&
28189 !_firesKeyPressEvent(event)) {
28190 // Some browsers have quirks not firing keypress events where all other
28191 // browsers do. This makes them more consistent.
28192 processKeyPress(event);
28193 }
28194 keyDownList.add(event);
28195 _dispatch(event);
28196 }
28197
28198 /** Handle keypress events. */
28199 void processKeyPress(KeyboardEvent event) {
28200 var e = new KeyEvent(event);
28201 // IE reports the character code in the keyCode field for keypress events.
28202 // There are two exceptions however, Enter and Escape.
28203 if (_Device.isIE) {
28204 if (e.keyCode == KeyCode.ENTER || e.keyCode == KeyCode.ESC) {
28205 e._shadowCharCode = 0;
28206 } else {
28207 e._shadowCharCode = e.keyCode;
28208 }
28209 } else if (_Device.isOpera) {
28210 // Opera reports the character code in the keyCode field.
28211 e._shadowCharCode = KeyCode.isCharacterKey(keyCode) ? e.keyCode : 0;
28212 }
28213 // Now we guestimate about what the keycode is that was actually
28214 // pressed, given previous keydown information.
28215 e._shadowKeyCode = _determineKeyCodeForKeypress(e);
28216
28217 // Correct the key value for certain browser-specific quirks.
28218 if (e._shadowKeyIdentifier &&
28219 _keyIdentifier.contains(e._shadowKeyIdentifier)) {
28220 // This is needed for Safari Windows because it currently doesn't give a
28221 // keyCode/which for non printable keys.
28222 e._shadowKeyCode = _keyIdentifier[keyIdentifier];
28223 }
28224 e._shadowAltKey = keyDownList.some((var element) => element.altKey);
28225 _dispatch(e);
28226 }
28227
28228 /** Handle keyup events. */
28229 void processKeyUp(KeyboardEvent event) {
28230 var e = new KeyEvent(event);
28231 KeyboardEvent toRemove = null;
28232 for (var key in keyDownList) {
28233 if (key.keyCode == e.keyCode) {
28234 toRemove = key;
28235 }
28236 }
28237 if (toRemove != null) {
28238 keyDownList = keyDownList.filter((element) => element != toRemove);
28239 } else if (keyDownList.length > 0) {
28240 // This happens when we've reached some international keyboard case we
28241 // haven't accounted for or we haven't correctly eliminated all browser
28242 // inconsistencies. Filing bugs on when this is reached is welcome!
28243 keyDownList.removeLast();
28244 }
28245 _dispatch(e);
28246 }
28247 }
28248 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
28249 // for details. All rights reserved. Use of this source code is governed by a
28250 // BSD-style license that can be found in the LICENSE file.
28251
28252
28253 /**
27827 * Defines the keycode values for keys that are returned by 28254 * Defines the keycode values for keys that are returned by
27828 * KeyboardEvent.keyCode. 28255 * KeyboardEvent.keyCode.
27829 * 28256 *
27830 * Important note: There is substantial divergence in how different browsers 28257 * Important note: There is substantial divergence in how different browsers
27831 * handle keycodes and their variants in different locales/keyboard layouts. We 28258 * handle keycodes and their variants in different locales/keyboard layouts. We
27832 * provide these constants to help make code processing keys more readable. 28259 * provide these constants to help make code processing keys more readable.
27833 */ 28260 */
27834 abstract class KeyCode { 28261 abstract class KeyCode {
27835 // These constant names were borrowed from Closure's Keycode enumeration 28262 // These constant names were borrowed from Closure's Keycode enumeration
27836 // class. 28263 // class.
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
28007 */ 28434 */
28008 static const int BACKSLASH = 220; 28435 static const int BACKSLASH = 220;
28009 /** 28436 /**
28010 * CAUTION: This constant requires localization for other locales and keyboard 28437 * CAUTION: This constant requires localization for other locales and keyboard
28011 * layouts. 28438 * layouts.
28012 */ 28439 */
28013 static const int CLOSE_SQUARE_BRACKET = 221; 28440 static const int CLOSE_SQUARE_BRACKET = 221;
28014 static const int WIN_KEY = 224; 28441 static const int WIN_KEY = 224;
28015 static const int MAC_FF_META = 224; 28442 static const int MAC_FF_META = 224;
28016 static const int WIN_IME = 229; 28443 static const int WIN_IME = 229;
28444
28445 /** A sentinel value if the keycode could not be determined. */
28446 static const int UNKNOWN = -1;
28447
28448 /**
28449 * Returns true if the keyCode produces a (US keyboard) character.
28450 * Note: This does not (yet) cover characters on non-US keyboards (Russian,
28451 * Hebrew, etc.).
28452 */
28453 static bool isCharacterKey(int keyCode) {
28454 if ((keyCode >= ZERO && keyCode <= NINE) ||
28455 (keyCode >= NUM_ZERO && keyCode <= NUM_MULTIPLY) ||
28456 (keyCode >= A && keyCode <= Z)) {
28457 return true;
28458 }
28459
28460 // Safari sends zero key code for non-latin characters.
28461 if (_Device.isWebKit && keyCode == 0) {
28462 return true;
28463 }
28464
28465 return (keyCode == SPACE || keyCode == QUESTION_MARK || keyCode == NUM_PLUS
28466 || keyCode == NUM_MINUS || keyCode == NUM_PERIOD ||
28467 keyCode == NUM_DIVISION || keyCode == SEMICOLON ||
28468 keyCode == FF_SEMICOLON || keyCode == DASH || keyCode == EQUALS ||
28469 keyCode == FF_EQUALS || keyCode == COMMA || keyCode == PERIOD ||
28470 keyCode == SLASH || keyCode == APOSTROPHE || keyCode == SINGLE_QUOTE ||
28471 keyCode == OPEN_SQUARE_BRACKET || keyCode == BACKSLASH ||
28472 keyCode == CLOSE_SQUARE_BRACKET);
28473 }
28017 } 28474 }
28018 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 28475 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
28019 // for details. All rights reserved. Use of this source code is governed by a 28476 // for details. All rights reserved. Use of this source code is governed by a
28020 // BSD-style license that can be found in the LICENSE file. 28477 // BSD-style license that can be found in the LICENSE file.
28021 28478
28022 28479
28023 /** 28480 /**
28024 * Defines the standard key locations returned by 28481 * Defines the standard key locations returned by
28025 * KeyboardEvent.getKeyLocation. 28482 * KeyboardEvent.getKeyLocation.
28026 */ 28483 */
(...skipping 747 matching lines...) Expand 10 before | Expand all | Expand 10 after
28774 final fragment = new DocumentFragment(); 29231 final fragment = new DocumentFragment();
28775 final e = new svg.SVGSVGElement(); 29232 final e = new svg.SVGSVGElement();
28776 e.innerHtml = svgContent; 29233 e.innerHtml = svgContent;
28777 29234
28778 // Copy list first since we don't want liveness during iteration. 29235 // Copy list first since we don't want liveness during iteration.
28779 final List nodes = new List.from(e.nodes); 29236 final List nodes = new List.from(e.nodes);
28780 fragment.nodes.addAll(nodes); 29237 fragment.nodes.addAll(nodes);
28781 return fragment; 29238 return fragment;
28782 } 29239 }
28783 } 29240 }
29241 /**
29242 * A custom KeyboardEvent that attempts to eliminate cross-browser
29243 * inconsistencies, and also provide both keyCode and charCode information
29244 * for all key events (when such information can be determined).
29245 *
29246 * This class is very much a work in progress, and we'd love to get information
29247 * on how we can make this class work with as many international keyboards as
29248 * possible. Bugs welcome!
29249 */
29250 class KeyEvent implements KeyboardEvent {
29251 /** The parent KeyboardEvent that this KeyEvent is wrapping and "fixing". */
29252 KeyboardEvent _parent;
29253
29254 /** The "fixed" value of whether the alt key is being pressed. */
29255 bool _shadowAltKey;
29256
29257 /** Caculated value of what the estimated charCode is for this event. */
29258 int _shadowCharCode;
29259
29260 /** Caculated value of what the estimated keyCode is for this event. */
29261 int _shadowKeyCode;
29262
29263 /** Caculated value of what the estimated keyCode is for this event. */
29264 int get keyCode => _shadowKeyCode;
29265
29266 /** Caculated value of what the estimated charCode is for this event. */
29267 int get charCode => this.type == 'keypress' ? _shadowCharCode : 0;
29268
29269 /** Caculated value of whether the alt key is pressed is for this event. */
29270 bool get altKey => _shadowAltKey;
29271
29272 /** Caculated value of what the estimated keyCode is for this event. */
29273 int get which => keyCode;
29274
29275 /** Accessor to the underlying keyCode value is the parent event. */
29276 int get _realKeyCode => _parent.keyCode;
29277
29278 /** Accessor to the underlying charCode value is the parent event. */
29279 int get _realCharCode => _parent.charCode;
29280
29281 /** Accessor to the underlying altKey value is the parent event. */
29282 bool get _realAltKey => _parent.altKey;
29283
29284 /** Construct a KeyEvent with [parent] as event we're emulating. */
29285 KeyEvent(KeyboardEvent parent) {
29286 _parent = parent;
29287 _shadowAltKey = _realAltKey;
29288 _shadowCharCode = _realCharCode;
29289 _shadowKeyCode = _realKeyCode;
29290 }
29291
29292 /** True if the altGraphKey is pressed during this event. */
29293 bool get altGraphKey => _parent.altGraphKey;
29294 bool get bubbles => _parent.bubbles;
29295 /** True if this event can be cancelled. */
29296 bool get cancelable => _parent.cancelable;
29297 bool get cancelBubble => _parent.cancelBubble;
29298 set cancelBubble(bool cancel) => _parent = cancel;
29299 /** Accessor to the clipboardData available for this event. */
29300 Clipboard get clipboardData => _parent.clipboardData;
29301 /** True if the ctrl key is pressed during this event. */
29302 bool get ctrlKey => _parent.ctrlKey;
29303 /** Accessor to the target this event is listening to for changes. */
29304 EventTarget get currentTarget => _parent.currentTarget;
29305 bool get defaultPrevented => _parent.defaultPrevented;
29306 int get detail => _parent.detail;
29307 int get eventPhase => _parent.eventPhase;
29308 /**
29309 * Accessor to the part of the keyboard that the key was pressed from (one of
29310 * KeyLocation.STANDARD, KeyLocation.RIGHT, KeyLocation.LEFT,
29311 * KeyLocation.NUMPAD, KeyLocation.MOBILE, KeyLocation.JOYSTICK).
29312 */
29313 int get keyLocation => _parent.keyLocation;
29314 int get layerX => _parent.layerX;
29315 int get layerY => _parent.layerY;
29316 /** True if the Meta (or Mac command) key is pressed during this event. */
29317 bool get metaKey => _parent.metaKey;
29318 int get pageX => _parent.pageX;
29319 int get pageY => _parent.pageY;
29320 bool get returnValue => _parent.returnValue;
29321 set returnValue(bool value) => _parent = value;
29322 /** True if the shift key was pressed during this event. */
29323 bool get shiftKey => _parent.shiftKey;
29324 int get timeStamp => _parent.timeStamp;
29325 /**
29326 * The type of key event that occurred. One of "keydown", "keyup", or
29327 * "keypress".
29328 */
29329 String get type => _parent.type;
29330 Window get view => _parent.view;
29331 void preventDefault() => _parent.preventDefault();
29332 void stopImmediatePropagation() => _parent.stopImmediatePropagation();
29333 void stopPropagation() => _parent.stopPropagation();
29334 void $dom_initUIEvent(String type, bool canBubble, bool cancelable,
29335 LocalWindow view, int detail) {
29336 throw new UnsupportedError("Cannot initialize a UI Event from a KeyEvent.");
29337 }
29338 void $dom_initEvent(String eventTypeArg, bool canBubbleArg,
29339 bool cancelableArg) {
29340 throw new UnsupportedError("Cannot initialize an Event from a KeyEvent.");
29341 }
29342 String get _shadowKeyIdentifier => _parent.$dom_keyIdentifier;
29343 }
28784 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 29344 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
28785 // for details. All rights reserved. Use of this source code is governed by a 29345 // for details. All rights reserved. Use of this source code is governed by a
28786 // BSD-style license that can be found in the LICENSE file. 29346 // BSD-style license that can be found in the LICENSE file.
28787 29347
28788 29348
28789 class _IDBKeyRangeFactoryProvider { 29349 class _IDBKeyRangeFactoryProvider {
28790 29350
28791 static IDBKeyRange createIDBKeyRange_only(/*IDBKey*/ value) => 29351 static IDBKeyRange createIDBKeyRange_only(/*IDBKey*/ value) =>
28792 IDBKeyRange.only_(value); 29352 IDBKeyRange.only_(value);
28793 29353
(...skipping 1014 matching lines...) Expand 10 before | Expand all | Expand 10 after
29808 bool get isEmpty => Maps.isEmpty(this); 30368 bool get isEmpty => Maps.isEmpty(this);
29809 } 30369 }
29810 30370
29811 get _printClosure => (s) { 30371 get _printClosure => (s) {
29812 try { 30372 try {
29813 window.console.log(s); 30373 window.console.log(s);
29814 } catch (_) { 30374 } catch (_) {
29815 _Utils.print(s); 30375 _Utils.print(s);
29816 } 30376 }
29817 }; 30377 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698