source: webkit/trunk/Source/WebCore/xml/XPathNodeSet.cpp

Last change on this file was 283851, checked in by [email protected], 4 years ago

[Build-time perf] Forward-declare more things in Element.h
https://bugs.webkit.org/show_bug.cgi?id=231283

Reviewed by Myles C. Maxfield.

Source/JavaScriptCore:

Add two new forwarding headers: one for Strong, and as a dependency, one for Handle.

  • CMakeLists.txt:
  • JavaScriptCore.xcodeproj/project.pbxproj:
  • heap/Handle.h:
  • heap/HandleForward.h: Copied from Source/JavaScriptCore/runtime/Forward.h.
  • heap/Strong.h:
  • heap/StrongForward.h: Copied from Source/JavaScriptCore/runtime/Forward.h.
  • runtime/Forward.h:

Source/WebCore:

Replace as many #includes as possible with forward type declarations. To do so, split out the inline function
definitions into their own ElementInlines.h header.

Move MediaKeyMessageEventInit into its own .idl to allow the bindings generator code to include
the two files separately, and to allow MediaKeyMessageEventInit to be forward-declared in MediaKeyMessageEvent.h.

Move Event's enums into their own EventOptions.h header that allows those enums to be forward declared.

Move ScrollExtents into its own ScrollExtents.h header, so that ScrollTypes.h can be freely #included without
pulling in geometry and math headers.

Modify some of the parameters to methods in HTMLMediaElement.h to be passed by reference or r-value reference,
allowing those types to be forward-declared.

Because the SVG and RenderSVG classes rely on ElementInlines.h, their inline methods must be inlined
as well, to ensure ElementInlines.h doesn't leak out into header includes generally.

With these changes in place, the net cost of Element.h during a typical build has gone from ~750s to ~57s.

  • CMakeLists.txt:
  • DerivedSources-input.xcfilelist:
  • DerivedSources-output.xcfilelist:
  • DerivedSources.make:
  • Headers.cmake:
  • Modules/encryptedmedia/MediaKeyMessageEvent.cpp:

(WebCore::MediaKeyMessageEvent::message const):

  • Modules/encryptedmedia/MediaKeyMessageEvent.h:
  • Modules/encryptedmedia/MediaKeyMessageEvent.idl:
  • Modules/encryptedmedia/MediaKeyMessageEventInit.idl: Added.
  • Modules/encryptedmedia/MediaKeyMessageType.idl: Added.
  • Modules/encryptedmedia/MediaKeySession.cpp:
  • Modules/entriesapi/HTMLInputElementEntriesAPI.cpp:
  • Modules/highlight/AppHighlightStorage.cpp:
  • Modules/model-element/HTMLModelElement.cpp:
  • Modules/remoteplayback/RemotePlayback.cpp:
  • Sources.txt:
  • WebCore.xcodeproj/project.pbxproj:
  • accessibility/AccessibilityListBoxOption.cpp:
  • accessibility/AccessibilityRenderObject.cpp:
  • accessibility/AccessibilitySVGElement.cpp:
  • accessibility/AccessibilitySVGRoot.cpp:
  • accessibility/atk/WebKitAccessible.cpp:
  • bindings/js/JSNodeCustom.h:
  • bindings/scripts/CodeGenerator.pm:

(GetterExpression):

  • bindings/scripts/test/JS/JSTestCEReactions.cpp:
  • bindings/scripts/test/JS/JSTestInterface.cpp:
  • bindings/scripts/test/JS/JSTestObj.cpp:
  • css/CSSCursorImageValue.cpp:
  • css/CSSFontFaceSource.cpp:
  • css/CSSStyleSheet.cpp:
  • css/SelectorChecker.cpp:
  • dom/ContainerNode.cpp:
  • dom/DataTransferMac.mm:
  • dom/DatasetDOMStringMap.cpp:
  • dom/Document.cpp:
  • dom/DocumentInlines.h: Added.

(WebCore::Document::textEncoding const):
(WebCore::Document::templateDocument const):
(WebCore::Document::existingAXObjectCache const):
(WebCore::Document::create):
(WebCore::Document::invalidateAccessKeyCache):
(WebCore::Node::scriptExecutionContext const):

  • dom/Element.cpp:
  • dom/Element.h:

(WebCore::Element::attributesIterator const): Deleted.
(WebCore::Element::findAttributeIndexByName const): Deleted.
(WebCore::Node::hasAttributes const): Deleted.
(WebCore::Node::attributes const): Deleted.
(WebCore::Node::parentElement const): Deleted.
(WebCore::Element::rootElement const): Deleted.
(WebCore::Element::hasAttributeWithoutSynchronization const): Deleted.
(WebCore::Element::attributeWithoutSynchronization const): Deleted.
(WebCore::Element::hasAttributesWithoutUpdate const): Deleted.
(WebCore::Element::idForStyleResolution const): Deleted.
(WebCore::Element::getIdAttribute const): Deleted.
(WebCore::Element::getNameAttribute const): Deleted.
(WebCore::Element::setIdAttribute): Deleted.
(WebCore::Element::classNames const): Deleted.
(WebCore::Element::attributeCount const): Deleted.
(WebCore::Element::attributeAt const): Deleted.
(WebCore::Element::findAttributeByName const): Deleted.
(WebCore::Element::hasID const): Deleted.
(WebCore::Element::hasClass const): Deleted.
(WebCore::Element::hasName const): Deleted.
(WebCore::Element::ensureUniqueElementData): Deleted.
(WebCore::shouldIgnoreAttributeCase): Deleted.
(WebCore::Element::getAttribute const): Deleted.
(WebCore::isInTopLayerOrBackdrop): Deleted.

  • dom/ElementInlines.h: Added.

(WebCore::Element::attributesIterator const):
(WebCore::Element::findAttributeIndexByName const):
(WebCore::Node::hasAttributes const):
(WebCore::Node::attributes const):
(WebCore::Node::parentElement const):
(WebCore::Element::rootElement const):
(WebCore::Element::hasAttributeWithoutSynchronization const):
(WebCore::Element::attributeWithoutSynchronization const):
(WebCore::Element::hasAttributesWithoutUpdate const):
(WebCore::Element::idForStyleResolution const):
(WebCore::Element::getIdAttribute const):
(WebCore::Element::getNameAttribute const):
(WebCore::Element::setIdAttribute):
(WebCore::Element::classNames const):
(WebCore::Element::attributeCount const):
(WebCore::Element::attributeAt const):
(WebCore::Element::findAttributeByName const):
(WebCore::Element::hasID const):
(WebCore::Element::hasClass const):
(WebCore::Element::hasName const):
(WebCore::Element::ensureUniqueElementData):
(WebCore::shouldIgnoreAttributeCase):
(WebCore::Element::getAttribute const):
(WebCore::isInTopLayerOrBackdrop):

  • dom/ElementIterator.h:
  • dom/ElementIteratorAssertions.h:
  • dom/Event.h:
  • dom/EventOptions.h: Added.
  • dom/FullscreenManager.cpp:
  • dom/InlineClassicScript.cpp:
  • dom/InlineStyleSheetOwner.cpp:
  • dom/NamedNodeMap.cpp:
  • dom/Node.h:
  • dom/Position.cpp:
  • dom/Range.cpp:
  • dom/ScriptElement.cpp:
  • dom/ShadowRoot.cpp:
  • dom/SlotAssignment.cpp:
  • dom/StyledElement.cpp:
  • dom/StyledElement.h:
  • dom/Text.cpp:
  • dom/VisitedLinkState.cpp:
  • editing/Editing.cpp:
  • editing/EditingStyle.cpp:
  • editing/EditorCommand.cpp:
  • editing/FrameSelection.h:
  • editing/MarkupAccumulator.cpp:
  • editing/ModifySelectionListLevel.cpp:
  • editing/TextIterator.cpp:
  • editing/cocoa/HTMLConverter.mm:
  • editing/cocoa/WebContentReaderCocoa.mm:
  • editing/gtk/EditorGtk.cpp:
  • html/Autofill.cpp:
  • html/BaseTextInputType.cpp:
  • html/DateInputType.cpp:
  • html/DateTimeLocalInputType.cpp:
  • html/FeaturePolicy.cpp:
  • html/FormAssociatedElement.cpp:
  • html/HTMLAnchorElement.h:

(WebCore::HTMLAnchorElement::visitedLinkHash const): Deleted.

  • html/HTMLAnchorElementInlines.h: Added.

(WebCore::HTMLAnchorElement::visitedLinkHash const):

  • html/HTMLAreaElement.cpp:
  • html/HTMLAttachmentElement.cpp:
  • html/HTMLBaseElement.cpp:
  • html/HTMLBodyElement.cpp:
  • html/HTMLButtonElement.cpp:
  • html/HTMLCanvasElement.cpp:
  • html/HTMLCanvasElement.h:
  • html/HTMLElement.h:
  • html/HTMLFormControlElement.cpp:

(WebCore::HTMLFormControlElement::resultForDialogSubmit const):

  • html/HTMLFormControlElement.h:

(WebCore::HTMLFormControlElement::resultForDialogSubmit const): Deleted.

  • html/HTMLFrameElementBase.cpp:
  • html/HTMLFrameOwnerElement.cpp:
  • html/HTMLHtmlElement.cpp:
  • html/HTMLIFrameElement.cpp:
  • html/HTMLImageElement.h:
  • html/HTMLLinkElement.cpp:
  • html/HTMLMarqueeElement.cpp:
  • html/HTMLMediaElement.h:
  • html/HTMLMetaElement.cpp:
  • html/HTMLParamElement.cpp:
  • html/HTMLPlugInImageElement.cpp:
  • html/HTMLScriptElement.cpp:
  • html/HTMLSlotElement.cpp:
  • html/HTMLSourceElement.cpp:
  • html/HTMLTableCellElement.cpp:
  • html/HTMLTableColElement.cpp:
  • html/HTMLTrackElement.cpp:
  • html/HTMLVideoElement.cpp:
  • html/ImageInputType.cpp:
  • html/InputType.cpp:
  • html/MediaElementSession.cpp:
  • html/MonthInputType.cpp:
  • html/NumberInputType.cpp:
  • html/TextFieldInputType.cpp:
  • html/TimeInputType.cpp:
  • html/ValidationMessage.cpp:
  • html/WeekInputType.cpp:
  • html/parser/HTMLConstructionSite.cpp:
  • html/parser/HTMLConstructionSite.h:
  • html/parser/HTMLTreeBuilder.cpp:
  • html/track/DataCue.cpp:
  • html/track/InbandGenericTextTrack.cpp:
  • html/track/InbandTextTrack.cpp:
  • html/track/LoadableTextTrack.cpp:
  • html/track/TextTrackCue.cpp:
  • html/track/TextTrackCue.h:
  • html/track/VTTRegion.h:
  • html/track/WebVTTElement.cpp:
  • html/track/WebVTTParser.cpp:
  • inspector/InspectorOverlay.cpp:
  • inspector/InspectorStyleSheet.cpp:
  • inspector/agents/InspectorPageAgent.cpp:
  • loader/FormSubmission.cpp:
  • loader/FrameLoader.cpp:
  • loader/ImageLoader.cpp:
  • loader/cache/CachedImage.cpp:
  • loader/cache/CachedResourceLoader.cpp:
  • loader/cache/CachedResourceLoader.h:
  • loader/cache/CachedResourceRequest.h:
  • mathml/MathMLAnnotationElement.cpp:
  • mathml/MathMLElement.cpp:
  • mathml/MathMLFractionElement.cpp:
  • mathml/MathMLMencloseElement.cpp:
  • mathml/MathMLOperatorElement.cpp:
  • mathml/MathMLPresentationElement.cpp:
  • mathml/MathMLSelectElement.cpp:
  • page/CaptionUserPreferences.h:
  • page/DragController.cpp:
  • page/EventHandler.cpp:
  • page/Frame.cpp:
  • page/FrameView.cpp:
  • page/IntersectionObserver.h:
  • page/KeyboardScroll.h:
  • page/PageSerializer.cpp:
  • page/Quirks.cpp:
  • page/mac/ImageOverlayControllerMac.mm:
  • page/mac/PageMac.mm:
  • page/scrolling/mac/ScrollingTreeScrollingNodeDelegateMac.mm:
  • page/scrolling/nicosia/ScrollingTreeScrollingNodeDelegateNicosia.cpp:
  • platform/ScrollAnimation.h:
  • platform/ScrollAnimationKinetic.cpp:
  • platform/ScrollAnimationSmooth.cpp:
  • platform/ScrollAnimator.cpp:
  • platform/ScrollAnimator.h:
  • platform/ScrollExtents.h: Added.

(WebCore::ScrollExtents::minimumScrollOffset const):
(WebCore::ScrollExtents::maximumScrollOffset const):

  • platform/ScrollSnapAnimatorState.cpp:
  • platform/ScrollSnapAnimatorState.h:
  • platform/ScrollTypes.h:

(WebCore::logicalToPhysical):
(WebCore::ScrollExtents::minimumScrollOffset const): Deleted.
(WebCore::ScrollExtents::maximumScrollOffset const): Deleted.

  • platform/ScrollingEffectsController.cpp:
  • platform/ScrollingEffectsController.h:
  • platform/ScrollingMomentumCalculator.h:
  • platform/SharedBuffer.cpp:
  • platform/SharedBuffer.h:
  • platform/audio/cocoa/MediaSessionManagerCocoa.mm:
  • platform/encryptedmedia/CDMLogging.cpp:
  • platform/mac/ScrollingEffectsController.mm:
  • platform/win/PasteboardWin.cpp:
  • rendering/CSSFilter.cpp:
  • rendering/HitTestResult.cpp:
  • rendering/LegacyLineLayout.cpp:
  • rendering/ReferencedSVGResources.cpp:
  • rendering/RenderBlockFlow.cpp:
  • rendering/RenderBox.cpp:
  • rendering/RenderDetailsMarker.cpp:
  • rendering/RenderElement.cpp:
  • rendering/RenderImage.cpp:
  • rendering/RenderLayer.cpp:
  • rendering/RenderLineBreak.cpp:
  • rendering/RenderListItem.cpp:
  • rendering/RenderMenuList.cpp:
  • rendering/RenderObject.h:
  • rendering/RenderSearchField.cpp:
  • rendering/RenderTableCell.cpp:
  • rendering/RenderText.cpp:
  • rendering/RenderThemeMac.mm:
  • rendering/RenderTreeAsText.cpp:
  • rendering/mathml/RenderMathMLFenced.cpp:
  • rendering/svg/RenderSVGBlock.cpp:
  • rendering/svg/RenderSVGBlock.h:

(WebCore::RenderSVGBlock::graphicsElement const): Deleted.

  • rendering/svg/RenderSVGBlockInlines.h: Added.

(WebCore::RenderSVGBlock::graphicsElement const):

  • rendering/svg/RenderSVGEllipse.cpp:
  • rendering/svg/RenderSVGForeignObject.cpp:
  • rendering/svg/RenderSVGGradientStop.cpp:
  • rendering/svg/RenderSVGGradientStop.h:
  • rendering/svg/RenderSVGGradientStopInlines.h: Added.

(WebCore::RenderSVGGradientStop::element const):

  • rendering/svg/RenderSVGImage.cpp:
  • rendering/svg/RenderSVGInline.h:

(WebCore::RenderSVGInline::graphicsElement const): Deleted.

  • rendering/svg/RenderSVGInlineInlines.h: Added.

(WebCore::RenderSVGInline::graphicsElement const):

  • rendering/svg/RenderSVGInlineText.cpp:
  • rendering/svg/RenderSVGRect.cpp:
  • rendering/svg/RenderSVGResourceClipper.cpp:
  • rendering/svg/RenderSVGResourceClipper.h:
  • rendering/svg/RenderSVGResourceClipperInlines.h: Added.

(WebCore::RenderSVGResourceClipper::clipPathElement const):
(WebCore::RenderSVGResourceClipper::clipPathUnits const):

  • rendering/svg/RenderSVGResourceContainer.cpp:
  • rendering/svg/RenderSVGResourceFilter.cpp:
  • rendering/svg/RenderSVGResourceFilter.h:
  • rendering/svg/RenderSVGResourceFilterInlines.h: Added.

(WebCore::RenderSVGResourceFilter::filterElement const):
(WebCore::RenderSVGResourceFilter::filterUnits const):
(WebCore::RenderSVGResourceFilter::primitiveUnits const):

  • rendering/svg/RenderSVGResourceFilterPrimitive.cpp:
  • rendering/svg/RenderSVGResourceLinearGradient.cpp:
  • rendering/svg/RenderSVGResourceLinearGradient.h:
  • rendering/svg/RenderSVGResourceLinearGradientInlines.h: Added.

(WebCore::RenderSVGResourceLinearGradient::linearGradientElement const):

  • rendering/svg/RenderSVGResourceMarker.cpp:
  • rendering/svg/RenderSVGResourceMarker.h:
  • rendering/svg/RenderSVGResourceMarkerInlines.h: Added.

(WebCore::RenderSVGResourceMarker::markerElement const):
(WebCore::RenderSVGResourceMarker::markerUnits const):

  • rendering/svg/RenderSVGResourceMasker.cpp:
  • rendering/svg/RenderSVGResourceMasker.h:
  • rendering/svg/RenderSVGResourceMaskerInlines.h: Added.

(WebCore::RenderSVGResourceMasker::maskElement const):
(WebCore::RenderSVGResourceMasker::maskUnits const):
(WebCore::RenderSVGResourceMasker::maskContentUnits const):

  • rendering/svg/RenderSVGResourcePattern.cpp:
  • rendering/svg/RenderSVGResourceRadialGradient.cpp:
  • rendering/svg/RenderSVGResourceRadialGradient.h:
  • rendering/svg/RenderSVGResourceRadialGradientInlines.h: Added.

(WebCore::RenderSVGResourceRadialGradient::radialGradientElement const):

  • rendering/svg/RenderSVGRoot.cpp:
  • rendering/svg/RenderSVGShape.cpp:
  • rendering/svg/RenderSVGShape.h:

(WebCore::RenderSVGShape::graphicsElement const): Deleted.

  • rendering/svg/RenderSVGShapeInlines.h: Added.

(WebCore::RenderSVGShape::graphicsElement const):

  • rendering/svg/RenderSVGTSpan.h:
  • rendering/svg/RenderSVGText.cpp:
  • rendering/svg/RenderSVGTextPath.cpp:
  • rendering/svg/RenderSVGTextPath.h:
  • rendering/svg/RenderSVGTransformableContainer.cpp:

(WebCore::RenderSVGTransformableContainer::graphicsElement):

  • rendering/svg/RenderSVGTransformableContainer.h:
  • rendering/svg/RenderSVGViewportContainer.cpp:
  • rendering/svg/SVGInlineFlowBox.cpp:
  • rendering/svg/SVGInlineTextBox.cpp:
  • rendering/svg/SVGInlineTextBox.h:
  • rendering/svg/SVGInlineTextBoxInlines.h: Added.

(WebCore::SVGInlineTextBox::renderer const):
(WebCore::SVGInlineTextBox::nextTextBox const):

  • rendering/svg/SVGPathData.cpp:
  • rendering/svg/SVGRenderSupport.cpp:
  • rendering/svg/SVGRenderTreeAsText.cpp:
  • rendering/svg/SVGRenderingContext.cpp:
  • rendering/svg/SVGResources.cpp:
  • rendering/svg/SVGRootInlineBox.cpp:
  • rendering/svg/SVGTextLayoutEngine.cpp:
  • rendering/svg/SVGTextQuery.cpp:
  • style/StyleAdjuster.cpp:
  • style/StyleBuilderState.cpp:
  • style/StyleChange.h:
  • style/StyleResolver.h:
  • style/StyleScope.cpp:
  • style/StyleSharingResolver.cpp:
  • svg/DocumentSVG.cpp:
  • svg/SVGAElement.cpp:
  • svg/SVGAltGlyphDefElement.cpp:
  • svg/SVGAltGlyphElement.cpp:
  • svg/SVGAnimateMotionElement.cpp:
  • svg/SVGAnimationElement.cpp:
  • svg/SVGCircleElement.cpp:
  • svg/SVGElement.cpp:
  • svg/SVGElement.h:

(WebCore::SVGElement::invalidateSVGAttributes): Deleted.
(WebCore::SVGElement::invalidateSVGPresentationalHintStyle): Deleted.
(WebCore::SVGAttributeHashTranslator::hash): Deleted.
(WebCore::SVGAttributeHashTranslator::equal): Deleted.
(WebCore::Node::hasTagName const): Deleted.

  • svg/SVGElementInlines.h: Added.

(WebCore::SVGElement::invalidateSVGAttributes):
(WebCore::SVGElement::invalidateSVGPresentationalHintStyle):
(WebCore::SVGAttributeHashTranslator::hash):
(WebCore::SVGAttributeHashTranslator::equal):
(WebCore::Element::hasTagName const):
(WebCore::Node::hasTagName const):

  • svg/SVGEllipseElement.cpp:
  • svg/SVGFEComponentTransferElement.cpp:
  • svg/SVGFELightElement.cpp:
  • svg/SVGFilterElement.cpp:
  • svg/SVGFontFaceElement.cpp:
  • svg/SVGFontFaceFormatElement.cpp:
  • svg/SVGFontFaceNameElement.cpp:
  • svg/SVGFontFaceSrcElement.cpp:
  • svg/SVGFontFaceUriElement.cpp:
  • svg/SVGForeignObjectElement.cpp:
  • svg/SVGGlyphRefElement.cpp:
  • svg/SVGHKernElement.cpp:
  • svg/SVGImageElement.cpp:
  • svg/SVGImageLoader.cpp:
  • svg/SVGLengthContext.cpp:
  • svg/SVGLinearGradientElement.cpp:
  • svg/SVGLocatable.cpp:
  • svg/SVGMPathElement.cpp:
  • svg/SVGMaskElement.cpp:
  • svg/SVGPathElement.cpp:
  • svg/SVGPatternElement.cpp:
  • svg/SVGRadialGradientElement.cpp:
  • svg/SVGRectElement.cpp:
  • svg/SVGSVGElement.cpp:
  • svg/SVGStyleElement.cpp:
  • svg/SVGStyleElement.h:
  • svg/SVGTextContentElement.cpp:
  • svg/SVGTextPositioningElement.cpp:
  • svg/SVGUseElement.cpp:
  • svg/SVGVKernElement.cpp:
  • svg/animation/SVGSMILElement.cpp:
  • svg/graphics/SVGImage.cpp:
  • svg/properties/SVGAttributeAnimator.cpp:
  • xml/XPathFunctions.cpp:
  • xml/XPathNodeSet.cpp:
  • xml/XPathStep.cpp:
  • xml/parser/XMLDocumentParser.cpp:

Source/WebKit:

Include ElementInlines.h in various necessary places.

  • Shared/TouchBarMenuData.cpp:
  • Shared/TouchBarMenuItemData.cpp:
  • Shared/glib/InputMethodState.cpp:
  • WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMElementGtk.cpp:
  • WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMHTMLAnchorElement.cpp:
  • WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMHTMLAreaElement.cpp:
  • WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMHTMLBRElement.cpp:
  • WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMHTMLBaseElement.cpp:
  • WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMHTMLBodyElement.cpp:
  • WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMHTMLButtonElement.cpp:
  • WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMHTMLDivElement.cpp:
  • WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMHTMLElement.cpp:
  • WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMHTMLEmbedElement.cpp:
  • WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMHTMLFontElement.cpp:
  • WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMHTMLFormElement.cpp:
  • WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMHTMLFrameElement.cpp:
  • WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMHTMLFrameSetElement.cpp:
  • WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMHTMLHRElement.cpp:
  • WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMHTMLHeadElement.cpp:
  • WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMHTMLHeadingElement.cpp:
  • WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMHTMLHtmlElement.cpp:
  • WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMHTMLIFrameElement.cpp:
  • WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMHTMLImageElement.cpp:
  • WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMHTMLInputElement.cpp:
  • WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMHTMLLIElement.cpp:
  • WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMHTMLLabelElement.cpp:
  • WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMHTMLLegendElement.cpp:
  • WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMHTMLLinkElement.cpp:
  • WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMHTMLMetaElement.cpp:
  • WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMHTMLModElement.cpp:
  • WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMHTMLOListElement.cpp:
  • WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMHTMLObjectElement.cpp:
  • WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMHTMLOptGroupElement.cpp:
  • WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMHTMLParagraphElement.cpp:
  • WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMHTMLParamElement.cpp:
  • WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMHTMLScriptElement.cpp:
  • WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMHTMLStyleElement.cpp:
  • WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMHTMLTableCaptionElement.cpp:
  • WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMHTMLTableCellElement.cpp:
  • WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMHTMLTableColElement.cpp:
  • WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMHTMLTableElement.cpp:
  • WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMHTMLTableRowElement.cpp:
  • WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMHTMLTableSectionElement.cpp:
  • WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMHTMLUListElement.cpp:
  • WebProcess/WebCoreSupport/WebChromeClient.cpp:
  • WebProcess/WebCoreSupport/mac/WebDragClientMac.mm:
  • WebProcess/cocoa/PlaybackSessionManager.mm:

Source/WebKitLegacy/mac:

Include ElementInlines.h in various necessary places.

  • WebView/WebHTMLRepresentation.mm:

Tools:

Include ArrayBuffer.h in various necessary places.

  • TestWebKitAPI/Tests/WebCore/SharedBuffer.cpp:
  • Property svn:eol-style set to native
File size: 8.4 KB
Line 
1/*
2 * Copyright (C) 2007 Alexey Proskuryakov <[email protected]>
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#include "config.h"
27#include "XPathNodeSet.h"
28
29#include "Attr.h"
30#include "Attribute.h"
31#include "Document.h"
32#include "ElementInlines.h"
33#include "NodeTraversal.h"
34
35namespace WebCore {
36namespace XPath {
37
38// When a node set is large, sorting it by traversing the whole document is better (we can
39// assume that we aren't dealing with documents that we cannot even traverse in reasonable time).
40const unsigned traversalSortCutoff = 10000;
41
42static inline Node* parentWithDepth(unsigned depth, const Vector<Node*>& parents)
43{
44 ASSERT(parents.size() >= depth + 1);
45 return parents[parents.size() - 1 - depth];
46}
47
48static void sortBlock(unsigned from, unsigned to, Vector<Vector<Node*>>& parentMatrix, bool mayContainAttributeNodes)
49{
50 ASSERT(from + 1 < to); // Should not call this function with less that two nodes to sort.
51 unsigned minDepth = UINT_MAX;
52 for (unsigned i = from; i < to; ++i) {
53 unsigned depth = parentMatrix[i].size() - 1;
54 if (minDepth > depth)
55 minDepth = depth;
56 }
57
58 // Find the common ancestor.
59 unsigned commonAncestorDepth = minDepth;
60 Node* commonAncestor;
61 while (true) {
62 commonAncestor = parentWithDepth(commonAncestorDepth, parentMatrix[from]);
63 if (commonAncestorDepth == 0)
64 break;
65
66 bool allEqual = true;
67 for (unsigned i = from + 1; i < to; ++i) {
68 if (commonAncestor != parentWithDepth(commonAncestorDepth, parentMatrix[i])) {
69 allEqual = false;
70 break;
71 }
72 }
73 if (allEqual)
74 break;
75
76 --commonAncestorDepth;
77 }
78
79 if (commonAncestorDepth == minDepth) {
80 // One of the nodes is the common ancestor => it is the first in document order.
81 // Find it and move it to the beginning.
82 for (unsigned i = from; i < to; ++i)
83 if (commonAncestor == parentMatrix[i][0]) {
84 parentMatrix[i].swap(parentMatrix[from]);
85 if (from + 2 < to)
86 sortBlock(from + 1, to, parentMatrix, mayContainAttributeNodes);
87 return;
88 }
89 }
90
91 if (mayContainAttributeNodes && commonAncestor->isElementNode()) {
92 // The attribute nodes and namespace nodes of an element occur before the children of the element.
93 // The namespace nodes are defined to occur before the attribute nodes.
94 // The relative order of namespace nodes is implementation-dependent.
95 // The relative order of attribute nodes is implementation-dependent.
96 unsigned sortedEnd = from;
97 // FIXME: namespace nodes are not implemented.
98 for (unsigned i = sortedEnd; i < to; ++i) {
99 Node* node = parentMatrix[i][0];
100 if (is<Attr>(*node) && downcast<Attr>(*node).ownerElement() == commonAncestor)
101 parentMatrix[i].swap(parentMatrix[sortedEnd++]);
102 }
103 if (sortedEnd != from) {
104 if (to - sortedEnd > 1)
105 sortBlock(sortedEnd, to, parentMatrix, mayContainAttributeNodes);
106 return;
107 }
108 }
109
110 // Children nodes of the common ancestor induce a subdivision of our node-set.
111 // Sort it according to this subdivision, and recursively sort each group.
112 HashSet<RefPtr<Node>> parentNodes;
113 for (unsigned i = from; i < to; ++i)
114 parentNodes.add(parentWithDepth(commonAncestorDepth + 1, parentMatrix[i]));
115
116 unsigned previousGroupEnd = from;
117 unsigned groupEnd = from;
118 for (Node* n = commonAncestor->firstChild(); n; n = n->nextSibling()) {
119 // If parentNodes contains the node, perform a linear search to move its children in the node-set to the beginning.
120 if (parentNodes.contains(n)) {
121 for (unsigned i = groupEnd; i < to; ++i)
122 if (parentWithDepth(commonAncestorDepth + 1, parentMatrix[i]) == n)
123 parentMatrix[i].swap(parentMatrix[groupEnd++]);
124
125 if (groupEnd - previousGroupEnd > 1)
126 sortBlock(previousGroupEnd, groupEnd, parentMatrix, mayContainAttributeNodes);
127
128 ASSERT(previousGroupEnd != groupEnd);
129 previousGroupEnd = groupEnd;
130#ifndef NDEBUG
131 parentNodes.remove(n);
132#endif
133 }
134 }
135
136 ASSERT(parentNodes.isEmpty());
137}
138
139void NodeSet::sort() const
140{
141 if (m_isSorted)
142 return;
143
144 unsigned nodeCount = m_nodes.size();
145 if (nodeCount < 2) {
146 m_isSorted = true;
147 return;
148 }
149
150 if (nodeCount > traversalSortCutoff) {
151 traversalSort();
152 return;
153 }
154
155 bool containsAttributeNodes = false;
156
157 Vector<Vector<Node*>> parentMatrix(nodeCount);
158 for (unsigned i = 0; i < nodeCount; ++i) {
159 Vector<Node*>& parentsVector = parentMatrix[i];
160 Node* node = m_nodes[i].get();
161 parentsVector.append(node);
162 if (is<Attr>(*node)) {
163 node = downcast<Attr>(*node).ownerElement();
164 parentsVector.append(node);
165 containsAttributeNodes = true;
166 }
167 while ((node = node->parentNode()))
168 parentsVector.append(node);
169 }
170 sortBlock(0, nodeCount, parentMatrix, containsAttributeNodes);
171
172 // It is not possible to just assign the result to m_nodes, because some nodes may get dereferenced and destroyed.
173 Vector<RefPtr<Node>> sortedNodes;
174 sortedNodes.reserveInitialCapacity(nodeCount);
175 for (unsigned i = 0; i < nodeCount; ++i)
176 sortedNodes.append(parentMatrix[i][0]);
177
178 m_nodes = WTFMove(sortedNodes);
179 m_isSorted = true;
180}
181
182static Node* findRootNode(Node* node)
183{
184 if (is<Attr>(*node))
185 node = downcast<Attr>(*node).ownerElement();
186 if (node->isConnected())
187 node = &node->document();
188 else {
189 while (Node* parent = node->parentNode())
190 node = parent;
191 }
192 return node;
193}
194
195void NodeSet::traversalSort() const
196{
197 HashSet<RefPtr<Node>> nodes;
198 bool containsAttributeNodes = false;
199
200 unsigned nodeCount = m_nodes.size();
201 ASSERT(nodeCount > 1);
202 for (auto& node : m_nodes) {
203 nodes.add(node.get());
204 if (node->isAttributeNode())
205 containsAttributeNodes = true;
206 }
207
208 Vector<RefPtr<Node>> sortedNodes;
209 sortedNodes.reserveInitialCapacity(nodeCount);
210
211 for (Node* node = findRootNode(m_nodes.first().get()); node; node = NodeTraversal::next(*node)) {
212 if (nodes.contains(node))
213 sortedNodes.append(node);
214
215 if (!containsAttributeNodes || !is<Element>(*node))
216 continue;
217
218 Element& element = downcast<Element>(*node);
219 if (!element.hasAttributes())
220 continue;
221
222 for (const Attribute& attribute : element.attributesIterator()) {
223 RefPtr<Attr> attr = element.attrIfExists(attribute.name());
224 if (attr && nodes.contains(attr.get()))
225 sortedNodes.append(attr);
226 }
227 }
228
229 ASSERT(sortedNodes.size() == nodeCount);
230 m_nodes = WTFMove(sortedNodes);
231 m_isSorted = true;
232}
233
234Node* NodeSet::firstNode() const
235{
236 if (isEmpty())
237 return nullptr;
238
239 sort(); // FIXME: fully sorting the node-set just to find its first node is wasteful.
240 return m_nodes.at(0).get();
241}
242
243Node* NodeSet::anyNode() const
244{
245 if (isEmpty())
246 return nullptr;
247
248 return m_nodes.at(0).get();
249}
250
251}
252}
Note: See TracBrowser for help on using the repository browser.