mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Format script component
This commit is contained in:
parent
2ca7a13473
commit
c37a345dc9
357 changed files with 25485 additions and 18076 deletions
|
@ -40,29 +40,38 @@ pub struct HTMLAnchorElement {
|
|||
}
|
||||
|
||||
impl HTMLAnchorElement {
|
||||
fn new_inherited(local_name: LocalName,
|
||||
prefix: Option<Prefix>,
|
||||
document: &Document) -> HTMLAnchorElement {
|
||||
fn new_inherited(
|
||||
local_name: LocalName,
|
||||
prefix: Option<Prefix>,
|
||||
document: &Document,
|
||||
) -> HTMLAnchorElement {
|
||||
HTMLAnchorElement {
|
||||
htmlelement:
|
||||
HTMLElement::new_inherited(local_name, prefix, document),
|
||||
htmlelement: HTMLElement::new_inherited(local_name, prefix, document),
|
||||
rel_list: Default::default(),
|
||||
url: DomRefCell::new(None),
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(unrooted_must_root)]
|
||||
pub fn new(local_name: LocalName,
|
||||
prefix: Option<Prefix>,
|
||||
document: &Document) -> DomRoot<HTMLAnchorElement> {
|
||||
Node::reflect_node(Box::new(HTMLAnchorElement::new_inherited(local_name, prefix, document)),
|
||||
document,
|
||||
HTMLAnchorElementBinding::Wrap)
|
||||
pub fn new(
|
||||
local_name: LocalName,
|
||||
prefix: Option<Prefix>,
|
||||
document: &Document,
|
||||
) -> DomRoot<HTMLAnchorElement> {
|
||||
Node::reflect_node(
|
||||
Box::new(HTMLAnchorElement::new_inherited(
|
||||
local_name, prefix, document,
|
||||
)),
|
||||
document,
|
||||
HTMLAnchorElementBinding::Wrap,
|
||||
)
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#concept-hyperlink-url-set
|
||||
fn set_url(&self) {
|
||||
let attribute = self.upcast::<Element>().get_attribute(&ns!(), &local_name!("href"));
|
||||
let attribute = self
|
||||
.upcast::<Element>()
|
||||
.get_attribute(&ns!(), &local_name!("href"));
|
||||
*self.url.borrow_mut() = attribute.and_then(|attribute| {
|
||||
let document = document_from_node(self);
|
||||
document.base_url().join(&attribute.value()).ok()
|
||||
|
@ -83,7 +92,8 @@ impl HTMLAnchorElement {
|
|||
|
||||
// https://html.spec.whatwg.org/multipage/#update-href
|
||||
fn update_href(&self, url: DOMString) {
|
||||
self.upcast::<Element>().set_string_attribute(&local_name!("href"), url);
|
||||
self.upcast::<Element>()
|
||||
.set_string_attribute(&local_name!("href"), url);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -95,7 +105,10 @@ impl VirtualMethods for HTMLAnchorElement {
|
|||
fn parse_plain_attribute(&self, name: &LocalName, value: DOMString) -> AttrValue {
|
||||
match name {
|
||||
&local_name!("rel") => AttrValue::from_serialized_tokenlist(value.into()),
|
||||
_ => self.super_type().unwrap().parse_plain_attribute(name, value),
|
||||
_ => self
|
||||
.super_type()
|
||||
.unwrap()
|
||||
.parse_plain_attribute(name, value),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -116,12 +129,14 @@ impl HTMLAnchorElementMethods for HTMLAnchorElement {
|
|||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-a-rel
|
||||
fn SetRel(&self, rel: DOMString) {
|
||||
self.upcast::<Element>().set_tokenlist_attribute(&local_name!("rel"), rel);
|
||||
self.upcast::<Element>()
|
||||
.set_tokenlist_attribute(&local_name!("rel"), rel);
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-a-rellist
|
||||
fn RelList(&self) -> DomRoot<DOMTokenList> {
|
||||
self.rel_list.or_init(|| DOMTokenList::new(self.upcast(), &local_name!("rel")))
|
||||
self.rel_list
|
||||
.or_init(|| DOMTokenList::new(self.upcast(), &local_name!("rel")))
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-a-coords
|
||||
|
@ -165,7 +180,7 @@ impl HTMLAnchorElementMethods for HTMLAnchorElement {
|
|||
Some(ref url) => {
|
||||
// Steps 3-4.
|
||||
UrlHelper::Hash(url)
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -183,7 +198,7 @@ impl HTMLAnchorElementMethods for HTMLAnchorElement {
|
|||
Some(url) => {
|
||||
UrlHelper::SetHash(url, value);
|
||||
DOMString::from(url.as_str())
|
||||
}
|
||||
},
|
||||
};
|
||||
// Step 6.
|
||||
self.update_href(url);
|
||||
|
@ -204,7 +219,7 @@ impl HTMLAnchorElementMethods for HTMLAnchorElement {
|
|||
// Steps 4-5.
|
||||
UrlHelper::Host(url)
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -222,7 +237,7 @@ impl HTMLAnchorElementMethods for HTMLAnchorElement {
|
|||
Some(url) => {
|
||||
UrlHelper::SetHost(url, value);
|
||||
DOMString::from(url.as_str())
|
||||
}
|
||||
},
|
||||
};
|
||||
// Step 5.
|
||||
self.update_href(url);
|
||||
|
@ -239,7 +254,7 @@ impl HTMLAnchorElementMethods for HTMLAnchorElement {
|
|||
Some(ref url) => {
|
||||
// Step 4.
|
||||
UrlHelper::Hostname(url)
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -257,7 +272,7 @@ impl HTMLAnchorElementMethods for HTMLAnchorElement {
|
|||
Some(url) => {
|
||||
UrlHelper::SetHostname(url, value);
|
||||
DOMString::from(url.as_str())
|
||||
}
|
||||
},
|
||||
};
|
||||
// Step 5.
|
||||
self.update_href(url);
|
||||
|
@ -270,7 +285,10 @@ impl HTMLAnchorElementMethods for HTMLAnchorElement {
|
|||
|
||||
USVString(match *self.url.borrow() {
|
||||
None => {
|
||||
match self.upcast::<Element>().get_attribute(&ns!(), &local_name!("href")) {
|
||||
match self
|
||||
.upcast::<Element>()
|
||||
.get_attribute(&ns!(), &local_name!("href"))
|
||||
{
|
||||
// Step 3.
|
||||
None => String::new(),
|
||||
// Step 4.
|
||||
|
@ -284,8 +302,8 @@ impl HTMLAnchorElementMethods for HTMLAnchorElement {
|
|||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-hyperlink-href
|
||||
fn SetHref(&self, value: USVString) {
|
||||
self.upcast::<Element>().set_string_attribute(&local_name!("href"),
|
||||
DOMString::from_string(value.0));
|
||||
self.upcast::<Element>()
|
||||
.set_string_attribute(&local_name!("href"), DOMString::from_string(value.0));
|
||||
self.set_url();
|
||||
}
|
||||
|
||||
|
@ -315,13 +333,13 @@ impl HTMLAnchorElementMethods for HTMLAnchorElement {
|
|||
// Step 3.
|
||||
None => USVString(String::new()),
|
||||
// Steps 3-4.
|
||||
Some(ref url) => UrlHelper::Password(url)
|
||||
Some(ref url) => UrlHelper::Password(url),
|
||||
}
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-hyperlink-password
|
||||
fn SetPassword(&self, value: USVString) {
|
||||
// Step 1.
|
||||
// Step 1.
|
||||
self.reinitialize_url();
|
||||
|
||||
// Step 2.
|
||||
|
@ -333,7 +351,7 @@ impl HTMLAnchorElementMethods for HTMLAnchorElement {
|
|||
Some(url) => {
|
||||
UrlHelper::SetPassword(url, value);
|
||||
DOMString::from(url.as_str())
|
||||
}
|
||||
},
|
||||
};
|
||||
// Step 5.
|
||||
self.update_href(url);
|
||||
|
@ -341,14 +359,14 @@ impl HTMLAnchorElementMethods for HTMLAnchorElement {
|
|||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-hyperlink-pathname
|
||||
fn Pathname(&self) -> USVString {
|
||||
// Step 1.
|
||||
// Step 1.
|
||||
self.reinitialize_url();
|
||||
|
||||
match *self.url.borrow() {
|
||||
// Step 3.
|
||||
None => USVString(String::new()),
|
||||
// Steps 4-5.
|
||||
Some(ref url) => UrlHelper::Pathname(url)
|
||||
Some(ref url) => UrlHelper::Pathname(url),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -366,7 +384,7 @@ impl HTMLAnchorElementMethods for HTMLAnchorElement {
|
|||
Some(url) => {
|
||||
UrlHelper::SetPathname(url, value);
|
||||
DOMString::from(url.as_str())
|
||||
}
|
||||
},
|
||||
};
|
||||
// Step 6.
|
||||
self.update_href(url);
|
||||
|
@ -381,7 +399,7 @@ impl HTMLAnchorElementMethods for HTMLAnchorElement {
|
|||
// Step 3.
|
||||
None => USVString(String::new()),
|
||||
// Step 4.
|
||||
Some(ref url) => UrlHelper::Port(url)
|
||||
Some(ref url) => UrlHelper::Port(url),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -392,15 +410,17 @@ impl HTMLAnchorElementMethods for HTMLAnchorElement {
|
|||
|
||||
// Step 3.
|
||||
let url = match self.url.borrow_mut().as_mut() {
|
||||
Some(ref url) if url.host().is_none() ||
|
||||
url.cannot_be_a_base() ||
|
||||
url.scheme() == "file" => return,
|
||||
Some(ref url)
|
||||
if url.host().is_none() || url.cannot_be_a_base() || url.scheme() == "file" =>
|
||||
{
|
||||
return
|
||||
},
|
||||
None => return,
|
||||
// Step 4.
|
||||
Some(url) => {
|
||||
UrlHelper::SetPort(url, value);
|
||||
DOMString::from(url.as_str())
|
||||
}
|
||||
},
|
||||
};
|
||||
// Step 5.
|
||||
self.update_href(url);
|
||||
|
@ -415,7 +435,7 @@ impl HTMLAnchorElementMethods for HTMLAnchorElement {
|
|||
// Step 2.
|
||||
None => USVString(":".to_owned()),
|
||||
// Step 3.
|
||||
Some(ref url) => UrlHelper::Protocol(url)
|
||||
Some(ref url) => UrlHelper::Protocol(url),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -431,7 +451,7 @@ impl HTMLAnchorElementMethods for HTMLAnchorElement {
|
|||
Some(url) => {
|
||||
UrlHelper::SetProtocol(url, value);
|
||||
DOMString::from(url.as_str())
|
||||
}
|
||||
},
|
||||
};
|
||||
// Step 4.
|
||||
self.update_href(url);
|
||||
|
@ -446,7 +466,7 @@ impl HTMLAnchorElementMethods for HTMLAnchorElement {
|
|||
// Step 2.
|
||||
None => USVString(String::new()),
|
||||
// Step 3.
|
||||
Some(ref url) => UrlHelper::Search(url)
|
||||
Some(ref url) => UrlHelper::Search(url),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -465,7 +485,7 @@ impl HTMLAnchorElementMethods for HTMLAnchorElement {
|
|||
Some(url) => {
|
||||
UrlHelper::SetSearch(url, value);
|
||||
DOMString::from(url.as_str())
|
||||
}
|
||||
},
|
||||
};
|
||||
// Step 6.
|
||||
self.update_href(url);
|
||||
|
@ -480,7 +500,7 @@ impl HTMLAnchorElementMethods for HTMLAnchorElement {
|
|||
// Step 2.
|
||||
None => USVString(String::new()),
|
||||
// Step 3.
|
||||
Some(ref url) => UrlHelper::Username(url)
|
||||
Some(ref url) => UrlHelper::Username(url),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -498,7 +518,7 @@ impl HTMLAnchorElementMethods for HTMLAnchorElement {
|
|||
Some(url) => {
|
||||
UrlHelper::SetUsername(url, value);
|
||||
DOMString::from(url.as_str())
|
||||
}
|
||||
},
|
||||
};
|
||||
// Step 5.
|
||||
self.update_href(url);
|
||||
|
@ -524,15 +544,12 @@ impl Activatable for HTMLAnchorElement {
|
|||
self.upcast::<Element>().has_attribute(&local_name!("href"))
|
||||
}
|
||||
|
||||
|
||||
//TODO:https://html.spec.whatwg.org/multipage/#the-a-element
|
||||
fn pre_click_activation(&self) {
|
||||
}
|
||||
fn pre_click_activation(&self) {}
|
||||
|
||||
//TODO:https://html.spec.whatwg.org/multipage/#the-a-element
|
||||
// https://html.spec.whatwg.org/multipage/#run-canceled-activation-steps
|
||||
fn canceled_activation(&self) {
|
||||
}
|
||||
fn canceled_activation(&self) {}
|
||||
|
||||
//https://html.spec.whatwg.org/multipage/#the-a-element:activation-behaviour
|
||||
fn activation_behavior(&self, event: &Event, target: &EventTarget) {
|
||||
|
@ -550,10 +567,11 @@ impl Activatable for HTMLAnchorElement {
|
|||
if target.is::<HTMLImageElement>() && element.has_attribute(&local_name!("ismap")) {
|
||||
let target_node = element.upcast::<Node>();
|
||||
let rect = target_node.bounding_content_box_or_zero();
|
||||
ismap_suffix = Some(
|
||||
format!("?{},{}", mouse_event.ClientX().to_f32().unwrap() - rect.origin.x.to_f32_px(),
|
||||
mouse_event.ClientY().to_f32().unwrap() - rect.origin.y.to_f32_px())
|
||||
)
|
||||
ismap_suffix = Some(format!(
|
||||
"?{},{}",
|
||||
mouse_event.ClientX().to_f32().unwrap() - rect.origin.x.to_f32_px(),
|
||||
mouse_event.ClientY().to_f32().unwrap() - rect.origin.y.to_f32_px()
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -570,12 +588,22 @@ impl Activatable for HTMLAnchorElement {
|
|||
}
|
||||
|
||||
//TODO:https://html.spec.whatwg.org/multipage/#the-a-element
|
||||
fn implicit_submission(&self, _ctrl_key: bool, _shift_key: bool, _alt_key: bool, _meta_key: bool) {
|
||||
fn implicit_submission(
|
||||
&self,
|
||||
_ctrl_key: bool,
|
||||
_shift_key: bool,
|
||||
_alt_key: bool,
|
||||
_meta_key: bool,
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
||||
/// <https://html.spec.whatwg.org/multipage/#following-hyperlinks-2>
|
||||
pub fn follow_hyperlink(subject: &Element, hyperlink_suffix: Option<String>, referrer_policy: Option<ReferrerPolicy>) {
|
||||
pub fn follow_hyperlink(
|
||||
subject: &Element,
|
||||
hyperlink_suffix: Option<String>,
|
||||
referrer_policy: Option<ReferrerPolicy>,
|
||||
) {
|
||||
// Step 1: TODO: If subject cannot navigate, then return.
|
||||
// Step 2, done in Step 7.
|
||||
|
||||
|
@ -600,8 +628,8 @@ pub fn follow_hyperlink(subject: &Element, hyperlink_suffix: Option<String>, ref
|
|||
|
||||
// Step 7.
|
||||
let (maybe_chosen, replace) = match target_attribute_value {
|
||||
Some(name) => source.choose_browsing_context(name.Value(), noopener),
|
||||
None => (Some(window.window_proxy()), false)
|
||||
Some(name) => source.choose_browsing_context(name.Value(), noopener),
|
||||
None => (Some(window.window_proxy()), false),
|
||||
};
|
||||
let chosen = match maybe_chosen {
|
||||
Some(proxy) => proxy,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue