2013-07-03 20:42:47 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* 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/. */
|
|
|
|
|
2014-11-05 04:12:32 +03:00
|
|
|
//! The high-level interface from script to constellation. Using this abstract interface helps
|
|
|
|
//! reduce coupling between these two components.
|
2013-07-03 20:42:47 +04:00
|
|
|
|
2013-08-20 21:54:58 +04:00
|
|
|
use geom::rect::Rect;
|
2014-06-10 02:52:41 +04:00
|
|
|
use geom::size::TypedSize2D;
|
2014-06-21 17:06:26 +04:00
|
|
|
use geom::scale_factor::ScaleFactor;
|
2014-12-05 14:16:11 +03:00
|
|
|
use hyper::header::Headers;
|
|
|
|
use hyper::method::{Method, Get};
|
2014-09-02 23:14:37 +04:00
|
|
|
use layers::geometry::DevicePixel;
|
|
|
|
use servo_util::geometry::{PagePx, ViewportPx};
|
2014-04-05 02:52:50 +04:00
|
|
|
use std::comm::{channel, Sender, Receiver};
|
|
|
|
use url::Url;
|
2013-07-03 20:42:47 +04:00
|
|
|
|
|
|
|
#[deriving(Clone)]
|
2014-04-28 02:52:39 +04:00
|
|
|
pub struct ConstellationChan(pub Sender<Msg>);
|
2013-11-07 03:02:18 +04:00
|
|
|
|
2013-07-03 20:42:47 +04:00
|
|
|
impl ConstellationChan {
|
2014-04-05 02:52:50 +04:00
|
|
|
pub fn new() -> (Receiver<Msg>, ConstellationChan) {
|
|
|
|
let (chan, port) = channel();
|
2014-01-13 07:16:21 +04:00
|
|
|
(port, ConstellationChan(chan))
|
2013-07-03 20:42:47 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-28 05:25:07 +04:00
|
|
|
#[deriving(PartialEq)]
|
2013-09-11 23:22:59 +04:00
|
|
|
pub enum IFrameSandboxState {
|
|
|
|
IFrameSandboxed,
|
|
|
|
IFrameUnsandboxed
|
|
|
|
}
|
|
|
|
|
2014-02-14 03:08:07 +04:00
|
|
|
// We pass this info to various tasks, so it lives in a separate, cloneable struct.
|
|
|
|
#[deriving(Clone)]
|
|
|
|
pub struct Failure {
|
2014-04-28 02:52:39 +04:00
|
|
|
pub pipeline_id: PipelineId,
|
|
|
|
pub subpage_id: Option<SubpageId>,
|
2014-02-14 03:08:07 +04:00
|
|
|
}
|
|
|
|
|
2014-06-21 17:06:26 +04:00
|
|
|
pub struct WindowSizeData {
|
|
|
|
/// The size of the initial layout viewport, before parsing an
|
|
|
|
/// http://www.w3.org/TR/css-device-adapt/#initial-viewport
|
|
|
|
pub initial_viewport: TypedSize2D<ViewportPx, f32>,
|
|
|
|
|
|
|
|
/// The "viewing area" in page px. See `PagePx` documentation for details.
|
|
|
|
pub visible_viewport: TypedSize2D<PagePx, f32>,
|
|
|
|
|
|
|
|
/// The resolution of the window in dppx, not including any "pinch zoom" factor.
|
|
|
|
pub device_pixel_ratio: ScaleFactor<ViewportPx, DevicePixel, f32>,
|
|
|
|
}
|
|
|
|
|
2014-11-13 20:57:33 +03:00
|
|
|
#[deriving(PartialEq)]
|
|
|
|
pub enum KeyState {
|
|
|
|
Pressed,
|
|
|
|
Released,
|
|
|
|
Repeated,
|
|
|
|
}
|
|
|
|
|
|
|
|
//N.B. Straight up copied from glfw-rs
|
|
|
|
#[deriving(Show)]
|
|
|
|
pub enum Key {
|
|
|
|
KeySpace,
|
|
|
|
KeyApostrophe,
|
|
|
|
KeyComma,
|
|
|
|
KeyMinus,
|
|
|
|
KeyPeriod,
|
|
|
|
KeySlash,
|
|
|
|
Key0,
|
|
|
|
Key1,
|
|
|
|
Key2,
|
|
|
|
Key3,
|
|
|
|
Key4,
|
|
|
|
Key5,
|
|
|
|
Key6,
|
|
|
|
Key7,
|
|
|
|
Key8,
|
|
|
|
Key9,
|
|
|
|
KeySemicolon,
|
|
|
|
KeyEqual,
|
|
|
|
KeyA,
|
|
|
|
KeyB,
|
|
|
|
KeyC,
|
|
|
|
KeyD,
|
|
|
|
KeyE,
|
|
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
KeyF21,
|
|
|
|
KeyF22,
|
|
|
|
KeyF23,
|
|
|
|
KeyF24,
|
|
|
|
KeyF25,
|
|
|
|
KeyKp0,
|
|
|
|
KeyKp1,
|
|
|
|
KeyKp2,
|
|
|
|
KeyKp3,
|
|
|
|
KeyKp4,
|
|
|
|
KeyKp5,
|
|
|
|
KeyKp6,
|
|
|
|
KeyKp7,
|
|
|
|
KeyKp8,
|
|
|
|
KeyKp9,
|
|
|
|
KeyKpDecimal,
|
|
|
|
KeyKpDivide,
|
|
|
|
KeyKpMultiply,
|
|
|
|
KeyKpSubtract,
|
|
|
|
KeyKpAdd,
|
|
|
|
KeyKpEnter,
|
|
|
|
KeyKpEqual,
|
|
|
|
KeyLeftShift,
|
|
|
|
KeyLeftControl,
|
|
|
|
KeyLeftAlt,
|
|
|
|
KeyLeftSuper,
|
|
|
|
KeyRightShift,
|
|
|
|
KeyRightControl,
|
|
|
|
KeyRightAlt,
|
|
|
|
KeyRightSuper,
|
|
|
|
KeyMenu,
|
|
|
|
}
|
|
|
|
|
|
|
|
bitflags! {
|
|
|
|
flags KeyModifiers: u8 {
|
|
|
|
const SHIFT = 0x01,
|
|
|
|
const CONTROL = 0x02,
|
|
|
|
const ALT = 0x04,
|
|
|
|
const SUPER = 0x08,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-31 00:49:28 +04:00
|
|
|
/// Messages from the compositor and script to the constellation.
|
2013-07-03 20:42:47 +04:00
|
|
|
pub enum Msg {
|
2014-01-16 07:40:00 +04:00
|
|
|
ExitMsg,
|
2014-02-14 03:08:07 +04:00
|
|
|
FailureMsg(Failure),
|
2013-07-30 08:21:19 +04:00
|
|
|
InitLoadUrlMsg(Url),
|
2014-11-14 03:45:29 +03:00
|
|
|
LoadCompleteMsg,
|
2013-08-20 21:54:58 +04:00
|
|
|
FrameRectMsg(PipelineId, SubpageId, Rect<f32>),
|
2014-10-10 02:00:34 +04:00
|
|
|
LoadUrlMsg(PipelineId, LoadData),
|
2014-11-12 04:48:34 +03:00
|
|
|
ScriptLoadedURLInIFrameMsg(Url, PipelineId, SubpageId, IFrameSandboxState),
|
2013-07-30 08:21:19 +04:00
|
|
|
NavigateMsg(NavigationDirection),
|
2014-12-08 20:28:10 +03:00
|
|
|
PainterReadyMsg(PipelineId),
|
2014-06-21 17:06:26 +04:00
|
|
|
ResizedWindowMsg(WindowSizeData),
|
2014-11-13 20:57:33 +03:00
|
|
|
KeyEvent(Key, KeyState, KeyModifiers),
|
2013-07-03 20:42:47 +04:00
|
|
|
}
|
|
|
|
|
2014-10-10 02:00:34 +04:00
|
|
|
/// Similar to net::resource_task::LoadData
|
|
|
|
/// can be passed to LoadUrlMsg to load a page with GET/POST
|
|
|
|
/// parameters or headers
|
|
|
|
#[deriving(Clone)]
|
|
|
|
pub struct LoadData {
|
|
|
|
pub url: Url,
|
|
|
|
pub method: Method,
|
2014-12-05 14:16:11 +03:00
|
|
|
pub headers: Headers,
|
2014-10-10 02:00:34 +04:00
|
|
|
pub data: Option<Vec<u8>>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl LoadData {
|
|
|
|
pub fn new(url: Url) -> LoadData {
|
|
|
|
LoadData {
|
|
|
|
url: url,
|
|
|
|
method: Get,
|
2014-12-05 14:16:11 +03:00
|
|
|
headers: Headers::new(),
|
2014-10-10 02:00:34 +04:00
|
|
|
data: None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-03 20:42:47 +04:00
|
|
|
/// Represents the two different ways to which a page can be navigated
|
2014-11-13 06:48:31 +03:00
|
|
|
#[deriving(Clone, PartialEq, Hash, Show)]
|
2013-10-22 20:16:17 +04:00
|
|
|
pub enum NavigationType {
|
2013-07-03 20:42:47 +04:00
|
|
|
Load, // entered or clicked on a url
|
|
|
|
Navigate, // browser forward/back buttons
|
|
|
|
}
|
|
|
|
|
2014-11-13 06:48:31 +03:00
|
|
|
#[deriving(Clone, PartialEq, Hash, Show)]
|
2013-07-03 20:42:47 +04:00
|
|
|
pub enum NavigationDirection {
|
|
|
|
Forward,
|
|
|
|
Back,
|
|
|
|
}
|
2013-07-30 08:21:19 +04:00
|
|
|
|
2014-11-13 06:48:31 +03:00
|
|
|
#[deriving(Clone, PartialEq, Eq, Hash, Show)]
|
2014-04-28 02:52:39 +04:00
|
|
|
pub struct PipelineId(pub uint);
|
2014-01-13 07:16:21 +04:00
|
|
|
|
2014-11-13 06:48:31 +03:00
|
|
|
#[deriving(Clone, PartialEq, Eq, Hash, Show)]
|
2014-04-28 02:52:39 +04:00
|
|
|
pub struct SubpageId(pub uint);
|