зеркало из https://github.com/mozilla/gecko-dev.git
Bug 37468 - Implement ServoStyleRule::SetSelectorText method for setting CSS rule selectorText from JS. r=xidorn
--HG-- extra : source : bd0a3fdb037c308ae7eab0be3c68d00fcb9b6056
This commit is contained in:
Родитель
4b2644bf85
Коммит
97ece751a4
|
@ -289,6 +289,9 @@ SERVO_BINDING_FUNC(Servo_StyleRule_GetSelectorCount, void,
|
|||
SERVO_BINDING_FUNC(Servo_StyleRule_SelectorMatchesElement, bool,
|
||||
RawServoStyleRuleBorrowed, RawGeckoElementBorrowed,
|
||||
uint32_t index, mozilla::CSSPseudoElementType pseudo_type)
|
||||
SERVO_BINDING_FUNC(Servo_StyleRule_SetSelectorText, bool,
|
||||
RawServoStyleSheetContentsBorrowed sheet,
|
||||
RawServoStyleRuleBorrowed rule, const nsAString* text)
|
||||
SERVO_BINDING_FUNC(Servo_ImportRule_GetHref, void,
|
||||
RawServoImportRuleBorrowed rule, nsAString* result)
|
||||
SERVO_BINDING_FUNC(Servo_ImportRule_GetSheet,
|
||||
|
|
|
@ -206,9 +206,23 @@ ServoStyleRule::GetSelectorText(nsAString& aSelectorText)
|
|||
void
|
||||
ServoStyleRule::SetSelectorText(const nsAString& aSelectorText)
|
||||
{
|
||||
// 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.
|
||||
if (RefPtr<StyleSheet> sheet = GetStyleSheet()) {
|
||||
ServoStyleSheet* servoSheet = sheet->AsServo();
|
||||
nsIDocument* doc = sheet->GetAssociatedDocument();
|
||||
|
||||
mozAutoDocUpdate updateBatch(doc, UPDATE_STYLE, true);
|
||||
|
||||
// StyleRule lives inside of the Inner, it is unsafe to call WillDirty
|
||||
// if sheet does not already have a unique Inner.
|
||||
sheet->AssertHasUniqueInner();
|
||||
sheet->WillDirty();
|
||||
|
||||
const RawServoStyleSheetContents* contents = servoSheet->RawContents();
|
||||
if (Servo_StyleRule_SetSelectorText(contents, mRawRule, &aSelectorText)) {
|
||||
sheet->DidDirty();
|
||||
sheet->RuleChanged(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include "mozilla/ServoUtils.h"
|
||||
#include "nsICSSLoaderObserver.h"
|
||||
#include "nsWrapperCache.h"
|
||||
#include "StyleSheetInfo.h"
|
||||
|
||||
class nsIDocument;
|
||||
class nsINode;
|
||||
|
@ -149,6 +150,7 @@ public:
|
|||
|
||||
inline bool HasUniqueInner() const;
|
||||
void EnsureUniqueInner();
|
||||
inline void AssertHasUniqueInner() const;
|
||||
|
||||
// Append all of this sheet's child sheets to aArray.
|
||||
void AppendAllChildSheets(nsTArray<StyleSheet*>& aArray);
|
||||
|
|
|
@ -133,6 +133,12 @@ StyleSheet::HasUniqueInner() const
|
|||
{
|
||||
return mInner->mSheets.Length() == 1;
|
||||
}
|
||||
|
||||
void
|
||||
StyleSheet::AssertHasUniqueInner() const
|
||||
{
|
||||
MOZ_ASSERT(HasUniqueInner());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ use cssparser::{ParseErrorKind, Parser, ParserInput, SourceLocation};
|
|||
use cssparser::ToCss as ParserToCss;
|
||||
use env_logger::Builder;
|
||||
use malloc_size_of::MallocSizeOfOps;
|
||||
use selectors::NthIndexCache;
|
||||
use selectors::{NthIndexCache, SelectorList};
|
||||
use selectors::matching::{MatchingContext, MatchingMode, matches_selector};
|
||||
use servo_arc::{Arc, ArcBorrow, RawOffsetArc};
|
||||
use smallvec::SmallVec;
|
||||
|
@ -1902,6 +1902,37 @@ pub extern "C" fn Servo_StyleRule_SelectorMatchesElement(
|
|||
})
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn Servo_StyleRule_SetSelectorText(
|
||||
sheet: RawServoStyleSheetContentsBorrowed,
|
||||
rule: RawServoStyleRuleBorrowed,
|
||||
text: *const nsAString,
|
||||
) -> bool {
|
||||
let value_str = (*text).to_string();
|
||||
|
||||
write_locked_arc(rule, |rule: &mut StyleRule| {
|
||||
use style::selector_parser::SelectorParser;
|
||||
|
||||
let contents = StylesheetContents::as_arc(&sheet);
|
||||
let namespaces = contents.namespaces.read();
|
||||
let url_data = contents.url_data.read();
|
||||
let parser = SelectorParser {
|
||||
stylesheet_origin: contents.origin,
|
||||
namespaces: &namespaces,
|
||||
url_data: Some(&url_data),
|
||||
};
|
||||
|
||||
let mut parser_input = ParserInput::new(&value_str);
|
||||
match SelectorList::parse(&parser, &mut Parser::new(&mut parser_input)) {
|
||||
Ok(selectors) => {
|
||||
rule.selectors = selectors;
|
||||
true
|
||||
}
|
||||
Err(_) => false,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn Servo_SelectorList_Closest(
|
||||
element: RawGeckoElementBorrowed,
|
||||
|
|
Загрузка…
Ссылка в новой задаче