diff options
author | bors-servo <metajack+bors@gmail.com> | 2015-04-14 00:10:08 -0500 |
---|---|---|
committer | bors-servo <metajack+bors@gmail.com> | 2015-04-14 00:10:08 -0500 |
commit | 4fac8b6810d9d748fffc025cfd1bb1d2b6c5655d (patch) | |
tree | 4e5f039f95c904475455d776153334c512f061f3 /components/script/dom/htmlanchorelement.rs | |
parent | 55de52d76ad0c864b7875c561df5c5f3867b2d73 (diff) | |
parent | 7a65b95ae5c847f5a6dbb650865ca6d14490e9bc (diff) | |
download | servo-4fac8b6810d9d748fffc025cfd1bb1d2b6c5655d.tar.gz servo-4fac8b6810d9d748fffc025cfd1bb1d2b6c5655d.zip |
Auto merge of #5593 - shinglyu:ismap, r=jdm
This implements issue 4873
Diffstat (limited to 'components/script/dom/htmlanchorelement.rs')
-rw-r--r-- | components/script/dom/htmlanchorelement.rs | 34 |
1 files changed, 27 insertions, 7 deletions
diff --git a/components/script/dom/htmlanchorelement.rs b/components/script/dom/htmlanchorelement.rs index 1219692cd9b..a4da4a148d6 100644 --- a/components/script/dom/htmlanchorelement.rs +++ b/components/script/dom/htmlanchorelement.rs @@ -2,14 +2,17 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + use dom::activation::Activatable; use dom::attr::AttrValue; use dom::bindings::codegen::Bindings::AttrBinding::AttrMethods; use dom::bindings::codegen::Bindings::HTMLAnchorElementBinding; use dom::bindings::codegen::Bindings::HTMLAnchorElementBinding::HTMLAnchorElementMethods; +use dom::bindings::codegen::Bindings::MouseEventBinding::MouseEventMethods; use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods; -use dom::bindings::codegen::InheritTypes::HTMLAnchorElementDerived; -use dom::bindings::codegen::InheritTypes::{ElementCast, HTMLElementCast, NodeCast}; +use dom::bindings::codegen::InheritTypes::{HTMLAnchorElementDerived, HTMLImageElementDerived}; +use dom::bindings::codegen::InheritTypes::{ElementCast, HTMLElementCast}; +use dom::bindings::codegen::InheritTypes::{MouseEventCast, NodeCast}; use dom::bindings::js::{MutNullableJS, JSRef, Temporary, OptionalRootable}; use dom::document::{Document, DocumentHelpers}; use dom::domtokenlist::DOMTokenList; @@ -17,10 +20,12 @@ use dom::element::{Element, AttributeHandlers, ElementTypeId}; use dom::event::Event; use dom::eventtarget::{EventTarget, EventTargetTypeId}; use dom::htmlelement::{HTMLElement, HTMLElementTypeId}; -use dom::node::{Node, NodeHelpers, NodeTypeId, document_from_node}; +use dom::node::{Node, NodeHelpers, NodeTypeId, document_from_node, window_from_node}; use dom::virtualmethods::VirtualMethods; +use dom::window::WindowHelpers; use std::default::Default; +use std::num::ToPrimitive; use string_cache::Atom; use util::str::DOMString; @@ -112,20 +117,35 @@ impl<'a> Activatable for JSRef<'a, HTMLAnchorElement> { } //https://html.spec.whatwg.org/multipage/semantics.html#the-a-element:activation-behaviour - fn activation_behavior(&self) { + fn activation_behavior(&self, event: JSRef<Event>, target: JSRef<EventTarget>) { //Step 1. If the node document is not fully active, abort. let doc = document_from_node(*self).root(); if !doc.r().is_fully_active() { return; } //TODO: Step 2. Check if browsing context is specified and act accordingly. - //TODO: Step 3. Handle <img ismap/>. - //TODO: Step 4. Download the link is `download` attribute is set. + //Step 3. Handle <img ismap/>. let element: JSRef<Element> = ElementCast::from_ref(*self); + let mouse_event = MouseEventCast::to_ref(event).unwrap(); + let mut ismap_suffix = None; + if let Some(element) = ElementCast::to_ref(target) { + if target.is_htmlimageelement() && element.has_attribute(&atom!("ismap")) { + + let target_node = NodeCast::to_ref(target).unwrap(); + let rect = window_from_node(target_node).root().r().content_box_query(target_node.to_trusted_node_address()); + ismap_suffix = Some( + format!("?{},{}", mouse_event.ClientX().to_f32().unwrap() - rect.origin.x.to_frac32_px(), + mouse_event.ClientY().to_f32().unwrap() - rect.origin.y.to_frac32_px()) + ) + } + } + + //TODO: Step 4. Download the link is `download` attribute is set. + let attr = element.get_attribute(&ns!(""), &atom!("href")).root(); match attr { Some(ref href) => { - let value = href.r().Value(); + let value = href.r().Value() + ismap_suffix.as_ref().map(|s| &**s).unwrap_or(""); debug!("clicked on link to {}", value); doc.r().load_anchor_href(value); } |