mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
parent
c9ba16f9fb
commit
0148e9705b
9 changed files with 53 additions and 232 deletions
|
@ -417,6 +417,31 @@ impl TextControl for HTMLInputElement {
|
|||
_ => false
|
||||
}
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#concept-input-apply
|
||||
//
|
||||
// Defines input types to which the select() IDL method applies. These are a superset of the
|
||||
// types for which selection_api_applies() returns true.
|
||||
//
|
||||
// Types omitted which could theoretically be included if they were
|
||||
// rendered as a text control: file
|
||||
fn has_selectable_text(&self) -> bool {
|
||||
match self.input_type() {
|
||||
InputType::Text | InputType::Search | InputType::Url
|
||||
| InputType::Tel | InputType::Password | InputType::Email
|
||||
| InputType::Date | InputType::Month | InputType::Week
|
||||
| InputType::Time | InputType::DatetimeLocal | InputType::Number
|
||||
| InputType::Color => {
|
||||
true
|
||||
}
|
||||
|
||||
InputType::Button | InputType::Checkbox | InputType::File
|
||||
| InputType::Hidden | InputType::Image | InputType::Radio
|
||||
| InputType::Range | InputType::Reset | InputType::Submit => {
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl HTMLInputElementMethods for HTMLInputElement {
|
||||
|
@ -687,6 +712,11 @@ impl HTMLInputElementMethods for HTMLInputElement {
|
|||
}
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-textarea/input-select
|
||||
fn Select(&self) {
|
||||
self.dom_select(); // defined in TextControl trait
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-textarea/input-selectionstart
|
||||
fn GetSelectionStart(&self) -> Option<u32> {
|
||||
self.get_dom_selection_start()
|
||||
|
|
|
@ -152,6 +152,10 @@ impl TextControl for HTMLTextAreaElement {
|
|||
fn selection_api_applies(&self) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn has_selectable_text(&self) -> bool {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
impl HTMLTextAreaElementMethods for HTMLTextAreaElement {
|
||||
|
@ -266,6 +270,11 @@ impl HTMLTextAreaElementMethods for HTMLTextAreaElement {
|
|||
self.upcast::<HTMLElement>().labels()
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-textarea/input-select
|
||||
fn Select(&self) {
|
||||
self.dom_select(); // defined in TextControl trait
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-textarea/input-selectionstart
|
||||
fn GetSelectionStart(&self) -> Option<u32> {
|
||||
self.get_dom_selection_start()
|
||||
|
|
|
@ -15,6 +15,18 @@ use textinput::{SelectionDirection, TextInput};
|
|||
pub trait TextControl: DerivedFrom<EventTarget> + DerivedFrom<Node> {
|
||||
fn textinput(&self) -> &DomRefCell<TextInput<ScriptToConstellationChan>>;
|
||||
fn selection_api_applies(&self) -> bool;
|
||||
fn has_selectable_text(&self) -> bool;
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-textarea/input-select
|
||||
fn dom_select(&self) {
|
||||
// Step 1
|
||||
if !self.has_selectable_text() {
|
||||
return;
|
||||
}
|
||||
|
||||
// Step 2
|
||||
self.set_selection_range(Some(0), Some(u32::max_value()), None);
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-textarea/input-selectionstart
|
||||
fn get_dom_selection_start(&self) -> Option<u32> {
|
||||
|
|
|
@ -89,7 +89,7 @@ interface HTMLInputElement : HTMLElement {
|
|||
|
||||
readonly attribute NodeList labels;
|
||||
|
||||
//void select();
|
||||
void select();
|
||||
[SetterThrows]
|
||||
attribute unsigned long? selectionStart;
|
||||
[SetterThrows]
|
||||
|
|
|
@ -50,7 +50,7 @@ interface HTMLTextAreaElement : HTMLElement {
|
|||
|
||||
readonly attribute NodeList labels;
|
||||
|
||||
// void select();
|
||||
void select();
|
||||
[SetterThrows]
|
||||
attribute unsigned long? selectionStart;
|
||||
[SetterThrows]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue