Skip to content

Commit

Permalink
Merge pull request #22 from DrMarcII/format
Browse files Browse the repository at this point in the history
Format dart files with dartformat.
  • Loading branch information
DrMarcII committed Jan 12, 2015
2 parents 023eec4 + b8ec0d8 commit 6c83b20
Show file tree
Hide file tree
Showing 7 changed files with 165 additions and 195 deletions.
109 changes: 54 additions & 55 deletions dart/lib/html.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ class HtmlPageLoader extends BasePageLoader {
return new HtmlPageLoader._(globalContext, clock);
}

HtmlPageLoader._(Node globalContext, Clock clock)
: super(clock) {
HtmlPageLoader._(Node globalContext, Clock clock) : super(clock) {
this._globalContext = new HtmlPageLoaderElement(globalContext, this);
this._mouse = new _HtmlMouse(this);
}
Expand All @@ -80,7 +79,6 @@ class HtmlPageLoader extends BasePageLoader {
}

class _HtmlMouse implements PageLoaderMouse {

final HtmlPageLoader loader;

int clientX = 0;
Expand Down Expand Up @@ -114,12 +112,13 @@ class _HtmlMouse implements PageLoaderMouse {
int get _borderWidth => (window.outerWidth - window.innerWidth) ~/ 2;
int get screenX => window.screenLeft + _borderWidth + clientX;
int get screenY => window.screenTop + window.outerHeight -
window.innerHeight - _borderWidth + clientY;
window.innerHeight -
_borderWidth +
clientY;

void dispatchEvent(String type, _ElementPageLoaderElement eventTarget,
[int button = 0]) {
var event = new MouseEvent(
type,
var event = new MouseEvent(type,
button: button,
clientX: clientX,
clientY: clientY,
Expand Down Expand Up @@ -179,11 +178,10 @@ abstract class HtmlPageLoaderElement implements PageLoaderElement {
int get hashCode => node.hashCode;

@override
bool operator ==(other) =>
other != null &&
other.runtimeType == runtimeType &&
other.node == node &&
other.loader == loader;
bool operator ==(other) => other != null &&
other.runtimeType == runtimeType &&
other.node == node &&
other.loader == loader;

@override
String toString() => '$runtimeType<${node.toString()}>';
Expand All @@ -197,8 +195,8 @@ abstract class HtmlPageLoaderElement implements PageLoaderElement {
// https://code.google.com/p/dart/issues/detail?id=13902
void _fireKeyPressEvents(Element element, String keys) {
for (int charCode in keys.codeUnits) {
element.dispatchEvent(
new KeyEvent('keypress', charCode: charCode).wrapped);
element
.dispatchEvent(new KeyEvent('keypress', charCode: charCode).wrapped);
}
}
}
Expand Down Expand Up @@ -333,47 +331,48 @@ class _DocumentPageLoaderElement extends HtmlPageLoaderElement {

class _ElementAttributes extends PageLoaderAttributes {
static const _BOOLEAN_ATTRIBUTES = const [
'async',
'autofocus',
'autoplay',
'checked',
'compact',
'complete',
'controls',
'declare',
'defaultchecked',
'defaultselected',
'defer',
'disabled',
'draggable',
'ended',
'formnovalidate',
'hidden',
'indeterminate',
'iscontenteditable',
'ismap',
'itemscope',
'loop',
'multiple',
'muted',
'nohref',
'noresize',
'noshade',
'novalidate',
'nowrap',
'open',
'paused',
'pubdate',
'readonly',
'required',
'reversed',
'scoped',
'seamless',
'seeking',
'selected',
'spellcheck',
'truespeed',
'willvalidate'];
'async',
'autofocus',
'autoplay',
'checked',
'compact',
'complete',
'controls',
'declare',
'defaultchecked',
'defaultselected',
'defer',
'disabled',
'draggable',
'ended',
'formnovalidate',
'hidden',
'indeterminate',
'iscontenteditable',
'ismap',
'itemscope',
'loop',
'multiple',
'muted',
'nohref',
'noresize',
'noshade',
'novalidate',
'nowrap',
'open',
'paused',
'pubdate',
'readonly',
'required',
'reversed',
'scoped',
'seamless',
'seeking',
'selected',
'spellcheck',
'truespeed',
'willvalidate'
];

final Element _node;

Expand Down Expand Up @@ -434,7 +433,7 @@ class _ElementAttributes extends PageLoaderAttributes {
try {
// 7.1
result = reflect(_node).getField(new Symbol(name)).reflectee;
} catch (e) { /* 7.2 - 7.3 ignore and default to attribute value or null*/ }
} catch (e) {/* 7.2 - 7.3 ignore and default to attribute value or null*/}

if (result is bool) {
return result ? 'true' : null;
Expand Down
8 changes: 2 additions & 6 deletions dart/lib/src/annotations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,11 @@ class Returns {
}

class ReturnsList extends Returns {

const ReturnsList(Type type) : super(type);
}

/// Filters element based on visibility.
class WithState extends ElementFilter implements HasFilterFinderOptions {

final bool _displayed;

const WithState._(this._displayed);
Expand Down Expand Up @@ -180,7 +178,6 @@ class _Root implements Finder, HasFilterFinderOptions {
/// Keeps only [PageLoaderElement]s that have the given attribute with the
/// given value.
class WithAttribute extends ElementFilter {

final String name;
final String value;

Expand All @@ -194,7 +191,6 @@ class WithAttribute extends ElementFilter {

/// Keeps only [PageLoaderElement]s that correspond to the given tag.
class IsTag extends ElementFilter {

final String tagName;

const IsTag(this.tagName);
Expand Down Expand Up @@ -316,8 +312,8 @@ class Global implements Finder {

@override
List<PageLoaderElement> findElements(PageLoaderElement context) =>
annotation.findElements(context.loader.globalContext);
annotation.findElements(context.loader.globalContext);

@override
String toString() => '@Global($annotation)';
}
}
48 changes: 18 additions & 30 deletions dart/lib/src/core.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ abstract class BasePageLoader implements PageLoader {
new _ClassInfo(type).getInstance(context, this);

@override
waitForValue(condition(), {Duration timeout: _DEFAULT_WAIT, Duration interval:
_DEFAULT_INTERVAL}) =>
waitForValue(condition(), {Duration timeout: _DEFAULT_WAIT,
Duration interval: _DEFAULT_INTERVAL}) =>
waitFor(condition, isNotNull, timeout: timeout, interval: interval);

@override
waitFor(condition(), Matcher matcher, {Duration timeout: _DEFAULT_WAIT,
Duration interval: _DEFAULT_INTERVAL}) {
waitFor(condition(), Matcher matcher,
{Duration timeout: _DEFAULT_WAIT, Duration interval: _DEFAULT_INTERVAL}) {
var endTime = clock.now.add(timeout);
while (true) {
try {
Expand Down Expand Up @@ -87,9 +87,8 @@ class _Lazy<T> implements Lazy<T> {
}

class _ClassInfo {

static final Map<ClassMirror, _ClassInfo> _classInfoCache = <ClassMirror,
_ClassInfo>{};
static final Map<ClassMirror, _ClassInfo> _classInfoCache =
<ClassMirror, _ClassInfo>{};

final ClassMirror _class;
final List<_FieldInfo> _fields;
Expand Down Expand Up @@ -119,11 +118,7 @@ class _ClassInfo {
}

return new _ClassInfo._(
type,
_fieldInfos(type),
finder,
filters,
finderIsOptional);
type, _fieldInfos(type), finder, filters, finderIsOptional);
});

_ClassInfo._(this._class, this._fields, this._finder, this._filters,
Expand Down Expand Up @@ -213,7 +208,6 @@ class _ClassInfo {
}

abstract class _FieldInfo {

factory _FieldInfo(DeclarationMirror field) {
var finder;
var filters = new List<Filter>();
Expand Down Expand Up @@ -336,7 +330,6 @@ abstract class _FieldInfo {
}

abstract class _FinderFieldInfo implements _FieldInfo {

final Symbol _fieldName;

_FinderFieldInfo(this._fieldName);
Expand All @@ -356,50 +349,46 @@ abstract class _FinderFieldInfo implements _FieldInfo {
}

class _FinderSingleFieldInfo extends _FinderFieldInfo {

final Finder _finder;
final List<Filter> _filters;
final ClassMirror _instanceType;
final bool _isOptional;

_FinderSingleFieldInfo(Symbol fieldName, this._finder, this._filters,
this._instanceType, this._isOptional)
: super(fieldName);
this._instanceType, this._isOptional) : super(fieldName);

@override
calculateFieldValue(PageLoaderElement context, BasePageLoader loader) {
var element = _getElement(context, _finder, _filters, _isOptional);
if (_instanceType.simpleName != #PageLoaderElement &&
element != null) {
if (_instanceType.simpleName != #PageLoaderElement && element != null) {
element = loader._getInstance(_instanceType, element);
}
return element;
}
}

class _FinderListFieldInfo extends _FinderFieldInfo {

final Finder _finder;
final List<Filter> _filters;
final ClassMirror _instanceType;

_FinderListFieldInfo(Symbol fieldName, this._finder, this._filters,
this._instanceType)
_FinderListFieldInfo(
Symbol fieldName, this._finder, this._filters, this._instanceType)
: super(fieldName);

@override
calculateFieldValue(PageLoaderElement context, BasePageLoader loader) {
List elements = _getElements(context, _finder, _filters);
if (_instanceType.simpleName != #PageLoaderElement) {
elements = elements.map(
(element) => loader._getInstance(_instanceType, element)).toList();
elements = elements
.map((element) => loader._getInstance(_instanceType, element))
.toList();
}
return elements;
}
}

class _FinderFunctionFieldInfo extends _FinderFieldInfo {

_FinderFieldInfo _impl;

_FinderFunctionFieldInfo(_FinderFieldInfo impl) : super(impl._fieldName) {
Expand All @@ -420,8 +409,8 @@ class _InjectedPageLoaderFieldInfo extends _FinderFieldInfo {
loader;
}

List<PageLoaderElement> _getElements(PageLoaderElement context, Finder finder,
List<Filter> filters) {
List<PageLoaderElement> _getElements(
PageLoaderElement context, Finder finder, List<Filter> filters) {
List<PageLoaderElement> elements = finder.findElements(context);
for (var filter in filters) {
elements = filter.filter(elements);
Expand All @@ -440,9 +429,8 @@ PageLoaderElement _getElement(PageLoaderElement context, Finder finder,
return null;
}
if (elements.length > 1) {
throw new PageLoaderException(
'Found ${elements.length} elements for '
'finder: $finder and filters: $filters');
throw new PageLoaderException('Found ${elements.length} elements for '
'finder: $finder and filters: $filters');
}
return elements.first;
}
Loading

0 comments on commit 6c83b20

Please sign in to comment.