mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
Auto merge of #14357 - BorisChiou:Bug1317178, r=emilio
Use single_value_to_css in Servo_DeclarationBlock_SerializeOneValue These are the servo-side changes for [bug 1317178](https://bugzilla.mozilla.org/show_bug.cgi?id=1317178). @Manishearth has already reviewed them there. Please merge these patches until the gecko-side changes for [bug 1317178](https://bugzilla.mozilla.org/show_bug.cgi?id=1317178) is landed. --- - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix [bug 1317178](https://bugzilla.mozilla.org/show_bug.cgi?id=1317178). - [X] These changes do not require tests because there are existing tests for this in mozilla-central <!-- 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/14357) <!-- Reviewable:end -->
This commit is contained in:
commit
67a4ecd68e
2 changed files with 8 additions and 19 deletions
|
@ -1073,6 +1073,8 @@ extern "C" {
|
|||
extern "C" {
|
||||
pub fn Servo_DeclarationBlock_SerializeOneValue(declarations:
|
||||
RawServoDeclarationBlockBorrowed,
|
||||
property: *mut nsIAtom,
|
||||
is_custom: bool,
|
||||
buffer: *mut nsString);
|
||||
}
|
||||
extern "C" {
|
||||
|
|
|
@ -568,32 +568,19 @@ pub extern "C" fn Servo_DeclarationBlock_GetCssText(declarations: RawServoDeclar
|
|||
#[no_mangle]
|
||||
pub extern "C" fn Servo_DeclarationBlock_SerializeOneValue(
|
||||
declarations: RawServoDeclarationBlockBorrowed,
|
||||
property: *mut nsIAtom, is_custom: bool,
|
||||
buffer: *mut nsString)
|
||||
{
|
||||
let mut string = String::new();
|
||||
|
||||
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.
|
||||
let property = get_property_name_from_atom(property, is_custom);
|
||||
let mut string = String::new();
|
||||
let rv = declarations.read().single_value_to_css(&property, &mut string);
|
||||
debug_assert!(rv.is_ok());
|
||||
|
||||
// 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);
|
||||
Gecko_Utf8SliceToString(buffer, string.as_ptr(), string.len());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue