28 #include "dom_docimpl.h"
30 #include <dom/dom_exception.h>
32 #include "dom_textimpl.h"
33 #include "dom_xmlimpl.h"
34 #include "dom2_rangeimpl.h"
35 #include "dom2_eventsimpl.h"
36 #include "xml_tokenizer.h"
37 #include <html/htmltokenizer.h>
38 #include "dom_restyler.h"
40 #include <css/cssstyleselector.h>
41 #include <css/css_stylesheetimpl.h>
42 #include <misc/seed.h>
43 #include <misc/loader.h>
44 #include <ecma/kjs_proxy.h>
45 #include <ecma/kjs_binding.h>
49 #include "khtml_debug.h"
52 #include <rendering/counter_tree.h>
53 #include <rendering/render_canvas.h>
54 #include <rendering/render_replaced.h>
55 #include <rendering/render_arena.h>
56 #include <rendering/render_layer.h>
57 #include <rendering/render_frames.h>
58 #include <rendering/render_image.h>
60 #include <khtmlview.h>
61 #include <khtml_part.h>
62 #include <kurlauthorized.h>
63 #include <khtml_settings.h>
64 #include <khtmlpart_p.h>
66 #include <xml/dom3_xpathimpl.h>
67 #include <html/html_baseimpl.h>
68 #include <html/html_blockimpl.h>
69 #include <html/html_canvasimpl.h>
70 #include <html/html_documentimpl.h>
71 #include <html/html_formimpl.h>
72 #include <html/html_headimpl.h>
73 #include <html/html_imageimpl.h>
74 #include <html/html_listimpl.h>
75 #include <html/html_miscimpl.h>
76 #include <html/html_tableimpl.h>
77 #include <html/html_objectimpl.h>
78 #include <html/HTMLAudioElement.h>
79 #include <html/HTMLVideoElement.h>
80 #include <html/HTMLSourceElement.h>
81 #include <editing/jsediting.h>
83 #include <ecma/kjs_window.h>
86 #include <svg/SVGElement.h>
87 #include <svg/SVGSVGElement.h>
88 #include <svg/SVGNames.h>
89 #include <svg/SVGDocumentExtensions.h>
90 #include <svg/SVGRectElement.h>
91 #include <svg/SVGDocument.h>
92 #include <svg/SVGCircleElement.h>
93 #include <svg/SVGStyleElement.h>
94 #include <svg/SVGEllipseElement.h>
95 #include <svg/SVGPolygonElement.h>
96 #include <svg/SVGPolylineElement.h>
97 #include <svg/SVGPathElement.h>
98 #include <svg/SVGDefsElement.h>
99 #include <svg/SVGLinearGradientElement.h>
100 #include <svg/SVGRadialGradientElement.h>
101 #include <svg/SVGStopElement.h>
102 #include <svg/SVGClipPathElement.h>
103 #include <svg/SVGGElement.h>
104 #include <svg/SVGUseElement.h>
105 #include <svg/SVGLineElement.h>
106 #include <svg/SVGTextElement.h>
107 #include <svg/SVGAElement.h>
108 #include <svg/SVGScriptElement.h>
109 #include <svg/SVGDescElement.h>
110 #include <svg/SVGTitleElement.h>
111 #include <svg/SVGTextPathElement.h>
112 #include <svg/SVGTSpanElement.h>
113 #include <svg/SVGHKernElement.h>
114 #include <svg/SVGAltGlyphElement.h>
115 #include <svg/SVGFontElement.h>
118 #include <QFontDatabase>
123 #undef FOCUS_EVENT // for win32, MinGW
128 using namespace khtml;
132 DOMImplementationImpl::DOMImplementationImpl()
136 DOMImplementationImpl::~DOMImplementationImpl()
140 bool DOMImplementationImpl::hasFeature(
const DOMString &feature,
const DOMString &version)
144 if ((lower ==
"html" || lower ==
"xml") &&
145 (
version.isEmpty() || version ==
"1.0" || version ==
"2.0")) {
150 if ((lower ==
"core") &&
151 (
version.isEmpty() || version ==
"2.0")) {
155 if ((lower ==
"traversal") &&
156 (
version.isEmpty() || version ==
"2.0")) {
160 if ((lower ==
"css") &&
161 (
version.isEmpty() || version ==
"2.0")) {
165 if ((lower ==
"events" || lower ==
"uievents" ||
166 lower ==
"mouseevents" || lower ==
"mutationevents" ||
167 lower ==
"htmlevents" || lower ==
"textevents") &&
168 (
version.isEmpty() || version ==
"2.0" || version ==
"3.0")) {
172 if (lower ==
"selectors-api" && version ==
"1.0") {
179 DocumentTypeImpl *DOMImplementationImpl::createDocumentType(
const DOMString &qualifiedName,
const DOMString &publicId,
180 const DOMString &systemId,
int &exceptioncode)
183 if (qualifiedName.isNull()) {
184 exceptioncode = DOMException::NAMESPACE_ERR;
189 if (!Element::khtmlValidQualifiedName(qualifiedName)) {
190 exceptioncode = DOMException::INVALID_CHARACTER_ERR;
196 if (!qualifiedName.isEmpty() && Element::khtmlMalformedQualifiedName(qualifiedName)) {
197 exceptioncode = DOMException::NAMESPACE_ERR;
201 return new DocumentTypeImpl(
this,
nullptr, qualifiedName, publicId, systemId);
205 DocumentTypeImpl *dtype,
211 if (!checkQualifiedName(qualifiedName, namespaceURI,
nullptr,
true,
212 true , &exceptioncode)) {
221 if (dtype && dtype->document()) {
222 exceptioncode = DOMException::WRONG_DOCUMENT_ERR;
228 if (namespaceURI == XHTML_NAMESPACE) {
229 doc =
new HTMLDocumentImpl(v);
235 dtype->setDocument(doc);
236 doc->appendChild(dtype, exceptioncode);
241 if (dtype || !qualifiedName.isEmpty() || !namespaceURI.isEmpty()) {
242 ElementImpl *element = doc->createElementNS(namespaceURI, qualifiedName);
243 doc->appendChild(element, exceptioncode);
253 CSSStyleSheetImpl *DOMImplementationImpl::createCSSStyleSheet(DOMStringImpl *title, DOMStringImpl *media,
258 CSSStyleSheetImpl *parent =
nullptr;
259 CSSStyleSheetImpl *sheet =
new CSSStyleSheetImpl(parent,
DOMString());
260 sheet->setMedia(
new MediaListImpl(sheet, media,
true ));
272 XMLDocumentImpl *DOMImplementationImpl::createXMLDocument(
KHTMLView *v)
274 XMLDocumentImpl *doc =
new XMLDocumentImpl(v);
279 HTMLDocumentImpl *DOMImplementationImpl::createHTMLDocument(
KHTMLView *v)
281 HTMLDocumentImpl *doc =
new HTMLDocumentImpl(v);
287 WebCore::SVGDocument *DOMImplementationImpl::createSVGDocument(
KHTMLView *v)
289 WebCore::SVGDocument *doc =
new WebCore::SVGDocument(v);
294 HTMLDocumentImpl *DOMImplementationImpl::createHTMLDocument(
const DOMString &title)
296 HTMLDocumentImpl *r = createHTMLDocument(
nullptr );
300 r->write(
QLatin1String(
"<HTML><HEAD><TITLE>") + title.string() +
308 ElementMappingCache::ElementMappingCache(): m_dict()
312 ElementMappingCache::~ElementMappingCache()
331 m_dict.insert(
id, info);
341 assert(m_dict.contains(
id));
352 assert(m_dict.contains(
id));
355 if (info->ref == 0) {
359 if (info->nd == nd) {
370 return m_dict.contains(
id);
378 return m_dict.value(
id);
386 : NodeBaseImpl(nullptr), m_svgExtensions(nullptr), m_counterDict(),
387 m_imageLoadEventTimer(0)
389 m_document.resetSkippingRef(
this);
390 m_selfOnlyRefCount = 0;
392 m_paintDevice =
nullptr;
397 m_renderArena.reset();
399 KHTMLGlobal::registerDocumentImpl(
this);
403 setPaintDevice(m_view);
405 m_docLoader =
new DocLoader(
nullptr,
this);
408 visuallyOrdered =
false;
410 m_docChanged =
false;
411 m_elemSheet =
nullptr;
412 m_tokenizer =
nullptr;
415 m_implementation =
nullptr;
418 m_htmlCompat =
false;
419 m_textColor =
"#000000";
420 m_focusNode =
nullptr;
421 m_hoverNode =
nullptr;
422 m_activeNode =
nullptr;
423 m_defaultView =
new AbstractViewImpl(
this);
424 m_defaultView->ref();
426 m_styleSheets =
new StyleSheetListImpl(
this);
427 m_styleSheets->ref();
428 m_addedStyleSheets =
nullptr;
430 m_styleSelectorDirty =
false;
431 m_styleSelector =
nullptr;
432 m_styleSheetListDirty =
true;
434 m_inStyleRecalc =
false;
435 m_pendingStylesheets = 0;
436 m_ignorePendingStylesheets =
false;
438 m_hadLoadError =
false;
439 m_docLoading =
false;
440 m_bVariableLength =
false;
441 m_inSyncLoad =
nullptr;
442 m_loadingXMLDoc =
nullptr;
443 m_documentElement =
nullptr;
444 m_cssTarget =
nullptr;
445 m_jsEditor =
nullptr;
447 m_stateRestorePos = 0;
448 m_windowEventTarget =
new WindowEventTargetImpl(
this);
449 m_windowEventTarget->ref();
451 for (
int c = 0; c < NumTreeVersions; ++c) {
452 m_domTreeVersions[c] = 0;
456 void DocumentImpl::removedLastRef()
458 if (m_selfOnlyRefCount) {
468 DocPtr<DocumentImpl> guard(
this);
478 m_cssTarget->deref();
479 m_cssTarget =
nullptr;
483 m_focusNode->deref();
484 m_focusNode =
nullptr;
488 m_hoverNode->deref();
489 m_hoverNode =
nullptr;
493 m_activeNode->deref();
494 m_activeNode =
nullptr;
497 if (m_documentElement) {
498 m_documentElement->deref();
499 m_documentElement =
nullptr;
505 m_tokenizer =
nullptr;
511 DocumentImpl::~DocumentImpl()
518 while (it.hasNext()) {
519 it.next().value()->deref();
522 if (m_loadingXMLDoc) {
523 m_loadingXMLDoc->deref(
this);
525 if (s_changedDocuments() && m_docChanged) {
526 s_changedDocuments()->removeAll(
this);
529 m_document.resetSkippingRef(
nullptr);
530 delete m_styleSelector;
533 m_elemSheet->deref();
538 if (m_implementation) {
539 m_implementation->deref();
541 delete m_dynamicDomRestyler;
543 m_defaultView->deref();
544 m_styleSheets->deref();
545 if (m_addedStyleSheets) {
546 m_addedStyleSheets->deref();
549 m_cssTarget->deref();
552 m_focusNode->deref();
555 m_hoverNode->deref();
558 m_activeNode->deref();
560 if (m_documentElement) {
561 m_documentElement->deref();
563 m_windowEventTarget->deref();
564 qDeleteAll(m_counterDict);
566 m_renderArena.reset();
568 KHTMLGlobal::deregisterDocumentImpl(
this);
571 DOMImplementationImpl *DocumentImpl::implementation()
const
573 if (!m_implementation) {
574 m_implementation =
new DOMImplementationImpl();
575 m_implementation->ref();
577 return m_implementation;
580 void DocumentImpl::childrenChanged()
583 if (m_documentElement) {
584 m_documentElement->deref();
586 m_documentElement =
nullptr;
595 ElementImpl *DocumentImpl::documentElement()
const
597 if (!m_documentElement) {
599 while (n && n->nodeType() != Node::ELEMENT_NODE) {
600 n = n->nextSibling();
602 m_documentElement =
static_cast<ElementImpl *
>(n);
603 if (m_documentElement) {
604 m_documentElement->ref();
607 return m_documentElement;
610 DocumentTypeImpl *DocumentImpl::doctype()
const
614 while (n && n->nodeType() != Node::DOCUMENT_TYPE_NODE) {
615 n = n->nextSibling();
617 m_doctype =
static_cast<DocumentTypeImpl *
>(n);
625 ElementImpl *DocumentImpl::createElement(
const DOMString &name,
int *pExceptioncode)
627 if (pExceptioncode && !Element::khtmlValidQualifiedName(name)) {
628 *pExceptioncode = DOMException::INVALID_CHARACTER_ERR;
634 bool htmlCompat = htmlMode() != XHtml;
635 splitPrefixLocalName(name, prefix, localName, htmlCompat);
636 XMLElementImpl *e =
new XMLElementImpl(document(), emptyNamespaceName, localName, prefix);
637 e->setHTMLCompat(htmlCompat);
641 AttrImpl *DocumentImpl::createAttribute(
const DOMString &tagName,
int *pExceptioncode)
643 if (pExceptioncode && !Element::khtmlValidAttrName(tagName)) {
644 *pExceptioncode = DOMException::INVALID_CHARACTER_ERR;
650 bool htmlCompat = (htmlMode() != XHtml);
651 splitPrefixLocalName(tagName, prefix, localName, htmlCompat);
653 AttrImpl *attr =
new AttrImpl(
nullptr, document(), NamespaceName::fromId(emptyNamespace),
654 localName, prefix,
DOMString(
"").implementation());
655 attr->setHTMLCompat(htmlCompat);
659 DocumentFragmentImpl *DocumentImpl::createDocumentFragment()
661 return new DocumentFragmentImpl(docPtr());
664 CommentImpl *DocumentImpl::createComment(DOMStringImpl *data)
666 return new CommentImpl(docPtr(), data);
669 CDATASectionImpl *DocumentImpl::createCDATASection(DOMStringImpl *data,
int &exceptioncode)
671 if (isHTMLDocument()) {
672 exceptioncode = DOMException::NOT_SUPPORTED_ERR;
675 return new CDATASectionImpl(docPtr(), data);
678 ProcessingInstructionImpl *DocumentImpl::createProcessingInstruction(
const DOMString &target, DOMStringImpl *data)
680 return new ProcessingInstructionImpl(docPtr(), target, data);
683 EntityReferenceImpl *DocumentImpl::createEntityReference(
const DOMString &name,
int &exceptioncode)
685 if (isHTMLDocument()) {
686 exceptioncode = DOMException::NOT_SUPPORTED_ERR;
689 return new EntityReferenceImpl(docPtr(),
name.implementation());
692 EditingTextImpl *DocumentImpl::createEditingTextNode(
const DOMString &text)
694 return new EditingTextImpl(docPtr(), text);
697 NodeImpl *DocumentImpl::importNode(NodeImpl *importedNode,
bool deep,
int &exceptioncode)
699 NodeImpl *result =
nullptr;
703 exceptioncode = DOMException::NOT_FOUND_ERR;
707 if (importedNode->nodeType() == Node::ELEMENT_NODE) {
709 ElementImpl *otherElem =
static_cast<ElementImpl *
>(importedNode);
710 NamedAttrMapImpl *otherMap =
static_cast<ElementImpl *
>(importedNode)->attributes(
true);
712 ElementImpl *tempElementImpl;
713 tempElementImpl = createElementNS(otherElem->namespaceURI(), otherElem->nonCaseFoldedTagName());
714 tempElementImpl->setHTMLCompat(htmlMode() != XHtml && otherElem->htmlCompat());
715 result = tempElementImpl;
718 for (
unsigned i = 0; i < otherMap->length(); i++) {
719 AttrImpl *otherAttr = otherMap->attributeAt(i).createAttr(otherElem, otherElem->docPtr());
721 tempElementImpl->setAttributeNS(otherAttr->namespaceURI(),
723 otherAttr->nodeValue(),
726 if (exceptioncode != 0) {
731 }
else if (importedNode->nodeType() == Node::TEXT_NODE) {
732 result = createTextNode(
static_cast<TextImpl *
>(importedNode)->
string());
734 }
else if (importedNode->nodeType() == Node::CDATA_SECTION_NODE) {
735 result = createCDATASection(
static_cast<CDATASectionImpl *
>(importedNode)->
string(), exceptioncode);
737 }
else if (importedNode->nodeType() == Node::ENTITY_REFERENCE_NODE) {
738 result = createEntityReference(importedNode->nodeName(), exceptioncode);
739 }
else if (importedNode->nodeType() == Node::PROCESSING_INSTRUCTION_NODE) {
740 result = createProcessingInstruction(importedNode->nodeName(), importedNode->nodeValue().implementation());
742 }
else if (importedNode->nodeType() == Node::COMMENT_NODE) {
743 result = createComment(
static_cast<CommentImpl *
>(importedNode)->
string());
745 }
else if (importedNode->nodeType() == Node::DOCUMENT_FRAGMENT_NODE) {
746 result = createDocumentFragment();
748 exceptioncode = DOMException::NOT_SUPPORTED_ERR;
753 if (deep && result) {
755 result->appendChild(importNode(n.handle(),
true, exceptioncode), exceptioncode);
762 ElementImpl *DocumentImpl::createElementNS(
const DOMString &_namespaceURI,
const DOMString &_qualifiedName,
int *pExceptioncode)
764 ElementImpl *e =
nullptr;
767 if (pExceptioncode && !checkQualifiedName(_qualifiedName, _namespaceURI, &colonPos,
773 splitPrefixLocalName(_qualifiedName.
implementation(), prefix, localName, colonPos);
775 if (_namespaceURI == SVG_NAMESPACE) {
776 e = createSVGElement(QualifiedName(prefix, localName, _namespaceURI));
781 qCWarning(KHTML_LOG) <<
"svg element" << localName <<
"either is not supported by khtml or it's not a proper svg element";
789 if (_namespaceURI == XHTML_NAMESPACE) {
790 e = createHTMLElement(localName,
false );
791 int _exceptioncode = 0;
792 if (!prefix.isNull()) {
793 e->setPrefix(prefix, _exceptioncode);
795 if (_exceptioncode) {
796 if (pExceptioncode) {
797 *pExceptioncode = _exceptioncode;
804 e =
new XMLElementImpl(document(), NamespaceName::fromString(_namespaceURI),
805 LocalName::fromString(localName), PrefixName::fromString(prefix));
811 AttrImpl *DocumentImpl::createAttributeNS(
const DOMString &_namespaceURI,
812 const DOMString &_qualifiedName,
int *pExceptioncode)
816 if (pExceptioncode && !checkQualifiedName(_qualifiedName, _namespaceURI, &colonPos,
823 bool htmlCompat = _namespaceURI.isNull() && htmlMode() != XHtml;
824 splitPrefixLocalName(_qualifiedName, prefix, localName,
false, colonPos);
825 AttrImpl *attr =
new AttrImpl(
nullptr, document(), NamespaceName::fromString(_namespaceURI),
826 localName, prefix,
DOMString(
"").implementation());
827 attr->setHTMLCompat(htmlCompat);
831 ElementImpl *DocumentImpl::getElementById(
const DOMString &elementId)
const
846 NodeImpl *current = _first;
853 current = nodeStack.
pop();
854 current = current->nextSibling();
856 if (current->isElementNode()) {
857 ElementImpl *e =
static_cast<ElementImpl *
>(current);
858 if (e->getAttribute(ATTR_ID) == elementId) {
864 NodeImpl *child = current->firstChild();
866 nodeStack.
push(current);
869 current = current->nextSibling();
881 void DocumentImpl::setTitle(
const DOMString &_title)
883 if (_title == m_title && !m_title.isNull()) {
889 QString titleStr = m_title.string();
890 for (
int i = 0; i < titleStr.
length(); ++i)
891 if (titleStr[i] <
' ') {
895 if (view() && !view()->part()->parentPart()) {
913 unsigned short DocumentImpl::nodeType()
const
915 return Node::DOCUMENT_NODE;
918 ElementImpl *DocumentImpl::createHTMLElement(
const DOMString &name,
bool caseInsensitive)
920 LocalName localname = LocalName::fromString(name,
921 caseInsensitive ? IDS_NormalizeLower : IDS_CaseSensitive);
922 uint
id = localname.id();
924 ElementImpl *n =
nullptr;
927 n =
new HTMLHtmlElementImpl(docPtr());
930 n =
new HTMLHeadElementImpl(docPtr());
933 n =
new HTMLBodyElementImpl(docPtr());
938 n =
new HTMLBaseElementImpl(docPtr());
941 n =
new HTMLLinkElementImpl(docPtr());
944 n =
new HTMLMetaElementImpl(docPtr());
947 n =
new HTMLStyleElementImpl(docPtr());
950 n =
new HTMLTitleElementImpl(docPtr());
955 n =
new HTMLFrameElementImpl(docPtr());
958 n =
new HTMLFrameSetElementImpl(docPtr());
961 n =
new HTMLIFrameElementImpl(docPtr());
967 n =
new HTMLFormElementImpl(docPtr(),
false);
970 n =
new HTMLButtonElementImpl(docPtr());
973 n =
new HTMLFieldSetElementImpl(docPtr());
976 n =
new HTMLInputElementImpl(docPtr());
979 n =
new HTMLIsIndexElementImpl(docPtr());
982 n =
new HTMLLabelElementImpl(docPtr());
985 n =
new HTMLLegendElementImpl(docPtr());
988 n =
new HTMLOptGroupElementImpl(docPtr());
991 n =
new HTMLOptionElementImpl(docPtr());
994 n =
new HTMLSelectElementImpl(docPtr());
997 n =
new HTMLTextAreaElementImpl(docPtr());
1002 n =
new HTMLDListElementImpl(docPtr());
1005 n =
new HTMLGenericElementImpl(docPtr(),
id);
1008 n =
new HTMLGenericElementImpl(docPtr(),
id);
1011 n =
new HTMLUListElementImpl(docPtr());
1014 n =
new HTMLOListElementImpl(docPtr());
1017 n =
new HTMLDirectoryElementImpl(docPtr());
1020 n =
new HTMLMenuElementImpl(docPtr());
1023 n =
new HTMLLIElementImpl(docPtr());
1029 n =
new HTMLDivElementImpl(docPtr(),
id);
1038 n =
new HTMLGenericElementImpl(docPtr(),
id);
1041 n =
new HTMLHRElementImpl(docPtr());
1047 n =
new HTMLPreElementImpl(docPtr(),
id);
1052 n =
new HTMLBaseFontElementImpl(docPtr());
1055 n =
new HTMLFontElementImpl(docPtr());
1061 n =
new HTMLGenericElementImpl(docPtr(),
id);
1066 n =
new HTMLAnchorElementImpl(docPtr());
1072 n =
new HTMLImageElementImpl(docPtr());
1075 n =
new HTMLCanvasElementImpl(docPtr());
1078 n =
new HTMLMapElementImpl(docPtr());
1082 n =
new HTMLAreaElementImpl(docPtr());
1087 n =
new HTMLAppletElementImpl(docPtr());
1090 n =
new HTMLObjectElementImpl(docPtr());
1093 n =
new HTMLEmbedElementImpl(docPtr());
1096 n =
new HTMLParamElementImpl(docPtr());
1099 n =
new HTMLScriptElementImpl(docPtr());
1104 n =
new HTMLAudioElement(docPtr());
1107 n =
new HTMLVideoElement(docPtr());
1110 n =
new HTMLSourceElement(docPtr());
1115 n =
new HTMLTableElementImpl(docPtr());
1118 n =
new HTMLTableCaptionElementImpl(docPtr());
1122 n =
new HTMLTableColElementImpl(docPtr(),
id);
1125 n =
new HTMLTableRowElementImpl(docPtr());
1129 n =
new HTMLTableCellElementImpl(docPtr(),
id);
1134 n =
new HTMLTableSectionElementImpl(docPtr(),
id,
false);
1139 n =
new HTMLBRElementImpl(docPtr());
1142 n =
new HTMLWBRElementImpl(docPtr());
1145 n =
new HTMLGenericElementImpl(docPtr(),
id);
1153 n =
new HTMLGenericElementImpl(docPtr(),
id);
1188 n =
new HTMLGenericElementImpl(docPtr(),
id);
1192 n =
new HTMLMarqueeElementImpl(docPtr());
1200 n =
new HTMLGenericElementImpl(docPtr(), localname);
1208 ElementImpl *DocumentImpl::createSVGElement(
const QualifiedName &name)
1210 uint
id =
name.localNameId().id();
1214 ElementImpl *n =
nullptr;
1217 n =
new WebCore::SVGTextPathElement(name, docPtr());
1220 n =
new WebCore::SVGTSpanElement(name, docPtr());
1223 n =
new WebCore::SVGHKernElement(name, docPtr());
1226 n =
new WebCore::SVGAltGlyphElement(name, docPtr());
1229 n =
new WebCore::SVGFontElement(name, docPtr());
1233 if (
id == WebCore::SVGNames::svgTag.localNameId().
id()) {
1234 n =
new WebCore::SVGSVGElement(name, docPtr());
1237 if (
id == WebCore::SVGNames::rectTag.localNameId().
id()) {
1238 n =
new WebCore::SVGRectElement(name, docPtr());
1241 if (
id == WebCore::SVGNames::circleTag.localNameId().
id()) {
1242 n =
new WebCore::SVGCircleElement(name, docPtr());
1245 if (
id == WebCore::SVGNames::ellipseTag.localNameId().
id()) {
1246 n =
new WebCore::SVGEllipseElement(name, docPtr());
1249 if (
id == WebCore::SVGNames::polylineTag.localNameId().
id()) {
1250 n =
new WebCore::SVGPolylineElement(name, docPtr());
1253 if (
id == WebCore::SVGNames::polygonTag.localNameId().
id()) {
1254 n =
new WebCore::SVGPolygonElement(name, docPtr());
1257 if (
id == WebCore::SVGNames::pathTag.localNameId().
id()) {
1258 n =
new WebCore::SVGPathElement(name, docPtr());
1261 if (
id == WebCore::SVGNames::defsTag.localNameId().
id()) {
1262 n =
new WebCore::SVGDefsElement(name, docPtr());
1265 if (
id == WebCore::SVGNames::linearGradientTag.localNameId().
id()) {
1266 n =
new WebCore::SVGLinearGradientElement(name, docPtr());
1269 if (
id == WebCore::SVGNames::radialGradientTag.localNameId().
id()) {
1270 n =
new WebCore::SVGRadialGradientElement(name, docPtr());
1273 if (
id == WebCore::SVGNames::stopTag.localNameId().
id()) {
1274 n =
new WebCore::SVGStopElement(name, docPtr());
1277 if (
id == WebCore::SVGNames::clipPathTag.localNameId().
id()) {
1278 n =
new WebCore::SVGClipPathElement(name, docPtr());
1281 if (
id == WebCore::SVGNames::gTag.localNameId().
id()) {
1282 n =
new WebCore::SVGGElement(name, docPtr());
1285 if (
id == WebCore::SVGNames::useTag.localNameId().
id()) {
1286 n =
new WebCore::SVGUseElement(name, docPtr());
1289 if (
id == WebCore::SVGNames::lineTag.localNameId().
id()) {
1290 n =
new WebCore::SVGLineElement(name, docPtr());
1293 if (
id == WebCore::SVGNames::textTag.localNameId().
id()) {
1294 n =
new WebCore::SVGTextElement(name, docPtr());
1297 if (
id == WebCore::SVGNames::aTag.localNameId().
id()) {
1298 n =
new WebCore::SVGAElement(name, docPtr());
1301 if (
id == WebCore::SVGNames::scriptTag.localNameId().
id()) {
1302 n =
new WebCore::SVGScriptElement(name, docPtr());
1305 if (
id == WebCore::SVGNames::descTag.localNameId().
id()) {
1306 n =
new WebCore::SVGDescElement(name, docPtr());
1309 if (
id == WebCore::SVGNames::titleTag.localNameId().
id()) {
1310 n =
new WebCore::SVGTitleElement(name, docPtr());
1313 if (
id == makeId(svgNamespace, ID_STYLE)) {
1314 n =
new WebCore::SVGStyleElement(name, docPtr());
1320 void DocumentImpl::attemptRestoreState(NodeImpl *n)
1322 if (!n->isElementNode()) {
1326 ElementImpl *el =
static_cast<ElementImpl *
>(n);
1328 if (m_stateRestorePos >= m_state.
size()) {
1333 QString idStr = m_state[m_stateRestorePos];
1334 QString nmStr = m_state[m_stateRestorePos + 1];
1335 QString tpStr = m_state[m_stateRestorePos + 2];
1336 QString stStr = m_state[m_stateRestorePos + 3];
1339 if (idStr.
toUInt() != el->id()) {
1342 if (nmStr != el->getAttribute(ATTR_NAME).string()) {
1345 if (tpStr != el->getAttribute(ATTR_TYPE).string()) {
1349 m_stateRestorePos += 4;
1351 el->restoreState(stStr);
1359 NodeImpl *n = it.next();
1360 if (!n->isElementNode()) {
1364 ElementImpl *el =
static_cast<ElementImpl *
>(n);
1367 s.
append(el->getAttribute(ATTR_NAME).string());
1368 s.
append(el->getAttribute(ATTR_TYPE).string());
1375 bool DocumentImpl::unsubmittedFormChanges()
1378 NodeImpl *node = it.next();
1379 if (node->isGenericFormElement() &&
static_cast<HTMLGenericFormElementImpl *
>(node)->unsubmittedFormChanges()) {
1387 RangeImpl *DocumentImpl::createRange()
1389 return new RangeImpl(docPtr());
1392 NodeIteratorImpl *DocumentImpl::createNodeIterator(NodeImpl *root,
unsigned long whatToShow,
1393 NodeFilterImpl *filter,
bool entityReferenceExpansion,
1397 exceptioncode = DOMException::NOT_SUPPORTED_ERR;
1401 return new NodeIteratorImpl(root, whatToShow, filter, entityReferenceExpansion);
1404 TreeWalkerImpl *DocumentImpl::createTreeWalker(NodeImpl *root,
unsigned long whatToShow, NodeFilterImpl *filter,
1405 bool entityReferenceExpansion,
int &exceptioncode)
1408 exceptioncode = DOMException::NOT_SUPPORTED_ERR;
1412 return new TreeWalkerImpl(root, whatToShow, filter, entityReferenceExpansion);
1415 void DocumentImpl::setDocumentChanged(
bool b)
1417 if (b && !m_docChanged) {
1418 s_changedDocuments()->append(
this);
1419 }
else if (!b && m_docChanged) {
1420 s_changedDocuments()->removeAll(
this);
1425 void DocumentImpl::recalcStyle(StyleChange change)
1430 if (m_inStyleRecalc) {
1434 m_inStyleRecalc =
true;
1440 if (change == Force) {
1441 RenderStyle *oldStyle = m_render->style();
1445 RenderStyle *_style =
new RenderStyle();
1446 _style->setDisplay(BLOCK);
1447 _style->setVisuallyOrdered(visuallyOrdered);
1450 FontDef fontDef = FontDef();
1452 fontDef.size = m_styleSelector->fontSizes()[3];
1453 _style->setFontDef(fontDef);
1454 _style->htmlFont().update(0);
1456 if (inCompatMode()) {
1457 _style->setHtmlHacks(
true);
1460 StyleChange ch = diff(_style, oldStyle);
1461 if (m_render && ch != NoChange) {
1462 m_render->setStyle(_style);
1473 for (n = _first; n; n = n->nextSibling())
1474 if (change >= Inherit || n->hasChangedChild() || n->changed()) {
1475 n->recalcStyle(change);
1479 if (changed() && m_view) {
1485 setHasChangedChild(
false);
1486 setDocumentChanged(
false);
1488 m_inStyleRecalc =
false;
1491 void DocumentImpl::updateRendering()
1493 if (!hasChangedChild()) {
1501 StyleChange change = NoChange;
1503 if (m_styleSelectorDirty) {
1504 recalcStyleSelector();
1508 recalcStyle(change);
1513 void DocumentImpl::updateDocumentsRendering()
1515 if (!s_changedDocuments()) {
1519 while (!s_changedDocuments()->isEmpty()) {
1521 if (it->isDocumentChanged()) {
1522 it->updateRendering();
1527 void DocumentImpl::updateLayout()
1529 if (ElementImpl *oe = ownerElement()) {
1530 oe->document()->updateLayout();
1533 bool oldIgnore = m_ignorePendingStylesheets;
1536 m_ignorePendingStylesheets =
true;
1543 if (m_view && renderer() && renderer()->needsLayout()) {
1547 m_ignorePendingStylesheets = oldIgnore;
1550 void DocumentImpl::attach()
1552 assert(!attached());
1555 setPaintDevice(m_view);
1558 if (!m_renderArena) {
1559 m_renderArena.reset(
new RenderArena());
1563 assert(!m_styleSelector);
1564 m_styleSelector =
new CSSStyleSelector(
this, m_usersheet, m_styleSheets, m_url,
1566 m_render =
new(m_renderArena.get()) RenderCanvas(
this, m_view);
1573 NodeBaseImpl::attach();
1577 void DocumentImpl::detach()
1585 m_tokenizer =
nullptr;
1588 m_imageLoadEventDispatchSoonList.
clear();
1589 m_imageLoadEventDispatchingList.
clear();
1590 NodeBaseImpl::detach();
1598 m_renderArena.reset();
1601 void DocumentImpl::setVisuallyOrdered()
1603 visuallyOrdered =
true;
1605 m_render->style()->setVisuallyOrdered(
true);
1609 void DocumentImpl::setSelection(NodeImpl *s,
int sp, NodeImpl *e,
int ep)
1612 static_cast<RenderCanvas *
>(m_render)->setSelection(s->renderer(), sp, e->renderer(), ep);
1616 void DocumentImpl::clearSelection()
1619 static_cast<RenderCanvas *
>(m_render)->clearSelection();
1623 void DocumentImpl::updateSelection()
1629 RenderCanvas *canvas =
static_cast<RenderCanvas *
>(m_render);
1630 Selection s = part()->caret();
1631 if (s.isEmpty() || s.state() == Selection::CARET) {
1632 canvas->clearSelection();
1634 RenderObject *startRenderer = s.start().node() ? s.start().node()->renderer() :
nullptr;
1635 RenderObject *endRenderer = s.end().node() ? s.end().node()->renderer() :
nullptr;
1636 RenderPosition renderedStart = RenderPosition::fromDOMPosition(s.start());
1637 RenderPosition renderedEnd = RenderPosition::fromDOMPosition(s.end());
1638 static_cast<RenderCanvas *
>(m_render)->setSelection(startRenderer, renderedStart.renderedOffset(), endRenderer, renderedEnd.renderedOffset());
1642 khtml::Tokenizer *DocumentImpl::createTokenizer()
1644 return new khtml::XMLTokenizer(docPtr(), m_view);
1647 int DocumentImpl::logicalDpiY()
1652 void DocumentImpl::open(
bool clearEventListeners)
1663 m_tokenizer =
nullptr;
1666 bool was_attached = attached();
1673 delete m_styleSelector;
1674 m_styleSelector =
nullptr;
1680 if (clearEventListeners) {
1681 windowEventTarget()->listenerList().clear();
1684 m_tokenizer = createTokenizer();
1686 connect(m_tokenizer, SIGNAL(finishedParsing()),
this, SIGNAL(finishedParsing()));
1687 m_tokenizer->begin();
1690 HTMLElementImpl *DocumentImpl::body()
const
1692 NodeImpl *de = documentElement();
1698 NodeImpl *body =
nullptr;
1699 for (NodeImpl *i = de->firstChild(); i; i = i->nextSibling()) {
1700 if (i->id() == ID_FRAMESET) {
1701 return static_cast<HTMLElementImpl *
>(i);
1704 if (i->id() == ID_BODY) {
1708 return static_cast<HTMLElementImpl *
>(body);
1711 void DocumentImpl::close()
1713 if (parsing() && hasVariableLength() && m_tokenizer) {
1714 m_tokenizer->finish();
1715 }
else if (parsing() || !m_tokenizer) {
1726 if (m_tokenizer && !m_tokenizer->isWaitingForScripts() && !m_tokenizer->isExecutingScript()) {
1728 m_tokenizer =
nullptr;
1732 m_view->
part()->checkEmitLoadEvent();
1736 void DocumentImpl::write(
const DOMString &text)
1738 write(text.string());
1741 void DocumentImpl::write(
const QString &text)
1746 m_view->
part()->resetFromScript();
1748 setHasVariableLength();
1750 m_tokenizer->write(text,
false);
1753 void DocumentImpl::writeln(
const DOMString &text)
1759 void DocumentImpl::finishParsing()
1762 m_tokenizer->finish();
1771 if (
ref.isEmpty()) {
1781 void DocumentImpl::setUserStyleSheet(
const QString &sheet)
1783 if (m_usersheet != sheet) {
1784 m_usersheet = sheet;
1789 CSSStyleSheetImpl *DocumentImpl::elementSheet()
1792 m_elemSheet =
new CSSStyleSheetImpl(
this, baseURL().url());
1798 void DocumentImpl::determineParseMode()
1803 m_htmlCompat =
false;
1815 int lowestTabIndex = SHRT_MAX + 1;
1816 for (n =
this; n !=
nullptr; n = n->traverseNextNode()) {
1817 if (n->isTabFocusable()) {
1818 if ((n->tabIndex() > 0) && (n->tabIndex() < lowestTabIndex)) {
1819 lowestTabIndex = n->tabIndex();
1824 if (lowestTabIndex == SHRT_MAX + 1) {
1829 for (n =
this; n !=
nullptr; n = n->traverseNextNode()) {
1830 if (n->isTabFocusable() && (n->tabIndex() == lowestTabIndex)) {
1837 fromTabIndex = fromNode->tabIndex();
1840 if (fromTabIndex == 0) {
1842 NodeImpl *n = fromNode->traverseNextNode();
1843 while (n && !(n->isTabFocusable() && n->tabIndex() == 0)) {
1844 n = n->traverseNextNode();
1852 int lowestSuitableTabIndex = SHRT_MAX + 1;
1855 bool reachedFromNode =
false;
1856 for (n =
this; n !=
nullptr; n = n->traverseNextNode()) {
1857 if (n->isTabFocusable() &&
1858 ((reachedFromNode && (n->tabIndex() >= fromTabIndex)) ||
1859 (!reachedFromNode && (n->tabIndex() > fromTabIndex))) &&
1860 (n->tabIndex() < lowestSuitableTabIndex) &&
1865 lowestSuitableTabIndex = n->tabIndex();
1868 if (n == fromNode) {
1869 reachedFromNode =
true;
1873 if (lowestSuitableTabIndex == SHRT_MAX + 1) {
1876 while (n && !(n->isTabFocusable() && n->tabIndex() == 0)) {
1877 n = n->traverseNextNode();
1883 for (n = fromNode->traverseNextNode(); n !=
nullptr; n = n->traverseNextNode()) {
1884 if (n->isTabFocusable() && (n->tabIndex() == lowestSuitableTabIndex)) {
1890 for (n =
this; n != fromNode; n = n->traverseNextNode()) {
1891 if (n->isTabFocusable() && (n->tabIndex() == lowestSuitableTabIndex)) {
1903 NodeImpl *lastNode =
this;
1904 while (lastNode->lastChild()) {
1905 lastNode = lastNode->lastChild();
1912 int highestTabIndex = 0;
1913 for (n = lastNode; n !=
nullptr; n = n->traversePreviousNode()) {
1914 if (n->isTabFocusable()) {
1915 if (n->tabIndex() == 0) {
1917 }
else if (n->tabIndex() > highestTabIndex) {
1918 highestTabIndex = n->tabIndex();
1924 for (n = lastNode; n !=
nullptr; n = n->traversePreviousNode()) {
1925 if (n->isTabFocusable() && (n->tabIndex() == highestTabIndex)) {
1932 short fromTabIndex = fromNode->tabIndex();
1934 if (fromTabIndex == 0) {
1936 NodeImpl *n = fromNode->traversePreviousNode();
1937 while (n && !(n->isTabFocusable() && n->tabIndex() == 0)) {
1938 n = n->traversePreviousNode();
1945 int highestTabIndex = 0;
1946 for (n =
this; n !=
nullptr; n = n->traverseNextNode()) {
1947 if (n->isTabFocusable() && (n->tabIndex() > highestTabIndex)) {
1948 highestTabIndex = n->tabIndex();
1952 if (highestTabIndex == 0) {
1956 for (n = lastNode; n !=
nullptr; n = n->traversePreviousNode()) {
1957 if (n->isTabFocusable() && (n->tabIndex() == highestTabIndex)) {
1969 short highestSuitableTabIndex = 0;
1972 bool reachedFromNode =
false;
1973 for (n =
this; n !=
nullptr; n = n->traverseNextNode()) {
1974 if (n->isTabFocusable() &&
1975 ((!reachedFromNode && (n->tabIndex() <= fromTabIndex)) ||
1976 (reachedFromNode && (n->tabIndex() < fromTabIndex))) &&
1977 (n->tabIndex() > highestSuitableTabIndex) &&
1982 highestSuitableTabIndex = n->tabIndex();
1985 if (n == fromNode) {
1986 reachedFromNode =
true;
1990 if (highestSuitableTabIndex == 0) {
1997 for (n = fromNode->traversePreviousNode(); n !=
nullptr; n = n->traversePreviousNode()) {
1998 if (n->isTabFocusable() && (n->tabIndex() == highestSuitableTabIndex)) {
2003 for (n = lastNode; n != fromNode; n = n->traversePreviousNode()) {
2004 if (n->isTabFocusable() && (n->tabIndex() == highestSuitableTabIndex)) {
2015 ElementImpl *DocumentImpl::findAccessKeyElement(
QChar c)
2018 for (NodeImpl *n =
this;
2020 n = n->traverseNextNode()) {
2021 if (n->isElementNode()) {
2022 ElementImpl *en =
static_cast< ElementImpl *
>(n);
2023 DOMString s = en->getAttribute(ATTR_ACCESSKEY);
2025 && s[ 0 ].toUpper() == c) {
2033 int DocumentImpl::nodeAbsIndex(NodeImpl *node)
2035 assert(node->document() ==
this);
2038 for (NodeImpl *n = node; n && n !=
this; n = n->traversePreviousNode()) {
2044 NodeImpl *DocumentImpl::nodeWithAbsIndex(
int absIndex)
2047 for (
int i = 0; n && (i < absIndex); i++) {
2048 n = n->traverseNextNode();
2055 assert(!equiv.isNull() && !content.isNull());
2059 if (strcasecmp(equiv,
"refresh") == 0 && v && v->
part()->metaRefreshEnabled()) {
2069 if (!ok && str.
length() && str[0] ==
'.') {
2079 while (pos < str.
length() && str[pos].isSpace()) {
2087 if (str.
length() && str[0] ==
'=') {
2091 (str[str.
length() - 1] ==
';' || str[str.
length() - 1] ==
',')) {
2095 const QString newURL = document()->completeURL(str);
2100 }
else if (strcasecmp(equiv,
"expires") == 0) {
2109 m_docLoader->setRelativeExpireDate(seconds);
2112 m_docLoader->setExpireDate(expire_date);
2116 }
else if (v && (strcasecmp(equiv,
"pragma") == 0 || strcasecmp(equiv,
"cache-control") == 0)) {
2122 }
else if ((strcasecmp(equiv,
"set-cookie") == 0)) {
2124 HTMLDocumentImpl *d =
static_cast<HTMLDocumentImpl *
>(
this);
2125 d->setCookie(content);
2126 }
else if (strcasecmp(equiv,
"default-style") == 0) {
2129 m_preferredStylesheetSet = content;
2131 }
else if (strcasecmp(equiv,
"content-language") == 0) {
2132 m_contentLanguage = content.string();
2136 bool DocumentImpl::prepareMouseEvent(
bool readonly,
int _x,
int _y,
MouseEvent *ev)
2139 assert(m_render->isCanvas());
2140 RenderObject::NodeInfo renderInfo(readonly, ev->
type == MousePress);
2141 bool isInside = m_render->layer()->nodeAtPoint(renderInfo, _x, _y);
2142 ev->innerNode = renderInfo.innerNode();
2143 ev->innerNonSharedNode = renderInfo.innerNonSharedNode();
2145 if (renderInfo.URLElement()) {
2146 assert(renderInfo.URLElement()->isElementNode());
2149 ElementImpl *e =
static_cast<ElementImpl *
>(renderInfo.URLElement());
2151 DOMString target = e->getAttribute(ATTR_TARGET);
2153 if (!target.isNull() && !href.isNull()) {
2172 bool DocumentImpl::childTypeAllowed(
unsigned short type)
2175 case Node::ATTRIBUTE_NODE:
2176 case Node::CDATA_SECTION_NODE:
2177 case Node::DOCUMENT_FRAGMENT_NODE:
2178 case Node::DOCUMENT_NODE:
2179 case Node::ENTITY_NODE:
2180 case Node::ENTITY_REFERENCE_NODE:
2181 case Node::NOTATION_NODE:
2182 case Node::TEXT_NODE:
2185 case Node::COMMENT_NODE:
2186 case Node::PROCESSING_INSTRUCTION_NODE:
2188 case Node::DOCUMENT_TYPE_NODE:
2189 case Node::ELEMENT_NODE:
2192 for (NodeImpl *c =
firstChild(); c; c = c->nextSibling())
2193 if (c->nodeType() == type) {
2201 WTF::PassRefPtr<NodeImpl> DocumentImpl::cloneNode(
bool deep)
2204 NodeImpl *dtn = m_doctype->cloneNode(deep);
2205 DocumentTypeImpl *dt =
static_cast<DocumentTypeImpl *
>(dtn);
2209 WTF::RefPtr<NodeImpl> clone = DOMImplementationImpl::createDocument(
"",
2213 assert(exceptioncode == 0);
2218 cloneChildNodes(clone.get());
2228 assert(m_pendingStylesheets > 0);
2230 m_pendingStylesheets--;
2232 if (!m_pendingStylesheets && m_tokenizer) {
2233 m_tokenizer->executeScriptsWaitingForStylesheets();
2239 m_pendingStylesheets++;
2242 DOMString DocumentImpl::selectedStylesheetSet()
const
2248 return view()->
part()->d->m_sheetUsed;
2251 void DocumentImpl::setSelectedStylesheetSet(
const DOMString &s)
2254 if (view() && view()->part()->d->m_sheetUsed != s.string()) {
2255 view()->
part()->d->m_sheetUsed = s.string();
2260 void DocumentImpl::addStyleSheet(StyleSheetImpl *sheet,
int *exceptioncode)
2264 if (!m_addedStyleSheets) {
2265 m_addedStyleSheets =
new StyleSheetListImpl;
2266 m_addedStyleSheets->ref();
2269 m_addedStyleSheets->add(sheet);
2270 if (sheet->isCSSStyleSheet()) {
2274 if (exceptioncode) {
2275 *exceptioncode = excode;
2279 void DocumentImpl::removeStyleSheet(StyleSheetImpl *sheet,
int *exceptioncode)
2282 bool removed =
false;
2283 bool is_css = sheet->isCSSStyleSheet();
2285 if (m_addedStyleSheets) {
2286 bool in_main_list = !sheet->hasOneRef();
2287 removed = m_addedStyleSheets->styleSheets.removeAll(sheet);
2290 if (m_addedStyleSheets->styleSheets.count() == 0) {
2291 bool reset = m_addedStyleSheets->hasOneRef();
2292 m_addedStyleSheets->deref();
2294 m_addedStyleSheets =
nullptr;
2300 m_styleSheets->remove(sheet);
2309 excode = DOMException::NOT_FOUND_ERR;
2312 if (exceptioncode) {
2313 *exceptioncode = excode;
2322 if (m_pendingStylesheets > 0) {
2326 m_styleSheetListDirty =
true;
2332 rebuildStyleSheetList();
2335 rebuildStyleSelector();
2340 m_styleSelectorDirty =
true;
2343 renderer()->setNeedsLayoutAndMinMaxRecalc();
2347 bool DocumentImpl::readyForLayout()
const
2349 return renderer() &&
haveStylesheetsLoaded() && (!isHTMLDocument() || (body() && body()->renderer()));
2352 void DocumentImpl::rebuildStyleSheetList(
bool force)
2354 if (!m_render || !attached()) {
2358 m_styleSheetListDirty =
true;
2364 m_styleSheetListDirty =
false;
2367 m_styleSheets->styleSheets.clear();
2368 QString sheetUsed = view() ? view()->
part()->d->m_sheetUsed.replace(
"&&",
"&") :
QString();
2369 bool autoselect = sheetUsed.
isEmpty();
2370 if (autoselect && !m_preferredStylesheetSet.isEmpty()) {
2371 sheetUsed = m_preferredStylesheetSet.string();
2374 for (
int i = 0; i < 2; i++) {
2375 m_availableSheets.
clear();
2376 m_availableSheets <<
i18n(
"Basic Page Style");
2377 bool canResetSheet =
false;
2380 for (n =
this; n; n = n->traverseNextNode()) {
2381 StyleSheetImpl *sheet =
nullptr;
2383 if (n->nodeType() == Node::PROCESSING_INSTRUCTION_NODE) {
2385 ProcessingInstructionImpl *pi =
static_cast<ProcessingInstructionImpl *
>(n);
2386 sheet = pi->sheet();
2387 if (!sheet && !pi->localHref().isEmpty()) {
2392 ElementImpl *elem = getElementById(pi->localHref());
2396 for (c = elem->firstChild(); c; c = c->nextSibling()) {
2397 if (c->nodeType() == Node::TEXT_NODE || c->nodeType() == Node::CDATA_SECTION_NODE) {
2398 sheetText += c->nodeValue();
2402 CSSStyleSheetImpl *cssSheet =
new CSSStyleSheetImpl(
this);
2403 cssSheet->parseString(sheetText);
2404 pi->setStyleSheet(cssSheet);
2409 title = sheet->title().string();
2410 if ((autoselect || title != sheetUsed) && sheet->disabled()) {
2412 }
else if (!title.
isEmpty() && !pi->isAlternate() && sheetUsed.
isEmpty()) {
2414 sheet->setDisabled(
false);
2417 }
else if (n->isHTMLElement() && (n->id() == ID_LINK || n->id() == ID_STYLE)) {
2418 if (n->id() == ID_LINK) {
2419 HTMLLinkElementImpl *l =
static_cast<HTMLLinkElementImpl *
>(n);
2420 if (l->isCSSStyleSheet()) {
2423 if (sheet || l->isLoading() || l->isAlternate()) {
2424 title = l->getAttribute(ATTR_TITLE).string();
2427 if ((autoselect || title != sheetUsed) && l->isDisabled()) {
2429 }
else if (!title.
isEmpty() && !l->isAlternate() && sheetUsed.
isEmpty()) {
2431 l->setDisabled(
false);
2436 HTMLStyleElementImpl *s =
static_cast<HTMLStyleElementImpl *
>(n);
2437 if (!s->isLoading()) {
2440 title = s->getAttribute(ATTR_TITLE).string();
2447 }
else if (n->isHTMLElement() && n->id() == ID_BODY) {
2450 sheet =
static_cast<HTMLBodyElementImpl *
>(n)->sheet();
2454 if (title != sheetUsed) {
2457 title = title.
replace(
'&',
"&&");
2458 if (!m_availableSheets.
contains(title)) {
2459 m_availableSheets.
append(title);
2466 m_styleSheets->styleSheets.append(sheet);
2471 if (isHTMLDocument() && n->id() == ID_BODY) {
2472 canResetSheet = !canResetSheet;
2480 (!canResetSheet && tokenizer()) ||
2481 m_availableSheets.
contains(sheetUsed)) {
2488 view()->
part()->d->m_sheetUsed.clear();
2490 if (!m_preferredStylesheetSet.isEmpty() && !(sheetUsed == m_preferredStylesheetSet)) {
2491 sheetUsed = m_preferredStylesheetSet.string();
2499 if (m_addedStyleSheets) {
2500 foreach (StyleSheetImpl *sh, m_addedStyleSheets->styleSheets) {
2501 if (sh->isCSSStyleSheet() && !sh->disabled()) {
2502 m_styleSheets->add(sh);
2508 foreach (StyleSheetImpl *sh, oldStyleSheets) {
2513 void DocumentImpl::rebuildStyleSelector()
2515 if (!m_render || !attached()) {
2520 delete m_styleSelector;
2521 QString usersheet = m_usersheet;
2522 if (m_view && m_view->mediaType() ==
"print") {
2523 usersheet += m_printSheet;
2525 m_styleSelector =
new CSSStyleSelector(
this, usersheet, m_styleSheets, m_url,
2528 m_styleSelectorDirty =
false;
2531 void DocumentImpl::setBaseURL(
const QUrl &_baseURL)
2533 m_baseURL = _baseURL;
2535 m_elemSheet->setHref(baseURL().toString());
2539 void DocumentImpl::setHoverNode(NodeImpl *newHoverNode)
2541 NodeImpl *oldHoverNode = m_hoverNode;
2543 newHoverNode->ref();
2545 m_hoverNode = newHoverNode;
2547 oldHoverNode->deref();
2551 void DocumentImpl::setActiveNode(NodeImpl *newActiveNode)
2553 NodeImpl *oldActiveNode = m_activeNode;
2554 if (newActiveNode) {
2555 newActiveNode->ref();
2557 m_activeNode = newActiveNode;
2558 if (oldActiveNode) {
2559 oldActiveNode->deref();
2563 void DocumentImpl::quietResetFocus()
2565 assert(m_focusNode !=
this);
2567 if (m_focusNode->active()) {
2568 setActiveNode(
nullptr);
2571 m_focusNode->setFocus(
false);
2572 m_focusNode->deref();
2574 m_focusNode =
nullptr;
2582 void DocumentImpl::setFocusNode(NodeImpl *newFocusNode)
2591 if (newFocusNode && !newFocusNode->isFocusable()) {
2596 if (newFocusNode && (newFocusNode->document() !=
this)) {
2600 if (m_focusNode != newFocusNode) {
2601 NodeImpl *oldFocusNode = m_focusNode;
2605 m_focusNode =
nullptr;
2609 if (oldFocusNode->active()) {
2610 oldFocusNode->setActive(
false);
2613 oldFocusNode->setFocus(
false);
2614 if (oldFocusNode->renderer() && oldFocusNode->renderer()->isWidget()) {
2616 RenderWidget *rw =
static_cast<RenderWidget *
>(oldFocusNode->renderer());
2617 if (rw->isRedirectedWidget()) {
2618 rw->handleFocusOut();
2622 oldFocusNode->dispatchHTMLEvent(EventImpl::BLUR_EVENT,
false,
false);
2623 oldFocusNode->dispatchUIEvent(EventImpl::DOMFOCUSOUT_EVENT);
2625 if ((oldFocusNode ==
this) && oldFocusNode->hasOneRef()) {
2626 oldFocusNode->deref();
2630 oldFocusNode->deref();
2636 if (!m_focusNode && newFocusNode) {
2638 m_focusNode = newFocusNode;
2640 m_focusNode->dispatchHTMLEvent(EventImpl::FOCUS_EVENT,
false,
false);
2641 if (m_focusNode != newFocusNode) {
2644 m_focusNode->dispatchUIEvent(EventImpl::DOMFOCUSIN_EVENT);
2645 if (m_focusNode != newFocusNode) {
2648 m_focusNode->setFocus();
2649 if (m_focusNode != newFocusNode) {
2656 if (!m_focusNode->renderer() || !m_focusNode->renderer()->isWidget()) {
2658 }
else if (
static_cast<RenderWidget *
>(m_focusNode->renderer())->widget()) {
2659 if (view()->isVisible()) {
2660 static_cast<RenderWidget *
>(m_focusNode->renderer())->widget()->setFocus();
2675 void DocumentImpl::setCSSTarget(NodeImpl *n)
2677 if (n == m_cssTarget) {
2682 m_cssTarget->setChanged();
2683 m_cssTarget->deref();
2692 void DocumentImpl::attachNodeIterator(NodeIteratorImpl *ni)
2694 m_nodeIterators.
append(ni);
2697 void DocumentImpl::detachNodeIterator(NodeIteratorImpl *ni)
2699 int i = m_nodeIterators.
indexOf(ni);
2705 void DocumentImpl::notifyBeforeNodeRemoval(NodeImpl *n)
2708 while (it.hasNext()) {
2709 it.next()->notifyBeforeNodeRemoval(n);
2713 bool DocumentImpl::isURLAllowed(
const QString &url)
const
2717 QUrl newURL(completeURL(url));
2718 newURL.setFragment(
QString());
2720 if (KHTMLGlobal::defaultHTMLSettings()->isAdFiltered(newURL.url())) {
2725 if (!thisPart || (thisPart->
onlyLocalReferences() && newURL.scheme() !=
"file" && newURL.scheme() !=
"data")) {
2736 bool foundSelfReference =
false;
2740 if (partURL == newURL) {
2741 if (foundSelfReference) {
2744 foundSelfReference =
true;
2751 void DocumentImpl::setDesignMode(
bool b)
2758 bool DocumentImpl::designMode()
const
2760 return part() ? part()->
isEditable() :
false;
2763 EventImpl *DocumentImpl::createEvent(
const DOMString &eventType,
int &exceptioncode)
2765 if (eventType ==
"UIEvents" || eventType ==
"UIEvent") {
2766 return new UIEventImpl();
2767 }
else if (eventType ==
"MouseEvents" || eventType ==
"MouseEvent") {
2768 return new MouseEventImpl();
2769 }
else if (eventType ==
"TextEvent") {
2770 return new TextEventImpl();
2771 }
else if (eventType ==
"KeyboardEvent") {
2772 return new KeyboardEventImpl();
2773 }
else if (eventType ==
"MutationEvents" || eventType ==
"MutationEvent") {
2774 return new MutationEventImpl();
2775 }
else if (eventType ==
"HTMLEvents" || eventType ==
"Events" ||
2776 eventType ==
"HTMLEvent" || eventType ==
"Event") {
2777 return new EventImpl();
2779 exceptioncode = DOMException::NOT_SUPPORTED_ERR;
2784 CSSStyleDeclarationImpl *DocumentImpl::getOverrideStyle(ElementImpl * , DOMStringImpl * )
2793 m_inSyncLoad->
exit();
2796 if (m_loadingXMLDoc) {
2797 m_loadingXMLDoc->deref(
this);
2799 m_loadingXMLDoc =
nullptr;
2802 void DocumentImpl::load(
const DOMString &uri)
2806 m_inSyncLoad->
exit();
2809 m_hadLoadError =
false;
2810 if (m_loadingXMLDoc) {
2811 m_loadingXMLDoc->deref(
this);
2821 m_docLoading =
true;
2822 m_loadingXMLDoc = m_docLoader->requestStyleSheet(uri.string(),
QString(),
"text/xml");
2824 if (!m_loadingXMLDoc) {
2825 m_docLoading =
false;
2829 m_loadingXMLDoc->ref(
this);
2831 if (!m_async && m_docLoading) {
2832 assert(!m_inSyncLoad);
2834 m_inSyncLoad->
exec();
2837 delete m_inSyncLoad;
2838 m_inSyncLoad =
nullptr;
2842 void DocumentImpl::loadXML(
const DOMString &source)
2848 dispatchHTMLEvent(EventImpl::LOAD_EVENT,
false,
false);
2853 if (!m_hadLoadError) {
2854 m_url =
QUrl(url.string());
2855 loadXML(khtml::isAcceptableCSSMimetype(mimetype) ? sheet :
"");
2858 m_docLoading =
false;
2861 m_inSyncLoad->
exit();
2864 assert(m_loadingXMLDoc !=
nullptr);
2865 m_loadingXMLDoc->deref(
this);
2866 m_loadingXMLDoc =
nullptr;
2869 void DocumentImpl::error(
int err,
const QString &text)
2871 m_docLoading =
false;
2874 m_inSyncLoad->
exit();
2877 m_hadLoadError =
true;
2879 int exceptioncode = 0;
2880 EventImpl *evt =
new EventImpl(EventImpl::ERROR_EVENT,
false,
false);
2882 evt->setMessage(KIO::buildErrorString(err, text));
2884 evt->setMessage(text);
2887 dispatchEvent(evt, exceptioncode,
true);
2890 assert(m_loadingXMLDoc !=
nullptr);
2891 m_loadingXMLDoc->deref(
this);
2892 m_loadingXMLDoc =
nullptr;
2895 void DocumentImpl::defaultEventHandler(EventImpl *evt)
2897 if (evt->id() == EventImpl::KHTML_CONTENTLOADED_EVENT && !evt->propagationStopped() && !evt->defaultPrevented()) {
2904 windowEventTarget()->listenerList().setHTMLEventListener(
id, listener);
2907 void DocumentImpl::setHTMLWindowEventListener(
unsigned id,
EventListener *listener)
2909 windowEventTarget()->listenerList().setHTMLEventListener(EventName::fromId(
id), listener);
2914 return windowEventTarget()->listenerList().getHTMLEventListener(
id);
2917 EventListener *DocumentImpl::getHTMLWindowEventListener(
unsigned id)
2919 return windowEventTarget()->listenerList().getHTMLEventListener(EventName::fromId(
id));
2924 windowEventTarget()->listenerList().addEventListener(
id, listener, useCapture);
2929 windowEventTarget()->listenerList().removeEventListener(
id, listener, useCapture);
2932 bool DocumentImpl::hasWindowEventListener(
EventName id)
2934 return windowEventTarget()->listenerList().hasEventListener(
id);
2939 return part() ? part()->createHTMLEventListener(code, name, node) :
nullptr;
2942 void DocumentImpl::dispatchImageLoadEventSoon(HTMLImageElementImpl *image)
2944 m_imageLoadEventDispatchSoonList.
append(image);
2945 if (!m_imageLoadEventTimer) {
2950 void DocumentImpl::removeImage(HTMLImageElementImpl *image)
2953 m_imageLoadEventDispatchSoonList.
removeAll(image);
2954 m_imageLoadEventDispatchingList.
removeAll(image);
2955 if (m_imageLoadEventDispatchSoonList.
isEmpty() && m_imageLoadEventTimer) {
2957 m_imageLoadEventTimer = 0;
2961 void DocumentImpl::dispatchImageLoadEventsNow()
2966 if (!m_imageLoadEventDispatchingList.
isEmpty()) {
2970 if (m_imageLoadEventTimer) {
2972 m_imageLoadEventTimer = 0;
2975 m_imageLoadEventDispatchingList = m_imageLoadEventDispatchSoonList;
2976 m_imageLoadEventDispatchSoonList.
clear();
2977 while (!m_imageLoadEventDispatchingList.
isEmpty()) {
2978 m_imageLoadEventDispatchingList.
takeFirst()->dispatchLoadEvent();
2980 m_imageLoadEventDispatchingList.
clear();
2985 assert(e->
timerId() == m_imageLoadEventTimer);
2987 dispatchImageLoadEventsNow();
2995 HTMLPartContainerElementImpl *DocumentImpl::ownerElement()
const
3001 ChildFrame *childFrame = childPart->d->m_frame;
3005 return childFrame->m_partContainerElement.data();
3008 khtml::SecurityOrigin *DocumentImpl::origin()
const
3011 m_origin = SecurityOrigin::create(URL());
3013 return m_origin.get();
3016 void DocumentImpl::setOrigin(khtml::SecurityOrigin *newOrigin)
3018 assert(origin()->isEmpty());
3019 m_origin = newOrigin;
3024 return origin()->domain();
3027 void DocumentImpl::setDomain(
const DOMString &newDomain)
3030 DOMString oldDomain = origin()->domain();
3034 int oldLength = oldDomain.length();
3035 int newLength = newDomain.length();
3036 if (newLength < oldLength) {
3039 if (test[oldLength - newLength - 1] ==
'.') {
3040 test.remove(0, oldLength - newLength);
3041 if (test == reference) {
3042 m_origin->setDomainFromDOM(reference.string());
3045 }
else if (oldLength == newLength) {
3049 if (oldDomain.
lower() == reference) {
3050 m_origin->setDomainFromDOM(reference.string());
3055 DOMString DocumentImpl::toString()
const
3059 for (NodeImpl *child =
firstChild(); child !=
nullptr; child = child->nextSibling()) {
3060 result += child->toString();
3066 void DOM::DocumentImpl::setRestoreState(
const QStringList &s)
3069 m_stateRestorePos = 0;
3072 KHTMLView *DOM::DocumentImpl::view()
const
3077 KHTMLPart *DOM::DocumentImpl::part()
const
3080 return view() ? view()->
part() :
nullptr;
3083 DynamicNodeListImpl::Cache *DOM::DocumentImpl::acquireCachedNodeListInfo(
3084 DynamicNodeListImpl::CacheFactory *factory, NodeImpl *base,
int type)
3088 DynamicNodeListImpl::CacheKey key(base, type);
3091 DynamicNodeListImpl::Cache *cached =
3092 (
type == DynamicNodeListImpl::UNCACHEABLE) ?
nullptr : m_nodeListCache.value(key.hash());
3095 if (cached->key == key) {
3105 DynamicNodeListImpl::Cache *newInfo = factory();
3107 newInfo->clear(
this);
3110 if (type != DynamicNodeListImpl::UNCACHEABLE) {
3112 m_nodeListCache.insert(key.hash(), newInfo);
3118 void DOM::DocumentImpl::releaseCachedNodeListInfo(DynamicNodeListImpl::Cache *entry)
3123 bool DOM::DocumentImpl::isSVGDocument()
const
3125 return (documentElement()->
id() == WebCore::SVGNames::svgTag.
id());
3128 const WebCore::SVGDocumentExtensions *DOM::DocumentImpl::svgExtensions()
3130 return m_svgExtensions;
3133 WebCore::SVGDocumentExtensions *DOM::DocumentImpl::accessSVGExtensions()
3135 if (!m_svgExtensions) {
3136 m_svgExtensions =
new WebCore::SVGDocumentExtensions(
this);
3138 return m_svgExtensions;
3144 JSEditor *DocumentImpl::jsEditor()
3147 m_jsEditor =
new JSEditor(
this);
3152 bool DocumentImpl::execCommand(
const DOMString &command,
bool userInterface,
const DOMString &value)
3155 return jsEditor()->execCommand(jsEditor()->commandImp(command), userInterface, value);
3158 bool DocumentImpl::queryCommandEnabled(
const DOMString &command)
3160 return jsEditor()->queryCommandEnabled(jsEditor()->commandImp(command));
3163 bool DocumentImpl::queryCommandIndeterm(
const DOMString &command)
3165 return jsEditor()->queryCommandIndeterm(jsEditor()->commandImp(command));
3168 bool DocumentImpl::queryCommandState(
const DOMString &command)
3170 return jsEditor()->queryCommandState(jsEditor()->commandImp(command));
3173 bool DocumentImpl::queryCommandSupported(
const DOMString &command)
3176 return jsEditor()->queryCommandSupported(jsEditor()->commandImp(command));
3181 return jsEditor()->queryCommandValue(jsEditor()->commandImp(command));
3187 khtml::XPathExpressionImpl *DocumentImpl::createExpression(
DOMString &expression,
3188 khtml::XPathNSResolverImpl *resolver,
3191 XPathExpressionImpl *cand =
new XPathExpressionImpl(expression, resolver);
3192 if ((exceptioncode = cand->parseExceptionCode())) {
3200 khtml::XPathNSResolverImpl *DocumentImpl::createNSResolver(NodeImpl *nodeResolver)
3202 return nodeResolver ?
new DefaultXPathNSResolverImpl(nodeResolver) : nullptr;
3205 khtml::XPathResultImpl *DocumentImpl::evaluate(
DOMString &expression,
3206 NodeImpl *contextNode,
3207 khtml::XPathNSResolverImpl *resolver,
3208 unsigned short type,
3209 khtml::XPathResultImpl * ,
3212 XPathExpressionImpl *expr = createExpression(expression, resolver, exceptioncode);
3213 if (exceptioncode) {
3218 XPathResultImpl *res = expr->evaluate(contextNode, type,
nullptr, exceptioncode);
3221 if (exceptioncode) {
3234 EventTargetImpl::Type WindowEventTargetImpl::eventTargetType()
const
3239 DocumentImpl *WindowEventTargetImpl::eventTargetDocument()
3244 KJS::Window *WindowEventTargetImpl::window()
3246 if (m_owner->part()) {
3247 return KJS::Window::retrieveWindow(m_owner->part());
3254 DocumentFragmentImpl::DocumentFragmentImpl(
DocumentImpl *doc) : NodeBaseImpl(doc)
3258 DOMString DocumentFragmentImpl::nodeName()
const
3260 return "#document-fragment";
3263 unsigned short DocumentFragmentImpl::nodeType()
const
3265 return Node::DOCUMENT_FRAGMENT_NODE;
3269 bool DocumentFragmentImpl::childTypeAllowed(
unsigned short type)
3272 case Node::ELEMENT_NODE:
3273 case Node::PROCESSING_INSTRUCTION_NODE:
3274 case Node::COMMENT_NODE:
3275 case Node::TEXT_NODE:
3276 case Node::CDATA_SECTION_NODE:
3277 case Node::ENTITY_REFERENCE_NODE:
3285 DOMString DocumentFragmentImpl::toString()
const
3289 for (NodeImpl *child =
firstChild(); child !=
nullptr; child = child->nextSibling()) {
3290 if (child->nodeType() == Node::COMMENT_NODE || child->nodeType() == Node::PROCESSING_INSTRUCTION_NODE) {
3293 result += child->toString();
3299 WTF::PassRefPtr<NodeImpl> DocumentFragmentImpl::cloneNode(
bool deep)
3301 WTF::RefPtr<DocumentFragmentImpl> clone =
new DocumentFragmentImpl(docPtr());
3303 cloneChildNodes(clone.get());
3310 DocumentTypeImpl::DocumentTypeImpl(DOMImplementationImpl *implementation,
DocumentImpl *doc,
3313 : NodeImpl(doc), m_implementation(implementation),
3314 m_qualifiedName(qualifiedName), m_publicId(publicId), m_systemId(systemId)
3316 m_implementation->ref();
3318 m_entities =
nullptr;
3319 m_notations =
nullptr;
3325 DocumentTypeImpl::~DocumentTypeImpl()
3327 m_implementation->deref();
3329 m_entities->deref();
3332 m_notations->deref();
3336 DOMString DocumentTypeImpl::toString()
const
3339 result += m_qualifiedName;
3340 if (!m_publicId.isEmpty()) {
3341 result +=
" PUBLIC \"";
3342 result += m_publicId;
3344 result += m_systemId;
3346 }
else if (!m_systemId.isEmpty()) {
3347 result +=
" SYSTEM \"";
3348 result += m_systemId;
3352 if (!m_subset.isEmpty()) {
3363 DOMString DocumentTypeImpl::nodeName()
const
3368 unsigned short DocumentTypeImpl::nodeType()
const
3370 return Node::DOCUMENT_TYPE_NODE;
3374 bool DocumentTypeImpl::childTypeAllowed(
unsigned short )
3379 WTF::PassRefPtr<NodeImpl> DocumentTypeImpl::cloneNode(
bool )
3381 DocumentTypeImpl *clone =
new DocumentTypeImpl(implementation(),
3389 NamedNodeMapImpl *DocumentTypeImpl::entities()
const
3392 m_entities =
new GenericRONamedNodeMapImpl(docPtr());
3398 NamedNodeMapImpl *DocumentTypeImpl::notations()
const
3401 m_notations =
new GenericRONamedNodeMapImpl(docPtr());
3407 void XMLDocumentImpl::close()
3409 bool doload = !parsing() && m_tokenizer;
3411 DocumentImpl::close();
3414 document()->dispatchWindowEvent(EventImpl::LOAD_EVENT,
false,
false);
3418 #include "moc_dom_docimpl.cpp"