mirror of
https://github.com/servo/servo.git
synced 2025-07-23 15:23:42 +01:00
Replace range::Range with std::ops::Range in script
This commit is contained in:
parent
659305fe0a
commit
c4872d9544
9 changed files with 14 additions and 23 deletions
|
@ -1087,8 +1087,8 @@ impl<'ln> ThreadSafeLayoutNode for ServoThreadSafeLayoutNode<'ln> {
|
||||||
} else {
|
} else {
|
||||||
return None;
|
return None;
|
||||||
};
|
};
|
||||||
selection.map(|range| Range::new(ByteIndex(range.begin() as isize),
|
selection.map(|range| Range::new(ByteIndex(range.start as isize),
|
||||||
ByteIndex(range.length() as isize)))
|
ByteIndex(range.len() as isize)))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn image_url(&self) -> Option<Url> {
|
fn image_url(&self) -> Option<Url> {
|
||||||
|
|
|
@ -49,7 +49,6 @@ offscreen_gl_context = "0.1.2"
|
||||||
rand = "0.3"
|
rand = "0.3"
|
||||||
phf = "0.7.13"
|
phf = "0.7.13"
|
||||||
phf_macros = "0.7.13"
|
phf_macros = "0.7.13"
|
||||||
range = { path = "../range" }
|
|
||||||
ref_filter_map = "1.0"
|
ref_filter_map = "1.0"
|
||||||
ref_slice = "0.1.0"
|
ref_slice = "0.1.0"
|
||||||
regex = "0.1.43"
|
regex = "0.1.43"
|
||||||
|
|
|
@ -31,13 +31,13 @@ use dom::nodelist::NodeList;
|
||||||
use dom::validation::Validatable;
|
use dom::validation::Validatable;
|
||||||
use dom::virtualmethods::VirtualMethods;
|
use dom::virtualmethods::VirtualMethods;
|
||||||
use msg::constellation_msg::ConstellationChan;
|
use msg::constellation_msg::ConstellationChan;
|
||||||
use range::Range;
|
|
||||||
use script_runtime::CommonScriptMsg;
|
use script_runtime::CommonScriptMsg;
|
||||||
use script_runtime::ScriptThreadEventCategory::InputEvent;
|
use script_runtime::ScriptThreadEventCategory::InputEvent;
|
||||||
use script_thread::Runnable;
|
use script_thread::Runnable;
|
||||||
use script_traits::ScriptMsg as ConstellationMsg;
|
use script_traits::ScriptMsg as ConstellationMsg;
|
||||||
use std::borrow::ToOwned;
|
use std::borrow::ToOwned;
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
|
use std::ops::Range;
|
||||||
use string_cache::Atom;
|
use string_cache::Atom;
|
||||||
use style::element_state::*;
|
use style::element_state::*;
|
||||||
use textinput::KeyReaction::{DispatchInput, Nothing, RedrawSelection, TriggerDefaultAction};
|
use textinput::KeyReaction::{DispatchInput, Nothing, RedrawSelection, TriggerDefaultAction};
|
||||||
|
@ -245,12 +245,11 @@ impl LayoutHTMLInputElementHelpers for LayoutJS<HTMLInputElement> {
|
||||||
let sel = textinput.get_absolute_selection_range();
|
let sel = textinput.get_absolute_selection_range();
|
||||||
|
|
||||||
// Translate indices from the raw value to indices in the replacement value.
|
// Translate indices from the raw value to indices in the replacement value.
|
||||||
let char_start = text[.. sel.begin()].chars().count();
|
let char_start = text[.. sel.start].chars().count();
|
||||||
let char_count = text[sel.begin() .. sel.end()].chars().count();
|
let char_end = char_start + text[sel].chars().count();
|
||||||
|
|
||||||
let bytes_per_char = PASSWORD_REPLACEMENT_CHAR.len_utf8();
|
let bytes_per_char = PASSWORD_REPLACEMENT_CHAR.len_utf8();
|
||||||
Some(Range::new(char_start * bytes_per_char,
|
Some(char_start * bytes_per_char .. char_end * bytes_per_char)
|
||||||
char_count * bytes_per_char))
|
|
||||||
}
|
}
|
||||||
InputType::InputText => Some(textinput.get_absolute_selection_range()),
|
InputType::InputText => Some(textinput.get_absolute_selection_range()),
|
||||||
_ => None
|
_ => None
|
||||||
|
|
|
@ -26,9 +26,9 @@ use dom::nodelist::NodeList;
|
||||||
use dom::validation::Validatable;
|
use dom::validation::Validatable;
|
||||||
use dom::virtualmethods::VirtualMethods;
|
use dom::virtualmethods::VirtualMethods;
|
||||||
use msg::constellation_msg::ConstellationChan;
|
use msg::constellation_msg::ConstellationChan;
|
||||||
use range::Range;
|
|
||||||
use script_traits::ScriptMsg as ConstellationMsg;
|
use script_traits::ScriptMsg as ConstellationMsg;
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
|
use std::ops::Range;
|
||||||
use string_cache::Atom;
|
use string_cache::Atom;
|
||||||
use style::element_state::*;
|
use style::element_state::*;
|
||||||
use textinput::{KeyReaction, Lines, TextInput, SelectionDirection};
|
use textinput::{KeyReaction, Lines, TextInput, SelectionDirection};
|
||||||
|
|
|
@ -59,7 +59,6 @@ extern crate phf;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate profile_traits;
|
extern crate profile_traits;
|
||||||
extern crate rand;
|
extern crate rand;
|
||||||
extern crate range;
|
|
||||||
extern crate ref_filter_map;
|
extern crate ref_filter_map;
|
||||||
extern crate ref_slice;
|
extern crate ref_slice;
|
||||||
extern crate regex;
|
extern crate regex;
|
||||||
|
|
|
@ -8,10 +8,10 @@ use clipboard_provider::ClipboardProvider;
|
||||||
use dom::keyboardevent::{KeyboardEvent, key_value};
|
use dom::keyboardevent::{KeyboardEvent, key_value};
|
||||||
use msg::constellation_msg::{ALT, CONTROL, SHIFT, SUPER};
|
use msg::constellation_msg::{ALT, CONTROL, SHIFT, SUPER};
|
||||||
use msg::constellation_msg::{Key, KeyModifiers};
|
use msg::constellation_msg::{Key, KeyModifiers};
|
||||||
use range::Range;
|
|
||||||
use std::borrow::ToOwned;
|
use std::borrow::ToOwned;
|
||||||
use std::cmp::{max, min};
|
use std::cmp::{max, min};
|
||||||
use std::default::Default;
|
use std::default::Default;
|
||||||
|
use std::ops::Range;
|
||||||
use std::usize;
|
use std::usize;
|
||||||
use util::str::DOMString;
|
use util::str::DOMString;
|
||||||
|
|
||||||
|
@ -220,10 +220,12 @@ impl<T: ClipboardProvider> TextInput<T> {
|
||||||
/// If there is no selection, returns an empty range at the insertion point.
|
/// If there is no selection, returns an empty range at the insertion point.
|
||||||
pub fn get_absolute_selection_range(&self) -> Range<usize> {
|
pub fn get_absolute_selection_range(&self) -> Range<usize> {
|
||||||
match self.get_sorted_selection() {
|
match self.get_sorted_selection() {
|
||||||
Some((begin, _end)) =>
|
Some((begin, end)) => self.get_absolute_point_for_text_point(&begin) ..
|
||||||
Range::new(self.get_absolute_point_for_text_point(&begin), self.selection_len()),
|
self.get_absolute_point_for_text_point(&end),
|
||||||
None =>
|
None => {
|
||||||
Range::new(self.get_absolute_insertion_point(), 0)
|
let insertion_point = self.get_absolute_insertion_point();
|
||||||
|
insertion_point .. insertion_point
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -235,11 +237,6 @@ impl<T: ClipboardProvider> TextInput<T> {
|
||||||
Some(text)
|
Some(text)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The length of the selected text in UTF-8 bytes.
|
|
||||||
fn selection_len(&self) -> usize {
|
|
||||||
self.fold_selection_slices(0, |len, slice| *len += slice.len())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The length of the selected text in UTF-16 code units.
|
/// The length of the selected text in UTF-16 code units.
|
||||||
fn selection_utf16_len(&self) -> usize {
|
fn selection_utf16_len(&self) -> usize {
|
||||||
self.fold_selection_slices(0usize,
|
self.fold_selection_slices(0usize,
|
||||||
|
|
1
components/servo/Cargo.lock
generated
1
components/servo/Cargo.lock
generated
|
@ -1819,7 +1819,6 @@ dependencies = [
|
||||||
"plugins 0.0.1",
|
"plugins 0.0.1",
|
||||||
"profile_traits 0.0.1",
|
"profile_traits 0.0.1",
|
||||||
"rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
|
"rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"range 0.0.1",
|
|
||||||
"ref_filter_map 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"ref_filter_map 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"ref_slice 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"ref_slice 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"regex 0.1.55 (registry+https://github.com/rust-lang/crates.io-index)",
|
"regex 0.1.55 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
|
1
ports/cef/Cargo.lock
generated
1
ports/cef/Cargo.lock
generated
|
@ -1687,7 +1687,6 @@ dependencies = [
|
||||||
"plugins 0.0.1",
|
"plugins 0.0.1",
|
||||||
"profile_traits 0.0.1",
|
"profile_traits 0.0.1",
|
||||||
"rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
|
"rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"range 0.0.1",
|
|
||||||
"ref_filter_map 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"ref_filter_map 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"ref_slice 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"ref_slice 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"regex 0.1.55 (registry+https://github.com/rust-lang/crates.io-index)",
|
"regex 0.1.55 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
|
1
ports/gonk/Cargo.lock
generated
1
ports/gonk/Cargo.lock
generated
|
@ -1670,7 +1670,6 @@ dependencies = [
|
||||||
"plugins 0.0.1",
|
"plugins 0.0.1",
|
||||||
"profile_traits 0.0.1",
|
"profile_traits 0.0.1",
|
||||||
"rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
|
"rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"range 0.0.1",
|
|
||||||
"ref_filter_map 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"ref_filter_map 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"ref_slice 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"ref_slice 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"regex 0.1.55 (registry+https://github.com/rust-lang/crates.io-index)",
|
"regex 0.1.55 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue