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

Side by Side Diff: sky/specs/events.md

Issue 880963005: Specs: Yet Another Gesture Model (mark IV). This one handles (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 11 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
« no previous file with comments | « sky/specs/dom.md ('k') | sky/specs/gestures.md » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 Sky Event Model 1 Sky Event Model
2 =============== 2 ===============
3 3
4 ```javascript 4 ```javascript
5 // EVENTS 5 // EVENTS
6 6
7 class Event { 7 class Event {
8 constructor (String type, Boolean bubbles = true, any data = null); // O(1) 8 constructor (String type, Boolean bubbles = true, any data = null); // O(1)
9 readonly attribute String type; // O(1) 9 readonly attribute String type; // O(1)
10 readonly attribute Boolean bubbles; // O(1) 10 readonly attribute Boolean bubbles; // O(1)
11 attribute any data; // O(1) 11 attribute any data; // O(1)
12 12
13 readonly attribute EventTarget target; // O(1) 13 readonly attribute EventTarget target; // O(1)
14 readonly attribute EventTarget currentTarget; // O(1)
14 attribute Boolean handled; // O(1) 15 attribute Boolean handled; // O(1)
15 attribute any result; // O(1) 16 attribute any result; // O(1)
16 17
17 // TODO(ianh): do events get blocked at scope boundaries, e.g. focus events when both sides are in the scope? 18 // TODO(ianh): do events get blocked at scope boundaries, e.g. focus events when both sides are in the scope?
18 // TODO(ianh): do events get retargetted, e.g. focus when leaving a custom e lement? 19 // TODO(ianh): do events get retargetted, e.g. focus when leaving a custom e lement?
19 } 20 }
20 21
21 // TODO(ianh): decide if we're using this generic Event class and 22 // TODO(ianh): decide if we're using this generic Event class and
22 // allowing any arbitrary properties to be set on it, or if we're 23 // allowing any arbitrary properties to be set on it, or if we're
23 // going to use subclasses (and drop "type"). If we use subclasses 24 // going to use subclasses (and drop "type"). If we use subclasses
24 // then how will declarative event handling work in frameworks? 25 // then how will declarative event handling work in frameworks?
25 // (consider that multiple modules can each have their own FooEvent 26 // (consider that multiple modules can each have their own FooEvent
26 // class with the same name...) 27 // class with the same name...)
27 // 28 //
28 // The advantage of this would be the ability to enforce (or at 29 // The advantage of this would be the ability to enforce (or at
29 // least better catch) incorrect uses of the API, e.g. to make sure 30 // least better catch) incorrect uses of the API, e.g. to make sure
30 // people don't stomp on themselves with the return value. 31 // people don't stomp on themselves with the return value.
31 32
32 callback EventListener any (Event event); 33 callback EventListener any (Event event);
33 // if the return value is not undefined: 34 // if the return value is not undefined:
34 // assign it to event.result 35 // assign it to event.result
35 // set event.handled to true 36 // set event.handled to true
36 37
37 abstract class EventTarget { 38 abstract class EventTarget {
38 any dispatchEvent(Event event, any defaultResult = null); // O(N) in total n umber of listeners for this type in the chain 39 any dispatchEvent(Event event, any defaultResult = null); // O(N) in total n umber of listeners for this type in the chain
39 // sets event.handled to false and event.result to defaultResult 40 // sets event.handled to false and event.result to defaultResult
40 // makes a record of the event target chain by calling getEventDispatchCha in() 41 // makes a record of the event target chain by calling getEventDispatchCha in()
41 // invokes all the handlers on the chain in turn 42 // sets event.target to this
43 // invokes all the handlers on the chain in turn, at each step setting cur rentTarget to the EventTarget for that step
42 // returns event.result 44 // returns event.result
43 virtual Array<EventTarget> getEventDispatchChain(); // O(1) // returns [] 45 virtual Array<EventTarget> getEventDispatchChain(); // O(1) // returns []
44 void addEventListener(String type, EventListener listener); // O(1) 46 void addEventListener(String type, EventListener listener); // O(1)
45 void removeEventListener(String type, EventListener listener); // O(N) in ev ent listeners with that type 47 void removeEventListener(String type, EventListener listener); // O(N) in ev ent listeners with that type
46 private Array<String> getRegisteredEventListenerTypes(); // O(N) 48 private Array<String> getRegisteredEventListenerTypes(); // O(N)
47 private Array<EventListener> getRegisteredEventListenersForType(String type) ; // O(N) 49 private Array<EventListener> getRegisteredEventListenersForType(String type) ; // O(N)
48 } 50 }
49 51
50 class CustomEventTarget : EventTarget { // implemented in JS 52 class CustomEventTarget : EventTarget { // implemented in JS
51 constructor (); // O(1) 53 constructor (); // O(1)
52 attribute EventTarget parentNode; // getter O(1), setter O(N) in height of t ree, throws if this would make a loop 54 attribute EventTarget parentNode; // getter O(1), setter O(N) in height of t ree, throws if this would make a loop
53 55
54 virtual Array<EventTarget> getEventDispatchChain(); // O(N) in height of tre e // implements EventTarget.getEventDispatchChain() 56 virtual Array<EventTarget> getEventDispatchChain(); // O(N) in height of tre e // implements EventTarget.getEventDispatchChain()
55 // let result = []; 57 // let result = [];
56 // let node = this; 58 // let node = this;
57 // while (node) { 59 // while (node) {
58 // result.push(node); 60 // result.push(node);
59 // node = node.parentNode; 61 // node = node.parentNode;
60 // } 62 // }
61 // return result; 63 // return result;
62 64
63 // you can inherit from this to make your object into an event target 65 // you can inherit from this to make your object into an event target
64 // or you can inherit from EventTarget and implement your own getEventDispat chChain() 66 // or you can inherit from EventTarget and implement your own getEventDispat chChain()
65 } 67 }
66 ``` 68 ```
OLDNEW
« no previous file with comments | « sky/specs/dom.md ('k') | sky/specs/gestures.md » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698