Source/WebCore: WebCore part of <rdar://problem/10262242> Add API for paginated display
authormitz@apple.com <mitz@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 17 Nov 2011 01:19:46 +0000 (01:19 +0000)
committermitz@apple.com <mitz@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 17 Nov 2011 01:19:46 +0000 (01:19 +0000)
https://bugs.webkit.org/show_bug.cgi?id=72537

Reviewed by Anders Carlsson.

* WebCore.exp.in: Exported Page::pageCount().
* page/Page.cpp:
(WebCore::Page::pageCount): Added this getter.
* page/Page.h:

Source/WebKit/mac: WebKit/mac part of <rdar://problem/10262242> Add API for paginated display
https://bugs.webkit.org/show_bug.cgi?id=72537

Reviewed by Anders Carlsson.

* WebView/WebView.mm:
(-[WebView _setPaginationMode:]): Added this accessor.
(-[WebView _paginationMode]): Ditto.
(-[WebView _setGapBetweenPages:]): Ditto.
(-[WebView _gapBetweenPages]): Ditto.
(-[WebView _pageCount]): Ditto.
* WebView/WebViewPrivate.h: Defined WebPaginationMode enum and values.

Source/WebKit2: WebKit2 part of <rdar://problem/10262242> Add API for paginated display
https://bugs.webkit.org/show_bug.cgi?id=72537

Reviewed by Anders Carlsson.

* Shared/WebPageCreationParameters.cpp:
(WebKit::WebPageCreationParameters::encode): Encode the pagination mode and gap between pages.
(WebKit::WebPageCreationParameters::decode): Decode the pagination mode and gap between pages.
* Shared/WebPageCreationParameters.h: Added paginationMode and gapBetweenPages members.
* UIProcess/API/C/WKPage.cpp:
(WKPageSetPaginationMode): Added this API wrapper.
(WKPageGetPaginationMode): Ditto.
(WKPageSetGapBetweenPages): Ditto.
(WKPageGetGapBetweenPages): Ditto.
(WKPageGetPageCount): Ditto.
* UIProcess/API/C/WKPagePrivate.h: Added an enum and a definition of WKPaginationMode and
accessors.
* UIProcess/API/mac/WKBrowsingContextController.mm:
(-[WKBrowsingContextController setPaginationMode:]): Added this API wrapper.
(-[WKBrowsingContextController paginationMode]): Ditto.
(-[WKBrowsingContextController setGapBetweenPages:]): Ditto.
(-[WKBrowsingContextController gapBetweenPages]): Ditto.
(-[WKBrowsingContextController pageCount]): Ditto.
* UIProcess/API/mac/WKBrowsingContextControllerPrivate.h: Added. Includes an enum and a definition
of WKBrowsingContextPaginationMode and property declarations.
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::WebPageProxy): Added intialization of m_paginationMode, m_gapBetweenPages,
and m_pageCount.
(WebKit::WebPageProxy::setPaginationMode): Added this accessor, which caches the value and sends
a message to the WebPage.
(WebKit::WebPageProxy::setGapBetweenPages): Ditto.
(WebKit::WebPageProxy::creationParameters): Set the pagination mode and gap between pages in the
creation parameters.
(WebKit::WebPageProxy::didChangePageCount): Added. Updates the cached page count.
* UIProcess/WebPageProxy.h:
(WebKit::WebPageProxy::paginationMode): Added this getter that returns a cached value.
(WebKit::WebPageProxy::gapBetweenPages): Ditto.
(WebKit::WebPageProxy::pageCount): Ditto.
* UIProcess/WebPageProxy.messages.in: Added DidChangedPageCount, sent when the page count changes
after layout.
* WebKit2.xcodeproj/project.pbxproj: Added WKBrowsingContextControllerPrivate.h.
* WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp:
(WebKit::WebFrameLoaderClient::dispatchDidLayout): Added a call to WebPage::mainFrameDidLayout(),
allowing the page to respond to changes in the column count.
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::WebPage): Added initializer for m_cachedPageCount.
(WebKit::WebPage::setPaginationMode): Added.
(WebKit::WebPage::setGapBetweenPages): Added.
(WebKit::WebPage::mainFrameDidLayout): Added. Sends a DidChangePageCount message to the UI process
if the page count has changed.
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/WebPage.messages.in: Added SetPaginationMode and SetGapBetweenPages messages.

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

22 files changed:
Source/WebCore/ChangeLog
Source/WebCore/WebCore.exp.in
Source/WebCore/page/Page.cpp
Source/WebCore/page/Page.h
Source/WebKit/mac/ChangeLog
Source/WebKit/mac/WebView/WebView.mm
Source/WebKit/mac/WebView/WebViewPrivate.h
Source/WebKit2/ChangeLog
Source/WebKit2/Shared/WebPageCreationParameters.cpp
Source/WebKit2/Shared/WebPageCreationParameters.h
Source/WebKit2/UIProcess/API/C/WKPage.cpp
Source/WebKit2/UIProcess/API/C/WKPagePrivate.h
Source/WebKit2/UIProcess/API/mac/WKBrowsingContextController.mm
Source/WebKit2/UIProcess/API/mac/WKBrowsingContextControllerPrivate.h [new file with mode: 0644]
Source/WebKit2/UIProcess/WebPageProxy.cpp
Source/WebKit2/UIProcess/WebPageProxy.h
Source/WebKit2/UIProcess/WebPageProxy.messages.in
Source/WebKit2/WebKit2.xcodeproj/project.pbxproj
Source/WebKit2/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp
Source/WebKit2/WebProcess/WebPage/WebPage.cpp
Source/WebKit2/WebProcess/WebPage/WebPage.h
Source/WebKit2/WebProcess/WebPage/WebPage.messages.in

index 55973c1f73055c1ac8311659e9386ea8bd764399..a0fb0b870cc236465bba433aa7115bda8785f76f 100644 (file)
@@ -1,3 +1,15 @@
+2011-11-16  Dan Bernstein  <mitz@apple.com>
+
+        WebCore part of <rdar://problem/10262242> Add API for paginated display
+        https://bugs.webkit.org/show_bug.cgi?id=72537
+
+        Reviewed by Anders Carlsson.
+
+        * WebCore.exp.in: Exported Page::pageCount().
+        * page/Page.cpp:
+        (WebCore::Page::pageCount): Added this getter.
+        * page/Page.h:
+
 2011-11-16  Shawn Singh  <shawnsingh@chromium.org>
 
         [chromium] Track property changes for render surfaces.
index acccfd2d71f6d43c93021628d4c9500d2948f4cf..19398b1c7068a6863f666f2d8631f60e40d56303 100644 (file)
@@ -1330,6 +1330,7 @@ __ZNK7WebCore4Page10pluginDataEv
 __ZNK7WebCore4Page15backForwardListEv
 __ZNK7WebCore4Page34inLowQualityImageInterpolationModeEv
 __ZNK7WebCore4Page9groupNameEv
+__ZNK7WebCore4Page9pageCountEv
 __ZNK7WebCore5Color7getRGBAERdS1_S1_S1_
 __ZNK7WebCore5Frame13ownerRendererEv
 __ZNK7WebCore5Frame14selectionImageEb
index ce73eb0bcb8e268c36a8d2a6dff1f669a0cb1a53..09d7e0568fbb11234d370937217b185a0286d3d1 100644 (file)
@@ -59,6 +59,7 @@
 #include "PluginViewBase.h"
 #include "ProgressTracker.h"
 #include "RenderTheme.h"
+#include "RenderView.h"
 #include "RenderWidget.h"
 #include "RuntimeEnabledFeatures.h"
 #include "SchemeRegistry.h"
@@ -677,6 +678,21 @@ void Page::setPagination(const Pagination& pagination)
     backForward()->markPagesForFullStyleRecalc();
 }
 
+unsigned Page::pageCount() const
+{
+    if (m_pagination.mode == Pagination::Unpaginated)
+        return 0;
+
+    FrameView* frameView = mainFrame()->view();
+    if (!frameView->didFirstLayout())
+        return 0;
+
+    mainFrame()->view()->forceLayout();
+
+    RenderView* contentRenderer = mainFrame()->contentRenderer();
+    return contentRenderer->columnCount(contentRenderer->columnInfo());
+}
+
 void Page::didMoveOnscreen()
 {
     for (Frame* frame = mainFrame(); frame; frame = frame->tree()->traverseNext()) {
index 4a7448dc1ec0736d0fcbeb5a29a20dcba63a52a7..f9f8d72595946614f02bfbe2f4895438486ce821 100644 (file)
@@ -267,6 +267,8 @@ namespace WebCore {
         const Pagination& pagination() const { return m_pagination; }
         void setPagination(const Pagination&);
 
+        unsigned pageCount() const;
+
         // Notifications when the Page starts and stops being presented via a native window.
         void didMoveOnscreen();
         void willMoveOffscreen();
index 19790372ec4f8b78b6aa1a18735581161718aa5c..506006a8fc4d46a717ceab3a05e36ef9b58b0904 100644 (file)
@@ -1,3 +1,18 @@
+2011-11-16  Dan Bernstein  <mitz@apple.com>
+
+        WebKit/mac part of <rdar://problem/10262242> Add API for paginated display
+        https://bugs.webkit.org/show_bug.cgi?id=72537
+
+        Reviewed by Anders Carlsson.
+
+        * WebView/WebView.mm:
+        (-[WebView _setPaginationMode:]): Added this accessor.
+        (-[WebView _paginationMode]): Ditto.
+        (-[WebView _setGapBetweenPages:]): Ditto.
+        (-[WebView _gapBetweenPages]): Ditto.
+        (-[WebView _pageCount]): Ditto.
+        * WebView/WebViewPrivate.h: Defined WebPaginationMode enum and values.
+
 2011-11-15  Andy Estes  <aestes@apple.com>
 
         Consolidate the logic that creates run loop observers for flushing layer tree changes to CoreAnimation
index 7fc0a8d08a4760517c37f20c88b27a6bcb0bbe65..94ae4f00992c2a5e0049c7182fb95df3bca50dde 100644 (file)
@@ -2717,6 +2717,78 @@ static PassOwnPtr<Vector<String> > toStringVector(NSArray* patterns)
     return view->fixedLayoutSize();
 }
 
+- (void)_setPaginationMode:(WebPaginationMode)paginationMode
+{
+    Page* page = core(self);
+    if (!page)
+        return;
+
+    Page::Pagination pagination = page->pagination();
+    switch (paginationMode) {
+    case WebPaginationModeUnpaginated:
+        pagination.mode = Page::Pagination::Unpaginated;
+        break;
+    case WebPaginationModeHorizontal:
+        pagination.mode = Page::Pagination::HorizontallyPaginated;
+        break;
+    case WebPaginationModeVertical:
+        pagination.mode = Page::Pagination::VerticallyPaginated;
+        break;
+    default:
+        return;
+    }
+
+    page->setPagination(pagination);
+}
+
+- (WebPaginationMode)_paginationMode
+{
+    Page* page = core(self);
+    if (!page)
+        return WebPaginationModeUnpaginated;
+
+    switch (page->pagination().mode) {
+    case Page::Pagination::Unpaginated:
+        return WebPaginationModeUnpaginated;
+    case Page::Pagination::HorizontallyPaginated:
+        return WebPaginationModeHorizontal;
+    case Page::Pagination::VerticallyPaginated:
+        return WebPaginationModeVertical;
+    }
+
+    ASSERT_NOT_REACHED();
+    return WebPaginationModeUnpaginated;
+}
+
+- (void)_setGapBetweenPages:(CGFloat)pageGap
+{
+    Page* page = core(self);
+    if (!page)
+        return;
+
+    Page::Pagination pagination = page->pagination();
+    pagination.gap = pageGap;
+    page->setPagination(pagination);
+}
+
+- (CGFloat)_gapBetweenPages
+{
+    Page* page = core(self);
+    if (!page)
+        return 0;
+
+    return page->pagination().gap;
+}
+
+- (NSUInteger)_pageCount
+{
+    Page* page = core(self);
+    if (!page)
+        return 0;
+
+    return page->pageCount();
+}
+
 - (CGFloat)_backingScaleFactor
 {
     return [self _deviceScaleFactor];
index fa7051f475060185ed8220c575726e45ae87b811..6aaab9dea359aa1cd836e27e2f628de399e8c557 100644 (file)
@@ -98,6 +98,12 @@ enum {
 };
 typedef NSUInteger WebFindOptions;
 
+typedef enum {
+    WebPaginationModeUnpaginated,
+    WebPaginationModeHorizontal,
+    WebPaginationModeVertical,
+} WebPaginationMode;
+
 @interface WebController : NSTreeController {
     IBOutlet WebView *webView;
 }
@@ -555,6 +561,12 @@ Could be worth adding to the API.
 - (BOOL)_useFixedLayout;
 - (NSSize)_fixedLayoutSize;
 
+- (void)_setPaginationMode:(WebPaginationMode)paginationMode;
+- (WebPaginationMode)_paginationMode;
+- (void)_setGapBetweenPages:(CGFloat)pageGap;
+- (CGFloat)_gapBetweenPages;
+- (NSUInteger)_pageCount;
+
 - (void)_setCustomBackingScaleFactor:(CGFloat)overrideScaleFactor;
 - (CGFloat)_backingScaleFactor;
 
index 98515b81e3e18ceec06d609b658dd7e93aa61a7d..56bd2d5fd1b35d234224081589c3d2fc8a060e66 100644 (file)
@@ -1,3 +1,58 @@
+2011-11-16  Dan Bernstein  <mitz@apple.com>
+
+        WebKit2 part of <rdar://problem/10262242> Add API for paginated display
+        https://bugs.webkit.org/show_bug.cgi?id=72537
+
+        Reviewed by Anders Carlsson.
+
+        * Shared/WebPageCreationParameters.cpp:
+        (WebKit::WebPageCreationParameters::encode): Encode the pagination mode and gap between pages.
+        (WebKit::WebPageCreationParameters::decode): Decode the pagination mode and gap between pages.
+        * Shared/WebPageCreationParameters.h: Added paginationMode and gapBetweenPages members.
+        * UIProcess/API/C/WKPage.cpp:
+        (WKPageSetPaginationMode): Added this API wrapper.
+        (WKPageGetPaginationMode): Ditto.
+        (WKPageSetGapBetweenPages): Ditto.
+        (WKPageGetGapBetweenPages): Ditto.
+        (WKPageGetPageCount): Ditto.
+        * UIProcess/API/C/WKPagePrivate.h: Added an enum and a definition of WKPaginationMode and
+        accessors.
+        * UIProcess/API/mac/WKBrowsingContextController.mm:
+        (-[WKBrowsingContextController setPaginationMode:]): Added this API wrapper.
+        (-[WKBrowsingContextController paginationMode]): Ditto.
+        (-[WKBrowsingContextController setGapBetweenPages:]): Ditto.
+        (-[WKBrowsingContextController gapBetweenPages]): Ditto.
+        (-[WKBrowsingContextController pageCount]): Ditto.
+        * UIProcess/API/mac/WKBrowsingContextControllerPrivate.h: Added. Includes an enum and a definition
+        of WKBrowsingContextPaginationMode and property declarations.
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::WebPageProxy): Added intialization of m_paginationMode, m_gapBetweenPages,
+        and m_pageCount.
+        (WebKit::WebPageProxy::setPaginationMode): Added this accessor, which caches the value and sends
+        a message to the WebPage.
+        (WebKit::WebPageProxy::setGapBetweenPages): Ditto.
+        (WebKit::WebPageProxy::creationParameters): Set the pagination mode and gap between pages in the
+        creation parameters.
+        (WebKit::WebPageProxy::didChangePageCount): Added. Updates the cached page count.
+        * UIProcess/WebPageProxy.h:
+        (WebKit::WebPageProxy::paginationMode): Added this getter that returns a cached value.
+        (WebKit::WebPageProxy::gapBetweenPages): Ditto.
+        (WebKit::WebPageProxy::pageCount): Ditto.
+        * UIProcess/WebPageProxy.messages.in: Added DidChangedPageCount, sent when the page count changes
+        after layout.
+        * WebKit2.xcodeproj/project.pbxproj: Added WKBrowsingContextControllerPrivate.h.
+        * WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp: 
+        (WebKit::WebFrameLoaderClient::dispatchDidLayout): Added a call to WebPage::mainFrameDidLayout(),
+        allowing the page to respond to changes in the column count.
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::WebPage): Added initializer for m_cachedPageCount.
+        (WebKit::WebPage::setPaginationMode): Added.
+        (WebKit::WebPage::setGapBetweenPages): Added.
+        (WebKit::WebPage::mainFrameDidLayout): Added. Sends a DidChangePageCount message to the UI process
+        if the page count has changed.
+        * WebProcess/WebPage/WebPage.h:
+        * WebProcess/WebPage/WebPage.messages.in: Added SetPaginationMode and SetGapBetweenPages messages.
+
 2011-11-16  Chris Fleizach  <cfleizach@apple.com>
 
         WebKitTestRunner needs to support accessibility-related DRT APIs
index 574b205e6127a8f9739e3b707f541a3504676851..fdce1ef7e6f5a61f54e049c7a2bb84dd4360cc70 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C)  2010 Apple Inc. All rights reserved.
+ * Copyright (C) 2010, 2011 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -46,6 +46,8 @@ void WebPageCreationParameters::encode(CoreIPC::ArgumentEncoder* encoder) const
     encoder->encode(areMemoryCacheClientCallsEnabled);
     encoder->encode(useFixedLayout);
     encoder->encode(fixedLayoutSize);
+    encoder->encodeEnum(paginationMode);
+    encoder->encode(gapBetweenPages);
     encoder->encode(userAgent);
     encoder->encode(sessionState);
     encoder->encode(highestUsedBackForwardItemID);
@@ -90,6 +92,10 @@ bool WebPageCreationParameters::decode(CoreIPC::ArgumentDecoder* decoder, WebPag
         return false;
     if (!decoder->decode(parameters.fixedLayoutSize))
         return false;
+    if (!decoder->decodeEnum(parameters.paginationMode))
+        return false;
+    if (!decoder->decode(parameters.gapBetweenPages))
+        return false;
     if (!decoder->decode(parameters.userAgent))
         return false;
     if (!decoder->decode(parameters.sessionState))
index b5559b235f3c223ebe4ae037ae7c6d47be5742de..613357b5e98106617dc03da7a73262bc6604e151 100644 (file)
@@ -63,6 +63,9 @@ struct WebPageCreationParameters {
     bool useFixedLayout;
     WebCore::IntSize fixedLayoutSize;
 
+    WebCore::Page::Pagination::Mode paginationMode;
+    double gapBetweenPages;
+
     String userAgent;
 
     SessionState sessionState;
index d329ca42b38e92bb15458fa04e4ab3e704c7fd18..ede4ea629098de093ab1ad686036f75158485403 100644 (file)
 #include "WebData.h"
 #include "WebPageProxy.h"
 #include "WebProcessProxy.h"
+#include <WebCore/Page.h>
 
 #ifdef __BLOCKS__
 #include <Block.h>
 #endif
 
+using namespace WebCore;
 using namespace WebKit;
 
 WKTypeID WKPageGetTypeID()
@@ -343,6 +345,55 @@ bool WKPageIsPinnedToRightSide(WKPageRef pageRef)
     return toImpl(pageRef)->isPinnedToRightSide();
 }
 
+void WKPageSetPaginationMode(WKPageRef pageRef, WKPaginationMode paginationMode)
+{
+    Page::Pagination::Mode mode;
+    switch (paginationMode) {
+    case kWKPaginationModeUnpaginated:
+        mode = Page::Pagination::Unpaginated;
+        break;
+    case kWKPaginationModeHorizontal:
+        mode = Page::Pagination::HorizontallyPaginated;
+        break;
+    case kWKPaginationModeVertical:
+        mode = Page::Pagination::VerticallyPaginated;
+        break;
+    default:
+        return;
+    }
+    toImpl(pageRef)->setPaginationMode(mode);
+}
+
+WKPaginationMode WKPageGetPaginationMode(WKPageRef pageRef)
+{
+    switch (toImpl(pageRef)->paginationMode()) {
+    case Page::Pagination::Unpaginated:
+        return kWKPaginationModeUnpaginated;
+    case Page::Pagination::HorizontallyPaginated:
+        return kWKPaginationModeHorizontal;
+    case Page::Pagination::VerticallyPaginated:
+        return kWKPaginationModeVertical;
+    }
+
+    ASSERT_NOT_REACHED();
+    return kWKPaginationModeUnpaginated;
+}
+
+void WKPageSetGapBetweenPages(WKPageRef pageRef, double gap)
+{
+    toImpl(pageRef)->setGapBetweenPages(gap);
+}
+
+double WKPageGetGapBetweenPages(WKPageRef pageRef)
+{
+    return toImpl(pageRef)->gapBetweenPages();
+}
+
+unsigned WKPageGetPageCount(WKPageRef pageRef)
+{
+    return toImpl(pageRef)->pageCount();
+}
+
 bool WKPageCanDelete(WKPageRef pageRef)
 {
     return toImpl(pageRef)->canDelete();
index 67a30405463b2766eeb5b5fdbdbb8caff6280d46..a1cea0bc52ee782858f3d5920f6021f0727be7f2 100644 (file)
@@ -52,6 +52,20 @@ WK_EXPORT WKPageDebugPaintFlags WKPageGetDebugPaintFlags(void);
 
 WK_EXPORT WKStringRef WKPageCopyStandardUserAgentWithApplicationName(WKStringRef);
 
+enum {
+    kWKPaginationModeUnpaginated,
+    kWKPaginationModeHorizontal,
+    kWKPaginationModeVertical,
+};
+typedef uint32_t WKPaginationMode;
+
+WK_EXPORT void WKPageSetPaginationMode(WKPageRef page, WKPaginationMode paginationMode);
+WK_EXPORT WKPaginationMode WKPageGetPaginationMode(WKPageRef page);
+WK_EXPORT void WKPageSetGapBetweenPages(WKPageRef page, double gap);
+WK_EXPORT double WKPageGetGapBetweenPages(WKPageRef page);
+
+WK_EXPORT unsigned WKPageGetPageCount(WKPageRef page);
+
 struct WKPrintInfo {
     float pageSetupScaleFactor;
     float availablePaperWidth;
index e2306a0baa7ab77e84998c71d8f89188dff459bb..8bb1ab7631fc3484677cb05cb5c21d6d94b21297 100644 (file)
 
 #import "config.h"
 #import "WKBrowsingContextController.h"
+#import "WKBrowsingContextControllerPrivate.h"
 #import "WKBrowsingContextControllerInternal.h"
 
 #import "WKErrorCF.h"
 #import "WKFrame.h"
-#import "WKPage.h"
+#import "WKPagePrivate.h"
 #import "WKRetainPtr.h"
 #import "WKStringCF.h"
 #import "WKURLCF.h"
@@ -196,6 +197,59 @@ static inline NSURL *autoreleased(WKURLRef url)
 
 @end
 
+@implementation WKBrowsingContextController (Private)
+
+- (void)setPaginationMode:(WKBrowsingContextPaginationMode)paginationMode
+{
+    WKPaginationMode mode;
+    switch (paginationMode) {
+    case WKPaginationModeUnpaginated:
+        mode = kWKPaginationModeUnpaginated;
+        break;
+    case WKPaginationModeHorizontal:
+        mode = kWKPaginationModeHorizontal;
+        break;
+    case WKPaginationModeVertical:
+        mode = kWKPaginationModeVertical;
+        break;
+    default:
+        return;
+    }
+
+    WKPageSetPaginationMode(self.pageRef, mode);
+}
+
+- (WKBrowsingContextPaginationMode)paginationMode
+{
+    switch (WKPageGetPaginationMode(self.pageRef)) {
+    case kWKPaginationModeUnpaginated:
+        return WKPaginationModeUnpaginated;
+    case kWKPaginationModeHorizontal:
+        return WKPaginationModeHorizontal;
+    case kWKPaginationModeVertical:
+        return WKPaginationModeVertical;
+    }
+
+    ASSERT_NOT_REACHED();
+    return WKPaginationModeUnpaginated;
+}
+
+- (void)setGapBetweenPages:(CGFloat)gapBetweenPages
+{
+    WKPageSetGapBetweenPages(self.pageRef, gapBetweenPages);
+}
+
+- (CGFloat)gapBetweenPages
+{
+    return WKPageGetGapBetweenPages(self.pageRef);
+}
+
+- (NSUInteger)pageCount
+{
+    return WKPageGetPageCount(self.pageRef);
+}
+
+@end
 
 @implementation WKBrowsingContextController (Internal)
 
diff --git a/Source/WebKit2/UIProcess/API/mac/WKBrowsingContextControllerPrivate.h b/Source/WebKit2/UIProcess/API/mac/WKBrowsingContextControllerPrivate.h
new file mode 100644 (file)
index 0000000..c597ffe
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2011 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.
+ */
+
+#import <WebKit2/WKBrowsingContextController.h>
+
+enum {
+    WKPaginationModeUnpaginated,
+    WKPaginationModeHorizontal,
+    WKPaginationModeVertical,
+};
+typedef NSUInteger WKBrowsingContextPaginationMode;
+
+@interface WKBrowsingContextController (Private)
+
+@property WKBrowsingContextPaginationMode paginationMode;
+@property CGFloat gapBetweenPages;
+
+@property(readonly) NSUInteger pageCount;
+
+@end
index b3c048cc954618fb79e99525e7294ff92abdd98f..3fdc1fa29b8be025d815056879d6693cb1f77d84 100644 (file)
@@ -159,6 +159,8 @@ WebPageProxy::WebPageProxy(PageClient* pageClient, PassRefPtr<WebProcessProxy> p
     , m_drawsTransparentBackground(false)
     , m_areMemoryCacheClientCallsEnabled(true)
     , m_useFixedLayout(false)
+    , m_paginationMode(Page::Pagination::Unpaginated)
+    , m_gapBetweenPages(0)
     , m_isValid(true)
     , m_isClosed(false)
     , m_isInPrintingMode(false)
@@ -187,6 +189,7 @@ WebPageProxy::WebPageProxy(PageClient* pageClient, PassRefPtr<WebProcessProxy> p
     , m_mainFrameHasVerticalScrollbar(false)
     , m_mainFrameIsPinnedToLeftSide(false)
     , m_mainFrameIsPinnedToRightSide(false)
+    , m_pageCount(0)
     , m_renderTreeSize(0)
     , m_shouldSendEventsSynchronously(false)
 {
@@ -1278,6 +1281,30 @@ void WebPageProxy::setFixedLayoutSize(const IntSize& size)
     process()->send(Messages::WebPage::SetFixedLayoutSize(size), m_pageID);
 }
 
+void WebPageProxy::setPaginationMode(WebCore::Page::Pagination::Mode mode)
+{
+    if (mode == m_paginationMode)
+        return;
+
+    m_paginationMode = mode;
+
+    if (!isValid())
+        return;
+    process()->send(Messages::WebPage::SetPaginationMode(mode), m_pageID);
+}
+
+void WebPageProxy::setGapBetweenPages(double gap)
+{
+    if (gap == m_gapBetweenPages)
+        return;
+
+    m_gapBetweenPages = gap;
+
+    if (!isValid())
+        return;
+    process()->send(Messages::WebPage::SetGapBetweenPages(gap), m_pageID);
+}
+
 void WebPageProxy::pageScaleFactorDidChange(double scaleFactor)
 {
     m_pageScaleFactor = scaleFactor;
@@ -3155,6 +3182,8 @@ WebPageCreationParameters WebPageProxy::creationParameters() const
     parameters.areMemoryCacheClientCallsEnabled = m_areMemoryCacheClientCallsEnabled;
     parameters.useFixedLayout = m_useFixedLayout;
     parameters.fixedLayoutSize = m_fixedLayoutSize;
+    parameters.paginationMode = m_paginationMode;
+    parameters.gapBetweenPages = m_gapBetweenPages;
     parameters.userAgent = userAgent();
     parameters.sessionState = SessionState(m_backForwardList->entries(), m_backForwardList->currentIndex());
     parameters.highestUsedBackForwardItemID = WebBackForwardListItem::highedUsedItemID();
@@ -3279,6 +3308,11 @@ void WebPageProxy::didChangeScrollOffsetPinningForMainFrame(bool pinnedToLeftSid
     m_mainFrameIsPinnedToRightSide = pinnedToRightSide;
 }
 
+void WebPageProxy::didChangePageCount(unsigned pageCount)
+{
+    m_pageCount = pageCount;
+}
+
 void WebPageProxy::didFailToInitializePlugin(const String& mimeType)
 {
     m_loaderClient.didFailToInitializePlugin(this, mimeType);
index 6787ed19b1eeaa4780fda84cf80a1899e75956dc..2fdd93d10ff039f915af80f92a3424e329164009 100644 (file)
@@ -56,6 +56,7 @@
 #include <WebCore/DragActions.h>
 #include <WebCore/DragSession.h>
 #include <WebCore/HitTestResult.h>
+#include <WebCore/Page.h>
 #include <WebCore/PlatformScreen.h>
 #include <WebCore/ScrollTypes.h>
 #include <WebCore/TextChecking.h>
@@ -412,6 +413,12 @@ public:
     bool isPinnedToLeftSide() const { return m_mainFrameIsPinnedToLeftSide; }
     bool isPinnedToRightSide() const { return m_mainFrameIsPinnedToRightSide; }
 
+    void setPaginationMode(WebCore::Page::Pagination::Mode);
+    WebCore::Page::Pagination::Mode paginationMode() const { return m_paginationMode; }
+    void setGapBetweenPages(double);
+    double gapBetweenPages() const { return m_gapBetweenPages; }
+    unsigned pageCount() const { return m_pageCount; }
+
 #if PLATFORM(MAC)
     // Called by the web process through a message.
     void registerWebProcessAccessibilityToken(const CoreIPC::DataReference&);
@@ -662,6 +669,7 @@ private:
     void notifyScrollerThumbIsVisibleInRect(const WebCore::IntRect&);
     void didChangeScrollbarsForMainFrame(bool hasHorizontalScrollbar, bool hasVerticalScrollbar);
     void didChangeScrollOffsetPinningForMainFrame(bool pinnedToLeftSide, bool pinnedToRightSide);
+    void didChangePageCount(unsigned);
     void didFailToInitializePlugin(const String& mimeType);
     void numWheelEventHandlersChanged(unsigned count) { m_wheelEventHandlerCount = count; }
 
@@ -884,6 +892,9 @@ private:
     bool m_useFixedLayout;
     WebCore::IntSize m_fixedLayoutSize;
 
+    WebCore::Page::Pagination::Mode m_paginationMode;
+    double m_gapBetweenPages;
+
     // If the process backing the web page is alive and kicking.
     bool m_isValid;
 
@@ -938,6 +949,8 @@ private:
     bool m_mainFrameIsPinnedToLeftSide;
     bool m_mainFrameIsPinnedToRightSide;
 
+    unsigned m_pageCount;
+
     WebCore::IntRect m_visibleScrollerThumbRect;
 
     uint64_t m_renderTreeSize;
index e4031d31fcfe4446e21ccadb0da6e2942509ae4a..1efe2844dff921bad582e46ff0922c70ee33dc57 100644 (file)
@@ -63,6 +63,7 @@ messages -> WebPageProxy {
     NotifyScrollerThumbIsVisibleInRect(WebCore::IntRect scrollerThumb)
     DidChangeScrollbarsForMainFrame(bool hasHorizontalScrollbar, bool hasVerticalScrollbar)
     DidChangeScrollOffsetPinningForMainFrame(bool hasHorizontalScrollbar, bool hasVerticalScrollbar)
+    DidChangePageCount(unsigned pageCount);
     DidFailToInitializePlugin(WTF::String mimeType)
     NumWheelEventHandlersChanged(unsigned count)
 
index fd50a7474f1bbc61bdd268b23436320bc712fe1b..51a91f85e3687b405ca01d9652f307890079089e 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 */; };
+               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, ); }; };
                37F90DE31376560E0051CF68 /* HTTPCookieAcceptPolicy.h in Headers */ = {isa = PBXBuildFile; fileRef = F638954F133BEF38008941D5 /* HTTPCookieAcceptPolicy.h */; };
                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>"; };
+               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; };
                51021E9B12B16788005C033C /* WebContextMenuClientMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebContextMenuClientMac.mm; sourceTree = "<group>"; };
                                BCBAAC6C144E61910053F82F /* WKBrowsingContextController.h */,
                                BCBAAC6D144E61920053F82F /* WKBrowsingContextController.mm */,
                                BCBAAC6E144E61920053F82F /* WKBrowsingContextControllerInternal.h */,
+                               3788A05B14743C90006319E5 /* WKBrowsingContextControllerPrivate.h */,
                                BCBAACEE145232430053F82F /* WKBrowsingContextGroup.h */,
                                BCBAACEF145232440053F82F /* WKBrowsingContextGroup.mm */,
                                BCBAACF0145232480053F82F /* WKBrowsingContextGroupInternal.h */,
                                BC4A6290147312BE006C681A /* WebConnection.h in Headers */,
                                BC4A6292147312BE006C681A /* WebConnectionClient.h in Headers */,
                                BC4A6297147313A0006C681A /* WKConnectionRef.h in Headers */,
+                               3788A05C14743C90006319E5 /* WKBrowsingContextControllerPrivate.h in Headers */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
index 3a110009e079c2ae8dd95077b1c067be981db38b..cd25a6749417bf1b2e4f8442d2e040ab5d97d938 100644 (file)
@@ -563,9 +563,11 @@ void WebFrameLoaderClient::dispatchDidLayout()
     // NOTE: Unlike the other layout notifications, this does not notify the
     // the UIProcess for every call.
 
-    // FIXME: Remove at the soonest possible time.
-    if (m_frame == m_frame->page()->mainWebFrame())
+    if (m_frame == m_frame->page()->mainWebFrame()) {
+        // FIXME: Remove at the soonest possible time.
         webPage->send(Messages::WebPageProxy::SetRenderTreeSize(webPage->renderTreeSize()));
+        webPage->mainFrameDidLayout();
+    }
 }
 
 Frame* WebFrameLoaderClient::dispatchCreatePage(const NavigationAction& navigationAction)
index de0219e8542d568e99bbe3ee587f51e75a029135..5ad945cb66d21dd16a0bb5b2598bf7f83e9b2684 100644 (file)
@@ -193,6 +193,7 @@ WebPage::WebPage(uint64_t pageID, const WebPageCreationParameters& parameters)
     , m_isRunningModal(false)
     , m_cachedMainFrameIsPinnedToLeftSide(false)
     , m_cachedMainFrameIsPinnedToRightSide(false)
+    , m_cachedPageCount(0)
     , m_isShowingContextMenu(false)
 #if PLATFORM(WIN)
     , m_gestureReachedScrollingLimit(false)
@@ -240,6 +241,9 @@ WebPage::WebPage(uint64_t pageID, const WebPageCreationParameters& parameters)
     setDrawsBackground(parameters.drawsBackground);
     setDrawsTransparentBackground(parameters.drawsTransparentBackground);
 
+    setPaginationMode(parameters.paginationMode);
+    setGapBetweenPages(parameters.gapBetweenPages);
+
     setMemoryCacheMessagesEnabled(parameters.areMemoryCacheClientCallsEnabled);
 
     setActive(parameters.isActive);
@@ -916,6 +920,20 @@ void WebPage::setFixedLayoutSize(const IntSize& size)
     view->forceLayout();
 }
 
+void WebPage::setPaginationMode(uint32_t mode)
+{
+    Page::Pagination pagination = m_page->pagination();
+    pagination.mode = static_cast<Page::Pagination::Mode>(mode);
+    m_page->setPagination(pagination);
+}
+
+void WebPage::setGapBetweenPages(double gap)
+{
+    Page::Pagination pagination = m_page->pagination();
+    pagination.gap = gap;
+    m_page->setPagination(pagination);
+}
+
 void WebPage::installPageOverlay(PassRefPtr<PageOverlay> pageOverlay)
 {
     bool shouldFadeIn = true;
@@ -2168,6 +2186,15 @@ void WebPage::didChangeScrollOffsetForMainFrame()
     }
 }
 
+void WebPage::mainFrameDidLayout()
+{
+    unsigned pageCount = m_page->pageCount();
+    if (pageCount != m_cachedPageCount) {
+        send(Messages::WebPageProxy::DidChangePageCount(pageCount));
+        m_cachedPageCount = pageCount;
+    }
+}
+
 #if PLATFORM(MAC)
 
 void WebPage::addPluginView(PluginView* pluginView)
index 5a3bfaa5652e0d18742c096a3d5c0e7197bdfa91..55a365962d30e6c73793ffb4544482623b7217d6 100644 (file)
@@ -265,6 +265,9 @@ public:
     void setUseFixedLayout(bool);
     void setFixedLayoutSize(const WebCore::IntSize&);
 
+    void setPaginationMode(uint32_t /* WebCore::Page::Pagination::Mode */);
+    void setGapBetweenPages(double);
+
     bool drawsBackground() const { return m_drawsBackground; }
     bool drawsTransparentBackground() const { return m_drawsTransparentBackground; }
 
@@ -422,6 +425,8 @@ public:
 
     void didChangeScrollOffsetForMainFrame();
 
+    void mainFrameDidLayout();
+
     bool canRunBeforeUnloadConfirmPanel() const { return m_canRunBeforeUnloadConfirmPanel; }
     void setCanRunBeforeUnloadConfirmPanel(bool canRunBeforeUnloadConfirmPanel) { m_canRunBeforeUnloadConfirmPanel = canRunBeforeUnloadConfirmPanel; }
 
@@ -696,6 +701,8 @@ private:
     bool m_cachedMainFrameIsPinnedToLeftSide;
     bool m_cachedMainFrameIsPinnedToRightSide;
 
+    unsigned m_cachedPageCount;
+
     bool m_isShowingContextMenu;
 
 #if PLATFORM(WIN)
index fbb3d8728ff5ce9d79196e84aad748d05272c144..d755f5eed3a273cb08342dd19aebec8c7dcdd37c 100644 (file)
@@ -121,6 +121,9 @@ messages -> WebPage {
     SetUseFixedLayout(bool fixed)
     SetFixedLayoutSize(WebCore::IntSize size)
 
+    SetPaginationMode(uint32_t mode);
+    SetGapBetweenPages(double gap);
+
     # Find.
     FindString(WTF::String string, uint32_t findOptions, unsigned maxMatchCount)
     HideFindUI()