 Chromium Code Reviews
 Chromium Code Reviews Issue 11416249:
  Make KeyboardEvent cross-browser consistent.  (Closed) 
  Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
    
  
    Issue 11416249:
  Make KeyboardEvent cross-browser consistent.  (Closed) 
  Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart| 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:svg' as svg; | 5 import 'dart:svg' as svg; | 
| 6 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 6 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 
| 7 // for details. All rights reserved. Use of this source code is governed by a | 7 // for details. All rights reserved. Use of this source code is governed by a | 
| 8 // BSD-style license that can be found in the LICENSE file. | 8 // BSD-style license that can be found in the LICENSE file. | 
| 9 | 9 | 
| 10 // DO NOT EDIT | 10 // DO NOT EDIT | 
| (...skipping 6423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6434 | 6434 | 
| 6435 /// @domName DirectoryReaderSync.readEntries; @docsEditable true | 6435 /// @domName DirectoryReaderSync.readEntries; @docsEditable true | 
| 6436 @Returns('_EntryArraySync') @Creates('_EntryArraySync') | 6436 @Returns('_EntryArraySync') @Creates('_EntryArraySync') | 
| 6437 List<EntrySync> readEntries() native; | 6437 List<EntrySync> readEntries() native; | 
| 6438 } | 6438 } | 
| 6439 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 6439 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 
| 6440 // for details. All rights reserved. Use of this source code is governed by a | 6440 // for details. All rights reserved. Use of this source code is governed by a | 
| 6441 // BSD-style license that can be found in the LICENSE file. | 6441 // BSD-style license that can be found in the LICENSE file. | 
| 6442 | 6442 | 
| 6443 | 6443 | 
| 6444 /** | |
| 6445 * Represents an HTML <div> element. | |
| 
Emily Fortuna
2012/11/28 22:58:12
these are "removed" because of Andrei's dartdoc ch
 | |
| 6446 * | |
| 6447 * The [DivElement] is a generic container for content and does not have any | |
| 6448 * special significance. It is functionally similar to [SpanElement]. | |
| 6449 * | |
| 6450 * The [DivElement] is a block-level element, as opposed to [SpanElement], | |
| 6451 * which is an inline-level element. | |
| 6452 * | |
| 6453 * Example usage: | |
| 6454 * | |
| 6455 * DivElement div = new DivElement(); | |
| 6456 * div.text = 'Here's my new DivElem | |
| 6457 * document.body.elements.add(elem); | |
| 6458 * | |
| 6459 * See also: | |
| 6460 * | |
| 6461 * * [HTML <div> element](http://www.w3.org/TR/html-markup/div.html) from W3C. | |
| 6462 * * [Block-level element](http://www.w3.org/TR/CSS2/visuren.html#block-boxes) f rom W3C. | |
| 6463 * * [Inline-level element](http://www.w3.org/TR/CSS2/visuren.html#inline-boxes) from W3C. | |
| 6464 */ | |
| 6465 /// @domName HTMLDivElement; @docsEditable true | 6444 /// @domName HTMLDivElement; @docsEditable true | 
| 6466 class DivElement extends Element implements Element native "*HTMLDivElement" { | 6445 class DivElement extends Element implements Element native "*HTMLDivElement" { | 
| 6467 | 6446 | 
| 6468 factory DivElement() => document.$dom_createElement("div"); | 6447 factory DivElement() => document.$dom_createElement("div"); | 
| 6469 } | 6448 } | 
| 6470 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 6449 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 
| 6471 // for details. All rights reserved. Use of this source code is governed by a | 6450 // for details. All rights reserved. Use of this source code is governed by a | 
| 6472 // BSD-style license that can be found in the LICENSE file. | 6451 // BSD-style license that can be found in the LICENSE file. | 
| 6473 | 6452 | 
| 6474 | 6453 | 
| (...skipping 4892 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 11367 int scopeType(int scopeIndex) native; | 11346 int scopeType(int scopeIndex) native; | 
| 11368 } | 11347 } | 
| 11369 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 11348 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 
| 11370 // for details. All rights reserved. Use of this source code is governed by a | 11349 // for details. All rights reserved. Use of this source code is governed by a | 
| 11371 // BSD-style license that can be found in the LICENSE file. | 11350 // BSD-style license that can be found in the LICENSE file. | 
| 11372 | 11351 | 
| 11373 | 11352 | 
| 11374 /// @domName KeyboardEvent; @docsEditable true | 11353 /// @domName KeyboardEvent; @docsEditable true | 
| 11375 class KeyboardEvent extends UIEvent native "*KeyboardEvent" { | 11354 class KeyboardEvent extends UIEvent native "*KeyboardEvent" { | 
| 11376 | 11355 | 
| 11356 factory KeyboardEvent(String type, Window view, | |
| 11357 [bool canBubble = true, bool cancelable = true, | |
| 11358 String keyIdentifier = null, int keyLocation = 1, bool ctrlKey = false, | |
| 11359 bool altKey = false, bool shiftKey = false, bool metaKey = false, | |
| 11360 bool altGraphKey = false]) { | |
| 11361 final e = document.$dom_createEvent("KeyboardEvent"); | |
| 11362 e.$dom_initKeyboardEvent(type, canBubble, cancelable, view, keyIdentifier, | |
| 11363 keyLocation, ctrlKey, altKey, shiftKey, metaKey, altGraphKey); | |
| 11364 return e; | |
| 11365 } | |
| 11366 | |
| 11367 /** @domName KeyboardEvent.initKeyboardEvent */ | |
| 11368 void $dom_initKeyboardEvent(String type, bool canBubble, bool cancelable, | |
| 11369 LocalWindow view, String keyIdentifier, int keyLocation, bool ctrlKey, | |
| 11370 bool altKey, bool shiftKey, bool metaKey, bool altGraphKey) { | |
| 11371 var function = JS('dynamic', '#.initKeyboardEvent || #.initKeyEvent', this, | |
| 11372 this); | |
| 11373 JS('void', '#(#, #, #, #, #, #, #, #, #, #, #)', function, type, | |
| 11374 canBubble, cancelable, view, keyIdentifier, keyLocation, ctrlKey, | |
| 11375 altKey, shiftKey, metaKey, altGraphKey); | |
| 11376 } | |
| 11377 | |
| 11378 /** @domName KeyboardEvent.keyCode */ | |
| 11379 int get keyCode => $dom_keyCode; | |
| 11380 | |
| 11381 /** @domName KeyboardEvent.charCode */ | |
| 11382 int get charCode => $dom_charCode; | |
| 11383 | |
| 11377 /// @domName KeyboardEvent.altGraphKey; @docsEditable true | 11384 /// @domName KeyboardEvent.altGraphKey; @docsEditable true | 
| 11378 final bool altGraphKey; | 11385 final bool altGraphKey; | 
| 11379 | 11386 | 
| 11380 /// @domName KeyboardEvent.altKey; @docsEditable true | 11387 /// @domName KeyboardEvent.altKey; @docsEditable true | 
| 11381 final bool altKey; | 11388 final bool altKey; | 
| 11382 | 11389 | 
| 11383 /// @domName KeyboardEvent.ctrlKey; @docsEditable true | 11390 /// @domName KeyboardEvent.ctrlKey; @docsEditable true | 
| 11384 final bool ctrlKey; | 11391 final bool ctrlKey; | 
| 11385 | 11392 | 
| 11386 /// @domName KeyboardEvent.keyIdentifier; @docsEditable true | 11393 /// @domName KeyboardEvent.keyIdentifier; @docsEditable true | 
| 11387 final String keyIdentifier; | 11394 String get $dom_keyIdentifier => JS("String", "#.keyIdentifier", this); | 
| 11388 | 11395 | 
| 11389 /// @domName KeyboardEvent.keyLocation; @docsEditable true | 11396 /// @domName KeyboardEvent.keyLocation; @docsEditable true | 
| 11390 final int keyLocation; | 11397 final int keyLocation; | 
| 11391 | 11398 | 
| 11392 /// @domName KeyboardEvent.metaKey; @docsEditable true | 11399 /// @domName KeyboardEvent.metaKey; @docsEditable true | 
| 11393 final bool metaKey; | 11400 final bool metaKey; | 
| 11394 | 11401 | 
| 11395 /// @domName KeyboardEvent.shiftKey; @docsEditable true | 11402 /// @domName KeyboardEvent.shiftKey; @docsEditable true | 
| 11396 final bool shiftKey; | 11403 final bool shiftKey; | 
| 11397 | 11404 | 
| 11398 /// @domName KeyboardEvent.initKeyboardEvent; @docsEditable true | |
| 11399 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; | |
| 11400 } | 11405 } | 
| 11401 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 11406 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 
| 11402 // for details. All rights reserved. Use of this source code is governed by a | 11407 // for details. All rights reserved. Use of this source code is governed by a | 
| 11403 // BSD-style license that can be found in the LICENSE file. | 11408 // BSD-style license that can be found in the LICENSE file. | 
| 11404 | 11409 | 
| 11405 | 11410 | 
| 11406 /// @domName HTMLKeygenElement; @docsEditable true | 11411 /// @domName HTMLKeygenElement; @docsEditable true | 
| 11407 class KeygenElement extends Element implements Element native "*HTMLKeygenElemen t" { | 11412 class KeygenElement extends Element implements Element native "*HTMLKeygenElemen t" { | 
| 11408 | 11413 | 
| 11409 factory KeygenElement() => document.$dom_createElement("keygen"); | 11414 factory KeygenElement() => document.$dom_createElement("keygen"); | 
| (...skipping 1474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 12884 final int totalJSHeapSize; | 12889 final int totalJSHeapSize; | 
| 12885 | 12890 | 
| 12886 /// @domName MemoryInfo.usedJSHeapSize; @docsEditable true | 12891 /// @domName MemoryInfo.usedJSHeapSize; @docsEditable true | 
| 12887 final int usedJSHeapSize; | 12892 final int usedJSHeapSize; | 
| 12888 } | 12893 } | 
| 12889 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 12894 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 
| 12890 // for details. All rights reserved. Use of this source code is governed by a | 12895 // for details. All rights reserved. Use of this source code is governed by a | 
| 12891 // BSD-style license that can be found in the LICENSE file. | 12896 // BSD-style license that can be found in the LICENSE file. | 
| 12892 | 12897 | 
| 12893 | 12898 | 
| 12894 /** | |
| 12895 * An HTML <menu> element. | |
| 12896 * | |
| 12897 * A <menu> element represents an unordered list of menu commands. | |
| 12898 * | |
| 12899 * See also: | |
| 12900 * | |
| 12901 * * [Menu Element](https://developer.mozilla.org/en-US/docs/HTML/Element/menu) from MDN. | |
| 12902 * * [Menu Element](http://www.w3.org/TR/html5/the-menu-element.html#the-menu-e lement) from the W3C. | |
| 12903 */ | |
| 12904 /// @domName HTMLMenuElement; @docsEditable true | 12899 /// @domName HTMLMenuElement; @docsEditable true | 
| 12905 class MenuElement extends Element implements Element native "*HTMLMenuElement" { | 12900 class MenuElement extends Element implements Element native "*HTMLMenuElement" { | 
| 12906 | 12901 | 
| 12907 factory MenuElement() => document.$dom_createElement("menu"); | 12902 factory MenuElement() => document.$dom_createElement("menu"); | 
| 12908 } | 12903 } | 
| 12909 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 12904 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 
| 12910 // for details. All rights reserved. Use of this source code is governed by a | 12905 // for details. All rights reserved. Use of this source code is governed by a | 
| 12911 // BSD-style license that can be found in the LICENSE file. | 12906 // BSD-style license that can be found in the LICENSE file. | 
| 12912 | 12907 | 
| 12913 | 12908 | 
| (...skipping 4820 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 17734 } | 17729 } | 
| 17735 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 17730 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 
| 17736 // for details. All rights reserved. Use of this source code is governed by a | 17731 // for details. All rights reserved. Use of this source code is governed by a | 
| 17737 // BSD-style license that can be found in the LICENSE file. | 17732 // BSD-style license that can be found in the LICENSE file. | 
| 17738 | 17733 | 
| 17739 | 17734 | 
| 17740 /// @domName UIEvent; @docsEditable true | 17735 /// @domName UIEvent; @docsEditable true | 
| 17741 class UIEvent extends Event native "*UIEvent" { | 17736 class UIEvent extends Event native "*UIEvent" { | 
| 17742 | 17737 | 
| 17743 /// @domName UIEvent.charCode; @docsEditable true | 17738 /// @domName UIEvent.charCode; @docsEditable true | 
| 17744 final int charCode; | 17739 int get $dom_charCode => JS("int", "#.charCode", this); | 
| 17745 | 17740 | 
| 17746 /// @domName UIEvent.detail; @docsEditable true | 17741 /// @domName UIEvent.detail; @docsEditable true | 
| 17747 final int detail; | 17742 final int detail; | 
| 17748 | 17743 | 
| 17749 /// @domName UIEvent.keyCode; @docsEditable true | 17744 /// @domName UIEvent.keyCode; @docsEditable true | 
| 17750 final int keyCode; | 17745 int get $dom_keyCode => JS("int", "#.keyCode", this); | 
| 17751 | 17746 | 
| 17752 /// @domName UIEvent.layerX; @docsEditable true | 17747 /// @domName UIEvent.layerX; @docsEditable true | 
| 17753 final int layerX; | 17748 final int layerX; | 
| 17754 | 17749 | 
| 17755 /// @domName UIEvent.layerY; @docsEditable true | 17750 /// @domName UIEvent.layerY; @docsEditable true | 
| 17756 final int layerY; | 17751 final int layerY; | 
| 17757 | 17752 | 
| 17758 /// @domName UIEvent.pageX; @docsEditable true | 17753 /// @domName UIEvent.pageX; @docsEditable true | 
| 17759 final int pageX; | 17754 final int pageX; | 
| 17760 | 17755 | 
| (...skipping 4787 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 22548 Element get first => _filtered.first; | 22543 Element get first => _filtered.first; | 
| 22549 | 22544 | 
| 22550 Element get last => _filtered.last; | 22545 Element get last => _filtered.last; | 
| 22551 } | 22546 } | 
| 22552 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 22547 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 
| 22553 // for details. All rights reserved. Use of this source code is governed by a | 22548 // for details. All rights reserved. Use of this source code is governed by a | 
| 22554 // BSD-style license that can be found in the LICENSE file. | 22549 // BSD-style license that can be found in the LICENSE file. | 
| 22555 | 22550 | 
| 22556 | 22551 | 
| 22557 /** | 22552 /** | 
| 22553 * Works with KeyboardEvent and KeyEvent to determine how to expose information | |
| 22554 * about Key(board)Events. This class functions like an EventListenerList, and | |
| 22555 * provides a consistent interface for the Dart | |
| 22556 * user, despite the fact that a multitude of browsers that have varying | |
| 22557 * keyboard default behavior. | |
| 22558 * | |
| 22559 * This class is very much a work in progress, and we'd love to get information | |
| 22560 * on how we can make this class work with as many international keyboards as | |
| 22561 * possible. Bugs welcome! | |
| 22562 */ | |
| 22563 class KeyboardEventController { | |
| 22564 // This code inspired by Closure's KeyHandling library. | |
| 22565 // http://closure-library.googlecode.com/svn/docs/closure_goog_events_keyhandl er.js.source.html | |
| 22566 | |
| 22567 /** | |
| 22568 * The set of keys that have been pressed down without seeing their | |
| 22569 * corresponding keyup event. | |
| 22570 */ | |
| 22571 List<KeyboardEvent> keyDownList; | |
| 22572 | |
| 22573 /** The set of functions that wish to be notified when a KeyEvent happens. */ | |
| 22574 List<Function> _callbacks; | |
| 22575 | |
| 22576 /** The type of KeyEvent we are tracking (keyup, keydown, keypress). */ | |
| 22577 String _type; | |
| 22578 | |
| 22579 // The distance to shift from upper case alphabet Roman letters to lower case. | |
| 22580 const int _ROMAN_ALPHABET_OFFSET = "a".charCodes[0] - "A".charCodes[0]; | |
| 22581 | |
| 22582 /** | |
| 22583 * An enumeration of key identifiers currently part of the W3C draft for DOM3 | |
| 22584 * and their mappings to keyCodes. | |
| 22585 * http://www.w3.org/TR/DOM-Level-3-Events/keyset.html#KeySet-Set | |
| 22586 */ | |
| 22587 static Map<String, int> _keyIdentifier = { | |
| 22588 'Up': KeyCode.UP, | |
| 22589 'Down': KeyCode.DOWN, | |
| 22590 'Left': KeyCode.LEFT, | |
| 22591 'Right': KeyCode.RIGHT, | |
| 22592 'Enter': KeyCode.ENTER, | |
| 22593 'F1': KeyCode.F1, | |
| 22594 'F2': KeyCode.F2, | |
| 22595 'F3': KeyCode.F3, | |
| 22596 'F4': KeyCode.F4, | |
| 22597 'F5': KeyCode.F5, | |
| 22598 'F6': KeyCode.F6, | |
| 22599 'F7': KeyCode.F7, | |
| 22600 'F8': KeyCode.F8, | |
| 22601 'F9': KeyCode.F9, | |
| 22602 'F10': KeyCode.F10, | |
| 22603 'F11': KeyCode.F11, | |
| 22604 'F12': KeyCode.F12, | |
| 22605 'U+007F': KeyCode.DELETE, | |
| 22606 'Home': KeyCode.HOME, | |
| 22607 'End': KeyCode.END, | |
| 22608 'PageUp': KeyCode.PAGE_UP, | |
| 22609 'PageDown': KeyCode.PAGE_DOWN, | |
| 22610 'Insert': KeyCode.INSERT | |
| 22611 }; | |
| 22612 | |
| 22613 /** Named constructor to add an onKeyPress event listener to our handler. */ | |
| 22614 KeyboardEventController.keypress(EventTarget target) { | |
| 22615 _KeyboardEventController(target, 'keypress'); | |
| 22616 } | |
| 22617 | |
| 22618 /** Named constructor to add an onKeyUp event listener to our handler. */ | |
| 22619 KeyboardEventController.keyup(EventTarget target) { | |
| 22620 _KeyboardEventController(target, 'keyup'); | |
| 22621 } | |
| 22622 | |
| 22623 /** Named constructor to add an onKeyDown event listener to our handler. */ | |
| 22624 KeyboardEventController.keydown(EventTarget target) { | |
| 22625 _KeyboardEventController(target, 'keydown'); | |
| 22626 } | |
| 22627 | |
| 22628 /** | |
| 22629 * General constructor, performs basic initialization for our improved | |
| 22630 * KeyboardEvent controller. | |
| 22631 */ | |
| 22632 _KeyboardEventController(EventTarget target, String type) { | |
| 22633 keyDownList = []; | |
| 22634 _callbacks = []; | |
| 22635 _type = type; | |
| 22636 target.on.keyDown.add(processKeyDown, true); | |
| 22637 target.on.keyPress.add(processKeyPress, true); | |
| 22638 target.on.keyUp.add(processKeyUp, true); | |
| 22639 } | |
| 22640 | |
| 22641 /** Add a callback that wishes to be notified when a KeyEvent occurs. */ | |
| 22642 void add(Function callback) { | |
| 22643 _callbacks.add(callback); | |
| 22644 } | |
| 22645 | |
| 22646 /** | |
| 22647 * Notify all callback listeners that a KeyEvent of the relevant type has | |
| 22648 * occurred. | |
| 22649 */ | |
| 22650 bool _dispatch(KeyEvent event) { | |
| 22651 if (event.type == _type) { | |
| 22652 for(var callback in _callbacks) { | |
| 22653 callback(event); | |
| 22654 } | |
| 22655 } | |
| 22656 } | |
| 22657 | |
| 22658 /** Remove the given callback from the listeners list. */ | |
| 22659 void remove(Function callback) { | |
| 22660 _callbacks = _callbacks.filter((element) => element != callback); | |
| 22661 } | |
| 22662 | |
| 22663 /** Determine if caps lock is one of the currently depressed keys. */ | |
| 22664 bool get _capsLockOn() => | |
| 22665 keyDownList.some((var element) => element.keyCode == KeyCode.CAPS_LOCK); | |
| 22666 | |
| 22667 /** | |
| 22668 * Given the previously recorded keydown key codes, see if we can determine | |
| 22669 * the keycode of this keypress [event]. (Generally browsers only provide | |
| 22670 * charCode information for keypress events, but with a little | |
| 22671 * reverse-engineering, we can also determine the keyCode.) Returns | |
| 22672 * KeyCode.UNKNOWN if the keycode could not be determined. | |
| 22673 */ | |
| 22674 int _determineKeyCodeForKeypress(KeyboardEvent event) { | |
| 22675 // Note: This function is a work in progress. We'll expand this function | |
| 22676 // once we get more information about other keyboards. | |
| 22677 for (var prevEvent in keyDownList) { | |
| 22678 if (prevEvent._shadowCharCode == event.charCode) { | |
| 22679 return prevEvent.keyCode; | |
| 22680 } | |
| 22681 if ((event.shiftKey || _capsLockOn) && event.charCode >= "A".charCodes[0] | |
| 22682 && event.charCode <= "Z".charCodes[0] && event.charCode + | |
| 22683 _ROMAN_ALPHABET_OFFSET == prevEvent._shadowCharCode) { | |
| 22684 return prevEvent.keyCode; | |
| 22685 } | |
| 22686 } | |
| 22687 return KeyCode.UNKNOWN; | |
| 22688 } | |
| 22689 | |
| 22690 /** | |
| 22691 * Given the charater code returned from a keyDown [event], try to ascertain | |
| 22692 * and return the corresponding charCode for the character that was pressed. | |
| 22693 * This information is not shown to the user, but used to help polyfill | |
| 22694 * keypress events. | |
| 22695 */ | |
| 22696 int _findCharCodeKeyDown(KeyboardEvent event) { | |
| 22697 if (event.keyLocation == 3) { // Numpad keys. | |
| 22698 switch (event.keyCode) { | |
| 22699 case KeyCode.NUM_ZERO: | |
| 22700 // Even though this function returns _charCodes_, for some cases the | |
| 22701 // KeyCode == the charCode we want, in which case we use the keycode | |
| 22702 // constant for readability. | |
| 22703 return KeyCode.ZERO; | |
| 22704 case KeyCode.NUM_ONE: | |
| 22705 return KeyCode.ONE; | |
| 22706 case KeyCode.NUM_TWO: | |
| 22707 return KeyCode.TWO; | |
| 22708 case KeyCode.NUM_THREE: | |
| 22709 return KeyCode.THREE; | |
| 22710 case KeyCode.NUM_FOUR: | |
| 22711 return KeyCode.FOUR; | |
| 22712 case KeyCode.NUM_FIVE: | |
| 22713 return KeyCode.FIVE; | |
| 22714 case KeyCode.NUM_SIX: | |
| 22715 return KeyCode.SIX; | |
| 22716 case KeyCode.NUM_SEVEN: | |
| 22717 return KeyCode.SEVEN; | |
| 22718 case KeyCode.NUM_EIGHT: | |
| 22719 return KeyCode.EIGHT; | |
| 22720 case KeyCode.NUM_NINE: | |
| 22721 return KeyCode.NINE; | |
| 22722 case KeyCode.NUM_MULTIPLY: | |
| 22723 return 42; // Char code for * | |
| 22724 case KeyCode.NUM_PLUS: | |
| 22725 return 43; // + | |
| 22726 case KeyCode.NUM_MINUS: | |
| 22727 return 45; // - | |
| 22728 case KeyCode.NUM_PERIOD: | |
| 22729 return 46; // . | |
| 22730 case KeyCode.NUM_DIVISION: | |
| 22731 return 47; // / | |
| 22732 } | |
| 22733 } else if (event.keyCode >= 65 && event.keyCode <= 90) { | |
| 22734 // Set the "char code" for key down as the lower case letter. Again, this | |
| 22735 // will not show up for the user, but will be helpful in estimating | |
| 22736 // keyCode locations and other information during the keyPress event. | |
| 22737 return event.keyCode + _ROMAN_ALPHABET_OFFSET; | |
| 22738 } | |
| 22739 switch(event.keyCode) { | |
| 22740 case KeyCode.SEMICOLON: | |
| 22741 return KeyCode.FF_SEMICOLON; | |
| 22742 case KeyCode.EQUALS: | |
| 22743 return KeyCode.FF_EQUALS; | |
| 22744 case KeyCode.COMMA: | |
| 22745 return 44; // Ascii value for , | |
| 22746 case KeyCode.DASH: | |
| 22747 return 45; // - | |
| 22748 case KeyCode.PERIOD: | |
| 22749 return 46; // . | |
| 22750 case KeyCode.SLASH: | |
| 22751 return 47; // / | |
| 22752 case KeyCode.APOSTROPHE: | |
| 22753 return 96; // ` | |
| 22754 case KeyCode.OPEN_SQUARE_BRACKET: | |
| 22755 return 91; // [ | |
| 22756 case KeyCode.BACKSLASH: | |
| 22757 return 92; // \ | |
| 22758 case KeyCode.CLOSE_SQUARE_BRACKET: | |
| 22759 return 93; // ] | |
| 22760 case KeyCode.SINGLE_QUOTE: | |
| 22761 return 39; // ' | |
| 22762 } | |
| 22763 return event.keyCode; | |
| 22764 } | |
| 22765 | |
| 22766 /** | |
| 22767 * Returns true if the key fires a keypress event in the current browser. | |
| 22768 */ | |
| 22769 bool _firesKeyPressEvent(KeyEvent event) { | |
| 22770 if (!_Device.isIE && !_Device.isWebKit) { | |
| 22771 return true; | |
| 22772 } | |
| 22773 | |
| 22774 if (_Device.userAgent.contains('Mac') && event.altKey) { | |
| 22775 return KeyCode.isCharacterKey(event.keyCode); | |
| 22776 } | |
| 22777 | |
| 22778 // Alt but not AltGr which is represented as Alt+Ctrl. | |
| 22779 if (event.altKey && !event.ctrlKey) { | |
| 22780 return false; | |
| 22781 } | |
| 22782 | |
| 22783 // Saves Ctrl or Alt + key for IE and WebKit, which won't fire keypress. | |
| 22784 if (!event.shiftKey && | |
| 22785 (keyDownList.last.keyCode == KeyCode.CTRL || | |
| 22786 keyDownList.last.keyCode == KeyCode.ALT || | |
| 22787 _Device.userAgent.contains('Mac') && | |
| 22788 keyDownList.last.keyCode == KeyCode.META)) { | |
| 22789 return false; | |
| 22790 } | |
| 22791 | |
| 22792 // Some keys with Ctrl/Shift do not issue keypress in WebKit. | |
| 22793 if (_Device.isWebKit && event.ctrlKey && event.shiftKey && ( | |
| 22794 event.keycode == KeyCode.BACKSLASH || | |
| 22795 event.keycode == KeyCode.OPEN_SQUARE_BRACKET || | |
| 22796 event.keycode == KeyCode.CLOSE_SQUARE_BRACKET || | |
| 22797 event.keycode == KeyCode.TILDE || | |
| 22798 event.keycode == KeyCode.SEMICOLON || event.keycode == KeyCode.DASH || | |
| 22799 event.keycode == KeyCode.EQUALS || event.keycode == KeyCode.COMMA || | |
| 22800 event.keycode == KeyCode.PERIOD || event.keycode == KeyCode.SLASH || | |
| 22801 event.keycode == KeyCode.APOSTROPHE || | |
| 22802 event.keycode == KeyCode.SINGLE_QUOTE)) { | |
| 22803 return false; | |
| 22804 } | |
| 22805 | |
| 22806 switch (event.keyCode) { | |
| 22807 case KeyCode.ENTER: | |
| 22808 // IE9 does not fire keypress on ENTER. | |
| 22809 return !_Device.isIE; | |
| 22810 case KeyCode.ESC: | |
| 22811 return !_Device.isWebKit; | |
| 22812 } | |
| 22813 | |
| 22814 return KeyCode.isCharacterKey(event.keyCode); | |
| 22815 } | |
| 22816 | |
| 22817 /** | |
| 22818 * Normalize the keycodes to the IE KeyCodes (this is what Chrome, IE, and | |
| 22819 * Opera all use). | |
| 22820 */ | |
| 22821 int normalizeKeyCodes(KeyboardEvent event) { | |
| 22822 // Note: This may change once we get input about non-US keyboards. | |
| 22823 if (_Device.isFirefox) { | |
| 22824 switch(event.keyCode) { | |
| 22825 case KeyCode.FF_EQUALS: | |
| 22826 return KeyCode.EQUALS; | |
| 22827 case KeyCode.FF_SEMICOLON: | |
| 22828 return KeyCode.SEMICOLON; | |
| 22829 case KeyCode.MAC_FF_META: | |
| 22830 return KeyCode.META; | |
| 22831 case KeyCode.WIN_KEY_FF_LINUX: | |
| 22832 return KeyCode.WIN_KEY; | |
| 22833 } | |
| 22834 } | |
| 22835 return event.keyCode; | |
| 22836 } | |
| 22837 | |
| 22838 /** Handle keydown events. */ | |
| 22839 void processKeyDown(KeyboardEvent e) { | |
| 22840 // Ctrl-Tab and Alt-Tab can cause the focus to be moved to another window | |
| 22841 // before we've caught a key-up event. If the last-key was one of these | |
| 22842 // we reset the state. | |
| 22843 if (keyDownList.length > 0 && | |
| 22844 (keyDownList.last.keyCode == KeyCode.CTRL && !e.ctrlKey || | |
| 22845 keyDownList.last.keyCode == KeyCode.ALT && !e.altKey || | |
| 22846 _Device.userAgent.contains('Mac') && | |
| 22847 keyDownList.last.keyCode == KeyCode.META && !e.metaKey)) { | |
| 22848 keyDownList = []; | |
| 22849 } | |
| 22850 | |
| 22851 var event = new KeyEvent(e); | |
| 22852 event._shadowKeyCode = normalizeKeyCodes(event); | |
| 22853 // Technically a "keydown" event doesn't have a charCode. This is | |
| 22854 // calculated nonetheless to provide us with more information in giving | |
| 22855 // as much information as possible on keypress about keycode and also | |
| 22856 // charCode. | |
| 22857 event._shadowCharCode = _findCharCodeKeyDown(event); | |
| 22858 if (keyDownList.length > 0 && event.keyCode != keyDownList.last.keyCode && | |
| 22859 !_firesKeyPressEvent(event)) { | |
| 22860 // Some browsers have quirks not firing keypress events where all other | |
| 22861 // browsers do. This makes them more consistent. | |
| 22862 processKeyPress(event); | |
| 22863 } | |
| 22864 keyDownList.add(event); | |
| 22865 _dispatch(event); | |
| 22866 } | |
| 22867 | |
| 22868 /** Handle keypress events. */ | |
| 22869 void processKeyPress(KeyboardEvent event) { | |
| 22870 var e = new KeyEvent(event); | |
| 22871 // IE reports the character code in the keyCode field for keypress events. | |
| 22872 // There are two exceptions however, Enter and Escape. | |
| 22873 if (_Device.isIE) { | |
| 22874 if (e.keyCode == KeyCode.ENTER || e.keyCode == KeyCode.ESC) { | |
| 22875 e._shadowCharCode = 0; | |
| 22876 } else { | |
| 22877 e._shadowCharCode = e.keyCode; | |
| 22878 } | |
| 22879 } else if (_Device.isOpera) { | |
| 22880 // Opera reports the character code in the keyCode field. | |
| 22881 e._shadowCharCode = KeyCode.isCharacterKey(keyCode) ? e.keyCode : 0; | |
| 22882 } | |
| 22883 // Now we guestimate about what the keycode is that was actually | |
| 22884 // pressed, given previous keydown information. | |
| 22885 e._shadowKeyCode = _determineKeyCodeForKeypress(e); | |
| 22886 | |
| 22887 // Correct the key value for certain browser-specific quirks. | |
| 22888 if (e._shadowKeyIdentifier && | |
| 22889 _keyIdentifier.contains(e._shadowKeyIdentifier)) { | |
| 22890 // This is needed for Safari Windows because it currently doesn't give a | |
| 22891 // keyCode/which for non printable keys. | |
| 22892 e._shadowKeyCode = _keyIdentifier[keyIdentifier]; | |
| 22893 } | |
| 22894 e._shadowAltKey = keyDownList.some((var element) => element.altKey); | |
| 22895 _dispatch(e); | |
| 22896 } | |
| 22897 | |
| 22898 /** Handle keyup events. */ | |
| 22899 void processKeyUp(KeyboardEvent event) { | |
| 22900 var e = new KeyEvent(event); | |
| 22901 KeyboardEvent toRemove = null; | |
| 22902 for (var key in keyDownList) { | |
| 22903 if (key.keyCode == e.keyCode) { | |
| 22904 toRemove = key; | |
| 22905 } | |
| 22906 } | |
| 22907 if (toRemove != null) { | |
| 22908 keyDownList = keyDownList.filter((element) => element != toRemove); | |
| 22909 } else if (keyDownList.length > 0) { | |
| 22910 // This happens when we've reached some international keyboard case we | |
| 22911 // haven't accounted for or we haven't correctly eliminated all browser | |
| 22912 // inconsistencies. Filing bugs on when this is reached is welcome! | |
| 22913 keyDownList.removeLast(); | |
| 22914 } | |
| 22915 _dispatch(e); | |
| 22916 } | |
| 22917 } | |
| 22918 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | |
| 22919 // for details. All rights reserved. Use of this source code is governed by a | |
| 22920 // BSD-style license that can be found in the LICENSE file. | |
| 22921 | |
| 22922 | |
| 22923 /** | |
| 22558 * Defines the keycode values for keys that are returned by | 22924 * Defines the keycode values for keys that are returned by | 
| 22559 * KeyboardEvent.keyCode. | 22925 * KeyboardEvent.keyCode. | 
| 22560 * | 22926 * | 
| 22561 * Important note: There is substantial divergence in how different browsers | 22927 * Important note: There is substantial divergence in how different browsers | 
| 22562 * handle keycodes and their variants in different locales/keyboard layouts. We | 22928 * handle keycodes and their variants in different locales/keyboard layouts. We | 
| 22563 * provide these constants to help make code processing keys more readable. | 22929 * provide these constants to help make code processing keys more readable. | 
| 22564 */ | 22930 */ | 
| 22565 abstract class KeyCode { | 22931 abstract class KeyCode { | 
| 22566 // These constant names were borrowed from Closure's Keycode enumeration | 22932 // These constant names were borrowed from Closure's Keycode enumeration | 
| 22567 // class. | 22933 // class. | 
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 22738 */ | 23104 */ | 
| 22739 static const int BACKSLASH = 220; | 23105 static const int BACKSLASH = 220; | 
| 22740 /** | 23106 /** | 
| 22741 * CAUTION: This constant requires localization for other locales and keyboard | 23107 * CAUTION: This constant requires localization for other locales and keyboard | 
| 22742 * layouts. | 23108 * layouts. | 
| 22743 */ | 23109 */ | 
| 22744 static const int CLOSE_SQUARE_BRACKET = 221; | 23110 static const int CLOSE_SQUARE_BRACKET = 221; | 
| 22745 static const int WIN_KEY = 224; | 23111 static const int WIN_KEY = 224; | 
| 22746 static const int MAC_FF_META = 224; | 23112 static const int MAC_FF_META = 224; | 
| 22747 static const int WIN_IME = 229; | 23113 static const int WIN_IME = 229; | 
| 23114 | |
| 23115 /** A sentinel value if the keycode could not be determined. */ | |
| 23116 static const int UNKNOWN = -1; | |
| 23117 | |
| 23118 /** | |
| 23119 * Returns true if the keyCode produces a (US keyboard) character. | |
| 23120 * Note: This does not (yet) cover characters on non-US keyboards (Russian, | |
| 23121 * Hebrew, etc.). | |
| 23122 */ | |
| 23123 static bool isCharacterKey(int keyCode) { | |
| 23124 if ((keyCode >= ZERO && keyCode <= NINE) || | |
| 23125 (keyCode >= NUM_ZERO && keyCode <= NUM_MULTIPLY) || | |
| 23126 (keyCode >= A && keyCode <= Z)) { | |
| 23127 return true; | |
| 23128 } | |
| 23129 | |
| 23130 // Safari sends zero key code for non-latin characters. | |
| 23131 if (_Device.isWebKit && keyCode == 0) { | |
| 23132 return true; | |
| 23133 } | |
| 23134 | |
| 23135 return (keyCode == SPACE || keyCode == QUESTION_MARK || keyCode == NUM_PLUS | |
| 23136 || keyCode == NUM_MINUS || keyCode == NUM_PERIOD || | |
| 23137 keyCode == NUM_DIVISION || keyCode == SEMICOLON || | |
| 23138 keyCode == FF_SEMICOLON || keyCode == DASH || keyCode == EQUALS || | |
| 23139 keyCode == FF_EQUALS || keyCode == COMMA || keyCode == PERIOD || | |
| 23140 keyCode == SLASH || keyCode == APOSTROPHE || keyCode == SINGLE_QUOTE || | |
| 23141 keyCode == OPEN_SQUARE_BRACKET || keyCode == BACKSLASH || | |
| 23142 keyCode == CLOSE_SQUARE_BRACKET); | |
| 23143 } | |
| 22748 } | 23144 } | 
| 22749 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 23145 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 
| 22750 // for details. All rights reserved. Use of this source code is governed by a | 23146 // for details. All rights reserved. Use of this source code is governed by a | 
| 22751 // BSD-style license that can be found in the LICENSE file. | 23147 // BSD-style license that can be found in the LICENSE file. | 
| 22752 | 23148 | 
| 22753 | 23149 | 
| 22754 /** | 23150 /** | 
| 22755 * Defines the standard key locations returned by | 23151 * Defines the standard key locations returned by | 
| 22756 * KeyboardEvent.getKeyLocation. | 23152 * KeyboardEvent.getKeyLocation. | 
| 22757 */ | 23153 */ | 
| (...skipping 1913 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 24671 | 25067 | 
| 24672 static History _createSafe(h) { | 25068 static History _createSafe(h) { | 
| 24673 if (identical(h, window.history)) { | 25069 if (identical(h, window.history)) { | 
| 24674 return h; | 25070 return h; | 
| 24675 } else { | 25071 } else { | 
| 24676 // TODO(vsm): Cache or implement equality. | 25072 // TODO(vsm): Cache or implement equality. | 
| 24677 return new _HistoryCrossFrame(h); | 25073 return new _HistoryCrossFrame(h); | 
| 24678 } | 25074 } | 
| 24679 } | 25075 } | 
| 24680 } | 25076 } | 
| 25077 /** | |
| 25078 * A custom KeyboardEvent that attempts to eliminate cross-browser | |
| 25079 * inconsistencies, and also provide both keyCode and charCode information | |
| 25080 * for all key events (when such information can be determined). | |
| 25081 * | |
| 25082 * This class is very much a work in progress, and we'd love to get information | |
| 25083 * on how we can make this class work with as many international keyboards as | |
| 25084 * possible. Bugs welcome! | |
| 25085 */ | |
| 25086 class KeyEvent implements KeyboardEvent { | |
| 25087 /** The parent KeyboardEvent that this KeyEvent is wrapping and "fixing". */ | |
| 25088 KeyboardEvent _parent; | |
| 25089 | |
| 25090 /** The "fixed" value of whether the alt key is being pressed. */ | |
| 25091 bool _shadowAltKey; | |
| 25092 | |
| 25093 /** Caculated value of what the estimated charCode is for this event. */ | |
| 25094 int _shadowCharCode; | |
| 25095 | |
| 25096 /** Caculated value of what the estimated keyCode is for this event. */ | |
| 25097 int _shadowKeyCode; | |
| 25098 | |
| 25099 /** Caculated value of what the estimated keyCode is for this event. */ | |
| 25100 int get keyCode => _shadowKeyCode; | |
| 25101 | |
| 25102 /** Caculated value of what the estimated charCode is for this event. */ | |
| 25103 int get charCode => this.type == 'keypress' ? _shadowCharCode : 0; | |
| 25104 | |
| 25105 /** Caculated value of whether the alt key is pressed is for this event. */ | |
| 25106 bool get altKey => _shadowAltKey; | |
| 25107 | |
| 25108 /** Caculated value of what the estimated keyCode is for this event. */ | |
| 25109 int get which => keyCode; | |
| 25110 | |
| 25111 /** Accessor to the underlying keyCode value is the parent event. */ | |
| 25112 int get _realKeyCode => JS('int', '#.keyCode', _parent); | |
| 25113 | |
| 25114 /** Accessor to the underlying charCode value is the parent event. */ | |
| 25115 int get _realCharCode => JS('int', '#.charCode', _parent); | |
| 25116 | |
| 25117 /** Accessor to the underlying altKey value is the parent event. */ | |
| 25118 bool get _realAltKey => JS('int', '#.altKey', _parent); | |
| 25119 | |
| 25120 /** Construct a KeyEvent with [parent] as event we're emulating. */ | |
| 25121 KeyEvent(KeyboardEvent parent) { | |
| 25122 _parent = parent; | |
| 25123 _shadowAltKey = _realAltKey; | |
| 25124 _shadowCharCode = _realCharCode; | |
| 25125 _shadowKeyCode = _realKeyCode; | |
| 25126 } | |
| 25127 | |
| 25128 /** | |
| 25129 * Catch-all to behave for all other methods not defined here just like the | |
| 25130 * _parent. | |
| 25131 */ | |
| 25132 void noSuchMethod(InvocationMirror invocation) { | |
| 25133 invocation.invokeOn(_parent); | |
| 25134 } | |
| 25135 | |
| 25136 // ----------------------------------------------------------------------- | |
| 25137 // This code duplication is unfortunate... It's like this because dart2js | |
| 25138 // generates code accessing fields like KeyEvent.bubbles as | |
| 25139 // KeyEvent.get$bubbles, which without these getters, would hit noSuchMethod, | |
| 25140 // and try to call get$bubbles on KeyBoardEvent, which just has a bubbles | |
| 25141 // field, not a get$bubbles. | |
| 25142 /** True if the altGraphKey is pressed during this event. */ | |
| 25143 bool get altGraphKey => _parent.altGraphKey; | |
| 25144 bool get bubbles => _parent.bubbles; | |
| 25145 /** True if this event can be cancelled. */ | |
| 25146 bool get cancelable => _parent.cancelable; | |
| 25147 bool get cancelBubble => _parent.cancelBubble; | |
| 25148 /** Accessor to the clipboardData available for this event. */ | |
| 25149 Clipboard get clipboardData => _parent.clipboardData; | |
| 25150 /** True if the ctrl key is pressed during this event. */ | |
| 25151 bool get ctrlKey => _parent.ctrlKey; | |
| 25152 /** Accessor to the target this event is listening to for changes. */ | |
| 25153 EventTarget get currentTarget => _parent.currentTarget; | |
| 25154 bool get defaultPrevented => _parent.defaultPrevented; | |
| 25155 int get detail => _parent.detail; | |
| 25156 int get eventPhase => _parent.eventPhase; | |
| 25157 /** | |
| 25158 * Accessor to the part of the keyboard that the key was pressed from (one of | |
| 25159 * KeyLocation.STANDARD, KeyLocation.RIGHT, KeyLocation.LEFT, | |
| 25160 * KeyLocation.NUMPAD, KeyLocation.MOBILE, KeyLocation.JOYSTICK). | |
| 25161 */ | |
| 25162 int get keyLocation => _parent.keyLocation; | |
| 25163 int get layerX => _parent.layerX; | |
| 25164 int get layerY => _parent.layerY; | |
| 25165 /** True if the Meta (or Mac command) key is pressed during this event. */ | |
| 25166 bool get metaKey => _parent.metaKey; | |
| 25167 int get pageX => _parent.pageX; | |
| 25168 int get pageY => _parent.pageY; | |
| 25169 bool get returnValue => _parent.returnValue; | |
| 25170 /** True if the shift key was pressed during this event. */ | |
| 25171 bool get shiftKey => _parent.shiftKey; | |
| 25172 int get timeStamp => _parent.timeStamp; | |
| 25173 /** | |
| 25174 * The type of key event that occurred. One of "keydown", "keyup", or | |
| 25175 * "keypress". | |
| 25176 */ | |
| 25177 String get type => _parent.type; | |
| 25178 Window get view => _parent.view; | |
| 25179 String get _shadowKeyIdentifier => JS('String', '#.keyIdentifier', _parent); | |
| 25180 } | |
| 24681 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 25181 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 
| 24682 // for details. All rights reserved. Use of this source code is governed by a | 25182 // for details. All rights reserved. Use of this source code is governed by a | 
| 24683 // BSD-style license that can be found in the LICENSE file. | 25183 // BSD-style license that can be found in the LICENSE file. | 
| 24684 | 25184 | 
| 24685 | 25185 | 
| 24686 class _AudioContextFactoryProvider { | 25186 class _AudioContextFactoryProvider { | 
| 24687 | 25187 | 
| 24688 static AudioContext createAudioContext() { | 25188 static AudioContext createAudioContext() { | 
| 24689 return JS('AudioContext', | 25189 return JS('AudioContext', | 
| 24690 'new (window.AudioContext || window.webkitAudioContext)()'); | 25190 'new (window.AudioContext || window.webkitAudioContext)()'); | 
| (...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 25114 if (length < 0) throw new ArgumentError('length'); | 25614 if (length < 0) throw new ArgumentError('length'); | 
| 25115 if (start < 0) throw new RangeError.value(start); | 25615 if (start < 0) throw new RangeError.value(start); | 
| 25116 int end = start + length; | 25616 int end = start + length; | 
| 25117 if (end > a.length) throw new RangeError.value(end); | 25617 if (end > a.length) throw new RangeError.value(end); | 
| 25118 for (int i = start; i < end; i++) { | 25618 for (int i = start; i < end; i++) { | 
| 25119 accumulator.add(a[i]); | 25619 accumulator.add(a[i]); | 
| 25120 } | 25620 } | 
| 25121 return accumulator; | 25621 return accumulator; | 
| 25122 } | 25622 } | 
| 25123 } | 25623 } | 
| OLD | NEW |