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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
306 const SelectionRegion& other) = default; | 307 const SelectionRegion& other) = default; |
307 | 308 |
308 TextInputManager::CompositionRangeInfo::CompositionRangeInfo() {} | 309 TextInputManager::CompositionRangeInfo::CompositionRangeInfo() {} |
309 | 310 |
310 TextInputManager::CompositionRangeInfo::CompositionRangeInfo( | 311 TextInputManager::CompositionRangeInfo::CompositionRangeInfo( |
311 const CompositionRangeInfo& other) = default; | 312 const CompositionRangeInfo& other) = default; |
312 | 313 |
313 TextInputManager::CompositionRangeInfo::~CompositionRangeInfo() {} | 314 TextInputManager::CompositionRangeInfo::~CompositionRangeInfo() {} |
314 | 315 |
315 TextInputManager::TextSelection::TextSelection() | 316 TextInputManager::TextSelection::TextSelection() |
316 : offset_(0), range_(gfx::Range::InvalidRange()) {} | 317 : offset_(0), range_(gfx::Range::InvalidRange()) {} |
EhsanK
2017/05/04 00:16:31
(nit) Initialize |user_initiated| (to false?).
nasko
2017/05/04 16:10:24
With C++11, we can now initialize it in the header
Peter Varga
2017/05/04 16:33:45
ok, I will check this.
| |
317 | 318 |
318 TextInputManager::TextSelection::TextSelection(const TextSelection& other) = | 319 TextInputManager::TextSelection::TextSelection(const TextSelection& other) = |
319 default; | 320 default; |
320 | 321 |
321 TextInputManager::TextSelection::~TextSelection() {} | 322 TextInputManager::TextSelection::~TextSelection() {} |
322 | 323 |
323 void TextInputManager::TextSelection::SetSelection(const base::string16& text, | 324 void TextInputManager::TextSelection::SetSelection(const base::string16& text, |
324 size_t offset, | 325 size_t offset, |
325 const gfx::Range& range) { | 326 const gfx::Range& range, |
327 bool user_initiated) { | |
326 text_ = text; | 328 text_ = text; |
327 range_.set_start(range.start()); | 329 range_.set_start(range.start()); |
328 range_.set_end(range.end()); | 330 range_.set_end(range.end()); |
329 offset_ = offset; | 331 offset_ = offset; |
332 user_initiated_ = user_initiated; | |
330 | 333 |
331 // Update the selected text. | 334 // Update the selected text. |
332 selected_text_.clear(); | 335 selected_text_.clear(); |
333 if (!text.empty() && !range.is_empty()) { | 336 if (!text.empty() && !range.is_empty()) { |
334 size_t pos = range.GetMin() - offset; | 337 size_t pos = range.GetMin() - offset; |
335 size_t n = range.length(); | 338 size_t n = range.length(); |
336 if (pos + n > text.length()) { | 339 if (pos + n > text.length()) { |
337 LOG(WARNING) | 340 LOG(WARNING) |
338 << "The text cannot fully cover range (selection's end point " | 341 << "The text cannot fully cover range (selection's end point " |
339 "exceeds text length)."; | 342 "exceeds text length)."; |
340 } | 343 } |
341 | 344 |
342 if (pos >= text.length()) { | 345 if (pos >= text.length()) { |
343 LOG(WARNING) << "The text cannot cover range (selection range's starting " | 346 LOG(WARNING) << "The text cannot cover range (selection range's starting " |
344 "point exceeds text length)."; | 347 "point exceeds text length)."; |
345 } else { | 348 } else { |
346 selected_text_.append(text.substr(pos, n)); | 349 selected_text_.append(text.substr(pos, n)); |
347 } | 350 } |
348 } | 351 } |
349 } | 352 } |
350 | 353 |
351 } // namespace content | 354 } // namespace content |
OLD | NEW |