diff options
author | Manish Goregaokar <manishsmail@gmail.com> | 2015-12-15 17:52:09 +0530 |
---|---|---|
committer | Manish Goregaokar <manishsmail@gmail.com> | 2016-01-03 13:18:24 +0530 |
commit | 23e7dfa57b6e4c8aa26dc74b742e65c31abbe50d (patch) | |
tree | 011532c4f1421a19a55843cc8ad5311e4a09c66e /components | |
parent | 1b0053f8b1d26d16fa8bf8eb906a947a8fa291da (diff) | |
download | servo-23e7dfa57b6e4c8aa26dc74b742e65c31abbe50d.tar.gz servo-23e7dfa57b6e4c8aa26dc74b742e65c31abbe50d.zip |
Relayout text input elements on blur
Diffstat (limited to 'components')
-rw-r--r-- | components/layout/wrapper.rs | 7 | ||||
-rw-r--r-- | components/script/dom/document.rs | 3 | ||||
-rw-r--r-- | components/script/dom/htmlinputelement.rs | 10 | ||||
-rw-r--r-- | components/script/dom/htmltextareaelement.rs | 11 | ||||
-rw-r--r-- | components/script/dom/virtualmethods.rs | 8 |
5 files changed, 33 insertions, 6 deletions
diff --git a/components/layout/wrapper.rs b/components/layout/wrapper.rs index 147fda916e3..f5ae6e23341 100644 --- a/components/layout/wrapper.rs +++ b/components/layout/wrapper.rs @@ -957,9 +957,10 @@ impl<'ln> ThreadSafeLayoutNode<'ln> for ServoThreadSafeLayoutNode<'ln> { }; if let Some(area) = this.downcast::<HTMLTextAreaElement>() { - let insertion_point = unsafe { area.get_absolute_insertion_point_for_layout() }; - let text = unsafe { area.get_value_for_layout() }; - return Some(CharIndex(search_index(insertion_point, text.char_indices()))); + if let Some(insertion_point) = unsafe { area.get_absolute_insertion_point_for_layout() } { + let text = unsafe { area.get_value_for_layout() }; + return Some(CharIndex(search_index(insertion_point, text.char_indices()))); + } } if let Some(input) = this.downcast::<HTMLInputElement>() { let insertion_point_index = unsafe { input.get_insertion_point_index_for_layout() }; diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index f2593121c6c..5bbbc4c1e62 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -72,6 +72,7 @@ use dom::touchevent::TouchEvent; use dom::touchlist::TouchList; use dom::treewalker::TreeWalker; use dom::uievent::UIEvent; +use dom::virtualmethods::{VirtualMethods, vtable_for}; use dom::window::{ReflowReason, Window}; use euclid::point::Point2D; use html5ever::tree_builder::{LimitedQuirks, NoQuirks, Quirks, QuirksMode}; @@ -593,6 +594,8 @@ impl Document { if let Some(ref elem) = self.focused.get() { elem.set_focus_state(false); + let node = vtable_for(&elem.upcast::<Node>()); + node.handle_blur(); } self.focused.set(self.possibly_focused.get().r()); diff --git a/components/script/dom/htmlinputelement.rs b/components/script/dom/htmlinputelement.rs index c94be647354..198fc302f94 100644 --- a/components/script/dom/htmlinputelement.rs +++ b/components/script/dom/htmlinputelement.rs @@ -208,6 +208,9 @@ impl LayoutHTMLInputElementHelpers for LayoutJS<HTMLInputElement> { #[allow(unrooted_must_root)] #[allow(unsafe_code)] unsafe fn get_insertion_point_index_for_layout(self) -> Option<isize> { + if !(*self.unsafe_get()).upcast::<Element>().get_focus_state() { + return None; + } match (*self.unsafe_get()).input_type.get() { InputType::InputText => { let raw = self.get_value_for_layout(); @@ -716,6 +719,13 @@ impl VirtualMethods for HTMLInputElement { } } } + + fn handle_blur(&self) { + if let Some(s) = self.super_type() { + s.handle_blur(); + } + self.force_relayout(); + } } impl FormControl for HTMLInputElement {} diff --git a/components/script/dom/htmltextareaelement.rs b/components/script/dom/htmltextareaelement.rs index b7d99f037c4..95f1438f6e3 100644 --- a/components/script/dom/htmltextareaelement.rs +++ b/components/script/dom/htmltextareaelement.rs @@ -45,7 +45,7 @@ pub trait LayoutHTMLTextAreaElementHelpers { #[allow(unsafe_code)] unsafe fn get_value_for_layout(self) -> String; #[allow(unsafe_code)] - unsafe fn get_absolute_insertion_point_for_layout(self) -> usize; + unsafe fn get_absolute_insertion_point_for_layout(self) -> Option<usize>; #[allow(unsafe_code)] fn get_cols(self) -> u32; #[allow(unsafe_code)] @@ -61,8 +61,13 @@ impl LayoutHTMLTextAreaElementHelpers for LayoutJS<HTMLTextAreaElement> { #[allow(unrooted_must_root)] #[allow(unsafe_code)] - unsafe fn get_absolute_insertion_point_for_layout(self) -> usize { - (*self.unsafe_get()).textinput.borrow_for_layout().get_absolute_insertion_point() + unsafe fn get_absolute_insertion_point_for_layout(self) -> Option<usize> { + if (*self.unsafe_get()).upcast::<Element>().get_focus_state() { + Some((*self.unsafe_get()).textinput.borrow_for_layout() + .get_absolute_insertion_point()) + } else { + None + } } #[allow(unsafe_code)] diff --git a/components/script/dom/virtualmethods.rs b/components/script/dom/virtualmethods.rs index 3540fbddf0f..b60c805c444 100644 --- a/components/script/dom/virtualmethods.rs +++ b/components/script/dom/virtualmethods.rs @@ -102,6 +102,14 @@ pub trait VirtualMethods { } } + /// Called when a previously focused element is no longer focused. + /// Use this to trigger relayouts + fn handle_blur(&self) { + if let Some(s) = self.super_type() { + s.handle_blur(); + } + } + /// https://dom.spec.whatwg.org/#concept-node-adopt-ext fn adopting_steps(&self, old_doc: &Document) { if let Some(ref s) = self.super_type() { |