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

Side by Side Diff: samples-dev/swarm/swarm_ui_lib/touch/EventUtil.dart

Issue 2828603002: Format samples and samples-dev directories. (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part of touch; 5 part of touch;
6 6
7 /** 7 /**
8 * Common events related helpers. 8 * Common events related helpers.
9 */ 9 */
10 class EventUtil { 10 class EventUtil {
11
12 /** 11 /**
13 * Add an event listener to an element. 12 * Add an event listener to an element.
14 * The event callback is specified by [handler]. 13 * The event callback is specified by [handler].
15 * If [capture] is true, the listener gets events on the capture phase. 14 * If [capture] is true, the listener gets events on the capture phase.
16 * If [removeHandlerOnFocus] is true the handler is removed when there is any 15 * If [removeHandlerOnFocus] is true the handler is removed when there is any
17 * focus event, and added back on blur events. 16 * focus event, and added back on blur events.
18 */ 17 */
19 static void observe(/*Element or Document*/ element, 18 static void observe(
20 Stream stream, Function handler, 19 /*Element or Document*/ element, Stream stream, Function handler,
21 [bool removeHandlerOnFocus = false]) { 20 [bool removeHandlerOnFocus = false]) {
22 var subscription = stream.listen(handler); 21 var subscription = stream.listen(handler);
23 // TODO(jacobr): this remove on focus behavior seems really ugly. 22 // TODO(jacobr): this remove on focus behavior seems really ugly.
24 if (removeHandlerOnFocus) { 23 if (removeHandlerOnFocus) {
25 element.onFocus.listen((e) { subscription.cancel(); }); 24 element.onFocus.listen((e) {
26 element.onBlur.listen((e) { subscription.cancel(); }); 25 subscription.cancel();
26 });
27 element.onBlur.listen((e) {
28 subscription.cancel();
29 });
27 } 30 }
28 } 31 }
29 32
30 /** 33 /**
31 * Clear the keyboard focus of the currently focused element (if there is 34 * Clear the keyboard focus of the currently focused element (if there is
32 * one). If there is no currently focused element then this function will do 35 * one). If there is no currently focused element then this function will do
33 * nothing. For most browsers this will cause the keyboard to be dismissed. 36 * nothing. For most browsers this will cause the keyboard to be dismissed.
34 */ 37 */
35 static void blurFocusedElement() { 38 static void blurFocusedElement() {
36 Element focusedEl = document.querySelector("*:focus"); 39 Element focusedEl = document.querySelector("*:focus");
37 if (focusedEl != null) { 40 if (focusedEl != null) {
38 focusedEl.blur(); 41 focusedEl.blur();
39 } 42 }
40 } 43 }
41 } 44 }
OLDNEW
« no previous file with comments | « samples-dev/swarm/swarm_ui_lib/touch/ClickBuster.dart ('k') | samples-dev/swarm/swarm_ui_lib/touch/FxUtil.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698