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 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 is_showing_(!widget_host->is_hidden()), | 271 is_showing_(!widget_host->is_hidden()), |
272 content_view_core_(NULL), | 272 content_view_core_(NULL), |
273 ime_adapter_android_(this), | 273 ime_adapter_android_(this), |
274 cached_background_color_(SK_ColorWHITE), | 274 cached_background_color_(SK_ColorWHITE), |
275 last_output_surface_id_(kUndefinedOutputSurfaceId), | 275 last_output_surface_id_(kUndefinedOutputSurfaceId), |
276 overscroll_effect_enabled_( | 276 overscroll_effect_enabled_( |
277 !base::CommandLine::ForCurrentProcess()->HasSwitch( | 277 !base::CommandLine::ForCurrentProcess()->HasSwitch( |
278 switches::kDisableOverscrollEdgeEffect)), | 278 switches::kDisableOverscrollEdgeEffect)), |
279 gesture_provider_(CreateGestureProviderConfig(), this), | 279 gesture_provider_(CreateGestureProviderConfig(), this), |
280 gesture_text_selector_(this), | 280 gesture_text_selector_(this), |
281 touch_scrolling_(false), | |
282 potentially_active_fling_count_(0), | |
283 accelerated_surface_route_id_(0), | 281 accelerated_surface_route_id_(0), |
284 using_synchronous_compositor_(SynchronousCompositorImpl::FromID( | 282 using_synchronous_compositor_(SynchronousCompositorImpl::FromID( |
285 widget_host->GetProcess()->GetID(), | 283 widget_host->GetProcess()->GetID(), |
286 widget_host->GetRoutingID()) != NULL), | 284 widget_host->GetRoutingID()) != NULL), |
287 frame_evictor_(new DelegatedFrameEvictor(this)), | 285 frame_evictor_(new DelegatedFrameEvictor(this)), |
288 locks_on_frame_count_(0), | 286 locks_on_frame_count_(0), |
289 observing_root_window_(false), | 287 observing_root_window_(false), |
290 weak_ptr_factory_(this) { | 288 weak_ptr_factory_(this) { |
291 host_->SetView(this); | 289 host_->SetView(this); |
292 SetContentViewCore(content_view_core); | 290 SetContentViewCore(content_view_core); |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
470 // We don't have plugin windows on Android. Do nothing. Note: this is called | 468 // We don't have plugin windows on Android. Do nothing. Note: this is called |
471 // from RenderWidgetHost::OnUpdateRect which is itself invoked while | 469 // from RenderWidgetHost::OnUpdateRect which is itself invoked while |
472 // processing the corresponding message from Renderer. | 470 // processing the corresponding message from Renderer. |
473 } | 471 } |
474 | 472 |
475 void RenderWidgetHostViewAndroid::Focus() { | 473 void RenderWidgetHostViewAndroid::Focus() { |
476 host_->Focus(); | 474 host_->Focus(); |
477 host_->SetInputMethodActive(true); | 475 host_->SetInputMethodActive(true); |
478 if (overscroll_effect_) | 476 if (overscroll_effect_) |
479 overscroll_effect_->Enable(); | 477 overscroll_effect_->Enable(); |
| 478 if (selection_controller_) |
| 479 selection_controller_->SetTemporarilyHidden(false); |
480 } | 480 } |
481 | 481 |
482 void RenderWidgetHostViewAndroid::Blur() { | 482 void RenderWidgetHostViewAndroid::Blur() { |
483 host_->SetInputMethodActive(false); | 483 host_->SetInputMethodActive(false); |
484 host_->Blur(); | 484 host_->Blur(); |
485 if (overscroll_effect_) | 485 if (overscroll_effect_) |
486 overscroll_effect_->Disable(); | 486 overscroll_effect_->Disable(); |
| 487 if (selection_controller_) |
| 488 selection_controller_->SetTemporarilyHidden(true); |
487 } | 489 } |
488 | 490 |
489 bool RenderWidgetHostViewAndroid::HasFocus() const { | 491 bool RenderWidgetHostViewAndroid::HasFocus() const { |
490 if (!content_view_core_) | 492 if (!content_view_core_) |
491 return false; // ContentViewCore not created yet. | 493 return false; // ContentViewCore not created yet. |
492 | 494 |
493 return content_view_core_->HasFocus(); | 495 return content_view_core_->HasFocus(); |
494 } | 496 } |
495 | 497 |
496 bool RenderWidgetHostViewAndroid::IsSurfaceAvailableForCopy() const { | 498 bool RenderWidgetHostViewAndroid::IsSurfaceAvailableForCopy() const { |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
728 | 730 |
729 void RenderWidgetHostViewAndroid::ResetGestureDetection() { | 731 void RenderWidgetHostViewAndroid::ResetGestureDetection() { |
730 const ui::MotionEvent* current_down_event = | 732 const ui::MotionEvent* current_down_event = |
731 gesture_provider_.GetCurrentDownEvent(); | 733 gesture_provider_.GetCurrentDownEvent(); |
732 if (!current_down_event) | 734 if (!current_down_event) |
733 return; | 735 return; |
734 | 736 |
735 scoped_ptr<ui::MotionEvent> cancel_event = current_down_event->Cancel(); | 737 scoped_ptr<ui::MotionEvent> cancel_event = current_down_event->Cancel(); |
736 DCHECK(cancel_event); | 738 DCHECK(cancel_event); |
737 OnTouchEvent(*cancel_event); | 739 OnTouchEvent(*cancel_event); |
738 | |
739 touch_scrolling_ = false; | |
740 potentially_active_fling_count_ = 0; | |
741 OnContentScrollingChange(); | |
742 } | 740 } |
743 | 741 |
744 void RenderWidgetHostViewAndroid::SetDoubleTapSupportEnabled(bool enabled) { | 742 void RenderWidgetHostViewAndroid::SetDoubleTapSupportEnabled(bool enabled) { |
745 gesture_provider_.SetDoubleTapSupportForPlatformEnabled(enabled); | 743 gesture_provider_.SetDoubleTapSupportForPlatformEnabled(enabled); |
746 } | 744 } |
747 | 745 |
748 void RenderWidgetHostViewAndroid::SetMultiTouchZoomSupportEnabled( | 746 void RenderWidgetHostViewAndroid::SetMultiTouchZoomSupportEnabled( |
749 bool enabled) { | 747 bool enabled) { |
750 gesture_provider_.SetMultiTouchZoomSupportEnabled(enabled); | 748 gesture_provider_.SetMultiTouchZoomSupportEnabled(enabled); |
751 } | 749 } |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
805 return; | 803 return; |
806 } | 804 } |
807 | 805 |
808 std::string utf8_selection = base::UTF16ToUTF8(text.substr(pos, n)); | 806 std::string utf8_selection = base::UTF16ToUTF8(text.substr(pos, n)); |
809 | 807 |
810 content_view_core_->OnSelectionChanged(utf8_selection); | 808 content_view_core_->OnSelectionChanged(utf8_selection); |
811 } | 809 } |
812 | 810 |
813 void RenderWidgetHostViewAndroid::SelectionBoundsChanged( | 811 void RenderWidgetHostViewAndroid::SelectionBoundsChanged( |
814 const ViewHostMsg_SelectionBounds_Params& params) { | 812 const ViewHostMsg_SelectionBounds_Params& params) { |
815 if (!selection_controller_) | 813 NOTREACHED() << "Selection bounds should be routed through the compositor."; |
816 return; | |
817 | |
818 gfx::RectF start_rect(params.anchor_rect); | |
819 gfx::RectF end_rect(params.focus_rect); | |
820 if (params.is_anchor_first) | |
821 std::swap(start_rect, end_rect); | |
822 | |
823 cc::ViewportSelectionBound start_bound, end_bound; | |
824 start_bound.visible = true; | |
825 end_bound.visible = true; | |
826 start_bound.edge_top = start_rect.origin(); | |
827 start_bound.edge_bottom = start_rect.bottom_left(); | |
828 end_bound.edge_top = end_rect.origin(); | |
829 end_bound.edge_bottom = end_rect.bottom_left(); | |
830 | |
831 if (params.anchor_rect == params.focus_rect) { | |
832 if (params.anchor_rect.x() || params.anchor_rect.y()) | |
833 start_bound.type = end_bound.type = cc::SELECTION_BOUND_CENTER; | |
834 } else { | |
835 start_bound.type = params.anchor_dir == blink::WebTextDirectionRightToLeft | |
836 ? cc::SELECTION_BOUND_LEFT | |
837 : cc::SELECTION_BOUND_RIGHT; | |
838 end_bound.type = params.focus_dir == blink::WebTextDirectionRightToLeft | |
839 ? cc::SELECTION_BOUND_RIGHT | |
840 : cc::SELECTION_BOUND_LEFT; | |
841 } | |
842 | |
843 selection_controller_->OnSelectionBoundsChanged(start_bound, end_bound); | |
844 } | 814 } |
845 | 815 |
846 void RenderWidgetHostViewAndroid::SetBackgroundOpaque(bool opaque) { | 816 void RenderWidgetHostViewAndroid::SetBackgroundOpaque(bool opaque) { |
847 RenderWidgetHostViewBase::SetBackgroundOpaque(opaque); | 817 RenderWidgetHostViewBase::SetBackgroundOpaque(opaque); |
848 host_->SetBackgroundOpaque(opaque); | 818 host_->SetBackgroundOpaque(opaque); |
849 } | 819 } |
850 | 820 |
851 void RenderWidgetHostViewAndroid::CopyFromCompositingSurface( | 821 void RenderWidgetHostViewAndroid::CopyFromCompositingSurface( |
852 const gfx::Rect& src_subrect, | 822 const gfx::Rect& src_subrect, |
853 const gfx::Size& dst_size, | 823 const gfx::Size& dst_size, |
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1231 // web design, so text will be legible without zooming). Also disable | 1201 // web design, so text will be legible without zooming). Also disable |
1232 // double tap and pinch for pages that prevent zooming in or out. | 1202 // double tap and pinch for pages that prevent zooming in or out. |
1233 bool has_mobile_viewport = HasMobileViewport(frame_metadata); | 1203 bool has_mobile_viewport = HasMobileViewport(frame_metadata); |
1234 bool has_fixed_page_scale = HasFixedPageScale(frame_metadata); | 1204 bool has_fixed_page_scale = HasFixedPageScale(frame_metadata); |
1235 gesture_provider_.SetDoubleTapSupportForPageEnabled( | 1205 gesture_provider_.SetDoubleTapSupportForPageEnabled( |
1236 !has_fixed_page_scale && !has_mobile_viewport); | 1206 !has_fixed_page_scale && !has_mobile_viewport); |
1237 | 1207 |
1238 if (!content_view_core_) | 1208 if (!content_view_core_) |
1239 return; | 1209 return; |
1240 | 1210 |
| 1211 DCHECK(selection_controller_); |
| 1212 selection_controller_->OnSelectionBoundsChanged( |
| 1213 frame_metadata.selection_start, frame_metadata.selection_end); |
| 1214 |
1241 // All offsets and sizes are in CSS pixels. | 1215 // All offsets and sizes are in CSS pixels. |
1242 content_view_core_->UpdateFrameInfo( | 1216 content_view_core_->UpdateFrameInfo( |
1243 frame_metadata.root_scroll_offset, | 1217 frame_metadata.root_scroll_offset, |
1244 frame_metadata.page_scale_factor, | 1218 frame_metadata.page_scale_factor, |
1245 gfx::Vector2dF(frame_metadata.min_page_scale_factor, | 1219 gfx::Vector2dF(frame_metadata.min_page_scale_factor, |
1246 frame_metadata.max_page_scale_factor), | 1220 frame_metadata.max_page_scale_factor), |
1247 frame_metadata.root_layer_size, | 1221 frame_metadata.root_layer_size, |
1248 frame_metadata.scrollable_viewport_size, | 1222 frame_metadata.scrollable_viewport_size, |
1249 frame_metadata.location_bar_offset, | 1223 frame_metadata.location_bar_offset, |
1250 frame_metadata.location_bar_content_translation); | 1224 frame_metadata.location_bar_content_translation); |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1352 } | 1326 } |
1353 | 1327 |
1354 bool RenderWidgetHostViewAndroid::Animate(base::TimeTicks frame_time) { | 1328 bool RenderWidgetHostViewAndroid::Animate(base::TimeTicks frame_time) { |
1355 bool needs_animate = | 1329 bool needs_animate = |
1356 overscroll_effect_ ? overscroll_effect_->Animate(frame_time) : false; | 1330 overscroll_effect_ ? overscroll_effect_->Animate(frame_time) : false; |
1357 if (selection_controller_) | 1331 if (selection_controller_) |
1358 needs_animate |= selection_controller_->Animate(frame_time); | 1332 needs_animate |= selection_controller_->Animate(frame_time); |
1359 return needs_animate; | 1333 return needs_animate; |
1360 } | 1334 } |
1361 | 1335 |
1362 void RenderWidgetHostViewAndroid::OnContentScrollingChange() { | |
1363 if (selection_controller_) | |
1364 selection_controller_->SetTemporarilyHidden(IsContentScrolling()); | |
1365 } | |
1366 | |
1367 bool RenderWidgetHostViewAndroid::IsContentScrolling() const { | |
1368 return touch_scrolling_ || potentially_active_fling_count_ > 0; | |
1369 } | |
1370 | |
1371 void RenderWidgetHostViewAndroid::AcceleratedSurfacePostSubBuffer( | 1336 void RenderWidgetHostViewAndroid::AcceleratedSurfacePostSubBuffer( |
1372 const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params, | 1337 const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params, |
1373 int gpu_host_id) { | 1338 int gpu_host_id) { |
1374 NOTREACHED(); | 1339 NOTREACHED(); |
1375 } | 1340 } |
1376 | 1341 |
1377 void RenderWidgetHostViewAndroid::AcceleratedSurfaceSuspend() { | 1342 void RenderWidgetHostViewAndroid::AcceleratedSurfaceSuspend() { |
1378 NOTREACHED(); | 1343 NOTREACHED(); |
1379 } | 1344 } |
1380 | 1345 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1427 void RenderWidgetHostViewAndroid::GestureEventAck( | 1392 void RenderWidgetHostViewAndroid::GestureEventAck( |
1428 const blink::WebGestureEvent& event, | 1393 const blink::WebGestureEvent& event, |
1429 InputEventAckState ack_result) { | 1394 InputEventAckState ack_result) { |
1430 // The overscroll effect requires an explicit release signal that may not be | 1395 // The overscroll effect requires an explicit release signal that may not be |
1431 // sent from the renderer compositor. | 1396 // sent from the renderer compositor. |
1432 if (event.type == blink::WebInputEvent::GestureScrollEnd || | 1397 if (event.type == blink::WebInputEvent::GestureScrollEnd || |
1433 event.type == blink::WebInputEvent::GestureFlingStart) { | 1398 event.type == blink::WebInputEvent::GestureFlingStart) { |
1434 DidOverscroll(DidOverscrollParams()); | 1399 DidOverscroll(DidOverscrollParams()); |
1435 } | 1400 } |
1436 | 1401 |
1437 switch (event.type) { | |
1438 case blink::WebInputEvent::GestureScrollBegin: | |
1439 touch_scrolling_ = true; | |
1440 potentially_active_fling_count_ = 0; | |
1441 OnContentScrollingChange(); | |
1442 break; | |
1443 case blink::WebInputEvent::GestureScrollEnd: | |
1444 touch_scrolling_ = false; | |
1445 OnContentScrollingChange(); | |
1446 break; | |
1447 case blink::WebInputEvent::GestureFlingStart: | |
1448 touch_scrolling_ = false; | |
1449 if (ack_result == INPUT_EVENT_ACK_STATE_CONSUMED) | |
1450 ++potentially_active_fling_count_; | |
1451 OnContentScrollingChange(); | |
1452 break; | |
1453 default: | |
1454 break; | |
1455 } | |
1456 | |
1457 if (content_view_core_) | 1402 if (content_view_core_) |
1458 content_view_core_->OnGestureEventAck(event, ack_result); | 1403 content_view_core_->OnGestureEventAck(event, ack_result); |
1459 } | 1404 } |
1460 | 1405 |
1461 InputEventAckState RenderWidgetHostViewAndroid::FilterInputEvent( | 1406 InputEventAckState RenderWidgetHostViewAndroid::FilterInputEvent( |
1462 const blink::WebInputEvent& input_event) { | 1407 const blink::WebInputEvent& input_event) { |
1463 if (selection_controller_) { | 1408 if (selection_controller_) { |
1464 switch (input_event.type) { | 1409 switch (input_event.type) { |
1465 case blink::WebInputEvent::GestureLongPress: | 1410 case blink::WebInputEvent::GestureLongPress: |
1466 selection_controller_->OnLongPressEvent(); | 1411 selection_controller_->OnLongPressEvent(); |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1608 gfx::ScaleVector2d(params.current_fling_velocity, | 1553 gfx::ScaleVector2d(params.current_fling_velocity, |
1609 device_scale_factor), | 1554 device_scale_factor), |
1610 gfx::ScaleVector2d( | 1555 gfx::ScaleVector2d( |
1611 params.causal_event_viewport_point.OffsetFromOrigin(), | 1556 params.causal_event_viewport_point.OffsetFromOrigin(), |
1612 device_scale_factor))) { | 1557 device_scale_factor))) { |
1613 SetNeedsAnimate(); | 1558 SetNeedsAnimate(); |
1614 } | 1559 } |
1615 } | 1560 } |
1616 | 1561 |
1617 void RenderWidgetHostViewAndroid::DidStopFlinging() { | 1562 void RenderWidgetHostViewAndroid::DidStopFlinging() { |
1618 if (potentially_active_fling_count_) { | |
1619 --potentially_active_fling_count_; | |
1620 OnContentScrollingChange(); | |
1621 } | |
1622 | |
1623 if (content_view_core_) | 1563 if (content_view_core_) |
1624 content_view_core_->DidStopFlinging(); | 1564 content_view_core_->DidStopFlinging(); |
1625 } | 1565 } |
1626 | 1566 |
1627 void RenderWidgetHostViewAndroid::SetContentViewCore( | 1567 void RenderWidgetHostViewAndroid::SetContentViewCore( |
1628 ContentViewCoreImpl* content_view_core) { | 1568 ContentViewCoreImpl* content_view_core) { |
1629 RemoveLayers(); | 1569 RemoveLayers(); |
1630 StopObservingRootWindow(); | 1570 StopObservingRootWindow(); |
1631 | 1571 |
1632 bool resize = false; | 1572 bool resize = false; |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1867 results->orientationAngle = display.RotationAsDegree(); | 1807 results->orientationAngle = display.RotationAsDegree(); |
1868 results->orientationType = | 1808 results->orientationType = |
1869 RenderWidgetHostViewBase::GetOrientationTypeForMobile(display); | 1809 RenderWidgetHostViewBase::GetOrientationTypeForMobile(display); |
1870 gfx::DeviceDisplayInfo info; | 1810 gfx::DeviceDisplayInfo info; |
1871 results->depth = info.GetBitsPerPixel(); | 1811 results->depth = info.GetBitsPerPixel(); |
1872 results->depthPerComponent = info.GetBitsPerComponent(); | 1812 results->depthPerComponent = info.GetBitsPerComponent(); |
1873 results->isMonochrome = (results->depthPerComponent == 0); | 1813 results->isMonochrome = (results->depthPerComponent == 0); |
1874 } | 1814 } |
1875 | 1815 |
1876 } // namespace content | 1816 } // namespace content |
OLD | NEW |