From 87dea525f4f53feb3d2db84fd76db5e06b79cdb2 Mon Sep 17 00:00:00 2001 From: "simon.fraser@apple.com" Date: Mon, 26 Sep 2011 19:01:36 +0000 Subject: [PATCH] Repaint tests don't work in WebKit2 https://bugs.webkit.org/show_bug.cgi?id=68453 Reviewed by Sam Weinig. Expose WKBundlePage methods to turn on repaint rect tracking in WebKit2, for WebKitTestRunner. As part of the change, expose utility methods on WebPage to get the main Frame and FrameView, which required renaming the exisiting method that returns a WebFrame. Fix callers of that method to handle null when necessary. * WebProcess/InjectedBundle/API/c/WKBundlePage.cpp: (WKBundlePageGetMainFrame): (WKBundlePageSetTracksRepaints): (WKBundlePageIsTrackingRepaints): (WKBundlePageResetTrackedRepaints): (WKBundlePageCopyTrackedRepaintRects): * WebProcess/InjectedBundle/API/c/WKBundlePagePrivate.h: * WebProcess/WebCoreSupport/WebChromeClient.cpp: (WebKit::findLargestFrameInFrameSet): (WebKit::WebChromeClient::closeWindowSoon): * WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp: (WebKit::WebFrameLoaderClient::dispatchDidFirstLayout): (WebKit::WebFrameLoaderClient::dispatchDidLayout): (WebKit::WebFrameLoaderClient::frameLoadCompleted): (WebKit::WebFrameLoaderClient::restoreViewState): (WebKit::WebFrameLoaderClient::provisionalLoadStarted): (WebKit::WebFrameLoaderClient::transitionToCommittedFromCachedFrame): (WebKit::WebFrameLoaderClient::transitionToCommittedForNewPage): (WebKit::WebFrameLoaderClient::createPlugin): * WebProcess/WebCoreSupport/mac/WebEditorClientMac.mm: (WebKit::WebEditorClient::documentFragmentFromAttributedString): * WebProcess/WebPage/WebFrame.cpp: (WebKit::WebFrame::isMainFrame): * WebProcess/WebPage/WebPage.cpp: (WebKit::WebPage::setTracksRepaints): (WebKit::WebPage::isTrackingRepaints): (WebKit::WebPage::resetTrackedRepaints): (WebKit::WebPage::trackedRepaintRects): (WebKit::WebPage::clearMainFrameName): (WebKit::WebPage::layoutIfNeeded): (WebKit::WebPage::mainFrameHasCustomRepresentation): (WebKit::WebPage::mainFrame): (WebKit::WebPage::mainFrameView): * WebProcess/WebPage/WebPage.h: (WebKit::WebPage::mainWebFrame): * WebProcess/WebPage/mac/WKAccessibilityWebPageObject.mm: (-[WKAccessibilityWebPageObject accessibilityHitTest:]): git-svn-id: http://svn.webkit.org/repository/webkit/trunk@95968 268f45cc-cd09-0410-ab3c-d52691b4dbfc --- Source/WebKit2/ChangeLog | 53 ++++++++++++++++++ .../InjectedBundle/API/c/WKBundlePage.cpp | 23 +++++++- .../InjectedBundle/API/c/WKBundlePagePrivate.h | 6 ++ .../WebProcess/WebCoreSupport/WebChromeClient.cpp | 4 +- .../WebCoreSupport/WebFrameLoaderClient.cpp | 16 +++--- .../WebCoreSupport/mac/WebEditorClientMac.mm | 3 +- Source/WebKit2/WebProcess/WebPage/WebFrame.cpp | 2 +- Source/WebKit2/WebProcess/WebPage/WebPage.cpp | 64 +++++++++++++++++++++- Source/WebKit2/WebProcess/WebPage/WebPage.h | 14 ++++- .../WebPage/mac/WKAccessibilityWebPageObject.mm | 10 ++-- 10 files changed, 172 insertions(+), 23 deletions(-) diff --git a/Source/WebKit2/ChangeLog b/Source/WebKit2/ChangeLog index cbd32be..5ab1e3a 100644 --- a/Source/WebKit2/ChangeLog +++ b/Source/WebKit2/ChangeLog @@ -1,3 +1,56 @@ +2011-09-23 Simon Fraser + + Repaint tests don't work in WebKit2 + https://bugs.webkit.org/show_bug.cgi?id=68453 + + Reviewed by Sam Weinig. + + Expose WKBundlePage methods to turn on repaint rect tracking + in WebKit2, for WebKitTestRunner. + + As part of the change, expose utility methods on WebPage + to get the main Frame and FrameView, which required renaming + the exisiting method that returns a WebFrame. Fix callers + of that method to handle null when necessary. + + * WebProcess/InjectedBundle/API/c/WKBundlePage.cpp: + (WKBundlePageGetMainFrame): + (WKBundlePageSetTracksRepaints): + (WKBundlePageIsTrackingRepaints): + (WKBundlePageResetTrackedRepaints): + (WKBundlePageCopyTrackedRepaintRects): + * WebProcess/InjectedBundle/API/c/WKBundlePagePrivate.h: + * WebProcess/WebCoreSupport/WebChromeClient.cpp: + (WebKit::findLargestFrameInFrameSet): + (WebKit::WebChromeClient::closeWindowSoon): + * WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp: + (WebKit::WebFrameLoaderClient::dispatchDidFirstLayout): + (WebKit::WebFrameLoaderClient::dispatchDidLayout): + (WebKit::WebFrameLoaderClient::frameLoadCompleted): + (WebKit::WebFrameLoaderClient::restoreViewState): + (WebKit::WebFrameLoaderClient::provisionalLoadStarted): + (WebKit::WebFrameLoaderClient::transitionToCommittedFromCachedFrame): + (WebKit::WebFrameLoaderClient::transitionToCommittedForNewPage): + (WebKit::WebFrameLoaderClient::createPlugin): + * WebProcess/WebCoreSupport/mac/WebEditorClientMac.mm: + (WebKit::WebEditorClient::documentFragmentFromAttributedString): + * WebProcess/WebPage/WebFrame.cpp: + (WebKit::WebFrame::isMainFrame): + * WebProcess/WebPage/WebPage.cpp: + (WebKit::WebPage::setTracksRepaints): + (WebKit::WebPage::isTrackingRepaints): + (WebKit::WebPage::resetTrackedRepaints): + (WebKit::WebPage::trackedRepaintRects): + (WebKit::WebPage::clearMainFrameName): + (WebKit::WebPage::layoutIfNeeded): + (WebKit::WebPage::mainFrameHasCustomRepresentation): + (WebKit::WebPage::mainFrame): + (WebKit::WebPage::mainFrameView): + * WebProcess/WebPage/WebPage.h: + (WebKit::WebPage::mainWebFrame): + * WebProcess/WebPage/mac/WKAccessibilityWebPageObject.mm: + (-[WKAccessibilityWebPageObject accessibilityHitTest:]): + 2011-09-25 Mark Hahnenberg Add custom vtable struct to ClassInfo struct diff --git a/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundlePage.cpp b/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundlePage.cpp index 9f19733..5cbfc5b 100644 --- a/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundlePage.cpp +++ b/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundlePage.cpp @@ -123,7 +123,7 @@ WKBundlePageGroupRef WKBundlePageGetPageGroup(WKBundlePageRef pageRef) WKBundleFrameRef WKBundlePageGetMainFrame(WKBundlePageRef pageRef) { - return toAPI(toImpl(pageRef)->mainFrame()); + return toAPI(toImpl(pageRef)->mainWebFrame()); } void WKBundlePageStopLoading(WKBundlePageRef pageRef) @@ -270,3 +270,24 @@ uint64_t WKBundlePageGetRenderTreeSize(WKBundlePageRef pageRef) { return toImpl(pageRef)->renderTreeSize(); } + +void WKBundlePageSetTracksRepaints(WKBundlePageRef pageRef, bool trackRepaints) +{ + toImpl(pageRef)->setTracksRepaints(trackRepaints); +} + +bool WKBundlePageIsTrackingRepaints(WKBundlePageRef pageRef) +{ + return toImpl(pageRef)->isTrackingRepaints(); +} + +void WKBundlePageResetTrackedRepaints(WKBundlePageRef pageRef) +{ + toImpl(pageRef)->resetTrackedRepaints(); +} + +WKArrayRef WKBundlePageCopyTrackedRepaintRects(WKBundlePageRef pageRef) +{ + return toAPI(toImpl(pageRef)->trackedRepaintRects().releaseRef()); +} + diff --git a/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundlePagePrivate.h b/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundlePagePrivate.h index 23bd018..bc01cca 100644 --- a/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundlePagePrivate.h +++ b/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundlePagePrivate.h @@ -55,6 +55,12 @@ WK_EXPORT void WKBundlePageSimulateMouseMotion(WKBundlePageRef page, WKPoint pos WK_EXPORT uint64_t WKBundlePageGetRenderTreeSize(WKBundlePageRef page); +WK_EXPORT void WKBundlePageSetTracksRepaints(WKBundlePageRef page, bool trackRepaints); +WK_EXPORT bool WKBundlePageIsTrackingRepaints(WKBundlePageRef page); +WK_EXPORT void WKBundlePageResetTrackedRepaints(WKBundlePageRef page); +WK_EXPORT WKArrayRef WKBundlePageCopyTrackedRepaintRects(WKBundlePageRef page); + + #ifdef __cplusplus } #endif diff --git a/Source/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.cpp b/Source/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.cpp index 7e27859..72bbcf5 100644 --- a/Source/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.cpp +++ b/Source/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.cpp @@ -75,7 +75,7 @@ static WebFrame* findLargestFrameInFrameSet(WebPage* page) { // Approximate what a user could consider a default target frame for application menu operations. - WebFrame* mainFrame = page->mainFrame(); + WebFrame* mainFrame = page->mainWebFrame(); if (!mainFrame->isFrameSet()) return 0; @@ -294,7 +294,7 @@ void WebChromeClient::closeWindowSoon() m_page->corePage()->setGroupName(String()); - if (WebFrame* frame = m_page->mainFrame()) { + if (WebFrame* frame = m_page->mainWebFrame()) { if (Frame* coreFrame = frame->coreFrame()) coreFrame->loader()->stopForUserCancel(); } diff --git a/Source/WebKit2/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp b/Source/WebKit2/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp index 174e67b..fd8b6b3 100644 --- a/Source/WebKit2/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp +++ b/Source/WebKit2/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp @@ -532,7 +532,7 @@ void WebFrameLoaderClient::dispatchDidFirstLayout() // Notify the UIProcess. webPage->send(Messages::WebPageProxy::DidFirstLayoutForFrame(m_frame->frameID(), InjectedBundleUserMessageEncoder(userData.get()))); - if (m_frame == m_frame->page()->mainFrame()) + if (m_frame == m_frame->page()->mainWebFrame()) webPage->drawingArea()->setLayerTreeStateIsFrozen(false); } @@ -564,7 +564,7 @@ void WebFrameLoaderClient::dispatchDidLayout() // the UIProcess for every call. // FIXME: Remove at the soonest possible time. - if (m_frame == m_frame->page()->mainFrame()) + if (m_frame == m_frame->page()->mainWebFrame()) webPage->send(Messages::WebPageProxy::SetRenderTreeSize(webPage->renderTreeSize())); } @@ -1028,7 +1028,7 @@ void WebFrameLoaderClient::frameLoadCompleted() if (!webPage) return; - if (m_frame == m_frame->page()->mainFrame()) + if (m_frame == m_frame->page()->mainWebFrame()) webPage->drawingArea()->setLayerTreeStateIsFrozen(false); } @@ -1045,7 +1045,7 @@ void WebFrameLoaderClient::restoreViewState() // FIXME: This should not be necessary. WebCore should be correctly invalidating // the view on restores from the back/forward cache. - if (m_frame == m_frame->page()->mainFrame()) + if (m_frame == m_frame->page()->mainWebFrame()) m_frame->page()->drawingArea()->setNeedsDisplay(m_frame->page()->bounds()); } @@ -1055,7 +1055,7 @@ void WebFrameLoaderClient::provisionalLoadStarted() if (!webPage) return; - if (m_frame == m_frame->page()->mainFrame()) + if (m_frame == m_frame->page()->mainWebFrame()) webPage->drawingArea()->setLayerTreeStateIsFrozen(true); } @@ -1103,7 +1103,7 @@ void WebFrameLoaderClient::savePlatformDataToCachedFrame(CachedFrame*) void WebFrameLoaderClient::transitionToCommittedFromCachedFrame(CachedFrame*) { WebPage* webPage = m_frame->page(); - bool isMainFrame = webPage->mainFrame() == m_frame; + bool isMainFrame = webPage->mainWebFrame() == m_frame; const ResourceResponse& response = m_frame->coreFrame()->loader()->documentLoader()->response(); m_frameHasCustomRepresentation = isMainFrame && WebProcess::shared().shouldUseCustomRepresentationForResponse(response); @@ -1114,7 +1114,7 @@ void WebFrameLoaderClient::transitionToCommittedForNewPage() WebPage* webPage = m_frame->page(); Color backgroundColor = webPage->drawsTransparentBackground() ? Color::transparent : Color::white; - bool isMainFrame = webPage->mainFrame() == m_frame; + bool isMainFrame = webPage->mainWebFrame() == m_frame; #if ENABLE(TILED_BACKING_STORE) IntSize currentVisibleContentSize = m_frame->coreFrame()->view() ? m_frame->coreFrame()->view()->visibleContentRect().size() : IntSize(); @@ -1232,7 +1232,7 @@ PassRefPtr WebFrameLoaderClient::createPlugin(const IntSize&, HTMLPlugIn parameters.loadManually = loadManually; parameters.documentURL = m_frame->coreFrame()->document()->url().string(); - Frame* mainFrame = webPage->mainFrame()->coreFrame(); + Frame* mainFrame = webPage->mainWebFrame()->coreFrame(); if (m_frame->coreFrame() == mainFrame) parameters.toplevelDocumentURL = parameters.documentURL; else if (m_frame->coreFrame()->document()->securityOrigin()->canAccess(mainFrame->document()->securityOrigin())) { diff --git a/Source/WebKit2/WebProcess/WebCoreSupport/mac/WebEditorClientMac.mm b/Source/WebKit2/WebProcess/WebCoreSupport/mac/WebEditorClientMac.mm index 0598100..9a27be8 100644 --- a/Source/WebKit2/WebProcess/WebCoreSupport/mac/WebEditorClientMac.mm +++ b/Source/WebKit2/WebProcess/WebCoreSupport/mac/WebEditorClientMac.mm @@ -114,8 +114,9 @@ DocumentFragment* WebEditorClient::documentFragmentFromAttributedString(NSAttrib NSExcludedElementsDocumentAttribute, nil, @"WebResourceHandler", nil]; NSArray *subResources; + Document* document = m_page->mainFrame() ? m_page->mainFrame()->document() : 0; DOMDocumentFragment* fragment = [string _documentFromRange:NSMakeRange(0, [string length]) - document:kit(m_page->mainFrame()->coreFrame()->document()) + document:kit(document) documentAttributes:dictionary subresources:&subResources]; for (WebResource* resource in subResources) diff --git a/Source/WebKit2/WebProcess/WebPage/WebFrame.cpp b/Source/WebKit2/WebProcess/WebPage/WebFrame.cpp index 45feab1..ae53755 100644 --- a/Source/WebKit2/WebProcess/WebPage/WebFrame.cpp +++ b/Source/WebKit2/WebProcess/WebPage/WebFrame.cpp @@ -323,7 +323,7 @@ bool WebFrame::isFrameSet() const bool WebFrame::isMainFrame() const { if (WebPage* p = page()) - return p->mainFrame() == this; + return p->mainWebFrame() == this; return false; } diff --git a/Source/WebKit2/WebProcess/WebPage/WebPage.cpp b/Source/WebKit2/WebProcess/WebPage/WebPage.cpp index 944d4de..4f19d6f 100644 --- a/Source/WebKit2/WebProcess/WebPage/WebPage.cpp +++ b/Source/WebKit2/WebProcess/WebPage/WebPage.cpp @@ -57,6 +57,7 @@ #include "WebFrame.h" #include "WebFullScreenManager.h" #include "WebGeolocationClient.h" +#include "WebGeometry.h" #include "WebImage.h" #include "WebInspector.h" #include "WebInspectorClient.h" @@ -375,6 +376,46 @@ uint64_t WebPage::renderTreeSize() const return size; } +void WebPage::setTracksRepaints(bool trackRepaints) +{ + if (FrameView* view = mainFrameView()) + view->setTracksRepaints(trackRepaints); +} + +bool WebPage::isTrackingRepaints() const +{ + if (FrameView* view = mainFrameView()) + return view->isTrackingRepaints(); + + return false; +} + +void WebPage::resetTrackedRepaints() +{ + if (FrameView* view = mainFrameView()) + view->resetTrackedRepaints(); +} + +PassRefPtr WebPage::trackedRepaintRects() +{ + FrameView* view = mainFrameView(); + if (!view) + return ImmutableArray::create(); + + const Vector& rects = view->trackedRepaintRects(); + size_t size = rects.size(); + if (!size) + return ImmutableArray::create(); + + Vector > vector; + vector.reserveInitialCapacity(size); + + for (size_t i = 0; i < size; ++i) + vector.uncheckedAppend(WebRect::create(toAPI(rects[i]))); + + return ImmutableArray::adopt(vector); +} + void WebPage::executeEditingCommand(const String& commandName, const String& argument) { Frame* frame = m_page->focusController()->focusedOrMainFrame(); @@ -395,7 +436,8 @@ bool WebPage::isEditingCommandEnabled(const String& commandName) void WebPage::clearMainFrameName() { - mainFrame()->coreFrame()->tree()->clearName(); + if (Frame* frame = mainFrame()) + frame->tree()->clearName(); } #if USE(ACCELERATED_COMPOSITING) @@ -607,7 +649,7 @@ void WebPage::layoutIfNeeded() m_mainFrame->coreFrame()->view()->updateLayoutAndStyleIfNeededRecursive(); if (m_underlayPage) { - if (FrameView *frameView = m_underlayPage->mainFrame()->coreFrame()->view()) + if (FrameView *frameView = m_underlayPage->mainFrameView()) frameView->updateLayoutAndStyleIfNeededRecursive(); } } @@ -1992,7 +2034,10 @@ void WebPage::clearSelection() bool WebPage::mainFrameHasCustomRepresentation() const { - return static_cast(mainFrame()->coreFrame()->loader()->client())->frameHasCustomRepresentation(); + if (Frame* frame = mainFrame()) + return static_cast(frame->loader()->client())->frameHasCustomRepresentation(); + + return false; } void WebPage::didChangeScrollOffsetForMainFrame() @@ -2461,4 +2506,17 @@ void WebPage::simulateMouseMotion(WebCore::IntPoint position, double time) mouseEvent(WebMouseEvent(WebMouseEvent::MouseMove, WebMouseEvent::NoButton, position, position, 0, 0, 0, 0, WebMouseEvent::Modifiers(), time)); } +Frame* WebPage::mainFrame() const +{ + return m_page ? m_page->mainFrame() : 0; +} + +FrameView* WebPage::mainFrameView() const +{ + if (Frame* frame = mainFrame()) + return frame->view(); + + return 0; +} + } // namespace WebKit diff --git a/Source/WebKit2/WebProcess/WebPage/WebPage.h b/Source/WebKit2/WebProcess/WebPage/WebPage.h index cbb88fe..d50cde3 100644 --- a/Source/WebKit2/WebProcess/WebPage/WebPage.h +++ b/Source/WebKit2/WebProcess/WebPage/WebPage.h @@ -31,6 +31,7 @@ #include "FindController.h" #include "GeolocationPermissionRequestManager.h" #include "ImageOptions.h" +#include "ImmutableArray.h" #include "InjectedBundlePageContextMenuClient.h" #include "InjectedBundlePageEditorClient.h" #include "InjectedBundlePageFormClient.h" @@ -80,6 +81,8 @@ namespace CoreIPC { namespace WebCore { class GraphicsContext; + class Frame; + class FrameView; class KeyboardEvent; class Page; class PrintContext; @@ -222,7 +225,11 @@ public: bool findStringFromInjectedBundle(const String&, FindOptions); - WebFrame* mainFrame() const { return m_mainFrame.get(); } + WebFrame* mainWebFrame() const { return m_mainFrame.get(); } + + WebCore::Frame* mainFrame() const; // May return 0. + WebCore::FrameView* mainFrameView() const; // May return 0. + PassRefPtr createPlugin(const Plugin::Parameters&); EditorState editorState() const; @@ -230,6 +237,11 @@ public: String renderTreeExternalRepresentation() const; uint64_t renderTreeSize() const; + void setTracksRepaints(bool); + bool isTrackingRepaints() const; + void resetTrackedRepaints(); + PassRefPtr trackedRepaintRects(); + void executeEditingCommand(const String& commandName, const String& argument); bool isEditingCommandEnabled(const String& commandName); void clearMainFrameName(); diff --git a/Source/WebKit2/WebProcess/WebPage/mac/WKAccessibilityWebPageObject.mm b/Source/WebKit2/WebProcess/WebPage/mac/WKAccessibilityWebPageObject.mm index 7cf5b4b..c553a55 100644 --- a/Source/WebKit2/WebProcess/WebPage/mac/WKAccessibilityWebPageObject.mm +++ b/Source/WebKit2/WebProcess/WebPage/mac/WKAccessibilityWebPageObject.mm @@ -176,12 +176,10 @@ using namespace WebKit; point.y -= remotePosition.y; point.x -= remotePosition.x; - if (m_page && m_page->mainFrame() && m_page->mainFrame()->coreFrame()) { - WebCore::FrameView* fv = m_page->mainFrame()->coreFrame()->view(); - if (fv) { - point.y += fv->scrollPosition().y(); - point.x += fv->scrollPosition().x(); - } + WebCore::FrameView* frameView = m_page ? m_page->mainFrameView() : 0; + if (frameView) { + point.y += frameView->scrollPosition().y(); + point.x += frameView->scrollPosition().x(); } return [[self accessibilityRootObjectWrapper] accessibilityHitTest:point]; -- 2.7.4