Remove the extra level of GeckoDeclarationBlock.

This commit is contained in:
Xidorn Quan 2016-10-18 15:53:41 +11:00
parent f967647226
commit 0b5c6fb701
4 changed files with 64 additions and 148 deletions

View file

@ -8,11 +8,9 @@ use env_logger;
use euclid::Size2D;
use parking_lot::RwLock;
use std::mem::transmute;
use std::ptr;
use std::slice;
use std::str::from_utf8_unchecked;
use std::sync::{Arc, Mutex};
use std::sync::atomic::{AtomicBool, AtomicPtr, Ordering};
use style::arc_ptr_eq;
use style::context::{LocalStyleContextCreationInfo, ReflowGoal, SharedStyleContext};
use style::dom::{NodeInfo, TElement, TNode};
@ -21,16 +19,16 @@ use style::gecko::data::{NUM_THREADS, PerDocumentStyleData};
use style::gecko::selector_impl::{GeckoSelectorImpl, PseudoElement};
use style::gecko::snapshot::GeckoElementSnapshot;
use style::gecko::traversal::RecalcStyleOnly;
use style::gecko::wrapper::{DUMMY_BASE_URL, GeckoDeclarationBlock};
use style::gecko::wrapper::{GeckoElement, GeckoNode};
use style::gecko::wrapper::DUMMY_BASE_URL;
use style::gecko_bindings::bindings::{RawGeckoElementBorrowed, RawGeckoNodeBorrowed};
use style::gecko_bindings::bindings::{RawServoDeclarationBlockBorrowed, RawServoDeclarationBlockStrong};
use style::gecko_bindings::bindings::{RawServoStyleSetBorrowed, RawServoStyleSetOwned};
use style::gecko_bindings::bindings::{RawServoStyleSheetBorrowed, ServoComputedValuesBorrowed};
use style::gecko_bindings::bindings::{RawServoStyleSheetStrong, ServoComputedValuesStrong};
use style::gecko_bindings::bindings::{ThreadSafePrincipalHolder, ThreadSafeURIHolder};
use style::gecko_bindings::bindings::{nsHTMLCSSStyleSheet, ServoComputedValuesBorrowedOrNull};
use style::gecko_bindings::bindings::Gecko_Utf8SliceToString;
use style::gecko_bindings::bindings::ServoComputedValuesBorrowedOrNull;
use style::gecko_bindings::structs::{SheetParsingMode, nsIAtom};
use style::gecko_bindings::structs::ServoElementSnapshot;
use style::gecko_bindings::structs::nsRestyleHint;
@ -131,28 +129,24 @@ pub extern "C" fn Servo_RestyleWithAddedDeclaration(declarations: RawServoDeclar
previous_style: ServoComputedValuesBorrowed)
-> ServoComputedValuesStrong
{
match GeckoDeclarationBlock::as_arc(&declarations).declarations {
Some(ref declarations) => {
let declaration_block = ApplicableDeclarationBlock {
mixed_declarations: declarations.clone(),
importance: Importance::Normal,
source_order: 0,
specificity: ::std::u32::MAX,
};
let previous_style = ComputedValues::as_arc(&previous_style);
let declarations = RwLock::<PropertyDeclarationBlock>::as_arc(&declarations);
let declaration_block = ApplicableDeclarationBlock {
mixed_declarations: declarations.clone(),
importance: Importance::Normal,
source_order: 0,
specificity: ::std::u32::MAX,
};
let previous_style = ComputedValues::as_arc(&previous_style);
// FIXME (bug 1303229): Use the actual viewport size here
let (computed, _) = cascade(Size2D::new(Au(0), Au(0)),
&[declaration_block],
false,
Some(previous_style),
None,
None,
Box::new(StdoutErrorReporter));
Arc::new(computed).into_strong()
},
None => ServoComputedValuesStrong::null(),
}
// FIXME (bug 1303229): Use the actual viewport size here
let (computed, _) = cascade(Size2D::new(Au(0), Au(0)),
&[declaration_block],
false,
Some(previous_style),
None,
None,
Box::new(StdoutErrorReporter));
Arc::new(computed).into_strong()
}
#[no_mangle]
@ -409,60 +403,34 @@ pub extern "C" fn Servo_ParseProperty(property_bytes: *const u8,
let results = results.into_iter().map(|r| (r, Importance::Normal)).collect();
Arc::new(GeckoDeclarationBlock {
declarations: Some(Arc::new(RwLock::new(PropertyDeclarationBlock {
declarations: results,
important_count: 0,
}))),
cache: AtomicPtr::new(ptr::null_mut()),
immutable: AtomicBool::new(false),
}).into_strong()
Arc::new(RwLock::new(PropertyDeclarationBlock {
declarations: results,
important_count: 0,
})).into_strong()
}
#[no_mangle]
pub extern "C" fn Servo_ParseStyleAttribute(bytes: *const u8, length: u32,
cache: *mut nsHTMLCSSStyleSheet)
pub extern "C" fn Servo_ParseStyleAttribute(bytes: *const u8, length: u32)
-> RawServoDeclarationBlockStrong {
let value = unsafe { from_utf8_unchecked(slice::from_raw_parts(bytes, length as usize)) };
Arc::new(GeckoDeclarationBlock {
declarations: GeckoElement::parse_style_attribute(value).map(|block| {
Arc::new(RwLock::new(block))
}),
cache: AtomicPtr::new(cache),
immutable: AtomicBool::new(false),
}).into_strong()
Arc::new(RwLock::new(GeckoElement::parse_style_attribute(value))).into_strong()
}
#[no_mangle]
pub extern "C" fn Servo_DeclarationBlock_AddRef(declarations: RawServoDeclarationBlockBorrowed) {
unsafe { GeckoDeclarationBlock::addref(declarations) };
unsafe { RwLock::<PropertyDeclarationBlock>::addref(declarations) };
}
#[no_mangle]
pub extern "C" fn Servo_DeclarationBlock_Release(declarations: RawServoDeclarationBlockBorrowed) {
unsafe { GeckoDeclarationBlock::release(declarations) };
unsafe { RwLock::<PropertyDeclarationBlock>::release(declarations) };
}
#[no_mangle]
pub extern "C" fn Servo_DeclarationBlock_Equals(a: RawServoDeclarationBlockBorrowed,
b: RawServoDeclarationBlockBorrowed)
-> bool {
GeckoDeclarationBlock::as_arc(&a) == GeckoDeclarationBlock::as_arc(&b)
}
#[no_mangle]
pub extern "C" fn Servo_DeclarationBlock_GetCache(declarations: RawServoDeclarationBlockBorrowed)
-> *mut nsHTMLCSSStyleSheet {
GeckoDeclarationBlock::as_arc(&declarations).cache.load(Ordering::Relaxed)
}
#[no_mangle]
pub extern "C" fn Servo_DeclarationBlock_SetImmutable(declarations: RawServoDeclarationBlockBorrowed) {
GeckoDeclarationBlock::as_arc(&declarations).immutable.store(true, Ordering::Relaxed)
}
#[no_mangle]
pub extern "C" fn Servo_DeclarationBlock_ClearCachePointer(declarations: RawServoDeclarationBlockBorrowed) {
GeckoDeclarationBlock::as_arc(&declarations).cache.store(ptr::null_mut(), Ordering::Relaxed)
*RwLock::<PropertyDeclarationBlock>::as_arc(&a).read() == *RwLock::<PropertyDeclarationBlock>::as_arc(&b).read()
}
#[no_mangle]
@ -472,29 +440,28 @@ pub extern "C" fn Servo_DeclarationBlock_SerializeOneValue(
{
let mut string = String::new();
if let Some(ref declarations) = GeckoDeclarationBlock::as_arc(&declarations).declarations {
declarations.read().to_css(&mut string).unwrap();
// FIXME: We are expecting |declarations| to be a declaration block with either a single
// longhand property-declaration or a series of longhand property-declarations that make
// up a single shorthand property. As a result, it should be possible to serialize
// |declarations| as a single declaration. However, we only want to return the *value* from
// that single declaration. For now, we just manually strip the property name, colon,
// leading spacing, and trailing space. In future we should find a more robust way to do
// this.
//
// See https://github.com/servo/servo/issues/13423
debug_assert!(string.find(':').is_some());
let position = string.find(':').unwrap();
// Get the value after the first colon and any following whitespace.
let value = &string[(position + 1)..].trim_left();
debug_assert!(value.ends_with(';'));
let length = value.len() - 1; // Strip last semicolon.
let declarations = RwLock::<PropertyDeclarationBlock>::as_arc(&declarations);
declarations.read().to_css(&mut string).unwrap();
// FIXME: We are expecting |declarations| to be a declaration block with either a single
// longhand property-declaration or a series of longhand property-declarations that make
// up a single shorthand property. As a result, it should be possible to serialize
// |declarations| as a single declaration. However, we only want to return the *value* from
// that single declaration. For now, we just manually strip the property name, colon,
// leading spacing, and trailing space. In future we should find a more robust way to do
// this.
//
// See https://github.com/servo/servo/issues/13423
debug_assert!(string.find(':').is_some());
let position = string.find(':').unwrap();
// Get the value after the first colon and any following whitespace.
let value = &string[(position + 1)..].trim_left();
debug_assert!(value.ends_with(';'));
let length = value.len() - 1; // Strip last semicolon.
// FIXME: Once we have nsString bindings for Servo (bug 1294742), we should be able to drop
// this and fill in |buffer| directly.
unsafe {
Gecko_Utf8SliceToString(buffer, value.as_ptr(), length);
}
// FIXME: Once we have nsString bindings for Servo (bug 1294742), we should be able to drop
// this and fill in |buffer| directly.
unsafe {
Gecko_Utf8SliceToString(buffer, value.as_ptr(), length);
}
}