mirror of
https://github.com/servo/servo.git
synced 2025-08-04 21:20:23 +01:00
Load purple.com when hitting ctrl+L.
This is a precursor to popping up an alert box.
This commit is contained in:
parent
fe9e248c21
commit
8fbd6326d8
5 changed files with 61 additions and 8 deletions
|
@ -17,8 +17,9 @@ use geom::rect::Rect;
|
|||
use geom::size::Size2D;
|
||||
use gfx::compositor::{Compositor, LayerBuffer, LayerBufferSet};
|
||||
use gfx::opts::Opts;
|
||||
use layers::layers::{Image, ImageData};
|
||||
use layers;
|
||||
use servo_util::time;
|
||||
use servo_util::{time, url};
|
||||
|
||||
mod resize_rate_limiter;
|
||||
|
||||
|
@ -97,7 +98,7 @@ fn mainloop(po: Port<Msg>, script_chan: SharedChan<ScriptMsg>, opts: &Opts) {
|
|||
0,
|
||||
layers::layers::RGB24Format,
|
||||
~[]);
|
||||
let image = @mut layers::layers::Image::new(image_data as @layers::layers::ImageData);
|
||||
let image = @mut Image::new(image_data as @ImageData);
|
||||
let image_layer = @mut layers::layers::ImageLayer(image);
|
||||
original_layer_transform = image_layer.common.transform;
|
||||
image_layer.common.set_transform(original_layer_transform.scale(800.0, 600.0, 1.0));
|
||||
|
@ -141,7 +142,7 @@ fn mainloop(po: Port<Msg>, script_chan: SharedChan<ScriptMsg>, opts: &Opts) {
|
|||
data_source_surface: buffer.draw_target.snapshot().get_data_surface(),
|
||||
size: Size2D(width, height)
|
||||
};
|
||||
let image = @mut layers::layers::Image::new(image_data as @layers::layers::ImageData);
|
||||
let image = @mut Image::new(image_data as @ImageData);
|
||||
|
||||
// Find or create an image layer.
|
||||
let image_layer;
|
||||
|
@ -192,6 +193,7 @@ fn mainloop(po: Port<Msg>, script_chan: SharedChan<ScriptMsg>, opts: &Opts) {
|
|||
window.present();
|
||||
}
|
||||
|
||||
// Hook the windowing system's resize callback up to the resize rate limiter.
|
||||
do window.set_resize_callback |width, height| {
|
||||
debug!("osmain: window resized to %ux%u", width, height);
|
||||
resize_rate_limiter.window_resized(width, height);
|
||||
|
|
|
@ -7,7 +7,8 @@
|
|||
/// GLUT is a very old and bare-bones toolkit. However, it has good cross-platform support, at
|
||||
/// least on desktops. It is designed for testing Servo without the need of a UI.
|
||||
|
||||
use windowing::{ApplicationMethods, CompositeCallback, ResizeCallback, WindowMethods};
|
||||
use windowing::{ApplicationMethods, CompositeCallback, LoadUrlCallback, ResizeCallback};
|
||||
use windowing::{WindowMethods};
|
||||
|
||||
use geom::size::Size2D;
|
||||
use glut::glut::{DOUBLE, WindowHeight, WindowWidth};
|
||||
|
@ -27,8 +28,10 @@ impl ApplicationMethods for Application {
|
|||
/// The type of a window.
|
||||
pub struct Window {
|
||||
glut_window: glut::Window,
|
||||
|
||||
composite_callback: Option<CompositeCallback>,
|
||||
resize_callback: Option<ResizeCallback>,
|
||||
load_url_callback: Option<LoadUrlCallback>,
|
||||
}
|
||||
|
||||
impl WindowMethods<Application> for Window {
|
||||
|
@ -41,8 +44,10 @@ impl WindowMethods<Application> for Window {
|
|||
// Create our window object.
|
||||
let window = @mut Window {
|
||||
glut_window: glut_window,
|
||||
|
||||
composite_callback: None,
|
||||
resize_callback: None,
|
||||
load_url_callback: None,
|
||||
};
|
||||
|
||||
// Register event handlers.
|
||||
|
@ -51,14 +56,17 @@ impl WindowMethods<Application> for Window {
|
|||
None => {}
|
||||
Some(callback) => callback(width as uint, height as uint),
|
||||
}
|
||||
};
|
||||
}
|
||||
do glut::display_func {
|
||||
// FIXME(pcwalton): This will not work with multiple windows.
|
||||
match window.composite_callback {
|
||||
None => {}
|
||||
Some(callback) => callback(),
|
||||
}
|
||||
};
|
||||
}
|
||||
do glut::keyboard_func |key, _, _| {
|
||||
window.handle_key(key)
|
||||
}
|
||||
|
||||
window
|
||||
}
|
||||
|
@ -84,9 +92,32 @@ impl WindowMethods<Application> for Window {
|
|||
self.resize_callback = Some(new_resize_callback)
|
||||
}
|
||||
|
||||
/// Registers a callback to be run when a new URL is to be loaded.
|
||||
pub fn set_load_url_callback(&mut self, new_load_url_callback: LoadUrlCallback) {
|
||||
self.load_url_callback = Some(new_load_url_callback)
|
||||
}
|
||||
|
||||
/// Spins the event loop.
|
||||
pub fn check_loop(@mut self) {
|
||||
glut::check_loop()
|
||||
}
|
||||
}
|
||||
|
||||
impl Window {
|
||||
/// Helper function to handle keyboard events.
|
||||
fn handle_key(&self, key: u8) {
|
||||
debug!("got key: %d", key as int);
|
||||
if key == 12 { // ^L
|
||||
self.load_url()
|
||||
}
|
||||
}
|
||||
|
||||
/// Helper function to pop up an alert box prompting the user to load a URL.
|
||||
fn load_url(&self) {
|
||||
match self.load_url_callback {
|
||||
None => error!("no URL callback registered, doing nothing"),
|
||||
Some(callback) => callback("http://purple.com/"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
/// along with the Servo process or trusted. If the OpenGL driver itself is untrusted, then this
|
||||
/// windowing implementation is not appropriate.
|
||||
|
||||
use windowing::{CompositeCallback, ResizeCallback};
|
||||
use windowing::{CompositeCallback, LoadUrlCallback, ResizeCallback};
|
||||
|
||||
use geom::size::Size2D;
|
||||
use sharegl::base::ShareContext;
|
||||
|
@ -53,6 +53,9 @@ impl WindowingMethods<Application> for Window {
|
|||
/// Registers a callback to run when a resize event occurs.
|
||||
pub fn set_resize_callback(&mut self, _: ResizeCallback) {}
|
||||
|
||||
/// Registers a callback to run when a new URL is to be loaded.
|
||||
pub fn set_load_url_callback(&mut self, _: LoadUrlCallback) {}
|
||||
|
||||
/// Returns the next event.
|
||||
pub fn check_loop(@mut self) {}
|
||||
}
|
||||
|
|
|
@ -121,8 +121,11 @@ pub struct ScriptContext {
|
|||
js_context: @Cx,
|
||||
/// The JavaScript compartment.
|
||||
js_compartment: @mut Compartment,
|
||||
|
||||
/// Global static data related to the DOM.
|
||||
dom_static: GlobalStaticData,
|
||||
/// Whether the JS bindings have been initialized.
|
||||
bindings_initialized: bool,
|
||||
|
||||
/// The outermost frame. This frame contains the document, window, and page URL.
|
||||
root_frame: Option<Frame>,
|
||||
|
@ -189,7 +192,9 @@ impl ScriptContext {
|
|||
js_runtime: js_runtime,
|
||||
js_context: js_context,
|
||||
js_compartment: compartment,
|
||||
|
||||
dom_static: GlobalStaticData(),
|
||||
bindings_initialized: false,
|
||||
|
||||
root_frame: None,
|
||||
|
||||
|
@ -287,7 +292,12 @@ impl ScriptContext {
|
|||
/// objects, parses HTML and CSS, and kicks off initial layout.
|
||||
fn load(&mut self, url: Url) {
|
||||
// Define the script DOM bindings.
|
||||
//
|
||||
// FIXME: Can this be done earlier, to save the flag?
|
||||
if !self.bindings_initialized {
|
||||
define_bindings(self.js_compartment);
|
||||
self.bindings_initialized = true
|
||||
}
|
||||
|
||||
// Parse HTML.
|
||||
//
|
||||
|
|
|
@ -12,6 +12,9 @@ pub type CompositeCallback = @fn();
|
|||
/// Type of the function that is called when the window is resized.
|
||||
pub type ResizeCallback = @fn(uint, uint);
|
||||
|
||||
/// Type of the function that is called when a new URL is to be loaded.
|
||||
pub type LoadUrlCallback = @fn(&str);
|
||||
|
||||
/// Methods for an abstract Application.
|
||||
pub trait ApplicationMethods {
|
||||
fn new() -> Self;
|
||||
|
@ -24,10 +27,14 @@ pub trait WindowMethods<A> {
|
|||
pub fn size(&self) -> Size2D<f32>;
|
||||
/// Presents the window to the screen (perhaps by page flipping).
|
||||
pub fn present(&mut self);
|
||||
|
||||
/// Registers a callback to run when a composite event occurs.
|
||||
pub fn set_composite_callback(&mut self, new_composite_callback: CompositeCallback);
|
||||
/// Registers a callback to run when a resize event occurs.
|
||||
pub fn set_resize_callback(&mut self, new_resize_callback: ResizeCallback);
|
||||
/// Registers a callback to run when a new URL is to be loaded.
|
||||
pub fn set_load_url_callback(&mut self, new_load_url_callback: LoadUrlCallback);
|
||||
|
||||
/// Spins the event loop.
|
||||
pub fn check_loop(@mut self);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue