Bug 1325878: Support deep-cloning of ServoMediaLists. r?xidorn draft
authorEmilio Cobos Álvarez <emilio@crisal.io>
Mon, 10 Apr 2017 14:36:45 +0800
changeset 561041 58835e9c2d6de1041c6dfaf86e75379e3557c4f5
parent 561040 bf60fc0d3eede29edf080c383a057a5eb1af170e
child 561042 e0a002731fb565a797dd5028df0f5fd2671d7684
push id53604
push userbmo:emilio+bugs@crisal.io
push dateWed, 12 Apr 2017 05:05:04 +0000
reviewersxidorn
bugs1325878
milestone55.0a1
Bug 1325878: Support deep-cloning of ServoMediaLists. r?xidorn MozReview-Commit-ID: K7NFe1tKrAZ
layout/style/ServoBindingList.h
layout/style/ServoMediaList.cpp
servo/components/style/media_queries.rs
servo/ports/geckolib/glue.rs
--- a/layout/style/ServoBindingList.h
+++ b/layout/style/ServoBindingList.h
@@ -257,16 +257,18 @@ SERVO_BINDING_FUNC(Servo_DeclarationBloc
 SERVO_BINDING_FUNC(Servo_DeclarationBlock_SetFontFamily, void,
                    RawServoDeclarationBlockBorrowed declarations,
                    const nsAString& value)
 SERVO_BINDING_FUNC(Servo_DeclarationBlock_SetTextDecorationColorOverride, void,
                    RawServoDeclarationBlockBorrowed declarations)
 
 // MediaList
 SERVO_BINDING_FUNC(Servo_MediaList_Create, RawServoMediaListStrong)
+SERVO_BINDING_FUNC(Servo_MediaList_DeepClone, RawServoMediaListStrong,
+                   RawServoMediaListBorrowed list)
 SERVO_BINDING_FUNC(Servo_MediaList_Matches, bool,
                    RawServoMediaListBorrowed list,
                    RawServoStyleSetBorrowed set)
 SERVO_BINDING_FUNC(Servo_MediaList_GetText, void,
                    RawServoMediaListBorrowed list, nsAString* result)
 SERVO_BINDING_FUNC(Servo_MediaList_SetText, void,
                    RawServoMediaListBorrowed list, const nsACString* text)
 SERVO_BINDING_FUNC(Servo_MediaList_GetLength, uint32_t,
--- a/layout/style/ServoMediaList.cpp
+++ b/layout/style/ServoMediaList.cpp
@@ -11,20 +11,19 @@
 #include "mozilla/ServoBindings.h"
 #include "mozilla/ServoStyleSet.h"
 
 namespace mozilla {
 
 already_AddRefed<dom::MediaList>
 ServoMediaList::Clone()
 {
-  // Currently MediaList::Clone() is only called from CSSStyleSheet's
-  // constructor, so we don't need to support it at the moment.
-  MOZ_ASSERT_UNREACHABLE("stylo: ServoMediaList doesn't support clone");
-  return nullptr;
+  RefPtr<ServoMediaList> clone =
+    new ServoMediaList(Servo_MediaList_DeepClone(mRawList).Consume());
+  return clone.forget();
 }
 
 ServoMediaList::ServoMediaList()
   : mRawList(Servo_MediaList_Create().Consume())
 {
 }
 
 ServoMediaList::ServoMediaList(const nsAString& aMedia)
--- a/servo/components/style/media_queries.rs
+++ b/servo/components/style/media_queries.rs
@@ -14,17 +14,17 @@ use std::fmt;
 use style_traits::ToCss;
 
 #[cfg(feature = "servo")]
 pub use servo::media_queries::{Device, Expression};
 #[cfg(feature = "gecko")]
 pub use gecko::media_queries::{Device, Expression};
 
 /// A type that encapsulates a media query list.
-#[derive(Debug)]
+#[derive(Debug, Clone)]
 #[cfg_attr(feature = "servo", derive(HeapSizeOf))]
 pub struct MediaList {
     /// The list of media queries.
     pub media_queries: Vec<MediaQuery>
 }
 
 impl ToCss for MediaList {
     fn to_css<W>(&self, dest: &mut W) -> fmt::Result
--- a/servo/ports/geckolib/glue.rs
+++ b/servo/ports/geckolib/glue.rs
@@ -1152,22 +1152,30 @@ pub extern "C" fn Servo_DeclarationBlock
 #[no_mangle]
 pub extern "C" fn Servo_DeclarationBlock_RemovePropertyById(declarations: RawServoDeclarationBlockBorrowed,
                                                             property: nsCSSPropertyID) {
     remove_property(declarations, get_property_id_from_nscsspropertyid!(property, ()))
 }
 
 #[no_mangle]
 pub extern "C" fn Servo_MediaList_Create() -> RawServoMediaListStrong {
-
     let global_style_data = &*GLOBAL_STYLE_DATA;
     Arc::new(global_style_data.shared_lock.wrap(MediaList::default())).into_strong()
 }
 
 #[no_mangle]
+pub extern "C" fn Servo_MediaList_DeepClone(list: RawServoMediaListBorrowed) -> RawServoMediaListStrong {
+    let global_style_data = &*GLOBAL_STYLE_DATA;
+    read_locked_arc(list, |list: &MediaList| {
+        Arc::new(global_style_data.shared_lock.wrap(list.clone()))
+            .into_strong()
+    })
+}
+
+#[no_mangle]
 pub extern "C" fn Servo_MediaList_Matches(list: RawServoMediaListBorrowed,
                                           raw_data: RawServoStyleSetBorrowed)
                                           -> bool {
     let per_doc_data = PerDocumentStyleData::from_ffi(raw_data).borrow();
     read_locked_arc(list, |list: &MediaList| {
         list.evaluate(&per_doc_data.stylist.device)
     })
 }