Bug 1315601 part 5 - Implement MediaList for Stylo. r=heycam,manishearth draft
authorXidorn Quan <me@upsuper.org>
Thu, 09 Mar 2017 17:56:31 +1100
changeset 497341 63e482fa74ef1f88777d9fbe7cdc4c4cb7832666
parent 497327 cfa00f45b4ff00857956cad9094a68a22149a692
child 497342 3dc10330853b1e486be83aec6d11388c8bbe8dac
push id48869
push userxquan@mozilla.com
push dateMon, 13 Mar 2017 06:50:23 +0000
reviewersheycam, manishearth
bugs1315601
milestone55.0a1
Bug 1315601 part 5 - Implement MediaList for Stylo. r=heycam,manishearth MozReview-Commit-ID: 1NSyoqguoJr
layout/style/ServoBindingList.h
layout/style/ServoMediaList.cpp
layout/style/ServoMediaList.h
layout/style/moz.build
--- a/layout/style/ServoBindingList.h
+++ b/layout/style/ServoBindingList.h
@@ -227,16 +227,31 @@ SERVO_BINDING_FUNC(Servo_DeclarationBloc
                    nsCSSPropertyID property,
                    nscolor value)
 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_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,
+                   RawServoMediaListBorrowed list)
+SERVO_BINDING_FUNC(Servo_MediaList_GetMediumAt, bool,
+                   RawServoMediaListBorrowed list, uint32_t index,
+                   nsAString* result)
+SERVO_BINDING_FUNC(Servo_MediaList_AppendMedium, void,
+                   RawServoMediaListBorrowed list, const nsACString* new_medium)
+SERVO_BINDING_FUNC(Servo_MediaList_DeleteMedium, bool,
+                   RawServoMediaListBorrowed list, const nsACString* old_medium)
+
 // CSS supports()
 SERVO_BINDING_FUNC(Servo_CSSSupports2, bool,
                    const nsACString* name, const nsACString* value)
 SERVO_BINDING_FUNC(Servo_CSSSupports, bool,
                    const nsACString* cond)
 
 // Computed style data
 SERVO_BINDING_FUNC(Servo_ComputedValues_GetForAnonymousBox,
new file mode 100644
--- /dev/null
+++ b/layout/style/ServoMediaList.cpp
@@ -0,0 +1,71 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/* representation of media lists for servo backend */
+
+#include "mozilla/ServoMediaList.h"
+
+#include "mozilla/ServoBindings.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;
+}
+
+void
+ServoMediaList::GetText(nsAString& aMediaText)
+{
+  Servo_MediaList_GetText(mRawList, &aMediaText);
+}
+
+void
+ServoMediaList::SetText(const nsAString& aMediaText)
+{
+  NS_ConvertUTF16toUTF8 mediaText(aMediaText);
+  Servo_MediaList_SetText(mRawList, &mediaText);
+}
+
+uint32_t
+ServoMediaList::Length()
+{
+  return Servo_MediaList_GetLength(mRawList);
+}
+
+void
+ServoMediaList::IndexedGetter(uint32_t aIndex, bool& aFound,
+                              nsAString& aReturn)
+{
+  aFound = Servo_MediaList_GetMediumAt(mRawList, aIndex, &aReturn);
+}
+
+nsresult
+ServoMediaList::Append(const nsAString& aNewMedium)
+{
+  if (aNewMedium.IsEmpty()) {
+    return NS_ERROR_DOM_NOT_FOUND_ERR;
+  }
+  NS_ConvertUTF16toUTF8 newMedium(aNewMedium);
+  Servo_MediaList_AppendMedium(mRawList, &newMedium);
+  return NS_OK;
+}
+
+nsresult
+ServoMediaList::Delete(const nsAString& aOldMedium)
+{
+  NS_ConvertUTF16toUTF8 oldMedium(aOldMedium);
+  if (Servo_MediaList_DeleteMedium(mRawList, &oldMedium)) {
+    return NS_OK;
+  }
+  return NS_ERROR_DOM_NOT_FOUND_ERR;
+}
+
+} // namespace mozilla
new file mode 100644
--- /dev/null
+++ b/layout/style/ServoMediaList.h
@@ -0,0 +1,44 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/* representation of media lists for servo backend */
+
+#ifndef mozilla_ServoMediaList_h
+#define mozilla_ServoMediaList_h
+
+#include "mozilla/dom/MediaList.h"
+#include "mozilla/ServoBindingTypes.h"
+
+namespace mozilla {
+
+class ServoMediaList final : public dom::MediaList
+{
+public:
+  explicit ServoMediaList(already_AddRefed<RawServoMediaList> aRawList)
+    : mRawList(aRawList) {}
+
+  already_AddRefed<dom::MediaList> Clone() final;
+
+  void GetText(nsAString& aMediaText) final;
+  void SetText(const nsAString& aMediaText) final;
+
+  uint32_t Length() final;
+  void IndexedGetter(uint32_t aIndex, bool& aFound,
+                     nsAString& aReturn) final;
+
+protected:
+  nsresult Delete(const nsAString& aOldMedium) final;
+  nsresult Append(const nsAString& aNewMedium) final;
+
+  ~ServoMediaList() {}
+
+private:
+  RefPtr<RawServoMediaList> mRawList;
+};
+
+} // namespace mozilla
+
+#endif // mozilla_ServoMediaList_h
--- a/layout/style/moz.build
+++ b/layout/style/moz.build
@@ -97,16 +97,17 @@ EXPORTS.mozilla += [
     'RuleProcessorCache.h',
     'ServoArcTypeList.h',
     'ServoBindingList.h',
     'ServoBindings.h',
     'ServoBindingTypes.h',
     'ServoCSSRuleList.h',
     'ServoDeclarationBlock.h',
     'ServoElementSnapshot.h',
+    'ServoMediaList.h',
     'ServoPropPrefList.h',
     'ServoSpecifiedValues.h',
     'ServoStyleRule.h',
     'ServoStyleSet.h',
     'ServoStyleSheet.h',
     'ServoTypes.h',
     'ServoUtils.h',
     'SheetType.h',
@@ -206,16 +207,17 @@ UNIFIED_SOURCES += [
     'nsTransitionManager.cpp',
     'PreloadedStyleSheet.cpp',
     'RuleNodeCacheConditions.cpp',
     'RuleProcessorCache.cpp',
     'ServoBindings.cpp',
     'ServoCSSRuleList.cpp',
     'ServoDeclarationBlock.cpp',
     'ServoElementSnapshot.cpp',
+    'ServoMediaList.cpp',
     'ServoSpecifiedValues.cpp',
     'ServoStyleRule.cpp',
     'ServoStyleSet.cpp',
     'ServoStyleSheet.cpp',
     'StyleAnimationValue.cpp',
     'StyleRule.cpp',
     'StyleSheet.cpp',
     'SVGAttrAnimationRuleProcessor.cpp',