OLD | NEW |
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 Loading... |
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 Loading... |
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 Loading... |
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 // Instance members referring to the internal event handlers because closures |
| 27889 // are not hashable. |
| 27890 var _keyUp, _keyDown, _keyPress; |
| 27891 |
| 27892 /** |
| 27893 * An enumeration of key identifiers currently part of the W3C draft for DOM3 |
| 27894 * and their mappings to keyCodes. |
| 27895 * http://www.w3.org/TR/DOM-Level-3-Events/keyset.html#KeySet-Set |
| 27896 */ |
| 27897 static Map<String, int> _keyIdentifier = { |
| 27898 'Up': KeyCode.UP, |
| 27899 'Down': KeyCode.DOWN, |
| 27900 'Left': KeyCode.LEFT, |
| 27901 'Right': KeyCode.RIGHT, |
| 27902 'Enter': KeyCode.ENTER, |
| 27903 'F1': KeyCode.F1, |
| 27904 'F2': KeyCode.F2, |
| 27905 'F3': KeyCode.F3, |
| 27906 'F4': KeyCode.F4, |
| 27907 'F5': KeyCode.F5, |
| 27908 'F6': KeyCode.F6, |
| 27909 'F7': KeyCode.F7, |
| 27910 'F8': KeyCode.F8, |
| 27911 'F9': KeyCode.F9, |
| 27912 'F10': KeyCode.F10, |
| 27913 'F11': KeyCode.F11, |
| 27914 'F12': KeyCode.F12, |
| 27915 'U+007F': KeyCode.DELETE, |
| 27916 'Home': KeyCode.HOME, |
| 27917 'End': KeyCode.END, |
| 27918 'PageUp': KeyCode.PAGE_UP, |
| 27919 'PageDown': KeyCode.PAGE_DOWN, |
| 27920 'Insert': KeyCode.INSERT |
| 27921 }; |
| 27922 |
| 27923 /** Named constructor to add an onKeyPress event listener to our handler. */ |
| 27924 KeyboardEventController.keypress(EventTarget target) { |
| 27925 _KeyboardEventController(target, 'keypress'); |
| 27926 } |
| 27927 |
| 27928 /** Named constructor to add an onKeyUp event listener to our handler. */ |
| 27929 KeyboardEventController.keyup(EventTarget target) { |
| 27930 _KeyboardEventController(target, 'keyup'); |
| 27931 } |
| 27932 |
| 27933 /** Named constructor to add an onKeyDown event listener to our handler. */ |
| 27934 KeyboardEventController.keydown(EventTarget target) { |
| 27935 _KeyboardEventController(target, 'keydown'); |
| 27936 } |
| 27937 |
| 27938 /** |
| 27939 * General constructor, performs basic initialization for our improved |
| 27940 * KeyboardEvent controller. |
| 27941 */ |
| 27942 _KeyboardEventController(EventTarget target, String type) { |
| 27943 _callbacks = []; |
| 27944 _type = type; |
| 27945 _target = target; |
| 27946 _initializeAllEventListeners(); |
| 27947 } |
| 27948 |
| 27949 /** |
| 27950 * Hook up all event listeners under the covers so we can estimate keycodes |
| 27951 * and charcodes when they are not provided. |
| 27952 */ |
| 27953 void _initializeAllEventListeners() { |
| 27954 keyDownList = []; |
| 27955 _keyDown = processKeyDown; |
| 27956 _keyUp = processKeyUp; |
| 27957 _keyPress = processKeyPress; |
| 27958 _target.on.keyDown.add(_keyDown, true); |
| 27959 _target.on.keyPress.add(_keyPress, true); |
| 27960 _target.on.keyUp.add(_keyUp, true); |
| 27961 } |
| 27962 |
| 27963 /** Add a callback that wishes to be notified when a KeyEvent occurs. */ |
| 27964 void add(void callback(KeyEvent)) { |
| 27965 if (_callbacks.length == 0) { |
| 27966 _initializeAllEventListeners(); |
| 27967 } |
| 27968 _callbacks.add(callback); |
| 27969 } |
| 27970 |
| 27971 /** |
| 27972 * Notify all callback listeners that a KeyEvent of the relevant type has |
| 27973 * occurred. |
| 27974 */ |
| 27975 bool _dispatch(KeyEvent event) { |
| 27976 if (event.type == _type) { |
| 27977 // Make a copy of the listeners in case a callback gets removed while |
| 27978 // dispatching from the list. |
| 27979 List callbacksCopy = new List.from(_callbacks); |
| 27980 for(var callback in callbacksCopy) { |
| 27981 callback(event); |
| 27982 } |
| 27983 } |
| 27984 } |
| 27985 |
| 27986 /** Remove the given callback from the listeners list. */ |
| 27987 void remove(void callback(KeyEvent)) { |
| 27988 var index = _callbacks.indexOf(callback); |
| 27989 if (index != -1) { |
| 27990 _callbacks.removeAt(index); |
| 27991 } |
| 27992 if (_callbacks.length == 0) { |
| 27993 // If we have no listeners, don't bother keeping track of keypresses. |
| 27994 _target.on.keyDown.remove(_keyDown); |
| 27995 _target.on.keyPress.remove(_keyPress); |
| 27996 _target.on.keyUp.remove(_keyUp); |
| 27997 } |
| 27998 } |
| 27999 |
| 28000 /** Determine if caps lock is one of the currently depressed keys. */ |
| 28001 bool get _capsLockOn() => |
| 28002 keyDownList.some((var element) => element.keyCode == KeyCode.CAPS_LOCK); |
| 28003 |
| 28004 /** |
| 28005 * Given the previously recorded keydown key codes, see if we can determine |
| 28006 * the keycode of this keypress [event]. (Generally browsers only provide |
| 28007 * charCode information for keypress events, but with a little |
| 28008 * reverse-engineering, we can also determine the keyCode.) Returns |
| 28009 * KeyCode.UNKNOWN if the keycode could not be determined. |
| 28010 */ |
| 28011 int _determineKeyCodeForKeypress(KeyboardEvent event) { |
| 28012 // Note: This function is a work in progress. We'll expand this function |
| 28013 // once we get more information about other keyboards. |
| 28014 for (var prevEvent in keyDownList) { |
| 28015 if (prevEvent._shadowCharCode == event.charCode) { |
| 28016 return prevEvent.keyCode; |
| 28017 } |
| 28018 if ((event.shiftKey || _capsLockOn) && event.charCode >= "A".charCodes[0] |
| 28019 && event.charCode <= "Z".charCodes[0] && event.charCode + |
| 28020 _ROMAN_ALPHABET_OFFSET == prevEvent._shadowCharCode) { |
| 28021 return prevEvent.keyCode; |
| 28022 } |
| 28023 } |
| 28024 return KeyCode.UNKNOWN; |
| 28025 } |
| 28026 |
| 28027 /** |
| 28028 * Given the charater code returned from a keyDown [event], try to ascertain |
| 28029 * and return the corresponding charCode for the character that was pressed. |
| 28030 * This information is not shown to the user, but used to help polyfill |
| 28031 * keypress events. |
| 28032 */ |
| 28033 int _findCharCodeKeyDown(KeyboardEvent event) { |
| 28034 if (event.keyLocation == 3) { // Numpad keys. |
| 28035 switch (event.keyCode) { |
| 28036 case KeyCode.NUM_ZERO: |
| 28037 // Even though this function returns _charCodes_, for some cases the |
| 28038 // KeyCode == the charCode we want, in which case we use the keycode |
| 28039 // constant for readability. |
| 28040 return KeyCode.ZERO; |
| 28041 case KeyCode.NUM_ONE: |
| 28042 return KeyCode.ONE; |
| 28043 case KeyCode.NUM_TWO: |
| 28044 return KeyCode.TWO; |
| 28045 case KeyCode.NUM_THREE: |
| 28046 return KeyCode.THREE; |
| 28047 case KeyCode.NUM_FOUR: |
| 28048 return KeyCode.FOUR; |
| 28049 case KeyCode.NUM_FIVE: |
| 28050 return KeyCode.FIVE; |
| 28051 case KeyCode.NUM_SIX: |
| 28052 return KeyCode.SIX; |
| 28053 case KeyCode.NUM_SEVEN: |
| 28054 return KeyCode.SEVEN; |
| 28055 case KeyCode.NUM_EIGHT: |
| 28056 return KeyCode.EIGHT; |
| 28057 case KeyCode.NUM_NINE: |
| 28058 return KeyCode.NINE; |
| 28059 case KeyCode.NUM_MULTIPLY: |
| 28060 return 42; // Char code for * |
| 28061 case KeyCode.NUM_PLUS: |
| 28062 return 43; // + |
| 28063 case KeyCode.NUM_MINUS: |
| 28064 return 45; // - |
| 28065 case KeyCode.NUM_PERIOD: |
| 28066 return 46; // . |
| 28067 case KeyCode.NUM_DIVISION: |
| 28068 return 47; // / |
| 28069 } |
| 28070 } else if (event.keyCode >= 65 && event.keyCode <= 90) { |
| 28071 // Set the "char code" for key down as the lower case letter. Again, this |
| 28072 // will not show up for the user, but will be helpful in estimating |
| 28073 // keyCode locations and other information during the keyPress event. |
| 28074 return event.keyCode + _ROMAN_ALPHABET_OFFSET; |
| 28075 } |
| 28076 switch(event.keyCode) { |
| 28077 case KeyCode.SEMICOLON: |
| 28078 return KeyCode.FF_SEMICOLON; |
| 28079 case KeyCode.EQUALS: |
| 28080 return KeyCode.FF_EQUALS; |
| 28081 case KeyCode.COMMA: |
| 28082 return 44; // Ascii value for , |
| 28083 case KeyCode.DASH: |
| 28084 return 45; // - |
| 28085 case KeyCode.PERIOD: |
| 28086 return 46; // . |
| 28087 case KeyCode.SLASH: |
| 28088 return 47; // / |
| 28089 case KeyCode.APOSTROPHE: |
| 28090 return 96; // ` |
| 28091 case KeyCode.OPEN_SQUARE_BRACKET: |
| 28092 return 91; // [ |
| 28093 case KeyCode.BACKSLASH: |
| 28094 return 92; // \ |
| 28095 case KeyCode.CLOSE_SQUARE_BRACKET: |
| 28096 return 93; // ] |
| 28097 case KeyCode.SINGLE_QUOTE: |
| 28098 return 39; // ' |
| 28099 } |
| 28100 return event.keyCode; |
| 28101 } |
| 28102 |
| 28103 /** |
| 28104 * Returns true if the key fires a keypress event in the current browser. |
| 28105 */ |
| 28106 bool _firesKeyPressEvent(KeyEvent event) { |
| 28107 if (!_Device.isIE && !_Device.isWebKit) { |
| 28108 return true; |
| 28109 } |
| 28110 |
| 28111 if (_Device.userAgent.contains('Mac') && event.altKey) { |
| 28112 return KeyCode.isCharacterKey(event.keyCode); |
| 28113 } |
| 28114 |
| 28115 // Alt but not AltGr which is represented as Alt+Ctrl. |
| 28116 if (event.altKey && !event.ctrlKey) { |
| 28117 return false; |
| 28118 } |
| 28119 |
| 28120 // Saves Ctrl or Alt + key for IE and WebKit, which won't fire keypress. |
| 28121 if (!event.shiftKey && |
| 28122 (keyDownList.last.keyCode == KeyCode.CTRL || |
| 28123 keyDownList.last.keyCode == KeyCode.ALT || |
| 28124 _Device.userAgent.contains('Mac') && |
| 28125 keyDownList.last.keyCode == KeyCode.META)) { |
| 28126 return false; |
| 28127 } |
| 28128 |
| 28129 // Some keys with Ctrl/Shift do not issue keypress in WebKit. |
| 28130 if (_Device.isWebKit && event.ctrlKey && event.shiftKey && ( |
| 28131 event.keycode == KeyCode.BACKSLASH || |
| 28132 event.keycode == KeyCode.OPEN_SQUARE_BRACKET || |
| 28133 event.keycode == KeyCode.CLOSE_SQUARE_BRACKET || |
| 28134 event.keycode == KeyCode.TILDE || |
| 28135 event.keycode == KeyCode.SEMICOLON || event.keycode == KeyCode.DASH || |
| 28136 event.keycode == KeyCode.EQUALS || event.keycode == KeyCode.COMMA || |
| 28137 event.keycode == KeyCode.PERIOD || event.keycode == KeyCode.SLASH || |
| 28138 event.keycode == KeyCode.APOSTROPHE || |
| 28139 event.keycode == KeyCode.SINGLE_QUOTE)) { |
| 28140 return false; |
| 28141 } |
| 28142 |
| 28143 switch (event.keyCode) { |
| 28144 case KeyCode.ENTER: |
| 28145 // IE9 does not fire keypress on ENTER. |
| 28146 return !_Device.isIE; |
| 28147 case KeyCode.ESC: |
| 28148 return !_Device.isWebKit; |
| 28149 } |
| 28150 |
| 28151 return KeyCode.isCharacterKey(event.keyCode); |
| 28152 } |
| 28153 |
| 28154 /** |
| 28155 * Normalize the keycodes to the IE KeyCodes (this is what Chrome, IE, and |
| 28156 * Opera all use). |
| 28157 */ |
| 28158 int _normalizeKeyCodes(KeyboardEvent event) { |
| 28159 // Note: This may change once we get input about non-US keyboards. |
| 28160 if (_Device.isFirefox) { |
| 28161 switch(event.keyCode) { |
| 28162 case KeyCode.FF_EQUALS: |
| 28163 return KeyCode.EQUALS; |
| 28164 case KeyCode.FF_SEMICOLON: |
| 28165 return KeyCode.SEMICOLON; |
| 28166 case KeyCode.MAC_FF_META: |
| 28167 return KeyCode.META; |
| 28168 case KeyCode.WIN_KEY_FF_LINUX: |
| 28169 return KeyCode.WIN_KEY; |
| 28170 } |
| 28171 } |
| 28172 return event.keyCode; |
| 28173 } |
| 28174 |
| 28175 /** Handle keydown events. */ |
| 28176 void processKeyDown(KeyboardEvent e) { |
| 28177 // Ctrl-Tab and Alt-Tab can cause the focus to be moved to another window |
| 28178 // before we've caught a key-up event. If the last-key was one of these |
| 28179 // we reset the state. |
| 28180 if (keyDownList.length > 0 && |
| 28181 (keyDownList.last.keyCode == KeyCode.CTRL && !e.ctrlKey || |
| 28182 keyDownList.last.keyCode == KeyCode.ALT && !e.altKey || |
| 28183 _Device.userAgent.contains('Mac') && |
| 28184 keyDownList.last.keyCode == KeyCode.META && !e.metaKey)) { |
| 28185 keyDownList = []; |
| 28186 } |
| 28187 |
| 28188 var event = new KeyEvent(e); |
| 28189 event._shadowKeyCode = _normalizeKeyCodes(event); |
| 28190 // Technically a "keydown" event doesn't have a charCode. This is |
| 28191 // calculated nonetheless to provide us with more information in giving |
| 28192 // as much information as possible on keypress about keycode and also |
| 28193 // charCode. |
| 28194 event._shadowCharCode = _findCharCodeKeyDown(event); |
| 28195 if (keyDownList.length > 0 && event.keyCode != keyDownList.last.keyCode && |
| 28196 !_firesKeyPressEvent(event)) { |
| 28197 // Some browsers have quirks not firing keypress events where all other |
| 28198 // browsers do. This makes them more consistent. |
| 28199 processKeyPress(event); |
| 28200 } |
| 28201 keyDownList.add(event); |
| 28202 _dispatch(event); |
| 28203 } |
| 28204 |
| 28205 /** Handle keypress events. */ |
| 28206 void processKeyPress(KeyboardEvent event) { |
| 28207 var e = new KeyEvent(event); |
| 28208 // IE reports the character code in the keyCode field for keypress events. |
| 28209 // There are two exceptions however, Enter and Escape. |
| 28210 if (_Device.isIE) { |
| 28211 if (e.keyCode == KeyCode.ENTER || e.keyCode == KeyCode.ESC) { |
| 28212 e._shadowCharCode = 0; |
| 28213 } else { |
| 28214 e._shadowCharCode = e.keyCode; |
| 28215 } |
| 28216 } else if (_Device.isOpera) { |
| 28217 // Opera reports the character code in the keyCode field. |
| 28218 e._shadowCharCode = KeyCode.isCharacterKey(keyCode) ? e.keyCode : 0; |
| 28219 } |
| 28220 // Now we guestimate about what the keycode is that was actually |
| 28221 // pressed, given previous keydown information. |
| 28222 e._shadowKeyCode = _determineKeyCodeForKeypress(e); |
| 28223 |
| 28224 // Correct the key value for certain browser-specific quirks. |
| 28225 if (e._shadowKeyIdentifier && |
| 28226 _keyIdentifier.contains(e._shadowKeyIdentifier)) { |
| 28227 // This is needed for Safari Windows because it currently doesn't give a |
| 28228 // keyCode/which for non printable keys. |
| 28229 e._shadowKeyCode = _keyIdentifier[keyIdentifier]; |
| 28230 } |
| 28231 e._shadowAltKey = keyDownList.some((var element) => element.altKey); |
| 28232 _dispatch(e); |
| 28233 } |
| 28234 |
| 28235 /** Handle keyup events. */ |
| 28236 void processKeyUp(KeyboardEvent event) { |
| 28237 var e = new KeyEvent(event); |
| 28238 KeyboardEvent toRemove = null; |
| 28239 for (var key in keyDownList) { |
| 28240 if (key.keyCode == e.keyCode) { |
| 28241 toRemove = key; |
| 28242 } |
| 28243 } |
| 28244 if (toRemove != null) { |
| 28245 keyDownList = keyDownList.filter((element) => element != toRemove); |
| 28246 } else if (keyDownList.length > 0) { |
| 28247 // This happens when we've reached some international keyboard case we |
| 28248 // haven't accounted for or we haven't correctly eliminated all browser |
| 28249 // inconsistencies. Filing bugs on when this is reached is welcome! |
| 28250 keyDownList.removeLast(); |
| 28251 } |
| 28252 _dispatch(e); |
| 28253 } |
| 28254 } |
| 28255 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 28256 // for details. All rights reserved. Use of this source code is governed by a |
| 28257 // BSD-style license that can be found in the LICENSE file. |
| 28258 |
| 28259 |
| 28260 /** |
27827 * Defines the keycode values for keys that are returned by | 28261 * Defines the keycode values for keys that are returned by |
27828 * KeyboardEvent.keyCode. | 28262 * KeyboardEvent.keyCode. |
27829 * | 28263 * |
27830 * Important note: There is substantial divergence in how different browsers | 28264 * Important note: There is substantial divergence in how different browsers |
27831 * handle keycodes and their variants in different locales/keyboard layouts. We | 28265 * handle keycodes and their variants in different locales/keyboard layouts. We |
27832 * provide these constants to help make code processing keys more readable. | 28266 * provide these constants to help make code processing keys more readable. |
27833 */ | 28267 */ |
27834 abstract class KeyCode { | 28268 abstract class KeyCode { |
27835 // These constant names were borrowed from Closure's Keycode enumeration | 28269 // These constant names were borrowed from Closure's Keycode enumeration |
27836 // class. | 28270 // class. |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
28007 */ | 28441 */ |
28008 static const int BACKSLASH = 220; | 28442 static const int BACKSLASH = 220; |
28009 /** | 28443 /** |
28010 * CAUTION: This constant requires localization for other locales and keyboard | 28444 * CAUTION: This constant requires localization for other locales and keyboard |
28011 * layouts. | 28445 * layouts. |
28012 */ | 28446 */ |
28013 static const int CLOSE_SQUARE_BRACKET = 221; | 28447 static const int CLOSE_SQUARE_BRACKET = 221; |
28014 static const int WIN_KEY = 224; | 28448 static const int WIN_KEY = 224; |
28015 static const int MAC_FF_META = 224; | 28449 static const int MAC_FF_META = 224; |
28016 static const int WIN_IME = 229; | 28450 static const int WIN_IME = 229; |
| 28451 |
| 28452 /** A sentinel value if the keycode could not be determined. */ |
| 28453 static const int UNKNOWN = -1; |
| 28454 |
| 28455 /** |
| 28456 * Returns true if the keyCode produces a (US keyboard) character. |
| 28457 * Note: This does not (yet) cover characters on non-US keyboards (Russian, |
| 28458 * Hebrew, etc.). |
| 28459 */ |
| 28460 static bool isCharacterKey(int keyCode) { |
| 28461 if ((keyCode >= ZERO && keyCode <= NINE) || |
| 28462 (keyCode >= NUM_ZERO && keyCode <= NUM_MULTIPLY) || |
| 28463 (keyCode >= A && keyCode <= Z)) { |
| 28464 return true; |
| 28465 } |
| 28466 |
| 28467 // Safari sends zero key code for non-latin characters. |
| 28468 if (_Device.isWebKit && keyCode == 0) { |
| 28469 return true; |
| 28470 } |
| 28471 |
| 28472 return (keyCode == SPACE || keyCode == QUESTION_MARK || keyCode == NUM_PLUS |
| 28473 || keyCode == NUM_MINUS || keyCode == NUM_PERIOD || |
| 28474 keyCode == NUM_DIVISION || keyCode == SEMICOLON || |
| 28475 keyCode == FF_SEMICOLON || keyCode == DASH || keyCode == EQUALS || |
| 28476 keyCode == FF_EQUALS || keyCode == COMMA || keyCode == PERIOD || |
| 28477 keyCode == SLASH || keyCode == APOSTROPHE || keyCode == SINGLE_QUOTE || |
| 28478 keyCode == OPEN_SQUARE_BRACKET || keyCode == BACKSLASH || |
| 28479 keyCode == CLOSE_SQUARE_BRACKET); |
| 28480 } |
28017 } | 28481 } |
28018 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 28482 // 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 | 28483 // 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. | 28484 // BSD-style license that can be found in the LICENSE file. |
28021 | 28485 |
28022 | 28486 |
28023 /** | 28487 /** |
28024 * Defines the standard key locations returned by | 28488 * Defines the standard key locations returned by |
28025 * KeyboardEvent.getKeyLocation. | 28489 * KeyboardEvent.getKeyLocation. |
28026 */ | 28490 */ |
(...skipping 747 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
28774 final fragment = new DocumentFragment(); | 29238 final fragment = new DocumentFragment(); |
28775 final e = new svg.SVGSVGElement(); | 29239 final e = new svg.SVGSVGElement(); |
28776 e.innerHtml = svgContent; | 29240 e.innerHtml = svgContent; |
28777 | 29241 |
28778 // Copy list first since we don't want liveness during iteration. | 29242 // Copy list first since we don't want liveness during iteration. |
28779 final List nodes = new List.from(e.nodes); | 29243 final List nodes = new List.from(e.nodes); |
28780 fragment.nodes.addAll(nodes); | 29244 fragment.nodes.addAll(nodes); |
28781 return fragment; | 29245 return fragment; |
28782 } | 29246 } |
28783 } | 29247 } |
| 29248 /** |
| 29249 * A custom KeyboardEvent that attempts to eliminate cross-browser |
| 29250 * inconsistencies, and also provide both keyCode and charCode information |
| 29251 * for all key events (when such information can be determined). |
| 29252 * |
| 29253 * This class is very much a work in progress, and we'd love to get information |
| 29254 * on how we can make this class work with as many international keyboards as |
| 29255 * possible. Bugs welcome! |
| 29256 */ |
| 29257 class KeyEvent implements KeyboardEvent { |
| 29258 /** The parent KeyboardEvent that this KeyEvent is wrapping and "fixing". */ |
| 29259 KeyboardEvent _parent; |
| 29260 |
| 29261 /** The "fixed" value of whether the alt key is being pressed. */ |
| 29262 bool _shadowAltKey; |
| 29263 |
| 29264 /** Caculated value of what the estimated charCode is for this event. */ |
| 29265 int _shadowCharCode; |
| 29266 |
| 29267 /** Caculated value of what the estimated keyCode is for this event. */ |
| 29268 int _shadowKeyCode; |
| 29269 |
| 29270 /** Caculated value of what the estimated keyCode is for this event. */ |
| 29271 int get keyCode => _shadowKeyCode; |
| 29272 |
| 29273 /** Caculated value of what the estimated charCode is for this event. */ |
| 29274 int get charCode => this.type == 'keypress' ? _shadowCharCode : 0; |
| 29275 |
| 29276 /** Caculated value of whether the alt key is pressed is for this event. */ |
| 29277 bool get altKey => _shadowAltKey; |
| 29278 |
| 29279 /** Caculated value of what the estimated keyCode is for this event. */ |
| 29280 int get which => keyCode; |
| 29281 |
| 29282 /** Accessor to the underlying keyCode value is the parent event. */ |
| 29283 int get _realKeyCode => _parent.keyCode; |
| 29284 |
| 29285 /** Accessor to the underlying charCode value is the parent event. */ |
| 29286 int get _realCharCode => _parent.charCode; |
| 29287 |
| 29288 /** Accessor to the underlying altKey value is the parent event. */ |
| 29289 bool get _realAltKey => _parent.altKey; |
| 29290 |
| 29291 /** Construct a KeyEvent with [parent] as event we're emulating. */ |
| 29292 KeyEvent(KeyboardEvent parent) { |
| 29293 _parent = parent; |
| 29294 _shadowAltKey = _realAltKey; |
| 29295 _shadowCharCode = _realCharCode; |
| 29296 _shadowKeyCode = _realKeyCode; |
| 29297 } |
| 29298 |
| 29299 /** True if the altGraphKey is pressed during this event. */ |
| 29300 bool get altGraphKey => _parent.altGraphKey; |
| 29301 bool get bubbles => _parent.bubbles; |
| 29302 /** True if this event can be cancelled. */ |
| 29303 bool get cancelable => _parent.cancelable; |
| 29304 bool get cancelBubble => _parent.cancelBubble; |
| 29305 set cancelBubble(bool cancel) => _parent = cancel; |
| 29306 /** Accessor to the clipboardData available for this event. */ |
| 29307 Clipboard get clipboardData => _parent.clipboardData; |
| 29308 /** True if the ctrl key is pressed during this event. */ |
| 29309 bool get ctrlKey => _parent.ctrlKey; |
| 29310 /** Accessor to the target this event is listening to for changes. */ |
| 29311 EventTarget get currentTarget => _parent.currentTarget; |
| 29312 bool get defaultPrevented => _parent.defaultPrevented; |
| 29313 int get detail => _parent.detail; |
| 29314 int get eventPhase => _parent.eventPhase; |
| 29315 /** |
| 29316 * Accessor to the part of the keyboard that the key was pressed from (one of |
| 29317 * KeyLocation.STANDARD, KeyLocation.RIGHT, KeyLocation.LEFT, |
| 29318 * KeyLocation.NUMPAD, KeyLocation.MOBILE, KeyLocation.JOYSTICK). |
| 29319 */ |
| 29320 int get keyLocation => _parent.keyLocation; |
| 29321 int get layerX => _parent.layerX; |
| 29322 int get layerY => _parent.layerY; |
| 29323 /** True if the Meta (or Mac command) key is pressed during this event. */ |
| 29324 bool get metaKey => _parent.metaKey; |
| 29325 int get pageX => _parent.pageX; |
| 29326 int get pageY => _parent.pageY; |
| 29327 bool get returnValue => _parent.returnValue; |
| 29328 set returnValue(bool value) => _parent = value; |
| 29329 /** True if the shift key was pressed during this event. */ |
| 29330 bool get shiftKey => _parent.shiftKey; |
| 29331 int get timeStamp => _parent.timeStamp; |
| 29332 /** |
| 29333 * The type of key event that occurred. One of "keydown", "keyup", or |
| 29334 * "keypress". |
| 29335 */ |
| 29336 String get type => _parent.type; |
| 29337 Window get view => _parent.view; |
| 29338 void preventDefault() => _parent.preventDefault(); |
| 29339 void stopImmediatePropagation() => _parent.stopImmediatePropagation(); |
| 29340 void stopPropagation() => _parent.stopPropagation(); |
| 29341 void $dom_initUIEvent(String type, bool canBubble, bool cancelable, |
| 29342 LocalWindow view, int detail) { |
| 29343 throw new UnsupportedError("Cannot initialize a UI Event from a KeyEvent."); |
| 29344 } |
| 29345 void $dom_initEvent(String eventTypeArg, bool canBubbleArg, |
| 29346 bool cancelableArg) { |
| 29347 throw new UnsupportedError("Cannot initialize an Event from a KeyEvent."); |
| 29348 } |
| 29349 String get _shadowKeyIdentifier => _parent.$dom_keyIdentifier; |
| 29350 } |
28784 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 29351 // 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 | 29352 // 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. | 29353 // BSD-style license that can be found in the LICENSE file. |
28787 | 29354 |
28788 | 29355 |
28789 class _IDBKeyRangeFactoryProvider { | 29356 class _IDBKeyRangeFactoryProvider { |
28790 | 29357 |
28791 static IDBKeyRange createIDBKeyRange_only(/*IDBKey*/ value) => | 29358 static IDBKeyRange createIDBKeyRange_only(/*IDBKey*/ value) => |
28792 IDBKeyRange.only_(value); | 29359 IDBKeyRange.only_(value); |
28793 | 29360 |
(...skipping 1014 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
29808 bool get isEmpty => Maps.isEmpty(this); | 30375 bool get isEmpty => Maps.isEmpty(this); |
29809 } | 30376 } |
29810 | 30377 |
29811 get _printClosure => (s) { | 30378 get _printClosure => (s) { |
29812 try { | 30379 try { |
29813 window.console.log(s); | 30380 window.console.log(s); |
29814 } catch (_) { | 30381 } catch (_) { |
29815 _Utils.print(s); | 30382 _Utils.print(s); |
29816 } | 30383 } |
29817 }; | 30384 }; |
OLD | NEW |