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) { |
240 DCHECK(IsRegistered(view)); | 241 DCHECK(IsRegistered(view)); |
241 text_selection_map_[view].SetSelection(text, offset, range); | 242 text_selection_map_[view].SetSelection(text, offset, range, user_initiated); |
242 for (auto& observer : observer_list_) | 243 for (auto& observer : observer_list_) |
243 observer.OnTextSelectionChanged(this, view); | 244 observer.OnTextSelectionChanged(this, view); |
244 } | 245 } |
245 | 246 |
246 void TextInputManager::Register(RenderWidgetHostViewBase* view) { | 247 void TextInputManager::Register(RenderWidgetHostViewBase* view) { |
247 DCHECK(!IsRegistered(view)); | 248 DCHECK(!IsRegistered(view)); |
248 | 249 |
249 text_input_state_map_[view] = TextInputState(); | 250 text_input_state_map_[view] = TextInputState(); |
250 selection_region_map_[view] = SelectionRegion(); | 251 selection_region_map_[view] = SelectionRegion(); |
251 composition_range_info_map_[view] = CompositionRangeInfo(); | 252 composition_range_info_map_[view] = CompositionRangeInfo(); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 TextInputManager::SelectionRegion::SelectionRegion( | 312 TextInputManager::SelectionRegion::SelectionRegion( |
312 const SelectionRegion& other) = default; | 313 const SelectionRegion& other) = default; |
313 | 314 |
314 TextInputManager::CompositionRangeInfo::CompositionRangeInfo() {} | 315 TextInputManager::CompositionRangeInfo::CompositionRangeInfo() {} |
315 | 316 |
316 TextInputManager::CompositionRangeInfo::CompositionRangeInfo( | 317 TextInputManager::CompositionRangeInfo::CompositionRangeInfo( |
317 const CompositionRangeInfo& other) = default; | 318 const CompositionRangeInfo& other) = default; |
318 | 319 |
319 TextInputManager::CompositionRangeInfo::~CompositionRangeInfo() {} | 320 TextInputManager::CompositionRangeInfo::~CompositionRangeInfo() {} |
320 | 321 |
321 TextInputManager::TextSelection::TextSelection() | 322 TextInputManager::TextSelection::TextSelection() {} |
322 : offset_(0), range_(gfx::Range::InvalidRange()) {} | |
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 void TextInputManager::TextSelection::SetSelection(const base::string16& text, | 329 void TextInputManager::TextSelection::SetSelection(const base::string16& text, |
330 size_t offset, | 330 size_t offset, |
331 const gfx::Range& range) { | 331 const gfx::Range& range, |
| 332 bool user_initiated) { |
332 text_ = text; | 333 text_ = text; |
333 range_.set_start(range.start()); | 334 range_.set_start(range.start()); |
334 range_.set_end(range.end()); | 335 range_.set_end(range.end()); |
335 offset_ = offset; | 336 offset_ = offset; |
| 337 user_initiated_ = user_initiated; |
336 | 338 |
337 // Update the selected text. | 339 // Update the selected text. |
338 selected_text_.clear(); | 340 selected_text_.clear(); |
339 if (!text.empty() && !range.is_empty()) { | 341 if (!text.empty() && !range.is_empty()) { |
340 size_t pos = range.GetMin() - offset; | 342 size_t pos = range.GetMin() - offset; |
341 size_t n = range.length(); | 343 size_t n = range.length(); |
342 if (pos + n > text.length()) { | 344 if (pos + n > text.length()) { |
343 LOG(WARNING) | 345 LOG(WARNING) |
344 << "The text cannot fully cover range (selection's end point " | 346 << "The text cannot fully cover range (selection's end point " |
345 "exceeds text length)."; | 347 "exceeds text length)."; |
346 } | 348 } |
347 | 349 |
348 if (pos >= text.length()) { | 350 if (pos >= text.length()) { |
349 LOG(WARNING) << "The text cannot cover range (selection range's starting " | 351 LOG(WARNING) << "The text cannot cover range (selection range's starting " |
350 "point exceeds text length)."; | 352 "point exceeds text length)."; |
351 } else { | 353 } else { |
352 selected_text_.append(text.substr(pos, n)); | 354 selected_text_.append(text.substr(pos, n)); |
353 } | 355 } |
354 } | 356 } |
355 } | 357 } |
356 | 358 |
357 } // namespace content | 359 } // namespace content |
OLD | NEW |