| OLD | NEW |
| 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 Loading... |
| 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 |
| OLD | NEW |