diff --git a/components/layout/wrapper.rs b/components/layout/wrapper.rs index 31a9d040ca3..e3d7f0a294a 100644 --- a/components/layout/wrapper.rs +++ b/components/layout/wrapper.rs @@ -979,9 +979,10 @@ impl<'ln> ThreadSafeLayoutNode<'ln> for ServoThreadSafeLayoutNode<'ln> { }; if let Some(area) = this.downcast::() { - 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::() { let insertion_point_index = unsafe { input.get_insertion_point_index_for_layout() }; diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index 3fed8b02819..0cea588a64e 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -1910,7 +1910,9 @@ impl Element { } pub fn set_focus_state(&self, value: bool) { - self.set_state(IN_FOCUS_STATE, value) + self.set_state(IN_FOCUS_STATE, value); + let doc = document_from_node(self); + doc.content_changed(self.upcast(), NodeDamage::OtherNodeDamage); } pub fn get_hover_state(&self) -> bool { diff --git a/components/script/dom/htmlinputelement.rs b/components/script/dom/htmlinputelement.rs index 2738c897e6b..368285f8a9f 100644 --- a/components/script/dom/htmlinputelement.rs +++ b/components/script/dom/htmlinputelement.rs @@ -202,6 +202,9 @@ impl LayoutHTMLInputElementHelpers for LayoutJS { #[allow(unrooted_must_root)] #[allow(unsafe_code)] unsafe fn get_insertion_point_index_for_layout(self) -> Option { + if !(*self.unsafe_get()).upcast::().get_focus_state() { + return None; + } match (*self.unsafe_get()).input_type.get() { InputType::InputText => { let raw = self.get_value_for_layout(); 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; #[allow(unsafe_code)] fn get_cols(self) -> u32; #[allow(unsafe_code)] @@ -61,8 +61,13 @@ impl LayoutHTMLTextAreaElementHelpers for LayoutJS { #[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 { + if (*self.unsafe_get()).upcast::().get_focus_state() { + Some((*self.unsafe_get()).textinput.borrow_for_layout() + .get_absolute_insertion_point()) + } else { + None + } } #[allow(unsafe_code)] diff --git a/components/style/properties.mako.rs b/components/style/properties.mako.rs index 2b419180476..72b57a931ef 100644 --- a/components/style/properties.mako.rs +++ b/components/style/properties.mako.rs @@ -6993,6 +6993,10 @@ pub fn modify_style_for_input_text(style: &mut Arc) { margin_style.margin_right = computed::LengthOrPercentageOrAuto::Length(Au(0)); margin_style.margin_bottom = computed::LengthOrPercentageOrAuto::Length(Au(0)); margin_style.margin_left = computed::LengthOrPercentageOrAuto::Length(Au(0)); + + // whitespace inside text input should not be collapsed + let inherited_text = Arc::make_mut(&mut style.inheritedtext); + inherited_text.white_space = longhands::white_space::computed_value::T::pre; } /// Adjusts the `clip` property so that an inline absolute hypothetical fragment doesn't clip its diff --git a/tests/html/input_whitespace_regression.html b/tests/html/input_whitespace_regression.html new file mode 100644 index 00000000000..b66e0a6e62c --- /dev/null +++ b/tests/html/input_whitespace_regression.html @@ -0,0 +1,7 @@ + +Both input elements below should have more than one space between "foo" and "bar": + +
+ + +
\ No newline at end of file diff --git a/tests/wpt/mozilla/meta/MANIFEST.json b/tests/wpt/mozilla/meta/MANIFEST.json index 309ca0d3fa8..83dbc474127 100644 --- a/tests/wpt/mozilla/meta/MANIFEST.json +++ b/tests/wpt/mozilla/meta/MANIFEST.json @@ -2443,6 +2443,30 @@ "url": "/_mozilla/css/input_placeholder_ref.html" } ], + "css/input_whitespace.html": [ + { + "path": "css/input_whitespace.html", + "references": [ + [ + "/_mozilla/css/input_whitespace_ref.html", + "==" + ] + ], + "url": "/_mozilla/css/input_whitespace.html" + } + ], + "css/input_whitespace_ref.html": [ + { + "path": "css/input_whitespace_ref.html", + "references": [ + [ + "/_mozilla/css/input_whitespace_ref.html", + "==" + ] + ], + "url": "/_mozilla/css/input_whitespace_ref.html" + } + ], "css/inset.html": [ { "path": "css/inset.html", @@ -8434,6 +8458,30 @@ "url": "/_mozilla/css/input_placeholder_ref.html" } ], + "css/input_whitespace.html": [ + { + "path": "css/input_whitespace.html", + "references": [ + [ + "/_mozilla/css/input_whitespace_ref.html", + "==" + ] + ], + "url": "/_mozilla/css/input_whitespace.html" + } + ], + "css/input_whitespace_ref.html": [ + { + "path": "css/input_whitespace_ref.html", + "references": [ + [ + "/_mozilla/css/input_whitespace_ref.html", + "==" + ] + ], + "url": "/_mozilla/css/input_whitespace_ref.html" + } + ], "css/inset.html": [ { "path": "css/inset.html", diff --git a/tests/wpt/mozilla/tests/css/input_whitespace.html b/tests/wpt/mozilla/tests/css/input_whitespace.html new file mode 100644 index 00000000000..44f26751eac --- /dev/null +++ b/tests/wpt/mozilla/tests/css/input_whitespace.html @@ -0,0 +1,20 @@ + + + + + + + + +
+
+
+ + + \ No newline at end of file diff --git a/tests/wpt/mozilla/tests/css/input_whitespace_ref.html b/tests/wpt/mozilla/tests/css/input_whitespace_ref.html new file mode 100644 index 00000000000..6be82abad19 --- /dev/null +++ b/tests/wpt/mozilla/tests/css/input_whitespace_ref.html @@ -0,0 +1,20 @@ + + + + + + + + +
+
+
+ + + \ No newline at end of file