Navigation Menu

Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
avr1254 committed Jul 14, 2020
2 parents 890d065 + bc8cfe3 commit de1a9bb
Show file tree
Hide file tree
Showing 69 changed files with 754 additions and 94 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions components/compositing/lib.rs
Expand Up @@ -109,6 +109,8 @@ pub enum ConstellationMsg {
MediaSessionAction(MediaSessionActionType),
/// Toggle browser visibility.
ChangeBrowserVisibility(TopLevelBrowsingContextId, bool),
/// Virtual keyboard was dismissed
IMEDismissed,
}

impl fmt::Debug for ConstellationMsg {
Expand Down Expand Up @@ -140,6 +142,7 @@ impl fmt::Debug for ConstellationMsg {
ExitFullScreen(..) => "ExitFullScreen",
MediaSessionAction(..) => "MediaSessionAction",
ChangeBrowserVisibility(..) => "ChangeBrowserVisibility",
IMEDismissed => "IMEDismissed",
};
write!(formatter, "ConstellationMsg::{}", variant)
}
Expand Down
3 changes: 3 additions & 0 deletions components/compositing/windowing.rs
Expand Up @@ -102,6 +102,8 @@ pub enum WindowEvent {
MediaSessionAction(MediaSessionActionType),
/// Set browser visibility. A hidden browser will not tick the animations.
ChangeBrowserVisibility(TopLevelBrowsingContextId, bool),
/// Virtual keyboard was dismissed
IMEDismissed,
}

impl Debug for WindowEvent {
Expand Down Expand Up @@ -134,6 +136,7 @@ impl Debug for WindowEvent {
WindowEvent::ExitFullScreen(..) => write!(f, "ExitFullScreen"),
WindowEvent::MediaSessionAction(..) => write!(f, "MediaSessionAction"),
WindowEvent::ChangeBrowserVisibility(..) => write!(f, "ChangeBrowserVisibility"),
WindowEvent::IMEDismissed => write!(f, "IMEDismissed"),
}
}
}
Expand Down
36 changes: 36 additions & 0 deletions components/constellation/constellation.rs
Expand Up @@ -1470,6 +1470,9 @@ where
FromCompositorMsg::Keyboard(key_event) => {
self.handle_key_msg(key_event);
},
FromCompositorMsg::IMEDismissed => {
self.handle_ime_dismissed();
},
// Perform a navigation previously requested by script, if approved by the embedder.
// If there is already a pending page (self.pending_changes), it will not be overridden;
// However, if the id is not encompassed by another change, it will be.
Expand Down Expand Up @@ -4074,6 +4077,39 @@ where
session_history.replace_history_state(pipeline_id, history_state_id, url);
}

fn handle_ime_dismissed(&mut self) {
// Send to the focused browsing contexts' current pipeline.
let focused_browsing_context_id = self
.active_browser_id
.and_then(|browser_id| self.browsers.get(&browser_id))
.map(|browser| browser.focused_browsing_context_id);
if let Some(browsing_context_id) = focused_browsing_context_id {
let pipeline_id = match self.browsing_contexts.get(&browsing_context_id) {
Some(ctx) => ctx.pipeline_id,
None => {
return warn!(
"Got IME dismissed event for nonexistent browsing context {}.",
browsing_context_id,
);
},
};
let msg =
ConstellationControlMsg::SendEvent(pipeline_id, CompositorEvent::IMEDismissedEvent);
let result = match self.pipelines.get(&pipeline_id) {
Some(pipeline) => pipeline.event_loop.send(msg),
None => {
return debug!(
"Pipeline {:?} got IME dismissed event after closure.",
pipeline_id
);
},
};
if let Err(e) = result {
self.handle_send_error(pipeline_id, e);
}
}
}

fn handle_key_msg(&mut self, event: KeyboardEvent) {
// Send to the focused browsing contexts' current pipeline. If it
// doesn't exist, fall back to sending to the compositor.
Expand Down
8 changes: 7 additions & 1 deletion components/devtools/actor.rs
Expand Up @@ -159,7 +159,13 @@ impl ActorRegistry {
msg: &Map<String, Value>,
stream: &mut TcpStream,
) -> Result<(), ()> {
let to = msg.get("to").unwrap().as_str().unwrap();
let to = match msg.get("to") {
Some(to) => to.as_str().unwrap(),
None => {
warn!("Received unexpected message: {:?}", msg);
return Err(());
},
};

match self.actors.get(to) {
None => debug!("message received for unknown actor \"{}\"", to),
Expand Down
10 changes: 7 additions & 3 deletions components/devtools/actors/browsing_context.rs
Expand Up @@ -12,8 +12,8 @@ use crate::actors::emulation::EmulationActor;
use crate::actors::inspector::InspectorActor;
use crate::actors::performance::PerformanceActor;
use crate::actors::profiler::ProfilerActor;
use crate::actors::root::RootActor;
use crate::actors::stylesheets::StyleSheetsActor;
use crate::actors::tab::TabDescriptorActor;
use crate::actors::thread::ThreadActor;
use crate::actors::timeline::TimelineActor;
use crate::protocol::JsonPacketStream;
Expand Down Expand Up @@ -130,6 +130,7 @@ pub struct BrowsingContextActor {
pub performance: String,
pub styleSheets: String,
pub thread: String,
pub tab: String,
pub streams: RefCell<Vec<TcpStream>>,
pub browsing_context_id: BrowsingContextId,
pub active_pipeline: Cell<PipelineId>,
Expand Down Expand Up @@ -266,6 +267,9 @@ impl BrowsingContextActor {
let thread = ThreadActor::new(actors.new_name("context"));

let DevtoolsPageInfo { title, url } = page_info;

let tabdesc = TabDescriptorActor::new(actors, name.clone());

let target = BrowsingContextActor {
name: name,
script_chan: script_sender,
Expand All @@ -278,6 +282,7 @@ impl BrowsingContextActor {
profiler: profiler.name(),
performance: performance.name(),
styleSheets: styleSheets.name(),
tab: tabdesc.name(),
thread: thread.name(),
streams: RefCell::new(Vec::new()),
browsing_context_id: id,
Expand All @@ -291,9 +296,8 @@ impl BrowsingContextActor {
actors.register(Box::new(performance));
actors.register(Box::new(styleSheets));
actors.register(Box::new(thread));
actors.register(Box::new(tabdesc));

let root = actors.find_mut::<RootActor>("root");
root.tabs.push(target.name.clone());
target
}

Expand Down
16 changes: 10 additions & 6 deletions components/devtools/actors/root.rs
Expand Up @@ -7,9 +7,9 @@
/// Connection point for all new remote devtools interactions, providing lists of know actors
/// that perform more specific actions (targets, addons, browser chrome, etc.)
use crate::actor::{Actor, ActorMessageStatus, ActorRegistry};
use crate::actors::browsing_context::{BrowsingContextActor, BrowsingContextActorMsg};
use crate::actors::device::DeviceActor;
use crate::actors::performance::PerformanceActor;
use crate::actors::tab::{TabDescriptorActor, TabDescriptorActorMsg};
use crate::actors::worker::{WorkerActor, WorkerMsg};
use crate::protocol::{ActorDescription, JsonPacketStream};
use serde_json::{Map, Value};
Expand Down Expand Up @@ -45,13 +45,13 @@ struct GetRootReply {
struct ListTabsReply {
from: String,
selected: u32,
tabs: Vec<BrowsingContextActorMsg>,
tabs: Vec<TabDescriptorActorMsg>,
}

#[derive(Serialize)]
struct GetTabReply {
from: String,
tab: BrowsingContextActorMsg,
tab: TabDescriptorActorMsg,
}

#[derive(Serialize)]
Expand Down Expand Up @@ -181,7 +181,11 @@ impl Actor for RootActor {
tabs: self
.tabs
.iter()
.map(|target| registry.find::<BrowsingContextActor>(target).encodable())
.map(|target| {
registry
.find::<TabDescriptorActor>(target)
.encodable(&registry)
})
.collect(),
};
stream.write_json_packet(&actor);
Expand Down Expand Up @@ -211,10 +215,10 @@ impl Actor for RootActor {
},

"getTab" => {
let tab = registry.find::<BrowsingContextActor>(&self.tabs[0]);
let tab = registry.find::<TabDescriptorActor>(&self.tabs[0]);
let reply = GetTabReply {
from: self.name(),
tab: tab.encodable(),
tab: tab.encodable(&registry),
};
stream.write_json_packet(&reply);
ActorMessageStatus::Processed
Expand Down
101 changes: 101 additions & 0 deletions components/devtools/actors/tab.rs
@@ -0,0 +1,101 @@
/* 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 https://mozilla.org/MPL/2.0/. */

use crate::actor::{Actor, ActorMessageStatus, ActorRegistry};
use crate::actors::browsing_context::{BrowsingContextActor, BrowsingContextActorMsg};
use crate::actors::root::RootActor;
use crate::protocol::JsonPacketStream;
use serde_json::{Map, Value};
use std::net::TcpStream;

#[derive(Serialize)]
pub struct TabDescriptorTraits {
getFavicon: bool,
hasTabInfo: bool,
watcher: bool,
}

#[derive(Serialize)]
pub struct TabDescriptorActorMsg {
actor: String,
title: String,
url: String,
outerWindowID: u32,
browsingContextId: u32,
traits: TabDescriptorTraits,
}

#[derive(Serialize)]
struct GetTargetReply {
from: String,
frame: BrowsingContextActorMsg,
}

pub struct TabDescriptorActor {
name: String,
browsing_context_actor: String,
}

impl Actor for TabDescriptorActor {
fn name(&self) -> String {
self.name.clone()
}

fn handle_message(
&self,
registry: &ActorRegistry,
msg_type: &str,
_msg: &Map<String, Value>,
stream: &mut TcpStream,
) -> Result<ActorMessageStatus, ()> {
Ok(match msg_type {
"getTarget" => {
let frame = registry
.find::<BrowsingContextActor>(&self.browsing_context_actor)
.encodable();
stream.write_json_packet(&GetTargetReply {
from: self.name(),
frame,
});
ActorMessageStatus::Processed
},
_ => ActorMessageStatus::Ignored,
})
}
}

impl TabDescriptorActor {
pub(crate) fn new(
actors: &mut ActorRegistry,
browsing_context_actor: String,
) -> TabDescriptorActor {
let name = actors.new_name("tabDescription");
let root = actors.find_mut::<RootActor>("root");
root.tabs.push(name.clone());
TabDescriptorActor {
name: name,
browsing_context_actor,
}
}

pub fn encodable(&self, registry: &ActorRegistry) -> TabDescriptorActorMsg {
let ctx_actor = registry.find::<BrowsingContextActor>(&self.browsing_context_actor);

let title = ctx_actor.title.borrow().clone();
let url = ctx_actor.url.borrow().clone();

TabDescriptorActorMsg {
title,
url,
actor: self.name(),
browsingContextId: ctx_actor.browsing_context_id.index.0.get(),
outerWindowID: ctx_actor.active_pipeline.get().index.0.get(),
traits: TabDescriptorTraits {
getFavicon: false,
hasTabInfo: true,
watcher: false,
},
}
}
}
1 change: 1 addition & 0 deletions components/devtools/lib.rs
Expand Up @@ -66,6 +66,7 @@ mod actors {
pub mod profiler;
pub mod root;
pub mod stylesheets;
pub mod tab;
pub mod thread;
pub mod timeline;
pub mod worker;
Expand Down
7 changes: 7 additions & 0 deletions components/script/dom/document.rs
Expand Up @@ -1722,6 +1722,13 @@ impl Document {
self.window.reflow(ReflowGoal::Full, ReflowReason::KeyEvent);
}

pub fn ime_dismissed(&self) {
self.request_focus(
self.GetBody().as_ref().map(|e| &*e.upcast()),
FocusType::Element,
)
}

pub fn dispatch_composition_event(
&self,
composition_event: ::keyboard_types::CompositionEvent,
Expand Down
12 changes: 10 additions & 2 deletions components/script/script_thread.rs
Expand Up @@ -129,8 +129,8 @@ use profile_traits::time::{self as profile_time, profile, ProfilerCategory};
use script_layout_interface::message::{self, LayoutThreadInit, Msg, ReflowGoal};
use script_traits::webdriver_msg::WebDriverScriptCommand;
use script_traits::CompositorEvent::{
CompositionEvent, KeyboardEvent, MouseButtonEvent, MouseMoveEvent, ResizeEvent, TouchEvent,
WheelEvent,
CompositionEvent, IMEDismissedEvent, KeyboardEvent, MouseButtonEvent, MouseMoveEvent,
ResizeEvent, TouchEvent, WheelEvent,
};
use script_traits::{
AnimationTickType, CompositorEvent, ConstellationControlMsg, DiscardBrowsingContext,
Expand Down Expand Up @@ -3583,6 +3583,14 @@ impl ScriptThread {
document.dispatch_key_event(key_event);
},

IMEDismissedEvent => {
let document = match self.documents.borrow().find_document(pipeline_id) {
Some(document) => document,
None => return warn!("Message sent to closed pipeline {}.", pipeline_id),
};
document.ime_dismissed();
},

CompositionEvent(composition_event) => {
let document = match self.documents.borrow().find_document(pipeline_id) {
Some(document) => document,
Expand Down
2 changes: 2 additions & 0 deletions components/script_traits/lib.rs
Expand Up @@ -570,6 +570,8 @@ pub enum CompositorEvent {
KeyboardEvent(KeyboardEvent),
/// An event from the IME is dispatched.
CompositionEvent(CompositionEvent),
/// Virtual keyboard was dismissed
IMEDismissedEvent,
}

/// Requests a TimerEvent-Message be sent after the given duration.
Expand Down
10 changes: 10 additions & 0 deletions components/servo/lib.rs
Expand Up @@ -663,6 +663,16 @@ where
}
},

WindowEvent::IMEDismissed => {
let msg = ConstellationMsg::IMEDismissed;
if let Err(e) = self.constellation_chan.send(msg) {
warn!(
"Sending IMEDismissed event to constellation failed ({:?}).",
e
);
}
},

WindowEvent::Quit => {
self.compositor.maybe_start_shutting_down();
},
Expand Down
5 changes: 5 additions & 0 deletions ports/libsimpleservo/api/src/lib.rs
Expand Up @@ -560,6 +560,11 @@ impl ServoGlue {
}
}

pub fn ime_dismissed(&mut self) -> Result<(), &'static str> {
info!("ime_dismissed");
self.process_event(WindowEvent::IMEDismissed)
}

pub fn on_context_menu_closed(
&mut self,
result: ContextMenuResult,
Expand Down

0 comments on commit de1a9bb

Please sign in to comment.