mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
commit
1de2fb3721
2 changed files with 8 additions and 10 deletions
|
@ -1082,11 +1082,13 @@ impl<'a> VirtualMethods for JSRef<'a, Element> {
|
||||||
impl<'a> style::TElement<'a> for JSRef<'a, Element> {
|
impl<'a> style::TElement<'a> for JSRef<'a, Element> {
|
||||||
fn get_attr(self, namespace: &Namespace, attr: &Atom) -> Option<&'a str> {
|
fn get_attr(self, namespace: &Namespace, attr: &Atom) -> Option<&'a str> {
|
||||||
self.get_attribute(namespace.clone(), attr).root().map(|attr| {
|
self.get_attribute(namespace.clone(), attr).root().map(|attr| {
|
||||||
|
// This transmute is used to cheat the lifetime restriction.
|
||||||
unsafe { mem::transmute(attr.value().as_slice()) }
|
unsafe { mem::transmute(attr.value().as_slice()) }
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
fn get_attrs(self, attr: &Atom) -> Vec<&'a str> {
|
fn get_attrs(self, attr: &Atom) -> Vec<&'a str> {
|
||||||
self.get_attributes(attr).iter().map(|attr| attr.root()).map(|attr| {
|
self.get_attributes(attr).iter().map(|attr| attr.root()).map(|attr| {
|
||||||
|
// This transmute is used to cheat the lifetime restriction.
|
||||||
unsafe { mem::transmute(attr.value().as_slice()) }
|
unsafe { mem::transmute(attr.value().as_slice()) }
|
||||||
}).collect()
|
}).collect()
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
use dom::bindings::cell::DOMRefCell;
|
||||||
use dom::bindings::codegen::Bindings::AttrBinding::AttrMethods;
|
use dom::bindings::codegen::Bindings::AttrBinding::AttrMethods;
|
||||||
use dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods;
|
use dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods;
|
||||||
use dom::bindings::codegen::Bindings::EventBinding::EventMethods;
|
use dom::bindings::codegen::Bindings::EventBinding::EventMethods;
|
||||||
|
@ -27,7 +28,6 @@ use string_cache::Atom;
|
||||||
|
|
||||||
use std::ascii::OwnedStrAsciiExt;
|
use std::ascii::OwnedStrAsciiExt;
|
||||||
use std::cell::{Cell, RefCell};
|
use std::cell::{Cell, RefCell};
|
||||||
use std::mem;
|
|
||||||
|
|
||||||
static DEFAULT_SUBMIT_VALUE: &'static str = "Submit";
|
static DEFAULT_SUBMIT_VALUE: &'static str = "Submit";
|
||||||
static DEFAULT_RESET_VALUE: &'static str = "Reset";
|
static DEFAULT_RESET_VALUE: &'static str = "Reset";
|
||||||
|
@ -50,7 +50,7 @@ pub struct HTMLInputElement {
|
||||||
input_type: Cell<InputType>,
|
input_type: Cell<InputType>,
|
||||||
checked: Cell<bool>,
|
checked: Cell<bool>,
|
||||||
uncommitted_value: RefCell<Option<String>>,
|
uncommitted_value: RefCell<Option<String>>,
|
||||||
value: RefCell<Option<String>>,
|
value: DOMRefCell<Option<String>>,
|
||||||
size: Cell<u32>,
|
size: Cell<u32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@ impl HTMLInputElement {
|
||||||
input_type: Cell::new(InputText),
|
input_type: Cell::new(InputText),
|
||||||
checked: Cell::new(false),
|
checked: Cell::new(false),
|
||||||
uncommitted_value: RefCell::new(None),
|
uncommitted_value: RefCell::new(None),
|
||||||
value: RefCell::new(None),
|
value: DOMRefCell::new(None),
|
||||||
size: Cell::new(DEFAULT_INPUT_SIZE),
|
size: Cell::new(DEFAULT_INPUT_SIZE),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -89,21 +89,17 @@ pub trait LayoutHTMLInputElementHelpers {
|
||||||
impl LayoutHTMLInputElementHelpers for HTMLInputElement {
|
impl LayoutHTMLInputElementHelpers for HTMLInputElement {
|
||||||
#[allow(unrooted_must_root)]
|
#[allow(unrooted_must_root)]
|
||||||
unsafe fn get_value_for_layout(&self) -> String {
|
unsafe fn get_value_for_layout(&self) -> String {
|
||||||
unsafe fn get_raw_value(input: &HTMLInputElement) -> Option<String> {
|
|
||||||
mem::transmute::<&RefCell<Option<String>>, &Option<String>>(&input.value).clone()
|
|
||||||
}
|
|
||||||
|
|
||||||
match self.input_type.get() {
|
match self.input_type.get() {
|
||||||
InputCheckbox | InputRadio => "".to_string(),
|
InputCheckbox | InputRadio => "".to_string(),
|
||||||
InputFile | InputImage => "".to_string(),
|
InputFile | InputImage => "".to_string(),
|
||||||
InputButton(ref default) => get_raw_value(self)
|
InputButton(ref default) => self.value.borrow_for_layout().clone()
|
||||||
.or_else(|| default.map(|v| v.to_string()))
|
.or_else(|| default.map(|v| v.to_string()))
|
||||||
.unwrap_or_else(|| "".to_string()),
|
.unwrap_or_else(|| "".to_string()),
|
||||||
InputPassword => {
|
InputPassword => {
|
||||||
let raw = get_raw_value(self).unwrap_or_else(|| "".to_string());
|
let raw = self.value.borrow_for_layout().clone().unwrap_or_else(|| "".to_string());
|
||||||
String::from_char(raw.len(), '*')
|
String::from_char(raw.len(), '*')
|
||||||
}
|
}
|
||||||
_ => get_raw_value(self).unwrap_or_else(|| "".to_string()),
|
_ => self.value.borrow_for_layout().clone().unwrap_or_else(|| "".to_string()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue