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