aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/htmlformelement.rs
diff options
context:
space:
mode:
authorAnshul Jethvani <ajethva@ncsu.edu>2019-12-06 23:41:49 -0500
committerAnshul Jethvani <ajethva@ncsu.edu>2019-12-06 23:48:06 -0500
commita935e00e21c595322cdcabed1f9379a9537966fa (patch)
tree96d26b17a5ec3448911babc0a4c76d01bffcc2a9 /components/script/dom/htmlformelement.rs
parent575f7f5670371da7113fd545a494b3c219bebb29 (diff)
downloadservo-a935e00e21c595322cdcabed1f9379a9537966fa.tar.gz
servo-a935e00e21c595322cdcabed1f9379a9537966fa.zip
sorting partially done for Step 6 of SupportedPropertyNames
Diffstat (limited to 'components/script/dom/htmlformelement.rs')
-rw-r--r--components/script/dom/htmlformelement.rs35
1 files changed, 31 insertions, 4 deletions
diff --git a/components/script/dom/htmlformelement.rs b/components/script/dom/htmlformelement.rs
index 0fafed06f40..43e09fb6061 100644
--- a/components/script/dom/htmlformelement.rs
+++ b/components/script/dom/htmlformelement.rs
@@ -69,6 +69,8 @@ use crate::dom::radionodelist::RadioNodeList;
use std::collections::HashMap;
use time::{now, Duration, Tm};
+// use crate::dom::bindings::codegen::Bindings::NodeBinding::NodeBinding::NodeMethods;
+
#[derive(Clone, Copy, JSTraceable, MallocSizeOf, PartialEq)]
pub struct GenerationId(u32);
@@ -334,12 +336,22 @@ impl HTMLFormElementMethods for HTMLFormElement {
// https://html.spec.whatwg.org/multipage/#the-form-element:supported-property-names
fn SupportedPropertyNames(&self) -> Vec<DOMString> {
// Step 1
+ #[derive(Debug, Eq, Ord, PartialEq, PartialOrd)]
enum SourcedNameSource {
Id,
Name,
Past(Duration),
}
+ impl SourcedNameSource {
+ fn is_past(&self) -> bool {
+ match self {
+ SourcedNameSource::Past(..) => true,
+ _ => false,
+ }
+ }
+ }
+
struct SourcedName {
name: DOMString,
element: DomRoot<Element>,
@@ -403,15 +415,30 @@ impl HTMLFormElementMethods for HTMLFormElement {
let entry = SourcedName {
name: key.clone(),
element: DomRoot::from_ref(&*val.0),
- source: SourcedNameSource::Past(now()-val.1), // calculate difference now()-val.1 to find age
+ source: SourcedNameSource::Past(now() - val.1), // calculate difference now()-val.1 to find age
};
sourcedNamesVec.push(entry);
}
// Step 5
- // TODO need to sort as per spec. This is a partially implemented function.
- // Kindly guide us on how to refine this function further.
- sourcedNamesVec.sort_by(|a, b| a.name.partial_cmp(&b.name).unwrap());
+ // TODO need to sort as per spec. Kindly guide us how to sort by tree order of the element entry of each tuple.
+ // Following gives error as CompareDocumentPosition return u16 and not Ordering.
+ // sourcedNamesVec.sort_by(|a, b|
+ // a.element.upcast::<Node>().CompareDocumentPosition(b.element.upcast::<Node>())
+ // );
+
+ // The remaining part where sorting is to be done by putting entries whose source is id first,
+ // then entries whose source is name, and finally entries whose source is past,
+ // and sorting entries with the same element and source by their age, oldest first.
+ // can be done as follows:
+
+ sourcedNamesVec.sort_by(|a, b| {
+ if a.source.is_past() && b.source.is_past() {
+ b.source.cmp(&a.source)
+ } else {
+ a.source.cmp(&b.source)
+ }
+ });
// Step 6
sourcedNamesVec.retain(|sn| !sn.name.to_string().is_empty());