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

Unified 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, 11 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/renderer_host/render_widget_host_view_android.cc
diff --git a/content/browser/renderer_host/render_widget_host_view_android.cc b/content/browser/renderer_host/render_widget_host_view_android.cc
index 2ee46f4f425a642b7e6f5a7263b594481261f35d..e636d407a1a5579fe246d4f33d7fa0870e10a4f1 100644
--- a/content/browser/renderer_host/render_widget_host_view_android.cc
+++ b/content/browser/renderer_host/render_widget_host_view_android.cc
@@ -796,6 +796,35 @@ void RenderWidgetHostViewAndroid::OnImeCancelComposition(
ime_adapter_android_.CancelComposition();
}
+void RenderWidgetHostViewAndroid::OnTextSelectionChanged(
+ TextInputManager* text_input_manager,
+ RenderWidgetHostViewBase* updated_view) {
+ DCHECK_EQ(text_input_manager_, text_input_manager);
+
+ // TODO(asimjour): remove the flag and fix text selection popup for
+ // virtual reality mode.
+ if (is_in_vr_)
+ return;
+
+ if (!content_view_core_)
+ return;
+
+ RenderWidgetHostImpl* focused_widget = GetFocusedWidget();
+ if (!focused_widget || !focused_widget->GetView())
+ return;
+
+ const TextInputManager::TextSelection& selection =
+ *text_input_manager_->GetTextSelection(focused_widget->GetView());
+ if (selection.range.is_empty()) {
+ content_view_core_->OnSelectionChanged("");
+ return;
+ }
+
+ base::string16 selected_text;
+ if (selection.GetSelectedText(&selected_text))
+ content_view_core_->OnSelectionChanged(base::UTF16ToUTF8(selected_text));
+}
+
void RenderWidgetHostViewAndroid::UpdateBackgroundColor(SkColor color) {
if (cached_background_color_ == color)
return;
@@ -944,38 +973,6 @@ void RenderWidgetHostViewAndroid::SetTooltipText(
// Tooltips don't makes sense on Android.
}
-void RenderWidgetHostViewAndroid::SelectionChanged(const base::string16& text,
- size_t offset,
- const gfx::Range& range) {
- // TODO(asimjour): remove the flag and fix text selection popup for
- // virtual reality mode.
- if (is_in_vr_)
- return;
-
- RenderWidgetHostViewBase::SelectionChanged(text, offset, range);
-
- if (!content_view_core_)
- return;
- if (range.is_empty()) {
- content_view_core_->OnSelectionChanged("");
- return;
- }
-
- DCHECK(!text.empty());
- size_t pos = range.GetMin() - offset;
- size_t n = range.length();
-
- DCHECK(pos + n <= text.length()) << "The text can not fully cover range.";
- if (pos >= text.length()) {
- NOTREACHED() << "The text can not cover range.";
- return;
- }
-
- std::string utf8_selection = base::UTF16ToUTF8(text.substr(pos, n));
-
- content_view_core_->OnSelectionChanged(utf8_selection);
-}
-
void RenderWidgetHostViewAndroid::SetBackgroundColor(SkColor color) {
RenderWidgetHostViewBase::SetBackgroundColor(color);
host_->SetBackgroundOpaque(GetBackgroundOpaque());

Powered by Google App Engine
This is Rietveld 408576698