Skip to content

Commit

Permalink
Revert "Refined types for most HtmlElement factory constructors"
Browse files Browse the repository at this point in the history
Need to fix ShadowElement

TBR=alanknight@google.com

Review-Url: https://codereview.chromium.org/2710323004 .
  • Loading branch information
rakudrama committed Feb 24, 2017
1 parent 68a102c commit 963df1e
Show file tree
Hide file tree
Showing 12 changed files with 176 additions and 229 deletions.
177 changes: 86 additions & 91 deletions sdk/lib/html/dart2js/html_dart2js.dart

Large diffs are not rendered by default.

77 changes: 36 additions & 41 deletions sdk/lib/html/dartium/html_dartium.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5633,7 +5633,7 @@ class CssStyleDeclaration extends DartHtmlDomObject with
factory CssStyleDeclaration() => new CssStyleDeclaration.css('');

factory CssStyleDeclaration.css(String css) {
final style = new DivElement().style;
final style = new Element.tag('div').style;
style.cssText = css;
return style;
}
Expand Down Expand Up @@ -11056,7 +11056,7 @@ class DocumentFragment extends Node implements NonElementParentNode, ParentNode


String get innerHtml {
final e = new DivElement();
final e = new Element.tag("div");
e.append(this.clone(true));
return e.innerHtml;
}
Expand Down Expand Up @@ -13753,14 +13753,9 @@ class Element extends Node implements NonDocumentTypeChildNode, GlobalEventHandl
* var myElement = new Element.tag('unknownTag');
* print(myElement is UnknownElement); // 'true'
*
* For standard elements it is better to use the element type constructors:
*
* For standard elements it is more preferable to use the type constructors:
* var element = new DivElement();
*
* It is better to use e.g `new CanvasElement()` because the type of the
* expression is `CanvasElement`, whereas the type of `Element.tag` is the
* less specific `Element`.
*
* See also:
*
* * [isTagSupported]
Expand All @@ -13770,147 +13765,147 @@ class Element extends Node implements NonDocumentTypeChildNode, GlobalEventHandl

/// Creates a new `<a>` element.
///
/// This is equivalent to calling `new Element.tag('a')`.
factory Element.a() => new AnchorElement();
/// This is identical to calling `new Element.tag('a')`.
factory Element.a() => new Element.tag('a');

/// Creates a new `<article>` element.
///
/// This is equivalent to calling `new Element.tag('article')`.
/// This is identical to calling `new Element.tag('article')`.
factory Element.article() => new Element.tag('article');

/// Creates a new `<aside>` element.
///
/// This is equivalent to calling `new Element.tag('aside')`.
/// This is identical to calling `new Element.tag('aside')`.
factory Element.aside() => new Element.tag('aside');

/// Creates a new `<audio>` element.
///
/// This is equivalent to calling `new Element.tag('audio')`.
/// This is identical to calling `new Element.tag('audio')`.
factory Element.audio() => new Element.tag('audio');

/// Creates a new `<br>` element.
///
/// This is equivalent to calling `new Element.tag('br')`.
factory Element.br() => new BRElement();
/// This is identical to calling `new Element.tag('br')`.
factory Element.br() => new Element.tag('br');

/// Creates a new `<canvas>` element.
///
/// This is equivalent to calling `new Element.tag('canvas')`.
factory Element.canvas() => new CanvasElement();
/// This is identical to calling `new Element.tag('canvas')`.
factory Element.canvas() => new Element.tag('canvas');

/// Creates a new `<div>` element.
///
/// This is equivalent to calling `new Element.tag('div')`.
factory Element.div() => new DivElement();
/// This is identical to calling `new Element.tag('div')`.
factory Element.div() => new Element.tag('div');

/// Creates a new `<footer>` element.
///
/// This is equivalent to calling `new Element.tag('footer')`.
/// This is identical to calling `new Element.tag('footer')`.
factory Element.footer() => new Element.tag('footer');

/// Creates a new `<header>` element.
///
/// This is equivalent to calling `new Element.tag('header')`.
/// This is identical to calling `new Element.tag('header')`.
factory Element.header() => new Element.tag('header');

/// Creates a new `<hr>` element.
///
/// This is equivalent to calling `new Element.tag('hr')`.
/// This is identical to calling `new Element.tag('hr')`.
factory Element.hr() => new Element.tag('hr');

/// Creates a new `<iframe>` element.
///
/// This is equivalent to calling `new Element.tag('iframe')`.
/// This is identical to calling `new Element.tag('iframe')`.
factory Element.iframe() => new Element.tag('iframe');

/// Creates a new `<img>` element.
///
/// This is equivalent to calling `new Element.tag('img')`.
/// This is identical to calling `new Element.tag('img')`.
factory Element.img() => new Element.tag('img');

/// Creates a new `<li>` element.
///
/// This is equivalent to calling `new Element.tag('li')`.
/// This is identical to calling `new Element.tag('li')`.
factory Element.li() => new Element.tag('li');

/// Creates a new `<nav>` element.
///
/// This is equivalent to calling `new Element.tag('nav')`.
/// This is identical to calling `new Element.tag('nav')`.
factory Element.nav() => new Element.tag('nav');

/// Creates a new `<ol>` element.
///
/// This is equivalent to calling `new Element.tag('ol')`.
/// This is identical to calling `new Element.tag('ol')`.
factory Element.ol() => new Element.tag('ol');

/// Creates a new `<option>` element.
///
/// This is equivalent to calling `new Element.tag('option')`.
/// This is identical to calling `new Element.tag('option')`.
factory Element.option() => new Element.tag('option');

/// Creates a new `<p>` element.
///
/// This is equivalent to calling `new Element.tag('p')`.
/// This is identical to calling `new Element.tag('p')`.
factory Element.p() => new Element.tag('p');

/// Creates a new `<pre>` element.
///
/// This is equivalent to calling `new Element.tag('pre')`.
/// This is identical to calling `new Element.tag('pre')`.
factory Element.pre() => new Element.tag('pre');

/// Creates a new `<section>` element.
///
/// This is equivalent to calling `new Element.tag('section')`.
/// This is identical to calling `new Element.tag('section')`.
factory Element.section() => new Element.tag('section');

/// Creates a new `<select>` element.
///
/// This is equivalent to calling `new Element.tag('select')`.
/// This is identical to calling `new Element.tag('select')`.
factory Element.select() => new Element.tag('select');

/// Creates a new `<span>` element.
///
/// This is equivalent to calling `new Element.tag('span')`.
/// This is identical to calling `new Element.tag('span')`.
factory Element.span() => new Element.tag('span');

/// Creates a new `<svg>` element.
///
/// This is equivalent to calling `new Element.tag('svg')`.
/// This is identical to calling `new Element.tag('svg')`.
factory Element.svg() => new Element.tag('svg');

/// Creates a new `<table>` element.
///
/// This is equivalent to calling `new Element.tag('table')`.
/// This is identical to calling `new Element.tag('table')`.
factory Element.table() => new Element.tag('table');

/// Creates a new `<td>` element.
///
/// This is equivalent to calling `new Element.tag('td')`.
/// This is identical to calling `new Element.tag('td')`.
factory Element.td() => new Element.tag('td');

/// Creates a new `<textarea>` element.
///
/// This is equivalent to calling `new Element.tag('textarea')`.
/// This is identical to calling `new Element.tag('textarea')`.
factory Element.textarea() => new Element.tag('textarea');

/// Creates a new `<th>` element.
///
/// This is equivalent to calling `new Element.tag('th')`.
/// This is identical to calling `new Element.tag('th')`.
factory Element.th() => new Element.tag('th');

/// Creates a new `<tr>` element.
///
/// This is equivalent to calling `new Element.tag('tr')`.
/// This is identical to calling `new Element.tag('tr')`.
factory Element.tr() => new Element.tag('tr');

/// Creates a new `<ul>` element.
///
/// This is equivalent to calling `new Element.tag('ul')`.
/// This is identical to calling `new Element.tag('ul')`.
factory Element.ul() => new Element.tag('ul');

/// Creates a new `<video>` element.
///
/// This is equivalent to calling `new Element.tag('video')`.
/// This is identical to calling `new Element.tag('video')`.
factory Element.video() => new Element.tag('video');

/**
Expand Down
4 changes: 2 additions & 2 deletions sdk/lib/svg/dart2js/svg_dart2js.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4722,14 +4722,14 @@ class SvgElement extends Element implements GlobalEventHandlers {
}

String get outerHtml {
final container = new DivElement();
final container = new Element.tag("div");
final SvgElement cloned = this.clone(true);
container.children.add(cloned);
return container.innerHtml;
}

String get innerHtml {
final container = new DivElement();
final container = new Element.tag("div");
final SvgElement cloned = this.clone(true);
container.children.addAll(cloned.children);
return container.innerHtml;
Expand Down
4 changes: 2 additions & 2 deletions sdk/lib/svg/dartium/svg_dartium.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6126,14 +6126,14 @@ class SvgElement extends Element implements GlobalEventHandlers {
}

String get outerHtml {
final container = new DivElement();
final container = new Element.tag("div");
final SvgElement cloned = this.clone(true);
container.children.add(cloned);
return container.innerHtml;
}

String get innerHtml {
final container = new DivElement();
final container = new Element.tag("div");
final SvgElement cloned = this.clone(true);
container.children.addAll(cloned.children);
return container.innerHtml;
Expand Down
2 changes: 1 addition & 1 deletion tools/dom/scripts/css_code_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def GenerateCssTemplateFile():
factory $CLASSNAME() => new CssStyleDeclaration.css('');
factory $CLASSNAME.css(String css) {
final style = new DivElement().style;
final style = new Element.tag('div').style;
style.cssText = css;
return style;
}
Expand Down
20 changes: 11 additions & 9 deletions tools/dom/scripts/htmldartgenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,30 +572,32 @@ def InputType(type_name):
# TODO(antonm): use common dispatcher generation for this case as well.
has_optional = any(param_info.is_optional
for param_info in constructor_info.param_infos)
factory_call = self.MakeFactoryCall(
factory_name, factory_constructor_name, factory_parameters,
constructor_info)

if not has_optional:
self._members_emitter.Emit(
'\n $(METADATA)'
'factory $CTOR($PARAMS) => '
'$FACTORY_CALL;\n',
'$FACTORY.$CTOR_FACTORY_NAME($FACTORY_PARAMS);\n',
CTOR=constructor_info._ConstructorFullName(self._DartType),
PARAMS=constructor_info.ParametersAsDeclaration(InputType),
FACTORY_CALL=factory_call,
METADATA=metadata)
FACTORY=factory_name,
METADATA=metadata,
CTOR_FACTORY_NAME=factory_constructor_name,
FACTORY_PARAMS=factory_parameters)
else:
inits = self._members_emitter.Emit(
'\n $(METADATA)'
'factory $CONSTRUCTOR($PARAMS) {\n'
' $CONSTRUCTOR e = $FACTORY_CALL;\n'
' $CONSTRUCTOR e = $FACTORY.$CTOR_FACTORY_NAME($FACTORY_PARAMS);\n'
'$!INITS'
' return e;\n'
' }\n',
CONSTRUCTOR=constructor_info._ConstructorFullName(self._DartType),
METADATA=metadata,
FACTORY_CALL=factory_call,
PARAMS=constructor_info.ParametersAsDeclaration(InputType))
FACTORY=factory_name,
CTOR_FACTORY_NAME=factory_constructor_name,
PARAMS=constructor_info.ParametersAsDeclaration(InputType),
FACTORY_PARAMS=factory_parameters)

for index, param_info in enumerate(constructor_info.param_infos):
if param_info.is_optional:
Expand Down
33 changes: 0 additions & 33 deletions tools/dom/scripts/systemhtml.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,19 +463,6 @@ def ElemSupportStr(tagName):
else ElemSupportStr(_html_element_constructors[key])) for key in
_js_support_checks_basic_element_with_constructors +
_js_support_checks_additional_element).items())


# JavaScript element class names of elements for which createElement does not
# always return exactly the right element, either because it might not be
# supported, or some browser does something weird.
_js_unreliable_element_factories = set(
_js_support_checks_basic_element_with_constructors +
_js_support_checks_additional_element +
[
'HTMLEmbedElement',
'HTMLObjectElement',
])

# ------------------------------------------------------------------------------

class HtmlDartInterfaceGenerator(object):
Expand Down Expand Up @@ -817,26 +804,6 @@ def GenerateCustomFactory(self, constructor_info):
# Custom factory will be taken from the template.
return self._interface.doc_js_name in _js_custom_constructors

def MakeFactoryCall(self, factory, method, arguments, constructor_info):
if factory is 'document' and method is 'createElement' \
and not ',' in arguments \
and not self._HasUnreliableFactoryConstructor():
return emitter.Format(
"JS('returns:$INTERFACE_NAME;creates:$INTERFACE_NAME;new:true',"
" '#.$METHOD(#)', $FACTORY, $ARGUMENTS)",
INTERFACE_NAME=self._interface_type_info.interface_name(),
FACTORY=factory,
METHOD=method,
ARGUMENTS=arguments)
return emitter.Format(
'$FACTORY.$METHOD($ARGUMENTS)',
FACTORY=factory,
METHOD=method,
ARGUMENTS=arguments)

def _HasUnreliableFactoryConstructor(self):
return self._interface.doc_js_name in _js_unreliable_element_factories

def IsConstructorArgumentOptional(self, argument):
return argument.optional

Expand Down
7 changes: 0 additions & 7 deletions tools/dom/scripts/systemnative.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,13 +308,6 @@ def GenerateCustomFactory(self, constructor_info):
def IsConstructorArgumentOptional(self, argument):
return IsOptional(argument)

def MakeFactoryCall(self, factory, method, arguments, constructor_info):
return emitter.Format(
'$FACTORY.$METHOD($ARGUMENTS)',
FACTORY=factory,
METHOD=method,
ARGUMENTS=arguments)

def EmitStaticFactoryOverload(self, constructor_info, name, arguments):
constructor_callback_cpp_name = name + 'constructorCallback'
self._EmitConstructorInfrastructure(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ $(ANNOTATIONS)$(NATIVESPEC)$(CLASS_MODIFIERS)class $CLASSNAME $EXTENDS with
factory $CLASSNAME() => new CssStyleDeclaration.css('');

factory $CLASSNAME.css(String css) {
final style = new DivElement().style;
final style = new Element.tag('div').style;
style.cssText = css;
return style;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ $endif


String get innerHtml {
final e = new DivElement();
final e = new Element.tag("div");
e.append(this.clone(true));
return e.innerHtml;
}
Expand Down
Loading

0 comments on commit 963df1e

Please sign in to comment.