⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 document.cpp

📁 linux下开源浏览器WebKit的源码,市面上的很多商用浏览器都是移植自WebKit
💻 CPP
📖 第 1 页 / 共 5 页
字号:
/* * Copyright (C) 1999 Lars Knoll (knoll@kde.org) *           (C) 1999 Antti Koivisto (koivisto@kde.org) *           (C) 2001 Dirk Mueller (mueller@kde.org) *           (C) 2006 Alexey Proskuryakov (ap@webkit.org) * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) * Copyright (C) 2008 David Levin (levin@chromium.org) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB.  If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */#include "config.h"#include "Document.h"#include "AnimationController.h"#include "AXObjectCache.h"#include "CDATASection.h"#include "CSSHelper.h"#include "CSSStyleSelector.h"#include "CSSStyleSheet.h"#include "CSSValueKeywords.h"#include "CString.h"#include "CachedCSSStyleSheet.h"#include "Comment.h"#include "Console.h"#include "CookieJar.h"#include "DOMImplementation.h"#include "DOMWindow.h"#include "DocLoader.h"#include "DocumentFragment.h"#include "DocumentLoader.h"#include "DocumentType.h"#include "EditingText.h"#include "Editor.h"#include "EntityReference.h"#include "Event.h"#include "EventHandler.h"#include "EventListener.h"#include "EventNames.h"#include "ExceptionCode.h"#include "FocusController.h"#include "Frame.h"#include "FrameLoader.h"#include "FrameTree.h"#include "FrameView.h"#include "HTMLAnchorElement.h"#include "HTMLBodyElement.h"#include "HTMLCanvasElement.h"#include "HTMLDocument.h"#include "HTMLElementFactory.h"#include "HTMLFrameOwnerElement.h"#include "HTMLHeadElement.h"#include "HTMLInputElement.h"#include "HTMLLinkElement.h"#include "HTMLMapElement.h"#include "HTMLNameCollection.h"#include "HTMLNames.h"#include "HTMLStyleElement.h"#include "HTMLTitleElement.h"#include "HTTPParsers.h"#include "HistoryItem.h"#include "HitTestRequest.h"#include "HitTestResult.h"#include "ImageLoader.h"#include "InspectorController.h"#include "KeyboardEvent.h"#include "Logging.h"#include "MessageEvent.h"#include "MouseEvent.h"#include "MouseEventWithHitTestResults.h"#include "MutationEvent.h"#include "NameNodeList.h"#include "NodeFilter.h"#include "NodeIterator.h"#include "NodeWithIndex.h"#include "OverflowEvent.h"#include "Page.h"#include "PlatformKeyboardEvent.h"#include "ProcessingInstruction.h"#include "ProgressEvent.h"#include "RegisteredEventListener.h"#include "RenderArena.h"#include "RenderTextControl.h"#include "RenderView.h"#include "RenderWidget.h"#include "ScriptController.h"#include "SecurityOrigin.h"#include "SegmentedString.h"#include "SelectionController.h"#include "Settings.h"#include "StyleSheetList.h"#include "TextEvent.h"#include "TextIterator.h"#include "TextResourceDecoder.h"#include "TreeWalker.h"#include "Timer.h"#include "UIEvent.h"#include "WebKitAnimationEvent.h"#include "WebKitTransitionEvent.h"#include "WheelEvent.h"#include "XMLHttpRequest.h"#include "XMLNames.h"#include "XMLTokenizer.h"#include "JSDOMBinding.h"#include "ScriptController.h"#include <wtf/CurrentTime.h>#include <wtf/HashFunctions.h>#include <wtf/MainThread.h>#include <wtf/StdLibExtras.h>#include <wtf/PassRefPtr.h>#if ENABLE(DATABASE)#include "Database.h"#include "DatabaseThread.h"#endif#if ENABLE(DOM_STORAGE)#include "StorageEvent.h"#endif#if ENABLE(XPATH)#include "XPathEvaluator.h"#include "XPathExpression.h"#include "XPathNSResolver.h"#include "XPathResult.h"#endif#if ENABLE(XSLT)#include "XSLTProcessor.h"#endif#if ENABLE(XBL)#include "XBLBindingManager.h"#endif#if ENABLE(SVG)#include "SVGDocumentExtensions.h"#include "SVGElementFactory.h"#include "SVGZoomEvent.h"#include "SVGStyleElement.h"#endif#if ENABLE(WML)#include "WMLDocument.h"#include "WMLElement.h"#include "WMLElementFactory.h"#include "WMLNames.h"#endifusing namespace std;using namespace WTF;using namespace Unicode;namespace WebCore {using namespace HTMLNames;// #define INSTRUMENT_LAYOUT_SCHEDULING 1// This amount of time must have elapsed before we will even consider scheduling a layout without a delay.// FIXME: For faster machines this value can really be lowered to 200.  250 is adequate, but a little high// for dual G5s. :)static const int cLayoutScheduleThreshold = 250;// Use 1 to represent the document's default form.static HTMLFormElement* const defaultForm = reinterpret_cast<HTMLFormElement*>(1);// DOM Level 2 says (letters added)://// a) Name start characters must have one of the categories Ll, Lu, Lo, Lt, Nl.// b) Name characters other than Name-start characters must have one of the categories Mc, Me, Mn, Lm, or Nd.// c) Characters in the compatibility area (i.e. with character code greater than #xF900 and less than #xFFFE) are not allowed in XML names.// d) Characters which have a font or compatibility decomposition (i.e. those with a "compatibility formatting tag" in field 5 of the database -- marked by field 5 beginning with a "<") are not allowed.// e) The following characters are treated as name-start characters rather than name characters, because the property file classifies them as Alphabetic: [#x02BB-#x02C1], #x0559, #x06E5, #x06E6.// f) Characters #x20DD-#x20E0 are excluded (in accordance with Unicode, section 5.14).// g) Character #x00B7 is classified as an extender, because the property list so identifies it.// h) Character #x0387 is added as a name character, because #x00B7 is its canonical equivalent.// i) Characters ':' and '_' are allowed as name-start characters.// j) Characters '-' and '.' are allowed as name characters.//// It also contains complete tables. If we decide it's better, we could include those instead of the following code.static inline bool isValidNameStart(UChar32 c){    // rule (e) above    if ((c >= 0x02BB && c <= 0x02C1) || c == 0x559 || c == 0x6E5 || c == 0x6E6)        return true;    // rule (i) above    if (c == ':' || c == '_')        return true;    // rules (a) and (f) above    const uint32_t nameStartMask = Letter_Lowercase | Letter_Uppercase | Letter_Other | Letter_Titlecase | Number_Letter;    if (!(Unicode::category(c) & nameStartMask))        return false;    // rule (c) above    if (c >= 0xF900 && c < 0xFFFE)        return false;    // rule (d) above    DecompositionType decompType = decompositionType(c);    if (decompType == DecompositionFont || decompType == DecompositionCompat)        return false;    return true;}static inline bool isValidNamePart(UChar32 c){    // rules (a), (e), and (i) above    if (isValidNameStart(c))        return true;    // rules (g) and (h) above    if (c == 0x00B7 || c == 0x0387)        return true;    // rule (j) above    if (c == '-' || c == '.')        return true;    // rules (b) and (f) above    const uint32_t otherNamePartMask = Mark_NonSpacing | Mark_Enclosing | Mark_SpacingCombining | Letter_Modifier | Number_DecimalDigit;    if (!(Unicode::category(c) & otherNamePartMask))        return false;    // rule (c) above    if (c >= 0xF900 && c < 0xFFFE)        return false;    // rule (d) above    DecompositionType decompType = decompositionType(c);    if (decompType == DecompositionFont || decompType == DecompositionCompat)        return false;    return true;}static Widget* widgetForNode(Node* focusedNode){    if (!focusedNode)        return 0;    RenderObject* renderer = focusedNode->renderer();    if (!renderer || !renderer->isWidget())        return 0;    return static_cast<RenderWidget*>(renderer)->widget();}static bool acceptsEditingFocus(Node *node){    ASSERT(node);    ASSERT(node->isContentEditable());    Node *root = node->rootEditableElement();    Frame* frame = node->document()->frame();    if (!frame || !root)        return false;    return frame->editor()->shouldBeginEditing(rangeOfContents(root).get());}static HashSet<Document*>* changedDocuments = 0;Document::Document(Frame* frame, bool isXHTML)    : ContainerNode(0)    , m_domtree_version(0)    , m_styleSheets(StyleSheetList::create(this))    , m_frameElementsShouldIgnoreScrolling(false)    , m_title("")    , m_titleSetExplicitly(false)    , m_imageLoadEventTimer(this, &Document::imageLoadEventTimerFired)    , m_updateFocusAppearanceTimer(this, &Document::updateFocusAppearanceTimerFired)#if ENABLE(XSLT)    , m_transformSource(0)#endif    , m_xmlVersion("1.0")    , m_xmlStandalone(false)#if ENABLE(XBL)    , m_bindingManager(new XBLBindingManager(this))#endif    , m_savedRenderer(0)    , m_secureForms(0)    , m_designMode(inherit)    , m_selfOnlyRefCount(0)#if ENABLE(SVG)    , m_svgExtensions(0)#endif#if ENABLE(DASHBOARD_SUPPORT)    , m_hasDashboardRegions(false)    , m_dashboardRegionsDirty(false)#endif    , m_accessKeyMapValid(false)    , m_createRenderers(true)    , m_inPageCache(false)    , m_useSecureKeyboardEntryWhenActive(false)    , m_isXHTML(isXHTML)    , m_numNodeListCaches(0)#if ENABLE(DATABASE)    , m_hasOpenDatabases(false)#endif    , m_usingGeolocation(false){    m_document.resetSkippingRef(this);    m_printing = false;        m_ignoreAutofocus = false;    m_frame = frame;    m_renderArena = 0;    m_axObjectCache = 0;        m_docLoader = new DocLoader(this);    visuallyOrdered = false;    m_bParsing = false;    m_docChanged = false;    m_tokenizer = 0;    m_wellFormed = false;    setParseMode(Strict);    m_textColor = Color::black;    m_listenerTypes = 0;    m_inDocument = true;    m_inStyleRecalc = false;    m_closeAfterStyleRecalc = false;    m_usesDescendantRules = false;    m_usesSiblingRules = false;    m_usesFirstLineRules = false;    m_usesFirstLetterRules = false;    m_usesBeforeAfterRules = false;    m_gotoAnchorNeededAfterStylesheetsLoad = false;     m_styleSelector = 0;    m_didCalculateStyleSelector = false;    m_pendingStylesheets = 0;    m_ignorePendingStylesheets = false;    m_hasNodesWithPlaceholderStyle = false;    m_pendingSheetLayout = NoLayoutWithPendingSheets;    m_cssTarget = 0;    resetLinkColor();    resetVisitedLinkColor();    resetActiveLinkColor();    m_processingLoadEvent = false;    m_startTime = currentTime();    m_overMinimumLayoutThreshold = false;        initSecurityContext();    initDNSPrefetch();    static int docID = 0;    m_docID = docID++;}void Document::removedLastRef(){    ASSERT(!m_deletionHasBegun);    if (m_selfOnlyRefCount) {        // If removing a child removes the last self-only ref, we don't        // want the document to be destructed until after        // removeAllChildren returns, so we guard ourselves with an        // extra self-only ref.        DocPtr<Document> guard(this);        // We must make sure not to be retaining any of our children through        // these extra pointers or we will create a reference cycle.        m_docType = 0;        m_focusedNode = 0;        m_hoverNode = 0;        m_activeNode = 0;        m_titleElement = 0;        m_documentElement = 0;        removeAllChildren();        deleteAllValues(m_markers);        m_markers.clear();        delete m_tokenizer;        m_tokenizer = 0;        m_cssCanvasElements.clear();#ifndef NDEBUG        m_inRemovedLastRefFunction = false;#endif    } else {#ifndef NDEBUG        m_deletionHasBegun = true;#endif        delete this;    }}Document::~Document(){    ASSERT(!renderer());

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -