Commit bd7603bd authored by Rafael Weinstein's avatar Rafael Weinstein

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
parent f6d53459
...@@ -20,7 +20,7 @@ import 'stock_menu.dart'; ...@@ -20,7 +20,7 @@ import 'stock_menu.dart';
class StocksApp extends App { class StocksApp extends App {
DrawerController _drawerController = new DrawerController(); DrawerController _drawerController = new DrawerController();
PopupMenuController _menuController = new PopupMenuController(); PopupMenuController _menuController;
static Style _style = new Style(''' static Style _style = new Style('''
display: flex; display: flex;
...@@ -58,6 +58,7 @@ class StocksApp extends App { ...@@ -58,6 +58,7 @@ class StocksApp extends App {
void _handleMenuClick(_) { void _handleMenuClick(_) {
setState(() { setState(() {
_menuController = new PopupMenuController();
_menuController.open(); _menuController.open();
}); });
} }
...@@ -111,22 +112,28 @@ class StocksApp extends App { ...@@ -111,22 +112,28 @@ class StocksApp extends App {
var toolbar = new ActionBar( var toolbar = new ActionBar(
children: [ children: [
new Icon(key: 'menu', style: _iconStyle, new EventTarget(
size: 24, new Icon(key: 'menu', style: _iconStyle,
type: 'navigation/menu_white') size: 24,
..events.listen('gesturetap', _drawerController.toggle), type: 'navigation/menu_white'),
onGestureTap: _drawerController.toggle
),
new Container( new Container(
style: _titleStyle, style: _titleStyle,
children: [title] children: [title]
), ),
new Icon(key: 'search', style: _iconStyle, new EventTarget(
size: 24, new Icon(key: 'search', style: _iconStyle,
type: 'action/search_white') size: 24,
..events.listen('gesturetap', _handleSearchClick), type: 'action/search_white'),
new Icon(key: 'more_white', style: _iconStyle, onGestureTap: _handleSearchClick
size: 24, ),
type: 'navigation/more_vert_white') new EventTarget(
..events.listen('gesturetap', _handleMenuClick), new Icon(key: 'more_white', style: _iconStyle,
size: 24,
type: 'navigation/more_vert_white'),
onGestureTap: _handleMenuClick
)
] ]
); );
...@@ -145,15 +152,19 @@ class StocksApp extends App { ...@@ -145,15 +152,19 @@ class StocksApp extends App {
drawer drawer
]; ];
if (_menuController.isOpen) { if (_menuController != null) {
children.add(new StockMenu(controller: _menuController) var menu = new EventTarget(
..events.listen('gesturetap', (_) { new StockMenu(controller: _menuController),
// TODO(abarth): We should close the menu when you tap away from the onGestureTap: (_) {
// menu rather than when you tap on the menu. // TODO(abarth): We should close the menu when you tap away from the
setState(() { // menu rather than when you tap on the menu.
_menuController.close(); setState(() {
}); _menuController.close();
})); _menuController = null;
});
}
);
children.add(menu);
} }
return new Container(key: 'StocksApp', children: children); return new Container(key: 'StocksApp', children: children);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment