CSSStyleSheet* InspectorCSSStore::inspectorStyleSheet(Document* ownerDocument, bool createIfAbsent, long callId) { DocumentToStyleSheetMap::iterator it = m_documentNodeToInspectorStyleSheetMap.find(ownerDocument); if (it != m_documentNodeToInspectorStyleSheetMap.end()) return it->second.get(); if (!createIfAbsent) return 0; ExceptionCode ec = 0; RefPtr<Element> styleElement = ownerDocument->createElement("style", ec); if (!ec) styleElement->setAttribute("type", "text/css", ec); if (!ec) ownerDocument->head()->appendChild(styleElement, ec); if (ec) { m_inspectorController->inspectorFrontend()->didAddRule(callId, ScriptValue::undefined(), false); return 0; } StyleSheetList* styleSheets = ownerDocument->styleSheets(); StyleSheet* styleSheet = styleSheets->item(styleSheets->length() - 1); if (!styleSheet->isCSSStyleSheet()) { m_inspectorController->inspectorFrontend()->didAddRule(callId, ScriptValue::undefined(), false); return 0; } CSSStyleSheet* inspectorStyleSheet = static_cast<CSSStyleSheet*>(styleSheet); m_documentNodeToInspectorStyleSheetMap.set(ownerDocument, inspectorStyleSheet); return inspectorStyleSheet; }
JSValue jsStyleSheetListLength(ExecState* exec, JSValue slotBase, const Identifier&) { JSStyleSheetList* castedThis = static_cast<JSStyleSheetList*>(asObject(slotBase)); UNUSED_PARAM(exec); StyleSheetList* imp = static_cast<StyleSheetList*>(castedThis->impl()); JSValue result = jsNumber(imp->length()); return result; }
void visitDOMWrapper(DOMDataStore* store, void* object, v8::Persistent<v8::Object> wrapper) { WrapperTypeInfo* typeInfo = V8DOMWrapper::domWrapperType(wrapper); if (typeInfo->isSubclass(&V8StyleSheetList::info)) { StyleSheetList* styleSheetList = static_cast<StyleSheetList*>(object); GroupId groupId(styleSheetList); if (Document* document = styleSheetList->document()) groupId = GroupId(document); m_grouper.append(GrouperItem(groupId, wrapper)); } else if (typeInfo->isSubclass(&V8DOMImplementation::info)) { DOMImplementation* domImplementation = static_cast<DOMImplementation*>(object); GroupId groupId(domImplementation); if (Document* document = domImplementation->document()) groupId = GroupId(document); m_grouper.append(GrouperItem(groupId, wrapper)); } else if (typeInfo->isSubclass(&V8StyleSheet::info) || typeInfo->isSubclass(&V8CSSRule::info)) { m_grouper.append(GrouperItem(calculateGroupId(static_cast<StyleBase*>(object)), wrapper)); #if 0 //CMP_ERROR_UNCLEAR CSSMutableStyleDeclaration } else if (typeInfo->isSubclass(&V8CSSStyleDeclaration::info)) { CSSStyleDeclaration* cssStyleDeclaration = static_cast<CSSStyleDeclaration*>(object); GroupId groupId = calculateGroupId(cssStyleDeclaration); m_grouper.append(GrouperItem(groupId, wrapper)); // Keep alive "dirty" primitive values (i.e. the ones that // have user-added properties) by creating implicit // references between the style declaration and the values // in it. if (cssStyleDeclaration->isMutableStyleDeclaration()) { CSSMutableStyleDeclaration* cssMutableStyleDeclaration = static_cast<CSSMutableStyleDeclaration*>(cssStyleDeclaration); Vector<v8::Persistent<v8::Value> > values; values.reserveCapacity(cssMutableStyleDeclaration->length()); CSSMutableStyleDeclaration::const_iterator end = cssMutableStyleDeclaration->end(); for (CSSMutableStyleDeclaration::const_iterator it = cssMutableStyleDeclaration->begin(); it != end; ++it) { v8::Persistent<v8::Object> value = store->domObjectMap().get(it->value()); if (!value.IsEmpty() && value->IsDirty()) values.append(value); } if (!values.isEmpty()) v8::V8::AddImplicitReferences(wrapper, values.data(), values.size()); } } else if (typeInfo->isSubclass(&V8CSSRuleList::info)) { CSSRuleList* cssRuleList = static_cast<CSSRuleList*>(object); GroupId groupId(cssRuleList); StyleList* styleList = cssRuleList->styleList(); if (styleList) groupId = calculateGroupId(styleList); m_grouper.append(GrouperItem(groupId, wrapper)); #endif } }
void JSStyleSheetList::markChildren(MarkStack& markStack) { Base::markChildren(markStack); StyleSheetList* list = impl(); JSGlobalData& globalData = *Heap::heap(this)->globalData(); unsigned length = list->length(); for (unsigned i = 0; i < length; ++i) markDOMObjectWrapper(markStack, globalData, list->item(i)); }
JSValue* jsStyleSheetListPrototypeFunctionItem(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) { if (!thisValue->isObject(&JSStyleSheetList::s_info)) return throwError(exec, TypeError); JSStyleSheetList* castedThisObj = static_cast<JSStyleSheetList*>(thisValue); StyleSheetList* imp = static_cast<StyleSheetList*>(castedThisObj->impl()); unsigned index = args[0]->toInt32(exec); KJS::JSValue* result = toJS(exec, WTF::getPtr(imp->item(index))); return result; }
JSValue* JSStyleSheetList::getValueProperty(ExecState* exec, int token) const { switch (token) { case LengthAttrNum: { StyleSheetList* imp = static_cast<StyleSheetList*>(impl()); return jsNumber(exec, imp->length()); } case ConstructorAttrNum: return getConstructor(exec); } return 0; }
void InspectorCSSAgent::getAllStyles(RefPtr<InspectorArray>* styles) { Vector<Document*> documents = m_domAgent->documents(); for (Vector<Document*>::iterator it = documents.begin(); it != documents.end(); ++it) { StyleSheetList* list = (*it)->styleSheets(); for (unsigned i = 0; i < list->length(); ++i) { StyleSheet* styleSheet = list->item(i); if (styleSheet->isCSSStyleSheet()) { InspectorStyleSheet* inspectorStyleSheet = bindStyleSheet(static_cast<CSSStyleSheet*>(styleSheet)); (*styles)->pushString(inspectorStyleSheet->id()); } } } }
v8::Handle<v8::Value> V8StyleSheetList::namedPropertyGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) { INC_STATS("DOM.StyleSheetList.NamedPropertyGetter"); if (info.Holder()->HasRealNamedProperty(name)) return v8Undefined(); // Search style sheet. StyleSheetList* imp = V8StyleSheetList::toNative(info.Holder()); HTMLStyleElement* item = imp->getNamedItem(toWebCoreString(name)); if (!item) return v8Undefined(); return toV8(item->sheet(), info.Holder()->CreationContext(), info.GetIsolate()); }
EncodedJSValue JSC_HOST_CALL jsStyleSheetListPrototypeFunctionItem(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); if (!thisValue.inherits(&JSStyleSheetList::s_info)) return throwVMTypeError(exec); JSStyleSheetList* castedThis = static_cast<JSStyleSheetList*>(asObject(thisValue)); StyleSheetList* imp = static_cast<StyleSheetList*>(castedThis->impl()); unsigned index(exec->argument(0).toUInt32(exec)); if (exec->hadException()) return JSValue::encode(jsUndefined()); JSC::JSValue result = toJS(exec, castedThis->globalObject(), WTF::getPtr(imp->item(index))); return JSValue::encode(result); }
InspectorStyleSheet* InspectorCSSAgent::viaInspectorStyleSheet(Document* document, bool createIfAbsent) { if (!document) { ASSERT(!createIfAbsent); return 0; } RefPtr<InspectorStyleSheet> inspectorStyleSheet = m_documentToInspectorStyleSheet.get(document); if (inspectorStyleSheet || !createIfAbsent) return inspectorStyleSheet.get(); ExceptionCode ec = 0; RefPtr<Element> styleElement = document->createElement("style", ec); if (!ec) styleElement->setAttribute("type", "text/css", ec); if (!ec) { ContainerNode* targetNode; // HEAD is absent in ImageDocuments, for example. if (document->head()) targetNode = document->head(); else if (document->body()) targetNode = document->body(); else return 0; targetNode->appendChild(styleElement, ec); } if (ec) return 0; StyleSheetList* styleSheets = document->styleSheets(); StyleSheet* styleSheet = styleSheets->item(styleSheets->length() - 1); if (!styleSheet->isCSSStyleSheet()) return 0; CSSStyleSheet* cssStyleSheet = static_cast<CSSStyleSheet*>(styleSheet); String id = String::number(m_lastStyleSheetId++); inspectorStyleSheet = InspectorStyleSheet::create(id, cssStyleSheet, "inspector", m_domAgent->documentURLString(document)); m_idToInspectorStyleSheet.set(id, inspectorStyleSheet); m_cssStyleSheetToInspectorStyleSheet.set(cssStyleSheet, inspectorStyleSheet); m_documentToInspectorStyleSheet.set(document, inspectorStyleSheet); return inspectorStyleSheet.get(); }
bool ElementShadow::hasSameStyles(ElementShadow *other) const { ShadowRoot* root = youngestShadowRoot(); ShadowRoot* otherRoot = other->youngestShadowRoot(); while (root || otherRoot) { if (!root || !otherRoot) return false; StyleSheetList* list = root->styleSheets(); StyleSheetList* otherList = otherRoot->styleSheets(); if (list->length() != otherList->length()) return false; for (size_t i = 0; i < list->length(); i++) { if (toCSSStyleSheet(list->item(i))->contents() != toCSSStyleSheet(otherList->item(i))->contents()) return false; } root = root->olderShadowRoot(); otherRoot = otherRoot->olderShadowRoot(); } return true; }
static v8::Handle<v8::Value> itemCallback(const v8::Arguments& args) { StyleSheetList* imp = V8StyleSheetList::toNative(args.Holder()); V8TRYCATCH(unsigned, index, toUInt32(MAYBE_MISSING_PARAMETER(args, 0, DefaultIsUndefined))); return toV8(imp->item(index), args.Holder(), args.GetIsolate()); }
static v8::Handle<v8::Value> lengthAttrGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) { StyleSheetList* imp = V8StyleSheetList::toNative(info.Holder()); return v8UnsignedInteger(imp->length(), info.GetIsolate()); }