Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various textinput fixes #8983

Merged
merged 5 commits into from Jan 11, 2016
Next

Relayout text input elements on blur

  • Loading branch information
Manishearth committed Jan 3, 2016
commit 23e7dfa57b6e4c8aa26dc74b742e65c31abbe50d
@@ -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() };
@@ -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());
@@ -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 {}
@@ -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)]
@@ -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() {
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.