diff options
| author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2015-05-20 09:56:07 +0000 |
|---|---|---|
| committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2015-05-20 09:56:07 +0000 |
| commit | 41386e9cb918eed93b3f13648cbef387e371e451 (patch) | |
| tree | a97f9d7bd1d9d091833286085f72da9d83fd0606 /Source/WebKit2/WebProcess/InjectedBundle/DOM | |
| parent | e15dd966d523731101f70ccf768bba12435a0208 (diff) | |
| download | WebKitGtk-tarball-41386e9cb918eed93b3f13648cbef387e371e451.tar.gz | |
webkitgtk-2.4.9webkitgtk-2.4.9
Diffstat (limited to 'Source/WebKit2/WebProcess/InjectedBundle/DOM')
8 files changed, 76 insertions, 474 deletions
diff --git a/Source/WebKit2/WebProcess/InjectedBundle/DOM/InjectedBundleCSSStyleDeclarationHandle.cpp b/Source/WebKit2/WebProcess/InjectedBundle/DOM/InjectedBundleCSSStyleDeclarationHandle.cpp deleted file mode 100644 index ac11d11a7..000000000 --- a/Source/WebKit2/WebProcess/InjectedBundle/DOM/InjectedBundleCSSStyleDeclarationHandle.cpp +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (C) 2014 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. - * - * THIS SOFTWARE IS PROVIDED BY APPLE INC. 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 INC. 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. - */ - -#include "config.h" -#include "InjectedBundleCSSStyleDeclarationHandle.h" - -#include <WebCore/CSSStyleDeclaration.h> -#include <wtf/HashMap.h> -#include <wtf/NeverDestroyed.h> - -using namespace WebCore; - -namespace WebKit { - -typedef HashMap<CSSStyleDeclaration*, InjectedBundleCSSStyleDeclarationHandle*> DOMHandleCache; - -static DOMHandleCache& domHandleCache() -{ - static NeverDestroyed<DOMHandleCache> cache; - return cache; -} - -PassRefPtr<InjectedBundleCSSStyleDeclarationHandle> InjectedBundleCSSStyleDeclarationHandle::getOrCreate(CSSStyleDeclaration* styleDeclaration) -{ - if (!styleDeclaration) - return nullptr; - - DOMHandleCache::AddResult result = domHandleCache().add(styleDeclaration, nullptr); - if (!result.isNewEntry) - return PassRefPtr<InjectedBundleCSSStyleDeclarationHandle>(result.iterator->value); - - RefPtr<InjectedBundleCSSStyleDeclarationHandle> styleDeclarationHandle = adoptRef(new InjectedBundleCSSStyleDeclarationHandle(*styleDeclaration)); - result.iterator->value = styleDeclarationHandle.get(); - return styleDeclarationHandle.release(); -} - -InjectedBundleCSSStyleDeclarationHandle::InjectedBundleCSSStyleDeclarationHandle(CSSStyleDeclaration& styleDeclaration) - : m_styleDeclaration(styleDeclaration) -{ -} - -InjectedBundleCSSStyleDeclarationHandle::~InjectedBundleCSSStyleDeclarationHandle() -{ - domHandleCache().remove(m_styleDeclaration.ptr()); -} - -} // namespace WebKit diff --git a/Source/WebKit2/WebProcess/InjectedBundle/DOM/InjectedBundleCSSStyleDeclarationHandle.h b/Source/WebKit2/WebProcess/InjectedBundle/DOM/InjectedBundleCSSStyleDeclarationHandle.h deleted file mode 100644 index 84c93c1ed..000000000 --- a/Source/WebKit2/WebProcess/InjectedBundle/DOM/InjectedBundleCSSStyleDeclarationHandle.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (C) 2014 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. - * - * THIS SOFTWARE IS PROVIDED BY APPLE INC. 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 INC. 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. - */ - -#ifndef InjectedBundleCSSStyleDeclarationHandle_h -#define InjectedBundleCSSStyleDeclarationHandle_h - -#include "APIObject.h" -#include <wtf/PassRefPtr.h> -#include <wtf/Ref.h> - -namespace WebCore { -class CSSStyleDeclaration; -} - -namespace WebKit { - -class InjectedBundleCSSStyleDeclarationHandle : public API::ObjectImpl<API::Object::Type::BundleCSSStyleDeclarationHandle> { -public: - static PassRefPtr<InjectedBundleCSSStyleDeclarationHandle> getOrCreate(WebCore::CSSStyleDeclaration*); - virtual ~InjectedBundleCSSStyleDeclarationHandle(); - -private: - InjectedBundleCSSStyleDeclarationHandle(WebCore::CSSStyleDeclaration&); - - Ref<WebCore::CSSStyleDeclaration> m_styleDeclaration; -}; - -} // namespace WebKit - -#endif // InjectedBundleCSSStyleDeclarationHandle_h diff --git a/Source/WebKit2/WebProcess/InjectedBundle/DOM/InjectedBundleFileHandle.cpp b/Source/WebKit2/WebProcess/InjectedBundle/DOM/InjectedBundleFileHandle.cpp deleted file mode 100644 index 193403a4e..000000000 --- a/Source/WebKit2/WebProcess/InjectedBundle/DOM/InjectedBundleFileHandle.cpp +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (C) 2015 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. - * - * THIS SOFTWARE IS PROVIDED BY APPLE INC. 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 INC. 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. - */ - -#include "config.h" -#include "InjectedBundleFileHandle.h" - -#include <WebCore/File.h> -#include <wtf/HashMap.h> -#include <wtf/NeverDestroyed.h> - -using namespace WebCore; - -namespace WebKit { - -typedef HashMap<File*, InjectedBundleFileHandle*> DOMHandleCache; - -static DOMHandleCache& domHandleCache() -{ - static NeverDestroyed<DOMHandleCache> cache; - return cache; -} - -RefPtr<InjectedBundleFileHandle> InjectedBundleFileHandle::create(const String& path) -{ - auto file = File::create(path); - return adoptRef(new InjectedBundleFileHandle(file.get())); -} - -RefPtr<InjectedBundleFileHandle> InjectedBundleFileHandle::getOrCreate(File* file) -{ - if (!file) - return nullptr; - - DOMHandleCache::AddResult result = domHandleCache().add(file, nullptr); - if (!result.isNewEntry) - return RefPtr<InjectedBundleFileHandle>(result.iterator->value); - - RefPtr<InjectedBundleFileHandle> fileHandle = adoptRef(new InjectedBundleFileHandle(*file)); - result.iterator->value = fileHandle.get(); - return fileHandle; -} - -InjectedBundleFileHandle::InjectedBundleFileHandle(File& file) - : m_file(file) -{ -} - -InjectedBundleFileHandle::~InjectedBundleFileHandle() -{ - domHandleCache().remove(m_file.ptr()); -} - -File* InjectedBundleFileHandle::coreFile() -{ - return m_file.ptr(); -} - -} // namespace WebKit diff --git a/Source/WebKit2/WebProcess/InjectedBundle/DOM/InjectedBundleFileHandle.h b/Source/WebKit2/WebProcess/InjectedBundle/DOM/InjectedBundleFileHandle.h deleted file mode 100644 index 27fd2cb5d..000000000 --- a/Source/WebKit2/WebProcess/InjectedBundle/DOM/InjectedBundleFileHandle.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (C) 2015 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. - * - * THIS SOFTWARE IS PROVIDED BY APPLE INC. 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 INC. 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. - */ - -#ifndef InjectedBundleFileHandle_h -#define InjectedBundleFileHandle_h - -#include "APIObject.h" -#include <wtf/Forward.h> -#include <wtf/PassRefPtr.h> -#include <wtf/RefPtr.h> - -namespace WebCore { -class File; -} - -namespace WebKit { - -class InjectedBundleFileHandle : public API::ObjectImpl<API::Object::Type::BundleFileHandle> { -public: - static RefPtr<InjectedBundleFileHandle> create(const WTF::String&); - static RefPtr<InjectedBundleFileHandle> getOrCreate(WebCore::File*); - - virtual ~InjectedBundleFileHandle(); - - WebCore::File* coreFile(); - -private: - InjectedBundleFileHandle(WebCore::File&); - - Ref<WebCore::File> m_file; -}; - -} // namespace WebKit - -#endif // InjectedBundleFileHandle_h diff --git a/Source/WebKit2/WebProcess/InjectedBundle/DOM/InjectedBundleNodeHandle.cpp b/Source/WebKit2/WebProcess/InjectedBundle/DOM/InjectedBundleNodeHandle.cpp index f742559e3..ccff2b36f 100644 --- a/Source/WebKit2/WebProcess/InjectedBundle/DOM/InjectedBundleNodeHandle.cpp +++ b/Source/WebKit2/WebProcess/InjectedBundle/DOM/InjectedBundleNodeHandle.cpp @@ -26,7 +26,6 @@ #include "config.h" #include "InjectedBundleNodeHandle.h" -#include "InjectedBundleRangeHandle.h" #include "ShareableBitmap.h" #include "WebFrame.h" #include "WebFrameLoaderClient.h" @@ -47,10 +46,7 @@ #include <WebCore/JSNode.h> #include <WebCore/Node.h> #include <WebCore/Page.h> -#include <WebCore/Position.h> -#include <WebCore/Range.h> #include <WebCore/RenderObject.h> -#include <WebCore/VisiblePosition.h> #include <wtf/HashMap.h> #include <wtf/NeverDestroyed.h> #include <wtf/text/WTFString.h> @@ -68,70 +64,65 @@ static DOMHandleCache& domHandleCache() return cache; } -RefPtr<InjectedBundleNodeHandle> InjectedBundleNodeHandle::getOrCreate(JSContextRef, JSObjectRef object) +PassRefPtr<InjectedBundleNodeHandle> InjectedBundleNodeHandle::getOrCreate(JSContextRef, JSObjectRef object) { - Node* node = JSNode::toWrapped(toJS(object)); + Node* node = toNode(toJS(object)); return getOrCreate(node); } -RefPtr<InjectedBundleNodeHandle> InjectedBundleNodeHandle::getOrCreate(Node* node) +PassRefPtr<InjectedBundleNodeHandle> InjectedBundleNodeHandle::getOrCreate(Node* node) { if (!node) - return nullptr; - - return InjectedBundleNodeHandle::getOrCreate(*node); -} + return 0; -Ref<InjectedBundleNodeHandle> InjectedBundleNodeHandle::getOrCreate(Node& node) -{ - DOMHandleCache::AddResult result = domHandleCache().add(&node, nullptr); + DOMHandleCache::AddResult result = domHandleCache().add(node, nullptr); if (!result.isNewEntry) - return Ref<InjectedBundleNodeHandle>(*result.iterator->value); + return PassRefPtr<InjectedBundleNodeHandle>(result.iterator->value); - Ref<InjectedBundleNodeHandle> nodeHandle = InjectedBundleNodeHandle::create(node); - result.iterator->value = nodeHandle.ptr(); - return nodeHandle; + RefPtr<InjectedBundleNodeHandle> nodeHandle = InjectedBundleNodeHandle::create(node); + result.iterator->value = nodeHandle.get(); + return nodeHandle.release(); } -Ref<InjectedBundleNodeHandle> InjectedBundleNodeHandle::create(Node& node) +PassRefPtr<InjectedBundleNodeHandle> InjectedBundleNodeHandle::create(Node* node) { - return adoptRef(*new InjectedBundleNodeHandle(node)); + return adoptRef(new InjectedBundleNodeHandle(node)); } -InjectedBundleNodeHandle::InjectedBundleNodeHandle(Node& node) +InjectedBundleNodeHandle::InjectedBundleNodeHandle(Node* node) : m_node(node) { } InjectedBundleNodeHandle::~InjectedBundleNodeHandle() { - domHandleCache().remove(m_node.ptr()); + domHandleCache().remove(m_node.get()); } -Node* InjectedBundleNodeHandle::coreNode() +Node* InjectedBundleNodeHandle::coreNode() const { - return m_node.ptr(); + return m_node.get(); } -Ref<InjectedBundleNodeHandle> InjectedBundleNodeHandle::document() +PassRefPtr<InjectedBundleNodeHandle> InjectedBundleNodeHandle::document() { - return getOrCreate(m_node->document()); + return getOrCreate(&m_node->document()); } // Additional DOM Operations // Note: These should only be operations that are not exposed to JavaScript. -IntRect InjectedBundleNodeHandle::elementBounds() +IntRect InjectedBundleNodeHandle::elementBounds() const { - if (!is<Element>(m_node)) + if (!m_node->isElementNode()) return IntRect(); - return downcast<Element>(m_node.get()).boundsInRootViewSpace(); + return toElement(m_node.get())->boundsInRootViewSpace(); } -IntRect InjectedBundleNodeHandle::renderRect(bool* isReplaced) +IntRect InjectedBundleNodeHandle::renderRect(bool* isReplaced) const { - return m_node->pixelSnappedRenderRect(isReplaced); + return m_node.get()->pixelSnappedRenderRect(isReplaced); } static PassRefPtr<WebImage> imageForRect(FrameView* frameView, const IntRect& rect, SnapshotOptions options) @@ -153,16 +144,7 @@ static PassRefPtr<WebImage> imageForRect(FrameView* frameView, const IntRect& re if (options & SnapshotOptionsExcludeSelectionHighlighting) shouldPaintSelection = FrameView::ExcludeSelection; - PaintBehavior paintBehavior = frameView->paintBehavior() | PaintBehaviorFlattenCompositingLayers; - if (options & SnapshotOptionsForceBlackText) - paintBehavior |= PaintBehaviorForceBlackText; - if (options & SnapshotOptionsForceWhiteText) - paintBehavior |= PaintBehaviorForceWhiteText; - - PaintBehavior oldPaintBehavior = frameView->paintBehavior(); - frameView->setPaintBehavior(paintBehavior); frameView->paintContentsForSnapshot(graphicsContext.get(), rect, shouldPaintSelection, FrameView::DocumentCoordinates); - frameView->setPaintBehavior(oldPaintBehavior); return snapshot.release(); } @@ -171,155 +153,113 @@ PassRefPtr<WebImage> InjectedBundleNodeHandle::renderedImage(SnapshotOptions opt { Frame* frame = m_node->document().frame(); if (!frame) - return nullptr; + return 0; FrameView* frameView = frame->view(); if (!frameView) - return nullptr; + return 0; m_node->document().updateLayout(); RenderObject* renderer = m_node->renderer(); if (!renderer) - return nullptr; + return 0; LayoutRect topLevelRect; - IntRect paintingRect = snappedIntRect(renderer->paintingRootRect(topLevelRect)); + IntRect paintingRect = pixelSnappedIntRect(renderer->paintingRootRect(topLevelRect)); - frameView->setNodeToDraw(m_node.ptr()); + frameView->setNodeToDraw(m_node.get()); RefPtr<WebImage> image = imageForRect(frameView, paintingRect, options); frameView->setNodeToDraw(0); return image.release(); } -PassRefPtr<InjectedBundleRangeHandle> InjectedBundleNodeHandle::visibleRange() -{ - VisiblePosition start = firstPositionInNode(m_node.ptr()); - VisiblePosition end = lastPositionInNode(m_node.ptr()); - - RefPtr<Range> range = makeRange(start, end); - return InjectedBundleRangeHandle::getOrCreate(range.get()); -} - void InjectedBundleNodeHandle::setHTMLInputElementValueForUser(const String& value) { - if (!is<HTMLInputElement>(m_node)) + if (!isHTMLInputElement(m_node.get())) return; - downcast<HTMLInputElement>(m_node.get()).setValueForUser(value); + toHTMLInputElement(m_node.get())->setValueForUser(value); } -bool InjectedBundleNodeHandle::isHTMLInputElementAutoFilled() const +bool InjectedBundleNodeHandle::isHTMLInputElementAutofilled() const { - if (!is<HTMLInputElement>(m_node)) + if (!isHTMLInputElement(m_node.get())) return false; - return downcast<HTMLInputElement>(m_node.get()).isAutoFilled(); + return toHTMLInputElement(m_node.get())->isAutofilled(); } -void InjectedBundleNodeHandle::setHTMLInputElementAutoFilled(bool filled) +void InjectedBundleNodeHandle::setHTMLInputElementAutofilled(bool filled) { - if (!is<HTMLInputElement>(m_node)) + if (!isHTMLInputElement(m_node.get())) return; - downcast<HTMLInputElement>(m_node.get()).setAutoFilled(filled); -} - -bool InjectedBundleNodeHandle::isHTMLInputElementAutoFillButtonEnabled() const -{ - if (!is<HTMLInputElement>(m_node)) - return false; - - return downcast<HTMLInputElement>(m_node.get()).showAutoFillButton(); -} - -void InjectedBundleNodeHandle::setHTMLInputElementAutoFillButtonEnabled(bool filled) -{ - if (!is<HTMLInputElement>(m_node)) - return; - - downcast<HTMLInputElement>(m_node.get()).setShowAutoFillButton(filled); -} - -IntRect InjectedBundleNodeHandle::htmlInputElementAutoFillButtonBounds() -{ - if (!is<HTMLInputElement>(m_node)) - return IntRect(); - - auto autoFillButton = downcast<HTMLInputElement>(m_node.get()).autoFillButtonElement(); - if (!autoFillButton) - return IntRect(); - - return autoFillButton->boundsInRootViewSpace(); + toHTMLInputElement(m_node.get())->setAutofilled(filled); } bool InjectedBundleNodeHandle::htmlInputElementLastChangeWasUserEdit() { - if (!is<HTMLInputElement>(m_node)) + if (!isHTMLInputElement(m_node.get())) return false; - return downcast<HTMLInputElement>(m_node.get()).lastChangeWasUserEdit(); + return toHTMLInputElement(m_node.get())->lastChangeWasUserEdit(); } bool InjectedBundleNodeHandle::htmlTextAreaElementLastChangeWasUserEdit() { - if (!is<HTMLTextAreaElement>(m_node)) - return false; - - return downcast<HTMLTextAreaElement>(m_node.get()).lastChangeWasUserEdit(); -} - -bool InjectedBundleNodeHandle::isTextField() const -{ - if (!is<HTMLInputElement>(m_node)) + if (!isHTMLTextAreaElement(m_node.get())) return false; - return downcast<HTMLInputElement>(m_node.get()).isText(); + return toHTMLTextAreaElement(m_node.get())->lastChangeWasUserEdit(); } PassRefPtr<InjectedBundleNodeHandle> InjectedBundleNodeHandle::htmlTableCellElementCellAbove() { - if (!is<HTMLTableCellElement>(m_node)) - return nullptr; + if (!m_node->hasTagName(tdTag)) + return 0; - return getOrCreate(downcast<HTMLTableCellElement>(m_node.get()).cellAbove()); + return getOrCreate(static_cast<HTMLTableCellElement*>(m_node.get())->cellAbove()); } PassRefPtr<WebFrame> InjectedBundleNodeHandle::documentFrame() { if (!m_node->isDocumentNode()) - return nullptr; + return 0; - Frame* frame = downcast<Document>(m_node.get()).frame(); + Frame* frame = static_cast<Document*>(m_node.get())->frame(); if (!frame) - return nullptr; + return 0; - return WebFrame::fromCoreFrame(*frame); + WebFrameLoaderClient* webFrameLoaderClient = toWebFrameLoaderClient(frame->loader().client()); + return webFrameLoaderClient ? webFrameLoaderClient->webFrame() : 0; } PassRefPtr<WebFrame> InjectedBundleNodeHandle::htmlFrameElementContentFrame() { - if (!is<HTMLFrameElement>(m_node)) - return nullptr; + if (!m_node->hasTagName(frameTag)) + return 0; - Frame* frame = downcast<HTMLFrameElement>(m_node.get()).contentFrame(); + Frame* frame = static_cast<HTMLFrameElement*>(m_node.get())->contentFrame(); if (!frame) - return nullptr; + return 0; - return WebFrame::fromCoreFrame(*frame); + WebFrameLoaderClient* webFrameLoaderClient = toWebFrameLoaderClient(frame->loader().client()); + return webFrameLoaderClient ? webFrameLoaderClient->webFrame() : 0; } PassRefPtr<WebFrame> InjectedBundleNodeHandle::htmlIFrameElementContentFrame() { - if (!is<HTMLIFrameElement>(m_node)) - return nullptr; + if (!m_node->hasTagName(iframeTag)) + return 0; - Frame* frame = downcast<HTMLIFrameElement>(m_node.get()).contentFrame(); + Frame* frame = toHTMLIFrameElement(m_node.get())->contentFrame(); if (!frame) - return nullptr; + return 0; - return WebFrame::fromCoreFrame(*frame); + WebFrameLoaderClient* webFrameLoaderClient = toWebFrameLoaderClient(frame->loader().client()); + return webFrameLoaderClient ? webFrameLoaderClient->webFrame() : 0; } } // namespace WebKit diff --git a/Source/WebKit2/WebProcess/InjectedBundle/DOM/InjectedBundleNodeHandle.h b/Source/WebKit2/WebProcess/InjectedBundle/DOM/InjectedBundleNodeHandle.h index 7cd84a604..4cb3ec93c 100644 --- a/Source/WebKit2/WebProcess/InjectedBundle/DOM/InjectedBundleNodeHandle.h +++ b/Source/WebKit2/WebProcess/InjectedBundle/DOM/InjectedBundleNodeHandle.h @@ -40,39 +40,32 @@ namespace WebCore { namespace WebKit { -class InjectedBundleRangeHandle; class InjectedBundleScriptWorld; class WebFrame; class WebImage; class InjectedBundleNodeHandle : public API::ObjectImpl<API::Object::Type::BundleNodeHandle> { public: - static RefPtr<InjectedBundleNodeHandle> getOrCreate(JSContextRef, JSObjectRef); - static RefPtr<InjectedBundleNodeHandle> getOrCreate(WebCore::Node*); - static Ref<InjectedBundleNodeHandle> getOrCreate(WebCore::Node&); + static PassRefPtr<InjectedBundleNodeHandle> getOrCreate(JSContextRef, JSObjectRef); + static PassRefPtr<InjectedBundleNodeHandle> getOrCreate(WebCore::Node*); virtual ~InjectedBundleNodeHandle(); - WebCore::Node* coreNode(); + WebCore::Node* coreNode() const; // Convenience DOM Operations - Ref<InjectedBundleNodeHandle> document(); + PassRefPtr<InjectedBundleNodeHandle> document(); // Additional DOM Operations // Note: These should only be operations that are not exposed to JavaScript. - WebCore::IntRect elementBounds(); - WebCore::IntRect renderRect(bool*); + WebCore::IntRect elementBounds() const; + WebCore::IntRect renderRect(bool*) const; PassRefPtr<WebImage> renderedImage(SnapshotOptions); - PassRefPtr<InjectedBundleRangeHandle> visibleRange(); void setHTMLInputElementValueForUser(const String&); - bool isHTMLInputElementAutoFilled() const; - void setHTMLInputElementAutoFilled(bool); - bool isHTMLInputElementAutoFillButtonEnabled() const; - void setHTMLInputElementAutoFillButtonEnabled(bool); - WebCore::IntRect htmlInputElementAutoFillButtonBounds(); + bool isHTMLInputElementAutofilled() const; + void setHTMLInputElementAutofilled(bool); bool htmlInputElementLastChangeWasUserEdit(); bool htmlTextAreaElementLastChangeWasUserEdit(); - bool isTextField() const; PassRefPtr<InjectedBundleNodeHandle> htmlTableCellElementCellAbove(); @@ -81,10 +74,10 @@ public: PassRefPtr<WebFrame> htmlIFrameElementContentFrame(); private: - static Ref<InjectedBundleNodeHandle> create(WebCore::Node&); - InjectedBundleNodeHandle(WebCore::Node&); + static PassRefPtr<InjectedBundleNodeHandle> create(WebCore::Node*); + InjectedBundleNodeHandle(WebCore::Node*); - Ref<WebCore::Node> m_node; + RefPtr<WebCore::Node> m_node; }; } // namespace WebKit diff --git a/Source/WebKit2/WebProcess/InjectedBundle/DOM/InjectedBundleRangeHandle.cpp b/Source/WebKit2/WebProcess/InjectedBundle/DOM/InjectedBundleRangeHandle.cpp index 2e759dece..9b947d103 100644 --- a/Source/WebKit2/WebProcess/InjectedBundle/DOM/InjectedBundleRangeHandle.cpp +++ b/Source/WebKit2/WebProcess/InjectedBundle/DOM/InjectedBundleRangeHandle.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010, 2015 Apple Inc. All rights reserved. + * Copyright (C) 2010 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -26,20 +26,9 @@ #include "config.h" #include "InjectedBundleRangeHandle.h" -#include "ShareableBitmap.h" -#include "WebImage.h" #include <JavaScriptCore/APICast.h> -#include <WebCore/Document.h> -#include <WebCore/FloatRect.h> -#include <WebCore/Frame.h> -#include <WebCore/FrameSelection.h> -#include <WebCore/FrameView.h> -#include <WebCore/GraphicsContext.h> -#include <WebCore/IntRect.h> #include <WebCore/JSRange.h> -#include <WebCore/Page.h> #include <WebCore/Range.h> -#include <WebCore/VisibleSelection.h> #include <wtf/HashMap.h> #include <wtf/NeverDestroyed.h> @@ -57,7 +46,7 @@ static DOMHandleCache& domHandleCache() PassRefPtr<InjectedBundleRangeHandle> InjectedBundleRangeHandle::getOrCreate(JSContextRef, JSObjectRef object) { - Range* range = JSRange::toWrapped(toJS(object)); + Range* range = toRange(toJS(object)); return getOrCreate(range); } @@ -75,9 +64,9 @@ PassRefPtr<InjectedBundleRangeHandle> InjectedBundleRangeHandle::getOrCreate(Ran return rangeHandle.release(); } -Ref<InjectedBundleRangeHandle> InjectedBundleRangeHandle::create(Range* range) +PassRefPtr<InjectedBundleRangeHandle> InjectedBundleRangeHandle::create(Range* range) { - return adoptRef(*new InjectedBundleRangeHandle(range)); + return adoptRef(new InjectedBundleRangeHandle(range)); } InjectedBundleRangeHandle::InjectedBundleRangeHandle(Range* range) @@ -95,60 +84,4 @@ Range* InjectedBundleRangeHandle::coreRange() const return m_range.get(); } -WebCore::IntRect InjectedBundleRangeHandle::boundingRectInWindowCoordinates() const -{ - FloatRect boundingRect = m_range->boundingRect(); - Frame* frame = m_range->ownerDocument().frame(); - return frame->view()->contentsToWindow(enclosingIntRect(boundingRect)); -} - -PassRefPtr<WebImage> InjectedBundleRangeHandle::renderedImage(SnapshotOptions options) -{ - Document& ownerDocument = m_range->ownerDocument(); - Frame* frame = ownerDocument.frame(); - if (!frame) - return nullptr; - - FrameView* frameView = frame->view(); - if (!frameView) - return nullptr; - - VisibleSelection oldSelection = frame->selection().selection(); - frame->selection().setSelection(VisibleSelection(*m_range)); - - float scaleFactor = (options & SnapshotOptionsExcludeDeviceScaleFactor) ? 1 : frame->page()->deviceScaleFactor(); - IntRect paintRect = enclosingIntRect(m_range->boundingRect()); - IntSize backingStoreSize = paintRect.size(); - backingStoreSize.scale(scaleFactor); - - RefPtr<ShareableBitmap> backingStore = ShareableBitmap::createShareable(backingStoreSize, ShareableBitmap::SupportsAlpha); - if (!backingStore) - return nullptr; - - auto graphicsContext = backingStore->createGraphicsContext(); - graphicsContext->scale(FloatSize(scaleFactor, scaleFactor)); - - paintRect.move(frameView->frameRect().x(), frameView->frameRect().y()); - paintRect.move(-frameView->scrollOffset()); - - graphicsContext->translate(-paintRect.x(), -paintRect.y()); - - PaintBehavior oldPaintBehavior = frameView->paintBehavior(); - PaintBehavior paintBehavior = oldPaintBehavior | PaintBehaviorSelectionOnly | PaintBehaviorFlattenCompositingLayers; - if (options & SnapshotOptionsForceBlackText) - paintBehavior |= PaintBehaviorForceBlackText; - if (options & SnapshotOptionsForceWhiteText) - paintBehavior |= PaintBehaviorForceWhiteText; - - frameView->setPaintBehavior(paintBehavior); - ownerDocument.updateLayout(); - - frameView->paint(graphicsContext.get(), paintRect); - frameView->setPaintBehavior(oldPaintBehavior); - - frame->selection().setSelection(oldSelection); - - return WebImage::create(backingStore); -} - } // namespace WebKit diff --git a/Source/WebKit2/WebProcess/InjectedBundle/DOM/InjectedBundleRangeHandle.h b/Source/WebKit2/WebProcess/InjectedBundle/DOM/InjectedBundleRangeHandle.h index aeef69e2c..7695b4366 100644 --- a/Source/WebKit2/WebProcess/InjectedBundle/DOM/InjectedBundleRangeHandle.h +++ b/Source/WebKit2/WebProcess/InjectedBundle/DOM/InjectedBundleRangeHandle.h @@ -27,20 +27,17 @@ #define InjectedBundleRangeHandle_h #include "APIObject.h" -#include "ImageOptions.h" #include <JavaScriptCore/JSBase.h> #include <wtf/PassRefPtr.h> #include <wtf/RefPtr.h> namespace WebCore { -class IntRect; -class Range; + class Range; } namespace WebKit { class InjectedBundleScriptWorld; -class WebImage; class InjectedBundleRangeHandle : public API::ObjectImpl<API::Object::Type::BundleRangeHandle> { public: @@ -49,13 +46,10 @@ public: virtual ~InjectedBundleRangeHandle(); - WebCore::IntRect boundingRectInWindowCoordinates() const; - PassRefPtr<WebImage> renderedImage(SnapshotOptions); - WebCore::Range* coreRange() const; private: - static Ref<InjectedBundleRangeHandle> create(WebCore::Range*); + static PassRefPtr<InjectedBundleRangeHandle> create(WebCore::Range*); InjectedBundleRangeHandle(WebCore::Range*); RefPtr<WebCore::Range> m_range; |
