Bug 1325878: Support deep-cloning of ServoMediaLists. r?xidorn
MozReview-Commit-ID: K7NFe1tKrAZ
--- 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)
})
}