提交 55eb0b38 编写于 作者: A Adam Barth

Mark fn2's EventListenerNode work for PointerEvent

Prevously we listened for events on the document and then walked up the
component hierarchy looking for EventListenerNodes. Now we do something similar
by hooking the event dispatching logic in the AppView.

R=eseidel@chromium.org

Review URL: https://codereview.chromium.org/1153343004
上级 e68fe5d3
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:sky' as sky;
import 'package:sky/framework/fn2.dart';
class ContainerApp extends App {
UINode build() {
return new EventListenerNode(
new Rectangle(0xFF00FFFF),
onPointerDown: _handlePointerDown);
}
void _handlePointerDown(sky.PointerEvent event) {
print("_handlePointerDown");
}
}
void main() {
new ContainerApp();
}
......@@ -16,7 +16,8 @@ class AppView {
_renderView = new RenderView(child: root);
_renderView.attach();
_renderView.layout(new ViewConstraints(width: sky.view.width, height: sky.view.height));
_renderView.layout(new ViewConstraints(width: sky.view.width,
height: sky.view.height));
scheduler.ensureVisualUpdate();
}
......@@ -61,10 +62,12 @@ class AppView {
}
break;
}
dispatchPointerEvent(event, result);
}
void dispatchPointerEvent(sky.PointerEvent event, HitTestResult result) {
assert(result != null);
result.path.reversed.forEach((RenderNode node) {
for (RenderNode node in result.path.reversed)
node.handlePointer(event);
});
}
}
......@@ -168,15 +168,13 @@ class ParentDataNode extends ContentNode {
ParentDataNode(UINode content, this.parentData): super(content);
}
typedef GestureEventListener(sky.GestureEvent e);
typedef PointerEventListener(sky.PointerEvent e);
typedef EventListener(sky.Event e);
typedef void GestureEventListener(sky.GestureEvent e);
typedef void PointerEventListener(sky.PointerEvent e);
typedef void EventListener(sky.Event e);
class EventListenerNode extends ContentNode {
final Map<String, sky.EventListener> listeners;
static final Set<String> _registeredEvents = new HashSet<String>();
static Map<String, sky.EventListener> _createListeners({
EventListener onWheel,
GestureEventListener onGestureFlingCancel,
......@@ -256,32 +254,6 @@ class EventListenerNode extends ContentNode {
listener(e);
}
}
static void _dispatchEvent(sky.Event e) {
UINode target = RenderNodeWrapper._getMounted(bridgeEventTargetToRenderNode(e.target));
// TODO(rafaelw): StopPropagation?
while (target != null) {
if (target is EventListenerNode) {
target._handleEvent(e);
}
target = target._parent;
}
}
static void _ensureDocumentListener(String eventType) {
if (_registeredEvents.add(eventType)) {
sky.document.addEventListener(eventType, _dispatchEvent);
}
}
void _sync(UINode old, dynamic slot) {
for (var type in listeners.keys) {
_ensureDocumentListener(type);
}
super._sync(old, slot);
}
}
/*
......@@ -898,10 +870,27 @@ abstract class Component extends UINode {
UINode build();
}
class _AppView extends AppView {
_AppView() : super(null);
void dispatchPointerEvent(sky.PointerEvent event, HitTestResult result) {
super.dispatchPointerEvent(event, result);
UINode target = RenderNodeWrapper._getMounted(result.path.first);
// TODO(rafaelw): StopPropagation?
while (target != null) {
if (target is EventListenerNode)
target._handleEvent(event);
target = target._parent;
}
}
}
abstract class App extends Component {
App() : super(stateful: true) {
_appView = new AppView(null);
_appView = new _AppView();
_scheduleComponentForRender(this);
}
......@@ -934,7 +923,7 @@ class RenderSolidColor extends RenderDecoratedBox {
RenderSolidColor(int backgroundColor, { this.desiredSize })
: backgroundColor = backgroundColor,
super(new BoxDecoration(backgroundColor: backgroundColor));
super(decoration: new BoxDecoration(backgroundColor: backgroundColor));
sky.Size getIntrinsicDimensions(BoxConstraints constraints) {
return constraints.constrain(desiredSize);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册