diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2016-04-28 20:22:09 -0700 |
---|---|---|
committer | bors-servo <lbergstrom+bors@mozilla.com> | 2016-04-28 20:22:09 -0700 |
commit | cf121ad8dff90b8fa55558ca9bdcbfe29512a617 (patch) | |
tree | 8f8ff7f5e68b18eb228acbc1448a7c4f451e1e69 /components/script/dom/htmltextareaelement.rs | |
parent | 1177ef5869e02b5129ebde6fa9780c93d362e16c (diff) | |
parent | c4872d95445636ef4dec45cbfc5c2d643c4b9441 (diff) | |
download | servo-cf121ad8dff90b8fa55558ca9bdcbfe29512a617.tar.gz servo-cf121ad8dff90b8fa55558ca9bdcbfe29512a617.zip |
Auto merge of #10895 - mbrubeck:byteindex, r=pcwalton
Use byte indices instead of char indices for text runs
Replace character indices with UTF-8 byte offsets throughout all code dealing with text runs. This eliminates a lot of complexity when converting from one to the other, and interoperates better with the rest of the Rust ecosystem.
For most code this is just a simple replacement of char indices with byte indices. In a few places like glyph storage and text fragment scanning, it also lets us get rid of code that existed only to map between bytes and chars.
Also includes some related fixes to text shaping, discovered while working on this conversion. See the commit messages for details.
r? @pcwalton
<!-- 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/10895)
<!-- Reviewable:end -->
Diffstat (limited to 'components/script/dom/htmltextareaelement.rs')
-rw-r--r-- | components/script/dom/htmltextareaelement.rs | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/components/script/dom/htmltextareaelement.rs b/components/script/dom/htmltextareaelement.rs index d3eb7827031..0f764f12e7d 100644 --- a/components/script/dom/htmltextareaelement.rs +++ b/components/script/dom/htmltextareaelement.rs @@ -26,9 +26,9 @@ use dom::nodelist::NodeList; use dom::validation::Validatable; use dom::virtualmethods::VirtualMethods; use msg::constellation_msg::ConstellationChan; -use range::Range; use script_traits::ScriptMsg as ConstellationMsg; use std::cell::Cell; +use std::ops::Range; use string_cache::Atom; use style::element_state::*; use textinput::{KeyReaction, Lines, TextInput, SelectionDirection}; @@ -47,7 +47,7 @@ pub trait LayoutHTMLTextAreaElementHelpers { #[allow(unsafe_code)] unsafe fn get_value_for_layout(self) -> String; #[allow(unsafe_code)] - unsafe fn get_absolute_selection_for_layout(self) -> Option<Range<usize>>; + unsafe fn selection_for_layout(self) -> Option<Range<usize>>; #[allow(unsafe_code)] fn get_cols(self) -> u32; #[allow(unsafe_code)] @@ -63,13 +63,12 @@ impl LayoutHTMLTextAreaElementHelpers for LayoutJS<HTMLTextAreaElement> { #[allow(unrooted_must_root)] #[allow(unsafe_code)] - unsafe fn get_absolute_selection_for_layout(self) -> Option<Range<usize>> { - if (*self.unsafe_get()).upcast::<Element>().focus_state() { - Some((*self.unsafe_get()).textinput.borrow_for_layout() - .get_absolute_selection_range()) - } else { - None + unsafe fn selection_for_layout(self) -> Option<Range<usize>> { + if !(*self.unsafe_get()).upcast::<Element>().focus_state() { + return None; } + let textinput = (*self.unsafe_get()).textinput.borrow_for_layout(); + Some(textinput.get_absolute_selection_range()) } #[allow(unsafe_code)] |