Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.

Added support for resetStyleInheritance and applyAuthorStyles on shadow root #20

Merged
merged 1 commit into from
Jun 24, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/block.dart
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,10 @@ class ComponentWrapper {
ComponentWrapper(this.directiveRef, this.controller, this.elementRoot, this.parser, $compiler, $http) {
var directive = directiveRef.directive;
var shadowRoot = elementRoot.createShadowRoot();
shadowRoot.applyAuthorStyles =
directive.$shadowRootOptions.$applyAuthorStyles;
shadowRoot.resetStyleInheritance =
directive.$shadowRootOptions.$resetStyleInheritance;

var styleData = '';
if (directive.$cssUrl != null) {
Expand Down
31 changes: 23 additions & 8 deletions lib/directive.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class Directive {
String $cssUrl;
Map<String, String> $map;
String $visibility;
ShadowRootOptions $shadowRootOptions;

bool isComponent = false;
bool isStructural = false;
Expand Down Expand Up @@ -46,15 +47,10 @@ class Directive {
$template = reflectStaticField(type, '\$template');
$templateUrl = reflectStaticField(type, '\$templateUrl');
$cssUrl = reflectStaticField(type, '\$cssUrl');
$priority = reflectStaticField(type, '\$priority');
$visibility = reflectStaticField(type, '\$visibility');
if ($visibility == null) {
$visibility = DirectiveVisibility.LOCAL;
}
$priority = _defaultIfNull(reflectStaticField(type, '\$priority'), 0);
$visibility = _defaultIfNull(
reflectStaticField(type, '\$visibility'), DirectiveVisibility.LOCAL);
$map = reflectStaticField(type, '\$map');
if ($priority == null) {
$priority = 0;
}
isStructural = $transclude != null;
var $selector = reflectStaticField(type, r'$selector');
if ($selector != null) {
Expand All @@ -63,9 +59,17 @@ class Directive {
if (isComponent && $map == null) {
$map = new Map<String, String>();
}
if (isComponent) {
$shadowRootOptions = _defaultIfNull(
reflectStaticField(type, '\$shadowRootOptions'),
new ShadowRootOptions());
}
}
}

dynamic _defaultIfNull(dynamic value, dynamic defaultValue) =>
value == null ? defaultValue : value;

class DirectiveRef {
dom.Node element;
String selector;
Expand Down Expand Up @@ -119,6 +123,17 @@ abstract class DirectiveVisibility {
static const String DIRECT_CHILDREN = 'direct_children';
}

/**
* See:
* http://www.html5rocks.com/en/tutorials/webcomponents/shadowdom-201/#toc-style-inheriting
*/
class ShadowRootOptions {
bool $applyAuthorStyles = false;
bool $resetStyleInheritance = false;
ShadowRootOptions([this.$applyAuthorStyles = false,
this.$resetStyleInheritance = false]);
}

class Controller {

}
19 changes: 19 additions & 0 deletions test/directive_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ class ExplicitNullTranscludeDirective {
static var $transclude = null;
}

class WithDefaultShadowRootOptionsComponent {
}

class WithCustomShadowRootOptionsComponent {
static var $shadowRootOptions = new ShadowRootOptions(true, true);
}

main() {
describe('directive factory', () {
it('should guess the directive name correctly', () {
Expand All @@ -38,5 +45,17 @@ main() {
Directive factory = new Directive(ExplicitNullTranscludeDirective);
expect(factory.$transclude).toEqual(null);
});

it('should default \$shadowRootOptions to false/false', () {
Directive factory = new Directive(WithDefaultShadowRootOptionsComponent);
expect(factory.$shadowRootOptions.$applyAuthorStyles, isFalse);
expect(factory.$shadowRootOptions.$resetStyleInheritance, isFalse);
});

it('should override \$shadowRootOptions with values provided by component type', () {
Directive factory = new Directive(WithCustomShadowRootOptionsComponent);
expect(factory.$shadowRootOptions.$applyAuthorStyles, isTrue);
expect(factory.$shadowRootOptions.$resetStyleInheritance, isTrue);
});
});
}