diff options
-rw-r--r-- | cc/layer_tree_host_impl.cc | 20 | ||||
-rw-r--r-- | cc/layer_tree_host_impl.h | 1 | ||||
-rw-r--r-- | cc/layer_tree_host_impl_unittest.cc | 17 | ||||
-rw-r--r-- | cc/layer_tree_impl.cc | 31 | ||||
-rw-r--r-- | cc/layer_tree_impl.h | 2 | ||||
-rw-r--r-- | cc/pinch_zoom_viewport.cc | 13 | ||||
-rw-r--r-- | cc/pinch_zoom_viewport.h | 14 | ||||
-rw-r--r-- | content/browser/android/content_startup_flags.cc | 4 | ||||
-rw-r--r-- | content/browser/android/content_view_core_impl.cc | 17 | ||||
-rw-r--r-- | content/browser/android/content_view_core_impl.h | 3 | ||||
-rw-r--r-- | content/browser/renderer_host/render_widget_host_view_android.cc | 2 | ||||
-rw-r--r-- | ui/gfx/screen_android.cc | 2 |
12 files changed, 59 insertions, 67 deletions
diff --git a/cc/layer_tree_host_impl.cc b/cc/layer_tree_host_impl.cc index 6b63b39..f4324bc 100644 --- a/cc/layer_tree_host_impl.cc +++ b/cc/layer_tree_host_impl.cc @@ -261,15 +261,15 @@ void LayerTreeHostImpl::startPageScaleAnimation(gfx::Vector2d targetOffset, bool return; gfx::Vector2dF scrollTotal = rootScrollLayer()->scrollOffset() + rootScrollLayer()->scrollDelta(); - gfx::SizeF scaledContentSize = contentSize(); + gfx::SizeF scaledScrollableSize = activeTree()->ScrollableSize(); if (!m_settings.pageScalePinchZoomEnabled) { scrollTotal.Scale(1 / m_pinchZoomViewport.page_scale_factor()); - scaledContentSize.Scale(1 / m_pinchZoomViewport.page_scale_factor()); + scaledScrollableSize.Scale(1 / m_pinchZoomViewport.page_scale_factor()); } gfx::SizeF viewportSize = gfx::ScaleSize(m_deviceViewportSize, 1 / m_deviceScaleFactor); double startTimeSeconds = (startTime - base::TimeTicks()).InSecondsF(); - m_pageScaleAnimation = PageScaleAnimation::create(scrollTotal, m_pinchZoomViewport.total_page_scale_factor(), viewportSize, scaledContentSize, startTimeSeconds); + m_pageScaleAnimation = PageScaleAnimation::create(scrollTotal, m_pinchZoomViewport.total_page_scale_factor(), viewportSize, scaledScrollableSize, startTimeSeconds); if (anchorPoint) { gfx::Vector2dF anchor(targetOffset); @@ -561,11 +561,6 @@ void LayerTreeHostImpl::setBackgroundTickingEnabled(bool enabled) m_timeSourceClientAdapter->setActive(enabled); } -gfx::Size LayerTreeHostImpl::contentSize() const -{ - return activeTree()->ContentSize(); -} - static inline RenderPass* findRenderPassById(RenderPass::Id renderPassId, const LayerTreeHostImpl::FrameData& frame) { RenderPassIdHashMap::const_iterator it = frame.renderPassesById.find(renderPassId); @@ -777,8 +772,8 @@ CompositorFrameMetadata LayerTreeHostImpl::makeCompositorFrameMetadata() const { CompositorFrameMetadata metadata; metadata.page_scale_factor = m_pinchZoomViewport.total_page_scale_factor(); - metadata.viewport_size = m_pinchZoomViewport.Bounds().size(); - metadata.root_layer_size = contentSize(); + metadata.viewport_size = m_pinchZoomViewport.ZoomedViewport().size(); + metadata.root_layer_size = activeTree()->ScrollableSize(); metadata.min_page_scale_factor = m_pinchZoomViewport.min_page_scale_factor(); metadata.max_page_scale_factor = m_pinchZoomViewport.max_page_scale_factor(); if (m_topControlsManager) { @@ -1053,6 +1048,7 @@ void LayerTreeHostImpl::setViewportSize(const gfx::Size& layoutViewportSize, con m_deviceViewportSize = deviceViewportSize; m_pinchZoomViewport.set_layout_viewport_size(layoutViewportSize); + m_pinchZoomViewport.set_device_viewport_size(deviceViewportSize); updateMaxScrollOffset(); @@ -1406,13 +1402,13 @@ void LayerTreeHostImpl::computePinchZoomDeltas(ScrollAndScaleSet* scrollInfo) scrollBegin.Scale(m_pinchZoomViewport.page_scale_delta()); float scaleBegin = m_pinchZoomViewport.total_page_scale_factor(); float pageScaleDeltaToSend = m_pinchZoomViewport.min_page_scale_factor() / m_pinchZoomViewport.page_scale_factor(); - gfx::SizeF scaledContentsSize = gfx::ScaleSize(contentSize(), pageScaleDeltaToSend); + gfx::SizeF scaledScrollableSize = gfx::ScaleSize(activeTree()->ScrollableSize(), pageScaleDeltaToSend); gfx::Vector2d anchorOffset = m_previousPinchAnchor.OffsetFromOrigin(); gfx::Vector2dF scrollEnd = scrollBegin + anchorOffset; scrollEnd.Scale(m_pinchZoomViewport.min_page_scale_factor() / scaleBegin); scrollEnd -= anchorOffset; - scrollEnd.ClampToMax(gfx::RectF(scaledContentsSize).bottom_right() - gfx::Rect(m_deviceViewportSize).bottom_right()); + scrollEnd.ClampToMax(gfx::RectF(scaledScrollableSize).bottom_right() - gfx::Rect(m_deviceViewportSize).bottom_right()); scrollEnd.ClampToMin(gfx::Vector2d()); scrollEnd.Scale(1 / pageScaleDeltaToSend); scrollEnd.Scale(m_deviceScaleFactor); diff --git a/cc/layer_tree_host_impl.h b/cc/layer_tree_host_impl.h index f4dbf3f..02da353c 100644 --- a/cc/layer_tree_host_impl.h +++ b/cc/layer_tree_host_impl.h @@ -295,7 +295,6 @@ private: bool calculateRenderPasses(FrameData&); void animateLayersRecursive(LayerImpl*, base::TimeTicks monotonicTime, base::Time wallClockTime, AnimationEventsVector*, bool& didAnimate, bool& needsAnimateLayers); void setBackgroundTickingEnabled(bool); - gfx::Size contentSize() const; void sendDidLoseOutputSurfaceRecursive(LayerImpl*); void clearRenderSurfaces(); diff --git a/cc/layer_tree_host_impl_unittest.cc b/cc/layer_tree_host_impl_unittest.cc index 432800f..ea28ae8 100644 --- a/cc/layer_tree_host_impl_unittest.cc +++ b/cc/layer_tree_host_impl_unittest.cc @@ -541,23 +541,6 @@ TEST_P(LayerTreeHostImplTest, scrollByReturnsCorrectValue) EXPECT_TRUE(m_hostImpl->scrollBy(gfx::Point(), gfx::Vector2d(5000, 5000))); } -TEST_P(LayerTreeHostImplTest, maxScrollOffsetChangedByDeviceScaleFactor) -{ - setupScrollAndContentsLayers(gfx::Size(100, 100)); - - float deviceScaleFactor = 2; - gfx::Size layoutViewport(25, 25); - gfx::Size deviceViewport(gfx::ToFlooredSize(gfx::ScaleSize(layoutViewport, deviceScaleFactor))); - m_hostImpl->setViewportSize(layoutViewport, deviceViewport); - m_hostImpl->setDeviceScaleFactor(deviceScaleFactor); - EXPECT_EQ(m_hostImpl->rootLayer()->maxScrollOffset(), gfx::Vector2d(25, 25)); - - deviceScaleFactor = 1; - m_hostImpl->setViewportSize(layoutViewport, layoutViewport); - m_hostImpl->setDeviceScaleFactor(deviceScaleFactor); - EXPECT_EQ(m_hostImpl->rootLayer()->maxScrollOffset(), gfx::Vector2d(75, 75)); -} - TEST_P(LayerTreeHostImplTest, clearRootRenderSurfaceAndHitTestTouchHandlerRegion) { setupScrollAndContentsLayers(gfx::Size(100, 100)); diff --git a/cc/layer_tree_impl.cc b/cc/layer_tree_impl.cc index 9f9588b..328116a 100644 --- a/cc/layer_tree_impl.cc +++ b/cc/layer_tree_impl.cc @@ -97,28 +97,21 @@ void LayerTreeImpl::UpdateMaxScrollOffset() { if (!root_scroll_layer_ || !root_scroll_layer_->children().size()) return; - gfx::SizeF view_bounds = device_viewport_size(); - if (LayerImpl* clip_layer = root_scroll_layer_->parent()) { - // Compensate for non-overlay scrollbars. - if (clip_layer->masksToBounds()) - view_bounds = gfx::ScaleSize(clip_layer->bounds(), device_scale_factor()); - } - - gfx::Size content_bounds = ContentSize(); - if (settings().pageScalePinchZoomEnabled) { - // Pinch with pageScale scrolls entirely in layout space. ContentSize - // returns the bounds including the page scale factor, so calculate the - // pre page-scale layout size here. - float page_scale_factor = pinch_zoom_viewport().page_scale_factor(); - content_bounds.set_width(content_bounds.width() / page_scale_factor); - content_bounds.set_height(content_bounds.height() / page_scale_factor); - } else { + gfx::SizeF view_bounds; + if (!settings().pageScalePinchZoomEnabled) { + view_bounds = device_viewport_size(); + if (LayerImpl* clip_layer = root_scroll_layer_->parent()) { + // Compensate for non-overlay scrollbars. + if (clip_layer->masksToBounds()) + view_bounds = gfx::ScaleSize(clip_layer->bounds(), device_scale_factor()); + } view_bounds.Scale(1 / pinch_zoom_viewport().page_scale_delta()); + } else { + view_bounds = layout_viewport_size(); } - gfx::Vector2dF max_scroll = gfx::Rect(content_bounds).bottom_right() - + gfx::Vector2dF max_scroll = gfx::Rect(ScrollableSize()).bottom_right() - gfx::RectF(view_bounds).bottom_right(); - max_scroll.Scale(1 / device_scale_factor()); // The viewport may be larger than the contents in some cases, such as // having a vertical scrollbar but no horizontal overflow. @@ -187,7 +180,7 @@ const LayerTreeImpl::LayerList& LayerTreeImpl::RenderSurfaceLayerList() const { return render_surface_layer_list_; } -gfx::Size LayerTreeImpl::ContentSize() const { +gfx::Size LayerTreeImpl::ScrollableSize() const { if (!root_scroll_layer_ || root_scroll_layer_->children().empty()) return gfx::Size(); return root_scroll_layer_->children()[0]->bounds(); diff --git a/cc/layer_tree_impl.h b/cc/layer_tree_impl.h index 01caba4..bae0cb9 100644 --- a/cc/layer_tree_impl.h +++ b/cc/layer_tree_impl.h @@ -121,7 +121,7 @@ class CC_EXPORT LayerTreeImpl { const LayerList& RenderSurfaceLayerList() const; - gfx::Size ContentSize() const; + gfx::Size ScrollableSize() const; LayerImpl* LayerById(int id); diff --git a/cc/pinch_zoom_viewport.cc b/cc/pinch_zoom_viewport.cc index dab6c9c..3f3e3a1 100644 --- a/cc/pinch_zoom_viewport.cc +++ b/cc/pinch_zoom_viewport.cc @@ -50,16 +50,17 @@ bool PinchZoomViewport::SetPageScaleFactorAndLimits( return true; } -gfx::RectF PinchZoomViewport::Bounds() const { - gfx::RectF bounds(gfx::PointF(), layout_viewport_size_); - bounds.Scale(1 / total_page_scale_factor()); - bounds += zoomed_viewport_offset_; - return bounds; +gfx::RectF PinchZoomViewport::ZoomedViewport() const { + gfx::SizeF layout_space_device_viewport_size = gfx::ScaleSize( + device_viewport_size_, + 1 / (device_scale_factor_ * total_page_scale_factor())); + return gfx::RectF(gfx::PointAtOffsetFromOrigin(zoomed_viewport_offset_), + layout_space_device_viewport_size); } gfx::Vector2dF PinchZoomViewport::ApplyScroll(const gfx::Vector2dF delta) { gfx::Vector2dF overflow; - gfx::RectF pinched_bounds = Bounds() + delta; + gfx::RectF pinched_bounds = ZoomedViewport() + delta; if (pinched_bounds.x() < 0) { overflow.set_x(pinched_bounds.x()); diff --git a/cc/pinch_zoom_viewport.h b/cc/pinch_zoom_viewport.h index 0b55a3f..9efe386 100644 --- a/cc/pinch_zoom_viewport.h +++ b/cc/pinch_zoom_viewport.h @@ -47,9 +47,10 @@ class CC_EXPORT PinchZoomViewport { float min_page_scale_factor, float max_page_scale_factor); - // Returns the bounds and offset of the scaled and translated viewport to use - // for pinch-zoom. - gfx::RectF Bounds() const; + // Returns the zoomed viewport in layout space. The rect's position is an + // offset from the root layer's scroll position (therefore, zero if fully + // zoomed out). + gfx::RectF ZoomedViewport() const; const gfx::Vector2dF& zoomed_viewport_offset() const { return zoomed_viewport_offset_; @@ -58,6 +59,12 @@ class CC_EXPORT PinchZoomViewport { void set_layout_viewport_size(const gfx::SizeF& size) { layout_viewport_size_ = size; } + // We need to store device_viewport_size separately because in mobile + // fixed-layout mode, there is not necessarily a simple mapping between layout + // viewport size and device viewport size. + void set_device_viewport_size(const gfx::SizeF& size) { + device_viewport_size_ = size; + } // Apply the scroll offset in layout space to the offset of the pinch-zoom // viewport. The viewport cannot be scrolled outside of the layout viewport @@ -81,6 +88,7 @@ class CC_EXPORT PinchZoomViewport { gfx::Vector2dF zoomed_viewport_offset_; gfx::SizeF layout_viewport_size_; + gfx::SizeF device_viewport_size_; }; } // namespace cc diff --git a/content/browser/android/content_startup_flags.cc b/content/browser/android/content_startup_flags.cc index 3e0ee61..e793204 100644 --- a/content/browser/android/content_startup_flags.cc +++ b/content/browser/android/content_startup_flags.cc @@ -57,7 +57,9 @@ void SetContentCommandLineFlags(int max_render_process_count) { switches::kEnableCompositedScrollingForFrames); parsed_command_line->AppendSwitch(switches::kEnableGestureTapHighlight); - parsed_command_line->AppendSwitch(switches::kEnableCssTransformPinch); + parsed_command_line->AppendSwitch(switches::kEnablePinch); + if (!parsed_command_line->HasSwitch(cc::switches::kEnableImplSidePainting)) + parsed_command_line->AppendSwitch(switches::kEnableCssTransformPinch); // Run the GPU service as a thread in the browser instead of as a // standalone process. diff --git a/content/browser/android/content_view_core_impl.cc b/content/browser/android/content_view_core_impl.cc index e8a0b3a..c7ebc41 100644 --- a/content/browser/android/content_view_core_impl.cc +++ b/content/browser/android/content_view_core_impl.cc @@ -8,6 +8,7 @@ #include "base/android/jni_array.h" #include "base/android/jni_string.h" #include "base/android/scoped_java_ref.h" +#include "base/command_line.h" #include "base/json/json_writer.h" #include "base/logging.h" #include "base/utf_string_conversions.h" @@ -37,6 +38,7 @@ #include "content/public/browser/notification_types.h" #include "content/public/browser/web_contents.h" #include "content/public/common/content_client.h" +#include "content/public/common/content_switches.h" #include "content/public/common/page_transition_types.h" #include "jni/ContentViewCore_jni.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" @@ -45,6 +47,8 @@ #include "ui/gfx/android/java_bitmap.h" #include "ui/gfx/android/window_android.h" #include "ui/gfx/screen.h" +#include "ui/gfx/size_conversions.h" +#include "ui/gfx/size_f.h" #include "webkit/glue/webmenuitem.h" #include "webkit/user_agent/user_agent_util.h" @@ -168,7 +172,8 @@ ContentViewCoreImpl::ContentViewCoreImpl(JNIEnv* env, jobject obj, InitJNI(env, obj); - if (!gfx::Screen::GetNativeScreen()->IsDIPEnabled()) { + if (CommandLine::ForCurrentProcess()->HasSwitch( + switches::kEnableCssTransformPinch)) { dpi_scale_ = 1; } else { scoped_ptr<content::DeviceInfo> device_info(new content::DeviceInfo()); @@ -585,15 +590,19 @@ void ContentViewCoreImpl::ShowDisambiguationPopup( java_bitmap.obj()); } -gfx::Rect ContentViewCoreImpl::GetBounds() const { +gfx::Size ContentViewCoreImpl::GetPhysicalSize() const { JNIEnv* env = AttachCurrentThread(); ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); if (j_obj.is_null()) - return gfx::Rect(); - return gfx::Rect(Java_ContentViewCore_getWidth(env, j_obj.obj()), + return gfx::Size(); + return gfx::Size(Java_ContentViewCore_getWidth(env, j_obj.obj()), Java_ContentViewCore_getHeight(env, j_obj.obj())); } +gfx::Size ContentViewCoreImpl::GetDIPSize() const { + return gfx::ToCeiledSize(gfx::ScaleSize(GetPhysicalSize(), 1 / DpiScale())); +} + void ContentViewCoreImpl::AttachLayer(scoped_refptr<cc::Layer> layer) { root_layer_->addChild(layer); } diff --git a/content/browser/android/content_view_core_impl.h b/content/browser/android/content_view_core_impl.h index 151dd91..96a4601 100644 --- a/content/browser/android/content_view_core_impl.h +++ b/content/browser/android/content_view_core_impl.h @@ -258,7 +258,8 @@ class ContentViewCoreImpl : public ContentViewCore, // Methods called from native code // -------------------------------------------------------------------------- - gfx::Rect GetBounds() const; + gfx::Size GetPhysicalSize() const; + gfx::Size GetDIPSize() const; void AttachLayer(scoped_refptr<cc::Layer> layer); void RemoveLayer(scoped_refptr<cc::Layer> layer); diff --git a/content/browser/renderer_host/render_widget_host_view_android.cc b/content/browser/renderer_host/render_widget_host_view_android.cc index f7655e3..fc65287 100644 --- a/content/browser/renderer_host/render_widget_host_view_android.cc +++ b/content/browser/renderer_host/render_widget_host_view_android.cc @@ -269,7 +269,7 @@ gfx::Rect RenderWidgetHostViewAndroid::GetViewBounds() const { if (!content_view_core_) return gfx::Rect(); - return content_view_core_->GetBounds(); + return gfx::Rect(content_view_core_->GetDIPSize()); } void RenderWidgetHostViewAndroid::UpdateCursor(const WebCursor& cursor) { diff --git a/ui/gfx/screen_android.cc b/ui/gfx/screen_android.cc index a80582e..bb8f01d 100644 --- a/ui/gfx/screen_android.cc +++ b/ui/gfx/screen_android.cc @@ -14,7 +14,7 @@ class ScreenAndroid : public Screen { ScreenAndroid() {} bool IsDIPEnabled() OVERRIDE { - return false; + return true; } gfx::Point GetCursorScreenPoint() OVERRIDE { |