mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Notify the embedder when it should display or hide an IME
This commit is contained in:
parent
05fe8fa08d
commit
42886613d3
8 changed files with 93 additions and 2 deletions
|
@ -812,6 +812,11 @@ impl Document {
|
|||
elem.set_focus_state(false);
|
||||
// FIXME: pass appropriate relatedTarget
|
||||
self.fire_focus_event(FocusEventType::Blur, node, None);
|
||||
|
||||
// Notify the embedder to hide the input method.
|
||||
if elem.input_method_type().is_some() {
|
||||
self.send_to_constellation(ScriptMsg::HideIME);
|
||||
}
|
||||
}
|
||||
|
||||
self.focused.set(self.possibly_focused.get().r());
|
||||
|
@ -826,6 +831,11 @@ impl Document {
|
|||
if focus_type == FocusType::Element {
|
||||
self.send_to_constellation(ScriptMsg::Focus);
|
||||
}
|
||||
|
||||
// Notify the embedder to display an input method.
|
||||
if let Some(kind) = elem.input_method_type() {
|
||||
self.send_to_constellation(ScriptMsg::ShowIME(kind));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -83,6 +83,7 @@ use html5ever::serialize::TraversalScope;
|
|||
use html5ever::serialize::TraversalScope::{ChildrenOnly, IncludeNode};
|
||||
use js::jsapi::Heap;
|
||||
use js::jsval::JSVal;
|
||||
use msg::constellation_msg::InputMethodType;
|
||||
use net_traits::request::CorsSettings;
|
||||
use ref_filter_map::ref_filter_map;
|
||||
use script_layout_interface::message::ReflowGoal;
|
||||
|
@ -1087,6 +1088,22 @@ impl Element {
|
|||
None
|
||||
}
|
||||
|
||||
// Returns the kind of IME control needed for a focusable element, if any.
|
||||
pub fn input_method_type(&self) -> Option<InputMethodType> {
|
||||
if !self.is_focusable_area() {
|
||||
return None;
|
||||
}
|
||||
|
||||
if let Some(input) = self.downcast::<HTMLInputElement>() {
|
||||
input.input_type().as_ime_type()
|
||||
} else if self.is::<HTMLTextAreaElement>() {
|
||||
Some(InputMethodType::Text)
|
||||
} else {
|
||||
// Other focusable elements that are not input fields.
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_focusable_area(&self) -> bool {
|
||||
if self.is_actually_disabled() {
|
||||
return false;
|
||||
|
|
|
@ -40,6 +40,7 @@ use dom::virtualmethods::VirtualMethods;
|
|||
use dom_struct::dom_struct;
|
||||
use html5ever::{LocalName, Prefix};
|
||||
use mime_guess;
|
||||
use msg::constellation_msg::InputMethodType;
|
||||
use net_traits::{CoreResourceMsg, IpcSend};
|
||||
use net_traits::blob_url_store::get_blob_origin;
|
||||
use net_traits::filemanager_thread::{FileManagerThreadMsg, FilterPattern};
|
||||
|
@ -137,6 +138,25 @@ impl InputType {
|
|||
InputType::Week => "week",
|
||||
}
|
||||
}
|
||||
|
||||
pub fn as_ime_type(&self) -> Option<InputMethodType> {
|
||||
match *self {
|
||||
InputType::Color => Some(InputMethodType::Color),
|
||||
InputType::Date => Some(InputMethodType::Date),
|
||||
InputType::DatetimeLocal => Some(InputMethodType::DatetimeLocal),
|
||||
InputType::Email => Some(InputMethodType::Email),
|
||||
InputType::Month => Some(InputMethodType::Month),
|
||||
InputType::Number => Some(InputMethodType::Number),
|
||||
InputType::Password => Some(InputMethodType::Password),
|
||||
InputType::Search => Some(InputMethodType::Search),
|
||||
InputType::Tel => Some(InputMethodType::Tel),
|
||||
InputType::Text => Some(InputMethodType::Text),
|
||||
InputType::Time => Some(InputMethodType::Time),
|
||||
InputType::Url => Some(InputMethodType::Url),
|
||||
InputType::Week => Some(InputMethodType::Week),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> From<&'a Atom> for InputType {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue