mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
Implement Document.createTouch
This commit is contained in:
parent
817eed22d1
commit
316802e206
6 changed files with 73 additions and 11 deletions
|
@ -594,7 +594,7 @@ impl Document {
|
||||||
EventCancelable::Cancelable,
|
EventCancelable::Cancelable,
|
||||||
Some(&self.window),
|
Some(&self.window),
|
||||||
clickCount,
|
clickCount,
|
||||||
x, y, x, y,
|
x, y, x, y, // TODO: Get real screen coordinates?
|
||||||
false, false, false, false,
|
false, false, false, false,
|
||||||
0i16,
|
0i16,
|
||||||
None);
|
None);
|
||||||
|
@ -723,13 +723,18 @@ impl Document {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
let target = el.upcast::<EventTarget>();
|
let target = el.upcast::<EventTarget>();
|
||||||
|
|
||||||
let x = Finite::wrap(point.x as f64);
|
|
||||||
let y = Finite::wrap(point.y as f64);
|
|
||||||
|
|
||||||
let window = self.window.root();
|
let window = self.window.root();
|
||||||
|
|
||||||
let touch = Touch::new(window.r(), identifier, target, x, y, x, y);
|
let client_x = Finite::wrap(point.x as f64);
|
||||||
|
let client_y = Finite::wrap(point.y as f64);
|
||||||
|
let page_x = Finite::wrap(point.x as f64 + window.PageXOffset() as f64);
|
||||||
|
let page_y = Finite::wrap(point.y as f64 + window.PageYOffset() as f64);
|
||||||
|
|
||||||
|
let touch = Touch::new(window.r(), identifier, target,
|
||||||
|
client_x, client_y, // TODO: Get real screen coordinates?
|
||||||
|
client_x, client_y,
|
||||||
|
page_x, page_y);
|
||||||
|
|
||||||
let mut touches = RootedVec::new();
|
let mut touches = RootedVec::new();
|
||||||
touches.push(JS::from_rooted(&touch));
|
touches.push(JS::from_rooted(&touch));
|
||||||
let touches = TouchList::new(window.r(), touches.r());
|
let touches = TouchList::new(window.r(), touches.r());
|
||||||
|
@ -1414,6 +1419,21 @@ impl DocumentMethods for Document {
|
||||||
NodeIterator::new(self, root, whatToShow, filter)
|
NodeIterator::new(self, root, whatToShow, filter)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://w3c.github.io/touch-events/#idl-def-Document
|
||||||
|
fn CreateTouch(&self,
|
||||||
|
window: &Window,
|
||||||
|
target: &EventTarget,
|
||||||
|
identifier: i32,
|
||||||
|
pageX: Finite<f64>,
|
||||||
|
pageY: Finite<f64>,
|
||||||
|
screenX: Finite<f64>,
|
||||||
|
screenY: Finite<f64>)
|
||||||
|
-> Root<Touch> {
|
||||||
|
let clientX = Finite::wrap(*pageX - window.PageXOffset() as f64);
|
||||||
|
let clientY = Finite::wrap(*pageY - window.PageYOffset() as f64);
|
||||||
|
Touch::new(window, identifier, target, screenX, screenY, clientX, clientY, pageX, pageY)
|
||||||
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-document-createtreewalker
|
// https://dom.spec.whatwg.org/#dom-document-createtreewalker
|
||||||
fn CreateTreeWalker(&self, root: &Node, whatToShow: u32, filter: Option<Rc<NodeFilter>>)
|
fn CreateTreeWalker(&self, root: &Node, whatToShow: u32, filter: Option<Rc<NodeFilter>>)
|
||||||
-> Root<TreeWalker> {
|
-> Root<TreeWalker> {
|
||||||
|
|
|
@ -20,12 +20,15 @@ pub struct Touch {
|
||||||
screen_y: f64,
|
screen_y: f64,
|
||||||
client_x: f64,
|
client_x: f64,
|
||||||
client_y: f64,
|
client_y: f64,
|
||||||
|
page_x: f64,
|
||||||
|
page_y: f64,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Touch {
|
impl Touch {
|
||||||
fn new_inherited(identifier: i32, target: &EventTarget,
|
fn new_inherited(identifier: i32, target: &EventTarget,
|
||||||
screen_x: Finite<f64>, screen_y: Finite<f64>,
|
screen_x: Finite<f64>, screen_y: Finite<f64>,
|
||||||
client_x: Finite<f64>, client_y: Finite<f64>) -> Touch {
|
client_x: Finite<f64>, client_y: Finite<f64>,
|
||||||
|
page_x: Finite<f64>, page_y: Finite<f64>) -> Touch {
|
||||||
Touch {
|
Touch {
|
||||||
reflector_: Reflector::new(),
|
reflector_: Reflector::new(),
|
||||||
identifier: identifier,
|
identifier: identifier,
|
||||||
|
@ -34,15 +37,19 @@ impl Touch {
|
||||||
screen_y: *screen_y,
|
screen_y: *screen_y,
|
||||||
client_x: *client_x,
|
client_x: *client_x,
|
||||||
client_y: *client_y,
|
client_y: *client_y,
|
||||||
|
page_x: *page_x,
|
||||||
|
page_y: *page_y,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new(window: &Window, identifier: i32, target: &EventTarget,
|
pub fn new(window: &Window, identifier: i32, target: &EventTarget,
|
||||||
screen_x: Finite<f64>, screen_y: Finite<f64>,
|
screen_x: Finite<f64>, screen_y: Finite<f64>,
|
||||||
client_x: Finite<f64>, client_y: Finite<f64>) -> Root<Touch> {
|
client_x: Finite<f64>, client_y: Finite<f64>,
|
||||||
|
page_x: Finite<f64>, page_y: Finite<f64>) -> Root<Touch> {
|
||||||
reflect_dom_object(box Touch::new_inherited(identifier, target,
|
reflect_dom_object(box Touch::new_inherited(identifier, target,
|
||||||
screen_x, screen_y,
|
screen_x, screen_y,
|
||||||
client_x, client_y),
|
client_x, client_y,
|
||||||
|
page_x, page_y),
|
||||||
GlobalRef::Window(window), TouchBinding::Wrap)
|
GlobalRef::Window(window), TouchBinding::Wrap)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -77,4 +84,14 @@ impl TouchMethods for Touch {
|
||||||
fn ClientY(&self) -> Finite<f64> {
|
fn ClientY(&self) -> Finite<f64> {
|
||||||
Finite::wrap(self.client_y)
|
Finite::wrap(self.client_y)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// https://w3c.github.io/touch-events/#widl-Touch-clientX
|
||||||
|
fn PageX(&self) -> Finite<f64> {
|
||||||
|
Finite::wrap(self.page_x)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// https://w3c.github.io/touch-events/#widl-Touch-clientY
|
||||||
|
fn PageY(&self) -> Finite<f64> {
|
||||||
|
Finite::wrap(self.page_y)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -159,3 +159,16 @@ partial interface Document {
|
||||||
// Tracking issue for document.all: https://github.com/servo/servo/issues/7396
|
// Tracking issue for document.all: https://github.com/servo/servo/issues/7396
|
||||||
// readonly attribute HTMLAllCollection all;
|
// readonly attribute HTMLAllCollection all;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// http://w3c.github.io/touch-events/#idl-def-Document
|
||||||
|
partial interface Document {
|
||||||
|
Touch createTouch(Window/*Proxy*/ view,
|
||||||
|
EventTarget target,
|
||||||
|
long identifier,
|
||||||
|
double pageX,
|
||||||
|
double pageY,
|
||||||
|
double screenX,
|
||||||
|
double screenY);
|
||||||
|
// FIXME (#8159):
|
||||||
|
// TouchList createTouchList(Touch... touches);
|
||||||
|
};
|
||||||
|
|
|
@ -12,8 +12,8 @@ interface Touch {
|
||||||
readonly attribute double screenY;
|
readonly attribute double screenY;
|
||||||
readonly attribute double clientX;
|
readonly attribute double clientX;
|
||||||
readonly attribute double clientY;
|
readonly attribute double clientY;
|
||||||
// readonly attribute double pageX;
|
readonly attribute double pageX;
|
||||||
// readonly attribute double pageY;
|
readonly attribute double pageY;
|
||||||
// readonly attribute float radiusX;
|
// readonly attribute float radiusX;
|
||||||
// readonly attribute float radiusY;
|
// readonly attribute float radiusY;
|
||||||
// readonly attribute float rotationAngle;
|
// readonly attribute float rotationAngle;
|
||||||
|
|
|
@ -15,6 +15,8 @@ skip: true
|
||||||
skip: false
|
skip: false
|
||||||
[url]
|
[url]
|
||||||
skip: false
|
skip: false
|
||||||
|
[touch-events]
|
||||||
|
skip: false
|
||||||
[workers]
|
[workers]
|
||||||
skip: false
|
skip: false
|
||||||
[XMLHttpRequest]
|
[XMLHttpRequest]
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
[create-touch-touchlist.html]
|
||||||
|
type: testharness
|
||||||
|
[document.createTouchList exists and correctly creates a TouchList from zero Touch objects]
|
||||||
|
expected: FAIL
|
||||||
|
|
||||||
|
[document.createTouchList exists and correctly creates a TouchList from a single Touch]
|
||||||
|
expected: FAIL
|
||||||
|
|
||||||
|
[document.createTouchList exists and correctly creates a TouchList from two Touch objects]
|
||||||
|
expected: FAIL
|
Loading…
Add table
Add a link
Reference in a new issue