Skip to content

Commit

Permalink
Bug 1302949 - Add a method to serialize a declaration block as a sing…
Browse files Browse the repository at this point in the history
…le value; r=Manishearth

MozReview-Commit-ID: 59CCT0P4CBm
  • Loading branch information
birtles authored and Manishearth committed Oct 9, 2016
1 parent 61bcc3a commit 1c78e1c
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
6 changes: 6 additions & 0 deletions components/style/gecko_bindings/bindings.rs
Expand Up @@ -165,6 +165,7 @@ use gecko_bindings::structs::nsINode;
use gecko_bindings::structs::nsIDocument;
use gecko_bindings::structs::nsIPrincipal;
use gecko_bindings::structs::nsIURI;
use gecko_bindings::structs::nsString;
use gecko_bindings::structs::RawGeckoNode;
use gecko_bindings::structs::RawGeckoElement;
use gecko_bindings::structs::RawGeckoDocument;
Expand Down Expand Up @@ -399,6 +400,11 @@ extern "C" {
*const ::std::os::raw::c_char,
aLength: u32) -> bool;
}
extern "C" {
pub fn Gecko_Utf8SliceToString(aString: *mut nsString,
aBuffer: *const u8,
aBufferLen: usize);
}
extern "C" {
pub fn Gecko_FontFamilyList_Clear(aList: *mut FontFamilyList);
}
Expand Down
37 changes: 36 additions & 1 deletion ports/geckolib/glue.rs
Expand Up @@ -3,7 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use app_units::Au;
use cssparser::Parser;
use cssparser::{Parser, ToCss};
use env_logger;
use euclid::Size2D;
use parking_lot::RwLock;
Expand All @@ -30,11 +30,13 @@ use style::gecko_bindings::bindings::{RawServoStyleSheetStrong, ServoComputedVal
use style::gecko_bindings::bindings::{ServoDeclarationBlockBorrowed, ServoDeclarationBlockStrong};
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::RawServoStyleSetBorrowedMut;
use style::gecko_bindings::ptr::{GeckoArcPrincipal, GeckoArcURI};
use style::gecko_bindings::structs::{SheetParsingMode, nsIAtom};
use style::gecko_bindings::structs::ServoElementSnapshot;
use style::gecko_bindings::structs::nsRestyleHint;
use style::gecko_bindings::structs::nsString;
use style::gecko_bindings::sugar::ownership::{FFIArcHelpers, HasArcFFI, HasBoxFFI};
use style::gecko_bindings::sugar::ownership::{HasSimpleFFI, Strong};
use style::parallel;
Expand Down Expand Up @@ -436,6 +438,39 @@ pub extern "C" fn Servo_DeclarationBlock_ClearCachePointer(declarations: ServoDe
GeckoDeclarationBlock::as_arc(&declarations).cache.store(ptr::null_mut(), Ordering::Relaxed)
}

#[no_mangle]
pub extern "C" fn Servo_DeclarationBlock_SerializeOneValue(
declarations: ServoDeclarationBlockBorrowed,
buffer: *mut nsString)
{
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.

// 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);
}
}
}

#[no_mangle]
pub extern "C" fn Servo_CSSSupports(property: *const u8, property_length: u32,
value: *const u8, value_length: u32) -> bool {
Expand Down

0 comments on commit 1c78e1c

Please sign in to comment.