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 <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 22 matching lines...) Expand all Loading... |
33 #include "cc/output/latency_info_swap_promise.h" | 33 #include "cc/output/latency_info_swap_promise.h" |
34 #include "cc/resources/single_release_callback.h" | 34 #include "cc/resources/single_release_callback.h" |
35 #include "cc/surfaces/surface.h" | 35 #include "cc/surfaces/surface.h" |
36 #include "cc/surfaces/surface_hittest.h" | 36 #include "cc/surfaces/surface_hittest.h" |
37 #include "cc/surfaces/surface_manager.h" | 37 #include "cc/surfaces/surface_manager.h" |
38 #include "cc/trees/layer_tree_host.h" | 38 #include "cc/trees/layer_tree_host.h" |
39 #include "components/display_compositor/gl_helper.h" | 39 #include "components/display_compositor/gl_helper.h" |
40 #include "content/browser/accessibility/browser_accessibility_manager_android.h" | 40 #include "content/browser/accessibility/browser_accessibility_manager_android.h" |
41 #include "content/browser/android/composited_touch_handle_drawable.h" | 41 #include "content/browser/android/composited_touch_handle_drawable.h" |
42 #include "content/browser/android/content_view_core_impl.h" | 42 #include "content/browser/android/content_view_core_impl.h" |
43 #include "content/browser/android/ime_adapter_android.h" | |
44 #include "content/browser/android/overscroll_controller_android.h" | 43 #include "content/browser/android/overscroll_controller_android.h" |
45 #include "content/browser/android/synchronous_compositor_host.h" | 44 #include "content/browser/android/synchronous_compositor_host.h" |
46 #include "content/browser/compositor/surface_utils.h" | 45 #include "content/browser/compositor/surface_utils.h" |
47 #include "content/browser/devtools/render_frame_devtools_agent_host.h" | 46 #include "content/browser/devtools/render_frame_devtools_agent_host.h" |
48 #include "content/browser/gpu/browser_gpu_channel_host_factory.h" | 47 #include "content/browser/gpu/browser_gpu_channel_host_factory.h" |
49 #include "content/browser/gpu/compositor_util.h" | 48 #include "content/browser/gpu/compositor_util.h" |
50 #include "content/browser/gpu/gpu_data_manager_impl.h" | 49 #include "content/browser/gpu/gpu_data_manager_impl.h" |
51 #include "content/browser/gpu/gpu_process_host.h" | 50 #include "content/browser/gpu/gpu_process_host.h" |
52 #include "content/browser/media/android/media_web_contents_observer_android.h" | 51 #include "content/browser/media/android/media_web_contents_observer_android.h" |
53 #include "content/browser/renderer_host/compositor_impl_android.h" | 52 #include "content/browser/renderer_host/compositor_impl_android.h" |
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
442 begin_frame_source_(nullptr), | 441 begin_frame_source_(nullptr), |
443 latest_confirmed_begin_frame_source_id_(0), | 442 latest_confirmed_begin_frame_source_id_(0), |
444 latest_confirmed_begin_frame_sequence_number_( | 443 latest_confirmed_begin_frame_sequence_number_( |
445 cc::BeginFrameArgs::kInvalidFrameNumber), | 444 cc::BeginFrameArgs::kInvalidFrameNumber), |
446 outstanding_begin_frame_requests_(0), | 445 outstanding_begin_frame_requests_(0), |
447 is_showing_(!widget_host->is_hidden()), | 446 is_showing_(!widget_host->is_hidden()), |
448 is_window_visible_(true), | 447 is_window_visible_(true), |
449 is_window_activity_started_(true), | 448 is_window_activity_started_(true), |
450 is_in_vr_(false), | 449 is_in_vr_(false), |
451 content_view_core_(nullptr), | 450 content_view_core_(nullptr), |
452 ime_adapter_android_(nullptr), | 451 ime_adapter_android_(this), |
453 background_color_(SK_ColorWHITE), | 452 background_color_(SK_ColorWHITE), |
454 cached_background_color_(SK_ColorWHITE), | 453 cached_background_color_(SK_ColorWHITE), |
455 view_(this), | 454 view_(this), |
456 gesture_provider_(ui::GetGestureProviderConfig( | 455 gesture_provider_(ui::GetGestureProviderConfig( |
457 ui::GestureProviderConfigType::CURRENT_PLATFORM), | 456 ui::GestureProviderConfigType::CURRENT_PLATFORM), |
458 this), | 457 this), |
459 stylus_text_selector_(this), | 458 stylus_text_selector_(this), |
460 using_browser_compositor_(CompositorImpl::IsInitialized()), | 459 using_browser_compositor_(CompositorImpl::IsInitialized()), |
461 synchronous_compositor_client_(nullptr), | 460 synchronous_compositor_client_(nullptr), |
462 frame_evictor_(new DelegatedFrameEvictor(this)), | 461 frame_evictor_(new DelegatedFrameEvictor(this)), |
(...skipping 26 matching lines...) Expand all Loading... |
489 CreateOverscrollControllerIfPossible(); | 488 CreateOverscrollControllerIfPossible(); |
490 | 489 |
491 if (GetTextInputManager()) | 490 if (GetTextInputManager()) |
492 GetTextInputManager()->AddObserver(this); | 491 GetTextInputManager()->AddObserver(this); |
493 } | 492 } |
494 | 493 |
495 RenderWidgetHostViewAndroid::~RenderWidgetHostViewAndroid() { | 494 RenderWidgetHostViewAndroid::~RenderWidgetHostViewAndroid() { |
496 if (content_view_core_) | 495 if (content_view_core_) |
497 content_view_core_->RemoveObserver(this); | 496 content_view_core_->RemoveObserver(this); |
498 SetContentViewCore(NULL); | 497 SetContentViewCore(NULL); |
499 if (ime_adapter_android_) | |
500 ime_adapter_android_ = nullptr; | |
501 DCHECK(ack_callbacks_.empty()); | 498 DCHECK(ack_callbacks_.empty()); |
502 DCHECK(!delegated_frame_host_); | 499 DCHECK(!delegated_frame_host_); |
503 } | 500 } |
504 | 501 |
505 void RenderWidgetHostViewAndroid::Blur() { | 502 void RenderWidgetHostViewAndroid::Blur() { |
506 host_->Blur(); | 503 host_->Blur(); |
507 if (overscroll_controller_) | 504 if (overscroll_controller_) |
508 overscroll_controller_->Disable(); | 505 overscroll_controller_->Disable(); |
509 } | 506 } |
510 | 507 |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
639 if (x_dip < 0 || x_dip > viewport_size.width() || | 636 if (x_dip < 0 || x_dip > viewport_size.width() || |
640 y_dip < 0 || y_dip > viewport_size.height()) | 637 y_dip < 0 || y_dip > viewport_size.height()) |
641 return; | 638 return; |
642 content_view_core_->OnShowUnhandledTapUIIfNeeded(x_dip, y_dip); | 639 content_view_core_->OnShowUnhandledTapUIIfNeeded(x_dip, y_dip); |
643 } | 640 } |
644 | 641 |
645 gfx::Rect RenderWidgetHostViewAndroid::GetViewBounds() const { | 642 gfx::Rect RenderWidgetHostViewAndroid::GetViewBounds() const { |
646 if (!content_view_core_) | 643 if (!content_view_core_) |
647 return default_bounds_; | 644 return default_bounds_; |
648 | 645 |
649 gfx::Size size(content_view_core_->GetViewSize()); | |
650 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 646 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
651 switches::kEnableOSKOverscroll)) { | 647 switches::kEnableOSKOverscroll)) |
652 size.Enlarge(0, view_.GetSystemWindowInsetBottom() / view_.GetDipScale()); | 648 return gfx::Rect(content_view_core_->GetViewSizeWithOSKHidden()); |
653 } | |
654 | 649 |
655 return gfx::Rect(size); | 650 return gfx::Rect(content_view_core_->GetViewSize()); |
656 } | 651 } |
657 | 652 |
658 gfx::Size RenderWidgetHostViewAndroid::GetVisibleViewportSize() const { | 653 gfx::Size RenderWidgetHostViewAndroid::GetVisibleViewportSize() const { |
659 if (!content_view_core_) | 654 if (!content_view_core_) |
660 return default_bounds_.size(); | 655 return default_bounds_.size(); |
661 | 656 |
662 return content_view_core_->GetViewSize(); | 657 return content_view_core_->GetViewSize(); |
663 } | 658 } |
664 | 659 |
665 gfx::Size RenderWidgetHostViewAndroid::GetPhysicalBackingSize() const { | 660 gfx::Size RenderWidgetHostViewAndroid::GetPhysicalBackingSize() const { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
699 | 694 |
700 void RenderWidgetHostViewAndroid::UpdateCursor(const WebCursor& cursor) { | 695 void RenderWidgetHostViewAndroid::UpdateCursor(const WebCursor& cursor) { |
701 // There are no cursors on Android. | 696 // There are no cursors on Android. |
702 } | 697 } |
703 | 698 |
704 void RenderWidgetHostViewAndroid::SetIsLoading(bool is_loading) { | 699 void RenderWidgetHostViewAndroid::SetIsLoading(bool is_loading) { |
705 // Do nothing. The UI notification is handled through ContentViewClient which | 700 // Do nothing. The UI notification is handled through ContentViewClient which |
706 // is TabContentsDelegate. | 701 // is TabContentsDelegate. |
707 } | 702 } |
708 | 703 |
| 704 long RenderWidgetHostViewAndroid::GetNativeImeAdapter() { |
| 705 return reinterpret_cast<intptr_t>(&ime_adapter_android_); |
| 706 } |
| 707 |
709 // ----------------------------------------------------------------------------- | 708 // ----------------------------------------------------------------------------- |
710 // TextInputManager::Observer implementations. | 709 // TextInputManager::Observer implementations. |
711 void RenderWidgetHostViewAndroid::OnUpdateTextInputStateCalled( | 710 void RenderWidgetHostViewAndroid::OnUpdateTextInputStateCalled( |
712 TextInputManager* text_input_manager, | 711 TextInputManager* text_input_manager, |
713 RenderWidgetHostViewBase* updated_view, | 712 RenderWidgetHostViewBase* updated_view, |
714 bool did_change_state) { | 713 bool did_change_state) { |
715 DCHECK_EQ(text_input_manager_, text_input_manager); | 714 DCHECK_EQ(text_input_manager_, text_input_manager); |
716 // If there are no active widgets, the TextInputState.type should be reported | 715 // If there are no active widgets, the TextInputState.type should be reported |
717 // as none. | 716 // as none. |
718 const TextInputState& state = | 717 const TextInputState& state = |
719 GetTextInputManager()->GetActiveWidget() | 718 GetTextInputManager()->GetActiveWidget() |
720 ? *GetTextInputManager()->GetTextInputState() | 719 ? *GetTextInputManager()->GetTextInputState() |
721 : TextInputState(); | 720 : TextInputState(); |
722 | 721 |
723 if (!ime_adapter_android_ || is_in_vr_) | 722 if (!content_view_core_ || is_in_vr_) |
724 return; | 723 return; |
725 | 724 |
726 ime_adapter_android_->UpdateState(state); | 725 content_view_core_->UpdateImeAdapter( |
| 726 GetNativeImeAdapter(), static_cast<int>(state.type), state.flags, |
| 727 state.mode, state.value, state.selection_start, state.selection_end, |
| 728 state.composition_start, state.composition_end, state.show_ime_if_needed, |
| 729 state.reply_to_request); |
727 } | 730 } |
728 | 731 |
729 void RenderWidgetHostViewAndroid::OnImeCompositionRangeChanged( | 732 void RenderWidgetHostViewAndroid::OnImeCompositionRangeChanged( |
730 TextInputManager* text_input_manager, | 733 TextInputManager* text_input_manager, |
731 RenderWidgetHostViewBase* updated_view) { | 734 RenderWidgetHostViewBase* updated_view) { |
732 DCHECK_EQ(text_input_manager_, text_input_manager); | 735 DCHECK_EQ(text_input_manager_, text_input_manager); |
733 const TextInputManager::CompositionRangeInfo* info = | 736 const TextInputManager::CompositionRangeInfo* info = |
734 text_input_manager_->GetCompositionRangeInfo(); | 737 text_input_manager_->GetCompositionRangeInfo(); |
735 if (!info) | 738 if (!info) |
736 return; | 739 return; |
737 | 740 |
738 std::vector<gfx::RectF> character_bounds; | 741 std::vector<gfx::RectF> character_bounds; |
739 for (const gfx::Rect& rect : info->character_bounds) | 742 for (const gfx::Rect& rect : info->character_bounds) |
740 character_bounds.emplace_back(rect); | 743 character_bounds.emplace_back(rect); |
741 | 744 |
742 if (ime_adapter_android_) | 745 ime_adapter_android_.SetCharacterBounds(character_bounds); |
743 ime_adapter_android_->SetCharacterBounds(character_bounds); | |
744 } | 746 } |
745 | 747 |
746 void RenderWidgetHostViewAndroid::OnImeCancelComposition( | 748 void RenderWidgetHostViewAndroid::OnImeCancelComposition( |
747 TextInputManager* text_input_manager, | 749 TextInputManager* text_input_manager, |
748 RenderWidgetHostViewBase* updated_view) { | 750 RenderWidgetHostViewBase* updated_view) { |
749 DCHECK_EQ(text_input_manager_, text_input_manager); | 751 DCHECK_EQ(text_input_manager_, text_input_manager); |
750 if (ime_adapter_android_) | 752 ime_adapter_android_.CancelComposition(); |
751 ime_adapter_android_->CancelComposition(); | |
752 } | 753 } |
753 | 754 |
754 void RenderWidgetHostViewAndroid::OnTextSelectionChanged( | 755 void RenderWidgetHostViewAndroid::OnTextSelectionChanged( |
755 TextInputManager* text_input_manager, | 756 TextInputManager* text_input_manager, |
756 RenderWidgetHostViewBase* updated_view) { | 757 RenderWidgetHostViewBase* updated_view) { |
757 DCHECK_EQ(text_input_manager_, text_input_manager); | 758 DCHECK_EQ(text_input_manager_, text_input_manager); |
758 | 759 |
759 // TODO(asimjour): remove the flag and fix text selection popup for | 760 // TODO(asimjour): remove the flag and fix text selection popup for |
760 // virtual reality mode. | 761 // virtual reality mode. |
761 if (is_in_vr_) | 762 if (is_in_vr_) |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
898 // but it is not necessary here because the final target view is responsible | 899 // but it is not necessary here because the final target view is responsible |
899 // for converting before computing the final transform. | 900 // for converting before computing the final transform. |
900 cc::SurfaceId surface_id = delegated_frame_host_->SurfaceId(); | 901 cc::SurfaceId surface_id = delegated_frame_host_->SurfaceId(); |
901 if (!surface_id.is_valid()) | 902 if (!surface_id.is_valid()) |
902 return false; | 903 return false; |
903 | 904 |
904 return target_view->TransformPointToLocalCoordSpace(point, surface_id, | 905 return target_view->TransformPointToLocalCoordSpace(point, surface_id, |
905 transformed_point); | 906 transformed_point); |
906 } | 907 } |
907 | 908 |
908 base::WeakPtr<RenderWidgetHostViewAndroid> | |
909 RenderWidgetHostViewAndroid::GetWeakPtrAndroid() { | |
910 return weak_ptr_factory_.GetWeakPtr(); | |
911 } | |
912 | |
913 bool RenderWidgetHostViewAndroid::OnTouchEvent( | 909 bool RenderWidgetHostViewAndroid::OnTouchEvent( |
914 const ui::MotionEvent& event) { | 910 const ui::MotionEvent& event) { |
915 if (!host_ || !host_->delegate()) | 911 if (!host_ || !host_->delegate()) |
916 return false; | 912 return false; |
917 | 913 |
918 ComputeEventLatencyOSTouchHistograms(event); | 914 ComputeEventLatencyOSTouchHistograms(event); |
919 | 915 |
920 // If a browser-based widget consumes the touch event, it's critical that | 916 // If a browser-based widget consumes the touch event, it's critical that |
921 // touch event interception be disabled. This avoids issues with | 917 // touch event interception be disabled. This avoids issues with |
922 // double-handling for embedder-detected gestures like side swipe. | 918 // double-handling for embedder-detected gestures like side swipe. |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
994 } | 990 } |
995 | 991 |
996 void RenderWidgetHostViewAndroid::SetMultiTouchZoomSupportEnabled( | 992 void RenderWidgetHostViewAndroid::SetMultiTouchZoomSupportEnabled( |
997 bool enabled) { | 993 bool enabled) { |
998 gesture_provider_.SetMultiTouchZoomSupportEnabled(enabled); | 994 gesture_provider_.SetMultiTouchZoomSupportEnabled(enabled); |
999 } | 995 } |
1000 | 996 |
1001 void RenderWidgetHostViewAndroid::FocusedNodeChanged( | 997 void RenderWidgetHostViewAndroid::FocusedNodeChanged( |
1002 bool is_editable_node, | 998 bool is_editable_node, |
1003 const gfx::Rect& node_bounds_in_screen) { | 999 const gfx::Rect& node_bounds_in_screen) { |
1004 if (ime_adapter_android_) | 1000 ime_adapter_android_.FocusedNodeChanged(is_editable_node); |
1005 ime_adapter_android_->FocusedNodeChanged(is_editable_node); | |
1006 } | 1001 } |
1007 | 1002 |
1008 void RenderWidgetHostViewAndroid::RenderProcessGone( | 1003 void RenderWidgetHostViewAndroid::RenderProcessGone( |
1009 base::TerminationStatus status, int error_code) { | 1004 base::TerminationStatus status, int error_code) { |
1010 Destroy(); | 1005 Destroy(); |
1011 } | 1006 } |
1012 | 1007 |
1013 void RenderWidgetHostViewAndroid::Destroy() { | 1008 void RenderWidgetHostViewAndroid::Destroy() { |
1014 host_->ViewDestroyed(); | 1009 host_->ViewDestroyed(); |
1015 SetContentViewCore(NULL); | 1010 SetContentViewCore(NULL); |
(...skipping 1165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2181 | 2176 |
2182 ui::WindowAndroidCompositor* compositor = window_android->GetCompositor(); | 2177 ui::WindowAndroidCompositor* compositor = window_android->GetCompositor(); |
2183 if (!compositor) | 2178 if (!compositor) |
2184 return; | 2179 return; |
2185 | 2180 |
2186 overscroll_controller_ = base::MakeUnique<OverscrollControllerAndroid>( | 2181 overscroll_controller_ = base::MakeUnique<OverscrollControllerAndroid>( |
2187 overscroll_refresh_handler, compositor, view_.GetDipScale()); | 2182 overscroll_refresh_handler, compositor, view_.GetDipScale()); |
2188 } | 2183 } |
2189 | 2184 |
2190 } // namespace content | 2185 } // namespace content |
OLD | NEW |