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;
|
2015-01-04 22:39:47 +03:00
|
|
|
use hyper::method::Method;
|
2014-09-02 23:14:37 +04:00
|
|
|
use layers::geometry::DevicePixel;
|
2014-12-18 10:24:49 +03:00
|
|
|
use servo_util::cursor::Cursor;
|
2014-09-02 23:14:37 +04:00
|
|
|
use servo_util::geometry::{PagePx, ViewportPx};
|
2015-01-28 04:15:50 +03:00
|
|
|
use std::sync::mpsc::{channel, Sender, Receiver};
|
2014-04-05 02:52:50 +04:00
|
|
|
use url::Url;
|
2013-07-03 20:42:47 +04:00
|
|
|
|
2015-01-28 04:15:50 +03:00
|
|
|
#[derive(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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-28 04:15:50 +03:00
|
|
|
#[derive(PartialEq, Eq, Copy)]
|
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.
|
2015-01-28 04:15:50 +03:00
|
|
|
#[derive(Clone, Copy)]
|
2014-02-14 03:08:07 +04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2015-01-28 04:15:50 +03:00
|
|
|
#[derive(Copy)]
|
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>,
|
|
|
|
}
|
|
|
|
|
2015-01-28 04:15:50 +03:00
|
|
|
#[derive(PartialEq, Eq, Copy, Clone)]
|
2014-11-13 20:57:33 +03:00
|
|
|
pub enum KeyState {
|
|
|
|
Pressed,
|
|
|
|
Released,
|
|
|
|
Repeated,
|
|
|
|
}
|
|
|
|
|
|
|
|
//N.B. Straight up copied from glfw-rs
|
2015-01-28 04:15:50 +03:00
|
|
|
#[derive(Show, PartialEq, Eq, Copy, Clone)]
|
2014-11-13 20:57:33 +03:00
|
|
|
pub enum Key {
|
2014-12-18 04:45:49 +03:00
|
|
|
Space,
|
|
|
|
Apostrophe,
|
|
|
|
Comma,
|
|
|
|
Minus,
|
|
|
|
Period,
|
|
|
|
Slash,
|
|
|
|
Num0,
|
|
|
|
Num1,
|
|
|
|
Num2,
|
|
|
|
Num3,
|
|
|
|
Num4,
|
|
|
|
Num5,
|
|
|
|
Num6,
|
|
|
|
Num7,
|
|
|
|
Num8,
|
|
|
|
Num9,
|
|
|
|
Semicolon,
|
|
|
|
Equal,
|
|
|
|
A,
|
|
|
|
B,
|
|
|
|
C,
|
|
|
|
D,
|
|
|
|
E,
|
|
|
|
F,
|
|
|
|
G,
|
|
|
|
H,
|
|
|
|
I,
|
|
|
|
J,
|
|
|
|
K,
|
|
|
|
L,
|
|
|
|
M,
|
|
|
|
N,
|
|
|
|
O,
|
|
|
|
P,
|
|
|
|
Q,
|
|
|
|
R,
|
|
|
|
S,
|
|
|
|
T,
|
|
|
|
U,
|
|
|
|
V,
|
|
|
|
W,
|
|
|
|
X,
|
|
|
|
Y,
|
|
|
|
Z,
|
|
|
|
LeftBracket,
|
|
|
|
Backslash,
|
|
|
|
RightBracket,
|
|
|
|
GraveAccent,
|
|
|
|
World1,
|
|
|
|
World2,
|
2014-11-13 20:57:33 +03:00
|
|
|
|
2014-12-18 04:45:49 +03:00
|
|
|
Escape,
|
|
|
|
Enter,
|
|
|
|
Tab,
|
|
|
|
Backspace,
|
|
|
|
Insert,
|
|
|
|
Delete,
|
|
|
|
Right,
|
|
|
|
Left,
|
|
|
|
Down,
|
|
|
|
Up,
|
|
|
|
PageUp,
|
|
|
|
PageDown,
|
|
|
|
Home,
|
|
|
|
End,
|
|
|
|
CapsLock,
|
|
|
|
ScrollLock,
|
|
|
|
NumLock,
|
|
|
|
PrintScreen,
|
|
|
|
Pause,
|
|
|
|
F1,
|
|
|
|
F2,
|
|
|
|
F3,
|
|
|
|
F4,
|
|
|
|
F5,
|
|
|
|
F6,
|
|
|
|
F7,
|
|
|
|
F8,
|
|
|
|
F9,
|
|
|
|
F10,
|
|
|
|
F11,
|
|
|
|
F12,
|
|
|
|
F13,
|
|
|
|
F14,
|
|
|
|
F15,
|
|
|
|
F16,
|
|
|
|
F17,
|
|
|
|
F18,
|
|
|
|
F19,
|
|
|
|
F20,
|
|
|
|
F21,
|
|
|
|
F22,
|
|
|
|
F23,
|
|
|
|
F24,
|
|
|
|
F25,
|
|
|
|
Kp0,
|
|
|
|
Kp1,
|
|
|
|
Kp2,
|
|
|
|
Kp3,
|
|
|
|
Kp4,
|
|
|
|
Kp5,
|
|
|
|
Kp6,
|
|
|
|
Kp7,
|
|
|
|
Kp8,
|
|
|
|
Kp9,
|
|
|
|
KpDecimal,
|
|
|
|
KpDivide,
|
|
|
|
KpMultiply,
|
|
|
|
KpSubtract,
|
|
|
|
KpAdd,
|
|
|
|
KpEnter,
|
|
|
|
KpEqual,
|
|
|
|
LeftShift,
|
|
|
|
LeftControl,
|
|
|
|
LeftAlt,
|
|
|
|
LeftSuper,
|
|
|
|
RightShift,
|
|
|
|
RightControl,
|
|
|
|
RightAlt,
|
|
|
|
RightSuper,
|
|
|
|
Menu,
|
2014-11-13 20:57:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
2015-01-04 22:39:47 +03:00
|
|
|
Exit,
|
|
|
|
Failure(Failure),
|
|
|
|
InitLoadUrl(Url),
|
|
|
|
LoadComplete,
|
|
|
|
FrameRect(PipelineId, SubpageId, Rect<f32>),
|
|
|
|
LoadUrl(PipelineId, LoadData),
|
2015-01-10 03:51:44 +03:00
|
|
|
ScriptLoadedURLInIFrame(Url, PipelineId, SubpageId, Option<SubpageId>, IFrameSandboxState),
|
2015-01-04 22:39:47 +03:00
|
|
|
Navigate(NavigationDirection),
|
|
|
|
PainterReady(PipelineId),
|
|
|
|
ResizedWindow(WindowSizeData),
|
2014-11-13 20:57:33 +03:00
|
|
|
KeyEvent(Key, KeyState, KeyModifiers),
|
2014-12-10 19:40:03 +03:00
|
|
|
/// Requests that the constellation inform the compositor of the title of the pipeline
|
|
|
|
/// immediately.
|
2015-01-04 22:39:47 +03:00
|
|
|
GetPipelineTitle(PipelineId),
|
2014-12-18 10:24:49 +03:00
|
|
|
/// Requests that the constellation inform the compositor of the a cursor change.
|
2015-01-04 22:39:47 +03:00
|
|
|
SetCursor(Cursor),
|
2013-07-03 20:42:47 +04:00
|
|
|
}
|
|
|
|
|
2014-10-10 02:00:34 +04:00
|
|
|
/// Similar to net::resource_task::LoadData
|
2015-01-04 22:39:47 +03:00
|
|
|
/// can be passed to LoadUrl to load a page with GET/POST
|
2014-10-10 02:00:34 +04:00
|
|
|
/// parameters or headers
|
2015-01-28 04:15:50 +03:00
|
|
|
#[derive(Clone)]
|
2014-10-10 02:00:34 +04:00
|
|
|
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,
|
2015-01-04 22:39:47 +03:00
|
|
|
method: 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
|
2015-01-28 04:15:50 +03:00
|
|
|
#[derive(Clone, PartialEq, Eq, Copy, 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
|
|
|
|
}
|
|
|
|
|
2015-01-28 04:15:50 +03:00
|
|
|
#[derive(Clone, PartialEq, Eq, Copy, Hash, Show)]
|
2013-07-03 20:42:47 +04:00
|
|
|
pub enum NavigationDirection {
|
|
|
|
Forward,
|
|
|
|
Back,
|
|
|
|
}
|
2013-07-30 08:21:19 +04:00
|
|
|
|
2015-01-28 04:15:50 +03:00
|
|
|
#[derive(Clone, PartialEq, Eq, Copy, Hash, Show)]
|
2014-04-28 02:52:39 +04:00
|
|
|
pub struct PipelineId(pub uint);
|
2014-01-13 07:16:21 +04:00
|
|
|
|
2015-01-28 04:15:50 +03:00
|
|
|
#[derive(Clone, PartialEq, Eq, Copy, Hash, Show)]
|
2014-04-28 02:52:39 +04:00
|
|
|
pub struct SubpageId(pub uint);
|
2015-01-03 06:21:47 +03:00
|
|
|
|
|
|
|
// The type of pipeline exit. During complete shutdowns, pipelines do not have to
|
|
|
|
// release resources automatically released on process termination.
|
2015-01-28 04:15:50 +03:00
|
|
|
#[derive(Copy)]
|
2015-01-03 06:21:47 +03:00
|
|
|
pub enum PipelineExitType {
|
|
|
|
PipelineOnly,
|
|
|
|
Complete,
|
|
|
|
}
|