mirror of
https://github.com/servo/servo.git
synced 2025-07-24 15:50:21 +01:00
Auto merge of #18888 - tigercosmos:xml, r=jdm
fix #18776: use XML fragment serialization for innerHTML in XML documents <!-- Please describe your changes on the following line: --> I am not sure whether my solution is in the right way. @jdm Can you give some advises? --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [ ] `./mach test-tidy` does not report any errors - [ ] These changes fix #18776 (github issue number if applicable). <!-- Either: --> - [ ] There are tests for these changes OR - [ ] These changes do not require tests because _____ <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/18888) <!-- Reviewable:end -->
This commit is contained in:
commit
adb45eb727
4 changed files with 29 additions and 315 deletions
|
@ -120,6 +120,11 @@ use style::values::{CSSFloat, Either};
|
|||
use style::values::{specified, computed};
|
||||
use stylesheet_loader::StylesheetOwner;
|
||||
use task::TaskOnce;
|
||||
use xml5ever::serialize as xmlSerialize;
|
||||
use xml5ever::serialize::SerializeOpts as XmlSerializeOpts;
|
||||
use xml5ever::serialize::TraversalScope as XmlTraversalScope;
|
||||
use xml5ever::serialize::TraversalScope::ChildrenOnly as XmlChildrenOnly;
|
||||
use xml5ever::serialize::TraversalScope::IncludeNode as XmlIncludeNode;
|
||||
|
||||
// TODO: Update focus state when the top-level browsing context gains or loses system focus,
|
||||
// and when the element enters or leaves a browsing context container.
|
||||
|
@ -1004,6 +1009,19 @@ impl Element {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn xmlSerialize(&self, traversal_scope: XmlTraversalScope) -> Fallible<DOMString> {
|
||||
let mut writer = vec![];
|
||||
match xmlSerialize::serialize(&mut writer,
|
||||
&self.upcast::<Node>(),
|
||||
XmlSerializeOpts {
|
||||
traversal_scope: traversal_scope,
|
||||
..Default::default()
|
||||
}) {
|
||||
Ok(()) => Ok(DOMString::from(String::from_utf8(writer).unwrap())),
|
||||
Err(_) => panic!("Cannot serialize element"),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn root_element(&self) -> DomRoot<Element> {
|
||||
if self.node.is_in_doc() {
|
||||
self.upcast::<Node>()
|
||||
|
@ -2047,11 +2065,14 @@ impl ElementMethods for Element {
|
|||
|
||||
/// https://w3c.github.io/DOM-Parsing/#widl-Element-innerHTML
|
||||
fn GetInnerHTML(&self) -> Fallible<DOMString> {
|
||||
// XXX TODO: XML case
|
||||
let qname = QualName::new(self.prefix().clone(),
|
||||
self.namespace().clone(),
|
||||
self.local_name().clone());
|
||||
self.serialize(ChildrenOnly(Some(qname)))
|
||||
if document_from_node(self).is_html_document() {
|
||||
return self.serialize(ChildrenOnly(Some(qname)));
|
||||
} else {
|
||||
return self.xmlSerialize(XmlChildrenOnly(Some(qname)));
|
||||
}
|
||||
}
|
||||
|
||||
/// https://w3c.github.io/DOM-Parsing/#widl-Element-innerHTML
|
||||
|
@ -2071,7 +2092,11 @@ impl ElementMethods for Element {
|
|||
|
||||
// https://dvcs.w3.org/hg/innerhtml/raw-file/tip/index.html#widl-Element-outerHTML
|
||||
fn GetOuterHTML(&self) -> Fallible<DOMString> {
|
||||
self.serialize(IncludeNode)
|
||||
if document_from_node(self).is_html_document() {
|
||||
return self.serialize(IncludeNode);
|
||||
} else {
|
||||
return self.xmlSerialize(XmlIncludeNode);
|
||||
}
|
||||
}
|
||||
|
||||
// https://w3c.github.io/DOM-Parsing/#dom-element-outerhtml
|
||||
|
|
|
@ -1,21 +1,7 @@
|
|||
[innerhtml-03.xhtml]
|
||||
type: testharness
|
||||
[innerHTML in XHTML]
|
||||
expected: FAIL
|
||||
|
||||
[innerHTML in XHTML 1]
|
||||
expected: FAIL
|
||||
|
||||
[innerHTML in XHTML 2]
|
||||
expected: FAIL
|
||||
bug: https://github.com/servo/servo/issues/18776
|
||||
|
||||
[innerHTML in XHTML 3]
|
||||
expected: FAIL
|
||||
|
||||
[innerHTML in XHTML 4]
|
||||
expected: FAIL
|
||||
|
||||
[innerHTML in XHTML 7]
|
||||
expected: FAIL
|
||||
|
||||
|
|
|
@ -1,11 +0,0 @@
|
|||
[outerhtml.html]
|
||||
type: testharness
|
||||
[Template contents should be serialized instead of template element if serializing template element]
|
||||
expected: FAIL
|
||||
|
||||
[Template contents should be serialized instead of template element if serializing template element. Test nested template]
|
||||
expected: FAIL
|
||||
|
||||
[Template contents should be serialized instead of template element if serializing template element. Test serializing whole document]
|
||||
expected: FAIL
|
||||
|
|
@ -1,296 +1,11 @@
|
|||
[outerHTML.html]
|
||||
type: testharness
|
||||
[Node for a]
|
||||
expected: FAIL
|
||||
|
||||
[Node for abbr]
|
||||
expected: FAIL
|
||||
|
||||
[Node for address]
|
||||
expected: FAIL
|
||||
|
||||
[Node for article]
|
||||
expected: FAIL
|
||||
|
||||
[Node for aside]
|
||||
expected: FAIL
|
||||
|
||||
[Node for audio]
|
||||
expected: FAIL
|
||||
|
||||
[Node for b]
|
||||
expected: FAIL
|
||||
|
||||
[Node for bdi]
|
||||
expected: FAIL
|
||||
|
||||
[Node for bdo]
|
||||
expected: FAIL
|
||||
|
||||
[Node for blockquote]
|
||||
expected: FAIL
|
||||
|
||||
[Node for body]
|
||||
expected: FAIL
|
||||
|
||||
[Node for button]
|
||||
expected: FAIL
|
||||
|
||||
[Node for canvas]
|
||||
expected: FAIL
|
||||
|
||||
[Node for caption]
|
||||
expected: FAIL
|
||||
|
||||
[Node for cite]
|
||||
expected: FAIL
|
||||
|
||||
[Node for code]
|
||||
expected: FAIL
|
||||
|
||||
[Node for colgroup]
|
||||
expected: FAIL
|
||||
|
||||
[Node for command]
|
||||
expected: FAIL
|
||||
|
||||
[Node for datalist]
|
||||
expected: FAIL
|
||||
|
||||
[Node for dd]
|
||||
expected: FAIL
|
||||
|
||||
[Node for del]
|
||||
expected: FAIL
|
||||
|
||||
[Node for details]
|
||||
expected: FAIL
|
||||
|
||||
[Node for dfn]
|
||||
expected: FAIL
|
||||
|
||||
[Node for dialog]
|
||||
expected: FAIL
|
||||
|
||||
[Node for div]
|
||||
expected: FAIL
|
||||
|
||||
[Node for dl]
|
||||
expected: FAIL
|
||||
|
||||
[Node for dt]
|
||||
expected: FAIL
|
||||
|
||||
[Node for em]
|
||||
expected: FAIL
|
||||
|
||||
[Node for fieldset]
|
||||
expected: FAIL
|
||||
|
||||
[Node for figcaption]
|
||||
expected: FAIL
|
||||
|
||||
[Node for figure]
|
||||
expected: FAIL
|
||||
|
||||
[Node for footer]
|
||||
expected: FAIL
|
||||
|
||||
[Node for form]
|
||||
expected: FAIL
|
||||
|
||||
[Node for h1]
|
||||
expected: FAIL
|
||||
|
||||
[Node for h2]
|
||||
expected: FAIL
|
||||
|
||||
[Node for h3]
|
||||
expected: FAIL
|
||||
|
||||
[Node for h4]
|
||||
expected: FAIL
|
||||
|
||||
[Node for h5]
|
||||
expected: FAIL
|
||||
|
||||
[Node for h6]
|
||||
expected: FAIL
|
||||
|
||||
[Node for head]
|
||||
expected: FAIL
|
||||
|
||||
[Node for header]
|
||||
expected: FAIL
|
||||
|
||||
[Node for hgroup]
|
||||
expected: FAIL
|
||||
|
||||
[Node for html]
|
||||
expected: FAIL
|
||||
|
||||
[Node for i]
|
||||
expected: FAIL
|
||||
|
||||
[Node for iframe]
|
||||
expected: FAIL
|
||||
|
||||
[Node for ins]
|
||||
expected: FAIL
|
||||
|
||||
[Node for kbd]
|
||||
expected: FAIL
|
||||
|
||||
[Node for label]
|
||||
expected: FAIL
|
||||
|
||||
[Node for legend]
|
||||
expected: FAIL
|
||||
|
||||
[Node for li]
|
||||
expected: FAIL
|
||||
|
||||
[Node for map]
|
||||
expected: FAIL
|
||||
|
||||
[Node for mark]
|
||||
expected: FAIL
|
||||
|
||||
[Node for menu]
|
||||
expected: FAIL
|
||||
|
||||
[Node for meter]
|
||||
expected: FAIL
|
||||
|
||||
[Node for nav]
|
||||
expected: FAIL
|
||||
|
||||
[Node for noscript]
|
||||
expected: FAIL
|
||||
|
||||
[Node for object]
|
||||
expected: FAIL
|
||||
|
||||
[Node for ol]
|
||||
expected: FAIL
|
||||
|
||||
[Node for optgroup]
|
||||
expected: FAIL
|
||||
|
||||
[Node for option]
|
||||
expected: FAIL
|
||||
|
||||
[Node for output]
|
||||
expected: FAIL
|
||||
|
||||
[Node for p]
|
||||
expected: FAIL
|
||||
|
||||
[Node for pre]
|
||||
expected: FAIL
|
||||
|
||||
[Node for progress]
|
||||
expected: FAIL
|
||||
|
||||
[Node for q]
|
||||
expected: FAIL
|
||||
|
||||
[Node for rp]
|
||||
expected: FAIL
|
||||
|
||||
[Node for rt]
|
||||
expected: FAIL
|
||||
|
||||
[Node for ruby]
|
||||
expected: FAIL
|
||||
|
||||
[Node for s]
|
||||
expected: FAIL
|
||||
|
||||
[Node for samp]
|
||||
expected: FAIL
|
||||
|
||||
[Node for script]
|
||||
expected: FAIL
|
||||
|
||||
[Node for section]
|
||||
expected: FAIL
|
||||
|
||||
[Node for select]
|
||||
expected: FAIL
|
||||
|
||||
[Node for small]
|
||||
expected: FAIL
|
||||
|
||||
[Node for span]
|
||||
expected: FAIL
|
||||
|
||||
[Node for strong]
|
||||
expected: FAIL
|
||||
|
||||
[Node for style]
|
||||
expected: FAIL
|
||||
|
||||
[Node for sub]
|
||||
expected: FAIL
|
||||
|
||||
[Node for summary]
|
||||
expected: FAIL
|
||||
|
||||
[Node for sup]
|
||||
expected: FAIL
|
||||
|
||||
[Node for table]
|
||||
expected: FAIL
|
||||
|
||||
[Node for tbody]
|
||||
expected: FAIL
|
||||
|
||||
[Node for td]
|
||||
expected: FAIL
|
||||
|
||||
[Node for textarea]
|
||||
expected: FAIL
|
||||
|
||||
[Node for tfoot]
|
||||
expected: FAIL
|
||||
|
||||
[Node for th]
|
||||
expected: FAIL
|
||||
|
||||
[Node for thead]
|
||||
expected: FAIL
|
||||
|
||||
[Node for time]
|
||||
expected: FAIL
|
||||
|
||||
[Node for title]
|
||||
expected: FAIL
|
||||
|
||||
[Node for tr]
|
||||
expected: FAIL
|
||||
|
||||
[Node for u]
|
||||
expected: FAIL
|
||||
|
||||
[Node for ul]
|
||||
expected: FAIL
|
||||
|
||||
[Node for var]
|
||||
expected: FAIL
|
||||
|
||||
[Node for video]
|
||||
expected: FAIL
|
||||
|
||||
[Node for data]
|
||||
expected: FAIL
|
||||
|
||||
[Node for area]
|
||||
expected: FAIL
|
||||
|
||||
[Node for base]
|
||||
expected: FAIL
|
||||
|
||||
|
||||
[Node for br]
|
||||
expected: FAIL
|
||||
|
||||
|
@ -329,4 +44,3 @@
|
|||
|
||||
[Node for wbr]
|
||||
expected: FAIL
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue