Bug 1317178 - [Servo] Use single_value_to_css in Servo_DeclarationBlock_SerializeOneValue. draft
authorBoris Chiou <boris.chiou@gmail.com>
Tue, 22 Nov 2016 19:20:00 +0800
changeset 443269 c14d7c8536a08297b84dc33443ee4e305af5c9eb
parent 443268 4b80cf00f959d8b6eb28931a06933ad27980f55b
child 538009 eb7a8d5425094859f1cc5bf6d249a7dc6ce6aa26
push id36944
push userbmo:boris.chiou@gmail.com
push dateThu, 24 Nov 2016 05:19:37 +0000
bugs1317178
milestone53.0a1
Bug 1317178 - [Servo] Use single_value_to_css in Servo_DeclarationBlock_SerializeOneValue.
servo/ports/geckolib/glue.rs
--- a/servo/ports/geckolib/glue.rs
+++ b/servo/ports/geckolib/glue.rs
@@ -563,42 +563,29 @@ pub extern "C" fn Servo_DeclarationBlock
                                                     result: *mut nsAString) {
     let declarations = RwLock::<PropertyDeclarationBlock>::as_arc(&declarations);
     declarations.read().to_css(unsafe { result.as_mut().unwrap() }).unwrap();
 }
 
 #[no_mangle]
 pub extern "C" fn Servo_DeclarationBlock_SerializeOneValue(
     declarations: RawServoDeclarationBlockBorrowed,
+    property: *mut nsIAtom, is_custom: bool,
     buffer: *mut nsString)
 {
+    let declarations = RwLock::<PropertyDeclarationBlock>::as_arc(&declarations);
+    let property = get_property_name_from_atom(property, is_custom);
     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 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());
     }
 }
 
 #[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
 }