void NamedNodeMap::setAttributes(const NamedNodeMap& other) { // clone all attributes in the other map, but attach to our element if (!m_element) return; // If assigning the map changes the id attribute, we need to call // updateId. Attribute* oldId = getAttributeItem(m_element->idAttributeName()); Attribute* newId = other.getAttributeItem(m_element->idAttributeName()); if (oldId || newId) m_element->updateId(oldId ? oldId->value() : nullAtom, newId ? newId->value() : nullAtom); clearAttributes(); unsigned newLength = other.length(); m_attributes.resize(newLength); for (unsigned i = 0; i < newLength; i++) m_attributes[i] = other.m_attributes[i]->clone(); // FIXME: This is wasteful. The class list could be preserved on a copy, and we // wouldn't have to waste time reparsing the attribute. // The derived class, HTMLNamedNodeMap, which manages a parsed class list for the CLASS attribute, // will update its member variable when parse attribute is called. for (unsigned i = 0; i < newLength; i++) m_element->attributeChanged(m_attributes[i].get(), true); }
/* * Runs the test case. */ void runTest() { Document doc; NodeList elementList; Element firstNode; Node testNode; NamedNodeMap attributes; Attr domesticAttr; Attr setAttr; Node setNode; doc = (Document) baseT::load("staff", true); elementList = doc.getElementsByTagName(SA::construct_from_utf8("address")); firstNode = (Element) elementList.item(0); domesticAttr = doc.createAttribute(SA::construct_from_utf8("domestic")); domesticAttr.setValue(SA::construct_from_utf8("Yes")); setAttr = firstNode.setAttributeNode(domesticAttr); elementList = doc.getElementsByTagName(SA::construct_from_utf8("address")); testNode = elementList.item(2); attributes = testNode.getAttributes(); { boolean success = false; try { setNode = attributes.setNamedItem(domesticAttr); } catch (const DOMException& ex) { success = (ex.code() == DOMException::INUSE_ATTRIBUTE_ERR); } assertTrue(success); } }
Value FunLang::evaluate() const { String lang = arg(0)->evaluate().toString(); Attribute* languageAttribute = 0; Node* node = evaluationContext().node.get(); while (node) { NamedNodeMap* attrs = node->attributes(); if (attrs) languageAttribute = attrs->getAttributeItem(XMLNames::langAttr); if (languageAttribute) break; node = node->parentNode(); } if (!languageAttribute) return BOOL_TO_VALUE_CAST false; String langValue = languageAttribute->value(); while (true) { if (equalIgnoringCase(langValue, lang)) return BOOL_TO_VALUE_CAST true; // Remove suffixes one by one. size_t index = langValue.reverseFind('-'); if (index == notFound) break; langValue = langValue.left(index); } return BOOL_TO_VALUE_CAST false; }
Node* Element::_getElementById (const DOMString& id) { for (size_t i = 0; i < _children.length(); i++) { NamedNodeMap attrs = _children.item(i)->attributes(); for (size_t h = 0; h < attrs.length(); h++) { Attr* attr = (Attr*) attrs.item(h); if (attr->_isId) { if (attr->value() == id) { return _children.item(i); } } } } for (size_t i = 0; i < _children.length(); i++) { Node* element = _children.item(i)->_getElementById(id); if (element) { return element; } } return NULL; }
/* * Runs the test case. */ void runTest() { Document doc1; Document doc2; NodeList elementList; Node testAddress; NamedNodeMap attributes; Node newAttribute; String strong; Node setNode; doc1 = (Document) baseT::load("hc_staff", true); doc2 = (Document) baseT::load("hc_staff", true); elementList = doc1.getElementsByTagName(SA::construct_from_utf8("acronym")); testAddress = elementList.item(2); newAttribute = doc2.createAttribute(SA::construct_from_utf8("newAttribute")); attributes = testAddress.getAttributes(); { boolean success = false; try { setNode = attributes.setNamedItem(newAttribute); } catch (const DOMException& ex) { success = (ex.code() == DOMException::WRONG_DOCUMENT_ERR); } assertTrue(success); } }
static String imageToMarkup(const String& url, Element* element) { StringBuilder markup; markup.append("<img src=\""); markup.append(url); markup.append("\""); // Copy over attributes. If we are dragging an image, we expect things like // the id to be copied as well. NamedNodeMap* attrs = element->attributes(); unsigned length = attrs->length(); for (unsigned i = 0; i < length; ++i) { Attribute* attr = attrs->attributeItem(i); if (attr->localName() == "src") continue; markup.append(" "); markup.append(attr->localName()); markup.append("=\""); String escapedAttr = attr->value(); escapedAttr.replace("\"", """); markup.append(escapedAttr); markup.append("\""); } markup.append("/>"); return markup.toString(); }
/* * Runs the test case. */ void runTest() { Document doc; NodeList acronymList; Node testNode; NamedNodeMap attributes; Attr titleAttr; String value; Node textNode; Node retval; Node lastChild; Document otherDoc; doc = (Document) baseT::load("hc_staff", true); otherDoc = (Document) baseT::load("hc_staff", true); acronymList = doc.getElementsByTagName(SA::construct_from_utf8("acronym")); testNode = acronymList.item(3); attributes = testNode.getAttributes(); titleAttr = (Attr) attributes.getNamedItem(SA::construct_from_utf8("title")); textNode = otherDoc.createTextNode(SA::construct_from_utf8("terday")); { boolean success = false; try { retval = titleAttr.appendChild(textNode); } catch (const DOMException& ex) { success = (ex.code() == DOMException::WRONG_DOCUMENT_ERR); } assertTrue(success); } }
JSValue jsNamedNodeMapLength(ExecState* exec, JSValue slotBase, const Identifier&) { JSNamedNodeMap* castedThis = static_cast<JSNamedNodeMap*>(asObject(slotBase)); UNUSED_PARAM(exec); NamedNodeMap* imp = static_cast<NamedNodeMap*>(castedThis->impl()); JSValue result = jsNumber(imp->length()); return result; }
v8::Handle<v8::Value> V8NamedNodeMap::indexedPropertyGetter(uint32_t index, const v8::AccessorInfo& info) { INC_STATS("DOM.NamedNodeMap.IndexedPropertyGetter"); NamedNodeMap* imp = V8NamedNodeMap::toNative(info.Holder()); RefPtr<Node> result = imp->item(index); if (!result) return v8::Handle<v8::Value>(); return toV8(result.release(), info.GetIsolate()); }
void MarkupAccumulator::appendElement(StringBuilder& out, Element* element, Namespaces* namespaces) { appendOpenTag(out, element, namespaces); NamedNodeMap* attributes = element->attributes(); unsigned length = attributes->length(); for (unsigned int i = 0; i < length; i++) appendAttribute(out, element, *attributes->attributeItem(i), namespaces); appendCloseTag(out, element); }
void HTMLEmbedElement::parametersForPlugin(Vector<String>& paramNames, Vector<String>& paramValues) { NamedNodeMap* attributes = this->attributes(true); if (!attributes) return; for (unsigned i = 0; i < attributes->length(); ++i) { Attribute* it = attributes->attributeItem(i); paramNames.append(it->localName().string()); paramValues.append(it->value().string()); } }
void DatasetDOMStringMap::getNames(Vector<String>& names) { NamedNodeMap* attributeMap = m_element->attributes(true); if (attributeMap) { unsigned length = attributeMap->length(); for (unsigned i = 0; i < length; i++) { Attribute* attribute = attributeMap->attributeItem(i); if (isValidAttributeName(attribute->localName())) names.append(convertAttributeNameToPropertyName(attribute->localName())); } } }
void HTMLConstructionSite::mergeAttributesFromTokenIntoElement(AtomicHTMLToken& token, Element* element) { if (!token.attributes()) return; NamedNodeMap* attributes = element->attributes(false); for (unsigned i = 0; i < token.attributes()->length(); ++i) { Attribute* attribute = token.attributes()->attributeItem(i); if (!attributes->getAttributeItem(attribute->name())) element->setAttribute(attribute->name(), attribute->value()); } }
void XmlWriter::write(const NodePtr nodeArg) { NodePtr node = nodeArg; indent+=2; NamedNodeMap attributes = node->getAttributes(); int nrAttrs = attributes.getLength(); //### Start open tag spaces(); po("<"); pos(node->getNodeName()); if (nrAttrs>0) po("\n"); //### Attributes for (int i=0 ; i<nrAttrs ; i++) { NodePtr attr = attributes.item(i); spaces(); pos(attr->getNodeName()); po("=\""); pos(attr->getNodeValue()); po("\"\n"); } //### Finish open tag if (nrAttrs>0) spaces(); po(">\n"); //### Contents spaces(); pos(node->getNodeValue()); //### Children for (NodePtr child = node->getFirstChild() ; child.get() ; child=child->getNextSibling()) { write(child); } //### Close tag spaces(); po("</"); pos(node->getNodeName()); po(">\n"); indent-=2; }
JSValue JSC_HOST_CALL jsNamedNodeMapPrototypeFunctionGetNamedItem(ExecState* exec, JSObject*, JSValue thisValue, const ArgList& args) { UNUSED_PARAM(args); if (!thisValue.inherits(&JSNamedNodeMap::s_info)) return throwError(exec, TypeError); JSNamedNodeMap* castedThisObj = static_cast<JSNamedNodeMap*>(asObject(thisValue)); NamedNodeMap* imp = static_cast<NamedNodeMap*>(castedThisObj->impl()); const UString& name = args.at(0).toString(exec); JSC::JSValue result = toJS(exec, castedThisObj->globalObject(), WTF::getPtr(imp->getNamedItem(name))); return result; }
bool DatasetDOMStringMap::contains(const String& name) { NamedNodeMap* attributeMap = m_element->attributes(true); if (attributeMap) { unsigned length = attributeMap->length(); for (unsigned i = 0; i < length; i++) { Attribute* attribute = attributeMap->attributeItem(i); if (propertyNameMatchesAttributeName(name, attribute->localName())) return true; } } return false; }
// When inserting a new line, we want to avoid nesting empty divs if we can. Otherwise, when // pasting, it's easy to have each new line be a div deeper than the previous. E.g., in the case // below, we want to insert at ^ instead of |. // <div>foo<div>bar</div>|</div>^ static Element* highestVisuallyEquivalentDivBelowRoot(Element* startBlock) { Element* curBlock = startBlock; // We don't want to return a root node (if it happens to be a div, e.g., in a document fragment) because there are no // siblings for us to append to. while (!curBlock->nextSibling() && curBlock->parentElement()->hasTagName(divTag) && curBlock->parentElement()->parentElement()) { NamedNodeMap* attributes = curBlock->parentElement()->attributes(true); if (attributes && !attributes->isEmpty()) break; curBlock = curBlock->parentElement(); } return curBlock; }
JSValue JSC_HOST_CALL jsNamedNodeMapPrototypeFunctionItem(ExecState* exec, JSObject*, JSValue thisValue, const ArgList& args) { UNUSED_PARAM(args); if (!thisValue.isObject(&JSNamedNodeMap::s_info)) return throwError(exec, TypeError); JSNamedNodeMap* castedThisObj = static_cast<JSNamedNodeMap*>(asObject(thisValue)); NamedNodeMap* imp = static_cast<NamedNodeMap*>(castedThisObj->impl()); unsigned index = args.at(0).toInt32(exec); JSC::JSValue result = toJS(exec, WTF::getPtr(imp->item(index))); return result; }
JSValue JSC_HOST_CALL jsNamedNodeMapPrototypeFunctionGetNamedItemNS(ExecState* exec, JSObject*, JSValue thisValue, const ArgList& args) { UNUSED_PARAM(args); if (!thisValue.isObject(&JSNamedNodeMap::s_info)) return throwError(exec, TypeError); JSNamedNodeMap* castedThisObj = static_cast<JSNamedNodeMap*>(asObject(thisValue)); NamedNodeMap* imp = static_cast<NamedNodeMap*>(castedThisObj->impl()); const UString& namespaceURI = valueToStringWithNullCheck(exec, args.at(0)); const UString& localName = args.at(1).toString(exec); JSC::JSValue result = toJS(exec, WTF::getPtr(imp->getNamedItemNS(namespaceURI, localName))); return result; }
void StyledMarkupAccumulator::appendElement(StringBuilder& out, Element* element, bool addDisplayInline, RangeFullySelectsNode rangeFullySelectsNode) { const bool documentIsHTML = element->document()->isHTMLDocument(); appendOpenTag(out, element, 0); NamedNodeMap* attributes = element->attributes(); const unsigned length = attributes->length(); const bool shouldAnnotateOrForceInline = element->isHTMLElement() && (shouldAnnotate() || addDisplayInline); const bool shouldOverrideStyleAttr = shouldAnnotateOrForceInline || shouldApplyWrappingStyle(element); for (unsigned int i = 0; i < length; i++) { Attribute* attribute = attributes->attributeItem(i); // We'll handle the style attribute separately, below. if (attribute->name() == styleAttr && shouldOverrideStyleAttr) continue; appendAttribute(out, element, *attribute, 0); } if (shouldOverrideStyleAttr) { RefPtr<EditingStyle> newInlineStyle; if (shouldApplyWrappingStyle(element)) { newInlineStyle = m_wrappingStyle->copy(); newInlineStyle->removePropertiesInElementDefaultStyle(element); newInlineStyle->removeStyleConflictingWithStyleOfNode(element); } else newInlineStyle = EditingStyle::create(); if (element->isStyledElement() && static_cast<StyledElement*>(element)->inlineStyleDecl()) newInlineStyle->overrideWithStyle(static_cast<StyledElement*>(element)->inlineStyleDecl()); if (shouldAnnotateOrForceInline) { if (shouldAnnotate()) newInlineStyle->mergeStyleFromRulesForSerialization(toHTMLElement(element)); if (addDisplayInline) newInlineStyle->forceInline(); // If the node is not fully selected by the range, then we don't want to keep styles that affect its relationship to the nodes around it // only the ones that affect it and the nodes within it. if (rangeFullySelectsNode == DoesNotFullySelectNode && newInlineStyle->style()) newInlineStyle->style()->removeProperty(CSSPropertyFloat); } if (!newInlineStyle->isEmpty()) { DEFINE_STATIC_LOCAL(const String, stylePrefix, (" style=\"")); out.append(stylePrefix); appendAttributeValue(out, newInlineStyle->style()->cssText(), documentIsHTML); out.append('\"'); } }
PassRefPtr<InspectorObject> InspectorCSSAgent::buildObjectForAttributeStyles(Element* element) { RefPtr<InspectorObject> styleAttributes = InspectorObject::create(); NamedNodeMap* attributes = element->attributes(); for (unsigned i = 0; attributes && i < attributes->length(); ++i) { Attribute* attribute = attributes->attributeItem(i); if (attribute->style()) { String attributeName = attribute->localName(); RefPtr<InspectorStyle> inspectorStyle = InspectorStyle::create(InspectorCSSId(), attribute->style(), 0); styleAttributes->setObject(attributeName.utf8().data(), inspectorStyle->buildObjectForStyle()); } } return styleAttributes; }
JSValue JSC_HOST_CALL jsNamedNodeMapPrototypeFunctionSetNamedItemNS(ExecState* exec, JSObject*, JSValue thisValue, const ArgList& args) { UNUSED_PARAM(args); if (!thisValue.isObject(&JSNamedNodeMap::s_info)) return throwError(exec, TypeError); JSNamedNodeMap* castedThisObj = static_cast<JSNamedNodeMap*>(asObject(thisValue)); NamedNodeMap* imp = static_cast<NamedNodeMap*>(castedThisObj->impl()); ExceptionCode ec = 0; Node* node = toNode(args.at(0)); JSC::JSValue result = toJS(exec, WTF::getPtr(imp->setNamedItemNS(node, ec))); setDOMException(exec, ec); return result; }
JSValue JSNamedNodeMap::setNamedItemNS(ExecState* exec, const ArgList& args) { NamedNodeMap* imp = static_cast<NamedNodeMap*>(impl()); ExceptionCode ec = 0; Node* newNode = toNode(args.at(0)); if (newNode && newNode->nodeType() == Node::ATTRIBUTE_NODE && imp->element()) { if (!allowSettingSrcToJavascriptURL(exec, imp->element(), newNode->nodeName(), newNode->nodeValue())) return jsNull(); } JSValue result = toJS(exec, globalObject(), WTF::getPtr(imp->setNamedItemNS(newNode, ec))); setDOMException(exec, ec); return result; }
EncodedJSValue JSC_HOST_CALL jsNamedNodeMapPrototypeFunctionItem(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); if (!thisValue.inherits(&JSNamedNodeMap::s_info)) return throwVMTypeError(exec); JSNamedNodeMap* castedThis = static_cast<JSNamedNodeMap*>(asObject(thisValue)); NamedNodeMap* imp = static_cast<NamedNodeMap*>(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); }
/* * Runs the test case. */ void runTest() { Document doc; NodeList genderList; Node gender; NodeList genList; Node gen; NodeList gList; Node g; NamedNodeMap attrList; Attr attrNode; doc = (Document) baseT::load("staff", true); genderList = doc.getElementsByTagName(SA::construct_from_utf8("gender")); gender = genderList.item(2); baseT::assertNotNull(gender, __LINE__, __FILE__); genList = gender.getChildNodes(); gen = genList.item(0); baseT::assertNotNull(gen, __LINE__, __FILE__); gList = gen.getChildNodes(); g = gList.item(0); baseT::template skipIfNot<EntityReference>(g); baseT::assertNotNull(g, __LINE__, __FILE__); attrList = g.getAttributes(); baseT::assertNotNull(attrList, __LINE__, __FILE__); attrNode = (Attr) attrList.getNamedItem(SA::construct_from_utf8("domestic")); baseT::assertNotNull(attrNode, __LINE__, __FILE__); { boolean success = false; try { attrNode.setValue(SA::construct_from_utf8("newvalue")); } catch (const DOMException& ex) { success = (ex.code() == DOMException::NO_MODIFICATION_ALLOWED_ERR); } assertTrue(success); } { boolean success = false; try { attrNode.setNodeValue(SA::construct_from_utf8("newvalue2")); } catch (const DOMException& ex) { success = (ex.code() == DOMException::NO_MODIFICATION_ALLOWED_ERR); } assertTrue(success); } }
v8::Handle<v8::Value> V8NamedNodeMap::namedPropertyGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) { INC_STATS("DOM.NamedNodeMap.NamedPropertyGetter"); if (!info.Holder()->GetRealNamedPropertyInPrototypeChain(name).IsEmpty()) return v8::Handle<v8::Value>(); if (info.Holder()->HasRealNamedCallbackProperty(name)) return v8::Handle<v8::Value>(); NamedNodeMap* imp = V8NamedNodeMap::toNative(info.Holder()); RefPtr<Node> result = imp->getNamedItem(toWebCoreString(name)); if (!result) return v8::Handle<v8::Value>(); return toV8(result.release(), info.GetIsolate()); }
EncodedJSValue JSC_HOST_CALL jsNamedNodeMapPrototypeFunctionGetNamedItem(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); if (!thisValue.inherits(&JSNamedNodeMap::s_info)) return throwVMTypeError(exec); JSNamedNodeMap* castedThis = static_cast<JSNamedNodeMap*>(asObject(thisValue)); ASSERT_GC_OBJECT_INHERITS(castedThis, &JSNamedNodeMap::s_info); NamedNodeMap* imp = static_cast<NamedNodeMap*>(castedThis->impl()); const String& name(ustringToString(exec->argument(0).toString(exec))); if (exec->hadException()) return JSValue::encode(jsUndefined()); JSC::JSValue result = toJS(exec, castedThis->globalObject(), WTF::getPtr(imp->getNamedItem(name))); return JSValue::encode(result); }
void dumpattrs(Node *node) { NamedNodeMap *attrs; Attr *a; uword i; size_t na; oratext *qname; oratext *namespce; oratext *local; oratext *prefix; oratext *value; if (attrs = node->getAttributes()) { cout << "\n ATTRIBUTES: \n"; for (na = attrs->getLength(), i = 0; i < na; i++) { /* get attr qualified name, local name, namespace, and prefix */ a = (Attr *)attrs->item(i); qname = namespce = local = prefix = value = (oratext*)" "; if (a->getQualifiedName() != (oratext*)NULL) qname = a->getQualifiedName(); if (a->getNamespace() != (oratext*)NULL) namespce = a->getNamespace(); if (a->getLocal() != (oratext*)NULL) local = a->getLocal(); if (a->getPrefix() != (oratext*)NULL) prefix = a->getPrefix(); if (a->getValue() != (oratext*)NULL) value = a->getValue(); cout << " " << (char*)qname << " = " << (char*)value << "\n"; cout << " Namespace : " << (char*)namespce << "\n"; cout << " Local Name: " << (char*)local << "\n"; cout << " Prefix : " << (char*)prefix << "\n\n"; } } cout << "\n"; }
/* * Runs the test case. */ void runTest() { Document doc; NodeList addressList; Node testNode; NamedNodeMap attributes; Attr domesticAttr; String value; doc = (Document) baseT::load("hc_staff", false); addressList = doc.getElementsByTagName(SA::construct_from_utf8("acronym")); testNode = addressList.item(0); attributes = testNode.getAttributes(); domesticAttr = (Attr) attributes.getNamedItem(SA::construct_from_utf8("title")); value = domesticAttr.getNodeValue(); baseT::assertEquals("Yes", value, __LINE__, __FILE__); }
/* * Runs the test case. */ void runTest() { Document doc; NodeList addressList; Node testNode; NamedNodeMap attributes; Attr domesticAttr; Node s; doc = (Document) baseT::load("staff", false); addressList = doc.getElementsByTagName(SA::construct_from_utf8("address")); testNode = addressList.item(0); attributes = testNode.getAttributes(); domesticAttr = (Attr) attributes.getNamedItem(SA::construct_from_utf8("domestic")); s = domesticAttr.getPreviousSibling(); baseT::assertNull(s, __LINE__, __FILE__); }