mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
forward EmbedderMsg to embedder
This commit is contained in:
parent
10abe03948
commit
5e33dcd29d
4 changed files with 151 additions and 238 deletions
|
@ -9,14 +9,12 @@ use euclid::TypedScale;
|
|||
use gleam::gl;
|
||||
use ipc_channel::ipc::IpcSender;
|
||||
use msg::constellation_msg::{Key, KeyModifiers, KeyState, TopLevelBrowsingContextId, TraversalDirection};
|
||||
use net_traits::net_error_list::NetError;
|
||||
use script_traits::{LoadData, MouseButton, TouchEventType, TouchId};
|
||||
use script_traits::{MouseButton, TouchEventType, TouchId};
|
||||
use servo_geometry::{DeviceIndependentPixel, DeviceUintLength};
|
||||
use servo_url::ServoUrl;
|
||||
use std::fmt::{Debug, Error, Formatter};
|
||||
use std::rc::Rc;
|
||||
use style_traits::DevicePixel;
|
||||
use style_traits::cursor::CursorKind;
|
||||
use webrender_api::{DeviceIntPoint, DevicePoint, DeviceUintSize, DeviceUintRect, ScrollLocation};
|
||||
|
||||
#[derive(Clone)]
|
||||
|
@ -123,64 +121,23 @@ pub enum AnimationState {
|
|||
pub trait WindowMethods {
|
||||
/// Presents the window to the screen (perhaps by page flipping).
|
||||
fn present(&self);
|
||||
|
||||
/// Get the coordinates of the native window, the screen and the framebuffer.
|
||||
fn get_coordinates(&self) -> EmbedderCoordinates;
|
||||
/// Set the size inside of borders and head
|
||||
fn set_inner_size(&self, ctx: TopLevelBrowsingContextId, size: DeviceUintSize);
|
||||
/// Set the window position
|
||||
fn set_position(&self, ctx: TopLevelBrowsingContextId, point: DeviceIntPoint);
|
||||
/// Set fullscreen state
|
||||
fn set_fullscreen_state(&self, ctx: TopLevelBrowsingContextId, state: bool);
|
||||
|
||||
/// Sets the page title for the current page.
|
||||
fn set_page_title(&self, ctx: TopLevelBrowsingContextId, title: Option<String>);
|
||||
/// Called when the browser chrome should display a status message.
|
||||
fn status(&self, ctx: TopLevelBrowsingContextId, Option<String>);
|
||||
/// Called when the browser has started loading a frame.
|
||||
fn load_start(&self, ctx: TopLevelBrowsingContextId);
|
||||
/// Called when the browser is done loading a frame.
|
||||
fn load_end(&self, ctx: TopLevelBrowsingContextId);
|
||||
/// Called when the browser encounters an error while loading a URL
|
||||
fn load_error(&self, ctx: TopLevelBrowsingContextId, code: NetError, url: String);
|
||||
/// Wether or not to follow a link
|
||||
fn allow_navigation(&self, ctx: TopLevelBrowsingContextId, url: ServoUrl, IpcSender<bool>);
|
||||
/// Called when the <head> tag has finished parsing
|
||||
fn head_parsed(&self, ctx: TopLevelBrowsingContextId);
|
||||
/// Called when the history state has changed.
|
||||
fn history_changed(&self, ctx: TopLevelBrowsingContextId, Vec<LoadData>, usize);
|
||||
|
||||
/// Returns a thread-safe object to wake up the window's event loop.
|
||||
fn create_event_loop_waker(&self) -> Box<EventLoopWaker>;
|
||||
|
||||
/// Requests that the window system prepare a composite. Typically this will involve making
|
||||
/// some type of platform-specific graphics context current. Returns true if the composite may
|
||||
/// proceed and false if it should not.
|
||||
fn prepare_for_composite(&self, width: DeviceUintLength, height: DeviceUintLength) -> bool;
|
||||
|
||||
/// Sets the cursor to be used in the window.
|
||||
fn set_cursor(&self, cursor: CursorKind);
|
||||
|
||||
/// Process a key event.
|
||||
fn handle_key(&self, ctx: Option<TopLevelBrowsingContextId>, ch: Option<char>, key: Key, mods: KeyModifiers);
|
||||
|
||||
/// Does this window support a clipboard
|
||||
fn supports_clipboard(&self) -> bool;
|
||||
|
||||
/// Add a favicon
|
||||
fn set_favicon(&self, ctx: TopLevelBrowsingContextId, url: ServoUrl);
|
||||
|
||||
/// Return the GL function pointer trait.
|
||||
fn gl(&self) -> Rc<gl::Gl>;
|
||||
|
||||
/// Returns a thread-safe object to wake up the window's event loop.
|
||||
fn create_event_loop_waker(&self) -> Box<EventLoopWaker>;
|
||||
/// Get the coordinates of the native window, the screen and the framebuffer.
|
||||
fn get_coordinates(&self) -> EmbedderCoordinates;
|
||||
/// Does this window support a clipboard
|
||||
fn supports_clipboard(&self) -> bool;
|
||||
/// Set whether the application is currently animating.
|
||||
/// Typically, when animations are active, the window
|
||||
/// will want to avoid blocking on UI events, and just
|
||||
/// run the event loop at the vsync interval.
|
||||
fn set_animation_state(&self, _state: AnimationState) {}
|
||||
|
||||
/// Called when a pipeline panics.
|
||||
fn handle_panic(&self, browser_id: TopLevelBrowsingContextId, reason: String, backtrace: Option<String>);
|
||||
fn set_animation_state(&self, _state: AnimationState);
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
|
|
|
@ -86,7 +86,6 @@ use gaol::sandbox::{ChildSandbox, ChildSandboxMethods};
|
|||
use gfx::font_cache_thread::FontCacheThread;
|
||||
use ipc_channel::ipc::{self, IpcSender};
|
||||
use log::{Log, LogMetadata, LogRecord};
|
||||
use msg::constellation_msg::KeyState;
|
||||
use net::resource_thread::new_resource_threads;
|
||||
use net_traits::IpcSend;
|
||||
use profile::mem as profile_mem;
|
||||
|
@ -124,7 +123,8 @@ pub use msg::constellation_msg::TopLevelBrowsingContextId as BrowserId;
|
|||
pub struct Servo<Window: WindowMethods + 'static> {
|
||||
compositor: IOCompositor<Window>,
|
||||
constellation_chan: Sender<ConstellationMsg>,
|
||||
embedder_receiver: EmbedderReceiver
|
||||
embedder_receiver: EmbedderReceiver,
|
||||
embedder_events: Vec<EmbedderMsg>,
|
||||
}
|
||||
|
||||
impl<Window> Servo<Window> where Window: WindowMethods + 'static {
|
||||
|
@ -255,6 +255,7 @@ impl<Window> Servo<Window> where Window: WindowMethods + 'static {
|
|||
compositor: compositor,
|
||||
constellation_chan: constellation_chan,
|
||||
embedder_receiver: embedder_receiver,
|
||||
embedder_events: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -371,83 +372,17 @@ impl<Window> Servo<Window> where Window: WindowMethods + 'static {
|
|||
|
||||
(_, ShutdownState::ShuttingDown) => {},
|
||||
|
||||
(EmbedderMsg::Status(top_level_browsing_context, message), ShutdownState::NotShuttingDown) => {
|
||||
self.compositor.window.status(top_level_browsing_context, message);
|
||||
(msg, ShutdownState::NotShuttingDown) => {
|
||||
self.embedder_events.push(msg);
|
||||
},
|
||||
|
||||
(EmbedderMsg::ChangePageTitle(top_level_browsing_context, title), ShutdownState::NotShuttingDown) => {
|
||||
self.compositor.window.set_page_title(top_level_browsing_context, title);
|
||||
},
|
||||
|
||||
(EmbedderMsg::MoveTo(top_level_browsing_context, point),
|
||||
ShutdownState::NotShuttingDown) => {
|
||||
self.compositor.window.set_position(top_level_browsing_context, point);
|
||||
},
|
||||
|
||||
(EmbedderMsg::ResizeTo(top_level_browsing_context, size),
|
||||
ShutdownState::NotShuttingDown) => {
|
||||
self.compositor.window.set_inner_size(top_level_browsing_context, size);
|
||||
},
|
||||
|
||||
(EmbedderMsg::AllowNavigation(top_level_browsing_context,
|
||||
url,
|
||||
response_chan),
|
||||
ShutdownState::NotShuttingDown) => {
|
||||
self.compositor.window.allow_navigation(top_level_browsing_context, url, response_chan);
|
||||
},
|
||||
|
||||
(EmbedderMsg::KeyEvent(top_level_browsing_context,
|
||||
ch,
|
||||
key,
|
||||
state,
|
||||
modified),
|
||||
ShutdownState::NotShuttingDown) => {
|
||||
if state == KeyState::Pressed {
|
||||
self.compositor.window.handle_key(top_level_browsing_context, ch, key, modified);
|
||||
}
|
||||
},
|
||||
|
||||
(EmbedderMsg::SetCursor(cursor), ShutdownState::NotShuttingDown) => {
|
||||
self.compositor.window.set_cursor(cursor)
|
||||
},
|
||||
|
||||
(EmbedderMsg::NewFavicon(top_level_browsing_context, url), ShutdownState::NotShuttingDown) => {
|
||||
self.compositor.window.set_favicon(top_level_browsing_context, url);
|
||||
},
|
||||
|
||||
(EmbedderMsg::HeadParsed(top_level_browsing_context, ), ShutdownState::NotShuttingDown) => {
|
||||
self.compositor.window.head_parsed(top_level_browsing_context, );
|
||||
},
|
||||
|
||||
(EmbedderMsg::HistoryChanged(top_level_browsing_context, entries, current),
|
||||
ShutdownState::NotShuttingDown) => {
|
||||
self.compositor.window.history_changed(top_level_browsing_context, entries, current);
|
||||
},
|
||||
|
||||
(EmbedderMsg::SetFullscreenState(top_level_browsing_context, state),
|
||||
ShutdownState::NotShuttingDown) => {
|
||||
self.compositor.window.set_fullscreen_state(top_level_browsing_context, state);
|
||||
},
|
||||
|
||||
(EmbedderMsg::LoadStart(top_level_browsing_context), ShutdownState::NotShuttingDown) => {
|
||||
self.compositor.window.load_start(top_level_browsing_context);
|
||||
},
|
||||
|
||||
(EmbedderMsg::LoadComplete(top_level_browsing_context), ShutdownState::NotShuttingDown) => {
|
||||
// Inform the embedder that the load has finished.
|
||||
//
|
||||
// TODO(pcwalton): Specify which frame's load completed.
|
||||
self.compositor.window.load_end(top_level_browsing_context);
|
||||
},
|
||||
(EmbedderMsg::Panic(top_level_browsing_context, reason, backtrace),
|
||||
ShutdownState::NotShuttingDown) => {
|
||||
self.compositor.window.handle_panic(top_level_browsing_context, reason, backtrace);
|
||||
},
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_events(&mut self) -> Vec<EmbedderMsg> {
|
||||
::std::mem::replace(&mut self.embedder_events, Vec::new())
|
||||
}
|
||||
|
||||
pub fn handle_events(&mut self, events: Vec<WindowEvent>) -> bool {
|
||||
if self.compositor.receive_messages() {
|
||||
self.receive_messages();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue