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

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

Issue 643193003: Support InputMethodManager#updateCursorAnchorInfo for Android 5.0 (C++ version) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Send ImeCompositionRangeChanged only when necessary Created 5 years, 10 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 "base/android/build_info.h" 9 #include "base/android/build_info.h"
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 #include "content/public/common/content_switches.h" 65 #include "content/public/common/content_switches.h"
66 #include "gpu/command_buffer/client/gles2_implementation.h" 66 #include "gpu/command_buffer/client/gles2_implementation.h"
67 #include "gpu/command_buffer/client/gles2_interface.h" 67 #include "gpu/command_buffer/client/gles2_interface.h"
68 #include "gpu/config/gpu_driver_bug_workaround_type.h" 68 #include "gpu/config/gpu_driver_bug_workaround_type.h"
69 #include "skia/ext/image_operations.h" 69 #include "skia/ext/image_operations.h"
70 #include "third_party/khronos/GLES2/gl2.h" 70 #include "third_party/khronos/GLES2/gl2.h"
71 #include "third_party/khronos/GLES2/gl2ext.h" 71 #include "third_party/khronos/GLES2/gl2ext.h"
72 #include "third_party/skia/include/core/SkCanvas.h" 72 #include "third_party/skia/include/core/SkCanvas.h"
73 #include "ui/base/android/window_android.h" 73 #include "ui/base/android/window_android.h"
74 #include "ui/base/android/window_android_compositor.h" 74 #include "ui/base/android/window_android_compositor.h"
75 #include "ui/base/ime/android/cursor_anchor_info_builder.h"
76 #include "ui/base/ime/android/cursor_anchor_info_controller.h"
75 #include "ui/events/gesture_detection/gesture_provider_config_helper.h" 77 #include "ui/events/gesture_detection/gesture_provider_config_helper.h"
76 #include "ui/events/gesture_detection/motion_event.h" 78 #include "ui/events/gesture_detection/motion_event.h"
77 #include "ui/gfx/android/device_display_info.h" 79 #include "ui/gfx/android/device_display_info.h"
78 #include "ui/gfx/android/java_bitmap.h" 80 #include "ui/gfx/android/java_bitmap.h"
79 #include "ui/gfx/android/view_configuration.h" 81 #include "ui/gfx/android/view_configuration.h"
80 #include "ui/gfx/display.h" 82 #include "ui/gfx/display.h"
81 #include "ui/gfx/geometry/dip_util.h" 83 #include "ui/gfx/geometry/dip_util.h"
82 #include "ui/gfx/geometry/size_conversions.h" 84 #include "ui/gfx/geometry/size_conversions.h"
83 #include "ui/gfx/screen.h" 85 #include "ui/gfx/screen.h"
84 #include "ui/touch_selection/touch_selection_controller.h" 86 #include "ui/touch_selection/touch_selection_controller.h"
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 } 328 }
327 329
328 RenderWidgetHostViewAndroid::RenderWidgetHostViewAndroid( 330 RenderWidgetHostViewAndroid::RenderWidgetHostViewAndroid(
329 RenderWidgetHostImpl* widget_host, 331 RenderWidgetHostImpl* widget_host,
330 ContentViewCoreImpl* content_view_core) 332 ContentViewCoreImpl* content_view_core)
331 : host_(widget_host), 333 : host_(widget_host),
332 outstanding_vsync_requests_(0), 334 outstanding_vsync_requests_(0),
333 is_showing_(!widget_host->is_hidden()), 335 is_showing_(!widget_host->is_hidden()),
334 content_view_core_(NULL), 336 content_view_core_(NULL),
335 ime_adapter_android_(this), 337 ime_adapter_android_(this),
338 cursor_anchor_info_controller_(
339 ui::CursorAnchorInfoController::Create(this)),
336 cached_background_color_(SK_ColorWHITE), 340 cached_background_color_(SK_ColorWHITE),
337 last_output_surface_id_(kUndefinedOutputSurfaceId), 341 last_output_surface_id_(kUndefinedOutputSurfaceId),
338 gesture_provider_(CreateGestureProviderConfig(), this), 342 gesture_provider_(CreateGestureProviderConfig(), this),
339 stylus_text_selector_(this), 343 stylus_text_selector_(this),
340 accelerated_surface_route_id_(0), 344 accelerated_surface_route_id_(0),
341 using_browser_compositor_(CompositorImpl::IsInitialized()), 345 using_browser_compositor_(CompositorImpl::IsInitialized()),
342 frame_evictor_(new DelegatedFrameEvictor(this)), 346 frame_evictor_(new DelegatedFrameEvictor(this)),
343 locks_on_frame_count_(0), 347 locks_on_frame_count_(0),
344 observing_root_window_(false), 348 observing_root_window_(false),
345 weak_ptr_factory_(this) { 349 weak_ptr_factory_(this) {
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after
701 ui::TextInputMode input_mode, 705 ui::TextInputMode input_mode,
702 bool can_compose_inline, 706 bool can_compose_inline,
703 int flags) { 707 int flags) {
704 // Unused on Android, which uses OnTextInputChanged instead. 708 // Unused on Android, which uses OnTextInputChanged instead.
705 } 709 }
706 710
707 long RenderWidgetHostViewAndroid::GetNativeImeAdapter() { 711 long RenderWidgetHostViewAndroid::GetNativeImeAdapter() {
708 return reinterpret_cast<intptr_t>(&ime_adapter_android_); 712 return reinterpret_cast<intptr_t>(&ime_adapter_android_);
709 } 713 }
710 714
715 bool RenderWidgetHostViewAndroid::RequestCursorUpdates(
716 uint32 cursor_update_mode) {
717 if (!cursor_anchor_info_controller_)
718 return false;
719
720 return cursor_anchor_info_controller_->OnRequestCursorUpdates(
721 cursor_update_mode);
722 }
723
711 void RenderWidgetHostViewAndroid::OnTextInputStateChanged( 724 void RenderWidgetHostViewAndroid::OnTextInputStateChanged(
712 const ViewHostMsg_TextInputState_Params& params) { 725 const ViewHostMsg_TextInputState_Params& params) {
713 if (selection_controller_) { 726 if (selection_controller_) {
714 // This call is semi-redundant with that in |OnFocusedNodeChanged|. The 727 // This call is semi-redundant with that in |OnFocusedNodeChanged|. The
715 // latter is guaranteed to be called before |OnSelectionBoundsChanged|, 728 // latter is guaranteed to be called before |OnSelectionBoundsChanged|,
716 // while this call is present to ensure consistency with IME after 729 // while this call is present to ensure consistency with IME after
717 // navigation and tab focus changes 730 // navigation and tab focus changes
718 const bool is_editable_node = params.type != ui::TEXT_INPUT_TYPE_NONE; 731 const bool is_editable_node = params.type != ui::TEXT_INPUT_TYPE_NONE;
719 selection_controller_->OnSelectionEditable(is_editable_node); 732 selection_controller_->OnSelectionEditable(is_editable_node);
720 } 733 }
721 734
722 // If the change is not originated from IME (e.g. Javascript, autofill), 735 // If the change is not originated from IME (e.g. Javascript, autofill),
723 // send back the renderer an acknowledgement, regardless of how we exit from 736 // send back the renderer an acknowledgement, regardless of how we exit from
724 // this method. 737 // this method.
725 base::ScopedClosureRunner ack_caller; 738 base::ScopedClosureRunner ack_caller;
726 if (params.is_non_ime_change) 739 if (params.is_non_ime_change)
727 ack_caller.Reset(base::Bind(&SendImeEventAck, host_)); 740 ack_caller.Reset(base::Bind(&SendImeEventAck, host_));
728 741
729 if (!IsShowing()) 742 if (!IsShowing())
730 return; 743 return;
731 744
732 content_view_core_->UpdateImeAdapter( 745 content_view_core_->UpdateImeAdapter(
733 GetNativeImeAdapter(), 746 GetNativeImeAdapter(),
734 static_cast<int>(params.type), params.flags, 747 static_cast<int>(params.type), params.flags,
735 params.value, params.selection_start, params.selection_end, 748 params.value, params.selection_start, params.selection_end,
736 params.composition_start, params.composition_end, 749 params.composition_start, params.composition_end,
737 params.show_ime_if_needed, params.is_non_ime_change); 750 params.show_ime_if_needed, params.is_non_ime_change);
751
752 if (cursor_anchor_info_controller_) {
753 cursor_anchor_info_controller_->OnTextInputStateChanged(
754 base::UTF8ToUTF16(params.value),
755 gfx::Range(params.selection_start, params.selection_end),
756 gfx::Range(params.composition_start, params.composition_end));
757 }
738 } 758 }
739 759
740 void RenderWidgetHostViewAndroid::OnDidChangeBodyBackgroundColor( 760 void RenderWidgetHostViewAndroid::OnDidChangeBodyBackgroundColor(
741 SkColor color) { 761 SkColor color) {
742 if (cached_background_color_ == color) 762 if (cached_background_color_ == color)
743 return; 763 return;
744 764
745 cached_background_color_ = color; 765 cached_background_color_ = color;
746 if (content_view_core_) 766 if (content_view_core_)
747 content_view_core_->OnBackgroundColorChanged(color); 767 content_view_core_->OnBackgroundColorChanged(color);
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
833 gesture_provider_.SetMultiTouchZoomSupportEnabled(enabled); 853 gesture_provider_.SetMultiTouchZoomSupportEnabled(enabled);
834 } 854 }
835 855
836 void RenderWidgetHostViewAndroid::ImeCancelComposition() { 856 void RenderWidgetHostViewAndroid::ImeCancelComposition() {
837 ime_adapter_android_.CancelComposition(); 857 ime_adapter_android_.CancelComposition();
838 } 858 }
839 859
840 void RenderWidgetHostViewAndroid::ImeCompositionRangeChanged( 860 void RenderWidgetHostViewAndroid::ImeCompositionRangeChanged(
841 const gfx::Range& range, 861 const gfx::Range& range,
842 const std::vector<gfx::Rect>& character_bounds) { 862 const std::vector<gfx::Rect>& character_bounds) {
843 // TODO(yukawa): Implement this. 863 if (cursor_anchor_info_controller_) {
864 cursor_anchor_info_controller_->OnCompositionRangeChanged(range,
865 character_bounds);
866 }
844 } 867 }
845 868
846 void RenderWidgetHostViewAndroid::FocusedNodeChanged(bool is_editable_node) { 869 void RenderWidgetHostViewAndroid::FocusedNodeChanged(bool is_editable_node) {
847 ime_adapter_android_.FocusedNodeChanged(is_editable_node); 870 ime_adapter_android_.FocusedNodeChanged(is_editable_node);
871 if (cursor_anchor_info_controller_)
872 cursor_anchor_info_controller_->OnFocusedNodeChanged(is_editable_node);
848 if (selection_controller_) 873 if (selection_controller_)
849 selection_controller_->OnSelectionEditable(is_editable_node); 874 selection_controller_->OnSelectionEditable(is_editable_node);
850 } 875 }
851 876
852 void RenderWidgetHostViewAndroid::RenderProcessGone( 877 void RenderWidgetHostViewAndroid::RenderProcessGone(
853 base::TerminationStatus status, int error_code) { 878 base::TerminationStatus status, int error_code) {
854 Destroy(); 879 Destroy();
855 } 880 }
856 881
857 void RenderWidgetHostViewAndroid::Destroy() { 882 void RenderWidgetHostViewAndroid::Destroy() {
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
1015 host_->Send(new ViewMsg_ReclaimCompositorResources(host_->GetRoutingID(), 1040 host_->Send(new ViewMsg_ReclaimCompositorResources(host_->GetRoutingID(),
1016 output_surface_id, ack)); 1041 output_surface_id, ack));
1017 } 1042 }
1018 1043
1019 void RenderWidgetHostViewAndroid::UnusedResourcesAreAvailable() { 1044 void RenderWidgetHostViewAndroid::UnusedResourcesAreAvailable() {
1020 if (ack_callbacks_.size()) 1045 if (ack_callbacks_.size())
1021 return; 1046 return;
1022 SendReturnedDelegatedResources(last_output_surface_id_); 1047 SendReturnedDelegatedResources(last_output_surface_id_);
1023 } 1048 }
1024 1049
1050 void RenderWidgetHostViewAndroid::SendCursorAnchorInfo(
1051 ui::CursorAnchorInfoBuilder* builder) {
1052 ime_adapter_android_.UpdateCursorAnchorInfo(builder->Build());
1053 }
1054
1025 void RenderWidgetHostViewAndroid::DestroyDelegatedContent() { 1055 void RenderWidgetHostViewAndroid::DestroyDelegatedContent() {
1026 RemoveLayers(); 1056 RemoveLayers();
1027 frame_provider_ = NULL; 1057 frame_provider_ = NULL;
1028 layer_ = NULL; 1058 layer_ = NULL;
1029 // This gets called when ever any eviction, loosing resources, swapping 1059 // This gets called when ever any eviction, loosing resources, swapping
1030 // problems are encountered and so we abort any pending readbacks here. 1060 // problems are encountered and so we abort any pending readbacks here.
1031 AbortPendingReadbackRequests(); 1061 AbortPendingReadbackRequests();
1032 } 1062 }
1033 1063
1034 void RenderWidgetHostViewAndroid::SwapDelegatedFrame( 1064 void RenderWidgetHostViewAndroid::SwapDelegatedFrame(
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
1339 #if defined(VIDEO_HOLE) 1369 #if defined(VIDEO_HOLE)
1340 if (host_ && host_->IsRenderView()) { 1370 if (host_ && host_->IsRenderView()) {
1341 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>( 1371 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(
1342 RenderViewHost::From(host_)); 1372 RenderViewHost::From(host_));
1343 WebContentsImpl* web_contents_impl = 1373 WebContentsImpl* web_contents_impl =
1344 static_cast<WebContentsImpl*>(WebContents::FromRenderViewHost(rvhi)); 1374 static_cast<WebContentsImpl*>(WebContents::FromRenderViewHost(rvhi));
1345 if (web_contents_impl) 1375 if (web_contents_impl)
1346 web_contents_impl->media_web_contents_observer()->OnFrameInfoUpdated(); 1376 web_contents_impl->media_web_contents_observer()->OnFrameInfoUpdated();
1347 } 1377 }
1348 #endif // defined(VIDEO_HOLE) 1378 #endif // defined(VIDEO_HOLE)
1379
1380 if (cursor_anchor_info_controller_) {
1381 cursor_anchor_info_controller_->OnFrameMetadataUpdated(
1382 frame_metadata, content_view_core_->GetLocationOnScreen());
1383 }
1349 } 1384 }
1350 1385
1351 void RenderWidgetHostViewAndroid::AcceleratedSurfaceInitialized(int route_id) { 1386 void RenderWidgetHostViewAndroid::AcceleratedSurfaceInitialized(int route_id) {
1352 // TODO: remove need for the surface id here 1387 // TODO: remove need for the surface id here
1353 accelerated_surface_route_id_ = route_id; 1388 accelerated_surface_route_id_ = route_id;
1354 } 1389 }
1355 1390
1356 void RenderWidgetHostViewAndroid::AttachLayers() { 1391 void RenderWidgetHostViewAndroid::AttachLayers() {
1357 if (!content_view_core_) 1392 if (!content_view_core_)
1358 return; 1393 return;
(...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after
1912 results->orientationAngle = display.RotationAsDegree(); 1947 results->orientationAngle = display.RotationAsDegree();
1913 results->orientationType = 1948 results->orientationType =
1914 RenderWidgetHostViewBase::GetOrientationTypeForMobile(display); 1949 RenderWidgetHostViewBase::GetOrientationTypeForMobile(display);
1915 gfx::DeviceDisplayInfo info; 1950 gfx::DeviceDisplayInfo info;
1916 results->depth = info.GetBitsPerPixel(); 1951 results->depth = info.GetBitsPerPixel();
1917 results->depthPerComponent = info.GetBitsPerComponent(); 1952 results->depthPerComponent = info.GetBitsPerComponent();
1918 results->isMonochrome = (results->depthPerComponent == 0); 1953 results->isMonochrome = (results->depthPerComponent == 0);
1919 } 1954 }
1920 1955
1921 } // namespace content 1956 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698