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

WIP - Added prompt user for url #17062

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Some generated files are not rendered by default. Learn more.

@@ -28,6 +28,7 @@ use std::sync::Arc;
use url::{Url, Position};

pub use url::Host;
pub use url::ParseError;

#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, HeapSizeOf)]
pub struct ServoUrl(Arc<Url>);
@@ -22,6 +22,7 @@ servo_geometry = {path = "../../components/geometry"}
servo_config = {path = "../../components/config"}
servo_url = {path = "../../components/url"}
style_traits = {path = "../../components/style_traits"}
tinyfiledialogs = "2.5.9"
webrender_traits = {git = "https://github.com/servo/webrender", features = ["ipc"]}

[target.'cfg(any(target_os = "linux", target_os = "macos"))'.dependencies]
@@ -22,6 +22,7 @@ extern crate servo_config;
extern crate servo_geometry;
extern crate servo_url;
extern crate style_traits;
extern crate tinyfiledialogs;
extern crate webrender_traits;

#[cfg(target_os = "windows")] extern crate winapi;
@@ -12,6 +12,7 @@ use euclid::{Point2D, Size2D, TypedPoint2D};
use euclid::rect::TypedRect;
use euclid::scale_factor::ScaleFactor;
use euclid::size::TypedSize2D;
use tinyfiledialogs;
#[cfg(target_os = "windows")]
use gdi32;
use gleam::gl;
@@ -32,7 +33,7 @@ use servo_config::opts;
use servo_config::prefs::PREFS;
use servo_config::resource_files;
use servo_geometry::DeviceIndependentPixel;
use servo_url::ServoUrl;
use servo_url::{ParseError, ServoUrl};
use std::cell::{Cell, RefCell};
#[cfg(any(target_os = "linux", target_os = "macos"))]
use std::ffi::CString;
@@ -1268,12 +1269,33 @@ impl WindowMethods for Window {
self.event_queue.borrow_mut().push(WindowEvent::Reload);
}
}
//On windows 8.1 when pressing ctrl + anything, ch = Some('\u{unicode_value}')

This comment has been minimized.

@paulrouget

paulrouget May 27, 2017

Contributor

We need to investigate that before merging this PR.

//so matching ch with Some('l') doesn't work here
//Instead we match with what's inside the key variable
(CMD_OR_CONTROL, _, Key::L) => {
if let Some(true) = PREFS.get("shell.builtin-key-shortcuts.enabled").as_boolean() {
let fallback_url: String = if let Some(ref current_url) = *self.current_url.borrow() {
current_url.to_string()
} else {
String::from("Your URL here")
};
//TODO:
// 1) make it work when clicking on "validate" button - Currently only works when pressing enter
// 2) Erratic behavior - sometime the dialog reloads empty after pressing enter
// (windows 8.1)
if let Some(user_input) = tinyfiledialogs::input_box("Enter a URL", "URL:", &fallback_url) {
if let Ok(sanitized_url) = sanitize_and_parse_url(user_input) {
//Maybe need to change WindowEvent::LoadUrl() to accept a ServoUrl instead of a String?
self.event_queue.borrow_mut().push(WindowEvent::LoadUrl(sanitized_url.to_string()));
}
}
}
}
(CMD_OR_CONTROL, Some('q'), _) => {
if let Some(true) = PREFS.get("shell.builtin-key-shortcuts.enabled").as_boolean() {
self.event_queue.borrow_mut().push(WindowEvent::Quit);
}
}

_ => {
self.platform_handle_key(key, mods);
}
@@ -1402,6 +1424,10 @@ fn is_printable(key_code: VirtualKeyCode) -> bool {
}
}

fn sanitize_and_parse_url(url: String) -> Result<ServoUrl, ParseError> {
ServoUrl::parse(url.trim())
}

#[cfg(not(target_os = "windows"))]
fn filter_nonprintable(ch: char, key_code: VirtualKeyCode) -> Option<char> {
if is_printable(key_code) {
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.