📄 html_headimpl.cpp
字号:
{}HTMLScriptElementImpl::~HTMLScriptElementImpl(){ if (m_cachedScript) m_cachedScript->deref(this);}NodeImpl::Id HTMLScriptElementImpl::id() const{ return ID_SCRIPT;}bool HTMLScriptElementImpl::isURLAttribute(AttributeImpl *attr) const{ return attr->id() == ATTR_SRC;}void HTMLScriptElementImpl::childrenChanged(){ // If a node is inserted as a child of the script element // and the script element has been inserted in the document // we evaluate the script. if (!m_createdByParser && inDocument() && firstChild()) evaluateScript(getDocument()->URL().url(), text());}void HTMLScriptElementImpl::insertedIntoDocument(){ HTMLElementImpl::insertedIntoDocument(); assert(!m_cachedScript); if (m_createdByParser) return; QString url = getAttribute(ATTR_SRC).string(); if (!url.isEmpty()) { QString charset = getAttribute(ATTR_CHARSET).string(); m_cachedScript = getDocument()->docLoader()->requestScript(DOMString(url), charset); if (m_cachedScript) m_cachedScript->ref(this); return; } // If there's an empty script node, we shouldn't evaluate the script // because if a script is inserted afterwards (by setting text or innerText) // it should be evaluated, and evaluateScript only evaluates a script once. DOMString scriptString = text(); if (!scriptString.isEmpty()) evaluateScript(getDocument()->URL().url(), scriptString);}void HTMLScriptElementImpl::removedFromDocument(){ HTMLElementImpl::removedFromDocument(); if (m_cachedScript) { m_cachedScript->deref(this); m_cachedScript = 0; }}void HTMLScriptElementImpl::notifyFinished(CachedObject* o){ CachedScript *cs = static_cast<CachedScript *>(o); assert(cs == m_cachedScript); QString URL = cs->url().string(); DOMString script = cs->script(); cs->deref(this); m_cachedScript = 0; evaluateScript(URL, script);}void HTMLScriptElementImpl::evaluateScript(const QString &URL, const DOMString &script){ if (m_evaluated) return; KHTMLPart *part = getDocument()->part(); if (part) { KJSProxy *proxy = KJSProxy::proxy(part); if (proxy) { m_evaluated = true; proxy->evaluate(URL, 0, script.string(), 0); DocumentImpl::updateDocumentsRendering(); } }}DOMString HTMLScriptElementImpl::text() const{ DOMString val = ""; for (NodeImpl *n = firstChild(); n; n = n->nextSibling()) { if (n->isTextNode()) val += static_cast<TextImpl *>(n)->data(); } return val;}void HTMLScriptElementImpl::setText(const DOMString &value){ int exceptioncode = 0; int numChildren = childNodeCount(); if (numChildren == 1 && firstChild()->isTextNode()) { static_cast<DOM::TextImpl *>(firstChild())->setData(value, exceptioncode); return; } if (numChildren > 0) { removeChildren(); } appendChild(getDocument()->createTextNode(value.implementation()), exceptioncode);}DOMString HTMLScriptElementImpl::htmlFor() const{ // DOM Level 1 says: reserved for future use. return DOMString();}void HTMLScriptElementImpl::setHtmlFor(const DOMString &/*value*/){ // DOM Level 1 says: reserved for future use.}DOMString HTMLScriptElementImpl::event() const{ // DOM Level 1 says: reserved for future use. return DOMString();}void HTMLScriptElementImpl::setEvent(const DOMString &/*value*/){ // DOM Level 1 says: reserved for future use.}DOMString HTMLScriptElementImpl::charset() const{ return getAttribute(ATTR_CHARSET);}void HTMLScriptElementImpl::setCharset(const DOMString &value){ setAttribute(ATTR_CHARSET, value);}bool HTMLScriptElementImpl::defer() const{ return !getAttribute(ATTR_DEFER).isNull();}void HTMLScriptElementImpl::setDefer(bool defer){ setAttribute(ATTR_DEFER, defer ? "" : 0);}DOMString HTMLScriptElementImpl::src() const{ return getDocument()->completeURL(getAttribute(ATTR_SRC).string());}void HTMLScriptElementImpl::setSrc(const DOMString &value){ setAttribute(ATTR_SRC, value);}DOMString HTMLScriptElementImpl::type() const{ return getAttribute(ATTR_TYPE);}void HTMLScriptElementImpl::setType(const DOMString &value){ setAttribute(ATTR_TYPE, value);}// -------------------------------------------------------------------------HTMLStyleElementImpl::~HTMLStyleElementImpl(){ if(m_sheet) m_sheet->deref();}NodeImpl::Id HTMLStyleElementImpl::id() const{ return ID_STYLE;}// other stuff...void HTMLStyleElementImpl::parseAttribute(AttributeImpl *attr){ switch (attr->id()) { case ATTR_TYPE: m_type = attr->value().lower(); break; case ATTR_MEDIA: m_media = attr->value().string().lower(); break; default: HTMLElementImpl::parseAttribute(attr); }}void HTMLStyleElementImpl::insertedIntoDocument(){ HTMLElementImpl::insertedIntoDocument(); if (m_sheet) getDocument()->updateStyleSelector();}void HTMLStyleElementImpl::removedFromDocument(){ HTMLElementImpl::removedFromDocument(); if (m_sheet) getDocument()->updateStyleSelector();}void HTMLStyleElementImpl::childrenChanged(){ HTMLElementImpl::childrenChanged(); DOMString text = ""; for (NodeImpl *c = firstChild(); c != 0; c = c->nextSibling()) { if ((c->nodeType() == Node::TEXT_NODE) || (c->nodeType() == Node::CDATA_SECTION_NODE) || (c->nodeType() == Node::COMMENT_NODE)) text += c->nodeValue(); } if (m_sheet) { m_sheet->deref(); m_sheet = 0; } m_loading = false; if ((m_type.isEmpty() || m_type == "text/css") // Type must be empty or CSS && (m_media.isNull() || m_media.contains("screen") || m_media.contains("all") || m_media.contains("print"))) { getDocument()->addPendingSheet(); m_loading = true; m_sheet = new CSSStyleSheetImpl(this); m_sheet->ref(); m_sheet->parseString( text, !getDocument()->inCompatMode() ); MediaListImpl* media = new MediaListImpl( m_sheet, DOMString( m_media ) ); m_sheet->setMedia( media ); m_loading = false; } if (!isLoading() && m_sheet) getDocument()->styleSheetLoaded();}bool HTMLStyleElementImpl::isLoading() const{ if (m_loading) return true; if(!m_sheet) return false; return static_cast<CSSStyleSheetImpl *>(m_sheet)->isLoading();}void HTMLStyleElementImpl::sheetLoaded(){ if (!isLoading()) getDocument()->styleSheetLoaded();}// -------------------------------------------------------------------------NodeImpl::Id HTMLTitleElementImpl::id() const{ return ID_TITLE;}void HTMLTitleElementImpl::childrenChanged(){ HTMLElementImpl::childrenChanged(); m_title = ""; for (NodeImpl *c = firstChild(); c != 0; c = c->nextSibling()) { if ((c->nodeType() == Node::TEXT_NODE) || (c->nodeType() == Node::CDATA_SECTION_NODE)) m_title += c->nodeValue(); } if ( !m_title.isEmpty() && inDocument()) getDocument()->setTitle(m_title);}DOMString HTMLTitleElementImpl::text(){ if (firstChild() && firstChild()->nodeType() == Node::TEXT_NODE) { return firstChild()->nodeValue(); } return "";}void HTMLTitleElementImpl::setText( const DOMString& str ){ int exceptioncode = 0; // Look for an existing text child node DOM::NodeListImpl* nl(childNodes()); if (nl) { for (unsigned int i = 0; i < nl->length(); i++) { if (nl->item(i)->nodeType() == DOM::Node::TEXT_NODE) { static_cast<DOM::TextImpl *>(nl->item(i))->setData(str, exceptioncode); return; } } delete nl; } // No child text node found, creating one DOM::TextImpl* t = getDocument()->createTextNode(str.implementation()); appendChild(t, exceptioncode);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -