aboutsummaryrefslogtreecommitdiffstats
path: root/ports/gonk/src/main.rs
blob: 19c1a0fb256e3005e2620ae34bfd7acb6ee317e6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/* 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/. */

#![deny(unused_imports)]
#![deny(unused_variables)]

#![feature(box_syntax)]
#![feature(convert)]
// For FFI
#![allow(non_snake_case, dead_code)]

//! The `servo` test application.
//!
//! Creates a `Browser` instance with a simple implementation of
//! the compositor's `WindowMethods` to create a working web browser.
//!
//! This browser's implementation of `WindowMethods` is built on top
//! of [glutin], the cross-platform OpenGL utility and windowing
//! library.
//!
//! For the engine itself look next door in lib.rs.
//!
//! [glutin]: https://github.com/tomaka/glutin

extern crate servo;
extern crate time;
extern crate util;
extern crate errno;

extern crate compositing;
extern crate script_traits;

extern crate euclid;
extern crate libc;
extern crate msg;
extern crate gleam;
extern crate layers;
extern crate egl;
extern crate url;
extern crate net;
extern crate env_logger;

use util::opts;
use net::resource_task;
use servo::Browser;
use compositing::windowing::WindowEvent;

use std::env;

mod window;
mod input;

struct BrowserWrapper {
    browser: Browser,
}

fn main() {
    env_logger::init().unwrap();

    // Parse the command line options and store them globally
    if opts::from_cmdline_args(env::args().collect::<Vec<_>>().as_slice()) {
        resource_task::global_init();

        let window = if opts::get().headless {
            None
        } else {
            Some(window::Window::new())
        };

        // Our wrapper around `Browser` that also implements some
        // callbacks required by the glutin window implementation.
        let mut browser = BrowserWrapper {
            browser: Browser::new(window.clone()),
        };

        match window {
            None => (),
            Some(ref window) => input::run_input_loop(&window.event_send)
        }

        browser.browser.handle_events(vec![WindowEvent::InitializeCompositing]);

        // Feed events from the window to the browser until the browser
        // says to stop.
        loop {
            let should_continue = match window {
                None => browser.browser.handle_events(vec![WindowEvent::Idle]),
                Some(ref window) => {
                    let events = window.wait_events();
                    browser.browser.handle_events(events)
                }
            };
            if !should_continue {
                break
            }
        }

        let BrowserWrapper {
            browser
        } = browser;
        browser.shutdown();
    }
}