Change how events are handled in Effen

This patch removes the mutable API to event handling (Nodes no longer have a events object with which to add listeners).

Instead, a new (non-Render) Node is introduced: EventTarget. This node represents a location in the Effen tree which can handle events as they bubble.

Note that this also changes the implementation to use event delegation (one set of listeners at the sky.document level) rather than direct listeners on leaf nodes.

R=abarth@chromium.org

Review URL: https://codereview.chromium.org/1019633004
This commit is contained in:
Rafael Weinstein 2015-03-15 12:33:30 -07:00
parent f6d53459aa
commit bd7603bdb0

View file

@ -20,7 +20,7 @@ import 'stock_menu.dart';
class StocksApp extends App {
DrawerController _drawerController = new DrawerController();
PopupMenuController _menuController = new PopupMenuController();
PopupMenuController _menuController;
static Style _style = new Style('''
display: flex;
@ -58,6 +58,7 @@ class StocksApp extends App {
void _handleMenuClick(_) {
setState(() {
_menuController = new PopupMenuController();
_menuController.open();
});
}
@ -111,22 +112,28 @@ class StocksApp extends App {
var toolbar = new ActionBar(
children: [
new Icon(key: 'menu', style: _iconStyle,
size: 24,
type: 'navigation/menu_white')
..events.listen('gesturetap', _drawerController.toggle),
new EventTarget(
new Icon(key: 'menu', style: _iconStyle,
size: 24,
type: 'navigation/menu_white'),
onGestureTap: _drawerController.toggle
),
new Container(
style: _titleStyle,
children: [title]
),
new Icon(key: 'search', style: _iconStyle,
size: 24,
type: 'action/search_white')
..events.listen('gesturetap', _handleSearchClick),
new Icon(key: 'more_white', style: _iconStyle,
size: 24,
type: 'navigation/more_vert_white')
..events.listen('gesturetap', _handleMenuClick),
new EventTarget(
new Icon(key: 'search', style: _iconStyle,
size: 24,
type: 'action/search_white'),
onGestureTap: _handleSearchClick
),
new EventTarget(
new Icon(key: 'more_white', style: _iconStyle,
size: 24,
type: 'navigation/more_vert_white'),
onGestureTap: _handleMenuClick
)
]
);
@ -145,15 +152,19 @@ class StocksApp extends App {
drawer
];
if (_menuController.isOpen) {
children.add(new StockMenu(controller: _menuController)
..events.listen('gesturetap', (_) {
// TODO(abarth): We should close the menu when you tap away from the
// menu rather than when you tap on the menu.
setState(() {
_menuController.close();
});
}));
if (_menuController != null) {
var menu = new EventTarget(
new StockMenu(controller: _menuController),
onGestureTap: (_) {
// TODO(abarth): We should close the menu when you tap away from the
// menu rather than when you tap on the menu.
setState(() {
_menuController.close();
_menuController = null;
});
}
);
children.add(menu);
}
return new Container(key: 'StocksApp', children: children);