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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « content/browser/renderer_host/text_input_manager.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/text_input_manager.h" 5 #include "content/browser/renderer_host/text_input_manager.h"
6 6
7 #include "base/strings/string16.h" 7 #include "base/strings/string16.h"
8 #include "content/browser/renderer_host/render_widget_host_impl.h" 8 #include "content/browser/renderer_host/render_widget_host_impl.h"
9 #include "content/browser/renderer_host/render_widget_host_view_base.h" 9 #include "content/browser/renderer_host/render_widget_host_view_base.h"
10 #include "content/common/view_messages.h" 10 #include "content/common/view_messages.h"
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 TextInputManager::CompositionRangeInfo::~CompositionRangeInfo() {} 309 TextInputManager::CompositionRangeInfo::~CompositionRangeInfo() {}
310 310
311 TextInputManager::TextSelection::TextSelection() 311 TextInputManager::TextSelection::TextSelection()
312 : offset(0), range(gfx::Range::InvalidRange()), text(base::string16()) {} 312 : offset(0), range(gfx::Range::InvalidRange()), text(base::string16()) {}
313 313
314 TextInputManager::TextSelection::TextSelection(const TextSelection& other) = 314 TextInputManager::TextSelection::TextSelection(const TextSelection& other) =
315 default; 315 default;
316 316
317 TextInputManager::TextSelection::~TextSelection() {} 317 TextInputManager::TextSelection::~TextSelection() {}
318 318
319 bool TextInputManager::TextSelection::GetSelectedText(
320 base::string16* selected_text) const {
321 if (text.empty() || range.is_empty())
322 return false;
323
324 size_t pos = range.GetMin() - offset;
325 size_t n = range.length();
326 if (pos + n > text.length()) {
327 LOG(WARNING) << "The text can not fully cover range (selection's end point "
328 "exceeds text length).";
329 return false;
330 }
331
332 if (pos >= text.length()) {
333 LOG(WARNING) << "The text ca not cover range (selection range's starting "
334 "point exceeds text length).";
335 return false;
336 }
337
338 selected_text->clear();
339 selected_text->append(text.substr(pos, n));
340 return true;
341 }
342
319 } // namespace content 343 } // namespace content
OLDNEW
« 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