Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move some presentational hints to the new infrastructure. #5988

Merged
merged 4 commits into from May 12, 2015
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Prev

Move textarea cols/rows to the new infrastructure.

  • Loading branch information
Ms2ger committed May 12, 2015
commit 8b0505930f72752a392308e67f009ddb5fb92419
@@ -71,7 +71,7 @@ use style::computed_values::content::ContentItem;
use style::computed_values::{content, display, white_space};
use selectors::matching::DeclarationBlock;
use selectors::parser::{NamespaceConstraint, AttrSelector};
use style::legacy::{IntegerAttribute, UnsignedIntegerAttribute};
use style::legacy::UnsignedIntegerAttribute;
use style::node::{TElement, TElementAttributes, TNode};
use style::properties::{PropertyDeclaration, PropertyDeclarationBlock};
use util::smallvec::VecLike;
@@ -656,12 +656,6 @@ impl<'le> TElementAttributes<'le> for LayoutElement<'le> {
}
}

fn get_integer_attribute(self, integer_attribute: IntegerAttribute) -> Option<i32> {
unsafe {
self.element.get_integer_attribute_for_layout(integer_attribute)
}
}

fn get_unsigned_integer_attribute(self, attribute: UnsignedIntegerAttribute) -> Option<u32> {
unsafe {
self.element.get_unsigned_integer_attribute_for_layout(attribute)
@@ -59,10 +59,11 @@ use dom::virtualmethods::{VirtualMethods, vtable_for};

use devtools_traits::AttrInfo;
use style;
use style::legacy::{UnsignedIntegerAttribute, IntegerAttribute, from_declaration};
use style::legacy::{UnsignedIntegerAttribute, from_declaration};
use style::properties::{PropertyDeclarationBlock, PropertyDeclaration, parse_style_attribute};
use style::properties::DeclaredValue::SpecifiedValue;
use style::properties::longhands::border_spacing;
use style::properties::longhands::{self, border_spacing};
use style::values::CSSFloat;
use style::values::specified::{self, CSSColor};
use util::geometry::Au;
use util::namespace;
@@ -164,8 +165,6 @@ pub trait RawLayoutElementHelpers {

unsafe fn synthesize_presentational_hints_for_legacy_attributes<V>(&self, &mut V)
where V: VecLike<DeclarationBlock<Vec<PropertyDeclaration>>>;
unsafe fn get_integer_attribute_for_layout(&self, integer_attribute: IntegerAttribute)
-> Option<i32>;
unsafe fn get_checked_state_for_layout(&self) -> bool;
unsafe fn get_indeterminate_state_for_layout(&self) -> bool;
unsafe fn get_unsigned_integer_attribute_for_layout(&self, attribute: UnsignedIntegerAttribute)
@@ -330,26 +329,50 @@ impl RawLayoutElementHelpers for Element {
PropertyDeclaration::Width(SpecifiedValue(width_value))));
}
}
}

#[inline]
unsafe fn get_integer_attribute_for_layout(&self, integer_attribute: IntegerAttribute)
-> Option<i32> {
match integer_attribute {
IntegerAttribute::Cols => {
if !self.is_htmltextareaelement() {
panic!("I'm not a textarea element!")
}
let this: &HTMLTextAreaElement = mem::transmute(self);
Some(this.get_cols_for_layout() as i32)

let cols = if self.is_htmltextareaelement() {
let this: &HTMLTextAreaElement = mem::transmute(self);
match this.get_cols_for_layout() {
0 => None,
c => Some(c as i32),
}
IntegerAttribute::Rows => {
if !self.is_htmltextareaelement() {
panic!("I'm not a textarea element!")
}
let this: &HTMLTextAreaElement = mem::transmute(self);
Some(this.get_rows_for_layout() as i32)
} else {
None
};

if let Some(cols) = cols {
// TODO(mttr) ServoCharacterWidth uses the size math for <input type="text">, but
// the math for <textarea> is a little different since we need to take
// scrollbar size into consideration (but we don't have a scrollbar yet!)
//
// https://html.spec.whatwg.org/multipage/#textarea-effective-width
let value = specified::Length::ServoCharacterWidth(specified::CharacterWidth(cols));
hints.push(from_declaration(
PropertyDeclaration::Width(SpecifiedValue(
specified::LengthOrPercentageOrAuto::Length(value)))));
}


let rows = if self.is_htmltextareaelement() {
let this: &HTMLTextAreaElement = mem::transmute(self);
match this.get_rows_for_layout() {
0 => None,
r => Some(r as i32),
}
} else {
None
};

if let Some(rows) = rows {
// TODO(mttr) This should take scrollbar size into consideration.
//
// https://html.spec.whatwg.org/multipage/#textarea-effective-height
let value = specified::Length::FontRelative(specified::FontRelativeLength::Em(rows as CSSFloat));
hints.push(from_declaration(
PropertyDeclaration::Height(SpecifiedValue(
longhands::height::SpecifiedValue(
specified::LengthOrPercentageOrAuto::Length(value))))));
}
}

@@ -10,7 +10,7 @@ use std::sync::Arc;
use selectors::tree::{TElement, TNode};
use selectors::matching::DeclarationBlock;
use node::TElementAttributes;
use values::{CSSFloat, specified};
use values::specified;
use properties::DeclaredValue::SpecifiedValue;
use properties::PropertyDeclaration;
use properties::longhands;
@@ -19,13 +19,6 @@ use selector_matching::Stylist;
use util::geometry::Au;
use util::smallvec::VecLike;

/// Legacy presentational attributes that take an integer as defined in HTML5 § 2.4.4.2.
#[derive(Copy, Clone, PartialEq, Eq)]
pub enum IntegerAttribute {
Cols,
Rows,
}

/// Legacy presentational attributes that take a nonnegative integer as defined in HTML5 § 2.4.4.2.
#[derive(Copy, Clone, PartialEq, Eq)]
pub enum UnsignedIntegerAttribute {
@@ -96,37 +89,6 @@ impl PresentationalHintSynthesis for Stylist {
matching_rules_list,
shareable);
}
name if *name == atom!("textarea") => {
match element.get_integer_attribute(IntegerAttribute::Cols) {
Some(value) if value != 0 => {
// TODO(mttr) ServoCharacterWidth uses the size math for <input type="text">, but
// the math for <textarea> is a little different since we need to take
// scrollbar size into consideration (but we don't have a scrollbar yet!)
//
// https://html.spec.whatwg.org/multipage/#textarea-effective-width
let value = specified::Length::ServoCharacterWidth(specified::CharacterWidth(value));
matching_rules_list.push(from_declaration(
PropertyDeclaration::Width(SpecifiedValue(
specified::LengthOrPercentageOrAuto::Length(value)))));
*shareable = false
}
Some(_) | None => {}
}
match element.get_integer_attribute(IntegerAttribute::Rows) {
Some(value) if value != 0 => {
// TODO(mttr) This should take scrollbar size into consideration.
//
// https://html.spec.whatwg.org/multipage/#textarea-effective-height
let value = specified::Length::FontRelative(specified::FontRelativeLength::Em(value as CSSFloat));
matching_rules_list.push(from_declaration(
PropertyDeclaration::Height(SpecifiedValue(
longhands::height::SpecifiedValue(
specified::LengthOrPercentageOrAuto::Length(value))))));
*shareable = false
}
Some(_) | None => {}
}
}
_ => {}
}
}
@@ -5,7 +5,7 @@
//! Traits that nodes must implement. Breaks the otherwise-cyclic dependency between layout and
//! style.

use legacy::{IntegerAttribute, UnsignedIntegerAttribute};
use legacy::UnsignedIntegerAttribute;
use properties::PropertyDeclaration;
use util::smallvec::VecLike;

@@ -16,7 +16,6 @@ use string_cache::{Atom, Namespace};
pub trait TElementAttributes<'a> : Copy {
fn synthesize_presentational_hints_for_legacy_attributes<V>(self, &mut V)
where V: VecLike<DeclarationBlock<Vec<PropertyDeclaration>>>;
fn get_integer_attribute(self, attribute: IntegerAttribute) -> Option<i32>;
fn get_unsigned_integer_attribute(self, attribute: UnsignedIntegerAttribute) -> Option<u32>;

fn get_attr(self, namespace: &Namespace, attr: &Atom) -> Option<&'a str>;
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.