Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(81)

Side by Side Diff: content/browser/renderer_host/text_input_manager.cc

Issue 2856093003: Update TextSelection for non-user initiated events (Closed)
Patch Set: Update TextSelection for non-user initiated events Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/browser/renderer_host/text_input_manager.h ('k') | content/common/frame_messages.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 TextInputManager::SelectionRegion::SelectionRegion( 306 TextInputManager::SelectionRegion::SelectionRegion(
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 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) {
326 text_ = text; 327 text_ = text;
327 range_.set_start(range.start()); 328 range_.set_start(range.start());
328 range_.set_end(range.end()); 329 range_.set_end(range.end());
329 offset_ = offset; 330 offset_ = offset;
331 user_initiated_ = user_initiated;
330 332
331 // Update the selected text. 333 // Update the selected text.
332 selected_text_.clear(); 334 selected_text_.clear();
333 if (!text.empty() && !range.is_empty()) { 335 if (!text.empty() && !range.is_empty()) {
334 size_t pos = range.GetMin() - offset; 336 size_t pos = range.GetMin() - offset;
335 size_t n = range.length(); 337 size_t n = range.length();
336 if (pos + n > text.length()) { 338 if (pos + n > text.length()) {
337 LOG(WARNING) 339 LOG(WARNING)
338 << "The text cannot fully cover range (selection's end point " 340 << "The text cannot fully cover range (selection's end point "
339 "exceeds text length)."; 341 "exceeds text length).";
340 } 342 }
341 343
342 if (pos >= text.length()) { 344 if (pos >= text.length()) {
343 LOG(WARNING) << "The text cannot cover range (selection range's starting " 345 LOG(WARNING) << "The text cannot cover range (selection range's starting "
344 "point exceeds text length)."; 346 "point exceeds text length).";
345 } else { 347 } else {
346 selected_text_.append(text.substr(pos, n)); 348 selected_text_.append(text.substr(pos, n));
347 } 349 }
348 } 350 }
349 } 351 }
350 352
351 } // namespace content 353 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/text_input_manager.h ('k') | content/common/frame_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698