aboutsummaryrefslogtreecommitdiffstats
path: root/components/script
diff options
context:
space:
mode:
authorConnor Brewster <brewsterc@my.caspercollege.edu>2016-04-25 14:59:48 -0600
committerConnor Brewster <brewsterc@my.caspercollege.edu>2016-05-03 22:09:35 -0600
commitdc85be4be5510f9ef204a35ea7461f645cbc7e39 (patch)
treed8273b417823db1fbe6f5e18a693b77c510359be /components/script
parent3f2ceeff5dd1966dafe34381e20ec405ab72ccee (diff)
downloadservo-dc85be4be5510f9ef204a35ea7461f645cbc7e39.tar.gz
servo-dc85be4be5510f9ef204a35ea7461f645cbc7e39.zip
Implement alert dialogs
Fixed conflict Fixed merge issue Finished implementation Disable tinyfiledialogs on Windows addressed comments Use ancestor's SubpageId Move display alert from method to function Add extra test for nested iframes Addressed comments Updated tinyfiledialogs
Diffstat (limited to 'components/script')
-rw-r--r--components/script/Cargo.toml3
-rw-r--r--components/script/dom/window.rs25
-rw-r--r--components/script/lib.rs2
3 files changed, 25 insertions, 5 deletions
diff --git a/components/script/Cargo.toml b/components/script/Cargo.toml
index d032bc81921..1e3326ae356 100644
--- a/components/script/Cargo.toml
+++ b/components/script/Cargo.toml
@@ -13,6 +13,9 @@ path = "lib.rs"
[features]
debugmozjs = ['js/debugmozjs']
+[target.'cfg(any(target_os = "macos", target_os = "linux"))'.dependencies]
+tinyfiledialogs = {git = "https://github.com/jdm/tinyfiledialogs"}
+
[dependencies]
plugins = {path = "../plugins"}
util = {path = "../util"}
diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs
index 94b6d2c7fb3..2f017c3b107 100644
--- a/components/script/dom/window.rs
+++ b/components/script/dom/window.rs
@@ -59,7 +59,7 @@ use script_thread::SendableMainThreadScriptChan;
use script_thread::{MainThreadScriptChan, MainThreadScriptMsg, RunnableWrapper};
use script_traits::{ConstellationControlMsg, UntrustedNodeAddress};
use script_traits::{DocumentState, MsDuration, ScriptToCompositorMsg, TimerEvent, TimerEventId};
-use script_traits::{MozBrowserEvent, ScriptMsg as ConstellationMsg, TimerEventRequest, TimerSource};
+use script_traits::{ScriptMsg as ConstellationMsg, TimerEventRequest, TimerSource};
use std::ascii::AsciiExt;
use std::borrow::ToOwned;
use std::cell::Cell;
@@ -85,6 +85,8 @@ use task_source::networking::NetworkingTaskSource;
use task_source::user_interaction::UserInteractionTaskSource;
use time;
use timers::{IsInterval, OneshotTimerCallback, OneshotTimerHandle, OneshotTimers, TimerCallback};
+#[cfg(any(target_os = "macos", target_os = "linux"))]
+use tinyfiledialogs::{self, MessageBoxIcon};
use url::Url;
use util::geometry::{self, MAX_RECT};
use util::str::{DOMString, HTML_SPACE_CHARACTERS};
@@ -343,6 +345,16 @@ impl Window {
}
}
+#[cfg(any(target_os = "macos", target_os = "linux"))]
+fn display_alert_dialog(message: &str) {
+ tinyfiledialogs::message_box_ok("Alert!", message, MessageBoxIcon::Warning);
+}
+
+#[cfg(not(any(target_os = "macos", target_os = "linux")))]
+fn display_alert_dialog(_message: &str) {
+ // tinyfiledialogs not supported on Windows
+}
+
// https://html.spec.whatwg.org/multipage/#atob
pub fn base64_btoa(input: DOMString) -> Fallible<DOMString> {
// "The btoa() method must throw an InvalidCharacterError exception if
@@ -425,10 +437,13 @@ impl WindowMethods for Window {
stdout.flush().unwrap();
stderr.flush().unwrap();
- // https://developer.mozilla.org/en-US/docs/Web/Events/mozbrowsershowmodalprompt
- let event = MozBrowserEvent::ShowModalPrompt("alert".to_owned(), "Alert".to_owned(),
- String::from(s), "".to_owned());
- self.Document().trigger_mozbrowser_event(event);
+ let (sender, receiver) = ipc::channel().unwrap();
+ self.constellation_chan().0.send(ConstellationMsg::Alert(self.pipeline(), s.to_string(), sender)).unwrap();
+
+ let should_display_alert_dialog = receiver.recv().unwrap();
+ if should_display_alert_dialog {
+ display_alert_dialog(&s);
+ }
}
// https://html.spec.whatwg.org/multipage/#dom-window-close
diff --git a/components/script/lib.rs b/components/script/lib.rs
index 05700431c3d..4feaae05845 100644
--- a/components/script/lib.rs
+++ b/components/script/lib.rs
@@ -73,6 +73,8 @@ extern crate smallvec;
#[macro_use]
extern crate style;
extern crate time;
+#[cfg(any(target_os = "macos", target_os = "linux"))]
+extern crate tinyfiledialogs;
extern crate unicase;
extern crate url;
#[macro_use]