| /* | |
| * Copyright (C) 2005, 2008 Apple Inc. All rights reserved. | |
| * | |
| * Redistribution and use in source and binary forms, with or without | |
| * modification, are permitted provided that the following conditions | |
| * are met: | |
| * | |
| * 1. Redistributions of source code must retain the above copyright | |
| * notice, this list of conditions and the following disclaimer. | |
| * 2. Redistributions in binary form must reproduce the above copyright | |
| * notice, this list of conditions and the following disclaimer in the | |
| * documentation and/or other materials provided with the distribution. | |
| * 3. Neither the name of Apple Inc. ("Apple") nor the names of | |
| * its contributors may be used to endorse or promote products derived | |
| * from this software without specific prior written permission. | |
| * | |
| * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY | |
| * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
| * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
| * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY | |
| * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
| * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
| * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |
| * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | |
| * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| */ | |
| #import "WebDOMOperationsPrivate.h" | |
| #import "DOMDocumentInternal.h" | |
| #import "DOMElementInternal.h" | |
| #import "DOMNodeInternal.h" | |
| #import "DOMRangeInternal.h" | |
| #import "DOMWheelEventInternal.h" | |
| #import "WebArchiveInternal.h" | |
| #import "WebDataSourcePrivate.h" | |
| #import "WebFrameInternal.h" | |
| #import "WebFrameLoaderClient.h" | |
| #import "WebFramePrivate.h" | |
| #import "WebKitNSStringExtras.h" | |
| #import <JavaScriptCore/APICast.h> | |
| #import <JavaScriptCore/JSCJSValue.h> | |
| #import <JavaScriptCore/JSGlobalObjectInlines.h> | |
| #import <JavaScriptCore/JSLock.h> | |
| #import <WebCore/BoundaryPointInlines.h> | |
| #import <WebCore/Document.h> | |
| #import <WebCore/FrameDestructionObserverInlines.h> | |
| #import <WebCore/FrameLoader.h> | |
| #import <WebCore/HTMLInputElement.h> | |
| #import <WebCore/HTMLTextFormControlElement.h> | |
| #import <WebCore/JSElement.h> | |
| #import <WebCore/LegacyWebArchive.h> | |
| #import <WebCore/LocalFrame.h> | |
| #import <WebCore/PlatformWheelEvent.h> | |
| #import <WebCore/Range.h> | |
| #import <WebCore/RenderElement.h> | |
| #import <WebCore/RenderObjectStyle.h> | |
| #import <WebCore/RenderTreeAsText.h> | |
| #import <WebCore/ShadowRoot.h> | |
| #import <WebCore/SimpleRange.h> | |
| #import <WebCore/WheelEvent.h> | |
| #import <WebCore/markup.h> | |
| #import <WebKitLegacy/DOMExtensions.h> | |
| #import <WebKitLegacy/DOMHTML.h> | |
| #import <wtf/Assertions.h> | |
| #import <wtf/text/MakeString.h> | |
| @implementation DOMElement (WebDOMElementOperationsPrivate) | |
| + (DOMElement *)_DOMElementFromJSContext:(JSContextRef)context value:(JSValueRef)value | |
| { | |
| if (!context) | |
| return 0; | |
| if (!value) | |
| return 0; | |
| JSC::JSGlobalObject* lexicalGlobalObject = toJS(context); | |
| JSC::JSLockHolder lock(lexicalGlobalObject); | |
| return kit(WebCore::JSElement::toWrapped(lexicalGlobalObject->vm(), toJS(lexicalGlobalObject, value))); | |
| } | |
| @end | |
| @implementation DOMNode (WebDOMNodeOperations) | |
| - (WebArchive *)webArchive | |
| { | |
| WebCore::LegacyWebArchive::ArchiveOptions options { WebCore::LegacyWebArchive::ShouldSaveScriptsFromMemoryCache::No }; | |
| return adoptNS([[WebArchive alloc] _initWithCoreLegacyWebArchive:WebCore::LegacyWebArchive::create(protect(*core(self)), WTF::move(options))]).autorelease(); | |
| } | |
| - (WebArchive *)webArchiveByFilteringSubframes:(WebArchiveSubframeFilter)webArchiveSubframeFilter | |
| { | |
| WebCore::LegacyWebArchive::ArchiveOptions options { WebCore::LegacyWebArchive::ShouldSaveScriptsFromMemoryCache::No }; | |
| RetainPtr webArchive = adoptNS([[WebArchive alloc] _initWithCoreLegacyWebArchive:WebCore::LegacyWebArchive::create(protect(*core(self)), WTF::move(options), [webArchiveSubframeFilter](WebCore::LocalFrame& subframe) -> bool { | |
| return webArchiveSubframeFilter(protect(kit(&subframe))); | |
| })]); | |
| return webArchive.autorelease(); | |
| } | |
| #if PLATFORM(IOS_FAMILY) | |
| - (BOOL)isHorizontalWritingMode | |
| { | |
| RefPtr node = core(self); | |
| if (!node) | |
| return YES; | |
| CheckedPtr<WebCore::RenderObject> renderer = node->renderer(); | |
| if (!renderer) | |
| return YES; | |
| return renderer->writingMode().isHorizontal(); | |
| } | |
| - (void)hidePlaceholder | |
| { | |
| if (RefPtr node = core(self); is<WebCore::HTMLTextFormControlElement>(node)) | |
| downcast<WebCore::HTMLTextFormControlElement>(*node).setCanShowPlaceholder(false); | |
| } | |
| - (void)showPlaceholderIfNecessary | |
| { | |
| if (RefPtr node = core(self); is<WebCore::HTMLTextFormControlElement>(node)) | |
| downcast<WebCore::HTMLTextFormControlElement>(*node).setCanShowPlaceholder(true); | |
| } | |
| #endif | |
| @end | |
| @implementation DOMNode (WebDOMNodeOperationsPendingPublic) | |
| - (NSString *)markupString | |
| { | |
| Ref node = *core(self); | |
| String markupString = serializeFragment(node, WebCore::SerializedNodes::SubtreeIncludingNode); | |
| auto nodeType = node->nodeType(); | |
| if (nodeType != WebCore::NodeType::Document && nodeType != WebCore::NodeType::DocumentType) | |
| markupString = makeString(documentTypeString(protect(node->document())), markupString); | |
| return markupString.createNSString().autorelease(); | |
| } | |
| - (NSRect)_renderRect:(bool *)isReplaced | |
| { | |
| return NSRect(protect(core(self))->pixelSnappedAbsoluteBoundingRect(isReplaced)); | |
| } | |
| @end | |
| @implementation DOMDocument (WebDOMDocumentOperations) | |
| - (WebFrame *)webFrame | |
| { | |
| RefPtr frame = protect(core(self))->frame(); | |
| if (!frame) | |
| return nil; | |
| return kit(frame.get()); | |
| } | |
| - (NSURL *)URLWithAttributeString:(NSString *)string | |
| { | |
| return protect(core(self))->encodingParseURL(string).createNSURL().autorelease(); | |
| } | |
| @end | |
| @implementation DOMDocument (WebDOMDocumentOperationsInternal) | |
| - (DOMRange *)_documentRange | |
| { | |
| DOMRange *range = [self createRange]; | |
| if (DOMNode* documentElement = [self documentElement]) | |
| [range selectNode:documentElement]; | |
| return range; | |
| } | |
| @end | |
| @implementation DOMRange (WebDOMRangeOperations) | |
| - (WebArchive *)webArchive | |
| { | |
| WebCore::LegacyWebArchive::ArchiveOptions options { WebCore::LegacyWebArchive::ShouldSaveScriptsFromMemoryCache::No }; | |
| return adoptNS([[WebArchive alloc] _initWithCoreLegacyWebArchive:WebCore::LegacyWebArchive::create(makeSimpleRange(protect(*core(self))), WTF::move(options))]).autorelease(); | |
| } | |
| - (NSString *)markupString | |
| { | |
| auto range = makeSimpleRange(protect(*core(self))); | |
| return makeString(documentTypeString(protect(range.start.document())), serializePreservingVisualAppearance(range, nullptr, WebCore::AnnotateForInterchange::Yes)).createNSString().autorelease(); | |
| } | |
| @end | |
| @implementation DOMHTMLFrameElement (WebDOMHTMLFrameElementOperations) | |
| - (WebFrame *)contentFrame | |
| { | |
| return [[self contentDocument] webFrame]; | |
| } | |
| @end | |
| @implementation DOMHTMLIFrameElement (WebDOMHTMLIFrameElementOperations) | |
| - (WebFrame *)contentFrame | |
| { | |
| return [[self contentDocument] webFrame]; | |
| } | |
| @end | |
| @implementation DOMHTMLInputElement (WebDOMHTMLInputElementOperationsPrivate) | |
| - (BOOL)_isAutofilled | |
| { | |
| return downcast<WebCore::HTMLInputElement>(core(self))->autofilled(); | |
| } | |
| - (BOOL)_isAutoFilledAndViewable | |
| { | |
| return downcast<WebCore::HTMLInputElement>(core(self))->autofilledAndViewable(); | |
| } | |
| - (void)_setAutofilled:(BOOL)autofilled | |
| { | |
| protect(downcast<WebCore::HTMLInputElement>(core(self)))->setAutofilled(autofilled); | |
| } | |
| - (void)_setAutoFilledAndViewable:(BOOL)autoFilledAndViewable | |
| { | |
| protect(downcast<WebCore::HTMLInputElement>(core(self)))->setAutofilledAndViewable(autoFilledAndViewable); | |
| } | |
| @end | |
| @implementation DOMHTMLObjectElement (WebDOMHTMLObjectElementOperations) | |
| - (WebFrame *)contentFrame | |
| { | |
| return [[self contentDocument] webFrame]; | |
| } | |
| @end | |
| #if !PLATFORM(IOS_FAMILY) | |
| NODELETE static NSEventPhase toNSEventPhase(WebCore::PlatformWheelEventPhase platformPhase) | |
| { | |
| switch (platformPhase) { | |
| case WebCore::PlatformWheelEventPhase::None: | |
| return NSEventPhaseNone; | |
| case WebCore::PlatformWheelEventPhase::Began: | |
| return NSEventPhaseBegan; | |
| case WebCore::PlatformWheelEventPhase::Stationary: | |
| return NSEventPhaseStationary; | |
| case WebCore::PlatformWheelEventPhase::Changed: | |
| return NSEventPhaseChanged; | |
| case WebCore::PlatformWheelEventPhase::Ended: | |
| return NSEventPhaseEnded; | |
| case WebCore::PlatformWheelEventPhase::Cancelled: | |
| return NSEventPhaseCancelled; | |
| case WebCore::PlatformWheelEventPhase::MayBegin: | |
| return NSEventPhaseMayBegin; | |
| case WebCore::PlatformWheelEventPhase::WillBegin: | |
| return NSEventPhaseNone; | |
| } | |
| return NSEventPhaseNone; | |
| } | |
| @implementation DOMWheelEvent (WebDOMWheelEventOperationsPrivate) | |
| - (NSEventPhase)_phase | |
| { | |
| return toNSEventPhase(protect(core(self))->phase()); | |
| } | |
| - (NSEventPhase)_momentumPhase | |
| { | |
| return toNSEventPhase(protect(core(self))->momentumPhase()); | |
| } | |
| @end | |
| #endif |