servo: Merge #20303 - refactor(window): reference winit where applicable (from kwonoj:refactor-winit); r=SimonSapin

<!-- Please describe your changes on the following line: -->
This is nearly first changes to rustlang code and I suspect I could make possible mistakes lot, please point me anything if need to be updated. 🙏

This PR intends to update codebase per #20299 , mostly followed suggestion around https://github.com/servo/servo/issues/20299#issuecomment-373171416 to update reference to use `winit` where applicable. Confirmed local build / check works correctly for updated references.

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #20299 (github issue number if applicable).

<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because _____

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

Source-Repo: https://github.com/servo/servo
Source-Revision: 5f408422941b87e936880074f99a69fbdeebd131

--HG--
extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear
extra : subtree_revision : e3ed7e0ceaa3d36a1dd07b14b04af761e8e8d90d
This commit is contained in:
OJ Kwon 2018-03-15 15:45:48 -04:00
Родитель c690d6f97d
Коммит 9b3a782c85
4 изменённых файлов: 33 добавлений и 28 удалений

1
servo/Cargo.lock сгенерированный
Просмотреть файл

@ -2681,6 +2681,7 @@ dependencies = [
"user32-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "user32-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"webrender_api 0.57.0 (git+https://github.com/servo/webrender)", "webrender_api 0.57.0 (git+https://github.com/servo/webrender)",
"winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
"winit 0.11.2 (registry+https://github.com/rust-lang/crates.io-index)",
"x11 2.17.3 (registry+https://github.com/rust-lang/crates.io-index)", "x11 2.17.3 (registry+https://github.com/rust-lang/crates.io-index)",
] ]

Просмотреть файл

@ -42,6 +42,7 @@ servo_url = {path = "../../components/url"}
style_traits = {path = "../../components/style_traits"} style_traits = {path = "../../components/style_traits"}
tinyfiledialogs = "3.0" tinyfiledialogs = "3.0"
webrender_api = {git = "https://github.com/servo/webrender", features = ["ipc"]} webrender_api = {git = "https://github.com/servo/webrender", features = ["ipc"]}
winit = "0.11.2"
[target.'cfg(not(target_os = "android"))'.dependencies] [target.'cfg(not(target_os = "android"))'.dependencies]
sig = "0.1" sig = "0.1"

Просмотреть файл

@ -12,10 +12,7 @@ use euclid::{Point2D, Size2D, TypedPoint2D, TypedVector2D, TypedScale, TypedSize
use gdi32; use gdi32;
use gleam::gl; use gleam::gl;
use glutin; use glutin;
use glutin::{Api, ElementState, Event, GlContext, GlRequest, MouseButton, MouseScrollDelta, VirtualKeyCode}; use glutin::{Api, GlContext, GlRequest};
use glutin::TouchPhase;
#[cfg(target_os = "macos")]
use glutin::os::macos::{ActivationPolicy, WindowBuilderExt};
use msg::constellation_msg::{self, Key, TopLevelBrowsingContextId as BrowserId}; use msg::constellation_msg::{self, Key, TopLevelBrowsingContextId as BrowserId};
use msg::constellation_msg::{KeyModifiers, KeyState, TraversalDirection}; use msg::constellation_msg::{KeyModifiers, KeyState, TraversalDirection};
use net_traits::net_error_list::NetError; use net_traits::net_error_list::NetError;
@ -46,6 +43,11 @@ use user32;
use webrender_api::{DeviceUintRect, DeviceUintSize, ScrollLocation}; use webrender_api::{DeviceUintRect, DeviceUintSize, ScrollLocation};
#[cfg(target_os = "windows")] #[cfg(target_os = "windows")]
use winapi; use winapi;
use winit;
use winit::{ElementState, Event, MouseButton, MouseScrollDelta, TouchPhase, VirtualKeyCode};
#[cfg(target_os = "macos")]
use winit::os::macos::{ActivationPolicy, WindowBuilderExt};
bitflags! { bitflags! {
struct GlutinKeyModifiers: u8 { struct GlutinKeyModifiers: u8 {
@ -78,7 +80,7 @@ const LINE_HEIGHT: f32 = 38.0;
const MULTISAMPLES: u16 = 16; const MULTISAMPLES: u16 = 16;
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
fn builder_with_platform_options(mut builder: glutin::WindowBuilder) -> glutin::WindowBuilder { fn builder_with_platform_options(mut builder: winit::WindowBuilder) -> winit::WindowBuilder {
if opts::get().headless || opts::get().output_file.is_some() { if opts::get().headless || opts::get().output_file.is_some() {
// Prevent the window from showing in Dock.app, stealing focus, // Prevent the window from showing in Dock.app, stealing focus,
// or appearing at all when running in headless mode or generating an // or appearing at all when running in headless mode or generating an
@ -89,7 +91,7 @@ fn builder_with_platform_options(mut builder: glutin::WindowBuilder) -> glutin::
} }
#[cfg(not(target_os = "macos"))] #[cfg(not(target_os = "macos"))]
fn builder_with_platform_options(builder: glutin::WindowBuilder) -> glutin::WindowBuilder { fn builder_with_platform_options(builder: winit::WindowBuilder) -> winit::WindowBuilder {
builder builder
} }
@ -168,7 +170,7 @@ impl HeadlessContext {
} }
enum WindowKind { enum WindowKind {
Window(glutin::GlWindow, RefCell<glutin::EventsLoop>), Window(glutin::GlWindow, RefCell<winit::EventsLoop>),
Headless(HeadlessContext), Headless(HeadlessContext),
} }
@ -178,7 +180,7 @@ pub struct Window {
screen_size: Size2D<u32>, screen_size: Size2D<u32>,
inner_size: Cell<TypedSize2D<u32, DeviceIndependentPixel>>, inner_size: Cell<TypedSize2D<u32, DeviceIndependentPixel>>,
mouse_down_button: Cell<Option<glutin::MouseButton>>, mouse_down_button: Cell<Option<winit::MouseButton>>,
mouse_down_point: Cell<Point2D<i32>>, mouse_down_point: Cell<Point2D<i32>>,
event_queue: RefCell<Vec<WindowEvent>>, event_queue: RefCell<Vec<WindowEvent>>,
@ -239,8 +241,8 @@ impl Window {
inner_size = TypedSize2D::new(width, height); inner_size = TypedSize2D::new(width, height);
WindowKind::Headless(HeadlessContext::new(width, height)) WindowKind::Headless(HeadlessContext::new(width, height))
} else { } else {
let events_loop = glutin::EventsLoop::new(); let events_loop = winit::EventsLoop::new();
let mut window_builder = glutin::WindowBuilder::new() let mut window_builder = winit::WindowBuilder::new()
.with_title("Servo".to_string()) .with_title("Servo".to_string())
.with_decorations(!opts::get().no_native_titlebar) .with_decorations(!opts::get().no_native_titlebar)
.with_transparency(opts::get().no_native_titlebar) .with_transparency(opts::get().no_native_titlebar)
@ -401,21 +403,21 @@ impl Window {
} }
} }
fn handle_window_event(&self, event: glutin::Event) { fn handle_window_event(&self, event: winit::Event) {
match event { match event {
Event::WindowEvent { Event::WindowEvent {
event: glutin::WindowEvent::ReceivedCharacter(ch), event: winit::WindowEvent::ReceivedCharacter(ch),
.. ..
} => self.handle_received_character(ch), } => self.handle_received_character(ch),
Event::WindowEvent { Event::WindowEvent {
event: glutin::WindowEvent::KeyboardInput { event: winit::WindowEvent::KeyboardInput {
input: glutin::KeyboardInput { input: winit::KeyboardInput {
state, virtual_keycode: Some(virtual_keycode), .. state, virtual_keycode: Some(virtual_keycode), ..
}, .. }, ..
}, .. }, ..
} => self.handle_keyboard_input(state, virtual_keycode), } => self.handle_keyboard_input(state, virtual_keycode),
Event::WindowEvent { Event::WindowEvent {
event: glutin::WindowEvent::MouseInput { event: winit::WindowEvent::MouseInput {
state, button, .. state, button, ..
}, .. }, ..
} => { } => {
@ -425,7 +427,7 @@ impl Window {
} }
}, },
Event::WindowEvent { Event::WindowEvent {
event: glutin::WindowEvent::CursorMoved { event: winit::WindowEvent::CursorMoved {
position: (x, y), position: (x, y),
.. ..
}, },
@ -436,7 +438,7 @@ impl Window {
WindowEvent::MouseWindowMoveEventClass(TypedPoint2D::new(x as f32, y as f32))); WindowEvent::MouseWindowMoveEventClass(TypedPoint2D::new(x as f32, y as f32)));
} }
Event::WindowEvent { Event::WindowEvent {
event: glutin::WindowEvent::MouseWheel { delta, phase, .. }, event: winit::WindowEvent::MouseWheel { delta, phase, .. },
.. ..
} => { } => {
let (dx, dy) = match delta { let (dx, dy) = match delta {
@ -448,7 +450,7 @@ impl Window {
self.scroll_window(scroll_location, phase); self.scroll_window(scroll_location, phase);
}, },
Event::WindowEvent { Event::WindowEvent {
event: glutin::WindowEvent::Touch(touch), event: winit::WindowEvent::Touch(touch),
.. ..
} => { } => {
use script_traits::TouchId; use script_traits::TouchId;
@ -459,17 +461,17 @@ impl Window {
self.event_queue.borrow_mut().push(WindowEvent::Touch(phase, id, point)); self.event_queue.borrow_mut().push(WindowEvent::Touch(phase, id, point));
} }
Event::WindowEvent { Event::WindowEvent {
event: glutin::WindowEvent::Refresh, event: winit::WindowEvent::Refresh,
.. ..
} => self.event_queue.borrow_mut().push(WindowEvent::Refresh), } => self.event_queue.borrow_mut().push(WindowEvent::Refresh),
Event::WindowEvent { Event::WindowEvent {
event: glutin::WindowEvent::Closed, event: winit::WindowEvent::Closed,
.. ..
} => { } => {
self.event_queue.borrow_mut().push(WindowEvent::Quit); self.event_queue.borrow_mut().push(WindowEvent::Quit);
} }
Event::WindowEvent { Event::WindowEvent {
event: glutin::WindowEvent::Resized(width, height), event: winit::WindowEvent::Resized(width, height),
.. ..
} => { } => {
// width and height are DevicePixel. // width and height are DevicePixel.
@ -524,7 +526,7 @@ impl Window {
} }
/// Helper function to handle a click /// Helper function to handle a click
fn handle_mouse(&self, button: glutin::MouseButton, action: glutin::ElementState, x: i32, y: i32) { fn handle_mouse(&self, button: winit::MouseButton, action: winit::ElementState, x: i32, y: i32) {
use script_traits::MouseButton; use script_traits::MouseButton;
// FIXME(tkuehn): max pixel dist should be based on pixel density // FIXME(tkuehn): max pixel dist should be based on pixel density
@ -587,9 +589,9 @@ impl Window {
} }
} }
if stop || self.is_animating() { if stop || self.is_animating() {
glutin::ControlFlow::Break winit::ControlFlow::Break
} else { } else {
glutin::ControlFlow::Continue winit::ControlFlow::Continue
} }
}); });
} }
@ -715,7 +717,7 @@ impl Window {
} }
} }
fn glutin_key_to_script_key(key: glutin::VirtualKeyCode) -> Result<constellation_msg::Key, ()> { fn glutin_key_to_script_key(key: winit::VirtualKeyCode) -> Result<constellation_msg::Key, ()> {
// TODO(negge): add more key mappings // TODO(negge): add more key mappings
match key { match key {
VirtualKeyCode::A => Ok(Key::A), VirtualKeyCode::A => Ok(Key::A),
@ -957,7 +959,7 @@ impl WindowMethods for Window {
fn create_event_loop_waker(&self) -> Box<EventLoopWaker> { fn create_event_loop_waker(&self) -> Box<EventLoopWaker> {
struct GlutinEventLoopWaker { struct GlutinEventLoopWaker {
proxy: Option<Arc<glutin::EventsLoopProxy>>, proxy: Option<Arc<winit::EventsLoopProxy>>,
} }
impl GlutinEventLoopWaker { impl GlutinEventLoopWaker {
fn new(window: &Window) -> GlutinEventLoopWaker { fn new(window: &Window) -> GlutinEventLoopWaker {
@ -1061,7 +1063,7 @@ impl WindowMethods for Window {
fn set_cursor(&self, cursor: CursorKind) { fn set_cursor(&self, cursor: CursorKind) {
match self.kind { match self.kind {
WindowKind::Window(ref window, ..) => { WindowKind::Window(ref window, ..) => {
use glutin::MouseCursor; use winit::MouseCursor;
let glutin_cursor = match cursor { let glutin_cursor = match cursor {
CursorKind::Auto => MouseCursor::Default, CursorKind::Auto => MouseCursor::Default,
@ -1272,7 +1274,7 @@ fn glutin_phase_to_touch_event_type(phase: TouchPhase) -> TouchEventType {
} }
fn is_printable(key_code: VirtualKeyCode) -> bool { fn is_printable(key_code: VirtualKeyCode) -> bool {
use glutin::VirtualKeyCode::*; use winit::VirtualKeyCode::*;
match key_code { match key_code {
Escape | Escape |
F1 | F1 |

Просмотреть файл

@ -42,6 +42,7 @@ extern crate sig;
extern crate style_traits; extern crate style_traits;
extern crate tinyfiledialogs; extern crate tinyfiledialogs;
extern crate webrender_api; extern crate webrender_api;
extern crate winit;
#[cfg(target_os = "windows")] extern crate winapi; #[cfg(target_os = "windows")] extern crate winapi;
#[cfg(target_os = "windows")] extern crate user32; #[cfg(target_os = "windows")] extern crate user32;