Bug 1307357 part 5 - Implement css text getters for ServoStyleRule. r?SimonSapin draft
authorXidorn Quan <me@upsuper.org>
Mon, 07 Nov 2016 17:20:04 +1100
changeset 441110 6ed9999655f03ae101eb4524c4c2ff14960b93f1
parent 441105 4b1ee8b0a5529db11f315f6765a6f61140a3eeae
child 441111 8ba19b8ec4ad81c7a58821335cc31953640dced2
push id36360
push userxquan@mozilla.com
push dateFri, 18 Nov 2016 12:08:30 +0000
reviewersSimonSapin
bugs1307357
milestone53.0a1
Bug 1307357 part 5 - Implement css text getters for ServoStyleRule. r?SimonSapin MozReview-Commit-ID: 44bKwabU4eJ
layout/style/ServoBindingList.h
layout/style/ServoStyleRule.cpp
servo/components/style/gecko_bindings/bindings.rs
servo/ports/geckolib/glue.rs
--- a/layout/style/ServoBindingList.h
+++ b/layout/style/ServoBindingList.h
@@ -53,16 +53,22 @@ SERVO_BINDING_FUNC(Servo_StyleSet_Insert
 
 // CSSRuleList
 SERVO_BINDING_FUNC(Servo_CssRules_ListTypes, void,
                    ServoCssRulesBorrowed rules,
                    nsTArrayBorrowed_uintptr_t result)
 SERVO_BINDING_FUNC(Servo_CssRules_GetStyleRuleAt, RawServoStyleRuleStrong,
                    ServoCssRulesBorrowed rules, uint32_t index)
 
+// CSS Rules
+SERVO_BINDING_FUNC(Servo_StyleRule_GetCssText, void,
+                   RawServoStyleRuleBorrowed rule, nsAString* result)
+SERVO_BINDING_FUNC(Servo_StyleRule_GetSelectorText, void,
+                   RawServoStyleRuleBorrowed rule, nsAString* result)
+
 // Animations API
 SERVO_BINDING_FUNC(Servo_ParseProperty,
                    RawServoDeclarationBlockStrong,
                    const nsACString* property, const nsACString* value,
                    const nsACString* base_url, ThreadSafeURIHolder* base,
                    ThreadSafeURIHolder* referrer,
                    ThreadSafePrincipalHolder* principal)
 SERVO_BINDING_FUNC(Servo_RestyleWithAddedDeclaration,
--- a/layout/style/ServoStyleRule.cpp
+++ b/layout/style/ServoStyleRule.cpp
@@ -3,16 +3,18 @@
 /* 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 CSSStyleRule for stylo */
 
 #include "mozilla/ServoStyleRule.h"
 
+#include "mozilla/ServoBindings.h"
+
 #include "nsDOMClassInfoID.h"
 
 namespace mozilla {
 
 // -- ServoStyleRule --------------------------------------------------
 
 // QueryInterface implementation for ServoStyleRule
 NS_INTERFACE_MAP_BEGIN(ServoStyleRule)
@@ -57,17 +59,18 @@ ServoStyleRule::GetType(uint16_t* aType)
 {
   *aType = nsIDOMCSSRule::STYLE_RULE;
   return NS_OK;
 }
 
 NS_IMETHODIMP
 ServoStyleRule::GetCssText(nsAString& aCssText)
 {
-  return NS_ERROR_NOT_IMPLEMENTED;
+  Servo_StyleRule_GetCssText(mRawRule, &aCssText);
+  return NS_OK;
 }
 
 NS_IMETHODIMP
 ServoStyleRule::SetCssText(const nsAString& aCssText)
 {
   return NS_OK;
 }
 
@@ -90,23 +93,27 @@ ServoStyleRule::GetCSSRule()
   return this;
 }
 
 /* CSSStyleRule implementation */
 
 NS_IMETHODIMP
 ServoStyleRule::GetSelectorText(nsAString& aSelectorText)
 {
-  return NS_ERROR_NOT_IMPLEMENTED;
+  Servo_StyleRule_GetSelectorText(mRawRule, &aSelectorText);
+  return NS_OK;
 }
 
 NS_IMETHODIMP
 ServoStyleRule::SetSelectorText(const nsAString& aSelectorText)
 {
-  return NS_ERROR_NOT_IMPLEMENTED;
+  // XXX We need to implement this... But Gecko doesn't have this either
+  //     so it's probably okay to leave it unimplemented currently?
+  //     See bug 37468 and mozilla::css::StyleRule::SetSelectorText.
+  return NS_OK;
 }
 
 NS_IMETHODIMP
 ServoStyleRule::GetStyle(nsIDOMCSSStyleDeclaration** aStyle)
 {
   *aStyle = nullptr;
   return NS_ERROR_NOT_IMPLEMENTED;
 }
--- a/servo/components/style/gecko_bindings/bindings.rs
+++ b/servo/components/style/gecko_bindings/bindings.rs
@@ -990,16 +990,24 @@ extern "C" {
                                                  reference:
                                                      RawServoStyleSheetBorrowed);
 }
 extern "C" {
     pub fn Servo_CssRules_ListRuleTypes(rules: ServoCssRulesBorrowed,
                                         result: nsTArrayBorrowed_uintptr_t);
 }
 extern "C" {
+    pub fn Servo_StyleRule_GetCssText(rule: RawServoStyleRuleBorrowed,
+                                      result: *mut nsAString_internal);
+}
+extern "C" {
+    pub fn Servo_StyleRule_GetSelectorText(rule: RawServoStyleRuleBorrowed,
+                                           result: *mut nsAString_internal);
+}
+extern "C" {
     pub fn Servo_ParseProperty(property: *const nsACString_internal,
                                value: *const nsACString_internal,
                                base_url: *const nsACString_internal,
                                base: *mut ThreadSafeURIHolder,
                                referrer: *mut ThreadSafeURIHolder,
                                principal: *mut ThreadSafePrincipalHolder)
      -> RawServoDeclarationBlockStrong;
 }
--- a/servo/ports/geckolib/glue.rs
+++ b/servo/ports/geckolib/glue.rs
@@ -315,16 +315,28 @@ pub extern "C" fn Servo_StyleRule_AddRef
 }
 
 #[no_mangle]
 pub extern "C" fn Servo_StyleRule_Release(rule: RawServoStyleRuleBorrowed) -> () {
     unsafe { RwLock::<StyleRule>::release(rule) };
 }
 
 #[no_mangle]
+pub extern "C" fn Servo_StyleRule_GetCssText(rule: RawServoStyleRuleBorrowed, result: *mut nsAString) -> () {
+    let rule = RwLock::<StyleRule>::as_arc(&rule);
+    rule.read().to_css(unsafe { result.as_mut().unwrap() }).unwrap();
+}
+
+#[no_mangle]
+pub extern "C" fn Servo_StyleRule_GetSelectorText(rule: RawServoStyleRuleBorrowed, result: *mut nsAString) -> () {
+    let rule = RwLock::<StyleRule>::as_arc(&rule);
+    rule.read().selectors_to_css(unsafe { result.as_mut().unwrap() }).unwrap();
+}
+
+#[no_mangle]
 pub extern "C" fn Servo_ComputedValues_Get(node: RawGeckoNodeBorrowed)
      -> ServoComputedValuesStrong {
     let node = GeckoNode(node);
 
     // Gecko erroneously calls this function from ServoRestyleManager::RecreateStyleContexts.
     // We plan to fix that, but just support it for now until that code gets rewritten.
     if node.is_text_node() {
         error!("Don't call Servo_ComputedValue_Get() for text nodes");