mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
Auto merge of #7764 - j3parker:input-caret-only-for-text, r=pcwalton
Only display text carets in text inputs For #7756 <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/7764) <!-- Reviewable:end -->
This commit is contained in:
commit
0c64e4a2c9
5 changed files with 40 additions and 12 deletions
|
@ -954,18 +954,20 @@ impl<'ln> ThreadSafeLayoutNode<'ln> {
|
||||||
let insertion_point = unsafe {
|
let insertion_point = unsafe {
|
||||||
input.get_insertion_point_for_layout()
|
input.get_insertion_point_for_layout()
|
||||||
};
|
};
|
||||||
let text = unsafe {
|
if let Some(insertion_point) = insertion_point {
|
||||||
input.get_value_for_layout()
|
let text = unsafe {
|
||||||
};
|
input.get_value_for_layout()
|
||||||
|
};
|
||||||
|
|
||||||
let mut character_count = 0;
|
let mut character_count = 0;
|
||||||
for (character_index, _) in text.char_indices() {
|
for (character_index, _) in text.char_indices() {
|
||||||
if character_index == insertion_point.index {
|
if character_index == insertion_point.index {
|
||||||
return Some(CharIndex(character_count))
|
return Some(CharIndex(character_count))
|
||||||
|
}
|
||||||
|
character_count += 1
|
||||||
}
|
}
|
||||||
character_count += 1
|
return Some(CharIndex(character_count))
|
||||||
}
|
}
|
||||||
return Some(CharIndex(character_count))
|
|
||||||
}
|
}
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
|
@ -143,7 +143,7 @@ pub trait LayoutHTMLInputElementHelpers {
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
unsafe fn get_size_for_layout(self) -> u32;
|
unsafe fn get_size_for_layout(self) -> u32;
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
unsafe fn get_insertion_point_for_layout(self) -> TextPoint;
|
unsafe fn get_insertion_point_for_layout(self) -> Option<TextPoint>;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait RawLayoutHTMLInputElementHelpers {
|
pub trait RawLayoutHTMLInputElementHelpers {
|
||||||
|
@ -197,8 +197,12 @@ impl LayoutHTMLInputElementHelpers for LayoutJS<HTMLInputElement> {
|
||||||
|
|
||||||
#[allow(unrooted_must_root)]
|
#[allow(unrooted_must_root)]
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
unsafe fn get_insertion_point_for_layout(self) -> TextPoint {
|
unsafe fn get_insertion_point_for_layout(self) -> Option<TextPoint> {
|
||||||
(*self.unsafe_get()).textinput.borrow_for_layout().edit_point
|
match (*self.unsafe_get()).input_type.get() {
|
||||||
|
InputType::InputText | InputType::InputPassword =>
|
||||||
|
Some((*self.unsafe_get()).textinput.borrow_for_layout().edit_point),
|
||||||
|
_ => None
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -337,6 +337,7 @@ device-pixel-ratio=2 != pixel_snapping_border_a.html pixel_snapping_border_ref.h
|
||||||
== stacking_context_overflow_a.html stacking_context_overflow_ref.html
|
== stacking_context_overflow_a.html stacking_context_overflow_ref.html
|
||||||
== stacking_context_overflow_relative_outline_a.html stacking_context_overflow_relative_outline_ref.html
|
== stacking_context_overflow_relative_outline_a.html stacking_context_overflow_relative_outline_ref.html
|
||||||
== style_is_in_doc.html style_is_in_doc_ref.html
|
== style_is_in_doc.html style_is_in_doc_ref.html
|
||||||
|
== submit_focus_a.html submit_focus_b.html
|
||||||
== table_auto_width.html table_auto_width_ref.html
|
== table_auto_width.html table_auto_width_ref.html
|
||||||
== table_caption_bottom_a.html table_caption_bottom_ref.html
|
== table_caption_bottom_a.html table_caption_bottom_ref.html
|
||||||
== table_caption_top_a.html table_caption_top_ref.html
|
== table_caption_top_a.html table_caption_top_ref.html
|
||||||
|
|
10
tests/ref/submit_focus_a.html
Normal file
10
tests/ref/submit_focus_a.html
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
<style>
|
||||||
|
button {
|
||||||
|
display: inline-block;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<button id="1">Submit</button>
|
||||||
|
<script>
|
||||||
|
var elem = document.getElementById('1');
|
||||||
|
elem.focus();
|
||||||
|
</script>
|
11
tests/ref/submit_focus_b.html
Normal file
11
tests/ref/submit_focus_b.html
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
<style>
|
||||||
|
input {
|
||||||
|
padding-left: 0;
|
||||||
|
padding-right: 0;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<input id="1" type="submit"></input>
|
||||||
|
<script>
|
||||||
|
var elem = document.getElementById('1');
|
||||||
|
elem.focus();
|
||||||
|
</script>
|
Loading…
Add table
Add a link
Reference in a new issue