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

Unified Diff: content/browser/renderer_host/text_input_manager.cc

Issue 2240553003: Track text selection on the browser side (Mac) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added #ifdef Created 4 years, 4 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
« no previous file with comments | « content/browser/renderer_host/text_input_manager.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/renderer_host/text_input_manager.cc
diff --git a/content/browser/renderer_host/text_input_manager.cc b/content/browser/renderer_host/text_input_manager.cc
index aa2522f91ca74f1272bd1cbd63eff233b51f6607..7c46df06f69587fbac6b444a401b51cde1e11bb5 100644
--- a/content/browser/renderer_host/text_input_manager.cc
+++ b/content/browser/renderer_host/text_input_manager.cc
@@ -316,4 +316,28 @@ TextInputManager::TextSelection::TextSelection(const TextSelection& other) =
TextInputManager::TextSelection::~TextSelection() {}
+bool TextInputManager::TextSelection::GetSelectedText(
+ base::string16* selected_text) const {
+ if (text.empty() || range.is_empty())
+ return false;
+
+ size_t pos = range.GetMin() - offset;
+ size_t n = range.length();
+ if (pos + n > text.length()) {
+ LOG(WARNING) << "The text can not fully cover range (selection's end point "
+ "exceeds text length).";
+ return false;
+ }
+
+ if (pos >= text.length()) {
+ LOG(WARNING) << "The text ca not cover range (selection range's starting "
+ "point exceeds text length).";
+ return false;
+ }
+
+ selected_text->clear();
+ selected_text->append(text.substr(pos, n));
+ return true;
+}
+
} // namespace content
« no previous file with comments | « content/browser/renderer_host/text_input_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698