From 9cf43877f268221f4d7c2eea5a89bffb55709c71 Mon Sep 17 00:00:00 2001 From: Jacob Parker Date: Sun, 27 Sep 2015 18:10:27 -0400 Subject: [PATCH] Only display text carets in text inputs --- components/layout/wrapper.rs | 20 +++++++++++--------- components/script/dom/htmlinputelement.rs | 10 +++++++--- tests/ref/basic.list | 1 + tests/ref/submit_focus_a.html | 10 ++++++++++ tests/ref/submit_focus_b.html | 11 +++++++++++ 5 files changed, 40 insertions(+), 12 deletions(-) create mode 100644 tests/ref/submit_focus_a.html create mode 100644 tests/ref/submit_focus_b.html diff --git a/components/layout/wrapper.rs b/components/layout/wrapper.rs index 678ebd63582..17102f0095d 100644 --- a/components/layout/wrapper.rs +++ b/components/layout/wrapper.rs @@ -954,18 +954,20 @@ impl<'ln> ThreadSafeLayoutNode<'ln> { let insertion_point = unsafe { input.get_insertion_point_for_layout() }; - let text = unsafe { - input.get_value_for_layout() - }; + if let Some(insertion_point) = insertion_point { + let text = unsafe { + input.get_value_for_layout() + }; - let mut character_count = 0; - for (character_index, _) in text.char_indices() { - if character_index == insertion_point.index { - return Some(CharIndex(character_count)) + let mut character_count = 0; + for (character_index, _) in text.char_indices() { + if character_index == insertion_point.index { + return Some(CharIndex(character_count)) + } + character_count += 1 } - character_count += 1 + return Some(CharIndex(character_count)) } - return Some(CharIndex(character_count)) } None } diff --git a/components/script/dom/htmlinputelement.rs b/components/script/dom/htmlinputelement.rs index 40020a74d14..a07529ebbec 100644 --- a/components/script/dom/htmlinputelement.rs +++ b/components/script/dom/htmlinputelement.rs @@ -143,7 +143,7 @@ pub trait LayoutHTMLInputElementHelpers { #[allow(unsafe_code)] unsafe fn get_size_for_layout(self) -> u32; #[allow(unsafe_code)] - unsafe fn get_insertion_point_for_layout(self) -> TextPoint; + unsafe fn get_insertion_point_for_layout(self) -> Option; } pub trait RawLayoutHTMLInputElementHelpers { @@ -197,8 +197,12 @@ impl LayoutHTMLInputElementHelpers for LayoutJS { #[allow(unrooted_must_root)] #[allow(unsafe_code)] - unsafe fn get_insertion_point_for_layout(self) -> TextPoint { - (*self.unsafe_get()).textinput.borrow_for_layout().edit_point + unsafe fn get_insertion_point_for_layout(self) -> Option { + match (*self.unsafe_get()).input_type.get() { + InputType::InputText | InputType::InputPassword => + Some((*self.unsafe_get()).textinput.borrow_for_layout().edit_point), + _ => None + } } } diff --git a/tests/ref/basic.list b/tests/ref/basic.list index fbcb78bc891..a901b38d862 100644 --- a/tests/ref/basic.list +++ b/tests/ref/basic.list @@ -335,6 +335,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_relative_outline_a.html stacking_context_overflow_relative_outline_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_caption_bottom_a.html table_caption_bottom_ref.html == table_caption_top_a.html table_caption_top_ref.html diff --git a/tests/ref/submit_focus_a.html b/tests/ref/submit_focus_a.html new file mode 100644 index 00000000000..261f3f005ec --- /dev/null +++ b/tests/ref/submit_focus_a.html @@ -0,0 +1,10 @@ + + + diff --git a/tests/ref/submit_focus_b.html b/tests/ref/submit_focus_b.html new file mode 100644 index 00000000000..1cedc3523a7 --- /dev/null +++ b/tests/ref/submit_focus_b.html @@ -0,0 +1,11 @@ + + +