diff options
author | Simon Hausmann <simon.hausmann@digia.com> | 2012-11-22 09:09:45 +0100 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@digia.com> | 2012-11-22 09:10:13 +0100 |
commit | 470286ecfe79d59df14944e5b5d34630fc739391 (patch) | |
tree | 43983212872e06cebefd2ae474418fa2908ca54c /Source/WebCore/dom/Document.cpp | |
parent | 23037105e948c2065da5a937d3a2396b0ff45c1e (diff) | |
download | qtwebkit-470286ecfe79d59df14944e5b5d34630fc739391.tar.gz |
Imported WebKit commit e89504fa9195b2063b2530961d4b73dd08de3242 (http://svn.webkit.org/repository/webkit/trunk@135485)
Change-Id: I03774e5ac79721c13ffa30d152537a74d0b12e66
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'Source/WebCore/dom/Document.cpp')
-rw-r--r-- | Source/WebCore/dom/Document.cpp | 166 |
1 files changed, 56 insertions, 110 deletions
diff --git a/Source/WebCore/dom/Document.cpp b/Source/WebCore/dom/Document.cpp index 0ba8c8b8c..383939850 100644 --- a/Source/WebCore/dom/Document.cpp +++ b/Source/WebCore/dom/Document.cpp @@ -51,8 +51,6 @@ #include "DOMSelection.h" #include "DOMWindow.h" #include "DateComponents.h" -#include "DeviceMotionController.h" -#include "DeviceOrientationController.h" #include "DocumentEventQueue.h" #include "DocumentFragment.h" #include "DocumentLoader.h" @@ -526,8 +524,6 @@ Document::Document(Frame* frame, const KURL& url, bool isXHTML, bool isHTML) if ((frame && frame->ownerElement()) || !url.isEmpty()) setURL(url); - m_axObjectCache = 0; - m_markers = adoptPtr(new DocumentMarkerController); if (m_frame) @@ -794,14 +790,13 @@ void Document::setCompatibilityMode(CompatibilityMode mode) { if (m_compatibilityModeLocked || mode == m_compatibilityMode) return; - ASSERT(m_styleSheetCollection->activeAuthorStyleSheets().isEmpty()); bool wasInQuirksMode = inQuirksMode(); m_compatibilityMode = mode; selectorQueryCache()->invalidate(); if (inQuirksMode() != wasInQuirksMode) { // All user stylesheets have to reparse using the different mode. - m_styleSheetCollection->clearPageUserSheet(); - m_styleSheetCollection->clearPageGroupUserSheets(); + m_styleSheetCollection->clearPageUserStyleSheet(); + m_styleSheetCollection->invalidateInjectedStyleSheetCache(); } } @@ -1394,7 +1389,7 @@ PassRefPtr<NodeList> Document::nodesFromRect(int centerX, int centerY, unsigned // When ignoreClipping is false, this method returns null for coordinates outside of the viewport. if (ignoreClipping) type |= HitTestRequest::IgnoreClipping; - else if (!frameView->visibleContentRect().intersects(HitTestResult::rectForPoint(point, topPadding, rightPadding, bottomPadding, leftPadding))) + else if (!frameView->visibleContentRect().intersects(HitTestLocation::rectForPoint(point, topPadding, rightPadding, bottomPadding, leftPadding))) return 0; if (allowShadowContent) type |= HitTestRequest::AllowShadowContent; @@ -1436,8 +1431,8 @@ static Node* nodeFromPoint(Frame* frame, RenderView* renderView, int x, int y, L if (!frameView) return 0; - float zoomFactor = frame->pageZoomFactor(); - IntPoint point = roundedIntPoint(FloatPoint(x * zoomFactor + frameView->scrollX(), y * zoomFactor + frameView->scrollY())); + float scaleFactor = frame->pageZoomFactor() * frame->frameScaleFactor(); + IntPoint point = roundedIntPoint(FloatPoint(x * scaleFactor + frameView->scrollX(), y * scaleFactor + frameView->scrollY())); if (!frameView->visibleContentRect().contains(point)) return 0; @@ -2171,99 +2166,36 @@ void Document::removeAllEventListeners() void Document::suspendActiveDOMObjects(ActiveDOMObject::ReasonForSuspension why) { ScriptExecutionContext::suspendActiveDOMObjects(why); - -#if ENABLE(DEVICE_ORIENTATION) - if (!page()) - return; - - if (DeviceMotionController* controller = DeviceMotionController::from(page())) - controller->suspendEventsForAllListeners(domWindow()); - if (DeviceOrientationController* controller = DeviceOrientationController::from(page())) - controller->suspendEventsForAllListeners(domWindow()); - -#endif } void Document::resumeActiveDOMObjects() { ScriptExecutionContext::resumeActiveDOMObjects(); - -#if ENABLE(DEVICE_ORIENTATION) - if (!page()) - return; - - if (DeviceMotionController* controller = DeviceMotionController::from(page())) - controller->resumeEventsForAllListeners(domWindow()); - if (DeviceOrientationController* controller = DeviceOrientationController::from(page())) - controller->resumeEventsForAllListeners(domWindow()); -#endif } void Document::clearAXObjectCache() { - // clear cache in top document - if (m_axObjectCache) { - // Clear the cache member variable before calling delete because attempts - // are made to access it during destruction. - AXObjectCache* axObjectCache = m_axObjectCache; - m_axObjectCache = 0; - delete axObjectCache; - return; - } - - // ask the top-level document to clear its cache - Document* doc = topDocument(); - if (doc != this) - doc->clearAXObjectCache(); + // Clear the cache member variable before calling delete because attempts + // are made to access it during destruction. + topDocument()->m_axObjectCache.release(); } bool Document::axObjectCacheExists() const { - if (m_axObjectCache) - return true; - - Document* doc = topDocument(); - if (doc != this) - return doc->axObjectCacheExists(); - - return false; + return topDocument()->m_axObjectCache; } - + AXObjectCache* Document::axObjectCache() const { // The only document that actually has a AXObjectCache is the top-level // document. This is because we need to be able to get from any WebCoreAXObject // to any other WebCoreAXObject on the same page. Using a single cache allows // lookups across nested webareas (i.e. multiple documents). - - if (m_axObjectCache) { - // return already known top-level cache - if (!ownerElement()) - return m_axObjectCache; - - // In some pages with frames, the cache is created before the sub-webarea is - // inserted into the tree. Here, we catch that case and just toss the old - // cache and start over. - // NOTE: This recovery may no longer be needed. I have been unable to trigger - // it again. See rdar://5794454 - // FIXME: Can this be fixed when inserting the subframe instead of now? - // FIXME: If this function was called to get the cache in order to remove - // an AXObject, we are now deleting the cache as a whole and returning a - // new empty cache that does not contain the AXObject! That should actually - // be OK. I am concerned about other cases like this where accessing the - // cache blows away the AXObject being operated on. - delete m_axObjectCache; - m_axObjectCache = 0; - } - - // ask the top-level document for its cache - Document* doc = topDocument(); - if (doc != this) - return doc->axObjectCache(); - - // this is the top-level document, so install a new cache - m_axObjectCache = new AXObjectCache(this); - return m_axObjectCache; + Document* topDocument = this->topDocument(); + ASSERT(topDocument == this || !m_axObjectCache); + if (!topDocument->m_axObjectCache) + topDocument->m_axObjectCache = adoptPtr(new AXObjectCache(this)); + return topDocument->m_axObjectCache.get(); } void Document::setVisuallyOrdered() @@ -3517,16 +3449,20 @@ void Document::getFocusableNodes(Vector<RefPtr<Node> >& nodes) void Document::setCSSTarget(Element* n) { - if (m_cssTarget) + if (m_cssTarget) { m_cssTarget->setNeedsStyleRecalc(); + invalidateParentDistributionIfNecessary(m_cssTarget, SelectRuleFeatureSet::RuleFeatureTarget); + } m_cssTarget = n; - if (n) + if (n) { n->setNeedsStyleRecalc(); + invalidateParentDistributionIfNecessary(n, SelectRuleFeatureSet::RuleFeatureTarget); + } } void Document::registerNodeListCache(DynamicNodeListCacheBase* list) { - if (list->type() != NodeListCollectionType) + if (list->hasIdNameCache()) m_nodeListCounts[InvalidateOnIdNameAttrChange]++; m_nodeListCounts[list->invalidationType()]++; if (list->isRootedAtDocument()) @@ -3535,7 +3471,7 @@ void Document::registerNodeListCache(DynamicNodeListCacheBase* list) void Document::unregisterNodeListCache(DynamicNodeListCacheBase* list) { - if (list->type() != NodeListCollectionType) + if (list->hasIdNameCache()) m_nodeListCounts[InvalidateOnIdNameAttrChange]--; m_nodeListCounts[list->invalidationType()]--; if (list->isRootedAtDocument()) { @@ -4443,11 +4379,6 @@ PassRefPtr<HTMLCollection> Document::plugins() return cachedCollection(DocEmbeds); } -PassRefPtr<HTMLCollection> Document::objects() -{ - return cachedCollection(DocObjects); -} - PassRefPtr<HTMLCollection> Document::scripts() { return cachedCollection(DocScripts); @@ -4673,7 +4604,7 @@ void Document::initSecurityContext() } if (Settings* settings = this->settings()) { - if (!settings->isWebSecurityEnabled()) { + if (!settings->webSecurityEnabled()) { // Web security is turned off. We should let this document access every other document. This is used primary by testing // harnesses for web sites. securityOrigin()->grantUniversalAccess(); @@ -5082,7 +5013,7 @@ void Document::requestFullScreenForElement(Element* element, unsigned short flag // The context object's node document fullscreen element stack is not empty and its top element // is not an ancestor of the context object. (NOTE: Ignore this requirement if the request was // made via the legacy Mozilla-style API.) - if (!m_fullScreenElementStack.isEmpty() && !m_fullScreenElementStack.first()->contains(element) && !inLegacyMozillaMode) + if (!m_fullScreenElementStack.isEmpty() && !m_fullScreenElementStack.last()->contains(element) && !inLegacyMozillaMode) break; // A descendant browsing context's document has a non-empty fullscreen element stack. @@ -5188,8 +5119,8 @@ void Document::webkitCancelFullScreen() // To achieve that aim, remove all the elements from the top document's stack except for the first before // calling webkitExitFullscreen(): - Deque<RefPtr<Element> > replacementFullscreenElementStack; - replacementFullscreenElementStack.prepend(topDocument()->webkitFullscreenElement()); + Vector<RefPtr<Element> > replacementFullscreenElementStack; + replacementFullscreenElementStack.append(topDocument()->webkitFullscreenElement()); topDocument()->m_fullScreenElementStack.swap(replacementFullscreenElementStack); topDocument()->webkitExitFullscreen(); @@ -5519,12 +5450,12 @@ void Document::popFullscreenElementStack() if (m_fullScreenElementStack.isEmpty()) return; - m_fullScreenElementStack.removeFirst(); + m_fullScreenElementStack.removeLast(); } void Document::pushFullscreenElementStack(Element* element) { - m_fullScreenElementStack.prepend(element); + m_fullScreenElementStack.append(element); } void Document::addDocumentToFullScreenChangeEventQueue(Document* doc) @@ -5539,6 +5470,21 @@ void Document::addDocumentToFullScreenChangeEventQueue(Document* doc) } #endif +#if ENABLE(DIALOG_ELEMENT) +void Document::addToTopLayer(Element* element) +{ + ASSERT(!m_topLayerElements.contains(element)); + m_topLayerElements.append(element); +} + +void Document::removeFromTopLayer(Element* element) +{ + size_t position = m_topLayerElements.find(element); + ASSERT(position != notFound); + m_topLayerElements.remove(position); +} +#endif + #if ENABLE(POINTER_LOCK) void Document::webkitExitPointerLock() { @@ -5736,7 +5682,7 @@ PassRefPtr<NodeList> Document::getItems(const String& typeNames) // In this case we need to create an empty string identifier to map such request in the cache. String localTypeNames = typeNames.isNull() ? MicroDataItemList::undefinedItemType() : typeNames; - return ensureRareData()->ensureNodeLists()->addCacheWithName<MicroDataItemList>(this, DynamicNodeList::MicroDataItemListType, localTypeNames); + return ensureRareData()->ensureNodeLists()->addCacheWithName<MicroDataItemList>(this, MicroDataItemListType, localTypeNames); } #endif @@ -5920,6 +5866,8 @@ void Document::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const { MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::DOM); ContainerNode::reportMemoryUsage(memoryObjectInfo); + TreeScope::reportMemoryUsage(memoryObjectInfo); + ScriptExecutionContext::reportMemoryUsage(memoryObjectInfo); info.addMember(m_styleResolver); info.addMember(m_url); info.addMember(m_baseURL); @@ -5958,20 +5906,20 @@ void Document::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const info.addMember(m_eventQueue); info.addMember(m_mediaCanStartListeners); info.addMember(m_pendingTasks); +#if ENABLE(LINK_PRERENDER) + info.addMember(m_prerenderer); +#endif } class ImmutableAttributeDataCacheKey { public: - ImmutableAttributeDataCacheKey(const QualifiedName& tagName, const Attribute* attributes, unsigned attributeCount) - : m_tagQName(tagName) - , m_attributes(attributes) + ImmutableAttributeDataCacheKey(const Attribute* attributes, unsigned attributeCount) + : m_attributes(attributes) , m_attributeCount(attributeCount) { } bool operator!=(const ImmutableAttributeDataCacheKey& other) const { - if (m_tagQName != other.m_tagQName) - return true; if (m_attributeCount != other.m_attributeCount) return true; return memcmp(m_attributes, other.m_attributes, sizeof(Attribute) * m_attributeCount); @@ -5979,12 +5927,10 @@ public: unsigned hash() const { - unsigned attributeHash = StringHasher::hashMemory(m_attributes, m_attributeCount * sizeof(Attribute)); - return WTF::pairIntHash(m_tagQName.localName().impl()->existingHash(), attributeHash); + return StringHasher::hashMemory(m_attributes, m_attributeCount * sizeof(Attribute)); } private: - QualifiedName m_tagQName; const Attribute* m_attributes; unsigned m_attributeCount; }; @@ -5999,11 +5945,11 @@ struct ImmutableAttributeDataCacheEntry { RefPtr<ElementAttributeData> value; }; -PassRefPtr<ElementAttributeData> Document::cachedImmutableAttributeData(const Element* element, const Vector<Attribute>& attributes) +PassRefPtr<ElementAttributeData> Document::cachedImmutableAttributeData(const Vector<Attribute>& attributes) { ASSERT(!attributes.isEmpty()); - ImmutableAttributeDataCacheKey cacheKey(element->tagQName(), attributes.data(), attributes.size()); + ImmutableAttributeDataCacheKey cacheKey(attributes.data(), attributes.size()); unsigned cacheHash = cacheKey.hash(); ImmutableAttributeDataCache::iterator cacheIterator = m_immutableAttributeDataCache.add(cacheHash, nullptr).iterator; @@ -6019,7 +5965,7 @@ PassRefPtr<ElementAttributeData> Document::cachedImmutableAttributeData(const El if (!cacheHash || cacheIterator->value) return attributeData.release(); - cacheIterator->value = adoptPtr(new ImmutableAttributeDataCacheEntry(ImmutableAttributeDataCacheKey(element->tagQName(), attributeData->immutableAttributeArray(), attributeData->length()), attributeData)); + cacheIterator->value = adoptPtr(new ImmutableAttributeDataCacheEntry(ImmutableAttributeDataCacheKey(attributeData->immutableAttributeArray(), attributeData->length()), attributeData)); return attributeData.release(); } |