mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Disallow toggling radio buttons. Use generated content for checkboxes and radio buttons. Switching to the glyph 0 for the average advance width.
This commit is contained in:
parent
f70bb68503
commit
8112859d55
7 changed files with 15 additions and 36 deletions
|
@ -235,7 +235,7 @@ impl FontHandleMethods for FontHandle {
|
|||
}
|
||||
}
|
||||
|
||||
let average_advance = self.glyph_index('x')
|
||||
let average_advance = self.glyph_index('0')
|
||||
.and_then(|idx| self.glyph_h_advance(idx))
|
||||
.map(|advance| self.font_units_to_au(advance))
|
||||
.unwrap_or(max_advance_width);
|
||||
|
|
|
@ -154,7 +154,7 @@ impl FontHandleMethods for FontHandle {
|
|||
let line_gap = (ascent + descent + leading + 0.5).floor();
|
||||
|
||||
let max_advance_width = Au::from_pt(bounding_rect.size.width as f64);
|
||||
let average_advance = self.glyph_index('x')
|
||||
let average_advance = self.glyph_index('0')
|
||||
.and_then(|idx| self.glyph_h_advance(idx))
|
||||
.map(|advance| Au::from_frac_px(advance))
|
||||
.unwrap_or(max_advance_width);
|
||||
|
|
|
@ -226,10 +226,10 @@ impl<'a> FlowConstructor<'a> {
|
|||
// value? definitely for string comparisons.
|
||||
let elem = node.as_element();
|
||||
let data = match elem.get_attr(&ns!(""), "type") {
|
||||
Some("checkbox") => InputCheckbox(node.get_input_checked()),
|
||||
Some("checkbox") => InputCheckbox,
|
||||
Some("button") | Some("submit") | Some("reset") =>
|
||||
InputButton(node.get_input_value().len() as u32),
|
||||
Some("radio") => InputRadioButton(node.get_input_checked()),
|
||||
Some("radio") => InputRadioButton,
|
||||
Some("file") => InputFile(node.get_input_size()),
|
||||
_ => InputText(node.get_input_size()),
|
||||
};
|
||||
|
|
|
@ -161,8 +161,8 @@ impl InlineBlockFragmentInfo {
|
|||
pub enum InputFragmentInfo {
|
||||
InputButton(u32),
|
||||
InputText(u32),
|
||||
InputCheckbox(bool),
|
||||
InputRadioButton(bool),
|
||||
InputCheckbox,
|
||||
InputRadioButton,
|
||||
InputFile(u32),
|
||||
}
|
||||
|
||||
|
|
|
@ -731,16 +731,6 @@ impl<'ln> ThreadSafeLayoutNode<'ln> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn get_input_checked(&self) -> bool {
|
||||
unsafe {
|
||||
if !self.get().is_htmlinputelement() {
|
||||
fail!("not an input element!")
|
||||
}
|
||||
let input: JS<HTMLInputElement> = self.get_jsmanaged().transmute_copy();
|
||||
input.get_checked_for_layout()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_input_value(&self) -> String {
|
||||
unsafe {
|
||||
if !self.get().is_htmlinputelement() {
|
||||
|
|
|
@ -81,17 +81,11 @@ impl HTMLInputElement {
|
|||
}
|
||||
|
||||
pub trait LayoutHTMLInputElementHelpers {
|
||||
unsafe fn get_checked_for_layout(&self) -> bool;
|
||||
unsafe fn get_value_for_layout(&self) -> String;
|
||||
unsafe fn get_size_for_layout(&self) -> u32;
|
||||
}
|
||||
|
||||
impl LayoutHTMLInputElementHelpers for JS<HTMLInputElement> {
|
||||
#[allow(unrooted_must_root)]
|
||||
unsafe fn get_checked_for_layout(&self) -> bool {
|
||||
(*self.unsafe_get()).checked.get()
|
||||
}
|
||||
|
||||
#[allow(unrooted_must_root)]
|
||||
unsafe fn get_value_for_layout(&self) -> String {
|
||||
unsafe fn get_raw_value(input: &JS<HTMLInputElement>) -> Option<String> {
|
||||
|
@ -99,16 +93,7 @@ impl LayoutHTMLInputElementHelpers for JS<HTMLInputElement> {
|
|||
}
|
||||
|
||||
match (*self.unsafe_get()).input_type.get() {
|
||||
InputCheckbox => if self.get_checked_for_layout() {
|
||||
"[X]"
|
||||
} else {
|
||||
"[ ]"
|
||||
}.to_string(),
|
||||
InputRadio => if self.get_checked_for_layout() {
|
||||
"(*)"
|
||||
} else {
|
||||
"( )"
|
||||
}.to_string(),
|
||||
InputCheckbox | InputRadio => "".to_string(),
|
||||
InputFile | InputImage => "".to_string(),
|
||||
InputButton(ref default) => get_raw_value(self)
|
||||
.or_else(|| default.map(|v| v.to_string()))
|
||||
|
@ -117,7 +102,7 @@ impl LayoutHTMLInputElementHelpers for JS<HTMLInputElement> {
|
|||
let raw = get_raw_value(self).unwrap_or_else(|| "".to_string());
|
||||
String::from_char(raw.len(), '*')
|
||||
}
|
||||
_ => get_raw_value(self).unwrap_or("".to_string()),
|
||||
_ => get_raw_value(self).unwrap_or_else(|| "".to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -369,9 +354,8 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLInputElement> {
|
|||
|
||||
if "click" == event.Type().as_slice() && !event.DefaultPrevented() {
|
||||
match self.input_type.get() {
|
||||
InputCheckbox | InputRadio => {
|
||||
self.SetChecked(!self.checked.get());
|
||||
}
|
||||
InputCheckbox => self.SetChecked(!self.checked.get()),
|
||||
InputRadio => self.SetChecked(true),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -123,3 +123,8 @@ input[type="reset"] { background: lightgrey; border-top: solid 1px #EEEEEE;
|
|||
input[type="hidden"] { display: none !important }
|
||||
input[type="checkbox"],
|
||||
input[type="radio"] { font-family: monospace !important; border: none !important; background: transparent; }
|
||||
|
||||
input[type="checkbox"]::before { content: "[ ]"; padding: 0; }
|
||||
input[type="checkbox"][checked]::before { content: "[✓]"; }
|
||||
input[type="radio"]::before { content: "( )"; padding: 0; }
|
||||
input[type="radio"][checked]::before { content: "(●)"; }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue