void JSProcessingInstruction::putValueProperty(ExecState* exec, int token, JSValue* value)
{
    switch (token) {
    case DataAttrNum: {
        ProcessingInstruction* imp = static_cast<ProcessingInstruction*>(impl());
        ExceptionCode ec = 0;
        imp->setData(valueToStringWithNullCheck(exec, value), ec);
        setDOMException(exec, ec);
        break;
    }
    }
}
  /*
   * Runs the test case.
   */
  void runTest()
  {
     Document doc;
     ProcessingInstruction newPINode;
     String piValue;
     String piName;
     int piType;
     doc = (Document) baseT::load("staff", true);
     newPINode = doc.createProcessingInstruction(SA::construct_from_utf8("TESTPI"), SA::construct_from_utf8("This is a new PI node"));
     baseT::assertNotNull(newPINode, __LINE__, __FILE__);
     piName = newPINode.getNodeName();
     baseT::assertEquals("TESTPI", piName, __LINE__, __FILE__);
 piValue = newPINode.getNodeValue();
     baseT::assertEquals("This is a new PI node", piValue, __LINE__, __FILE__);
 piType = (int) newPINode.getNodeType();
     baseT::assertEquals(7, piType, __LINE__, __FILE__);
 
  }
JSValue* JSProcessingInstruction::getValueProperty(ExecState* exec, int token) const
{
    switch (token) {
    case TargetAttrNum: {
        ProcessingInstruction* imp = static_cast<ProcessingInstruction*>(impl());
        return jsStringOrNull(exec, imp->target());
    }
    case DataAttrNum: {
        ProcessingInstruction* imp = static_cast<ProcessingInstruction*>(impl());
        return jsStringOrNull(exec, imp->data());
    }
    case SheetAttrNum: {
        ProcessingInstruction* imp = static_cast<ProcessingInstruction*>(impl());
        return toJS(exec, WTF::getPtr(imp->sheet()));
    }
    case ConstructorAttrNum:
        return getConstructor(exec);
    }
    return 0;
}
void DocumentStyleSheetCollection::collectActiveStyleSheets(Vector<RefPtr<StyleSheet> >& sheets)
{
    if (m_document->settings() && !m_document->settings()->authorAndUserStylesEnabled())
        return;

    StyleSheetCandidateListHashSet::iterator begin = m_styleSheetCandidateNodes.begin();
    StyleSheetCandidateListHashSet::iterator end = m_styleSheetCandidateNodes.end();
    for (StyleSheetCandidateListHashSet::iterator it = begin; it != end; ++it) {
        Node* n = *it;
        StyleSheet* sheet = 0;
        if (n->nodeType() == Node::PROCESSING_INSTRUCTION_NODE) {
            // Processing instruction (XML documents only).
            // We don't support linking to embedded CSS stylesheets, see <https://bugs.webkit.org/show_bug.cgi?id=49281> for discussion.
            ProcessingInstruction* pi = static_cast<ProcessingInstruction*>(n);
            sheet = pi->sheet();
#if ENABLE(XSLT)
            // Don't apply XSL transforms to already transformed documents -- <rdar://problem/4132806>
            if (pi->isXSL() && !m_document->transformSourceDocument()) {
                // Don't apply XSL transforms until loading is finished.
                if (!m_document->parsing())
                    m_document->applyXSLTransform(pi);
                return;
            }
#endif
        } else if ((n->isHTMLElement() && (n->hasTagName(linkTag) || n->hasTagName(styleTag)))
#if ENABLE(SVG)
                   ||  (n->isSVGElement() && n->hasTagName(SVGNames::styleTag))
#endif
                   ) {
            Element* e = toElement(n);
            AtomicString title = e->getAttribute(titleAttr);
            bool enabledViaScript = false;
            if (e->hasTagName(linkTag)) {
                // <LINK> element
                HTMLLinkElement* linkElement = static_cast<HTMLLinkElement*>(n);
                if (linkElement->isDisabled())
                    continue;
                enabledViaScript = linkElement->isEnabledViaScript();
                if (linkElement->styleSheetIsLoading()) {
                    // it is loading but we should still decide which style sheet set to use
                    if (!enabledViaScript && !title.isEmpty() && m_preferredStylesheetSetName.isEmpty()) {
                        const AtomicString& rel = e->getAttribute(relAttr);
                        if (!rel.contains("alternate")) {
                            m_preferredStylesheetSetName = title;
                            m_selectedStylesheetSetName = title;
                        }
                    }
                    continue;
                }
                if (!linkElement->sheet())
                    title = nullAtom;
            }
            // Get the current preferred styleset. This is the
            // set of sheets that will be enabled.
#if ENABLE(SVG)
            if (e->hasTagName(SVGNames::styleTag))
                sheet = static_cast<SVGStyleElement*>(n)->sheet();
            else
#endif
            {
                if (e->hasTagName(linkTag))
                    sheet = static_cast<HTMLLinkElement*>(n)->sheet();
                else
                    // <STYLE> element
                    sheet = toHTMLStyleElement(e)->sheet();
            }
            // Check to see if this sheet belongs to a styleset
            // (thus making it PREFERRED or ALTERNATE rather than
            // PERSISTENT).
            AtomicString rel = e->getAttribute(relAttr);
            if (!enabledViaScript && !title.isEmpty()) {
                // Yes, we have a title.
                if (m_preferredStylesheetSetName.isEmpty()) {
                    // No preferred set has been established. If
                    // we are NOT an alternate sheet, then establish
                    // us as the preferred set. Otherwise, just ignore
                    // this sheet.
                    if (e->hasTagName(styleTag) || !rel.contains("alternate"))
                        m_preferredStylesheetSetName = m_selectedStylesheetSetName = title;
                }
                if (title != m_preferredStylesheetSetName)
                    sheet = 0;
            }

            if (rel.contains("alternate") && title.isEmpty())
                sheet = 0;
        }
        if (sheet)
            sheets.append(sheet);
    }
}
Пример #5
0
static Document & getDoc()
{
	if (singleton)
	{
		return *singleton;
	}

	singleton = new Document;
	Document & doc = *singleton;
	doc.setDoctype(Doctype("html", "html.dtd"));

	AttList attributes;
	list<Content*> childs;

	ProcessingInstruction* se = new ProcessingInstruction(ElementName("", "xml"));

	attributes.push_back(Attribut("version", "2.0"));
	attributes.push_back(Attribut("encoding", "utf8"));
	se->setAttList(attributes);
	doc.setXmlProlog(se);	

	Element* root = new Element;
	root->setName(ElementName("", "html"));
	doc.setRoot(root);
	
	Element* head = new Element;
	head->setName(ElementName("", "head"));
	list<Content*> headChildren;
	Element* title = new Element;
	title->setName(ElementName("", "title"));
	
	list<Content*> titleChild;
	Data* titleContent = new Data("Bienvenue");
	titleChild.push_back(titleContent);
	title->setChildren(titleChild);
	
	headChildren.push_back(title);
	head->setChildren(headChildren);
	childs.push_back(head);

	Element* body = new Element;
	body->setName(ElementName("", "body"));
	childs.push_back(body);
	root->setChildren(childs);

	Element* element = new Element;
	element->setName(ElementName("", "a"));
	attributes.clear();
	attributes.push_back(Attribut("alt", "Google.fr"));
	attributes.push_back(Attribut("href", "http://www.google.fr"));	
	element->setAttList(attributes);
	
	EmptyElement* img = new EmptyElement;
	img->setName(ElementName("", "img"));
	attributes.clear();
	attributes.push_back(Attribut("src", "http://www.google.fr/img.jpg"));
	img->setAttList(attributes);

	childs.clear();
	childs.push_back(img);

	Data* data = new Data("Mon petit lien");
	childs.push_back(data);

	Comment* comment = new Comment("<!-- Ceci est un commentaire. -->");
	childs.push_back(comment);
	element->setChildren(childs);

	childs.clear();
	childs.push_back(element);
	body->setChildren(childs);

	return doc;
}