| 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 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 : offset(0), range(gfx::Range::InvalidRange()), text(base::string16()) {} | 322 : offset(0), range(gfx::Range::InvalidRange()), text(base::string16()) {} |
| 323 | 323 |
| 324 TextInputManager::TextSelection::TextSelection(const TextSelection& other) = | 324 TextInputManager::TextSelection::TextSelection(const TextSelection& other) = |
| 325 default; | 325 default; |
| 326 | 326 |
| 327 TextInputManager::TextSelection::~TextSelection() {} | 327 TextInputManager::TextSelection::~TextSelection() {} |
| 328 | 328 |
| 329 bool TextInputManager::TextSelection::GetSelectedText( | 329 bool TextInputManager::TextSelection::GetSelectedText( |
| 330 base::string16* selected_text) const { | 330 base::string16* selected_text) const { |
| 331 if (text.empty() || range.is_empty()) | 331 if (text.empty() || range.is_empty()) |
| 332 return false; | 332 return true; |
| 333 | 333 |
| 334 size_t pos = range.GetMin() - offset; | 334 size_t pos = range.GetMin() - offset; |
| 335 size_t n = range.length(); | 335 size_t n = range.length(); |
| 336 if (pos + n > text.length()) { | 336 if (pos + n > text.length()) { |
| 337 LOG(WARNING) << "The text can not fully cover range (selection's end point " | 337 LOG(WARNING) << "The text can not fully cover range (selection's end point " |
| 338 "exceeds text length)."; | 338 "exceeds text length)."; |
| 339 return false; | |
| 340 } | 339 } |
| 341 | 340 |
| 342 if (pos >= text.length()) { | 341 if (pos >= text.length()) { |
| 343 LOG(WARNING) << "The text ca not cover range (selection range's starting " | 342 LOG(WARNING) << "The text ca not cover range (selection range's starting " |
| 344 "point exceeds text length)."; | 343 "point exceeds text length)."; |
| 345 return false; | 344 return false; |
| 346 } | 345 } |
| 347 | 346 |
| 348 selected_text->clear(); | 347 selected_text->clear(); |
| 349 selected_text->append(text.substr(pos, n)); | 348 selected_text->append(text.substr(pos, n)); |
| 350 return true; | 349 return true; |
| 351 } | 350 } |
| 352 | 351 |
| 353 } // namespace content | 352 } // namespace content |
| OLD | NEW |