mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Specs: fix a raft of syntax errors caught by actually running a syntax checker...
Review URL: https://codereview.chromium.org/943843002
This commit is contained in:
parent
9226084b80
commit
2175f32677
@ -17,14 +17,14 @@ abstract class Node extends EventTarget {
|
||||
external Root get owner; // O(1)
|
||||
|
||||
external ParentNode get parentNode; // O(1)
|
||||
Element get parentElement => {
|
||||
Element get parentElement {
|
||||
if (parentNode is Element)
|
||||
return parentNode as Element;
|
||||
return null;
|
||||
}
|
||||
|
||||
external Node get previousSibling; // O(1)
|
||||
Element get previousElementSibling => {
|
||||
Element get previousElementSibling {
|
||||
var result = previousSibling;
|
||||
while (result != null && result is! Element)
|
||||
result = result.previousSibling;
|
||||
@ -32,7 +32,7 @@ abstract class Node extends EventTarget {
|
||||
}
|
||||
|
||||
external Node get nextSibling; // O(1)
|
||||
Element get nextElementSibling => {
|
||||
Element get nextElementSibling {
|
||||
var result = nextSibling;
|
||||
while (result != null && result is! Element)
|
||||
result = result.nextSibling;
|
||||
@ -53,7 +53,7 @@ abstract class Node extends EventTarget {
|
||||
});
|
||||
}
|
||||
|
||||
void _insertAfter(Node node); // O(N) in number of arguments plus all their descendants
|
||||
external void _insertAfter(Node node); // O(N) in number of arguments plus all their descendants
|
||||
// node must be Text or Element, parentNode must be non-null
|
||||
void insertAfter(List nodes) {
|
||||
var lastNode = this;
|
||||
@ -119,7 +119,7 @@ abstract class Node extends EventTarget {
|
||||
|
||||
abstract class ParentNode extends Node {
|
||||
external Node get firstChild; // O(1)
|
||||
Element get firstElementChild => {
|
||||
Element get firstElementChild {
|
||||
var result = firstChild;
|
||||
while (result != null && result is! Element)
|
||||
result = result.nextSibling;
|
||||
@ -127,7 +127,7 @@ abstract class ParentNode extends Node {
|
||||
}
|
||||
|
||||
external Node get lastChild; // O(1)
|
||||
Element get lastElementChild => {
|
||||
Element get lastElementChild {
|
||||
var result = lastChild;
|
||||
while (result != null && result is! Element)
|
||||
result = result.previousSibling;
|
||||
@ -143,7 +143,7 @@ abstract class ParentNode extends Node {
|
||||
|
||||
external void _appendChild(Node node); // O(N) in number of descendants
|
||||
// node must be Text or Element
|
||||
void appendChild(Node node) {
|
||||
void appendChild(node) {
|
||||
if (node is String)
|
||||
node = new Text(node);
|
||||
_appendChild(node);
|
||||
@ -154,7 +154,7 @@ abstract class ParentNode extends Node {
|
||||
|
||||
external void _prependChild(Node node); // O(N) in number of descendants
|
||||
// node must be Text or Element
|
||||
void prependChild(Node node) {
|
||||
void prependChild(node) {
|
||||
if (node is String)
|
||||
node = new Text(node);
|
||||
_prependChild(node);
|
||||
@ -168,7 +168,7 @@ abstract class ParentNode extends Node {
|
||||
}
|
||||
|
||||
external void removeChildren(); // O(N) in number of descendants
|
||||
void setChild(Node node) {
|
||||
void setChild(node) {
|
||||
removeChildren();
|
||||
appendChild(node);
|
||||
}
|
||||
@ -191,15 +191,15 @@ class tagname extends AutomaticMetadata {
|
||||
final String name;
|
||||
void init(DeclarationMirror target, Module module) {
|
||||
assert(target is ClassMirror);
|
||||
if (!target.isSubclassOf(reflectClass(Element)))
|
||||
throw Error('@tagname can only be used on descendants of Element');
|
||||
if (!(target as ClassMirror).isSubclassOf(reflectClass(Element)))
|
||||
throw new UnsupportedError('@tagname can only be used on descendants of Element');
|
||||
module.registerElement(name, (target as ClassMirror).reflectedType);
|
||||
}
|
||||
}
|
||||
|
||||
// @hasShadow annotation for registering elements
|
||||
class _HasShadow {
|
||||
const HasShadow();
|
||||
const _HasShadow();
|
||||
}
|
||||
const hasShadow = const _HasShadow();
|
||||
|
||||
@ -207,8 +207,11 @@ abstract class Element extends ParentNode {
|
||||
Element({Map<String, String> attributes: null,
|
||||
List children: null,
|
||||
Module hostModule: null}) { // O(M+N), M = number of attributes, N = number of children nodes plus all their descendants
|
||||
var shadowClass = reflectClass(hasShadow);
|
||||
bool needsShadow = reflect(this).type.metadata.singleWhere((mirror) => mirror.type == hasShadowClass);
|
||||
var shadowClass = reflectClass(hasShadow.runtimeType);
|
||||
var shadowAnnotations = reflect(this).type.metadata.where((mirror) => mirror.type == shadowClass);
|
||||
if (shadowAnnotations.length > 2)
|
||||
throw new StateError('@hasShadow specified multiple times on ' + currentMirrorSystem().getName(reflectClass(this.runtimeType).simpleName));
|
||||
bool needsShadow = shadowAnnotations.length == 1;
|
||||
if (children != null)
|
||||
children = children.map((node) => node is String ? new Text(node) : node).toList();
|
||||
this._initElement(attributes, children, hostModule, needsShadow);
|
||||
@ -222,7 +225,7 @@ abstract class Element extends ParentNode {
|
||||
String get tagName { // O(N) in number of annotations on the class
|
||||
// throws a StateError if the class doesn't have an @tagname annotation
|
||||
var tagnameClass = reflectClass(tagname);
|
||||
return (reflectClass(this.runtimeType).metadata.singleWhere((mirror) => mirror.type == tagnameClass).reflectee as tagname).value;
|
||||
return (reflectClass(this.runtimeType).metadata.singleWhere((mirror) => mirror.type == tagnameClass).reflectee as tagname).name;
|
||||
}
|
||||
|
||||
external bool hasAttribute(String name); // O(N) in number of attributes
|
||||
@ -235,7 +238,7 @@ abstract class Element extends ParentNode {
|
||||
// Returns a new Array and new Attr instances every time.
|
||||
external List<Attr> getAttributes(); // O(N) in number of attributes
|
||||
|
||||
external final Root shadowRoot; // O(1)
|
||||
external Root get shadowRoot; // O(1)
|
||||
// returns the shadow root
|
||||
|
||||
void endTagParsedCallback() { }
|
||||
@ -270,8 +273,14 @@ class Fragment extends ParentNode {
|
||||
}
|
||||
|
||||
class Root extends ParentNode {
|
||||
external Root ({List children, Element host}); // O(N) in number of children nodes arguments plus all their descendants
|
||||
// children must be String, Text, or Element
|
||||
Root({List children: null, this.host}) { // O(N) in number of children nodes plus all their descendants
|
||||
if (children != null)
|
||||
children = children.map((node) => node is String ? new Text(node) : node).toList();
|
||||
this._initRoot(children);
|
||||
}
|
||||
external void _initRoot(List children);
|
||||
// appends the given children nodes
|
||||
// children must be Text or Element
|
||||
|
||||
final Element host;
|
||||
|
||||
@ -280,8 +289,7 @@ class Root extends ParentNode {
|
||||
}
|
||||
|
||||
class ApplicationRoot extends Root {
|
||||
external ApplicationRoot ({List children}) : Root(children: children); // O(N) in number of children nodes arguments plus all their descendants
|
||||
// children must be String, Text, or Element
|
||||
ApplicationRoot ({List children}) : super(children: children); // O(N) in number of children nodes arguments plus all their descendants
|
||||
|
||||
@override
|
||||
Type getLayoutManager() => rootLayoutManager; // O(1)
|
||||
|
||||
@ -112,19 +112,20 @@ abstract class Gesture extends EventTarget {
|
||||
if (returnValue.cancel) {
|
||||
assert(returnValue.choose == false);
|
||||
if (wasActive)
|
||||
module.application.cancelGesture(this);
|
||||
module.application.gestureManager.cancelGesture(this);
|
||||
// if we never became active, then we never called addGesture() below
|
||||
_active = false;
|
||||
} else if (active == true) {
|
||||
if (wasActive == false || event is PointerDownEvent)
|
||||
module.application.addGesture(event, this);
|
||||
module.application.gestureManager.addGesture(event, this);
|
||||
if (returnValue.choose == true)
|
||||
module.application.chooseGesture(this);
|
||||
module.application.gestureManager.chooseGesture(this);
|
||||
}
|
||||
_ready = returnValue.finished;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
```
|
||||
Subclasses should override ``processEvent()``:
|
||||
- as the events are received, they get examined to see if they
|
||||
@ -136,10 +137,9 @@ Subclasses should override ``processEvent()``:
|
||||
- doing anything with the event or target other than reading
|
||||
state is a contract violation
|
||||
- you are allowed to call sendEvent() at any time during a
|
||||
processEventInternal() call, or after a call to
|
||||
processEventInternal(), assuming that the last such call returned
|
||||
valid=true, until the next call to processEventInternal() or
|
||||
cancel().
|
||||
processEvent() call, or after a call to processEvent(), assuming
|
||||
that the last such call returned valid=true, until the next call to
|
||||
processEvent() or cancel().
|
||||
- set forceChoose=true on the return value if you are confident
|
||||
that this is the gesture the user meant, even if it's possible
|
||||
that another gesture is still claiming it's valid (e.g. a long
|
||||
@ -151,6 +151,7 @@ Subclasses should override ``processEvent()``:
|
||||
"cancel" events if cancel() is called
|
||||
|
||||
```dart
|
||||
*/
|
||||
|
||||
class PointerState {
|
||||
PointerState({this.gestures, this.chosen}) {
|
||||
@ -251,6 +252,7 @@ class GestureManager {
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
</script>
|
||||
```
|
||||
|
||||
@ -263,13 +265,15 @@ SKY MODULE
|
||||
<!-- note: this hasn't been dartified yet -->
|
||||
|
||||
<script>
|
||||
*/
|
||||
class TapGesture extends Gesture {
|
||||
TapGesture = Gesture;
|
||||
|
||||
// internal state:
|
||||
// Integer numButtons = 0;
|
||||
// Boolean primaryDown = false;
|
||||
|
||||
virtual GestureState processEvent(Event event);
|
||||
GestureState processEvent(Event event);
|
||||
// - let returnValue = { finished = false }
|
||||
// - if the event is a pointer-down:
|
||||
// - increment this.numButtons
|
||||
@ -334,23 +338,29 @@ class TapGesture extends Gesture {
|
||||
// - return returnValue
|
||||
}
|
||||
|
||||
class LongPressGesture : Gesture {
|
||||
GestureState processEvent(EventTarget target, Event event);
|
||||
class LongPressGesture extends Gesture {
|
||||
LongPressGesture = Gesture;
|
||||
|
||||
GestureState processEvent(PointerEvent event);
|
||||
// long-tap-start: sent when the primary pointer goes down
|
||||
// long-tap-cancel: sent when cancel()ed or finger goes out of bounding box
|
||||
// long-tap: sent when the primary pointer is released
|
||||
}
|
||||
|
||||
class DoubleTapGesture : Gesture {
|
||||
GestureState processEvent(EventTarget target, Event event);
|
||||
class DoubleTapGesture extends Gesture {
|
||||
DoubleTapGesture = Gesture;
|
||||
|
||||
GestureState processEvent(PointerEvent event);
|
||||
// double-tap-start: sent when the primary pointer goes down the first time
|
||||
// double-tap-cancel: sent when cancel()ed or finger goes out of bounding box, or it times out
|
||||
// double-tap: sent when the primary pointer is released the second time within the timeout
|
||||
}
|
||||
|
||||
|
||||
abstract class ScrollGesture : Gesture {
|
||||
GestureState processEvent(EventTarget target, Event event);
|
||||
abstract class ScrollGesture extends Gesture {
|
||||
ScrollGesture = Gesture;
|
||||
|
||||
GestureState processEvent(PointerEvent event);
|
||||
// this fires the following events (inertia is a boolean, delta is a float):
|
||||
// scroll-start, with field inertia=false, delta=0; prechoose=true
|
||||
// scroll, with fields inertia (is this a simulated scroll from inertia or a real scroll?), delta (number of pixels to scroll); prechoose=true
|
||||
@ -366,41 +376,52 @@ abstract class ScrollGesture : Gesture {
|
||||
// - finished=true when the primary pointer goes up
|
||||
}
|
||||
|
||||
class HorizontalScrollGesture : ScrollGesture { }
|
||||
class HorizontalScrollGesture extends ScrollGesture {
|
||||
// a ScrollGesture giving x-axis scrolling
|
||||
HorizontalScrollGesture = ScrollGesture;
|
||||
}
|
||||
|
||||
class VerticalScrollGesture : ScrollGesture { }
|
||||
class VerticalScrollGesture extends ScrollGesture {
|
||||
// a ScrollGesture giving y-axis scrolling
|
||||
VerticalScrollGesture = ScrollGesture;
|
||||
}
|
||||
|
||||
|
||||
class PanGesture : Gesture {
|
||||
class PanGesture extends Gesture {
|
||||
PanGesture = Gesture;
|
||||
// similar to ScrollGesture, but with two axes
|
||||
// pan-start, pan, pan-end
|
||||
// events have inertia (boolean), dx (float), dy (float)
|
||||
}
|
||||
|
||||
|
||||
abstract class ZoomGesture : Gesture {
|
||||
GestureState processEvent(EventTarget target, Event event);
|
||||
abstract class ZoomGesture extends Gesture {
|
||||
ZoomGesture = Gesture;
|
||||
|
||||
GestureState processEvent(PointerEvent event);
|
||||
// zoom-start: sent when we could start zooming (e.g. for pinch-zoom, when two fingers hit the glass) (prechoose)
|
||||
// zoom-end: sent when cancel()ed after zoom-start, or when the fingers are lifted (prechoose)
|
||||
// zoom, with a 'scale' attribute, whose value is a multiple of the scale factor at zoom-start
|
||||
// e.g. if the user zooms to 2x, you'd get a bunch of 'zoom' events like scale=1.0, scale=1.17, ... scale=1.91, scale=2.0
|
||||
}
|
||||
|
||||
class PinchZoomGesture : ZoomGesture {
|
||||
class PinchZoomGesture extends ZoomGesture {
|
||||
PinchZoomGesture = ZoomGesture;
|
||||
// a ZoomGesture for two-finger-pinch gesture
|
||||
// zoom is prechoose
|
||||
}
|
||||
|
||||
class DoubleTapZoomGesture : ZoomGesture {
|
||||
class DoubleTapZoomGesture extends ZoomGesture {
|
||||
DoubleTapZoomGesture = ZoomGesture;
|
||||
// a ZoomGesture for the double-tap-slide gesture
|
||||
// when the slide starts, forceChoose
|
||||
}
|
||||
|
||||
|
||||
class PanAndZoomGesture : Gesture {
|
||||
GestureState processEvent(EventTarget target, Event event);
|
||||
class PanAndZoomGesture extends Gesture {
|
||||
PanAndZoomGesture = Gesture;
|
||||
|
||||
GestureState processEvent(PointerEvent event);
|
||||
// manipulate-start (prechoose)
|
||||
// manipulate: (prechoose)
|
||||
// panX, panY: pixels
|
||||
@ -410,8 +431,10 @@ class PanAndZoomGesture : Gesture {
|
||||
}
|
||||
|
||||
|
||||
abstract class FlingGesture : Gesture {
|
||||
GestureState processEvent(EventTarget target, Event event);
|
||||
abstract class FlingGesture extends Gesture {
|
||||
FlingGesture = Gesture;
|
||||
|
||||
GestureState processEvent(PointerEvent event);
|
||||
// fling-start: when the gesture begins (prechoose)
|
||||
// fling-move: while the user is directly dragging the element (has delta attribute with the distance from fling-start) (prechoose)
|
||||
// fling: the user has released the pointer and the decision is it was in fact flung
|
||||
@ -419,10 +442,17 @@ abstract class FlingGesture : Gesture {
|
||||
// fling-end: cancel(), or after fling or fling-cancel (prechoose)
|
||||
}
|
||||
|
||||
class FlingLeftGesture : FlingGesture { }
|
||||
class FlingRightGesture : FlingGesture { }
|
||||
class FlingUpGesture : FlingGesture { }
|
||||
class FlingDownGesture : FlingGesture { }
|
||||
|
||||
class FlingLeftGesture extends FlingGesture {
|
||||
FlingLeftGesture = FlingGesture;
|
||||
}
|
||||
class FlingRightGesture extends FlingGesture {
|
||||
FlingRightGesture = FlingGesture;
|
||||
}
|
||||
class FlingUpGesture extends FlingGesture {
|
||||
FlingUpGesture = FlingGesture;
|
||||
}
|
||||
class FlingDownGesture extends FlingGesture {
|
||||
FlingDownGesture = FlingGesture;
|
||||
}
|
||||
</script>
|
||||
```
|
||||
|
||||
@ -100,7 +100,7 @@ abstract class AbstractModule extends EventTarget {
|
||||
// if it's already loaded, the future will resolve immediately
|
||||
// if loading fails, the future will have an error
|
||||
|
||||
List<Module> getImports(); // O(N)
|
||||
external List<Module> getImports(); // O(N)
|
||||
// returns the Module objects of all the imported modules
|
||||
|
||||
external void registerElement(String tagname, Type elementClass); // O(1)
|
||||
|
||||
@ -434,6 +434,7 @@ class PointerMovedEvent extends PointerEvent<Null> {
|
||||
PointerMovedEvent = PointerEvent;
|
||||
bool get bubbles => false;
|
||||
}
|
||||
/*
|
||||
```
|
||||
|
||||
Wheel events
|
||||
@ -470,12 +471,13 @@ Note: The only wheels that are supported are mouse wheels and physical
|
||||
dials. Track balls are not reported as mouse wheels.
|
||||
|
||||
```dart
|
||||
*/
|
||||
class WheelEvent extends Event {
|
||||
Event({ this.wheel,
|
||||
this.delta: 0.0,
|
||||
this.pointer,
|
||||
this.x, this.y,
|
||||
}): super();
|
||||
WheelEvent({ this.wheel,
|
||||
this.delta: 0.0,
|
||||
this.pointer,
|
||||
this.x, this.y
|
||||
}): super();
|
||||
|
||||
final int wheel;
|
||||
final double delta; // revolutions (or fractions thereof)
|
||||
|
||||
@ -22,6 +22,8 @@ argument's default value.
|
||||
The following definitions are exposed in ``dart:sky``:
|
||||
|
||||
```dart
|
||||
import 'dart:mirrors';
|
||||
|
||||
abstract class AutomaticMetadata {
|
||||
const AutomaticMetadata();
|
||||
void init(DeclarationMirror target, Module module);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user