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

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

Issue 2659433002: Track Text Selection information in TextInputManager (OOPIF for Android) (Closed)
Patch Set: Clean ups Created 3 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 <utility> 9 #include <utility>
10 10
(...skipping 778 matching lines...) Expand 10 before | Expand all | Expand 10 after
789 ime_adapter_android_.SetCharacterBounds(character_bounds); 789 ime_adapter_android_.SetCharacterBounds(character_bounds);
790 } 790 }
791 791
792 void RenderWidgetHostViewAndroid::OnImeCancelComposition( 792 void RenderWidgetHostViewAndroid::OnImeCancelComposition(
793 TextInputManager* text_input_manager, 793 TextInputManager* text_input_manager,
794 RenderWidgetHostViewBase* updated_view) { 794 RenderWidgetHostViewBase* updated_view) {
795 DCHECK_EQ(text_input_manager_, text_input_manager); 795 DCHECK_EQ(text_input_manager_, text_input_manager);
796 ime_adapter_android_.CancelComposition(); 796 ime_adapter_android_.CancelComposition();
797 } 797 }
798 798
799 void RenderWidgetHostViewAndroid::OnTextSelectionChanged(
800 TextInputManager* text_input_manager,
801 RenderWidgetHostViewBase* updated_view) {
802 DCHECK_EQ(text_input_manager_, text_input_manager);
803
804 // TODO(asimjour): remove the flag and fix text selection popup for
805 // virtual reality mode.
806 if (is_in_vr_)
807 return;
808
809 if (!content_view_core_)
810 return;
811
812 RenderWidgetHostImpl* focused_widget = GetFocusedWidget();
813 if (!focused_widget || !focused_widget->GetView())
814 return;
815
816 const TextInputManager::TextSelection& selection =
817 *text_input_manager_->GetTextSelection(focused_widget->GetView());
818 if (selection.range.is_empty()) {
819 content_view_core_->OnSelectionChanged("");
820 return;
821 }
822
823 base::string16 selected_text;
824 if (selection.GetSelectedText(&selected_text))
825 content_view_core_->OnSelectionChanged(base::UTF16ToUTF8(selected_text));
826 }
827
799 void RenderWidgetHostViewAndroid::UpdateBackgroundColor(SkColor color) { 828 void RenderWidgetHostViewAndroid::UpdateBackgroundColor(SkColor color) {
800 if (cached_background_color_ == color) 829 if (cached_background_color_ == color)
801 return; 830 return;
802 831
803 cached_background_color_ = color; 832 cached_background_color_ = color;
804 833
805 if (delegated_frame_host_) 834 if (delegated_frame_host_)
806 delegated_frame_host_->UpdateBackgroundColor(color); 835 delegated_frame_host_->UpdateBackgroundColor(color);
807 836
808 if (content_view_core_) 837 if (content_view_core_)
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
937 GetTextInputManager()->RemoveObserver(this); 966 GetTextInputManager()->RemoveObserver(this);
938 967
939 delete this; 968 delete this;
940 } 969 }
941 970
942 void RenderWidgetHostViewAndroid::SetTooltipText( 971 void RenderWidgetHostViewAndroid::SetTooltipText(
943 const base::string16& tooltip_text) { 972 const base::string16& tooltip_text) {
944 // Tooltips don't makes sense on Android. 973 // Tooltips don't makes sense on Android.
945 } 974 }
946 975
947 void RenderWidgetHostViewAndroid::SelectionChanged(const base::string16& text,
948 size_t offset,
949 const gfx::Range& range) {
950 // TODO(asimjour): remove the flag and fix text selection popup for
951 // virtual reality mode.
952 if (is_in_vr_)
953 return;
954
955 RenderWidgetHostViewBase::SelectionChanged(text, offset, range);
956
957 if (!content_view_core_)
958 return;
959 if (range.is_empty()) {
960 content_view_core_->OnSelectionChanged("");
961 return;
962 }
963
964 DCHECK(!text.empty());
965 size_t pos = range.GetMin() - offset;
966 size_t n = range.length();
967
968 DCHECK(pos + n <= text.length()) << "The text can not fully cover range.";
969 if (pos >= text.length()) {
970 NOTREACHED() << "The text can not cover range.";
971 return;
972 }
973
974 std::string utf8_selection = base::UTF16ToUTF8(text.substr(pos, n));
975
976 content_view_core_->OnSelectionChanged(utf8_selection);
977 }
978
979 void RenderWidgetHostViewAndroid::SetBackgroundColor(SkColor color) { 976 void RenderWidgetHostViewAndroid::SetBackgroundColor(SkColor color) {
980 RenderWidgetHostViewBase::SetBackgroundColor(color); 977 RenderWidgetHostViewBase::SetBackgroundColor(color);
981 host_->SetBackgroundOpaque(GetBackgroundOpaque()); 978 host_->SetBackgroundOpaque(GetBackgroundOpaque());
982 UpdateBackgroundColor(color); 979 UpdateBackgroundColor(color);
983 } 980 }
984 981
985 void RenderWidgetHostViewAndroid::CopyFromCompositingSurface( 982 void RenderWidgetHostViewAndroid::CopyFromCompositingSurface(
986 const gfx::Rect& src_subrect, 983 const gfx::Rect& src_subrect,
987 const gfx::Size& dst_size, 984 const gfx::Size& dst_size,
988 const ReadbackRequestCallback& callback, 985 const ReadbackRequestCallback& callback,
(...skipping 1078 matching lines...) Expand 10 before | Expand all | Expand 10 after
2067 ui::WindowAndroidCompositor* compositor = window_android->GetCompositor(); 2064 ui::WindowAndroidCompositor* compositor = window_android->GetCompositor();
2068 if (!compositor) 2065 if (!compositor)
2069 return; 2066 return;
2070 2067
2071 overscroll_controller_ = base::MakeUnique<OverscrollControllerAndroid>( 2068 overscroll_controller_ = base::MakeUnique<OverscrollControllerAndroid>(
2072 overscroll_refresh_handler, compositor, 2069 overscroll_refresh_handler, compositor,
2073 ui::GetScaleFactorForNativeView(GetNativeView())); 2070 ui::GetScaleFactorForNativeView(GetNativeView()));
2074 } 2071 }
2075 2072
2076 } // namespace content 2073 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698