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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 #include "content/public/common/content_switches.h" | 64 #include "content/public/common/content_switches.h" |
65 #include "gpu/command_buffer/client/gles2_implementation.h" | 65 #include "gpu/command_buffer/client/gles2_implementation.h" |
66 #include "gpu/command_buffer/client/gles2_interface.h" | 66 #include "gpu/command_buffer/client/gles2_interface.h" |
67 #include "gpu/config/gpu_driver_bug_workaround_type.h" | 67 #include "gpu/config/gpu_driver_bug_workaround_type.h" |
68 #include "skia/ext/image_operations.h" | 68 #include "skia/ext/image_operations.h" |
69 #include "third_party/khronos/GLES2/gl2.h" | 69 #include "third_party/khronos/GLES2/gl2.h" |
70 #include "third_party/khronos/GLES2/gl2ext.h" | 70 #include "third_party/khronos/GLES2/gl2ext.h" |
71 #include "third_party/skia/include/core/SkCanvas.h" | 71 #include "third_party/skia/include/core/SkCanvas.h" |
72 #include "ui/base/android/window_android.h" | 72 #include "ui/base/android/window_android.h" |
73 #include "ui/base/android/window_android_compositor.h" | 73 #include "ui/base/android/window_android_compositor.h" |
| 74 #include "ui/base/ime/android/cursor_anchor_info_builder.h" |
| 75 #include "ui/base/ime/android/cursor_anchor_info_controller.h" |
74 #include "ui/events/gesture_detection/gesture_provider_config_helper.h" | 76 #include "ui/events/gesture_detection/gesture_provider_config_helper.h" |
75 #include "ui/events/gesture_detection/motion_event.h" | 77 #include "ui/events/gesture_detection/motion_event.h" |
76 #include "ui/gfx/android/device_display_info.h" | 78 #include "ui/gfx/android/device_display_info.h" |
77 #include "ui/gfx/android/java_bitmap.h" | 79 #include "ui/gfx/android/java_bitmap.h" |
78 #include "ui/gfx/android/view_configuration.h" | 80 #include "ui/gfx/android/view_configuration.h" |
79 #include "ui/gfx/display.h" | 81 #include "ui/gfx/display.h" |
80 #include "ui/gfx/geometry/dip_util.h" | 82 #include "ui/gfx/geometry/dip_util.h" |
81 #include "ui/gfx/geometry/size_conversions.h" | 83 #include "ui/gfx/geometry/size_conversions.h" |
82 #include "ui/gfx/screen.h" | 84 #include "ui/gfx/screen.h" |
83 #include "ui/touch_selection/touch_selection_controller.h" | 85 #include "ui/touch_selection/touch_selection_controller.h" |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 } | 345 } |
344 | 346 |
345 RenderWidgetHostViewAndroid::RenderWidgetHostViewAndroid( | 347 RenderWidgetHostViewAndroid::RenderWidgetHostViewAndroid( |
346 RenderWidgetHostImpl* widget_host, | 348 RenderWidgetHostImpl* widget_host, |
347 ContentViewCoreImpl* content_view_core) | 349 ContentViewCoreImpl* content_view_core) |
348 : host_(widget_host), | 350 : host_(widget_host), |
349 outstanding_vsync_requests_(0), | 351 outstanding_vsync_requests_(0), |
350 is_showing_(!widget_host->is_hidden()), | 352 is_showing_(!widget_host->is_hidden()), |
351 content_view_core_(NULL), | 353 content_view_core_(NULL), |
352 ime_adapter_android_(this), | 354 ime_adapter_android_(this), |
| 355 cursor_anchor_info_controller_( |
| 356 ui::CursorAnchorInfoController::Create(this)), |
353 cached_background_color_(SK_ColorWHITE), | 357 cached_background_color_(SK_ColorWHITE), |
354 last_output_surface_id_(kUndefinedOutputSurfaceId), | 358 last_output_surface_id_(kUndefinedOutputSurfaceId), |
355 gesture_provider_(CreateGestureProviderConfig(), this), | 359 gesture_provider_(CreateGestureProviderConfig(), this), |
356 stylus_text_selector_(this), | 360 stylus_text_selector_(this), |
357 accelerated_surface_route_id_(0), | 361 accelerated_surface_route_id_(0), |
358 using_browser_compositor_(CompositorImpl::IsInitialized()), | 362 using_browser_compositor_(CompositorImpl::IsInitialized()), |
359 frame_evictor_(new DelegatedFrameEvictor(this)), | 363 frame_evictor_(new DelegatedFrameEvictor(this)), |
360 locks_on_frame_count_(0), | 364 locks_on_frame_count_(0), |
361 observing_root_window_(false), | 365 observing_root_window_(false), |
362 weak_ptr_factory_(this) { | 366 weak_ptr_factory_(this) { |
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
710 ui::TextInputMode input_mode, | 714 ui::TextInputMode input_mode, |
711 bool can_compose_inline, | 715 bool can_compose_inline, |
712 int flags) { | 716 int flags) { |
713 // Unused on Android, which uses OnTextInputChanged instead. | 717 // Unused on Android, which uses OnTextInputChanged instead. |
714 } | 718 } |
715 | 719 |
716 long RenderWidgetHostViewAndroid::GetNativeImeAdapter() { | 720 long RenderWidgetHostViewAndroid::GetNativeImeAdapter() { |
717 return reinterpret_cast<intptr_t>(&ime_adapter_android_); | 721 return reinterpret_cast<intptr_t>(&ime_adapter_android_); |
718 } | 722 } |
719 | 723 |
| 724 bool RenderWidgetHostViewAndroid::RequestCursorUpdates( |
| 725 uint32 cursor_update_mode) { |
| 726 if (!cursor_anchor_info_controller_) |
| 727 return false; |
| 728 |
| 729 return cursor_anchor_info_controller_->OnRequestCursorUpdates( |
| 730 cursor_update_mode); |
| 731 } |
| 732 |
720 void RenderWidgetHostViewAndroid::OnTextInputStateChanged( | 733 void RenderWidgetHostViewAndroid::OnTextInputStateChanged( |
721 const ViewHostMsg_TextInputState_Params& params) { | 734 const ViewHostMsg_TextInputState_Params& params) { |
722 if (selection_controller_) { | 735 if (selection_controller_) { |
723 // This call is semi-redundant with that in |OnFocusedNodeChanged|. The | 736 // This call is semi-redundant with that in |OnFocusedNodeChanged|. The |
724 // latter is guaranteed to be called before |OnSelectionBoundsChanged|, | 737 // latter is guaranteed to be called before |OnSelectionBoundsChanged|, |
725 // while this call is present to ensure consistency with IME after | 738 // while this call is present to ensure consistency with IME after |
726 // navigation and tab focus changes | 739 // navigation and tab focus changes |
727 const bool is_editable_node = params.type != ui::TEXT_INPUT_TYPE_NONE; | 740 const bool is_editable_node = params.type != ui::TEXT_INPUT_TYPE_NONE; |
728 selection_controller_->OnSelectionEditable(is_editable_node); | 741 selection_controller_->OnSelectionEditable(is_editable_node); |
729 } | 742 } |
730 | 743 |
731 // If the change is not originated from IME (e.g. Javascript, autofill), | 744 // If the change is not originated from IME (e.g. Javascript, autofill), |
732 // send back the renderer an acknowledgement, regardless of how we exit from | 745 // send back the renderer an acknowledgement, regardless of how we exit from |
733 // this method. | 746 // this method. |
734 base::ScopedClosureRunner ack_caller; | 747 base::ScopedClosureRunner ack_caller; |
735 if (params.is_non_ime_change) | 748 if (params.is_non_ime_change) |
736 ack_caller.Reset(base::Bind(&SendImeEventAck, host_)); | 749 ack_caller.Reset(base::Bind(&SendImeEventAck, host_)); |
737 | 750 |
738 if (!IsShowing()) | 751 if (!IsShowing()) |
739 return; | 752 return; |
740 | 753 |
741 content_view_core_->UpdateImeAdapter( | 754 content_view_core_->UpdateImeAdapter( |
742 GetNativeImeAdapter(), | 755 GetNativeImeAdapter(), |
743 static_cast<int>(params.type), params.flags, | 756 static_cast<int>(params.type), params.flags, |
744 params.value, params.selection_start, params.selection_end, | 757 params.value, params.selection_start, params.selection_end, |
745 params.composition_start, params.composition_end, | 758 params.composition_start, params.composition_end, |
746 params.show_ime_if_needed, params.is_non_ime_change); | 759 params.show_ime_if_needed, params.is_non_ime_change); |
| 760 |
| 761 if (cursor_anchor_info_controller_) { |
| 762 cursor_anchor_info_controller_->OnTextInputStateChanged( |
| 763 base::UTF8ToUTF16(params.value), |
| 764 gfx::Range(params.selection_start, params.selection_end), |
| 765 gfx::Range(params.composition_start, params.composition_end)); |
| 766 } |
747 } | 767 } |
748 | 768 |
749 void RenderWidgetHostViewAndroid::OnDidChangeBodyBackgroundColor( | 769 void RenderWidgetHostViewAndroid::OnDidChangeBodyBackgroundColor( |
750 SkColor color) { | 770 SkColor color) { |
751 if (cached_background_color_ == color) | 771 if (cached_background_color_ == color) |
752 return; | 772 return; |
753 | 773 |
754 cached_background_color_ = color; | 774 cached_background_color_ = color; |
755 if (content_view_core_) | 775 if (content_view_core_) |
756 content_view_core_->OnBackgroundColorChanged(color); | 776 content_view_core_->OnBackgroundColorChanged(color); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
842 gesture_provider_.SetMultiTouchZoomSupportEnabled(enabled); | 862 gesture_provider_.SetMultiTouchZoomSupportEnabled(enabled); |
843 } | 863 } |
844 | 864 |
845 void RenderWidgetHostViewAndroid::ImeCancelComposition() { | 865 void RenderWidgetHostViewAndroid::ImeCancelComposition() { |
846 ime_adapter_android_.CancelComposition(); | 866 ime_adapter_android_.CancelComposition(); |
847 } | 867 } |
848 | 868 |
849 void RenderWidgetHostViewAndroid::ImeCompositionRangeChanged( | 869 void RenderWidgetHostViewAndroid::ImeCompositionRangeChanged( |
850 const gfx::Range& range, | 870 const gfx::Range& range, |
851 const std::vector<gfx::Rect>& character_bounds) { | 871 const std::vector<gfx::Rect>& character_bounds) { |
852 // TODO(yukawa): Implement this. | 872 if (cursor_anchor_info_controller_) { |
| 873 cursor_anchor_info_controller_->OnCompositionRangeChanged(range, |
| 874 character_bounds); |
| 875 } |
853 } | 876 } |
854 | 877 |
855 void RenderWidgetHostViewAndroid::FocusedNodeChanged(bool is_editable_node) { | 878 void RenderWidgetHostViewAndroid::FocusedNodeChanged(bool is_editable_node) { |
856 ime_adapter_android_.FocusedNodeChanged(is_editable_node); | 879 ime_adapter_android_.FocusedNodeChanged(is_editable_node); |
| 880 if (cursor_anchor_info_controller_) |
| 881 cursor_anchor_info_controller_->OnFocusedNodeChanged(is_editable_node); |
857 if (selection_controller_) | 882 if (selection_controller_) |
858 selection_controller_->OnSelectionEditable(is_editable_node); | 883 selection_controller_->OnSelectionEditable(is_editable_node); |
859 } | 884 } |
860 | 885 |
861 void RenderWidgetHostViewAndroid::RenderProcessGone( | 886 void RenderWidgetHostViewAndroid::RenderProcessGone( |
862 base::TerminationStatus status, int error_code) { | 887 base::TerminationStatus status, int error_code) { |
863 Destroy(); | 888 Destroy(); |
864 } | 889 } |
865 | 890 |
866 void RenderWidgetHostViewAndroid::Destroy() { | 891 void RenderWidgetHostViewAndroid::Destroy() { |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1029 host_->GetProcess()->GetID(), | 1054 host_->GetProcess()->GetID(), |
1030 ack); | 1055 ack); |
1031 } | 1056 } |
1032 | 1057 |
1033 void RenderWidgetHostViewAndroid::UnusedResourcesAreAvailable() { | 1058 void RenderWidgetHostViewAndroid::UnusedResourcesAreAvailable() { |
1034 if (ack_callbacks_.size()) | 1059 if (ack_callbacks_.size()) |
1035 return; | 1060 return; |
1036 SendReturnedDelegatedResources(last_output_surface_id_); | 1061 SendReturnedDelegatedResources(last_output_surface_id_); |
1037 } | 1062 } |
1038 | 1063 |
| 1064 void RenderWidgetHostViewAndroid::SendCursorAnchorInfo( |
| 1065 ui::CursorAnchorInfoBuilder* builder) { |
| 1066 ime_adapter_android_.UpdateCursorAnchorInfo(builder->Build()); |
| 1067 } |
| 1068 |
1039 void RenderWidgetHostViewAndroid::DestroyDelegatedContent() { | 1069 void RenderWidgetHostViewAndroid::DestroyDelegatedContent() { |
1040 RemoveLayers(); | 1070 RemoveLayers(); |
1041 frame_provider_ = NULL; | 1071 frame_provider_ = NULL; |
1042 layer_ = NULL; | 1072 layer_ = NULL; |
1043 // This gets called when ever any eviction, loosing resources, swapping | 1073 // This gets called when ever any eviction, loosing resources, swapping |
1044 // problems are encountered and so we abort any pending readbacks here. | 1074 // problems are encountered and so we abort any pending readbacks here. |
1045 AbortPendingReadbackRequests(); | 1075 AbortPendingReadbackRequests(); |
1046 } | 1076 } |
1047 | 1077 |
1048 void RenderWidgetHostViewAndroid::SwapDelegatedFrame( | 1078 void RenderWidgetHostViewAndroid::SwapDelegatedFrame( |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1359 #if defined(VIDEO_HOLE) | 1389 #if defined(VIDEO_HOLE) |
1360 if (host_ && host_->IsRenderView()) { | 1390 if (host_ && host_->IsRenderView()) { |
1361 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>( | 1391 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>( |
1362 RenderViewHost::From(host_)); | 1392 RenderViewHost::From(host_)); |
1363 WebContentsImpl* web_contents_impl = | 1393 WebContentsImpl* web_contents_impl = |
1364 static_cast<WebContentsImpl*>(WebContents::FromRenderViewHost(rvhi)); | 1394 static_cast<WebContentsImpl*>(WebContents::FromRenderViewHost(rvhi)); |
1365 if (web_contents_impl) | 1395 if (web_contents_impl) |
1366 web_contents_impl->media_web_contents_observer()->OnFrameInfoUpdated(); | 1396 web_contents_impl->media_web_contents_observer()->OnFrameInfoUpdated(); |
1367 } | 1397 } |
1368 #endif // defined(VIDEO_HOLE) | 1398 #endif // defined(VIDEO_HOLE) |
| 1399 |
| 1400 if (cursor_anchor_info_controller_) { |
| 1401 cursor_anchor_info_controller_->OnFrameMetadataUpdated( |
| 1402 frame_metadata, content_view_core_->GetLocationOnScreen()); |
| 1403 } |
1369 } | 1404 } |
1370 | 1405 |
1371 void RenderWidgetHostViewAndroid::AcceleratedSurfaceInitialized(int route_id) { | 1406 void RenderWidgetHostViewAndroid::AcceleratedSurfaceInitialized(int route_id) { |
1372 // TODO: remove need for the surface id here | 1407 // TODO: remove need for the surface id here |
1373 accelerated_surface_route_id_ = route_id; | 1408 accelerated_surface_route_id_ = route_id; |
1374 } | 1409 } |
1375 | 1410 |
1376 void RenderWidgetHostViewAndroid::AttachLayers() { | 1411 void RenderWidgetHostViewAndroid::AttachLayers() { |
1377 if (!content_view_core_) | 1412 if (!content_view_core_) |
1378 return; | 1413 return; |
(...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1922 results->orientationAngle = display.RotationAsDegree(); | 1957 results->orientationAngle = display.RotationAsDegree(); |
1923 results->orientationType = | 1958 results->orientationType = |
1924 RenderWidgetHostViewBase::GetOrientationTypeForMobile(display); | 1959 RenderWidgetHostViewBase::GetOrientationTypeForMobile(display); |
1925 gfx::DeviceDisplayInfo info; | 1960 gfx::DeviceDisplayInfo info; |
1926 results->depth = info.GetBitsPerPixel(); | 1961 results->depth = info.GetBitsPerPixel(); |
1927 results->depthPerComponent = info.GetBitsPerComponent(); | 1962 results->depthPerComponent = info.GetBitsPerComponent(); |
1928 results->isMonochrome = (results->depthPerComponent == 0); | 1963 results->isMonochrome = (results->depthPerComponent == 0); |
1929 } | 1964 } |
1930 | 1965 |
1931 } // namespace content | 1966 } // namespace content |
OLD | NEW |