Commit 32ca055f authored by Hixie's avatar Hixie

Notification of metrics changes.

The Rendering layer binding now multiplexes the dart:ui metrics change
notification so that multiple consumers can all listen to the change.
parent 1e446ffc
...@@ -13,6 +13,9 @@ import 'hit_test.dart'; ...@@ -13,6 +13,9 @@ import 'hit_test.dart';
import 'object.dart'; import 'object.dart';
import 'view.dart'; import 'view.dart';
typedef void EventListener(InputEvent event);
typedef void MetricListener(Size size);
int _hammingWeight(int value) { int _hammingWeight(int value) {
if (value == 0) if (value == 0)
return 0; return 0;
...@@ -24,8 +27,6 @@ int _hammingWeight(int value) { ...@@ -24,8 +27,6 @@ int _hammingWeight(int value) {
return weight; return weight;
} }
typedef void EventListener(InputEvent event);
/// A hit test entry used by [FlutterBinding] /// A hit test entry used by [FlutterBinding]
class BindingHitTestEntry extends HitTestEntry { class BindingHitTestEntry extends HitTestEntry {
const BindingHitTestEntry(HitTestTarget target, this.result) : super(target); const BindingHitTestEntry(HitTestTarget target, this.result) : super(target);
...@@ -137,7 +138,7 @@ class FlutterBinding extends HitTestTarget { ...@@ -137,7 +138,7 @@ class FlutterBinding extends HitTestTarget {
if (renderViewOverride == null) { if (renderViewOverride == null) {
_renderView = new RenderView(child: root); _renderView = new RenderView(child: root);
_renderView.attach(); _renderView.attach();
_renderView.rootConstraints = _createConstraints(); _handleMetricsChanged();
_renderView.scheduleInitialFrame(); _renderView.scheduleInitialFrame();
} else { } else {
_renderView = renderViewOverride; _renderView = renderViewOverride;
...@@ -156,11 +157,19 @@ class FlutterBinding extends HitTestTarget { ...@@ -156,11 +157,19 @@ class FlutterBinding extends HitTestTarget {
RenderView get renderView => _renderView; RenderView get renderView => _renderView;
RenderView _renderView; RenderView _renderView;
ViewConstraints _createConstraints() { final List<MetricListener> _metricListeners = new List<MetricListener>();
return new ViewConstraints(size: new Size(ui.view.width, ui.view.height));
} /// Calls listener for every event that isn't localized to a given view coordinate
void addMetricListener(MetricListener listener) => _metricListeners.add(listener);
/// Stops calling listener for every event that isn't localized to a given view coordinate
bool removeMetricListener(MetricListener listener) => _metricListeners.remove(listener);
void _handleMetricsChanged() { void _handleMetricsChanged() {
_renderView.rootConstraints = _createConstraints(); Size size = new Size(ui.view.width, ui.view.height);
_renderView.rootConstraints = new ViewConstraints(size: size);
for (MetricListener listener in _metricListeners)
listener(size);
} }
/// Pump the rendering pipeline to generate a frame for the given time stamp /// Pump the rendering pipeline to generate a frame for the given time stamp
...@@ -184,6 +193,7 @@ class FlutterBinding extends HitTestTarget { ...@@ -184,6 +193,7 @@ class FlutterBinding extends HitTestTarget {
if (ourEvent is PointerInputEvent) { if (ourEvent is PointerInputEvent) {
_handlePointerInputEvent(ourEvent); _handlePointerInputEvent(ourEvent);
} else { } else {
assert(event.type == 'back');
for (EventListener listener in _eventListeners) for (EventListener listener in _eventListeners)
listener(ourEvent); listener(ourEvent);
} }
......
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