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

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

Issue 2240553003: Track text selection on the browser side (Mac) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed the failing tests on 'mac_chromium_rel_ng' Created 4 years, 4 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
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 "base/strings/string16.h" 7 #include "base/strings/string16.h"
8 #include "content/browser/renderer_host/render_widget_host_impl.h" 8 #include "content/browser/renderer_host/render_widget_host_impl.h"
9 #include "content/browser/renderer_host/render_widget_host_view_base.h" 9 #include "content/browser/renderer_host/render_widget_host_view_base.h"
10 #include "content/common/view_messages.h" 10 #include "content/common/view_messages.h"
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 } 78 }
79 79
80 const TextInputManager::TextSelection* TextInputManager::GetTextSelection( 80 const TextInputManager::TextSelection* TextInputManager::GetTextSelection(
81 RenderWidgetHostViewBase* view) const { 81 RenderWidgetHostViewBase* view) const {
82 DCHECK(!view || IsRegistered(view)); 82 DCHECK(!view || IsRegistered(view));
83 if (!view) 83 if (!view)
84 view = active_view_; 84 view = active_view_;
85 return !!view ? &text_selection_map_.at(view) : nullptr; 85 return !!view ? &text_selection_map_.at(view) : nullptr;
86 } 86 }
87 87
88 bool TextInputManager::GetSelectedText(RenderWidgetHostViewBase* view,
89 base::string16* selected_text) const {
90 const TextSelection* selection = GetTextSelection(view);
91 if (!selection)
92 return false;
93
94 if (selection->text.empty() || selection->range.is_empty())
95 return false;
96
97 selected_text->clear();
98 size_t pos = selection->range.GetMin() - selection->offset;
99 size_t n = selection->range.length();
100 DCHECK(pos + n <= selection->text.length())
Avi (use Gerrit) 2016/08/12 15:53:10 DCHECK_LE
EhsanK 2016/08/16 13:36:45 Done.
101 << "The text can not fully cover range.";
102 if (pos >= selection->text.length()) {
erikchen 2016/08/12 19:33:43 Is it ever possible for an instance of TextSelecti
EhsanK 2016/08/16 13:36:45 I am not sure but the selection information are co
erikchen 2016/08/16 16:36:22 Yes, early return is appropriate. Short of memory
EhsanK 2016/08/17 06:20:50 I think the DCHECK above should also change then.
103 NOTREACHED() << "The text can not cover range.";
104 return false;
105 }
106 selected_text->append(selection->text.substr(pos, n));
107 return true;
108 }
109
88 void TextInputManager::UpdateTextInputState( 110 void TextInputManager::UpdateTextInputState(
89 RenderWidgetHostViewBase* view, 111 RenderWidgetHostViewBase* view,
90 const TextInputState& text_input_state) { 112 const TextInputState& text_input_state) {
91 DCHECK(IsRegistered(view)); 113 DCHECK(IsRegistered(view));
92 114
93 if (text_input_state.type == ui::TEXT_INPUT_TYPE_NONE && 115 if (text_input_state.type == ui::TEXT_INPUT_TYPE_NONE &&
94 active_view_ != view) { 116 active_view_ != view) {
95 // We reached here because an IPC is received to reset the TextInputState 117 // We reached here because an IPC is received to reset the TextInputState
96 // for |view|. But |view| != |active_view_|, which suggests that at least 118 // for |view|. But |view| != |active_view_|, which suggests that at least
97 // one other view has become active and we have received the corresponding 119 // one other view has become active and we have received the corresponding
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 320
299 TextInputManager::TextSelection::TextSelection() 321 TextInputManager::TextSelection::TextSelection()
300 : offset(0), range(gfx::Range::InvalidRange()), text(base::string16()) {} 322 : offset(0), range(gfx::Range::InvalidRange()), text(base::string16()) {}
301 323
302 TextInputManager::TextSelection::TextSelection(const TextSelection& other) = 324 TextInputManager::TextSelection::TextSelection(const TextSelection& other) =
303 default; 325 default;
304 326
305 TextInputManager::TextSelection::~TextSelection() {} 327 TextInputManager::TextSelection::~TextSelection() {}
306 328
307 } // namespace content 329 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698