aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2018-04-23 11:55:27 -0400
committerGitHub <noreply@github.com>2018-04-23 11:55:27 -0400
commitc5f7c9ccf33fac4bf2c1750e7040b76216fc912c (patch)
treef04f4b80566b6acea2323e9fceedbd2aab9a97b2 /components/script/dom
parent05fe8fa08d507836ce5659ff56f83022a90b241a (diff)
parent42886613d32f2daff25f1f3ce7a7328bcc2306f7 (diff)
downloadservo-c5f7c9ccf33fac4bf2c1750e7040b76216fc912c.tar.gz
servo-c5f7c9ccf33fac4bf2c1750e7040b76216fc912c.zip
Auto merge of #20676 - fabricedesre:ime-embedding, r=cbrewster
Notify the embedder when it should display or hide an IME <!-- Please describe your changes on the following line: --> This adds a couple of embedder messages triggered when an editable element is focused or blured. The embedder also gets the type of data to edit so it can display a different keyboard type or a custom input method eg. for color choosing. This is a partial fix for issue #12127 --- <!-- 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 build-geckolib` does not report any errors - [X] `./mach test-tidy` does not report any errors - [ ] These changes fix #__ (github issue number if applicable). <!-- Either: --> - [ ] There are tests for these changes OR - [X] These changes do not require tests because there are no tests for the embedding api :( <!-- 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. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/20676) <!-- Reviewable:end -->
Diffstat (limited to 'components/script/dom')
-rw-r--r--components/script/dom/document.rs10
-rw-r--r--components/script/dom/element.rs17
-rwxr-xr-xcomponents/script/dom/htmlinputelement.rs20
3 files changed, 47 insertions, 0 deletions
diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs
index 71df0e70356..5c9cd57b128 100644
--- a/components/script/dom/document.rs
+++ b/components/script/dom/document.rs
@@ -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));
+ }
}
}
diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs
index a53446fd4a3..11b9168eb41 100644
--- a/components/script/dom/element.rs
+++ b/components/script/dom/element.rs
@@ -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;
diff --git a/components/script/dom/htmlinputelement.rs b/components/script/dom/htmlinputelement.rs
index 5618b366702..ab7d55d5b9a 100755
--- a/components/script/dom/htmlinputelement.rs
+++ b/components/script/dom/htmlinputelement.rs
@@ -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 {