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

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

Issue 2354793003: Browser Side TextInputState Tracking for Android (Closed)
Patch Set: Addressing kenrb@'s comments Created 4 years, 1 month 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"
11 #include "ui/gfx/geometry/rect.h" 11 #include "ui/gfx/geometry/rect.h"
12 #include "ui/gfx/range/range.h" 12 #include "ui/gfx/range/range.h"
13 13
14 namespace content { 14 namespace content {
15 15
16 namespace { 16 namespace {
17 17
18 bool AreDifferentTextInputStates(const content::TextInputState& old_state, 18 bool AreDifferentTextInputStates(const content::TextInputState& old_state,
19 const content::TextInputState& new_state) { 19 const content::TextInputState& new_state) {
20 #if defined(USE_AURA) 20 #if defined(USE_AURA)
21 return old_state.type != new_state.type || old_state.mode != new_state.mode || 21 return old_state.type != new_state.type || old_state.mode != new_state.mode ||
22 old_state.flags != new_state.flags || 22 old_state.flags != new_state.flags ||
23 old_state.can_compose_inline != new_state.can_compose_inline; 23 old_state.can_compose_inline != new_state.can_compose_inline;
24 #elif defined(OS_MACOSX) 24 #elif defined(OS_MACOSX)
25 return old_state.type != new_state.type || 25 return old_state.type != new_state.type ||
26 old_state.can_compose_inline != new_state.can_compose_inline; 26 old_state.can_compose_inline != new_state.can_compose_inline;
27 #else 27 #else
28 // TODO(ekaramad): Implement the logic for other platforms (crbug.com/578168). 28 // On Android, TextInputState update is sent only if there is some change in
29 NOTREACHED(); 29 // the state. So the new state is always different.
Charlie Reis 2016/11/02 22:23:13 nit: Comma, not period. (Second sentence is not a
EhsanK 2016/11/18 19:55:59 Acknowledged...and good point. I believe what need
30 return true; 30 return true;
31 #endif 31 #endif
32 } 32 }
33 33
34 } // namespace 34 } // namespace
35 35
36 TextInputManager::TextInputManager() : active_view_(nullptr) {} 36 TextInputManager::TextInputManager() : active_view_(nullptr) {}
37 37
38 TextInputManager::~TextInputManager() { 38 TextInputManager::~TextInputManager() {
39 // If there is an active view, we should unregister it first so that the 39 // If there is an active view, we should unregister it first so that the
(...skipping 10 matching lines...) Expand all
50 for (auto* view : views) 50 for (auto* view : views)
51 Unregister(view); 51 Unregister(view);
52 } 52 }
53 53
54 RenderWidgetHostImpl* TextInputManager::GetActiveWidget() const { 54 RenderWidgetHostImpl* TextInputManager::GetActiveWidget() const {
55 return !!active_view_ ? static_cast<RenderWidgetHostImpl*>( 55 return !!active_view_ ? static_cast<RenderWidgetHostImpl*>(
56 active_view_->GetRenderWidgetHost()) 56 active_view_->GetRenderWidgetHost())
57 : nullptr; 57 : nullptr;
58 } 58 }
59 59
60 const TextInputState* TextInputManager::GetTextInputState() const { 60 const TextInputState* TextInputManager::GetTextInputState(
61 return !!active_view_ ? &text_input_state_map_.at(active_view_) : nullptr; 61 RenderWidgetHostViewBase* view) const {
62 DCHECK(!view || IsRegistered(view));
63 if (!view)
64 view = active_view_;
65 return !!view ? &text_input_state_map_.at(view) : nullptr;
62 } 66 }
63 67
64 const TextInputManager::SelectionRegion* TextInputManager::GetSelectionRegion( 68 const TextInputManager::SelectionRegion* TextInputManager::GetSelectionRegion(
65 RenderWidgetHostViewBase* view) const { 69 RenderWidgetHostViewBase* view) const {
66 DCHECK(!view || IsRegistered(view)); 70 DCHECK(!view || IsRegistered(view));
67 if (!view) 71 if (!view)
68 view = active_view_; 72 view = active_view_;
69 return view ? &selection_region_map_.at(view) : nullptr; 73 return view ? &selection_region_map_.at(view) : nullptr;
70 } 74 }
71 75
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 "point exceeds text length)."; 345 "point exceeds text length).";
342 return false; 346 return false;
343 } 347 }
344 348
345 selected_text->clear(); 349 selected_text->clear();
346 selected_text->append(text.substr(pos, n)); 350 selected_text->append(text.substr(pos, n));
347 return true; 351 return true;
348 } 352 }
349 353
350 } // namespace content 354 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698