void StyleEngine::modifiedStyleSheetCandidateNode(Node* node) { if (!node->inDocument()) return; TreeScope& treeScope = isHTMLStyleElement(*node) ? node->treeScope() : *m_document; ASSERT(isHTMLStyleElement(node) || treeScope == m_document); markTreeScopeDirty(treeScope); }
void StyleEngine::modifiedStyleSheet(StyleSheet* sheet) { if (!sheet) return; Node* node = sheet->ownerNode(); if (!node || !node->inDocument()) return; TreeScope& treeScope = isHTMLStyleElement(*node) ? node->treeScope() : *m_document; ASSERT(isHTMLStyleElement(node) || treeScope == m_document); markTreeScopeDirty(treeScope); }
void StyleEngine::addStyleSheetCandidateNode(Node* node, bool createdByParser) { if (!node->inDocument()) return; TreeScope& treeScope = isHTMLStyleElement(*node) ? node->treeScope() : *m_document; ASSERT(isHTMLStyleElement(node) || treeScope == m_document); TreeScopeStyleSheetCollection* collection = ensureStyleSheetCollectionFor(treeScope); ASSERT(collection); collection->addStyleSheetCandidateNode(node, createdByParser); markTreeScopeDirty(treeScope); if (treeScope != m_document) insertTreeScopeInDocumentOrder(m_activeTreeScopes, &treeScope); }
void PageSerializer::serializeFrame(Frame* frame) { Document* document = frame->document(); URL url = document->url(); if (!url.isValid() || url.isBlankURL()) { // For blank frames we generate a fake URL so they can be referenced by their containing frame. url = urlForBlankFrame(frame); } if (m_resourceURLs.contains(url)) { // FIXME: We could have 2 frame with the same URL but which were dynamically changed and have now // different content. So we should serialize both and somehow rename the frame src in the containing // frame. Arg! return; } Vector<Node*> nodes; SerializerMarkupAccumulator accumulator(*this, *document, &nodes); TextEncoding textEncoding(document->charset()); CString data; if (!textEncoding.isValid()) { // FIXME: iframes used as images trigger this. We should deal with them correctly. return; } String text = accumulator.serializeNodes(*document->documentElement(), 0, IncludeNode); CString frameHTML = textEncoding.encode(text, EntitiesForUnencodables); m_resources->append(Resource(url, document->suggestedMIMEType(), SharedBuffer::create(frameHTML.data(), frameHTML.length()))); m_resourceURLs.add(url); for (Vector<Node*>::iterator iter = nodes.begin(); iter != nodes.end(); ++iter) { Node* node = *iter; if (!node->isElementNode()) continue; Element* element = toElement(node); // We have to process in-line style as it might contain some resources (typically background images). if (element->isStyledElement()) retrieveResourcesForProperties(toStyledElement(element)->inlineStyle(), document); if (isHTMLImageElement(element)) { HTMLImageElement* imageElement = toHTMLImageElement(element); URL url = document->completeURL(imageElement->getAttribute(HTMLNames::srcAttr)); CachedImage* cachedImage = imageElement->cachedImage(); addImageToResources(cachedImage, imageElement->renderer(), url); } else if (element->hasTagName(HTMLNames::linkTag)) { HTMLLinkElement* linkElement = toHTMLLinkElement(element); if (CSSStyleSheet* sheet = linkElement->sheet()) { URL url = document->completeURL(linkElement->getAttribute(HTMLNames::hrefAttr)); serializeCSSStyleSheet(sheet, url); ASSERT(m_resourceURLs.contains(url)); } } else if (isHTMLStyleElement(element)) { if (CSSStyleSheet* sheet = toHTMLStyleElement(element)->sheet()) serializeCSSStyleSheet(sheet, URL()); } } for (Frame* childFrame = frame->tree().firstChild(); childFrame; childFrame = childFrame->tree().nextSibling()) serializeFrame(childFrame); }
void StyleElement::clearDocumentData(Document& document, Element* element) { if (m_sheet) m_sheet->clearOwnerNode(); if (element->inDocument()) document.styleEngine()->removeStyleSheetCandidateNode(element, isHTMLStyleElement(element) ? toHTMLStyleElement(element)->scopingNode() : 0); }
static bool isAcceptableCSSStyleSheetParent(const Node& parentNode) { // Only these nodes can be parents of StyleSheets, and they need to call // clearOwnerNode() when moved out of document. Note that destructor of // the nodes don't call clearOwnerNode() with Oilpan. return parentNode.isDocumentNode() || isHTMLLinkElement(parentNode) || isHTMLStyleElement(parentNode) || isSVGStyleElement(parentNode) || parentNode.getNodeType() == Node::kProcessingInstructionNode; }
static bool isAcceptableCSSStyleSheetParent(Node* parentNode) { // Only these nodes can be parents of StyleSheets, and they need to call clearOwnerNode() when moved out of document. return !parentNode || parentNode->isDocumentNode() || parentNode->hasTagName(HTMLNames::linkTag) || isHTMLStyleElement(parentNode) || parentNode->hasTagName(SVGNames::styleTag) || parentNode->nodeType() == Node::PROCESSING_INSTRUCTION_NODE; }
void StyleElement::clearDocumentData(Document& document, Element* element) { if (m_sheet) m_sheet->clearOwnerNode(); if (element->inDocument()) { ContainerNode* scopingNode = isHTMLStyleElement(element) ? toHTMLStyleElement(element)->scopingNode() : 0; TreeScope& treeScope = scopingNode ? scopingNode->treeScope() : element->treeScope(); document.styleEngine()->removeStyleSheetCandidateNode(element, scopingNode, treeScope); } }
void StyleEngine::removeStyleSheetCandidateNode(Node* node, ContainerNode* scopingNode, TreeScope& treeScope) { ASSERT(isHTMLStyleElement(node) || treeScope == m_document); TreeScopeStyleSheetCollection* collection = styleSheetCollectionFor(treeScope); ASSERT(collection); collection->removeStyleSheetCandidateNode(node, scopingNode); markTreeScopeDirty(treeScope); m_activeTreeScopes.remove(&treeScope); }
static bool isAcceptableCSSStyleSheetParent(Node* parentNode) { // Only these nodes can be parents of StyleSheets, and they need to call // clearOwnerNode() when moved out of document. // Destruction of the style sheet counts as being "moved out of the // document", but only in the non-oilpan version of blink. I.e. don't call // clearOwnerNode() in the owner's destructor in oilpan. return !parentNode || parentNode->isDocumentNode() || isHTMLStyleElement(*parentNode); }
static bool isAcceptableCSSStyleSheetParent(Node* parentNode) { // Only these nodes can be parents of StyleSheets, and they need to call // clearOwnerNode() when moved out of document. Note that destructor of // the nodes don't call clearOwnerNode() with Oilpan. return !parentNode || parentNode->isDocumentNode() || isHTMLLinkElement(*parentNode) || isHTMLStyleElement(*parentNode) || isSVGStyleElement(*parentNode) || parentNode->getNodeType() == Node::PROCESSING_INSTRUCTION_NODE; }
TreeScope* ScopedStyleResolver::treeScopeFor(Document& document, const CSSStyleSheet* sheet) { ASSERT(sheet); if (!sheet->ownerDocument()) return 0; Node* ownerNode = sheet->ownerNode(); if (!isHTMLStyleElement(ownerNode) && !isSVGStyleElement(ownerNode)) return &document; Element& styleElement = toElement(*ownerNode); if (styleElement.isInShadowTree()) return styleElement.containingShadowRoot(); return &document; }
ContainerNode* ScopedStyleResolver::scopingNodeFor(Document& document, const CSSStyleSheet* sheet) { ASSERT(sheet); Document* sheetDocument = sheet->ownerDocument(); if (!sheetDocument) return 0; Node* ownerNode = sheet->ownerNode(); if (!isHTMLStyleElement(ownerNode)) return &document; HTMLStyleElement& styleElement = toHTMLStyleElement(*ownerNode); if (!styleElement.scoped()) { if (styleElement.isInShadowTree()) return styleElement.containingShadowRoot(); return &document; } ContainerNode* parent = styleElement.parentNode(); if (!parent) return 0; return (parent->isElementNode() || parent->isShadowRoot()) ? parent : 0; }
TextDirection HTMLElement::directionality(Node** strongDirectionalityTextNode) const { if (isHTMLInputElement(*this)) { HTMLInputElement* inputElement = toHTMLInputElement(const_cast<HTMLElement*>(this)); bool hasStrongDirectionality; TextDirection textDirection = determineDirectionality(inputElement->value(), &hasStrongDirectionality); if (strongDirectionalityTextNode) *strongDirectionalityTextNode = hasStrongDirectionality ? inputElement : 0; return textDirection; } Node* node = ComposedTreeTraversal::firstChild(*this); while (node) { // Skip bdi, script, style and text form controls. if (equalIgnoringCase(node->nodeName(), "bdi") || isHTMLScriptElement(*node) || isHTMLStyleElement(*node) || (node->isElementNode() && toElement(node)->isTextFormControl())) { node = ComposedTreeTraversal::nextSkippingChildren(*node, this); continue; } // Skip elements with valid dir attribute if (node->isElementNode()) { AtomicString dirAttributeValue = toElement(node)->fastGetAttribute(dirAttr); if (isValidDirAttribute(dirAttributeValue)) { node = ComposedTreeTraversal::nextSkippingChildren(*node, this); continue; } } if (node->isTextNode()) { bool hasStrongDirectionality; TextDirection textDirection = determineDirectionality(node->textContent(true), &hasStrongDirectionality); if (hasStrongDirectionality) { if (strongDirectionalityTextNode) *strongDirectionalityTextNode = node; return textDirection; } } node = ComposedTreeTraversal::next(*node, this); } if (strongDirectionalityTextNode) *strongDirectionalityTextNode = 0; return LTR; }
static bool shouldUseLengthLimit(const ContainerNode& node) { return !isHTMLScriptElement(node) && !isHTMLStyleElement(node); }
static bool isStyleElement(const Node* node) { return node && (isHTMLStyleElement(node) || isSVGStyleElement(node)); }