mirror of
https://github.com/servo/servo.git
synced 2025-08-04 13:10:20 +01:00
Auto merge of #8983 - Manishearth:cursors, r=jdm
Various textinput fixes - Currently the cursor sticks around if you click elsewhere. Now the text inputs are relayout-ed on blur. - Currently whitespace gets collapsed in text input (https://github.com/servo/servo/issues/8772). Not anymore. <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/8983) <!-- Reviewable:end -->
This commit is contained in:
commit
099beee85c
9 changed files with 117 additions and 7 deletions
|
@ -979,9 +979,10 @@ impl<'ln> ThreadSafeLayoutNode<'ln> for ServoThreadSafeLayoutNode<'ln> {
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(area) = this.downcast::<HTMLTextAreaElement>() {
|
if let Some(area) = this.downcast::<HTMLTextAreaElement>() {
|
||||||
let insertion_point = unsafe { area.get_absolute_insertion_point_for_layout() };
|
if let Some(insertion_point) = unsafe { area.get_absolute_insertion_point_for_layout() } {
|
||||||
let text = unsafe { area.get_value_for_layout() };
|
let text = unsafe { area.get_value_for_layout() };
|
||||||
return Some(CharIndex(search_index(insertion_point, text.char_indices())));
|
return Some(CharIndex(search_index(insertion_point, text.char_indices())));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if let Some(input) = this.downcast::<HTMLInputElement>() {
|
if let Some(input) = this.downcast::<HTMLInputElement>() {
|
||||||
let insertion_point_index = unsafe { input.get_insertion_point_index_for_layout() };
|
let insertion_point_index = unsafe { input.get_insertion_point_index_for_layout() };
|
||||||
|
|
|
@ -1910,7 +1910,9 @@ impl Element {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_focus_state(&self, value: bool) {
|
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 {
|
pub fn get_hover_state(&self) -> bool {
|
||||||
|
|
|
@ -202,6 +202,9 @@ impl LayoutHTMLInputElementHelpers for LayoutJS<HTMLInputElement> {
|
||||||
#[allow(unrooted_must_root)]
|
#[allow(unrooted_must_root)]
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
unsafe fn get_insertion_point_index_for_layout(self) -> Option<isize> {
|
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() {
|
match (*self.unsafe_get()).input_type.get() {
|
||||||
InputType::InputText => {
|
InputType::InputText => {
|
||||||
let raw = self.get_value_for_layout();
|
let raw = self.get_value_for_layout();
|
||||||
|
|
|
@ -45,7 +45,7 @@ pub trait LayoutHTMLTextAreaElementHelpers {
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
unsafe fn get_value_for_layout(self) -> String;
|
unsafe fn get_value_for_layout(self) -> String;
|
||||||
#[allow(unsafe_code)]
|
#[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)]
|
#[allow(unsafe_code)]
|
||||||
fn get_cols(self) -> u32;
|
fn get_cols(self) -> u32;
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
|
@ -61,8 +61,13 @@ impl LayoutHTMLTextAreaElementHelpers for LayoutJS<HTMLTextAreaElement> {
|
||||||
|
|
||||||
#[allow(unrooted_must_root)]
|
#[allow(unrooted_must_root)]
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
unsafe fn get_absolute_insertion_point_for_layout(self) -> usize {
|
unsafe fn get_absolute_insertion_point_for_layout(self) -> Option<usize> {
|
||||||
(*self.unsafe_get()).textinput.borrow_for_layout().get_absolute_insertion_point()
|
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)]
|
#[allow(unsafe_code)]
|
||||||
|
|
|
@ -6993,6 +6993,10 @@ pub fn modify_style_for_input_text(style: &mut Arc<ComputedValues>) {
|
||||||
margin_style.margin_right = computed::LengthOrPercentageOrAuto::Length(Au(0));
|
margin_style.margin_right = computed::LengthOrPercentageOrAuto::Length(Au(0));
|
||||||
margin_style.margin_bottom = computed::LengthOrPercentageOrAuto::Length(Au(0));
|
margin_style.margin_bottom = computed::LengthOrPercentageOrAuto::Length(Au(0));
|
||||||
margin_style.margin_left = 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
|
/// Adjusts the `clip` property so that an inline absolute hypothetical fragment doesn't clip its
|
||||||
|
|
7
tests/html/input_whitespace_regression.html
Normal file
7
tests/html/input_whitespace_regression.html
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
|
||||||
|
Both input elements below should have more than one space between "foo" and "bar":
|
||||||
|
|
||||||
|
<form>
|
||||||
|
<input value="foo bar">
|
||||||
|
<input value="foo bar">
|
||||||
|
</form>
|
|
@ -2443,6 +2443,30 @@
|
||||||
"url": "/_mozilla/css/input_placeholder_ref.html"
|
"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": [
|
"css/inset.html": [
|
||||||
{
|
{
|
||||||
"path": "css/inset.html",
|
"path": "css/inset.html",
|
||||||
|
@ -8434,6 +8458,30 @@
|
||||||
"url": "/_mozilla/css/input_placeholder_ref.html"
|
"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": [
|
"css/inset.html": [
|
||||||
{
|
{
|
||||||
"path": "css/inset.html",
|
"path": "css/inset.html",
|
||||||
|
|
20
tests/wpt/mozilla/tests/css/input_whitespace.html
Normal file
20
tests/wpt/mozilla/tests/css/input_whitespace.html
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
<!doctype html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<title></title>
|
||||||
|
<link rel="match" href="input_whitespace_ref.html">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div><input type="text" size="30" value="placeholder"></div>
|
||||||
|
<div><input type="text" size="30" value="place holder"></div>
|
||||||
|
<div><input type="text" size="30" value="place holder"></div>
|
||||||
|
<textarea rows="7" cols="50">a a a a a
|
||||||
|
|
||||||
|
b
|
||||||
|
|
||||||
|
|
||||||
|
b
|
||||||
|
</textarea>
|
||||||
|
</body>
|
||||||
|
</html>
|
20
tests/wpt/mozilla/tests/css/input_whitespace_ref.html
Normal file
20
tests/wpt/mozilla/tests/css/input_whitespace_ref.html
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
<!doctype html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<title></title>
|
||||||
|
<link rel="match" href="input_whitespace_ref.html">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div><input type="text" size="30" value="placeholder"></div>
|
||||||
|
<div><input type="text" size="30" value="place holder"></div>
|
||||||
|
<div><input type="text" size="30" value="place holder"></div>
|
||||||
|
<textarea rows="7" cols="50">a a a a a
|
||||||
|
|
||||||
|
b
|
||||||
|
|
||||||
|
|
||||||
|
b
|
||||||
|
</textarea>
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
Add table
Add a link
Reference in a new issue