OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/renderer_host/render_widget_host_view_android.h" | 5 #include "content/browser/renderer_host/render_widget_host_view_android.h" |
6 | 6 |
7 #include <android/bitmap.h> | 7 #include <android/bitmap.h> |
8 | 8 |
9 #include "base/android/build_info.h" | 9 #include "base/android/build_info.h" |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 #include "ui/gfx/geometry/size_conversions.h" | 81 #include "ui/gfx/geometry/size_conversions.h" |
82 #include "ui/gfx/screen.h" | 82 #include "ui/gfx/screen.h" |
83 #include "ui/touch_selection/touch_selection_controller.h" | 83 #include "ui/touch_selection/touch_selection_controller.h" |
84 | 84 |
85 namespace content { | 85 namespace content { |
86 | 86 |
87 namespace { | 87 namespace { |
88 | 88 |
89 const int kUndefinedOutputSurfaceId = -1; | 89 const int kUndefinedOutputSurfaceId = -1; |
90 | 90 |
91 // Used to accomodate finite precision when comparing scaled viewport and | |
92 // content widths. While this value may seem large, width=device-width on an N7 | |
93 // V1 saw errors of ~0.065 between computed window and content widths. | |
94 const float kMobileViewportWidthEpsilon = 0.15f; | |
95 | |
96 static const char kAsyncReadBackString[] = "Compositing.CopyFromSurfaceTime"; | 91 static const char kAsyncReadBackString[] = "Compositing.CopyFromSurfaceTime"; |
97 | 92 |
98 // Sends an acknowledgement to the renderer of a processed IME event. | 93 // Sends an acknowledgement to the renderer of a processed IME event. |
99 void SendImeEventAck(RenderWidgetHostImpl* host) { | 94 void SendImeEventAck(RenderWidgetHostImpl* host) { |
100 host->Send(new ViewMsg_ImeEventAck(host->GetRoutingID())); | 95 host->Send(new ViewMsg_ImeEventAck(host->GetRoutingID())); |
101 } | 96 } |
102 | 97 |
103 class GLHelperHolder | 98 class GLHelperHolder |
104 : public blink::WebGraphicsContext3D::WebGraphicsContextLostCallback { | 99 : public blink::WebGraphicsContext3D::WebGraphicsContextLostCallback { |
105 public: | 100 public: |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 | 281 |
287 ui::GestureProvider::Config CreateGestureProviderConfig() { | 282 ui::GestureProvider::Config CreateGestureProviderConfig() { |
288 ui::GestureProvider::Config config = ui::GetGestureProviderConfig( | 283 ui::GestureProvider::Config config = ui::GetGestureProviderConfig( |
289 ui::GestureProviderConfigType::CURRENT_PLATFORM); | 284 ui::GestureProviderConfigType::CURRENT_PLATFORM); |
290 config.disable_click_delay = | 285 config.disable_click_delay = |
291 base::CommandLine::ForCurrentProcess()->HasSwitch( | 286 base::CommandLine::ForCurrentProcess()->HasSwitch( |
292 switches::kDisableClickDelay); | 287 switches::kDisableClickDelay); |
293 return config; | 288 return config; |
294 } | 289 } |
295 | 290 |
296 bool HasFixedPageScale(const cc::CompositorFrameMetadata& frame_metadata) { | |
297 return frame_metadata.min_page_scale_factor == | |
298 frame_metadata.max_page_scale_factor; | |
299 } | |
300 | |
301 bool HasMobileViewport(const cc::CompositorFrameMetadata& frame_metadata) { | |
302 float window_width_dip = | |
303 frame_metadata.page_scale_factor * | |
304 frame_metadata.scrollable_viewport_size.width(); | |
305 float content_width_css = frame_metadata.root_layer_size.width(); | |
306 return content_width_css <= window_width_dip + kMobileViewportWidthEpsilon; | |
307 } | |
308 | |
309 } // anonymous namespace | 291 } // anonymous namespace |
310 | 292 |
311 ReadbackRequest::ReadbackRequest(float scale, | 293 ReadbackRequest::ReadbackRequest(float scale, |
312 SkColorType color_type, | 294 SkColorType color_type, |
313 gfx::Rect src_subrect, | 295 gfx::Rect src_subrect, |
314 ReadbackRequestCallback& result_callback) | 296 ReadbackRequestCallback& result_callback) |
315 : scale_(scale), | 297 : scale_(scale), |
316 color_type_(color_type), | 298 color_type_(color_type), |
317 src_subrect_(src_subrect), | 299 src_subrect_(src_subrect), |
318 result_callback_(result_callback) { | 300 result_callback_(result_callback) { |
(...skipping 1006 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1325 SkCanvas canvas(bitmap); | 1307 SkCanvas canvas(bitmap); |
1326 canvas.scale( | 1308 canvas.scale( |
1327 (float)output_width / (float)input_size_in_pixel.width(), | 1309 (float)output_width / (float)input_size_in_pixel.width(), |
1328 (float)output_height / (float)input_size_in_pixel.height()); | 1310 (float)output_height / (float)input_size_in_pixel.height()); |
1329 compositor->DemandDrawSw(&canvas); | 1311 compositor->DemandDrawSw(&canvas); |
1330 callback.Run(bitmap, READBACK_SUCCESS); | 1312 callback.Run(bitmap, READBACK_SUCCESS); |
1331 } | 1313 } |
1332 | 1314 |
1333 void RenderWidgetHostViewAndroid::OnFrameMetadataUpdated( | 1315 void RenderWidgetHostViewAndroid::OnFrameMetadataUpdated( |
1334 const cc::CompositorFrameMetadata& frame_metadata) { | 1316 const cc::CompositorFrameMetadata& frame_metadata) { |
1335 | |
1336 // Disable double tap zoom for pages that have a width=device-width or | |
1337 // narrower viewport (indicating that this is a mobile-optimized or responsive | |
1338 // web design, so text will be legible without zooming). Also disable | |
1339 // double tap and pinch for pages that prevent zooming in or out. | |
1340 bool has_mobile_viewport = HasMobileViewport(frame_metadata); | |
1341 bool has_fixed_page_scale = HasFixedPageScale(frame_metadata); | |
1342 gesture_provider_.SetDoubleTapSupportForPageEnabled( | 1317 gesture_provider_.SetDoubleTapSupportForPageEnabled( |
1343 !has_fixed_page_scale && !has_mobile_viewport); | 1318 IsMobileOptimizedFrame(frame_metadata)); |
1344 | 1319 |
1345 if (!content_view_core_) | 1320 if (!content_view_core_) |
1346 return; | 1321 return; |
1347 | 1322 |
1348 if (overscroll_controller_) | 1323 if (overscroll_controller_) |
1349 overscroll_controller_->OnFrameMetadataUpdated(frame_metadata); | 1324 overscroll_controller_->OnFrameMetadataUpdated(frame_metadata); |
1350 | 1325 |
1351 if (selection_controller_) { | 1326 if (selection_controller_) { |
1352 selection_controller_->OnSelectionBoundsChanged( | 1327 selection_controller_->OnSelectionBoundsChanged( |
1353 ui::SelectionBound(frame_metadata.selection_start), | 1328 ui::SelectionBound(frame_metadata.selection_start), |
(...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1940 results->orientationAngle = display.RotationAsDegree(); | 1915 results->orientationAngle = display.RotationAsDegree(); |
1941 results->orientationType = | 1916 results->orientationType = |
1942 RenderWidgetHostViewBase::GetOrientationTypeForMobile(display); | 1917 RenderWidgetHostViewBase::GetOrientationTypeForMobile(display); |
1943 gfx::DeviceDisplayInfo info; | 1918 gfx::DeviceDisplayInfo info; |
1944 results->depth = info.GetBitsPerPixel(); | 1919 results->depth = info.GetBitsPerPixel(); |
1945 results->depthPerComponent = info.GetBitsPerComponent(); | 1920 results->depthPerComponent = info.GetBitsPerComponent(); |
1946 results->isMonochrome = (results->depthPerComponent == 0); | 1921 results->isMonochrome = (results->depthPerComponent == 0); |
1947 } | 1922 } |
1948 | 1923 |
1949 } // namespace content | 1924 } // namespace content |
OLD | NEW |