-
Notifications
You must be signed in to change notification settings - Fork 178
Expand file tree
/
Copy pathtextarea.rs
More file actions
76 lines (68 loc) · 2.51 KB
/
textarea.rs
File metadata and controls
76 lines (68 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
use webcore::value::Reference;
use webcore::try_from::TryInto;
use webapi::event_target::{IEventTarget, EventTarget};
use webapi::node::{INode, Node};
use webapi::element::{IElement, Element};
use webapi::html_element::{IHtmlElement, HtmlElement};
/// The HTML `<textarea>` element represents a multi-line plain-text editing control.
///
/// [(JavaScript docs)](https://developer.mozilla.org/en/docs/Web/HTML/Element/textarea)
// https://html.spec.whatwg.org/#htmltextareaelement
#[derive(Clone, Debug, PartialEq, Eq, ReferenceType)]
#[reference(instance_of = "HTMLTextAreaElement")]
#[reference(subclass_of(EventTarget, Node, Element, HtmlElement))]
pub struct TextAreaElement( Reference );
impl IEventTarget for TextAreaElement {}
impl INode for TextAreaElement {}
impl IElement for TextAreaElement {}
impl IHtmlElement for TextAreaElement {}
impl TextAreaElement {
/// The value of the control.
// https://html.spec.whatwg.org/#the-textarea-element:dom-textarea-value
#[inline]
pub fn value( &self ) -> String {
js! (
return @{self}.value;
).try_into().unwrap()
}
/// Sets the value of the control.
// https://html.spec.whatwg.org/#the-textarea-element:dom-textarea-value
#[inline]
pub fn set_value( &self, value: &str ) {
js! { @(no_return)
@{self}.value = @{value};
}
}
/// The offset to the start of the selection.
// https://html.spec.whatwg.org/#dom-textarea/input-selectionstart
#[inline]
pub fn selection_start( &self ) -> u32 {
js! (
return @{self}.selectionStart;
).try_into().ok()
}
/// Sets the offset to the start of the selection.
// https://html.spec.whatwg.org/#dom-textarea/input-selectionstart
#[inline]
pub fn set_selection_start( &self, value: u32 ) -> Result<(), InvalidStateError> {
js_try! ( @(no_return)
@{self}.selectionStart = @{value};
).unwrap()
}
/// The offset to the end of the selection.
// https://html.spec.whatwg.org/#dom-textarea/input-selectionend
#[inline]
pub fn selection_end( &self ) -> u32 {
js! (
return @{self}.selectionEnd;
).try_into().ok()
}
/// Sets the offset to the end of the selection.
// https://html.spec.whatwg.org/#dom-textarea/input-selectionend
#[inline]
pub fn set_selection_end( &self, value: u32 ) -> Result<(), InvalidStateError> {
js_try! ( @(no_return)
@{self}.selectionEnd = @{value};
).unwrap()
}
}