<rdar://problem/8494396> WebKit2 lacks API for obtaining a representation of the...
authormitz@apple.com <mitz@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 7 Mar 2012 20:23:37 +0000 (20:23 +0000)
committermitz@apple.com <mitz@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 7 Mar 2012 20:23:37 +0000 (20:23 +0000)
https://bugs.webkit.org/show_bug.cgi?id=80230

Reviewed by Beth Dakin.

* CMakeLists.txt:
* GNUmakefile.am:

* Shared/API/c/WKBase.h: Added a type definition of WKRenderObjectRef.

* Shared/API/c/WKRenderObject.cpp: Added.
(WKRenderObjectGetTypeID): Added. Returns the WKRenderObject type ID.
(WKRenderObjectCopyName): Added this getter wrapper.
(WKRenderObjectGetAbsolutePosition): Ditto.
(WKRenderObjectGetFrameRect): Ditto.
(WKRenderObjectGetChildren): Ditto.

* Shared/API/c/WKRenderObject.h: Added.

* Shared/APIObject.h: Added TypeRenderObject to the APIObject::Type enum.
* Shared/UserMessageCoders.h:
(WebKit::UserMessageEncoder::baseEncode): Added WebRenderObject encoding.
(WebKit::UserMessageDecoder::baseDecode): Added WebRenderObject decoding.
* Shared/WebRenderObject.cpp: Added.
(WebKit::WebRenderObject::create): Added. Creates a WebRenderObject for the page’s main
frame content renderer.
(WebKit::WebRenderObject::WebRenderObject): Added. Constructs a WebRenderObject with the
name, metrics and children of the given RenderObject, following the rules used in WebKit1
WebRenderNode. In particular, a RenderWidget representing a frame gets the frame’s content
renderer as a child.

* Shared/WebRenderObject.h: Added.
(WebKit::WebRenderObject::create):
(WebKit::WebRenderObject::children):
(WebKit::WebRenderObject::name):
(WebKit::WebRenderObject::absolutePosition):
(WebKit::WebRenderObject::frameRect):
(WebKit::WebRenderObject::WebRenderObject):

* Target.pri:

* UIProcess/API/C/WKAPICast.h: Added a mapping between WKRenderObjectRef and WebRenderObject.

* WebKit2.xcodeproj/project.pbxproj: Added WebRenderObject.{cpp,h} and WKRenderObject.{cpp.h}.

* WebProcess/InjectedBundle/API/c/WKBundlePage.cpp:
(WKBundlePageCopyRenderTree): Added this bundle API for getting the render tree.

* WebProcess/InjectedBundle/API/c/WKBundlePagePrivate.h:

* win/WebKit2.vcproj:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@110085 268f45cc-cd09-0410-ab3c-d52691b4dbfc

16 files changed:
Source/WebKit2/CMakeLists.txt
Source/WebKit2/ChangeLog
Source/WebKit2/GNUmakefile.am
Source/WebKit2/Shared/API/c/WKBase.h
Source/WebKit2/Shared/API/c/WKRenderObject.cpp [new file with mode: 0644]
Source/WebKit2/Shared/API/c/WKRenderObject.h [new file with mode: 0644]
Source/WebKit2/Shared/APIObject.h
Source/WebKit2/Shared/UserMessageCoders.h
Source/WebKit2/Shared/WebRenderObject.cpp [new file with mode: 0644]
Source/WebKit2/Shared/WebRenderObject.h [new file with mode: 0644]
Source/WebKit2/Target.pri
Source/WebKit2/UIProcess/API/C/WKAPICast.h
Source/WebKit2/WebKit2.xcodeproj/project.pbxproj
Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundlePage.cpp
Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundlePagePrivate.h
Source/WebKit2/win/WebKit2.vcproj

index 574432e8766519ff8a278a25ffcd5be2439d6b29..095c6ab160b8e4e397856b9018e83faddf018c9d 100644 (file)
@@ -155,6 +155,7 @@ SET(WebKit2_SOURCES
     Shared/WebPopupItem.cpp
     Shared/WebPreferencesStore.cpp
     Shared/WebProcessCreationParameters.cpp
+    Shared/WebRenderObject.cpp
     Shared/WebTouchEvent.cpp
     Shared/WebURLRequest.cpp
     Shared/WebURLResponse.cpp
@@ -173,6 +174,7 @@ SET(WebKit2_SOURCES
     Shared/API/c/WKMutableArray.cpp
     Shared/API/c/WKMutableDictionary.cpp
     Shared/API/c/WKNumber.cpp
+    Shared/API/c/WKRenderObject.cpp
     Shared/API/c/WKSecurityOrigin.cpp
     Shared/API/c/WKSerializedScriptValue.cpp
     Shared/API/c/WKString.cpp
index 33fae807b98e87959f33b82833086065084d6856..a621213e8a6a78f902b49712160208d078dc48da 100644 (file)
@@ -1,3 +1,57 @@
+2012-03-07  Dan Bernstein  <mitz@apple.com>
+
+        <rdar://problem/8494396> WebKit2 lacks API for obtaining a representation of the render tree of a page, like WebRenderNode
+        https://bugs.webkit.org/show_bug.cgi?id=80230
+
+        Reviewed by Beth Dakin.
+
+        * CMakeLists.txt:
+        * GNUmakefile.am:
+
+        * Shared/API/c/WKBase.h: Added a type definition of WKRenderObjectRef.
+
+        * Shared/API/c/WKRenderObject.cpp: Added.
+        (WKRenderObjectGetTypeID): Added. Returns the WKRenderObject type ID.
+        (WKRenderObjectCopyName): Added this getter wrapper.
+        (WKRenderObjectGetAbsolutePosition): Ditto.
+        (WKRenderObjectGetFrameRect): Ditto.
+        (WKRenderObjectGetChildren): Ditto.
+
+        * Shared/API/c/WKRenderObject.h: Added.
+
+        * Shared/APIObject.h: Added TypeRenderObject to the APIObject::Type enum.
+        * Shared/UserMessageCoders.h:
+        (WebKit::UserMessageEncoder::baseEncode): Added WebRenderObject encoding.
+        (WebKit::UserMessageDecoder::baseDecode): Added WebRenderObject decoding.
+        * Shared/WebRenderObject.cpp: Added.
+        (WebKit::WebRenderObject::create): Added. Creates a WebRenderObject for the page’s main
+        frame content renderer.
+        (WebKit::WebRenderObject::WebRenderObject): Added. Constructs a WebRenderObject with the
+        name, metrics and children of the given RenderObject, following the rules used in WebKit1
+        WebRenderNode. In particular, a RenderWidget representing a frame gets the frame’s content
+        renderer as a child.
+
+        * Shared/WebRenderObject.h: Added.
+        (WebKit::WebRenderObject::create):
+        (WebKit::WebRenderObject::children):
+        (WebKit::WebRenderObject::name):
+        (WebKit::WebRenderObject::absolutePosition):
+        (WebKit::WebRenderObject::frameRect):
+        (WebKit::WebRenderObject::WebRenderObject):
+
+        * Target.pri:
+
+        * UIProcess/API/C/WKAPICast.h: Added a mapping between WKRenderObjectRef and WebRenderObject.
+
+        * WebKit2.xcodeproj/project.pbxproj: Added WebRenderObject.{cpp,h} and WKRenderObject.{cpp.h}.
+
+        * WebProcess/InjectedBundle/API/c/WKBundlePage.cpp:
+        (WKBundlePageCopyRenderTree): Added this bundle API for getting the render tree.
+
+        * WebProcess/InjectedBundle/API/c/WKBundlePagePrivate.h:
+
+        * win/WebKit2.vcproj:
+
 2012-03-07  Kenneth Rohde Christiansen  <kenneth@webkit.org>
 
         Pinch zoom acts weirdly on nytimes.com while loading
index 613ebb44786c29b2a9d234a60f77b3eeb40cf940..45c4ff34fab4ede685dfa9cf38d184adb6680dd4 100644 (file)
@@ -19,6 +19,7 @@ libwebkit2gtk_@WEBKITGTK_API_MAJOR_VERSION@_@WEBKITGTK_API_MINOR_VERSION@_la_HEA
        $(WebKit2)/Shared/API/c/WKMutableDictionary.h \
        $(WebKit2)/Shared/API/c/WKNumber.h \
        $(WebKit2)/Shared/API/c/WKPageLoadTypes.h \
+       $(WebKit2)/Shared/API/c/WKRenderObject.h \
        $(WebKit2)/Shared/API/c/WKSecurityOrigin.h \
        $(WebKit2)/Shared/API/c/WKSerializedScriptValue.h \
        $(WebKit2)/Shared/API/c/WKSerializedScriptValuePrivate.h \
@@ -288,6 +289,8 @@ webkit2_sources += \
        Source/WebKit2/Shared/API/c/WKNumber.cpp \
        Source/WebKit2/Shared/API/c/WKNumber.h \
        Source/WebKit2/Shared/API/c/WKPageLoadTypes.h \
+       Source/WebKit2/Shared/API/c/WKRenderObject.cpp \
+       Source/WebKit2/Shared/API/c/WKRenderObject.h \
        Source/WebKit2/Shared/API/c/WKSecurityOrigin.cpp \
        Source/WebKit2/Shared/API/c/WKSecurityOrigin.h \
        Source/WebKit2/Shared/API/c/WKSerializedScriptValue.cpp \
@@ -435,6 +438,8 @@ webkit2_sources += \
        Source/WebKit2/Shared/WebPreferencesStore.h \
        Source/WebKit2/Shared/WebProcessCreationParameters.cpp \
        Source/WebKit2/Shared/WebProcessCreationParameters.h \
+       Source/WebKit2/Shared/WebRenderObject.cpp \
+       Source/WebKit2/Shared/WebRenderObject.h \
        Source/WebKit2/Shared/WebSecurityOrigin.h \
        Source/WebKit2/Shared/WebSerializedScriptValue.h \
        Source/WebKit2/Shared/WebString.h \
index adbce6d684b668dd01039a2f481afefc4b64e9eb..5200beabd35a54c055de8e4132f3f414f7a4b93f 100644 (file)
@@ -59,6 +59,7 @@ typedef const struct OpaqueWKGraphicsContext* WKGraphicsContextRef;
 typedef const struct OpaqueWKImage* WKImageRef;
 typedef const struct OpaqueWKPointRef* WKPointRef;
 typedef const struct OpaqueWKRectRef* WKRectRef;
+typedef const struct OpaqueWKRenderObject* WKRenderObjectRef;
 typedef const struct OpaqueWKSecurityOrigin* WKSecurityOriginRef;
 typedef const struct OpaqueWKSerializedScriptValue* WKSerializedScriptValueRef;
 typedef const struct OpaqueWKSizeRef* WKSizeRef;
diff --git a/Source/WebKit2/Shared/API/c/WKRenderObject.cpp b/Source/WebKit2/Shared/API/c/WKRenderObject.cpp
new file mode 100644 (file)
index 0000000..1c72749
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2012 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 "WKRenderObject.h"
+
+#include "WKAPICast.h"
+#include "WebRenderObject.h"
+
+using namespace WebCore;
+using namespace WebKit;
+
+WKTypeID WKRenderObjectGetTypeID()
+{
+    return toAPI(WebRenderObject::APIType);
+}
+
+WKStringRef WKRenderObjectCopyName(WKRenderObjectRef renderObjectRef)
+{
+    return toCopiedAPI(toImpl(renderObjectRef)->name());
+}
+
+WKPoint WKRenderObjectGetAbsolutePosition(WKRenderObjectRef renderObjectRef)
+{
+    IntPoint absolutePosition = toImpl(renderObjectRef)->absolutePosition();
+    return WKPointMake(absolutePosition.x(), absolutePosition.y());
+}
+
+WKRect WKRenderObjectGetFrameRect(WKRenderObjectRef renderObjectRef)
+{
+    IntRect frameRect = toImpl(renderObjectRef)->frameRect();
+    return WKRectMake(frameRect.x(), frameRect.y(), frameRect.width(), frameRect.height());
+}
+
+WKArrayRef WKRenderObjectGetChildren(WKRenderObjectRef renderObjectRef)
+{
+    return toAPI(toImpl(renderObjectRef)->children().get());
+}
diff --git a/Source/WebKit2/Shared/API/c/WKRenderObject.h b/Source/WebKit2/Shared/API/c/WKRenderObject.h
new file mode 100644 (file)
index 0000000..51d1e22
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2012 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 WKRenderObject_h
+#define WKRenderObject_h
+
+#include <WebKit2/WKBase.h>
+#include <WebKit2/WKGeometry.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+WK_EXPORT WKTypeID WKRenderObjectGetTypeID();
+
+WK_EXPORT WKStringRef WKRenderObjectCopyName(WKRenderObjectRef renderObject);
+WK_EXPORT WKPoint WKRenderObjectGetAbsolutePosition(WKRenderObjectRef renderObject);
+WK_EXPORT WKRect WKRenderObjectGetFrameRect(WKRenderObjectRef renderObject);
+WK_EXPORT WKArrayRef WKRenderObjectGetChildren(WKRenderObjectRef renderObject);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // WKRenderObject_h
index 183cea0a460a101d7d7033c3c457345b603663ba..48d1d82fb96f64e8542ce0174dd662dd2bcba5ca 100644 (file)
@@ -48,6 +48,7 @@ public:
         TypeGraphicsContext,
         TypeImage,
         TypeProtectionSpace,
+        TypeRenderObject,
         TypeSecurityOrigin,
         TypeSerializedScriptValue,
         TypeString,
index df3860805f031b174c65ba65004ac654a6dd3041..47bce57f3dbde90654ba28b538b0e5f202a3f488 100644 (file)
@@ -38,6 +38,7 @@
 #include "WebGeometry.h"
 #include "WebImage.h"
 #include "WebNumber.h"
+#include "WebRenderObject.h"
 #include "WebSerializedScriptValue.h"
 #include "WebString.h"
 #include "WebURL.h"
@@ -56,6 +57,7 @@ namespace WebKit {
 //   - WebData -> WebData
 //   - WebDouble -> WebDouble
 //   - WebImage -> WebImage
+//   - WebRenderObject -> WebRenderObject
 //   - WebUInt64 -> WebUInt64
 //   - WebURL -> WebURL
 //   - WebURLRequest -> WebURLRequest
@@ -139,6 +141,14 @@ public:
             encoder->encode(rectObject->rect().size.height);
             return true;
         }
+        case APIObject::TypeRenderObject: {
+            WebRenderObject* renderObject = static_cast<WebRenderObject*>(m_root);
+            encoder->encode(renderObject->name());
+            encoder->encode(renderObject->absolutePosition());
+            encoder->encode(renderObject->frameRect());
+            encoder->encode(Owner(renderObject->children().get()));
+            return true;
+        }
         case APIObject::TypeURL: {
             WebURL* urlObject = static_cast<WebURL*>(m_root);
             encoder->encode(urlObject->string());
@@ -338,6 +348,26 @@ public:
             coder.m_root = WebRect::create(WKRectMake(x, y, width, height));
             break;
         }
+        case APIObject::TypeRenderObject: {
+            String name;
+            WebCore::IntPoint absolutePosition;
+            WebCore::IntRect frameRect;
+            RefPtr<APIObject> children;
+            
+            if (!decoder->decode(name))
+                return false;
+            if (!decoder->decode(absolutePosition))
+                return false;
+            if (!decoder->decode(frameRect))
+                return false;
+            Owner messageCoder(coder, children);
+            if (!decoder->decode(messageCoder))
+                return false;
+            if (children->type() != APIObject::TypeArray)
+                return false;
+            coder.m_root = WebRenderObject::create(name, absolutePosition, frameRect, WTF::static_pointer_cast<MutableArray>(children));
+            break;
+        }
         case APIObject::TypeURL: {
             String string;
             if (!decoder->decode(string))
diff --git a/Source/WebKit2/Shared/WebRenderObject.cpp b/Source/WebKit2/Shared/WebRenderObject.cpp
new file mode 100644 (file)
index 0000000..6f3bcff
--- /dev/null
@@ -0,0 +1,92 @@
+/*
+ * Copyright (C) 2012 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 "WebRenderObject.h"
+
+#include "WebPage.h"
+#include <WebCore/Frame.h>
+#include <WebCore/FrameLoaderClient.h>
+#include <WebCore/RenderText.h>
+#include <WebCore/RenderView.h>
+#include <WebCore/RenderWidget.h>
+
+using namespace WebCore;
+
+namespace WebKit {
+
+PassRefPtr<WebRenderObject> WebRenderObject::create(WebPage* page)
+{
+    Frame* mainFrame = page->mainFrame();
+    if (!mainFrame)
+        return 0;
+
+    if (!mainFrame->loader()->client()->hasHTMLView())
+        return 0;
+
+    RenderView* contentRenderer = mainFrame->contentRenderer();
+    if (!contentRenderer)
+        return 0;
+
+    return adoptRef(new WebRenderObject(contentRenderer));
+}
+
+WebRenderObject::WebRenderObject(RenderObject* renderer)
+{
+    m_name = renderer->renderName();
+
+    // FIXME: broken with transforms
+    m_absolutePosition = flooredIntPoint(renderer->localToAbsolute(FloatPoint()));
+
+    if (renderer->isBox())
+        m_frameRect = toRenderBox(renderer)->frameRect();
+    else if (renderer->isText()) {
+        m_frameRect = toRenderText(renderer)->linesBoundingBox();
+        m_frameRect.setX(toRenderText(renderer)->firstRunX());
+        m_frameRect.setY(toRenderText(renderer)->firstRunY());
+    } else if (renderer->isRenderInline())
+        m_frameRect = toRenderBoxModelObject(renderer)->borderBoundingBox();
+
+    m_children = MutableArray::create();
+    for (RenderObject* coreChild = renderer->firstChild(); coreChild; coreChild = coreChild->nextSibling()) {
+        RefPtr<WebRenderObject> child = adoptRef(new WebRenderObject(coreChild));
+        m_children->append(child.get());
+    }
+
+    if (!renderer->isWidget())
+        return;
+
+    Widget* widget = toRenderWidget(renderer)->widget();
+    if (!widget || !widget->isFrameView())
+        return;
+
+    FrameView* frameView = static_cast<FrameView*>(widget);
+    if (RenderView* coreContentRenderer = frameView->frame()->contentRenderer()) {
+        RefPtr<WebRenderObject> contentRenderer = adoptRef(new WebRenderObject(coreContentRenderer));
+        m_children->append(contentRenderer.get());
+    }
+}
+
+} // namespace WebKit
diff --git a/Source/WebKit2/Shared/WebRenderObject.h b/Source/WebKit2/Shared/WebRenderObject.h
new file mode 100644 (file)
index 0000000..1fcb03c
--- /dev/null
@@ -0,0 +1,81 @@
+/*
+ * Copyright (C) 2012 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 WebRenderObject_h
+#define WebRenderObject_h
+
+#include "APIObject.h"
+#include "MutableArray.h"
+#include <WebCore/IntRect.h>
+#include <wtf/PassRefPtr.h>
+#include <wtf/Vector.h>
+#include <wtf/text/WTFString.h>
+
+namespace WebCore {
+    class RenderObject;
+}
+
+namespace WebKit {
+
+class WebPage;
+
+class WebRenderObject : public APIObject {
+public:
+    static const Type APIType = TypeRenderObject;
+
+    static PassRefPtr<WebRenderObject> create(WebPage*);
+    static PassRefPtr<WebRenderObject> create(const String& name, WebCore::IntPoint absolutePosition, WebCore::IntRect frameRect, PassRefPtr<MutableArray> children)
+    {
+        return adoptRef(new WebRenderObject(name, absolutePosition, frameRect, children));
+    }
+
+    RefPtr<ImmutableArray> children() const { return m_children; }
+
+    const String& name() const { return m_name; }
+    WebCore::IntPoint absolutePosition() const { return m_absolutePosition; }
+    WebCore::IntRect frameRect() const { return m_frameRect; }
+
+private:
+    WebRenderObject(WebCore::RenderObject*);
+    WebRenderObject(const String& name, WebCore::IntPoint absolutePosition, WebCore::IntRect frameRect, PassRefPtr<MutableArray> children)
+        : m_children(children)
+        , m_name(name)
+        , m_absolutePosition(absolutePosition)
+        , m_frameRect(frameRect)
+    {
+    }
+
+    virtual Type type() const OVERRIDE { return APIType; }
+
+    RefPtr<MutableArray> m_children;
+
+    String m_name;
+    WebCore::IntPoint m_absolutePosition;
+    WebCore::IntRect m_frameRect;
+};
+
+} // namespace WebKit
+
+#endif // WebRenderObject_h
index 132056aa332f6dc8c766acfec89fe4f4d077720b..226160fbc73fa20094b50dc2e8753a2f0de46056 100644 (file)
@@ -49,6 +49,7 @@ HEADERS += \
     Shared/API/c/WKMutableDictionary.h \
     Shared/API/c/WKNumber.h \
     Shared/API/c/WKPageLoadTypes.h \
+    Shared/API/c/WKRenderObject.h \
     Shared/API/c/WKSecurityOrigin.h \
     Shared/API/c/WKSerializedScriptValue.h \
     Shared/API/c/WKSharedAPICast.h \
@@ -112,6 +113,7 @@ HEADERS += \
     Shared/WebPopupItem.h \
     Shared/WebPreferencesStore.h \
     Shared/WebProcessCreationParameters.h \
+    Shared/WebRenderObject.h \
     Shared/WebURLRequest.h \
     Shared/WebURLResponse.h \
     Shared/WebUserContentURLPattern.h \
@@ -393,6 +395,7 @@ SOURCES += \
     Shared/API/c/WKImage.cpp \
     Shared/API/c/WKMutableDictionary.cpp \
     Shared/API/c/WKNumber.cpp \
+    Shared/API/c/WKRenderObject.cpp \
     Shared/API/c/WKSecurityOrigin.cpp \
     Shared/API/c/WKSerializedScriptValue.cpp \
     Shared/API/c/WKString.cpp \
@@ -455,6 +458,7 @@ SOURCES += \
     Shared/WebPopupItem.cpp \
     Shared/WebPreferencesStore.cpp \
     Shared/WebProcessCreationParameters.cpp \
+    Shared/WebRenderObject.cpp \
     Shared/WebTouchEvent.cpp \
     Shared/WebURLRequest.cpp \
     Shared/WebURLResponse.cpp \
index 0e7175a428f780820c8971de39c96510aaafac90..296cd8648c3d1a3254bfb07bf063bf650c7a6ba8 100644 (file)
@@ -83,6 +83,7 @@ class WebPageProxy;
 class WebPluginSiteDataManager;
 class WebPreferences;
 class WebProtectionSpace;
+class WebRenderObject;
 class WebTextChecker;
 
 WK_ADD_API_MAPPING(WKApplicationCacheManagerRef, WebApplicationCacheManagerProxy)
@@ -119,6 +120,7 @@ WK_ADD_API_MAPPING(WKPageRef, WebPageProxy)
 WK_ADD_API_MAPPING(WKPluginSiteDataManagerRef, WebPluginSiteDataManager)
 WK_ADD_API_MAPPING(WKPreferencesRef, WebPreferences)
 WK_ADD_API_MAPPING(WKProtectionSpaceRef, WebProtectionSpace)
+WK_ADD_API_MAPPING(WKRenderObjectRef, WebRenderObject)
 WK_ADD_API_MAPPING(WKTextCheckerRef, WebTextChecker)
 
 #if ENABLE(INSPECTOR)
index e3ffc85b2ccb455b906dd226208e97e878aec16b..203d24d512cb8992dfbfd0fc330526dec1318426 100644 (file)
                33D3A3CA1339617900709BE4 /* WebMediaCacheManagerProxyMessageReceiver.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 33D3A3C61339617900709BE4 /* WebMediaCacheManagerProxyMessageReceiver.cpp */; };
                33D3A3CB1339617900709BE4 /* WebMediaCacheManagerProxyMessages.h in Headers */ = {isa = PBXBuildFile; fileRef = 33D3A3C71339617900709BE4 /* WebMediaCacheManagerProxyMessages.h */; };
                33F9D5B91312F1EE000D683F /* WebResourceCacheManagerCFNet.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 33F9D5B81312F1EE000D683F /* WebResourceCacheManagerCFNet.cpp */; };
+               3760881E150413E900FC82C7 /* WebRenderObject.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3760881C150413E900FC82C7 /* WebRenderObject.cpp */; };
+               3760881F150413E900FC82C7 /* WebRenderObject.h in Headers */ = {isa = PBXBuildFile; fileRef = 3760881D150413E900FC82C7 /* WebRenderObject.h */; };
+               37608822150414F700FC82C7 /* WKRenderObject.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37608820150414F700FC82C7 /* WKRenderObject.cpp */; };
+               37608823150414F700FC82C7 /* WKRenderObject.h in Headers */ = {isa = PBXBuildFile; fileRef = 37608821150414F700FC82C7 /* WKRenderObject.h */; settings = {ATTRIBUTES = (Private, ); }; };
                3788A05C14743C90006319E5 /* WKBrowsingContextControllerPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = 3788A05B14743C90006319E5 /* WKBrowsingContextControllerPrivate.h */; settings = {ATTRIBUTES = (Private, ); }; };
                37C4E9F6131C6E7E0029BD5A /* config.h in Headers */ = {isa = PBXBuildFile; fileRef = B396EA5512E0ED2D00F4FEB7 /* config.h */; };
                37F623B812A57B6200E3FDF6 /* WKFindOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = 37F623B712A57B6200E3FDF6 /* WKFindOptions.h */; settings = {ATTRIBUTES = (Private, ); }; };
                33D3A3C61339617900709BE4 /* WebMediaCacheManagerProxyMessageReceiver.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebMediaCacheManagerProxyMessageReceiver.cpp; sourceTree = "<group>"; };
                33D3A3C71339617900709BE4 /* WebMediaCacheManagerProxyMessages.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebMediaCacheManagerProxyMessages.h; sourceTree = "<group>"; };
                33F9D5B81312F1EE000D683F /* WebResourceCacheManagerCFNet.cpp */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.objcpp; fileEncoding = 4; name = WebResourceCacheManagerCFNet.cpp; path = ResourceCache/cf/WebResourceCacheManagerCFNet.cpp; sourceTree = "<group>"; };
+               3760881C150413E900FC82C7 /* WebRenderObject.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebRenderObject.cpp; sourceTree = "<group>"; };
+               3760881D150413E900FC82C7 /* WebRenderObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebRenderObject.h; sourceTree = "<group>"; };
+               37608820150414F700FC82C7 /* WKRenderObject.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WKRenderObject.cpp; sourceTree = "<group>"; };
+               37608821150414F700FC82C7 /* WKRenderObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKRenderObject.h; sourceTree = "<group>"; };
                3788A05B14743C90006319E5 /* WKBrowsingContextControllerPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKBrowsingContextControllerPrivate.h; sourceTree = "<group>"; };
                37F623B712A57B6200E3FDF6 /* WKFindOptions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKFindOptions.h; sourceTree = "<group>"; };
                510031F61379CACB00C8DFE4 /* WebProcessShim.dylib */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.dylib"; includeInIndex = 0; path = WebProcessShim.dylib; sourceTree = BUILT_PRODUCTS_DIR; };
                                BCD598AA112B7FDF00EC8C23 /* WebPreferencesStore.h */,
                                BC306823125A6B9400E71278 /* WebProcessCreationParameters.cpp */,
                                BC306822125A6B9400E71278 /* WebProcessCreationParameters.h */,
+                               3760881C150413E900FC82C7 /* WebRenderObject.cpp */,
+                               3760881D150413E900FC82C7 /* WebRenderObject.h */,
                                F634445512A885C8000612D8 /* WebSecurityOrigin.h */,
                                A72D5D7F1236CBA800A88B15 /* WebSerializedScriptValue.h */,
                                BCF04C8E11FF9F6E00F86A58 /* WebString.h */,
                                BC4075E5124FF0270068F20A /* WKNumber.cpp */,
                                BC4075E6124FF0270068F20A /* WKNumber.h */,
                                BC2D021812AC426C00E732A3 /* WKPageLoadTypes.h */,
+                               37608820150414F700FC82C7 /* WKRenderObject.cpp */,
+                               37608821150414F700FC82C7 /* WKRenderObject.h */,
                                F634445A12A885E9000612D8 /* WKSecurityOrigin.cpp */,
                                F634445B12A885E9000612D8 /* WKSecurityOrigin.h */,
                                BC4075E7124FF0270068F20A /* WKSerializedScriptValue.cpp */,
                                E17BF99614D0A73E00A5A069 /* NetscapeSandboxFunctions.h in Headers */,
                                BCE0937814FB128C001138D9 /* LayerHostingContext.h in Headers */,
                                296BD85D15019BC30071F424 /* StringUtilities.h in Headers */,
+                               3760881F150413E900FC82C7 /* WebRenderObject.h in Headers */,
+                               37608823150414F700FC82C7 /* WKRenderObject.h in Headers */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
                                E17BF99814D0AA8300A5A069 /* NetscapeSandboxFunctions.mm in Sources */,
                                BCE0937714FB128C001138D9 /* LayerHostingContext.mm in Sources */,
                                296BD85E15019BC30071F424 /* StringUtilities.mm in Sources */,
+                               3760881E150413E900FC82C7 /* WebRenderObject.cpp in Sources */,
+                               37608822150414F700FC82C7 /* WKRenderObject.cpp in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
index 3090c6e65aa594610bc2e2ab4f3acc6d9ccd120b..79e4e752f081d7cce0b8c52246c94b45cfdc854f 100644 (file)
@@ -34,6 +34,7 @@
 #include "WebFullScreenManager.h"
 #include "WebImage.h"
 #include "WebPage.h"
+#include "WebRenderObject.h"
 #include "WebURL.h"
 #include "WebURLRequest.h"
 
@@ -328,6 +329,11 @@ uint64_t WKBundlePageGetRenderTreeSize(WKBundlePageRef pageRef)
     return toImpl(pageRef)->renderTreeSize();
 }
 
+WKRenderObjectRef WKBundlePageCopyRenderTree(WKBundlePageRef pageRef)
+{
+    return toAPI(WebRenderObject::create(toImpl(pageRef)).leakRef());
+}
+
 void WKBundlePageSetPaintedObjectsCounterThreshold(WKBundlePageRef page, uint64_t threshold)
 {
     toImpl(page)->setPaintedObjectsCounterThreshold(threshold);
index 312331e770ad3e5c38aeab32a49b611f0dae76fe..6462e9d57a75b38a1f814d1379da7c083e9113e2 100644 (file)
@@ -55,6 +55,8 @@ WK_EXPORT void WKBundlePageSimulateMouseMotion(WKBundlePageRef page, WKPoint pos
 
 WK_EXPORT uint64_t WKBundlePageGetRenderTreeSize(WKBundlePageRef page);
 
+WK_EXPORT WKRenderObjectRef WKBundlePageCopyRenderTree(WKBundlePageRef page);
+
 // FIXME: This is temporary. Ultimately WebKit should choose the threshold itself.
 WK_EXPORT void WKBundlePageSetPaintedObjectsCounterThreshold(WKBundlePageRef page, uint64_t threshold);
 
index d5b266c0f76ccb004f7064d7171284897635c23e..18ffe90ac0fe99e0828564b01a959b4b4694d739 100755 (executable)
                                RelativePath="..\Shared\WebProcessCreationParameters.h"
                                >
                        </File>
+                       <File
+                               RelativePath="..\Shared\WebRenderObject.cpp"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\Shared\WebRenderObject.h"
+                               >
+                       </File>
                        <File
                                RelativePath="..\Shared\WebSecurityOrigin.h"
                                >
                                        RelativePath="..\Shared\API\c\WKPageLoadTypes.h"
                                        >
                                </File>
+                               <File
+                                       RelativePath="..\Shared\API\c\WKRenderObject.cpp"
+                                       >
+                               </File>
+                               <File
+                                       RelativePath="..\Shared\API\c\WKRenderObject.h"
+                                       >
+                               </File>
                                <File
                                        RelativePath="..\Shared\API\c\WKSecurityOrigin.cpp"
                                        >