void CSSStyleRule::setSelectorText(const String& selectorText)
{
    Document* doc = 0;
    StyleSheet* ownerStyleSheet = m_style->stylesheet();
    if (ownerStyleSheet) {
        if (ownerStyleSheet->isCSSStyleSheet())
            doc = static_cast<CSSStyleSheet*>(ownerStyleSheet)->document();
        if (!doc)
            doc = ownerStyleSheet->ownerNode() ? ownerStyleSheet->ownerNode()->document() : 0;
    }
    if (!doc)
        doc = m_style->node() ? m_style->node()->document() : 0;

    if (!doc)
        return;

    CSSParser p;
    CSSSelectorList selectorList;
    p.parseSelector(selectorText, doc, selectorList);
    if (!selectorList.first())
        return;

    String oldSelectorText = this->selectorText();
    m_selectorList.adopt(selectorList);
    if (this->selectorText() == oldSelectorText)
        return;

    doc->styleSelectorChanged(DeferRecalcStyle);
}
static GroupId calculateGroupId(StyleBase* styleBase)
{
    ASSERT(styleBase);
    StyleBase* current = styleBase;
    StyleSheet* styleSheet = 0;
    while (true) {
        // Special case: CSSStyleDeclarations might be either inline and in this case
        // we need to group them with their node or regular ones.
        if (current->isMutableStyleDeclaration()) {
            CSSMutableStyleDeclaration* cssMutableStyleDeclaration = static_cast<CSSMutableStyleDeclaration*>(current);
            if (cssMutableStyleDeclaration->isInlineStyleDeclaration()) {
                ASSERT(cssMutableStyleDeclaration->parent()->isStyleSheet());
                return calculateGroupId(cssMutableStyleDeclaration->node());
            }
            // Either we have no parent, or this parent is a CSSRule.
            ASSERT(cssMutableStyleDeclaration->parent() == cssMutableStyleDeclaration->parentRule());
        }

        if (current->isStyleSheet())
            styleSheet = static_cast<StyleSheet*>(current);

        StyleBase* parent = current->parent();
        if (!parent)
            break;
        current = parent;
    }

    if (styleSheet) {
        if (Node* ownerNode = styleSheet->ownerNode())
            return calculateGroupId(ownerNode);
        return GroupId(styleSheet);
    }

    return GroupId(current);
}
示例#3
0
KURL StyleBase::baseURL() const
{
    // Try to find the style sheet. If found look for its URL.
    // If it has none, get the URL from the parent sheet or the parent node.

    StyleSheet* sheet = const_cast<StyleBase*>(this)->stylesheet();
    if (!sheet)
        return KURL();
    if (!sheet->href().isNull())
        return KURL(sheet->href());
    if (sheet->parent()) 
        return sheet->parent()->baseURL();
    if (!sheet->ownerNode()) 
        return KURL();
    return sheet->ownerNode()->document()->baseURL();
}
void* V8StyleSheet::opaqueRootForGC(void* object, v8::Persistent<v8::Object> wrapper)
{
    ASSERT(!wrapper.IsIndependent());
    StyleSheet* impl = static_cast<StyleSheet*>(object);
    if (Node* owner = impl->ownerNode())
        return V8GCController::opaqueRootForGC(owner);
    return object;
}
void JSStyleSheet::markChildren(MarkStack& markStack)
{
    Base::markChildren(markStack);

    StyleSheet* sheet = impl();
    JSGlobalData& globalData = *Heap::heap(this)->globalData();

    unsigned length = sheet->length();
    for (unsigned i = 0; i < length; ++i)
        markDOMObjectWrapper(markStack, globalData, sheet->item(i));

    // This prevents us from having a style sheet with a dangling ownerNode pointer.
    // A better solution would be to handle this on the DOM side -- if the style sheet
    // is kept around, then we want the node to stay around too. One possibility would
    // be to make ref/deref on the style sheet ref/deref the node instead, but there's
    // a lot of disentangling of the CSS DOM objects that would need to happen first.
    if (Node* ownerNode = sheet->ownerNode())
        markDOMNodeWrapper(markStack, ownerNode->document(), ownerNode);
}
示例#6
0
JSValue* JSStyleSheet::getValueProperty(ExecState* exec, int token) const
{
    switch (token) {
    case TypeAttrNum: {
        StyleSheet* imp = static_cast<StyleSheet*>(impl());
        return jsStringOrNull(exec, imp->type());
    }
    case DisabledAttrNum: {
        StyleSheet* imp = static_cast<StyleSheet*>(impl());
        return jsBoolean(imp->disabled());
    }
    case OwnerNodeAttrNum: {
        StyleSheet* imp = static_cast<StyleSheet*>(impl());
        return toJS(exec, WTF::getPtr(imp->ownerNode()));
    }
    case ParentStyleSheetAttrNum: {
        StyleSheet* imp = static_cast<StyleSheet*>(impl());
        return toJS(exec, WTF::getPtr(imp->parentStyleSheet()));
    }
    case HrefAttrNum: {
        StyleSheet* imp = static_cast<StyleSheet*>(impl());
        return jsStringOrNull(exec, imp->href());
    }
    case TitleAttrNum: {
        StyleSheet* imp = static_cast<StyleSheet*>(impl());
        return jsStringOrNull(exec, imp->title());
    }
    case MediaAttrNum: {
        StyleSheet* imp = static_cast<StyleSheet*>(impl());
        return toJS(exec, WTF::getPtr(imp->media()));
    }
    case ConstructorAttrNum:
        return getConstructor(exec);
    }
    return 0;
}
static v8::Handle<v8::Value> ownerNodeAttrGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
{
    INC_STATS("DOM.StyleSheet.ownerNode._get");
    StyleSheet* imp = V8StyleSheet::toNative(info.Holder());
    return toV8(imp->ownerNode());
}
static v8::Handle<v8::Value> ownerNodeAttrGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
{
    StyleSheet* imp = V8StyleSheet::toNative(info.Holder());
    return toV8Fast(imp->ownerNode(), info, imp);
}