Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(85)

Side by Side Diff: content/browser/renderer_host/render_widget_host_view_android.cc

Issue 2752113005: Let ImeAdapterAndroid have the same lifecycle as its Java peer (Closed)
Patch Set: fix tests Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 23 matching lines...) Expand all
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_factory.h" 36 #include "cc/surfaces/surface_factory.h"
37 #include "cc/surfaces/surface_hittest.h" 37 #include "cc/surfaces/surface_hittest.h"
38 #include "cc/surfaces/surface_manager.h" 38 #include "cc/surfaces/surface_manager.h"
39 #include "cc/trees/layer_tree_host.h" 39 #include "cc/trees/layer_tree_host.h"
40 #include "components/display_compositor/gl_helper.h" 40 #include "components/display_compositor/gl_helper.h"
41 #include "content/browser/accessibility/browser_accessibility_manager_android.h" 41 #include "content/browser/accessibility/browser_accessibility_manager_android.h"
42 #include "content/browser/android/composited_touch_handle_drawable.h" 42 #include "content/browser/android/composited_touch_handle_drawable.h"
43 #include "content/browser/android/content_view_core_impl.h" 43 #include "content/browser/android/content_view_core_impl.h"
44 #include "content/browser/android/ime_adapter_android.h"
44 #include "content/browser/android/overscroll_controller_android.h" 45 #include "content/browser/android/overscroll_controller_android.h"
45 #include "content/browser/android/synchronous_compositor_host.h" 46 #include "content/browser/android/synchronous_compositor_host.h"
46 #include "content/browser/compositor/surface_utils.h" 47 #include "content/browser/compositor/surface_utils.h"
47 #include "content/browser/devtools/render_frame_devtools_agent_host.h" 48 #include "content/browser/devtools/render_frame_devtools_agent_host.h"
48 #include "content/browser/gpu/browser_gpu_channel_host_factory.h" 49 #include "content/browser/gpu/browser_gpu_channel_host_factory.h"
49 #include "content/browser/gpu/compositor_util.h" 50 #include "content/browser/gpu/compositor_util.h"
50 #include "content/browser/gpu/gpu_data_manager_impl.h" 51 #include "content/browser/gpu/gpu_data_manager_impl.h"
51 #include "content/browser/gpu/gpu_process_host.h" 52 #include "content/browser/gpu/gpu_process_host.h"
52 #include "content/browser/media/android/media_web_contents_observer_android.h" 53 #include "content/browser/media/android/media_web_contents_observer_android.h"
53 #include "content/browser/renderer_host/compositor_impl_android.h" 54 #include "content/browser/renderer_host/compositor_impl_android.h"
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 begin_frame_source_(nullptr), 444 begin_frame_source_(nullptr),
444 latest_confirmed_begin_frame_source_id_(0), 445 latest_confirmed_begin_frame_source_id_(0),
445 latest_confirmed_begin_frame_sequence_number_( 446 latest_confirmed_begin_frame_sequence_number_(
446 cc::BeginFrameArgs::kInvalidFrameNumber), 447 cc::BeginFrameArgs::kInvalidFrameNumber),
447 outstanding_begin_frame_requests_(0), 448 outstanding_begin_frame_requests_(0),
448 is_showing_(!widget_host->is_hidden()), 449 is_showing_(!widget_host->is_hidden()),
449 is_window_visible_(true), 450 is_window_visible_(true),
450 is_window_activity_started_(true), 451 is_window_activity_started_(true),
451 is_in_vr_(false), 452 is_in_vr_(false),
452 content_view_core_(nullptr), 453 content_view_core_(nullptr),
453 ime_adapter_android_(this), 454 ime_adapter_android_(nullptr),
454 cached_background_color_(SK_ColorWHITE), 455 cached_background_color_(SK_ColorWHITE),
455 view_(this), 456 view_(this),
456 gesture_provider_(ui::GetGestureProviderConfig( 457 gesture_provider_(ui::GetGestureProviderConfig(
457 ui::GestureProviderConfigType::CURRENT_PLATFORM), 458 ui::GestureProviderConfigType::CURRENT_PLATFORM),
458 this), 459 this),
459 stylus_text_selector_(this), 460 stylus_text_selector_(this),
460 using_browser_compositor_(CompositorImpl::IsInitialized()), 461 using_browser_compositor_(CompositorImpl::IsInitialized()),
461 synchronous_compositor_client_(nullptr), 462 synchronous_compositor_client_(nullptr),
462 frame_evictor_(new DelegatedFrameEvictor(this)), 463 frame_evictor_(new DelegatedFrameEvictor(this)),
463 observing_root_window_(false), 464 observing_root_window_(false),
(...skipping 25 matching lines...) Expand all
489 CreateOverscrollControllerIfPossible(); 490 CreateOverscrollControllerIfPossible();
490 491
491 if (GetTextInputManager()) 492 if (GetTextInputManager())
492 GetTextInputManager()->AddObserver(this); 493 GetTextInputManager()->AddObserver(this);
493 } 494 }
494 495
495 RenderWidgetHostViewAndroid::~RenderWidgetHostViewAndroid() { 496 RenderWidgetHostViewAndroid::~RenderWidgetHostViewAndroid() {
496 if (content_view_core_) 497 if (content_view_core_)
497 content_view_core_->RemoveObserver(this); 498 content_view_core_->RemoveObserver(this);
498 SetContentViewCore(NULL); 499 SetContentViewCore(NULL);
500 if (ime_adapter_android_)
501 ime_adapter_android_ = nullptr;
499 DCHECK(ack_callbacks_.empty()); 502 DCHECK(ack_callbacks_.empty());
500 DCHECK(!delegated_frame_host_); 503 DCHECK(!delegated_frame_host_);
501 } 504 }
502 505
503 void RenderWidgetHostViewAndroid::Blur() { 506 void RenderWidgetHostViewAndroid::Blur() {
504 host_->Blur(); 507 host_->Blur();
505 if (overscroll_controller_) 508 if (overscroll_controller_)
506 overscroll_controller_->Disable(); 509 overscroll_controller_->Disable();
507 } 510 }
508 511
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
696 699
697 void RenderWidgetHostViewAndroid::UpdateCursor(const WebCursor& cursor) { 700 void RenderWidgetHostViewAndroid::UpdateCursor(const WebCursor& cursor) {
698 // There are no cursors on Android. 701 // There are no cursors on Android.
699 } 702 }
700 703
701 void RenderWidgetHostViewAndroid::SetIsLoading(bool is_loading) { 704 void RenderWidgetHostViewAndroid::SetIsLoading(bool is_loading) {
702 // Do nothing. The UI notification is handled through ContentViewClient which 705 // Do nothing. The UI notification is handled through ContentViewClient which
703 // is TabContentsDelegate. 706 // is TabContentsDelegate.
704 } 707 }
705 708
706 long RenderWidgetHostViewAndroid::GetNativeImeAdapter() {
707 return reinterpret_cast<intptr_t>(&ime_adapter_android_);
708 }
709
710 // ----------------------------------------------------------------------------- 709 // -----------------------------------------------------------------------------
711 // TextInputManager::Observer implementations. 710 // TextInputManager::Observer implementations.
712 void RenderWidgetHostViewAndroid::OnUpdateTextInputStateCalled( 711 void RenderWidgetHostViewAndroid::OnUpdateTextInputStateCalled(
713 TextInputManager* text_input_manager, 712 TextInputManager* text_input_manager,
714 RenderWidgetHostViewBase* updated_view, 713 RenderWidgetHostViewBase* updated_view,
715 bool did_change_state) { 714 bool did_change_state) {
716 DCHECK_EQ(text_input_manager_, text_input_manager); 715 DCHECK_EQ(text_input_manager_, text_input_manager);
717 // If there are no active widgets, the TextInputState.type should be reported 716 // If there are no active widgets, the TextInputState.type should be reported
718 // as none. 717 // as none.
719 const TextInputState& state = 718 const TextInputState& state =
720 GetTextInputManager()->GetActiveWidget() 719 GetTextInputManager()->GetActiveWidget()
721 ? *GetTextInputManager()->GetTextInputState() 720 ? *GetTextInputManager()->GetTextInputState()
722 : TextInputState(); 721 : TextInputState();
723 722
724 if (!content_view_core_ || is_in_vr_) 723 if (!content_view_core_ || is_in_vr_)
725 return; 724 return;
726 725
727 content_view_core_->UpdateImeAdapter( 726 content_view_core_->UpdateImeAdapter(
728 GetNativeImeAdapter(), static_cast<int>(state.type), state.flags, 727 static_cast<int>(state.type), state.flags, state.mode, state.value,
729 state.mode, state.value, state.selection_start, state.selection_end, 728 state.selection_start, state.selection_end, state.composition_start,
730 state.composition_start, state.composition_end, state.show_ime_if_needed, 729 state.composition_end, state.show_ime_if_needed, state.reply_to_request);
731 state.reply_to_request);
732 } 730 }
733 731
734 void RenderWidgetHostViewAndroid::OnImeCompositionRangeChanged( 732 void RenderWidgetHostViewAndroid::OnImeCompositionRangeChanged(
735 TextInputManager* text_input_manager, 733 TextInputManager* text_input_manager,
736 RenderWidgetHostViewBase* updated_view) { 734 RenderWidgetHostViewBase* updated_view) {
737 DCHECK_EQ(text_input_manager_, text_input_manager); 735 DCHECK_EQ(text_input_manager_, text_input_manager);
738 const TextInputManager::CompositionRangeInfo* info = 736 const TextInputManager::CompositionRangeInfo* info =
739 text_input_manager_->GetCompositionRangeInfo(); 737 text_input_manager_->GetCompositionRangeInfo();
740 if (!info) 738 if (!info)
741 return; 739 return;
742 740
743 std::vector<gfx::RectF> character_bounds; 741 std::vector<gfx::RectF> character_bounds;
744 for (const gfx::Rect& rect : info->character_bounds) 742 for (const gfx::Rect& rect : info->character_bounds)
745 character_bounds.emplace_back(rect); 743 character_bounds.emplace_back(rect);
746 744
747 ime_adapter_android_.SetCharacterBounds(character_bounds); 745 if (ime_adapter_android_)
746 ime_adapter_android_->SetCharacterBounds(character_bounds);
748 } 747 }
749 748
750 void RenderWidgetHostViewAndroid::OnImeCancelComposition( 749 void RenderWidgetHostViewAndroid::OnImeCancelComposition(
751 TextInputManager* text_input_manager, 750 TextInputManager* text_input_manager,
752 RenderWidgetHostViewBase* updated_view) { 751 RenderWidgetHostViewBase* updated_view) {
753 DCHECK_EQ(text_input_manager_, text_input_manager); 752 DCHECK_EQ(text_input_manager_, text_input_manager);
754 ime_adapter_android_.CancelComposition(); 753 if (ime_adapter_android_)
754 ime_adapter_android_->CancelComposition();
755 } 755 }
756 756
757 void RenderWidgetHostViewAndroid::OnTextSelectionChanged( 757 void RenderWidgetHostViewAndroid::OnTextSelectionChanged(
758 TextInputManager* text_input_manager, 758 TextInputManager* text_input_manager,
759 RenderWidgetHostViewBase* updated_view) { 759 RenderWidgetHostViewBase* updated_view) {
760 DCHECK_EQ(text_input_manager_, text_input_manager); 760 DCHECK_EQ(text_input_manager_, text_input_manager);
761 761
762 // TODO(asimjour): remove the flag and fix text selection popup for 762 // TODO(asimjour): remove the flag and fix text selection popup for
763 // virtual reality mode. 763 // virtual reality mode.
764 if (is_in_vr_) 764 if (is_in_vr_)
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
901 // but it is not necessary here because the final target view is responsible 901 // but it is not necessary here because the final target view is responsible
902 // for converting before computing the final transform. 902 // for converting before computing the final transform.
903 cc::SurfaceId surface_id = delegated_frame_host_->SurfaceId(); 903 cc::SurfaceId surface_id = delegated_frame_host_->SurfaceId();
904 if (!surface_id.is_valid()) 904 if (!surface_id.is_valid())
905 return false; 905 return false;
906 906
907 return target_view->TransformPointToLocalCoordSpace(point, surface_id, 907 return target_view->TransformPointToLocalCoordSpace(point, surface_id,
908 transformed_point); 908 transformed_point);
909 } 909 }
910 910
911 base::WeakPtr<RenderWidgetHostViewAndroid>
912 RenderWidgetHostViewAndroid::GetWeakPtrAndroid() {
913 return weak_ptr_factory_.GetWeakPtr();
914 }
915
911 void RenderWidgetHostViewAndroid::OnStartContentIntent( 916 void RenderWidgetHostViewAndroid::OnStartContentIntent(
912 const GURL& content_url, bool is_main_frame) { 917 const GURL& content_url, bool is_main_frame) {
913 view_.StartContentIntent(content_url, is_main_frame); 918 view_.StartContentIntent(content_url, is_main_frame);
914 } 919 }
915 920
916 bool RenderWidgetHostViewAndroid::OnTouchEvent( 921 bool RenderWidgetHostViewAndroid::OnTouchEvent(
917 const ui::MotionEvent& event) { 922 const ui::MotionEvent& event) {
918 if (!host_ || !host_->delegate()) 923 if (!host_ || !host_->delegate())
919 return false; 924 return false;
920 925
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
997 } 1002 }
998 1003
999 void RenderWidgetHostViewAndroid::SetMultiTouchZoomSupportEnabled( 1004 void RenderWidgetHostViewAndroid::SetMultiTouchZoomSupportEnabled(
1000 bool enabled) { 1005 bool enabled) {
1001 gesture_provider_.SetMultiTouchZoomSupportEnabled(enabled); 1006 gesture_provider_.SetMultiTouchZoomSupportEnabled(enabled);
1002 } 1007 }
1003 1008
1004 void RenderWidgetHostViewAndroid::FocusedNodeChanged( 1009 void RenderWidgetHostViewAndroid::FocusedNodeChanged(
1005 bool is_editable_node, 1010 bool is_editable_node,
1006 const gfx::Rect& node_bounds_in_screen) { 1011 const gfx::Rect& node_bounds_in_screen) {
1007 ime_adapter_android_.FocusedNodeChanged(is_editable_node); 1012 if (ime_adapter_android_)
1013 ime_adapter_android_->FocusedNodeChanged(is_editable_node);
1008 } 1014 }
1009 1015
1010 void RenderWidgetHostViewAndroid::RenderProcessGone( 1016 void RenderWidgetHostViewAndroid::RenderProcessGone(
1011 base::TerminationStatus status, int error_code) { 1017 base::TerminationStatus status, int error_code) {
1012 Destroy(); 1018 Destroy();
1013 } 1019 }
1014 1020
1015 void RenderWidgetHostViewAndroid::Destroy() { 1021 void RenderWidgetHostViewAndroid::Destroy() {
1016 host_->ViewDestroyed(); 1022 host_->ViewDestroyed();
1017 SetContentViewCore(NULL); 1023 SetContentViewCore(NULL);
(...skipping 1151 matching lines...) Expand 10 before | Expand all | Expand 10 after
2169 2175
2170 ui::WindowAndroidCompositor* compositor = window_android->GetCompositor(); 2176 ui::WindowAndroidCompositor* compositor = window_android->GetCompositor();
2171 if (!compositor) 2177 if (!compositor)
2172 return; 2178 return;
2173 2179
2174 overscroll_controller_ = base::MakeUnique<OverscrollControllerAndroid>( 2180 overscroll_controller_ = base::MakeUnique<OverscrollControllerAndroid>(
2175 overscroll_refresh_handler, compositor, view_.GetDipScale()); 2181 overscroll_refresh_handler, compositor, view_.GetDipScale());
2176 } 2182 }
2177 2183
2178 } // namespace content 2184 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_widget_host_view_android.h ('k') | content/browser/site_per_process_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698