Make WK(Web)View magnification setters actually use view-relative positions
authortimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 14 Apr 2014 17:27:59 +0000 (17:27 +0000)
committertimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 14 Apr 2014 17:27:59 +0000 (17:27 +0000)
https://bugs.webkit.org/show_bug.cgi?id=131611
<rdar://problem/15965239>

Reviewed by Darin Adler.

* UIProcess/API/mac/WKView.mm:
(-[WKView setMagnification:centeredAtPoint:]):
(-[WKView setMagnification:]):
Use scalePageInViewCoordinates instead.

* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::scalePageInViewCoordinates):
* UIProcess/WebPageProxy.h:
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::scalePageInViewCoordinates):
(WebKit::WebPage::pageScaleFactor):
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/WebPage.messages.in:
Add scalePageInViewCoordinates, which turns the scale centerpoint within the view
into what scalePage expects: a post-scale scroll offset.

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

Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/mac/WKView.mm
Source/WebKit2/UIProcess/WebPageProxy.cpp
Source/WebKit2/UIProcess/WebPageProxy.h
Source/WebKit2/WebProcess/WebPage/WebPage.cpp
Source/WebKit2/WebProcess/WebPage/WebPage.h
Source/WebKit2/WebProcess/WebPage/WebPage.messages.in

index e821907..574cc7d 100644 (file)
@@ -1,5 +1,29 @@
 2014-04-14  Tim Horton  <timothy_horton@apple.com>
 
+        Make WK(Web)View magnification setters actually use view-relative positions
+        https://bugs.webkit.org/show_bug.cgi?id=131611
+        <rdar://problem/15965239>
+
+        Reviewed by Darin Adler.
+
+        * UIProcess/API/mac/WKView.mm:
+        (-[WKView setMagnification:centeredAtPoint:]):
+        (-[WKView setMagnification:]):
+        Use scalePageInViewCoordinates instead.
+
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::scalePageInViewCoordinates):
+        * UIProcess/WebPageProxy.h:
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::scalePageInViewCoordinates):
+        (WebKit::WebPage::pageScaleFactor):
+        * WebProcess/WebPage/WebPage.h:
+        * WebProcess/WebPage/WebPage.messages.in:
+        Add scalePageInViewCoordinates, which turns the scale centerpoint within the view
+        into what scalePage expects: a post-scale scroll offset.
+
+2014-04-14  Tim Horton  <timothy_horton@apple.com>
+
         Support setting a background color on page overlays
         https://bugs.webkit.org/show_bug.cgi?id=131600
 
index 162f428..2953a84 100644 (file)
@@ -3869,13 +3869,13 @@ static NSString *pathWithUniqueFilenameForPath(NSString *path)
 
 - (void)setMagnification:(double)magnification centeredAtPoint:(NSPoint)point
 {
-    _data->_page->scalePage(magnification, roundedIntPoint(point));
+    _data->_page->scalePageInViewCoordinates(magnification, roundedIntPoint(point));
 }
 
 - (void)setMagnification:(double)magnification
 {
     FloatPoint viewCenter(NSMidX([self bounds]), NSMidY([self bounds]));
-    _data->_page->scalePage(magnification, roundedIntPoint(viewCenter));
+    _data->_page->scalePageInViewCoordinates(magnification, roundedIntPoint(viewCenter));
 }
 
 - (double)magnification
index 3cc7105..4aaee45 100644 (file)
@@ -1730,6 +1730,15 @@ void WebPageProxy::scalePage(double scale, const IntPoint& origin)
     m_process->send(Messages::WebPage::ScalePage(scale, origin), m_pageID);
 }
 
+void WebPageProxy::scalePageInViewCoordinates(double scale, const IntPoint& centerInViewCoordinates)
+{
+    if (!isValid())
+        return;
+
+    m_pageScaleFactor = scale;
+    m_process->send(Messages::WebPage::ScalePageInViewCoordinates(scale, centerInViewCoordinates), m_pageID);
+}
+
 void WebPageProxy::setIntrinsicDeviceScaleFactor(float scaleFactor)
 {
     if (m_intrinsicDeviceScaleFactor == scaleFactor)
index dba3ca6..229a5e6 100644 (file)
@@ -731,6 +731,7 @@ public:
     void setPageAndTextZoomFactors(double pageZoomFactor, double textZoomFactor);
 
     void scalePage(double scale, const WebCore::IntPoint& origin);
+    void scalePageInViewCoordinates(double scale, const WebCore::IntPoint& centerInViewCoordinates);
     double pageScaleFactor() const { return m_pageScaleFactor; }
 
     float deviceScaleFactor() const;
index e79296e..b35a8cd 100644 (file)
@@ -1298,12 +1298,23 @@ void WebPage::scalePage(double scale, const IntPoint& origin)
     send(Messages::WebPageProxy::PageScaleFactorDidChange(scale));
 }
 
+void WebPage::scalePageInViewCoordinates(double scale, IntPoint centerInViewCoordinates)
+{
+    if (scale == pageScaleFactor())
+        return;
+
+    IntPoint scrollPositionAtNewScale = mainFrameView()->rootViewToContents(-centerInViewCoordinates);
+    double scaleRatio = scale / pageScaleFactor();
+    scrollPositionAtNewScale.scale(scaleRatio, scaleRatio);
+    scalePage(scale, scrollPositionAtNewScale);
+}
+
 double WebPage::pageScaleFactor() const
 {
     PluginView* pluginView = pluginViewForFrame(&m_page->mainFrame());
     if (pluginView && pluginView->handlesPageScaleFactor())
         return pluginView->pageScaleFactor();
-    
+
     return m_page->pageScaleFactor();
 }
 
index e36fd8b..62033e3 100644 (file)
@@ -349,6 +349,7 @@ public:
     void windowScreenDidChange(uint64_t);
 
     void scalePage(double scale, const WebCore::IntPoint& origin);
+    void scalePageInViewCoordinates(double scale, WebCore::IntPoint centerInViewCoordinates);
     double pageScaleFactor() const;
 
     void setUseFixedLayout(bool);
index 3fa06d2..7739513 100644 (file)
@@ -167,6 +167,7 @@ messages -> WebPage LegacyReceiver {
     WindowScreenDidChange(uint64_t displayID)
 
     ScalePage(double scale, WebCore::IntPoint origin)
+    ScalePageInViewCoordinates(double scale, WebCore::IntPoint centerInViewCoordinates)
 
     SetUseFixedLayout(bool fixed)
     SetFixedLayoutSize(WebCore::IntSize size)