Struct script::textinput::TextInput

source ·
pub struct TextInput<T: ClipboardProvider> {
    lines: Vec<DOMString>,
    edit_point: TextPoint,
    selection_origin: Option<TextPoint>,
    selection_direction: SelectionDirection,
    multiline: bool,
    clipboard_provider: T,
    max_length: Option<UTF16CodeUnits>,
    min_length: Option<UTF16CodeUnits>,
    was_last_change_by_set_content: bool,
}
Expand description

Encapsulated state for handling keyboard input in a single or multiline text input control.

Fields§

§lines: Vec<DOMString>

Current text input content, split across lines without trailing ‘\n’

§edit_point: TextPoint

Current cursor input point

§selection_origin: Option<TextPoint>

The current selection goes from the selection_origin until the edit_point. Note that the selection_origin may be after the edit_point, in the case of a backward selection.

§selection_direction: SelectionDirection§multiline: bool

Is this a multiline input?

§clipboard_provider: T§max_length: Option<UTF16CodeUnits>

The maximum number of UTF-16 code units this text input is allowed to hold.

https://html.spec.whatwg.org/multipage/#attr-fe-maxlength

§min_length: Option<UTF16CodeUnits>§was_last_change_by_set_content: bool

Was last change made by set_content?

Implementations§

source§

impl<T: ClipboardProvider> TextInput<T>

source

pub fn new( lines: Lines, initial: DOMString, clipboard_provider: T, max_length: Option<UTF16CodeUnits>, min_length: Option<UTF16CodeUnits>, selection_direction: SelectionDirection, ) -> TextInput<T>

Instantiate a new text input control

source

pub fn edit_point(&self) -> TextPoint

source

pub fn selection_origin(&self) -> Option<TextPoint>

source

pub fn selection_origin_or_edit_point(&self) -> TextPoint

The selection origin, or the edit point if there is no selection. Note that the selection origin may be after the edit point, in the case of a backward selection.

source

pub fn selection_direction(&self) -> SelectionDirection

source

pub fn set_max_length(&mut self, length: Option<UTF16CodeUnits>)

source

pub fn set_min_length(&mut self, length: Option<UTF16CodeUnits>)

source

pub fn was_last_change_by_set_content(&self) -> bool

Was last edit made by set_content?

source

pub fn delete_char(&mut self, dir: Direction)

Remove a character at the current editing point

source

pub fn insert_char(&mut self, ch: char)

Insert a character at the current editing point

source

pub fn insert_string<S: Into<String>>(&mut self, s: S)

Insert a string at the current editing point

source

pub fn selection_start(&self) -> TextPoint

The start of the selection (or the edit point, if there is no selection). Always less than or equal to selection_end(), regardless of the selection direction.

source

pub fn selection_start_offset(&self) -> UTF8Bytes

The byte offset of the selection_start()

source

pub fn selection_end(&self) -> TextPoint

The end of the selection (or the edit point, if there is no selection). Always greater than or equal to selection_start(), regardless of the selection direction.

source

pub fn selection_end_offset(&self) -> UTF8Bytes

The byte offset of the selection_end()

source

pub fn has_selection(&self) -> bool

Whether or not there is an active selection (the selection may be zero-length)

source

pub fn sorted_selection_bounds(&self) -> (TextPoint, TextPoint)

Returns a tuple of (start, end) giving the bounds of the current selection. start is always less than or equal to end.

source

pub fn sorted_selection_offsets_range(&self) -> Range<UTF8Bytes>

Return the selection range as byte offsets from the start of the content.

If there is no selection, returns an empty range at the edit point.

source

pub fn selection_state(&self) -> SelectionState

The state of the current selection. Can be used to compare whether selection state has changed.

source

fn assert_ok_selection(&self)

source

pub fn get_selection_text(&self) -> Option<String>

source

fn selection_utf16_len(&self) -> UTF16CodeUnits

The length of the selected text in UTF-16 code units.

source

fn fold_selection_slices<B, F: FnMut(&mut B, &str)>(&self, acc: B, f: F) -> B

Run the callback on a series of slices that, concatenated, make up the selected text.

The accumulator acc can be mutated by the callback, and will be returned at the end.

source

pub fn replace_selection(&mut self, insert: DOMString)

source

pub fn current_line_length(&self) -> UTF8Bytes

Return the length in bytes of the current line under the editing point.

source

pub fn adjust_vertical(&mut self, adjust: isize, select: Selection)

Adjust the editing point position by a given number of lines. The resulting column is as close to the original column position as possible.

source

pub fn adjust_horizontal( &mut self, adjust: UTF8Bytes, direction: Direction, select: Selection, )

Adjust the editing point position by a given number of bytes. 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.

source

pub fn adjust_horizontal_by_one( &mut self, direction: Direction, select: Selection, )

Adjust the editing point position by exactly one grapheme cluster. If the edit point is at the beginning of the line and the direction is “Backward” or the edit point is at the end of the line and the direction is “Forward”, a vertical adjustment is made

source

fn adjust_selection_for_horizontal_change( &mut self, adjust: Direction, select: Selection, ) -> bool

Return whether to cancel the caret move

source

fn update_selection_direction(&mut self)

Update the field selection_direction.

When the edit_point (or focus) is before the selection_origin (or anchor) you have a backward selection. Otherwise you have a forward selection.

source

fn perform_horizontal_adjustment( &mut self, adjust: UTF8Bytes, direction: Direction, select: Selection, )

source

pub fn handle_return(&mut self) -> KeyReaction

Deal with a newline input.

source

pub fn select_all(&mut self)

Select all text in the input control.

source

pub fn clear_selection(&mut self)

Remove the current selection.

source

pub fn clear_selection_to_limit(&mut self, direction: Direction)

Remove the current selection and set the edit point to the end of the content.

source

pub fn adjust_horizontal_by_word( &mut self, direction: Direction, select: Selection, )

source

pub fn adjust_horizontal_to_line_end( &mut self, direction: Direction, select: Selection, )

source

pub fn adjust_horizontal_to_limit( &mut self, direction: Direction, select: Selection, )

source

pub fn handle_keydown(&mut self, event: &KeyboardEvent) -> KeyReaction

Process a given KeyboardEvent and return an action for the caller to execute.

source

pub fn handle_keydown_aux( &mut self, key: Key, mods: Modifiers, macos: bool, ) -> KeyReaction

source

pub fn handle_compositionend(&mut self, event: &CompositionEvent) -> KeyReaction

source

pub fn is_empty(&self) -> bool

Whether the content is empty.

source

pub fn len_utf8(&self) -> UTF8Bytes

The length of the content in bytes.

source

pub fn utf16_len(&self) -> UTF16CodeUnits

The total number of code units required to encode the content in utf16.

source

pub fn char_count(&self) -> usize

The length of the content in Unicode code points.

source

pub fn get_content(&self) -> DOMString

Get the current contents of the text input. Multiple lines are joined by \n.

source

pub fn single_line_content(&self) -> &DOMString

Get a reference to the contents of a single-line text input. Panics if self is a multiline input.

source

pub fn set_content(&mut self, content: DOMString)

Set the current contents of the text input. If this is control supports multiple lines, any \n encountered will be stripped and force a new logical line.

source

fn text_point_to_offset(&self, text_point: &TextPoint) -> UTF8Bytes

Convert a TextPoint into a byte offset from the start of the content.

source

fn offset_to_text_point(&self, abs_point: UTF8Bytes) -> TextPoint

Convert a byte offset from the start of the content into a TextPoint.

source

pub fn set_selection_range( &mut self, start: u32, end: u32, direction: SelectionDirection, )

source

pub fn set_edit_point_index(&mut self, index: usize)

Set the edit point index position based off of a given grapheme cluster offset

Trait Implementations§

source§

impl<T> MallocSizeOf for TextInput<T>

source§

fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize

Measure the heap usage of all descendant heap-allocated structures, but not the space taken up by the value itself.
source§

impl<T> Traceable for TextInput<T>

source§

unsafe fn trace(&self, tracer: *mut JSTracer)

Trace self.

Auto Trait Implementations§

§

impl<T> Freeze for TextInput<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for TextInput<T>
where T: RefUnwindSafe,

§

impl<T> !Send for TextInput<T>

§

impl<T> !Sync for TextInput<T>

§

impl<T> Unpin for TextInput<T>
where T: Unpin,

§

impl<T> UnwindSafe for TextInput<T>
where T: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> Downcast<T> for T

source§

fn downcast(&self) -> &T

source§

impl<T> Filterable for T

source§

fn filterable( self, filter_name: &'static str, ) -> RequestFilterDataProvider<T, fn(_: DataRequest<'_>) -> bool>

Creates a filterable data provider with the given name for debugging. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

impl<T> MaybeBoxed<Box<T>> for T

source§

fn maybe_boxed(self) -> Box<T>

Convert
source§

impl<T> MaybeBoxed<T> for T

source§

fn maybe_boxed(self) -> T

Convert
source§

impl<T> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
source§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same for T

source§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> Upcast<T> for T

source§

fn upcast(&self) -> Option<&T>

source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

impl<T> ErasedDestructor for T
where T: 'static,

source§

impl<T> MaybeSendSync for T