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 "content/browser/renderer_host/render_widget_host_impl.h" | 7 #include "content/browser/renderer_host/render_widget_host_impl.h" |
8 #include "content/browser/renderer_host/render_widget_host_view_base.h" | 8 #include "content/browser/renderer_host/render_widget_host_view_base.h" |
9 #include "content/common/view_messages.h" | 9 #include "content/common/view_messages.h" |
10 #include "ui/gfx/geometry/rect.h" | 10 #include "ui/gfx/geometry/rect.h" |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 composition_range_info_map_[view].range.set_start(range.start()); | 229 composition_range_info_map_[view].range.set_start(range.start()); |
230 composition_range_info_map_[view].range.set_end(range.end()); | 230 composition_range_info_map_[view].range.set_end(range.end()); |
231 | 231 |
232 for (auto& observer : observer_list_) | 232 for (auto& observer : observer_list_) |
233 observer.OnImeCompositionRangeChanged(this, view); | 233 observer.OnImeCompositionRangeChanged(this, view); |
234 } | 234 } |
235 | 235 |
236 void TextInputManager::SelectionChanged(RenderWidgetHostViewBase* view, | 236 void TextInputManager::SelectionChanged(RenderWidgetHostViewBase* view, |
237 const base::string16& text, | 237 const base::string16& text, |
238 size_t offset, | 238 size_t offset, |
239 const gfx::Range& range, | 239 const gfx::Range& range) { |
240 bool user_initiated) { | |
241 DCHECK(IsRegistered(view)); | 240 DCHECK(IsRegistered(view)); |
242 text_selection_map_[view].SetSelection(text, offset, range, user_initiated); | 241 text_selection_map_[view].SetSelection(text, offset, range); |
243 for (auto& observer : observer_list_) | 242 for (auto& observer : observer_list_) |
244 observer.OnTextSelectionChanged(this, view); | 243 observer.OnTextSelectionChanged(this, view); |
245 } | 244 } |
246 | 245 |
247 void TextInputManager::Register(RenderWidgetHostViewBase* view) { | 246 void TextInputManager::Register(RenderWidgetHostViewBase* view) { |
248 DCHECK(!IsRegistered(view)); | 247 DCHECK(!IsRegistered(view)); |
249 | 248 |
250 text_input_state_map_[view] = TextInputState(); | 249 text_input_state_map_[view] = TextInputState(); |
251 selection_region_map_[view] = SelectionRegion(); | 250 selection_region_map_[view] = SelectionRegion(); |
252 composition_range_info_map_[view] = CompositionRangeInfo(); | 251 composition_range_info_map_[view] = CompositionRangeInfo(); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 TextInputManager::SelectionRegion::SelectionRegion( | 305 TextInputManager::SelectionRegion::SelectionRegion( |
307 const SelectionRegion& other) = default; | 306 const SelectionRegion& other) = default; |
308 | 307 |
309 TextInputManager::CompositionRangeInfo::CompositionRangeInfo() {} | 308 TextInputManager::CompositionRangeInfo::CompositionRangeInfo() {} |
310 | 309 |
311 TextInputManager::CompositionRangeInfo::CompositionRangeInfo( | 310 TextInputManager::CompositionRangeInfo::CompositionRangeInfo( |
312 const CompositionRangeInfo& other) = default; | 311 const CompositionRangeInfo& other) = default; |
313 | 312 |
314 TextInputManager::CompositionRangeInfo::~CompositionRangeInfo() {} | 313 TextInputManager::CompositionRangeInfo::~CompositionRangeInfo() {} |
315 | 314 |
316 TextInputManager::TextSelection::TextSelection() {} | 315 TextInputManager::TextSelection::TextSelection() |
| 316 : offset_(0), range_(gfx::Range::InvalidRange()) {} |
317 | 317 |
318 TextInputManager::TextSelection::TextSelection(const TextSelection& other) = | 318 TextInputManager::TextSelection::TextSelection(const TextSelection& other) = |
319 default; | 319 default; |
320 | 320 |
321 TextInputManager::TextSelection::~TextSelection() {} | 321 TextInputManager::TextSelection::~TextSelection() {} |
322 | 322 |
323 void TextInputManager::TextSelection::SetSelection(const base::string16& text, | 323 void TextInputManager::TextSelection::SetSelection(const base::string16& text, |
324 size_t offset, | 324 size_t offset, |
325 const gfx::Range& range, | 325 const gfx::Range& range) { |
326 bool user_initiated) { | |
327 text_ = text; | 326 text_ = text; |
328 range_.set_start(range.start()); | 327 range_.set_start(range.start()); |
329 range_.set_end(range.end()); | 328 range_.set_end(range.end()); |
330 offset_ = offset; | 329 offset_ = offset; |
331 user_initiated_ = user_initiated; | |
332 | 330 |
333 // Update the selected text. | 331 // Update the selected text. |
334 selected_text_.clear(); | 332 selected_text_.clear(); |
335 if (!text.empty() && !range.is_empty()) { | 333 if (!text.empty() && !range.is_empty()) { |
336 size_t pos = range.GetMin() - offset; | 334 size_t pos = range.GetMin() - offset; |
337 size_t n = range.length(); | 335 size_t n = range.length(); |
338 if (pos + n > text.length()) { | 336 if (pos + n > text.length()) { |
339 LOG(WARNING) | 337 LOG(WARNING) |
340 << "The text cannot fully cover range (selection's end point " | 338 << "The text cannot fully cover range (selection's end point " |
341 "exceeds text length)."; | 339 "exceeds text length)."; |
342 } | 340 } |
343 | 341 |
344 if (pos >= text.length()) { | 342 if (pos >= text.length()) { |
345 LOG(WARNING) << "The text cannot cover range (selection range's starting " | 343 LOG(WARNING) << "The text cannot cover range (selection range's starting " |
346 "point exceeds text length)."; | 344 "point exceeds text length)."; |
347 } else { | 345 } else { |
348 selected_text_.append(text.substr(pos, n)); | 346 selected_text_.append(text.substr(pos, n)); |
349 } | 347 } |
350 } | 348 } |
351 } | 349 } |
352 | 350 |
353 } // namespace content | 351 } // namespace content |
OLD | NEW |