Auto merge of #10347 - mbrubeck:incremental-selection, r=pcwalton

Fix incremental reflow of text selection changes

r? @emilio or @pcwalton

CC @paulrouget: This fixes a bug in the browser.html URL bar auto-completion.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/10347)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2016-04-02 19:54:50 +05:30
commit 0489280ded
5 changed files with 83 additions and 20 deletions

View file

@ -200,6 +200,7 @@ impl HTMLInputElement {
text_input.selection_begin = Some(text_input.get_text_point_for_absolute_point(start)); text_input.selection_begin = Some(text_input.get_text_point_for_absolute_point(start));
text_input.edit_point = text_input.get_text_point_for_absolute_point(end); text_input.edit_point = text_input.get_text_point_for_absolute_point(end);
self.selection_direction.set(*direction); self.selection_direction.set(*direction);
self.upcast::<Node>().dirty(NodeDamage::OtherNodeDamage);
} }
} }
@ -401,7 +402,7 @@ impl HTMLInputElementMethods for HTMLInputElement {
} }
self.value_changed.set(true); self.value_changed.set(true);
self.force_relayout(); self.upcast::<Node>().dirty(NodeDamage::OtherNodeDamage);
Ok(()) Ok(())
} }
@ -586,11 +587,6 @@ fn in_same_group(other: &HTMLInputElement, owner: Option<&HTMLFormElement>,
} }
impl HTMLInputElement { impl HTMLInputElement {
fn force_relayout(&self) {
let doc = document_from_node(self);
doc.content_changed(self.upcast(), NodeDamage::OtherNodeDamage)
}
fn radio_group_updated(&self, group: Option<&Atom>) { fn radio_group_updated(&self, group: Option<&Atom>) {
if self.Checked() { if self.Checked() {
broadcast_radio_checked(self, group); broadcast_radio_checked(self, group);
@ -654,7 +650,7 @@ impl HTMLInputElement {
self.get_radio_group_name().as_ref()); self.get_radio_group_name().as_ref());
} }
self.force_relayout(); self.upcast::<Node>().dirty(NodeDamage::OtherNodeDamage);
//TODO: dispatch change event //TODO: dispatch change event
} }
@ -684,7 +680,7 @@ impl HTMLInputElement {
.expect("Failed to reset input value to default."); .expect("Failed to reset input value to default.");
self.value_dirty.set(false); self.value_dirty.set(false);
self.value_changed.set(false); self.value_changed.set(false);
self.force_relayout(); self.upcast::<Node>().dirty(NodeDamage::OtherNodeDamage);
} }
} }
@ -889,11 +885,11 @@ impl VirtualMethods for HTMLInputElement {
ChangeEventRunnable::send(self.upcast::<Node>()); ChangeEventRunnable::send(self.upcast::<Node>());
} }
self.force_relayout(); self.upcast::<Node>().dirty(NodeDamage::OtherNodeDamage);
event.PreventDefault(); event.PreventDefault();
} }
RedrawSelection => { RedrawSelection => {
self.force_relayout(); self.upcast::<Node>().dirty(NodeDamage::OtherNodeDamage);
event.PreventDefault(); event.PreventDefault();
} }
Nothing => (), Nothing => (),

View file

@ -209,7 +209,7 @@ impl HTMLTextAreaElementMethods for HTMLTextAreaElement {
self.textinput.borrow_mut().set_content(value); self.textinput.borrow_mut().set_content(value);
self.value_changed.set(true); self.value_changed.set(true);
self.force_relayout(); self.upcast::<Node>().dirty(NodeDamage::OtherNodeDamage);
} }
// https://html.spec.whatwg.org/multipage/#dom-lfe-labels // https://html.spec.whatwg.org/multipage/#dom-lfe-labels
@ -233,13 +233,6 @@ impl HTMLTextAreaElement {
} }
impl HTMLTextAreaElement {
fn force_relayout(&self) {
let doc = document_from_node(self);
doc.content_changed(self.upcast(), NodeDamage::OtherNodeDamage)
}
}
impl VirtualMethods for HTMLTextAreaElement { impl VirtualMethods for HTMLTextAreaElement {
fn super_type(&self) -> Option<&VirtualMethods> { fn super_type(&self) -> Option<&VirtualMethods> {
Some(self.upcast::<HTMLElement>() as &VirtualMethods) Some(self.upcast::<HTMLElement>() as &VirtualMethods)
@ -324,11 +317,11 @@ impl VirtualMethods for HTMLTextAreaElement {
ChangeEventRunnable::send(self.upcast::<Node>()); ChangeEventRunnable::send(self.upcast::<Node>());
} }
self.force_relayout(); self.upcast::<Node>().dirty(NodeDamage::OtherNodeDamage);
event.PreventDefault(); event.PreventDefault();
} }
KeyReaction::RedrawSelection => { KeyReaction::RedrawSelection => {
self.force_relayout(); self.upcast::<Node>().dirty(NodeDamage::OtherNodeDamage);
event.PreventDefault(); event.PreventDefault();
} }
KeyReaction::Nothing => (), KeyReaction::Nothing => (),

View file

@ -2615,6 +2615,18 @@
"url": "/_mozilla/css/input_selection_a.html" "url": "/_mozilla/css/input_selection_a.html"
} }
], ],
"css/input_selection_incremental_a.html": [
{
"path": "css/input_selection_incremental_a.html",
"references": [
[
"/_mozilla/css/input_selection_incremental_ref.html",
"=="
]
],
"url": "/_mozilla/css/input_selection_incremental_a.html"
}
],
"css/input_selection_ref.html": [ "css/input_selection_ref.html": [
{ {
"path": "css/input_selection_ref.html", "path": "css/input_selection_ref.html",
@ -9049,6 +9061,18 @@
"url": "/_mozilla/css/input_selection_a.html" "url": "/_mozilla/css/input_selection_a.html"
} }
], ],
"css/input_selection_incremental_a.html": [
{
"path": "css/input_selection_incremental_a.html",
"references": [
[
"/_mozilla/css/input_selection_incremental_ref.html",
"=="
]
],
"url": "/_mozilla/css/input_selection_incremental_a.html"
}
],
"css/input_selection_ref.html": [ "css/input_selection_ref.html": [
{ {
"path": "css/input_selection_ref.html", "path": "css/input_selection_ref.html",

View file

@ -0,0 +1,31 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>input selection incremental test</title>
<link rel="match" href="input_selection_incremental_ref.html">
<style>
input {
font: 16px sans-serif;
border: 0 none;
margin: 0;
padding: 0;
}
::selection {
color: white;
background: rgba(176, 214, 255, 1.0);
}
</style>
</head>
<body>
<input value="Hello">
<script>
var input = document.querySelector("input");
input.focus();
input.setSelectionRange(0, 5);
document.body.offsetWidth; // force layout
input.setSelectionRange(0, 1);
</script>
</body>
</html>

View file

@ -0,0 +1,19 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>input selection incremental reference</title>
<style>
body {
font: 16px sans-serif;
}
.selection {
color: white;
background: rgba(176, 214, 255, 1.0);
}
</style>
</head>
<body>
<span class="selection">H</span>ello
</body>
</html>