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 6430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6441 | 6441 |
6442 /// @domName DirectoryReaderSync.readEntries; @docsEditable true | 6442 /// @domName DirectoryReaderSync.readEntries; @docsEditable true |
6443 @Returns('_EntryArraySync') @Creates('_EntryArraySync') | 6443 @Returns('_EntryArraySync') @Creates('_EntryArraySync') |
6444 List<EntrySync> readEntries() native; | 6444 List<EntrySync> readEntries() native; |
6445 } | 6445 } |
6446 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 6446 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
6447 // for details. All rights reserved. Use of this source code is governed by a | 6447 // for details. All rights reserved. Use of this source code is governed by a |
6448 // BSD-style license that can be found in the LICENSE file. | 6448 // BSD-style license that can be found in the LICENSE file. |
6449 | 6449 |
6450 | 6450 |
6451 /** | |
6452 * Represents an HTML <div> element. | |
6453 * | |
6454 * The [DivElement] is a generic container for content and does not have any | |
6455 * special significance. It is functionally similar to [SpanElement]. | |
6456 * | |
6457 * The [DivElement] is a block-level element, as opposed to [SpanElement], | |
6458 * which is an inline-level element. | |
6459 * | |
6460 * Example usage: | |
6461 * | |
6462 * DivElement div = new DivElement(); | |
6463 * div.text = 'Here's my new DivElem | |
6464 * document.body.elements.add(elem); | |
6465 * | |
6466 * See also: | |
6467 * | |
6468 * * [HTML <div> element](http://www.w3.org/TR/html-markup/div.html) from W3C. | |
6469 * * [Block-level element](http://www.w3.org/TR/CSS2/visuren.html#block-boxes) f
rom W3C. | |
6470 * * [Inline-level element](http://www.w3.org/TR/CSS2/visuren.html#inline-boxes)
from W3C. | |
6471 */ | |
6472 /// @domName HTMLDivElement; @docsEditable true | 6451 /// @domName HTMLDivElement; @docsEditable true |
6473 class DivElement extends Element implements Element native "*HTMLDivElement" { | 6452 class DivElement extends Element implements Element native "*HTMLDivElement" { |
6474 | 6453 |
6475 factory DivElement() => document.$dom_createElement("div"); | 6454 factory DivElement() => document.$dom_createElement("div"); |
6476 } | 6455 } |
6477 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 6456 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
6478 // for details. All rights reserved. Use of this source code is governed by a | 6457 // for details. All rights reserved. Use of this source code is governed by a |
6479 // BSD-style license that can be found in the LICENSE file. | 6458 // BSD-style license that can be found in the LICENSE file. |
6480 | 6459 |
6481 | 6460 |
(...skipping 4911 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11393 int scopeType(int scopeIndex) native; | 11372 int scopeType(int scopeIndex) native; |
11394 } | 11373 } |
11395 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 11374 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
11396 // for details. All rights reserved. Use of this source code is governed by a | 11375 // for details. All rights reserved. Use of this source code is governed by a |
11397 // BSD-style license that can be found in the LICENSE file. | 11376 // BSD-style license that can be found in the LICENSE file. |
11398 | 11377 |
11399 | 11378 |
11400 /// @domName KeyboardEvent; @docsEditable true | 11379 /// @domName KeyboardEvent; @docsEditable true |
11401 class KeyboardEvent extends UIEvent native "*KeyboardEvent" { | 11380 class KeyboardEvent extends UIEvent native "*KeyboardEvent" { |
11402 | 11381 |
| 11382 factory KeyboardEvent(String type, Window view, |
| 11383 [bool canBubble = true, bool cancelable = true, |
| 11384 String keyIdentifier = null, int keyLocation = 1, bool ctrlKey = false, |
| 11385 bool altKey = false, bool shiftKey = false, bool metaKey = false, |
| 11386 bool altGraphKey = false]) { |
| 11387 final e = document.$dom_createEvent("KeyboardEvent"); |
| 11388 e.$dom_initKeyboardEvent(type, canBubble, cancelable, view, keyIdentifier, |
| 11389 keyLocation, ctrlKey, altKey, shiftKey, metaKey, altGraphKey); |
| 11390 return e; |
| 11391 } |
| 11392 |
| 11393 /** @domName KeyboardEvent.initKeyboardEvent */ |
| 11394 void $dom_initKeyboardEvent(String type, bool canBubble, bool cancelable, |
| 11395 LocalWindow view, String keyIdentifier, int keyLocation, bool ctrlKey, |
| 11396 bool altKey, bool shiftKey, bool metaKey, bool altGraphKey) { |
| 11397 var function = JS('dynamic', '#.initKeyboardEvent || #.initKeyEvent', this, |
| 11398 this); |
| 11399 JS('void', '#(#, #, #, #, #, #, #, #, #, #, #)', function, type, |
| 11400 canBubble, cancelable, view, keyIdentifier, keyLocation, ctrlKey, |
| 11401 altKey, shiftKey, metaKey, altGraphKey); |
| 11402 } |
| 11403 |
| 11404 /** @domName KeyboardEvent.keyCode */ |
| 11405 int get keyCode => $dom_keyCode; |
| 11406 |
| 11407 /** @domName KeyboardEvent.charCode */ |
| 11408 int get charCode => $dom_charCode; |
| 11409 |
11403 /// @domName KeyboardEvent.altGraphKey; @docsEditable true | 11410 /// @domName KeyboardEvent.altGraphKey; @docsEditable true |
11404 final bool altGraphKey; | 11411 final bool altGraphKey; |
11405 | 11412 |
11406 /// @domName KeyboardEvent.altKey; @docsEditable true | 11413 /// @domName KeyboardEvent.altKey; @docsEditable true |
11407 final bool altKey; | 11414 final bool altKey; |
11408 | 11415 |
11409 /// @domName KeyboardEvent.ctrlKey; @docsEditable true | 11416 /// @domName KeyboardEvent.ctrlKey; @docsEditable true |
11410 final bool ctrlKey; | 11417 final bool ctrlKey; |
11411 | 11418 |
11412 /// @domName KeyboardEvent.keyIdentifier; @docsEditable true | 11419 /// @domName KeyboardEvent.keyIdentifier; @docsEditable true |
11413 final String keyIdentifier; | 11420 String get $dom_keyIdentifier => JS("String", "#.keyIdentifier", this); |
11414 | 11421 |
11415 /// @domName KeyboardEvent.keyLocation; @docsEditable true | 11422 /// @domName KeyboardEvent.keyLocation; @docsEditable true |
11416 final int keyLocation; | 11423 final int keyLocation; |
11417 | 11424 |
11418 /// @domName KeyboardEvent.metaKey; @docsEditable true | 11425 /// @domName KeyboardEvent.metaKey; @docsEditable true |
11419 final bool metaKey; | 11426 final bool metaKey; |
11420 | 11427 |
11421 /// @domName KeyboardEvent.shiftKey; @docsEditable true | 11428 /// @domName KeyboardEvent.shiftKey; @docsEditable true |
11422 final bool shiftKey; | 11429 final bool shiftKey; |
11423 | 11430 |
11424 /// @domName KeyboardEvent.initKeyboardEvent; @docsEditable true | |
11425 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; | |
11426 } | 11431 } |
11427 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 11432 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
11428 // for details. All rights reserved. Use of this source code is governed by a | 11433 // for details. All rights reserved. Use of this source code is governed by a |
11429 // BSD-style license that can be found in the LICENSE file. | 11434 // BSD-style license that can be found in the LICENSE file. |
11430 | 11435 |
11431 | 11436 |
11432 /// @domName HTMLKeygenElement; @docsEditable true | 11437 /// @domName HTMLKeygenElement; @docsEditable true |
11433 class KeygenElement extends Element implements Element native "*HTMLKeygenElemen
t" { | 11438 class KeygenElement extends Element implements Element native "*HTMLKeygenElemen
t" { |
11434 | 11439 |
11435 factory KeygenElement() => document.$dom_createElement("keygen"); | 11440 factory KeygenElement() => document.$dom_createElement("keygen"); |
(...skipping 1475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12911 final int totalJSHeapSize; | 12916 final int totalJSHeapSize; |
12912 | 12917 |
12913 /// @domName MemoryInfo.usedJSHeapSize; @docsEditable true | 12918 /// @domName MemoryInfo.usedJSHeapSize; @docsEditable true |
12914 final int usedJSHeapSize; | 12919 final int usedJSHeapSize; |
12915 } | 12920 } |
12916 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 12921 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
12917 // for details. All rights reserved. Use of this source code is governed by a | 12922 // for details. All rights reserved. Use of this source code is governed by a |
12918 // BSD-style license that can be found in the LICENSE file. | 12923 // BSD-style license that can be found in the LICENSE file. |
12919 | 12924 |
12920 | 12925 |
12921 /** | |
12922 * An HTML <menu> element. | |
12923 * | |
12924 * A <menu> element represents an unordered list of menu commands. | |
12925 * | |
12926 * See also: | |
12927 * | |
12928 * * [Menu Element](https://developer.mozilla.org/en-US/docs/HTML/Element/menu)
from MDN. | |
12929 * * [Menu Element](http://www.w3.org/TR/html5/the-menu-element.html#the-menu-e
lement) from the W3C. | |
12930 */ | |
12931 /// @domName HTMLMenuElement; @docsEditable true | 12926 /// @domName HTMLMenuElement; @docsEditable true |
12932 class MenuElement extends Element implements Element native "*HTMLMenuElement" { | 12927 class MenuElement extends Element implements Element native "*HTMLMenuElement" { |
12933 | 12928 |
12934 factory MenuElement() => document.$dom_createElement("menu"); | 12929 factory MenuElement() => document.$dom_createElement("menu"); |
12935 } | 12930 } |
12936 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 12931 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
12937 // for details. All rights reserved. Use of this source code is governed by a | 12932 // for details. All rights reserved. Use of this source code is governed by a |
12938 // BSD-style license that can be found in the LICENSE file. | 12933 // BSD-style license that can be found in the LICENSE file. |
12939 | 12934 |
12940 | 12935 |
(...skipping 4824 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
17765 /// @domName TreeWalker.previousNode; @docsEditable true | 17760 /// @domName TreeWalker.previousNode; @docsEditable true |
17766 Node previousNode() native; | 17761 Node previousNode() native; |
17767 | 17762 |
17768 /// @domName TreeWalker.previousSibling; @docsEditable true | 17763 /// @domName TreeWalker.previousSibling; @docsEditable true |
17769 Node previousSibling() native; | 17764 Node previousSibling() native; |
17770 } | 17765 } |
17771 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 17766 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
17772 // for details. All rights reserved. Use of this source code is governed by a | 17767 // for details. All rights reserved. Use of this source code is governed by a |
17773 // BSD-style license that can be found in the LICENSE file. | 17768 // BSD-style license that can be found in the LICENSE file. |
17774 | 17769 |
| 17770 // WARNING: Do not edit - generated code. |
| 17771 |
17775 | 17772 |
17776 /// @domName UIEvent; @docsEditable true | 17773 /// @domName UIEvent; @docsEditable true |
17777 class UIEvent extends Event native "*UIEvent" { | 17774 class UIEvent extends Event native "*UIEvent" { |
| 17775 // In JS, canBubble and cancelable are technically required parameters to |
| 17776 // init*Event. In practice, though, if they aren't provided they simply |
| 17777 // default to false (since that's Boolean(undefined)). |
| 17778 // |
| 17779 // Contrary to JS, we default canBubble and cancelable to true, since that's |
| 17780 // what people want most of the time anyway. |
| 17781 factory UIEvent(String type, Window view, int detail, |
| 17782 [bool canBubble = true, bool cancelable = true]) { |
| 17783 final e = document.$dom_createEvent("UIEvent"); |
| 17784 e.$dom_initUIEvent(type, canBubble, cancelable, view, detail); |
| 17785 return e; |
| 17786 } |
17778 | 17787 |
17779 /// @domName UIEvent.charCode; @docsEditable true | 17788 /// @domName UIEvent.charCode; @docsEditable true |
17780 final int charCode; | 17789 int get $dom_charCode => JS("int", "#.charCode", this); |
17781 | 17790 |
17782 /// @domName UIEvent.detail; @docsEditable true | 17791 /// @domName UIEvent.detail; @docsEditable true |
17783 final int detail; | 17792 final int detail; |
17784 | 17793 |
17785 /// @domName UIEvent.keyCode; @docsEditable true | 17794 /// @domName UIEvent.keyCode; @docsEditable true |
17786 final int keyCode; | 17795 int get $dom_keyCode => JS("int", "#.keyCode", this); |
17787 | 17796 |
17788 /// @domName UIEvent.layerX; @docsEditable true | 17797 /// @domName UIEvent.layerX; @docsEditable true |
17789 final int layerX; | 17798 final int layerX; |
17790 | 17799 |
17791 /// @domName UIEvent.layerY; @docsEditable true | 17800 /// @domName UIEvent.layerY; @docsEditable true |
17792 final int layerY; | 17801 final int layerY; |
17793 | 17802 |
17794 /// @domName UIEvent.pageX; @docsEditable true | 17803 /// @domName UIEvent.pageX; @docsEditable true |
17795 final int pageX; | 17804 final int pageX; |
17796 | 17805 |
17797 /// @domName UIEvent.pageY; @docsEditable true | 17806 /// @domName UIEvent.pageY; @docsEditable true |
17798 final int pageY; | 17807 final int pageY; |
17799 | 17808 |
17800 /// @domName UIEvent.view; @docsEditable true | 17809 /// @domName UIEvent.view; @docsEditable true |
17801 Window get view => _convertNativeToDart_Window(this._view); | 17810 Window get view => _convertNativeToDart_Window(this._view); |
17802 dynamic get _view => JS("dynamic", "#.view", this); | 17811 dynamic get _view => JS("dynamic", "#.view", this); |
17803 | 17812 |
17804 /// @domName UIEvent.which; @docsEditable true | 17813 /// @domName UIEvent.which; @docsEditable true |
17805 final int which; | 17814 final int which; |
17806 | 17815 |
17807 /// @domName UIEvent.initUIEvent; @docsEditable true | 17816 /// @domName UIEvent.initUIEvent; @docsEditable true |
17808 void initUIEvent(String type, bool canBubble, bool cancelable, LocalWindow vie
w, int detail) native; | 17817 void $dom_initUIEvent(String type, bool canBubble, bool cancelable, LocalWindo
w view, int detail) native "initUIEvent"; |
| 17818 |
17809 } | 17819 } |
17810 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 17820 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
17811 // for details. All rights reserved. Use of this source code is governed by a | 17821 // for details. All rights reserved. Use of this source code is governed by a |
17812 // BSD-style license that can be found in the LICENSE file. | 17822 // BSD-style license that can be found in the LICENSE file. |
17813 | 17823 |
17814 | 17824 |
17815 /// @domName HTMLUListElement; @docsEditable true | 17825 /// @domName HTMLUListElement; @docsEditable true |
17816 class UListElement extends Element implements Element native "*HTMLUListElement"
{ | 17826 class UListElement extends Element implements Element native "*HTMLUListElement"
{ |
17817 | 17827 |
17818 factory UListElement() => document.$dom_createElement("ul"); | 17828 factory UListElement() => document.$dom_createElement("ul"); |
(...skipping 4768 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
22587 Element get first => _filtered.first; | 22597 Element get first => _filtered.first; |
22588 | 22598 |
22589 Element get last => _filtered.last; | 22599 Element get last => _filtered.last; |
22590 } | 22600 } |
22591 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 22601 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
22592 // for details. All rights reserved. Use of this source code is governed by a | 22602 // for details. All rights reserved. Use of this source code is governed by a |
22593 // BSD-style license that can be found in the LICENSE file. | 22603 // BSD-style license that can be found in the LICENSE file. |
22594 | 22604 |
22595 | 22605 |
22596 /** | 22606 /** |
| 22607 * Works with KeyboardEvent and KeyEvent to determine how to expose information |
| 22608 * about Key(board)Events. This class functions like an EventListenerList, and |
| 22609 * provides a consistent interface for the Dart |
| 22610 * user, despite the fact that a multitude of browsers that have varying |
| 22611 * keyboard default behavior. |
| 22612 * |
| 22613 * This class is very much a work in progress, and we'd love to get information |
| 22614 * on how we can make this class work with as many international keyboards as |
| 22615 * possible. Bugs welcome! |
| 22616 */ |
| 22617 class KeyboardEventController { |
| 22618 // This code inspired by Closure's KeyHandling library. |
| 22619 // http://closure-library.googlecode.com/svn/docs/closure_goog_events_keyhandl
er.js.source.html |
| 22620 |
| 22621 /** |
| 22622 * The set of keys that have been pressed down without seeing their |
| 22623 * corresponding keyup event. |
| 22624 */ |
| 22625 List<KeyboardEvent> keyDownList; |
| 22626 |
| 22627 /** The set of functions that wish to be notified when a KeyEvent happens. */ |
| 22628 List<Function> _callbacks; |
| 22629 |
| 22630 /** The type of KeyEvent we are tracking (keyup, keydown, keypress). */ |
| 22631 String _type; |
| 22632 |
| 22633 // The distance to shift from upper case alphabet Roman letters to lower case. |
| 22634 const int _ROMAN_ALPHABET_OFFSET = "a".charCodes[0] - "A".charCodes[0]; |
| 22635 |
| 22636 /** |
| 22637 * An enumeration of key identifiers currently part of the W3C draft for DOM3 |
| 22638 * and their mappings to keyCodes. |
| 22639 * http://www.w3.org/TR/DOM-Level-3-Events/keyset.html#KeySet-Set |
| 22640 */ |
| 22641 static Map<String, int> _keyIdentifier = { |
| 22642 'Up': KeyCode.UP, |
| 22643 'Down': KeyCode.DOWN, |
| 22644 'Left': KeyCode.LEFT, |
| 22645 'Right': KeyCode.RIGHT, |
| 22646 'Enter': KeyCode.ENTER, |
| 22647 'F1': KeyCode.F1, |
| 22648 'F2': KeyCode.F2, |
| 22649 'F3': KeyCode.F3, |
| 22650 'F4': KeyCode.F4, |
| 22651 'F5': KeyCode.F5, |
| 22652 'F6': KeyCode.F6, |
| 22653 'F7': KeyCode.F7, |
| 22654 'F8': KeyCode.F8, |
| 22655 'F9': KeyCode.F9, |
| 22656 'F10': KeyCode.F10, |
| 22657 'F11': KeyCode.F11, |
| 22658 'F12': KeyCode.F12, |
| 22659 'U+007F': KeyCode.DELETE, |
| 22660 'Home': KeyCode.HOME, |
| 22661 'End': KeyCode.END, |
| 22662 'PageUp': KeyCode.PAGE_UP, |
| 22663 'PageDown': KeyCode.PAGE_DOWN, |
| 22664 'Insert': KeyCode.INSERT |
| 22665 }; |
| 22666 |
| 22667 /** Named constructor to add an onKeyPress event listener to our handler. */ |
| 22668 KeyboardEventController.keypress(EventTarget target) { |
| 22669 _KeyboardEventController(target, 'keypress'); |
| 22670 } |
| 22671 |
| 22672 /** Named constructor to add an onKeyUp event listener to our handler. */ |
| 22673 KeyboardEventController.keyup(EventTarget target) { |
| 22674 _KeyboardEventController(target, 'keyup'); |
| 22675 } |
| 22676 |
| 22677 /** Named constructor to add an onKeyDown event listener to our handler. */ |
| 22678 KeyboardEventController.keydown(EventTarget target) { |
| 22679 _KeyboardEventController(target, 'keydown'); |
| 22680 } |
| 22681 |
| 22682 /** |
| 22683 * General constructor, performs basic initialization for our improved |
| 22684 * KeyboardEvent controller. |
| 22685 */ |
| 22686 _KeyboardEventController(EventTarget target, String type) { |
| 22687 keyDownList = []; |
| 22688 _callbacks = []; |
| 22689 _type = type; |
| 22690 target.on.keyDown.add(processKeyDown, true); |
| 22691 target.on.keyPress.add(processKeyPress, true); |
| 22692 target.on.keyUp.add(processKeyUp, true); |
| 22693 } |
| 22694 |
| 22695 /** Add a callback that wishes to be notified when a KeyEvent occurs. */ |
| 22696 void add(void callback(KeyEvent)) { |
| 22697 _callbacks.add(callback); |
| 22698 } |
| 22699 |
| 22700 /** |
| 22701 * Notify all callback listeners that a KeyEvent of the relevant type has |
| 22702 * occurred. |
| 22703 */ |
| 22704 bool _dispatch(KeyEvent event) { |
| 22705 if (event.type == _type) { |
| 22706 for(var callback in _callbacks) { |
| 22707 callback(event); |
| 22708 } |
| 22709 } |
| 22710 } |
| 22711 |
| 22712 /** Remove the given callback from the listeners list. */ |
| 22713 void remove(void callback(KeyEvent)) { |
| 22714 var i = 0; |
| 22715 for (i = 0; i < _callbacks.length; i++) { |
| 22716 if (_callbacks[i] == callback) break; |
| 22717 } |
| 22718 if (i < _callbacks.length) _callbacks.removeAt(i); |
| 22719 } |
| 22720 |
| 22721 /** Determine if caps lock is one of the currently depressed keys. */ |
| 22722 bool get _capsLockOn() => |
| 22723 keyDownList.some((var element) => element.keyCode == KeyCode.CAPS_LOCK); |
| 22724 |
| 22725 /** |
| 22726 * Given the previously recorded keydown key codes, see if we can determine |
| 22727 * the keycode of this keypress [event]. (Generally browsers only provide |
| 22728 * charCode information for keypress events, but with a little |
| 22729 * reverse-engineering, we can also determine the keyCode.) Returns |
| 22730 * KeyCode.UNKNOWN if the keycode could not be determined. |
| 22731 */ |
| 22732 int _determineKeyCodeForKeypress(KeyboardEvent event) { |
| 22733 // Note: This function is a work in progress. We'll expand this function |
| 22734 // once we get more information about other keyboards. |
| 22735 for (var prevEvent in keyDownList) { |
| 22736 if (prevEvent._shadowCharCode == event.charCode) { |
| 22737 return prevEvent.keyCode; |
| 22738 } |
| 22739 if ((event.shiftKey || _capsLockOn) && event.charCode >= "A".charCodes[0] |
| 22740 && event.charCode <= "Z".charCodes[0] && event.charCode + |
| 22741 _ROMAN_ALPHABET_OFFSET == prevEvent._shadowCharCode) { |
| 22742 return prevEvent.keyCode; |
| 22743 } |
| 22744 } |
| 22745 return KeyCode.UNKNOWN; |
| 22746 } |
| 22747 |
| 22748 /** |
| 22749 * Given the charater code returned from a keyDown [event], try to ascertain |
| 22750 * and return the corresponding charCode for the character that was pressed. |
| 22751 * This information is not shown to the user, but used to help polyfill |
| 22752 * keypress events. |
| 22753 */ |
| 22754 int _findCharCodeKeyDown(KeyboardEvent event) { |
| 22755 if (event.keyLocation == 3) { // Numpad keys. |
| 22756 switch (event.keyCode) { |
| 22757 case KeyCode.NUM_ZERO: |
| 22758 // Even though this function returns _charCodes_, for some cases the |
| 22759 // KeyCode == the charCode we want, in which case we use the keycode |
| 22760 // constant for readability. |
| 22761 return KeyCode.ZERO; |
| 22762 case KeyCode.NUM_ONE: |
| 22763 return KeyCode.ONE; |
| 22764 case KeyCode.NUM_TWO: |
| 22765 return KeyCode.TWO; |
| 22766 case KeyCode.NUM_THREE: |
| 22767 return KeyCode.THREE; |
| 22768 case KeyCode.NUM_FOUR: |
| 22769 return KeyCode.FOUR; |
| 22770 case KeyCode.NUM_FIVE: |
| 22771 return KeyCode.FIVE; |
| 22772 case KeyCode.NUM_SIX: |
| 22773 return KeyCode.SIX; |
| 22774 case KeyCode.NUM_SEVEN: |
| 22775 return KeyCode.SEVEN; |
| 22776 case KeyCode.NUM_EIGHT: |
| 22777 return KeyCode.EIGHT; |
| 22778 case KeyCode.NUM_NINE: |
| 22779 return KeyCode.NINE; |
| 22780 case KeyCode.NUM_MULTIPLY: |
| 22781 return 42; // Char code for * |
| 22782 case KeyCode.NUM_PLUS: |
| 22783 return 43; // + |
| 22784 case KeyCode.NUM_MINUS: |
| 22785 return 45; // - |
| 22786 case KeyCode.NUM_PERIOD: |
| 22787 return 46; // . |
| 22788 case KeyCode.NUM_DIVISION: |
| 22789 return 47; // / |
| 22790 } |
| 22791 } else if (event.keyCode >= 65 && event.keyCode <= 90) { |
| 22792 // Set the "char code" for key down as the lower case letter. Again, this |
| 22793 // will not show up for the user, but will be helpful in estimating |
| 22794 // keyCode locations and other information during the keyPress event. |
| 22795 return event.keyCode + _ROMAN_ALPHABET_OFFSET; |
| 22796 } |
| 22797 switch(event.keyCode) { |
| 22798 case KeyCode.SEMICOLON: |
| 22799 return KeyCode.FF_SEMICOLON; |
| 22800 case KeyCode.EQUALS: |
| 22801 return KeyCode.FF_EQUALS; |
| 22802 case KeyCode.COMMA: |
| 22803 return 44; // Ascii value for , |
| 22804 case KeyCode.DASH: |
| 22805 return 45; // - |
| 22806 case KeyCode.PERIOD: |
| 22807 return 46; // . |
| 22808 case KeyCode.SLASH: |
| 22809 return 47; // / |
| 22810 case KeyCode.APOSTROPHE: |
| 22811 return 96; // ` |
| 22812 case KeyCode.OPEN_SQUARE_BRACKET: |
| 22813 return 91; // [ |
| 22814 case KeyCode.BACKSLASH: |
| 22815 return 92; // \ |
| 22816 case KeyCode.CLOSE_SQUARE_BRACKET: |
| 22817 return 93; // ] |
| 22818 case KeyCode.SINGLE_QUOTE: |
| 22819 return 39; // ' |
| 22820 } |
| 22821 return event.keyCode; |
| 22822 } |
| 22823 |
| 22824 /** |
| 22825 * Returns true if the key fires a keypress event in the current browser. |
| 22826 */ |
| 22827 bool _firesKeyPressEvent(KeyEvent event) { |
| 22828 if (!_Device.isIE && !_Device.isWebKit) { |
| 22829 return true; |
| 22830 } |
| 22831 |
| 22832 if (_Device.userAgent.contains('Mac') && event.altKey) { |
| 22833 return KeyCode.isCharacterKey(event.keyCode); |
| 22834 } |
| 22835 |
| 22836 // Alt but not AltGr which is represented as Alt+Ctrl. |
| 22837 if (event.altKey && !event.ctrlKey) { |
| 22838 return false; |
| 22839 } |
| 22840 |
| 22841 // Saves Ctrl or Alt + key for IE and WebKit, which won't fire keypress. |
| 22842 if (!event.shiftKey && |
| 22843 (keyDownList.last.keyCode == KeyCode.CTRL || |
| 22844 keyDownList.last.keyCode == KeyCode.ALT || |
| 22845 _Device.userAgent.contains('Mac') && |
| 22846 keyDownList.last.keyCode == KeyCode.META)) { |
| 22847 return false; |
| 22848 } |
| 22849 |
| 22850 // Some keys with Ctrl/Shift do not issue keypress in WebKit. |
| 22851 if (_Device.isWebKit && event.ctrlKey && event.shiftKey && ( |
| 22852 event.keycode == KeyCode.BACKSLASH || |
| 22853 event.keycode == KeyCode.OPEN_SQUARE_BRACKET || |
| 22854 event.keycode == KeyCode.CLOSE_SQUARE_BRACKET || |
| 22855 event.keycode == KeyCode.TILDE || |
| 22856 event.keycode == KeyCode.SEMICOLON || event.keycode == KeyCode.DASH || |
| 22857 event.keycode == KeyCode.EQUALS || event.keycode == KeyCode.COMMA || |
| 22858 event.keycode == KeyCode.PERIOD || event.keycode == KeyCode.SLASH || |
| 22859 event.keycode == KeyCode.APOSTROPHE || |
| 22860 event.keycode == KeyCode.SINGLE_QUOTE)) { |
| 22861 return false; |
| 22862 } |
| 22863 |
| 22864 switch (event.keyCode) { |
| 22865 case KeyCode.ENTER: |
| 22866 // IE9 does not fire keypress on ENTER. |
| 22867 return !_Device.isIE; |
| 22868 case KeyCode.ESC: |
| 22869 return !_Device.isWebKit; |
| 22870 } |
| 22871 |
| 22872 return KeyCode.isCharacterKey(event.keyCode); |
| 22873 } |
| 22874 |
| 22875 /** |
| 22876 * Normalize the keycodes to the IE KeyCodes (this is what Chrome, IE, and |
| 22877 * Opera all use). |
| 22878 */ |
| 22879 int normalizeKeyCodes(KeyboardEvent event) { |
| 22880 // Note: This may change once we get input about non-US keyboards. |
| 22881 if (_Device.isFirefox) { |
| 22882 switch(event.keyCode) { |
| 22883 case KeyCode.FF_EQUALS: |
| 22884 return KeyCode.EQUALS; |
| 22885 case KeyCode.FF_SEMICOLON: |
| 22886 return KeyCode.SEMICOLON; |
| 22887 case KeyCode.MAC_FF_META: |
| 22888 return KeyCode.META; |
| 22889 case KeyCode.WIN_KEY_FF_LINUX: |
| 22890 return KeyCode.WIN_KEY; |
| 22891 } |
| 22892 } |
| 22893 return event.keyCode; |
| 22894 } |
| 22895 |
| 22896 /** Handle keydown events. */ |
| 22897 void processKeyDown(KeyboardEvent e) { |
| 22898 // Ctrl-Tab and Alt-Tab can cause the focus to be moved to another window |
| 22899 // before we've caught a key-up event. If the last-key was one of these |
| 22900 // we reset the state. |
| 22901 if (keyDownList.length > 0 && |
| 22902 (keyDownList.last.keyCode == KeyCode.CTRL && !e.ctrlKey || |
| 22903 keyDownList.last.keyCode == KeyCode.ALT && !e.altKey || |
| 22904 _Device.userAgent.contains('Mac') && |
| 22905 keyDownList.last.keyCode == KeyCode.META && !e.metaKey)) { |
| 22906 keyDownList = []; |
| 22907 } |
| 22908 |
| 22909 var event = new KeyEvent(e); |
| 22910 event._shadowKeyCode = normalizeKeyCodes(event); |
| 22911 // Technically a "keydown" event doesn't have a charCode. This is |
| 22912 // calculated nonetheless to provide us with more information in giving |
| 22913 // as much information as possible on keypress about keycode and also |
| 22914 // charCode. |
| 22915 event._shadowCharCode = _findCharCodeKeyDown(event); |
| 22916 if (keyDownList.length > 0 && event.keyCode != keyDownList.last.keyCode && |
| 22917 !_firesKeyPressEvent(event)) { |
| 22918 // Some browsers have quirks not firing keypress events where all other |
| 22919 // browsers do. This makes them more consistent. |
| 22920 processKeyPress(event); |
| 22921 } |
| 22922 keyDownList.add(event); |
| 22923 _dispatch(event); |
| 22924 } |
| 22925 |
| 22926 /** Handle keypress events. */ |
| 22927 void processKeyPress(KeyboardEvent event) { |
| 22928 var e = new KeyEvent(event); |
| 22929 // IE reports the character code in the keyCode field for keypress events. |
| 22930 // There are two exceptions however, Enter and Escape. |
| 22931 if (_Device.isIE) { |
| 22932 if (e.keyCode == KeyCode.ENTER || e.keyCode == KeyCode.ESC) { |
| 22933 e._shadowCharCode = 0; |
| 22934 } else { |
| 22935 e._shadowCharCode = e.keyCode; |
| 22936 } |
| 22937 } else if (_Device.isOpera) { |
| 22938 // Opera reports the character code in the keyCode field. |
| 22939 e._shadowCharCode = KeyCode.isCharacterKey(keyCode) ? e.keyCode : 0; |
| 22940 } |
| 22941 // Now we guestimate about what the keycode is that was actually |
| 22942 // pressed, given previous keydown information. |
| 22943 e._shadowKeyCode = _determineKeyCodeForKeypress(e); |
| 22944 |
| 22945 // Correct the key value for certain browser-specific quirks. |
| 22946 if (e._shadowKeyIdentifier && |
| 22947 _keyIdentifier.contains(e._shadowKeyIdentifier)) { |
| 22948 // This is needed for Safari Windows because it currently doesn't give a |
| 22949 // keyCode/which for non printable keys. |
| 22950 e._shadowKeyCode = _keyIdentifier[keyIdentifier]; |
| 22951 } |
| 22952 e._shadowAltKey = keyDownList.some((var element) => element.altKey); |
| 22953 _dispatch(e); |
| 22954 } |
| 22955 |
| 22956 /** Handle keyup events. */ |
| 22957 void processKeyUp(KeyboardEvent event) { |
| 22958 var e = new KeyEvent(event); |
| 22959 KeyboardEvent toRemove = null; |
| 22960 for (var key in keyDownList) { |
| 22961 if (key.keyCode == e.keyCode) { |
| 22962 toRemove = key; |
| 22963 } |
| 22964 } |
| 22965 if (toRemove != null) { |
| 22966 keyDownList = keyDownList.filter((element) => element != toRemove); |
| 22967 } else if (keyDownList.length > 0) { |
| 22968 // This happens when we've reached some international keyboard case we |
| 22969 // haven't accounted for or we haven't correctly eliminated all browser |
| 22970 // inconsistencies. Filing bugs on when this is reached is welcome! |
| 22971 keyDownList.removeLast(); |
| 22972 } |
| 22973 _dispatch(e); |
| 22974 } |
| 22975 } |
| 22976 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 22977 // for details. All rights reserved. Use of this source code is governed by a |
| 22978 // BSD-style license that can be found in the LICENSE file. |
| 22979 |
| 22980 |
| 22981 /** |
22597 * Defines the keycode values for keys that are returned by | 22982 * Defines the keycode values for keys that are returned by |
22598 * KeyboardEvent.keyCode. | 22983 * KeyboardEvent.keyCode. |
22599 * | 22984 * |
22600 * Important note: There is substantial divergence in how different browsers | 22985 * Important note: There is substantial divergence in how different browsers |
22601 * handle keycodes and their variants in different locales/keyboard layouts. We | 22986 * handle keycodes and their variants in different locales/keyboard layouts. We |
22602 * provide these constants to help make code processing keys more readable. | 22987 * provide these constants to help make code processing keys more readable. |
22603 */ | 22988 */ |
22604 abstract class KeyCode { | 22989 abstract class KeyCode { |
22605 // These constant names were borrowed from Closure's Keycode enumeration | 22990 // These constant names were borrowed from Closure's Keycode enumeration |
22606 // class. | 22991 // class. |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
22777 */ | 23162 */ |
22778 static const int BACKSLASH = 220; | 23163 static const int BACKSLASH = 220; |
22779 /** | 23164 /** |
22780 * CAUTION: This constant requires localization for other locales and keyboard | 23165 * CAUTION: This constant requires localization for other locales and keyboard |
22781 * layouts. | 23166 * layouts. |
22782 */ | 23167 */ |
22783 static const int CLOSE_SQUARE_BRACKET = 221; | 23168 static const int CLOSE_SQUARE_BRACKET = 221; |
22784 static const int WIN_KEY = 224; | 23169 static const int WIN_KEY = 224; |
22785 static const int MAC_FF_META = 224; | 23170 static const int MAC_FF_META = 224; |
22786 static const int WIN_IME = 229; | 23171 static const int WIN_IME = 229; |
| 23172 |
| 23173 /** A sentinel value if the keycode could not be determined. */ |
| 23174 static const int UNKNOWN = -1; |
| 23175 |
| 23176 /** |
| 23177 * Returns true if the keyCode produces a (US keyboard) character. |
| 23178 * Note: This does not (yet) cover characters on non-US keyboards (Russian, |
| 23179 * Hebrew, etc.). |
| 23180 */ |
| 23181 static bool isCharacterKey(int keyCode) { |
| 23182 if ((keyCode >= ZERO && keyCode <= NINE) || |
| 23183 (keyCode >= NUM_ZERO && keyCode <= NUM_MULTIPLY) || |
| 23184 (keyCode >= A && keyCode <= Z)) { |
| 23185 return true; |
| 23186 } |
| 23187 |
| 23188 // Safari sends zero key code for non-latin characters. |
| 23189 if (_Device.isWebKit && keyCode == 0) { |
| 23190 return true; |
| 23191 } |
| 23192 |
| 23193 return (keyCode == SPACE || keyCode == QUESTION_MARK || keyCode == NUM_PLUS |
| 23194 || keyCode == NUM_MINUS || keyCode == NUM_PERIOD || |
| 23195 keyCode == NUM_DIVISION || keyCode == SEMICOLON || |
| 23196 keyCode == FF_SEMICOLON || keyCode == DASH || keyCode == EQUALS || |
| 23197 keyCode == FF_EQUALS || keyCode == COMMA || keyCode == PERIOD || |
| 23198 keyCode == SLASH || keyCode == APOSTROPHE || keyCode == SINGLE_QUOTE || |
| 23199 keyCode == OPEN_SQUARE_BRACKET || keyCode == BACKSLASH || |
| 23200 keyCode == CLOSE_SQUARE_BRACKET); |
| 23201 } |
22787 } | 23202 } |
22788 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 23203 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
22789 // for details. All rights reserved. Use of this source code is governed by a | 23204 // for details. All rights reserved. Use of this source code is governed by a |
22790 // BSD-style license that can be found in the LICENSE file. | 23205 // BSD-style license that can be found in the LICENSE file. |
22791 | 23206 |
22792 | 23207 |
22793 /** | 23208 /** |
22794 * Defines the standard key locations returned by | 23209 * Defines the standard key locations returned by |
22795 * KeyboardEvent.getKeyLocation. | 23210 * KeyboardEvent.getKeyLocation. |
22796 */ | 23211 */ |
(...skipping 1913 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
24710 | 25125 |
24711 static History _createSafe(h) { | 25126 static History _createSafe(h) { |
24712 if (identical(h, window.history)) { | 25127 if (identical(h, window.history)) { |
24713 return h; | 25128 return h; |
24714 } else { | 25129 } else { |
24715 // TODO(vsm): Cache or implement equality. | 25130 // TODO(vsm): Cache or implement equality. |
24716 return new _HistoryCrossFrame(h); | 25131 return new _HistoryCrossFrame(h); |
24717 } | 25132 } |
24718 } | 25133 } |
24719 } | 25134 } |
| 25135 /** |
| 25136 * A custom KeyboardEvent that attempts to eliminate cross-browser |
| 25137 * inconsistencies, and also provide both keyCode and charCode information |
| 25138 * for all key events (when such information can be determined). |
| 25139 * |
| 25140 * This class is very much a work in progress, and we'd love to get information |
| 25141 * on how we can make this class work with as many international keyboards as |
| 25142 * possible. Bugs welcome! |
| 25143 */ |
| 25144 class KeyEvent implements KeyboardEvent { |
| 25145 /** The parent KeyboardEvent that this KeyEvent is wrapping and "fixing". */ |
| 25146 KeyboardEvent _parent; |
| 25147 |
| 25148 /** The "fixed" value of whether the alt key is being pressed. */ |
| 25149 bool _shadowAltKey; |
| 25150 |
| 25151 /** Caculated value of what the estimated charCode is for this event. */ |
| 25152 int _shadowCharCode; |
| 25153 |
| 25154 /** Caculated value of what the estimated keyCode is for this event. */ |
| 25155 int _shadowKeyCode; |
| 25156 |
| 25157 /** Caculated value of what the estimated keyCode is for this event. */ |
| 25158 int get keyCode => _shadowKeyCode; |
| 25159 |
| 25160 /** Caculated value of what the estimated charCode is for this event. */ |
| 25161 int get charCode => this.type == 'keypress' ? _shadowCharCode : 0; |
| 25162 |
| 25163 /** Caculated value of whether the alt key is pressed is for this event. */ |
| 25164 bool get altKey => _shadowAltKey; |
| 25165 |
| 25166 /** Caculated value of what the estimated keyCode is for this event. */ |
| 25167 int get which => keyCode; |
| 25168 |
| 25169 /** Accessor to the underlying keyCode value is the parent event. */ |
| 25170 int get _realKeyCode => JS('int', '#.keyCode', _parent); |
| 25171 |
| 25172 /** Accessor to the underlying charCode value is the parent event. */ |
| 25173 int get _realCharCode => JS('int', '#.charCode', _parent); |
| 25174 |
| 25175 /** Accessor to the underlying altKey value is the parent event. */ |
| 25176 bool get _realAltKey => JS('int', '#.altKey', _parent); |
| 25177 |
| 25178 /** Construct a KeyEvent with [parent] as event we're emulating. */ |
| 25179 KeyEvent(KeyboardEvent parent) { |
| 25180 _parent = parent; |
| 25181 _shadowAltKey = _realAltKey; |
| 25182 _shadowCharCode = _realCharCode; |
| 25183 _shadowKeyCode = _realKeyCode; |
| 25184 } |
| 25185 |
| 25186 /** True if the altGraphKey is pressed during this event. */ |
| 25187 bool get altGraphKey => _parent.altGraphKey; |
| 25188 bool get bubbles => _parent.bubbles; |
| 25189 /** True if this event can be cancelled. */ |
| 25190 bool get cancelable => _parent.cancelable; |
| 25191 bool get cancelBubble => _parent.cancelBubble; |
| 25192 /** Accessor to the clipboardData available for this event. */ |
| 25193 Clipboard get clipboardData => _parent.clipboardData; |
| 25194 /** True if the ctrl key is pressed during this event. */ |
| 25195 bool get ctrlKey => _parent.ctrlKey; |
| 25196 /** Accessor to the target this event is listening to for changes. */ |
| 25197 EventTarget get currentTarget => _parent.currentTarget; |
| 25198 bool get defaultPrevented => _parent.defaultPrevented; |
| 25199 int get detail => _parent.detail; |
| 25200 int get eventPhase => _parent.eventPhase; |
| 25201 /** |
| 25202 * Accessor to the part of the keyboard that the key was pressed from (one of |
| 25203 * KeyLocation.STANDARD, KeyLocation.RIGHT, KeyLocation.LEFT, |
| 25204 * KeyLocation.NUMPAD, KeyLocation.MOBILE, KeyLocation.JOYSTICK). |
| 25205 */ |
| 25206 int get keyLocation => _parent.keyLocation; |
| 25207 int get layerX => _parent.layerX; |
| 25208 int get layerY => _parent.layerY; |
| 25209 /** True if the Meta (or Mac command) key is pressed during this event. */ |
| 25210 bool get metaKey => _parent.metaKey; |
| 25211 int get pageX => _parent.pageX; |
| 25212 int get pageY => _parent.pageY; |
| 25213 bool get returnValue => _parent.returnValue; |
| 25214 /** True if the shift key was pressed during this event. */ |
| 25215 bool get shiftKey => _parent.shiftKey; |
| 25216 int get timeStamp => _parent.timeStamp; |
| 25217 /** |
| 25218 * The type of key event that occurred. One of "keydown", "keyup", or |
| 25219 * "keypress". |
| 25220 */ |
| 25221 String get type => _parent.type; |
| 25222 Window get view => _parent.view; |
| 25223 void preventDefault() => _parent.preventDefault(); |
| 25224 void stopImmediatePropagation() => _parent.stopImmediatePropagation(); |
| 25225 void stopPropagation() => _parent.stopPropagation(); |
| 25226 void $dom_initUIEvent(String type, bool canBubble, bool cancelable, |
| 25227 LocalWindow view, int detail) { |
| 25228 _parent.$dom_initUIEvent(type, canBubble, cancelable, view, detail); |
| 25229 } |
| 25230 void $dom_initEvent(String eventTypeArg, bool canBubbleArg, |
| 25231 bool cancelableArg) { |
| 25232 _parent.$dom_initEvent(eventTypeArg, canBubbleArg, cancelableArg); |
| 25233 } |
| 25234 String get _shadowKeyIdentifier => JS('String', '#.keyIdentifier', _parent); |
| 25235 } |
24720 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 25236 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
24721 // for details. All rights reserved. Use of this source code is governed by a | 25237 // for details. All rights reserved. Use of this source code is governed by a |
24722 // BSD-style license that can be found in the LICENSE file. | 25238 // BSD-style license that can be found in the LICENSE file. |
24723 | 25239 |
24724 | 25240 |
24725 class _AudioContextFactoryProvider { | 25241 class _AudioContextFactoryProvider { |
24726 | 25242 |
24727 static AudioContext createAudioContext() { | 25243 static AudioContext createAudioContext() { |
24728 return JS('AudioContext', | 25244 return JS('AudioContext', |
24729 'new (window.AudioContext || window.webkitAudioContext)()'); | 25245 'new (window.AudioContext || window.webkitAudioContext)()'); |
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
25153 if (length < 0) throw new ArgumentError('length'); | 25669 if (length < 0) throw new ArgumentError('length'); |
25154 if (start < 0) throw new RangeError.value(start); | 25670 if (start < 0) throw new RangeError.value(start); |
25155 int end = start + length; | 25671 int end = start + length; |
25156 if (end > a.length) throw new RangeError.value(end); | 25672 if (end > a.length) throw new RangeError.value(end); |
25157 for (int i = start; i < end; i++) { | 25673 for (int i = start; i < end; i++) { |
25158 accumulator.add(a[i]); | 25674 accumulator.add(a[i]); |
25159 } | 25675 } |
25160 return accumulator; | 25676 return accumulator; |
25161 } | 25677 } |
25162 } | 25678 } |
OLD | NEW |