Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of changes #515

Merged
merged 25 commits into from Jun 14, 2013
Merged
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
a53a7f6
Add link following and refactor the profiler.
Jun 6, 2013
9085b88
Implement scrolling and better zooming
Jun 6, 2013
abe6a06
Update rust-layers for GL_LINEAR zooming
pcwalton Jun 6, 2013
bf4df24
Provide an interface to the engine for the script task
Jun 6, 2013
ff1178f
handle relative url's when clicking
Jun 6, 2013
0bbf2fc
Refactor flow tree construction and actually use display property.
Jun 8, 2013
1fbfd7d
Implement horizontal scrolling and pinch-to-zoom
pcwalton Jun 9, 2013
7b28462
Send status messages to the compositor
Jun 7, 2013
a9ed2d8
Spin the event loop every 50 ms to allow Rust channels to be processed.
pcwalton Jun 10, 2013
e50cee9
Resolve relative URLs that begin with '//'
pcwalton Jun 10, 2013
f3ad95f
Added a command-line argument for rendering tiles at higher resolutions
Jun 11, 2013
1aa8d64
Fix URL relativization so that links on Wikipedia work
pcwalton Jun 11, 2013
96b9be6
Add a cheesy progress indicator
pcwalton Jun 11, 2013
204c5b6
Add a spinner for layout
pcwalton Jun 11, 2013
aad5113
Update submodules
pcwalton Jun 12, 2013
162ba83
Fix merge fallout
pcwalton Jun 12, 2013
aee2611
Make script and style display:none
pcwalton Jun 12, 2013
e1b9e01
Fix merge fallout which was disabling all CSS classes.
pcwalton Jun 12, 2013
327e799
test: Add a box model smoketest
pcwalton Jun 12, 2013
b75b2de
Compute percent widths/margins properly and fix numerous small visual…
Jun 4, 2013
4017839
Fix padding
Jun 4, 2013
badf1b8
Vertical margins now contribute to content height.
Jun 4, 2013
f3cdbaf
Stop sorting after every profiler datum comes in.
pcwalton Jun 13, 2013
2ec3412
Fix submodules and test_slam_layout
pcwalton Jun 13, 2013
c35abb2
Update rust-glut
pcwalton Jun 14, 2013
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Implement scrolling and better zooming

  • Loading branch information
eschweic authored and pcwalton committed Jun 12, 2013
commit 9085b882c63c866c3bf3d532eb07f55b18e53f24
@@ -128,6 +128,9 @@ fn run_main_loop(port: Port<Msg>,
let page_size = @mut Size2D(0f32, 0f32);
let window_size = @mut Size2D(800, 600);

// Keeps track of the current zoom factor
let world_zoom = @mut 1f32;

let check_for_messages: @fn() = || {
// Periodically check if the script task responded to our last resize event
resize_rate_limiter.check_resize_response();
@@ -262,16 +265,65 @@ fn run_main_loop(port: Port<Msg>,
*world_offset = world_offset_copy - delta;

// Clamp the world offset to the screen size.
let max_x = (page_size.width - window_size.width as f32).max(&0.0);
let max_x = (page_size.width * *world_zoom - window_size.width as f32).max(&0.0);
world_offset.x = world_offset.x.clamp(&0.0, &max_x);
let max_y = (page_size.height - window_size.height as f32).max(&0.0);
let max_y = (page_size.height * *world_zoom - window_size.height as f32).max(&0.0);
world_offset.y = world_offset.y.clamp(&0.0, &max_y);

debug!("compositor: scrolled to %?", *world_offset);

root_layer.common.set_transform(identity().translate(-world_offset.x,
-world_offset.y,
0.0));
let mut scroll_transform = identity();

scroll_transform = scroll_transform.translate(window_size.width as f32 / 2f32 * *world_zoom - world_offset.x,
window_size.height as f32 / 2f32 * *world_zoom - world_offset.y,
0.0);
scroll_transform = scroll_transform.scale(*world_zoom, *world_zoom, 1f32);
scroll_transform = scroll_transform.translate(window_size.width as f32 / -2f32,
window_size.height as f32 / -2f32,
0.0);

root_layer.common.set_transform(scroll_transform);

window.set_needs_display()
}



// When the user pinch-zooms, scale the layer
do window.set_zoom_callback |delta| {
let zoom_const = 0.01;
let old_world_zoom = *world_zoom;

// Determine zoom amount
*world_zoom = (*world_zoom + delta.y * zoom_const).max(&1.0);

// Update world offset
let corner_to_center_x = world_offset.x + window_size.width as f32 / 2f32;
let new_corner_to_center_x = corner_to_center_x * *world_zoom / old_world_zoom;
world_offset.x = world_offset.x + new_corner_to_center_x - corner_to_center_x;

let corner_to_center_y = world_offset.y + window_size.height as f32 / 2f32;
let new_corner_to_center_y = corner_to_center_y * *world_zoom / old_world_zoom;
world_offset.y = world_offset.y + new_corner_to_center_y - corner_to_center_y;

// Clamp to page bounds when zooming out
let max_x = (page_size.width * *world_zoom - window_size.width as f32).max(&0.0);
world_offset.x = world_offset.x.clamp(&0.0, &max_x);
let max_y = (page_size.height * *world_zoom - window_size.height as f32).max(&0.0);
world_offset.y = world_offset.y.clamp(&0.0, &max_y);


// Apply transformations
let mut zoom_transform = identity();
zoom_transform = zoom_transform.translate(window_size.width as f32 / 2f32 * *world_zoom - world_offset.x,
window_size.height as f32 / 2f32 * *world_zoom - world_offset.y,
0.0);
zoom_transform = zoom_transform.scale(*world_zoom, *world_zoom, 1f32);
zoom_transform = zoom_transform.translate(window_size.width as f32 / -2f32,
window_size.height as f32 / -2f32,
0.0);
root_layer.common.set_transform(zoom_transform);


window.set_needs_display()
}
@@ -9,13 +9,13 @@

use windowing::{ApplicationMethods, CompositeCallback, LoadUrlCallback, MouseCallback};
use windowing::{ResizeCallback, ScrollCallback, WindowMethods, WindowMouseEvent, WindowClickEvent};
use windowing::{WindowMouseDownEvent, WindowMouseUpEvent};
use windowing::{WindowMouseDownEvent, WindowMouseUpEvent, ZoomCallback};

use alert::{Alert, AlertMethods};
use core::libc::c_int;
use geom::point::Point2D;
use geom::size::Size2D;
use glut::glut::{DOUBLE, WindowHeight, WindowWidth};
use glut::glut::{ACTIVE_CTRL, DOUBLE, WindowHeight, WindowWidth};
use glut::glut;
use glut::machack;

@@ -39,8 +39,10 @@ pub struct Window {
load_url_callback: Option<LoadUrlCallback>,
mouse_callback: Option<MouseCallback>,
scroll_callback: Option<ScrollCallback>,
zoom_callback: Option<ZoomCallback>,

drag_origin: Point2D<c_int>,

mouse_down_button: @mut c_int,
mouse_down_point: @mut Point2D<c_int>,
}
@@ -61,12 +63,15 @@ impl WindowMethods<Application> for Window {
load_url_callback: None,
mouse_callback: None,
scroll_callback: None,
zoom_callback: None,

drag_origin: Point2D(0, 0),

mouse_down_button: @mut 0,
mouse_down_point: @mut Point2D(0, 0),
};


// Register event handlers.
do glut::reshape_func(window.glut_window) |width, height| {
match window.resize_callback {
@@ -132,6 +137,11 @@ impl WindowMethods<Application> for Window {
self.scroll_callback = Some(new_scroll_callback)
}

/// Registers a zoom to be run when the user zooms.
pub fn set_zoom_callback(&mut self, new_zoom_callback: ZoomCallback) {
self.zoom_callback = Some(new_zoom_callback)
}

/// Spins the event loop.
pub fn check_loop(@mut self) {
glut::check_loop()
@@ -147,8 +157,19 @@ 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()
match key {
12 => self.load_url(), // Ctrl+L
k if k == ('=' as u8) && (glut::get_modifiers() & ACTIVE_CTRL) != 0 => { // Ctrl++
for self.zoom_callback.each |&callback| {
callback(Point2D(0.0, 20.0));
}
}
k if k == 31 && (glut::get_modifiers() & ACTIVE_CTRL) != 0 => { // Ctrl+-
for self.zoom_callback.each |&callback| {
callback(Point2D(0.0, -20.0));
}
}
_ => {}
}
}

@@ -28,6 +28,9 @@ pub type MouseCallback = @fn(WindowMouseEvent);
/// Type of the function that is called when the user scrolls.
pub type ScrollCallback = @fn(Point2D<f32>);

///Type of the function that is called when the user zooms.
pub type ZoomCallback = @fn(Point2D<f32>);

/// Methods for an abstract Application.
pub trait ApplicationMethods {
fn new() -> Self;
@@ -51,6 +54,8 @@ pub trait WindowMethods<A> {
pub fn set_mouse_callback(&mut self, new_mouse_callback: MouseCallback);
/// Registers a callback to run when the user scrolls.
pub fn set_scroll_callback(&mut self, new_scroll_callback: ScrollCallback);
/// Registers a callback to run when the user zooms.
pub fn set_zoom_callback(&mut self, new_zoom_callback: ZoomCallback);

/// Spins the event loop.
pub fn check_loop(@mut self);
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.