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

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

Issue 1948343002: [reland] Browser Side Text Input State Tracking for OOPIF (Aura Only) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressing kenrb@ Comments Created 4 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "content/browser/renderer_host/text_input_manager.h"
6
7 #include "content/browser/renderer_host/render_widget_host_view_base.h"
8
9 namespace content {
10
11 namespace {
12
13 bool AreDifferentTextInputStates(const content::TextInputState& old_state,
14 const content::TextInputState& new_state) {
15 #if defined(USE_AURA)
16 return old_state.type != new_state.type || old_state.mode != new_state.mode ||
17 old_state.flags != new_state.flags ||
18 old_state.can_compose_inline != new_state.can_compose_inline;
19 #else
20 // TODO(ekaramad): Implement this logic for other platforms.
Charlie Reis 2016/05/18 20:46:04 Maybe add a NOTREACHED()? We don't want to forget
EhsanK 2016/05/24 20:42:45 Done. Also, added #ifdef USE_AURA in RenderWidgetH
21 return true;
22 #endif
23 }
24
25 } // namespace
26
27 TextInputManager::TextInputManager() : active_view_(nullptr) {}
28
29 TextInputManager::~TextInputManager() {
30 FOR_EACH_OBSERVER(Observer, observer_list_,
31 OnDestroyingTextInputManager(this));
32 }
33
34 const TextInputState* TextInputManager::GetTextInputState() {
35 return !!active_view_ ? &text_input_state_map_[active_view_] : nullptr;
36 }
37
38 RenderWidgetHostViewBase* TextInputManager::GetActiveView() const {
39 return active_view_;
40 }
41
42 void TextInputManager::UpdateTextInputState(
43 RenderWidgetHostViewBase* view,
44 const TextInputState& text_input_state) {
45 DCHECK(IsRegisteredView(view));
46
47 bool changed = AreDifferentTextInputStates(text_input_state_map_[view],
Charlie Reis 2016/05/18 20:46:04 What if text_input_state_map_[view] were null? Ar
EhsanK 2016/05/24 20:42:45 On line 45, we verify that the view is registered,
Charlie Reis 2016/05/26 06:22:03 Hopefully so. The IsRegistered check is a DCHECK,
48 text_input_state);
49
50 text_input_state_map_[view] = text_input_state;
51
52 // |active_view_| is only updated when the state for |view| is not none.
53 if (text_input_state.type != ui::TEXT_INPUT_TYPE_NONE)
54 active_view_ = view;
55
56 // If the state for |active_view_| is none, then we no longer have an
57 // |active_view_|.
58 if (active_view_ == view && text_input_state.type == ui::TEXT_INPUT_TYPE_NONE)
59 active_view_ = nullptr;
60
61 NotifyObserversAboutInputStateUpdate(view, changed);
62 }
63
64 void TextInputManager::Register(RenderWidgetHostViewBase* view) {
65 DCHECK(!IsRegisteredView(view));
66
67 text_input_state_map_[view] = TextInputState();
68 view->AddObserver(this);
69 }
70
71 void TextInputManager::Unregister(RenderWidgetHostViewBase* view) {
72 DCHECK(IsRegisteredView(view));
73
74 text_input_state_map_.erase(view);
75 if (active_view_ == view) {
76 active_view_ = nullptr;
77 NotifyObserversAboutInputStateUpdate(view, true);
78 }
79 view->RemoveObserver(this);
80 }
81
82 bool TextInputManager::IsRegisteredView(RenderWidgetHostViewBase* view) const {
83 return text_input_state_map_.count(view) == 1;
84 }
85
86 void TextInputManager::AddObserver(Observer* observer) {
87 observer_list_.AddObserver(observer);
88 }
89
90 void TextInputManager::RemoveObserver(Observer* observer) {
91 observer_list_.RemoveObserver(observer);
92 }
93
94 void TextInputManager::OnRenderWidgetHostViewBaseDestroyed(
95 RenderWidgetHostViewBase* view) {
96 DCHECK(IsRegisteredView(view));
97
98 Unregister(view);
99
100 if (observer_list_.HasObserver(view))
101 RemoveObserver(view);
102
103 if (active_view_ == view) {
Charlie Reis 2016/05/18 20:46:04 Didn't we just do this block in Unregister on line
EhsanK 2016/05/24 20:42:45 You are right and the DCHECK was impossible to hit
104 DCHECK(text_input_state_map_[active_view_].type !=
105 ui::TEXT_INPUT_TYPE_NONE);
106 active_view_ = nullptr;
107 NotifyObserversAboutInputStateUpdate(view, true);
108 }
109 }
110
111 void TextInputManager::NotifyObserversAboutInputStateUpdate(
112 RenderWidgetHostViewBase* updated_view,
113 bool state_changed) {
114 if (state_changed) {
115 FOR_EACH_OBSERVER(Observer, observer_list_,
116 OnTextInputStateUpdated(this, updated_view));
117 }
118 FOR_EACH_OBSERVER(Observer, observer_list_,
119 OnTextInputStateUpdateCalled(this));
120 }
121
122 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698