implTransform needs to scale scroll delta with deviceScaleFactor.

This CL fixes a number of issues. First, it fixes the implTransform for non-unit
device scale factors, fixing the issue about not being able to pan the zoom viewport
all the way to the right/bottom margins. It also allows remove the "fudge-factor" used
for hit testing in LayerTreeHost::adjustEventPointForPinchZoom, and finally it
resolves the issue regarding pinch-zoom not handling the anchor point properly
when device scale factor != 1.

BUG=158089


Review URL: https://chromiumcodereview.appspot.com/11414035

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@169308 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/cc/layer_tree_host_impl.cc b/cc/layer_tree_host_impl.cc
index 057c363..0f96a43 100644
--- a/cc/layer_tree_host_impl.cc
+++ b/cc/layer_tree_host_impl.cc
@@ -60,6 +60,7 @@
     , m_sentPageScaleDelta(1)
     , m_minPageScaleFactor(0)
     , m_maxPageScaleFactor(0)
+    , m_deviceScaleFactor(1)
 {
 }
 
@@ -101,7 +102,7 @@
 {
     gfx::RectF bounds(gfx::PointF(), m_layoutViewportSize);
     bounds.Scale(1 / totalPageScaleFactor());
-    bounds += m_pinchViewportScrollDelta;
+    bounds += m_zoomedViewportOffset;
     return bounds;
 }
 
@@ -129,7 +130,7 @@
         overflow.set_y(pinchedBounds.bottom() - m_layoutViewportSize.height());
         pinchedBounds += gfx::Vector2dF(0, m_layoutViewportSize.height() - pinchedBounds.bottom());
     }
-    m_pinchViewportScrollDelta = pinchedBounds.OffsetFromOrigin();
+    m_zoomedViewportOffset = pinchedBounds.OffsetFromOrigin();
 
     return overflow;
 }
@@ -143,8 +144,10 @@
     // impl transform, otherwise the scale is handled by WebCore.
     if (pageScalePinchZoomEnabled) {
         transform.scale(m_pageScaleFactor);
-        transform.translate(-m_pinchViewportScrollDelta.x(),
-                            -m_pinchViewportScrollDelta.y());
+        // The offset needs to be scaled by deviceScaleFactor as this transform
+        // needs to work with physical pixels.
+        gfx::Vector2dF zoomedDeviceViewportOffset = gfx::ScaleVector2d(m_zoomedViewportOffset, m_deviceScaleFactor);
+        transform.translate(-zoomedDeviceViewportOffset.x(), -zoomedDeviceViewportOffset.y());
     }
 
     return transform;
@@ -1043,6 +1046,7 @@
     if (deviceScaleFactor == m_deviceScaleFactor)
         return;
     m_deviceScaleFactor = deviceScaleFactor;
+    m_pinchZoomViewport.setDeviceScaleFactor(m_deviceScaleFactor);
 
     updateMaxScrollOffset();
 }
@@ -1340,7 +1344,7 @@
 
     if (m_settings.pageScalePinchZoomEnabled) {
         // Compute the application of the delta with respect to the current page zoom of the page.
-        move.Scale(1 / (m_pinchZoomViewport.pageScaleFactor() * m_deviceScaleFactor));
+        move.Scale(1 / m_pinchZoomViewport.pageScaleFactor());
     }
 
     gfx::Vector2dF scrollOverflow = m_settings.pageScalePinchZoomEnabled ? m_pinchZoomViewport.applyScroll(move) : move;