/* 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/. */ //! The high-level interface from script to constellation. Using this abstract interface helps //! reduce coupling between these two components. use euclid::scale_factor::ScaleFactor; use euclid::size::TypedSize2D; use hyper::header::Headers; use hyper::method::Method; use ipc_channel::ipc::{self, IpcReceiver, IpcSender, IpcSharedMemory}; use layers::geometry::DevicePixel; use serde::{Deserialize, Serialize}; use std::cell::Cell; use std::fmt; use std::sync::mpsc::channel; use url::Url; use util::geometry::{PagePx, ViewportPx}; use util::mem::HeapSizeOf; use webdriver_msg::{LoadStatus, WebDriverScriptCommand}; #[derive(Deserialize, Serialize)] pub struct ConstellationChan(pub IpcSender); impl ConstellationChan { pub fn new() -> (IpcReceiver, ConstellationChan) { let (chan, port) = ipc::channel().unwrap(); (port, ConstellationChan(chan)) } } impl Clone for ConstellationChan { fn clone(&self) -> ConstellationChan { ConstellationChan(self.0.clone()) } } #[derive(PartialEq, Eq, Copy, Clone, Debug, Deserialize, Serialize)] pub enum IFrameSandboxState { IFrameSandboxed, IFrameUnsandboxed } // We pass this info to various tasks, so it lives in a separate, cloneable struct. #[derive(Clone, Copy, Deserialize, Serialize)] pub struct Failure { pub pipeline_id: PipelineId, pub parent_info: Option<(PipelineId, SubpageId)>, } #[derive(Copy, Clone, Deserialize, Serialize, HeapSizeOf)] 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, /// The "viewing area" in page px. See `PagePx` documentation for details. pub visible_viewport: TypedSize2D, /// The resolution of the window in dppx, not including any "pinch zoom" factor. pub device_pixel_ratio: ScaleFactor, } #[derive(PartialEq, Eq, Copy, Clone, Debug, Deserialize, Serialize)] pub enum KeyState { Pressed, Released, Repeated, } //N.B. Based on the glutin key enum #[derive(Debug, PartialEq, Eq, Copy, Clone, Deserialize, Serialize, HeapSizeOf)] pub enum Key { 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, 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, } bitflags! { #[derive(Deserialize, Serialize)] flags KeyModifiers: u8 { const NONE = 0x00, const SHIFT = 0x01, const CONTROL = 0x02, const ALT = 0x04, const SUPER = 0x08, } } /// Specifies the information required to load a URL in an iframe. #[derive(Deserialize, Serialize)] pub struct IframeLoadInfo { /// Url to load pub url: Url, /// Pipeline ID of the parent of this iframe pub containing_pipeline_id: PipelineId, /// The new subpage ID for this load pub new_subpage_id: SubpageId, /// The old subpage ID for this iframe, if a page was previously loaded. pub old_subpage_id: Option, /// The new pipeline ID that the iframe has generated. pub new_pipeline_id: PipelineId, /// Sandbox type of this iframe pub sandbox: IFrameSandboxState, } #[derive(Deserialize, HeapSizeOf, Serialize)] pub enum MouseEventType { Click, MouseDown, MouseUp, } /// The mouse button involved in the event. #[derive(Clone, Copy, Debug, Deserialize, Serialize)] pub enum MouseButton { /// The left mouse button. Left, /// The middle mouse button. Middle, /// The right mouse button. Right, } /// Messages from the paint task to the constellation. #[derive(Deserialize, Serialize)] pub enum PaintMsg { Failure(Failure), } #[derive(Clone, Eq, PartialEq, Deserialize, Serialize, Debug)] pub enum AnimationState { AnimationsPresent, AnimationCallbacksPresent, NoAnimationsPresent, NoAnimationCallbacksPresent, } /// Used to determine if a script has any pending asynchronous activity. #[derive(Copy, Clone, Debug, PartialEq, Deserialize, Serialize)] pub enum DocumentState { /// The document has been loaded and is idle. Idle, /// The document is either loading or waiting on an event. Pending, } // https://developer.mozilla.org/en-US/docs/Web/API/Using_the_Browser_API#Events #[derive(Deserialize, Serialize)] pub enum MozBrowserEvent { /// Sent when the scroll position within a browser `