mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
Auto merge of #14038 - upsuper:bug1294299, r=heycam
Add Element.style support for stylo <!-- Please describe your changes on the following line: --> This is the Servo side change of [bug 1294299](https://bugzilla.mozilla.org/show_bug.cgi?id=1294299) which has been reviewed by @heycam, @emilio, and @SimonSapin. This should not be merged until the Gecko side change gets merged into mozilla-central. r? @heycam --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [ ] These changes fix #__ (github issue number if applicable). <!-- Either: --> - [ ] There are tests for these changes OR - [ ] These changes do not require tests because _____ <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/14038) <!-- Reviewable:end -->
This commit is contained in:
commit
2390503772
5 changed files with 3063 additions and 10 deletions
|
@ -236,10 +236,12 @@ COMPILATION_TARGETS = {
|
||||||
"target_dir": "../gecko_bindings",
|
"target_dir": "../gecko_bindings",
|
||||||
"blacklist_types": [
|
"blacklist_types": [
|
||||||
"nsACString_internal",
|
"nsACString_internal",
|
||||||
|
"nsAString_internal",
|
||||||
],
|
],
|
||||||
"raw_lines": [
|
"raw_lines": [
|
||||||
"pub use nsstring::nsACString;",
|
"pub use nsstring::{nsACString, nsAString};",
|
||||||
"type nsACString_internal = nsACString;",
|
"type nsACString_internal = nsACString;",
|
||||||
|
"type nsAString_internal = nsAString;"
|
||||||
],
|
],
|
||||||
"flags": [
|
"flags": [
|
||||||
"--ignore-methods",
|
"--ignore-methods",
|
||||||
|
|
|
@ -32,14 +32,14 @@ def msvc32_symbolify(source, ident):
|
||||||
|
|
||||||
|
|
||||||
class GkAtomSource:
|
class GkAtomSource:
|
||||||
PATTERN = re.compile('^GK_ATOM\((.+),\s*"(.*)"\)')
|
PATTERN = re.compile('^GK_ATOM\((?P<ident>.+),\s*"(?P<value>.*)"\)', re.M)
|
||||||
FILE = "dist/include/nsGkAtomList.h"
|
FILE = "dist/include/nsGkAtomList.h"
|
||||||
CLASS = "nsGkAtoms"
|
CLASS = "nsGkAtoms"
|
||||||
TYPE = "nsIAtom"
|
TYPE = "nsIAtom"
|
||||||
|
|
||||||
|
|
||||||
class CSSPseudoElementsAtomSource:
|
class CSSPseudoElementsAtomSource:
|
||||||
PATTERN = re.compile('^CSS_PSEUDO_ELEMENT\((.+),\s*"(.*)",')
|
PATTERN = re.compile('^CSS_PSEUDO_ELEMENT\((?P<ident>.+),\s*"(?P<value>.*)",', re.M)
|
||||||
FILE = "dist/include/nsCSSPseudoElementList.h"
|
FILE = "dist/include/nsCSSPseudoElementList.h"
|
||||||
CLASS = "nsCSSPseudoElements"
|
CLASS = "nsCSSPseudoElements"
|
||||||
# NB: nsICSSPseudoElement is effectively the same as a nsIAtom, but we need
|
# NB: nsICSSPseudoElement is effectively the same as a nsIAtom, but we need
|
||||||
|
@ -48,16 +48,24 @@ class CSSPseudoElementsAtomSource:
|
||||||
|
|
||||||
|
|
||||||
class CSSAnonBoxesAtomSource:
|
class CSSAnonBoxesAtomSource:
|
||||||
PATTERN = re.compile('^CSS_ANON_BOX\((.+),\s*"(.*)"\)')
|
PATTERN = re.compile('^CSS_ANON_BOX\((?P<ident>.+),\s*"(?P<value>.*)"\)', re.M)
|
||||||
FILE = "dist/include/nsCSSAnonBoxList.h"
|
FILE = "dist/include/nsCSSAnonBoxList.h"
|
||||||
CLASS = "nsCSSAnonBoxes"
|
CLASS = "nsCSSAnonBoxes"
|
||||||
TYPE = "nsICSSAnonBoxPseudo"
|
TYPE = "nsICSSAnonBoxPseudo"
|
||||||
|
|
||||||
|
|
||||||
|
class CSSPropsAtomSource:
|
||||||
|
PATTERN = re.compile('^CSS_PROP_[A-Z]+\(\s*(?P<value>[^,]+),\s*(?P<ident>[^,]+)', re.M)
|
||||||
|
FILE = "dist/include/nsCSSPropList.h"
|
||||||
|
CLASS = "nsCSSProps"
|
||||||
|
TYPE = "nsICSSProperty"
|
||||||
|
|
||||||
|
|
||||||
SOURCES = [
|
SOURCES = [
|
||||||
GkAtomSource,
|
GkAtomSource,
|
||||||
CSSPseudoElementsAtomSource,
|
CSSPseudoElementsAtomSource,
|
||||||
CSSAnonBoxesAtomSource,
|
CSSAnonBoxesAtomSource,
|
||||||
|
CSSPropsAtomSource,
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@ -95,10 +103,14 @@ def collect_atoms(objdir):
|
||||||
atoms = []
|
atoms = []
|
||||||
for source in SOURCES:
|
for source in SOURCES:
|
||||||
with open(os.path.join(objdir, source.FILE)) as f:
|
with open(os.path.join(objdir, source.FILE)) as f:
|
||||||
for line in f.readlines():
|
content = f.read()
|
||||||
result = re.match(source.PATTERN, line)
|
found = set()
|
||||||
if result:
|
for match in source.PATTERN.finditer(content):
|
||||||
atoms.append(Atom(source, result.group(1), result.group(2)))
|
ident = match.group('ident')
|
||||||
|
if ident in found:
|
||||||
|
continue
|
||||||
|
found.add(ident)
|
||||||
|
atoms.append(Atom(source, ident, match.group('value')))
|
||||||
return atoms
|
return atoms
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
/* automatically generated by rust-bindgen */
|
/* automatically generated by rust-bindgen */
|
||||||
|
|
||||||
pub use nsstring::nsACString;
|
pub use nsstring::{nsACString, nsAString};
|
||||||
type nsACString_internal = nsACString;
|
type nsACString_internal = nsACString;
|
||||||
|
type nsAString_internal = nsAString;
|
||||||
pub type ServoComputedValuesStrong = ::gecko_bindings::sugar::ownership::Strong<ServoComputedValues>;
|
pub type ServoComputedValuesStrong = ::gecko_bindings::sugar::ownership::Strong<ServoComputedValues>;
|
||||||
pub type ServoComputedValuesBorrowedOrNull<'a> = Option<&'a ServoComputedValues>;
|
pub type ServoComputedValuesBorrowedOrNull<'a> = Option<&'a ServoComputedValues>;
|
||||||
pub type ServoComputedValuesBorrowed<'a> = &'a ServoComputedValues;
|
pub type ServoComputedValuesBorrowed<'a> = &'a ServoComputedValues;
|
||||||
|
@ -922,16 +923,73 @@ extern "C" {
|
||||||
pub fn Servo_ParseStyleAttribute(data: *const nsACString_internal)
|
pub fn Servo_ParseStyleAttribute(data: *const nsACString_internal)
|
||||||
-> RawServoDeclarationBlockStrong;
|
-> RawServoDeclarationBlockStrong;
|
||||||
}
|
}
|
||||||
|
extern "C" {
|
||||||
|
pub fn Servo_DeclarationBlock_CreateEmpty()
|
||||||
|
-> RawServoDeclarationBlockStrong;
|
||||||
|
}
|
||||||
|
extern "C" {
|
||||||
|
pub fn Servo_DeclarationBlock_Clone(declarations:
|
||||||
|
RawServoDeclarationBlockBorrowed)
|
||||||
|
-> RawServoDeclarationBlockStrong;
|
||||||
|
}
|
||||||
extern "C" {
|
extern "C" {
|
||||||
pub fn Servo_DeclarationBlock_Equals(a: RawServoDeclarationBlockBorrowed,
|
pub fn Servo_DeclarationBlock_Equals(a: RawServoDeclarationBlockBorrowed,
|
||||||
b: RawServoDeclarationBlockBorrowed)
|
b: RawServoDeclarationBlockBorrowed)
|
||||||
-> bool;
|
-> bool;
|
||||||
}
|
}
|
||||||
|
extern "C" {
|
||||||
|
pub fn Servo_DeclarationBlock_GetCssText(declarations:
|
||||||
|
RawServoDeclarationBlockBorrowed,
|
||||||
|
result: *mut nsAString_internal);
|
||||||
|
}
|
||||||
extern "C" {
|
extern "C" {
|
||||||
pub fn Servo_DeclarationBlock_SerializeOneValue(declarations:
|
pub fn Servo_DeclarationBlock_SerializeOneValue(declarations:
|
||||||
RawServoDeclarationBlockBorrowed,
|
RawServoDeclarationBlockBorrowed,
|
||||||
buffer: *mut nsString);
|
buffer: *mut nsString);
|
||||||
}
|
}
|
||||||
|
extern "C" {
|
||||||
|
pub fn Servo_DeclarationBlock_Count(declarations:
|
||||||
|
RawServoDeclarationBlockBorrowed)
|
||||||
|
-> u32;
|
||||||
|
}
|
||||||
|
extern "C" {
|
||||||
|
pub fn Servo_DeclarationBlock_GetNthProperty(declarations:
|
||||||
|
RawServoDeclarationBlockBorrowed,
|
||||||
|
index: u32,
|
||||||
|
result:
|
||||||
|
*mut nsAString_internal)
|
||||||
|
-> bool;
|
||||||
|
}
|
||||||
|
extern "C" {
|
||||||
|
pub fn Servo_DeclarationBlock_GetPropertyValue(declarations:
|
||||||
|
RawServoDeclarationBlockBorrowed,
|
||||||
|
property: *mut nsIAtom,
|
||||||
|
is_custom: bool,
|
||||||
|
value:
|
||||||
|
*mut nsAString_internal);
|
||||||
|
}
|
||||||
|
extern "C" {
|
||||||
|
pub fn Servo_DeclarationBlock_GetPropertyIsImportant(declarations:
|
||||||
|
RawServoDeclarationBlockBorrowed,
|
||||||
|
property:
|
||||||
|
*mut nsIAtom,
|
||||||
|
is_custom: bool)
|
||||||
|
-> bool;
|
||||||
|
}
|
||||||
|
extern "C" {
|
||||||
|
pub fn Servo_DeclarationBlock_SetProperty(declarations:
|
||||||
|
RawServoDeclarationBlockBorrowed,
|
||||||
|
property: *mut nsIAtom,
|
||||||
|
is_custom: bool,
|
||||||
|
value: *mut nsACString_internal,
|
||||||
|
is_important: bool) -> bool;
|
||||||
|
}
|
||||||
|
extern "C" {
|
||||||
|
pub fn Servo_DeclarationBlock_RemoveProperty(declarations:
|
||||||
|
RawServoDeclarationBlockBorrowed,
|
||||||
|
property: *mut nsIAtom,
|
||||||
|
is_custom: bool);
|
||||||
|
}
|
||||||
extern "C" {
|
extern "C" {
|
||||||
pub fn Servo_CSSSupports(name: *const nsACString_internal,
|
pub fn Servo_CSSSupports(name: *const nsACString_internal,
|
||||||
value: *const nsACString_internal) -> bool;
|
value: *const nsACString_internal) -> bool;
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -7,6 +7,7 @@ use cssparser::{Parser, ToCss};
|
||||||
use env_logger;
|
use env_logger;
|
||||||
use euclid::Size2D;
|
use euclid::Size2D;
|
||||||
use parking_lot::RwLock;
|
use parking_lot::RwLock;
|
||||||
|
use std::fmt::Write;
|
||||||
use std::mem::transmute;
|
use std::mem::transmute;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
use style::arc_ptr_eq;
|
use style::arc_ptr_eq;
|
||||||
|
@ -25,9 +26,9 @@ use style::gecko_bindings::bindings::{RawServoStyleSetBorrowed, RawServoStyleSet
|
||||||
use style::gecko_bindings::bindings::{RawServoStyleSheetBorrowed, ServoComputedValuesBorrowed};
|
use style::gecko_bindings::bindings::{RawServoStyleSheetBorrowed, ServoComputedValuesBorrowed};
|
||||||
use style::gecko_bindings::bindings::{RawServoStyleSheetStrong, ServoComputedValuesStrong};
|
use style::gecko_bindings::bindings::{RawServoStyleSheetStrong, ServoComputedValuesStrong};
|
||||||
use style::gecko_bindings::bindings::{ThreadSafePrincipalHolder, ThreadSafeURIHolder};
|
use style::gecko_bindings::bindings::{ThreadSafePrincipalHolder, ThreadSafeURIHolder};
|
||||||
|
use style::gecko_bindings::bindings::{nsACString, nsAString};
|
||||||
use style::gecko_bindings::bindings::Gecko_Utf8SliceToString;
|
use style::gecko_bindings::bindings::Gecko_Utf8SliceToString;
|
||||||
use style::gecko_bindings::bindings::ServoComputedValuesBorrowedOrNull;
|
use style::gecko_bindings::bindings::ServoComputedValuesBorrowedOrNull;
|
||||||
use style::gecko_bindings::bindings::nsACString;
|
|
||||||
use style::gecko_bindings::structs::{SheetParsingMode, nsIAtom};
|
use style::gecko_bindings::structs::{SheetParsingMode, nsIAtom};
|
||||||
use style::gecko_bindings::structs::ServoElementSnapshot;
|
use style::gecko_bindings::structs::ServoElementSnapshot;
|
||||||
use style::gecko_bindings::structs::nsRestyleHint;
|
use style::gecko_bindings::structs::nsRestyleHint;
|
||||||
|
@ -420,6 +421,18 @@ pub extern "C" fn Servo_ParseStyleAttribute(data: *const nsACString) -> RawServo
|
||||||
Arc::new(RwLock::new(GeckoElement::parse_style_attribute(value))).into_strong()
|
Arc::new(RwLock::new(GeckoElement::parse_style_attribute(value))).into_strong()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub extern "C" fn Servo_DeclarationBlock_CreateEmpty() -> RawServoDeclarationBlockStrong {
|
||||||
|
Arc::new(RwLock::new(PropertyDeclarationBlock { declarations: vec![], important_count: 0 })).into_strong()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub extern "C" fn Servo_DeclarationBlock_Clone(declarations: RawServoDeclarationBlockBorrowed)
|
||||||
|
-> RawServoDeclarationBlockStrong {
|
||||||
|
let declarations = RwLock::<PropertyDeclarationBlock>::as_arc(&declarations);
|
||||||
|
Arc::new(RwLock::new(declarations.read().clone())).into_strong()
|
||||||
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn Servo_DeclarationBlock_AddRef(declarations: RawServoDeclarationBlockBorrowed) {
|
pub extern "C" fn Servo_DeclarationBlock_AddRef(declarations: RawServoDeclarationBlockBorrowed) {
|
||||||
unsafe { RwLock::<PropertyDeclarationBlock>::addref(declarations) };
|
unsafe { RwLock::<PropertyDeclarationBlock>::addref(declarations) };
|
||||||
|
@ -437,6 +450,13 @@ pub extern "C" fn Servo_DeclarationBlock_Equals(a: RawServoDeclarationBlockBorro
|
||||||
*RwLock::<PropertyDeclarationBlock>::as_arc(&a).read() == *RwLock::<PropertyDeclarationBlock>::as_arc(&b).read()
|
*RwLock::<PropertyDeclarationBlock>::as_arc(&a).read() == *RwLock::<PropertyDeclarationBlock>::as_arc(&b).read()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub extern "C" fn Servo_DeclarationBlock_GetCssText(declarations: RawServoDeclarationBlockBorrowed,
|
||||||
|
result: *mut nsAString) {
|
||||||
|
let declarations = RwLock::<PropertyDeclarationBlock>::as_arc(&declarations);
|
||||||
|
declarations.read().to_css(unsafe { result.as_mut().unwrap() }).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn Servo_DeclarationBlock_SerializeOneValue(
|
pub extern "C" fn Servo_DeclarationBlock_SerializeOneValue(
|
||||||
declarations: RawServoDeclarationBlockBorrowed,
|
declarations: RawServoDeclarationBlockBorrowed,
|
||||||
|
@ -469,6 +489,85 @@ pub extern "C" fn Servo_DeclarationBlock_SerializeOneValue(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub extern "C" fn Servo_DeclarationBlock_Count(declarations: RawServoDeclarationBlockBorrowed) -> u32 {
|
||||||
|
let declarations = RwLock::<PropertyDeclarationBlock>::as_arc(&declarations);
|
||||||
|
declarations.read().declarations.len() as u32
|
||||||
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub extern "C" fn Servo_DeclarationBlock_GetNthProperty(declarations: RawServoDeclarationBlockBorrowed,
|
||||||
|
index: u32, result: *mut nsAString) -> bool {
|
||||||
|
let declarations = RwLock::<PropertyDeclarationBlock>::as_arc(&declarations);
|
||||||
|
if let Some(&(ref decl, _)) = declarations.read().declarations.get(index as usize) {
|
||||||
|
let result = unsafe { result.as_mut().unwrap() };
|
||||||
|
write!(result, "{}", decl.name()).unwrap();
|
||||||
|
true
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// FIXME Methods of PropertyDeclarationBlock should take atoms directly.
|
||||||
|
// This function is just a temporary workaround before that finishes.
|
||||||
|
fn get_property_name_from_atom(atom: *mut nsIAtom, is_custom: bool) -> String {
|
||||||
|
let atom = Atom::from(atom);
|
||||||
|
if !is_custom {
|
||||||
|
atom.to_string()
|
||||||
|
} else {
|
||||||
|
let mut result = String::with_capacity(atom.len() as usize + 2);
|
||||||
|
write!(result, "--{}", atom).unwrap();
|
||||||
|
result
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub extern "C" fn Servo_DeclarationBlock_GetPropertyValue(declarations: RawServoDeclarationBlockBorrowed,
|
||||||
|
property: *mut nsIAtom, is_custom: bool,
|
||||||
|
value: *mut nsAString) {
|
||||||
|
let declarations = RwLock::<PropertyDeclarationBlock>::as_arc(&declarations);
|
||||||
|
let property = get_property_name_from_atom(property, is_custom);
|
||||||
|
declarations.read().property_value_to_css(&property, unsafe { value.as_mut().unwrap() }).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub extern "C" fn Servo_DeclarationBlock_GetPropertyIsImportant(declarations: RawServoDeclarationBlockBorrowed,
|
||||||
|
property: *mut nsIAtom, is_custom: bool) -> bool {
|
||||||
|
let declarations = RwLock::<PropertyDeclarationBlock>::as_arc(&declarations);
|
||||||
|
let property = get_property_name_from_atom(property, is_custom);
|
||||||
|
declarations.read().property_priority(&property).important()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub extern "C" fn Servo_DeclarationBlock_SetProperty(declarations: RawServoDeclarationBlockBorrowed,
|
||||||
|
property: *mut nsIAtom, is_custom: bool,
|
||||||
|
value: *mut nsACString, is_important: bool) -> bool {
|
||||||
|
let property = get_property_name_from_atom(property, is_custom);
|
||||||
|
let value = unsafe { value.as_ref().unwrap().as_str_unchecked() };
|
||||||
|
// FIXME Needs real URL and ParserContextExtraData.
|
||||||
|
let base_url = &*DUMMY_BASE_URL;
|
||||||
|
let extra_data = ParserContextExtraData::default();
|
||||||
|
if let Ok(decls) = parse_one_declaration(&property, value, &base_url,
|
||||||
|
Box::new(StdoutErrorReporter), extra_data) {
|
||||||
|
let mut declarations = RwLock::<PropertyDeclarationBlock>::as_arc(&declarations).write();
|
||||||
|
let importance = if is_important { Importance::Important } else { Importance::Normal };
|
||||||
|
for decl in decls.into_iter() {
|
||||||
|
declarations.set_parsed_declaration(decl, importance);
|
||||||
|
}
|
||||||
|
true
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub extern "C" fn Servo_DeclarationBlock_RemoveProperty(declarations: RawServoDeclarationBlockBorrowed,
|
||||||
|
property: *mut nsIAtom, is_custom: bool) {
|
||||||
|
let declarations = RwLock::<PropertyDeclarationBlock>::as_arc(&declarations);
|
||||||
|
let property = get_property_name_from_atom(property, is_custom);
|
||||||
|
declarations.write().remove_property(&property);
|
||||||
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn Servo_CSSSupports(property: *const nsACString, value: *const nsACString) -> bool {
|
pub extern "C" fn Servo_CSSSupports(property: *const nsACString, value: *const nsACString) -> bool {
|
||||||
let property = unsafe { property.as_ref().unwrap().as_str_unchecked() };
|
let property = unsafe { property.as_ref().unwrap().as_str_unchecked() };
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue