servo: Merge
#4989 - Use platform-sized integers for textinput.rs (from jdm:textinputsizes); r=Ms2ger
Source-Repo:
https://github.com/servo/servo
Source-Revision:
e8ade1e3d331a78921b3a7a3be2737a94b096ffa
--- a/servo/components/script/textinput.rs
+++ b/servo/components/script/textinput.rs
@@ -19,19 +19,19 @@ enum Selection {
Selected,
NotSelected
}
#[jstraceable]
#[derive(Copy)]
struct TextPoint {
/// 0-based line number
- line: uint,
+ line: usize,
/// 0-based column number
- index: uint,
+ index: usize,
}
/// Encapsulated state for handling keyboard input in a single or multiline text input control.
#[jstraceable]
pub struct TextInput {
/// Current text input content, split across lines without trailing '\n'
lines: Vec<DOMString>,
/// Current cursor input point
@@ -161,89 +161,89 @@ impl TextInput {
new_lines.push_all(lines_suffix);
new_lines
};
self.lines = new_lines;
}
/// Return the length of the current line under the editing point.
- fn current_line_length(&self) -> uint {
+ fn current_line_length(&self) -> usize {
self.lines[self.edit_point.line].chars().count()
}
/// Adjust the editing point position by a given of lines. The resulting column is
/// as close to the original column position as possible.
- fn adjust_vertical(&mut self, adjust: int, select: Selection) {
+ fn adjust_vertical(&mut self, adjust: isize, select: Selection) {
if !self.multiline {
return;
}
if select == Selection::Selected {
if self.selection_begin.is_none() {
self.selection_begin = Some(self.edit_point);
}
} else {
self.clear_selection();
}
assert!(self.edit_point.line < self.lines.len());
- let target_line: int = self.edit_point.line as int + adjust;
+ let target_line: isize = self.edit_point.line as isize + adjust;
if target_line < 0 {
self.edit_point.index = 0;
self.edit_point.line = 0;
return;
- } else if target_line as uint >= self.lines.len() {
+ } else if target_line as usize >= self.lines.len() {
self.edit_point.line = self.lines.len() - 1;
self.edit_point.index = self.current_line_length();
return;
}
- self.edit_point.line = target_line as uint;
+ self.edit_point.line = target_line as usize;
self.edit_point.index = min(self.current_line_length(), self.edit_point.index);
}
/// Adjust the editing point position by a given number of columns. If the adjustment
/// requested is larger than is available in the current line, the editing point is
/// adjusted vertically and the process repeats with the remaining adjustment requested.
- fn adjust_horizontal(&mut self, adjust: int, select: Selection) {
+ fn adjust_horizontal(&mut self, adjust: isize, select: Selection) {
if select == Selection::Selected {
if self.selection_begin.is_none() {
self.selection_begin = Some(self.edit_point);
}
} else {
if self.selection_begin.is_some() {
let (begin, end) = self.get_sorted_selection();
self.edit_point = if adjust < 0 {begin} else {end};
self.clear_selection();
return
}
}
if adjust < 0 {
let remaining = self.edit_point.index;
- if adjust.abs() as uint > remaining && self.edit_point.line > 0 {
+ if adjust.abs() as usize > remaining && self.edit_point.line > 0 {
self.adjust_vertical(-1, select);
self.edit_point.index = self.current_line_length();
self.adjust_horizontal(adjust + remaining as int + 1, select);
} else {
- self.edit_point.index = max(0, self.edit_point.index as int + adjust) as uint;
+ self.edit_point.index = max(0, self.edit_point.index as int + adjust) as usize;
}
} else {
let remaining = self.current_line_length() - self.edit_point.index;
- if adjust as uint > remaining && self.lines.len() > self.edit_point.line + 1 {
+ if adjust as usize > remaining && self.lines.len() > self.edit_point.line + 1 {
self.adjust_vertical(1, select);
self.edit_point.index = 0;
// one shift is consumed by the change of line, hence the -1
self.adjust_horizontal(adjust - remaining as int - 1, select);
} else {
self.edit_point.index = min(self.current_line_length(),
- self.edit_point.index + adjust as uint);
+ self.edit_point.index + adjust as usize);
}
}
}
/// Deal with a newline input.
fn handle_return(&mut self) -> KeyReaction {
if !self.multiline {
return KeyReaction::TriggerDefaultAction;