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

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: 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.
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 OnTextInputManagerDestroyed(this));
32 DCHECK(text_input_state_map_.empty());
33 }
34
35 const TextInputState* TextInputManager::GetTextInputState() {
36 return !!active_view_ ? &text_input_state_map_[active_view_] : nullptr;
37 }
38
39 RenderWidgetHostViewBase* TextInputManager::GetActiveView() const {
40 return active_view_;
41 }
42
43 void TextInputManager::UpdateTextInputState(
44 RenderWidgetHostViewBase* view,
45 const TextInputState& text_input_state) {
46 DCHECK(text_input_state_map_.count(view) == 1);
47
48 bool changed = AreDifferentTextInputStates(text_input_state_map_[view],
49 text_input_state);
50
51 text_input_state_map_[view] = text_input_state;
52
53 // Only change |active_view_| if this new text input state is not none.
54 if (text_input_state.type != ui::TEXT_INPUT_TYPE_NONE)
55 active_view_ = view;
56
57 // If the |active_view_| loses state, then there is no active sources.
58 if (active_view_ == view && text_input_state.type == ui::TEXT_INPUT_TYPE_NONE)
59 active_view_ = nullptr;
60
61 text_input_state_map_[view] = text_input_state;
62 NotifyObserversAboutInputStateUpdate(view, changed);
63 }
64
65 void TextInputManager::Register(RenderWidgetHostViewBase* view) {
66 DCHECK(text_input_state_map_.count(view) == 0);
67
68 text_input_state_map_[view] = TextInputState();
69 view->AddObserver(this);
70 AddObserver(view);
71 }
72
73 void TextInputManager::Unregister(RenderWidgetHostViewBase* view) {
74 DCHECK(text_input_state_map_.count(view) == 1);
75
76 text_input_state_map_.erase(view);
77 if (active_view_ == view) {
78 active_view_ = nullptr;
79 NotifyObserversAboutInputStateUpdate(view, true);
80 }
81 view->RemoveObserver(this);
82 RemoveObserver(view);
83 }
84
85 void TextInputManager::AddObserver(Observer* observer) {
86 observer_list_.AddObserver(observer);
87 }
88
89 void TextInputManager::RemoveObserver(Observer* observer) {
90 observer_list_.RemoveObserver(observer);
91 }
92
93 void TextInputManager::OnRenderWidgetHostViewBaseDestroyed(
94 RenderWidgetHostViewBase* view) {
95 DCHECK(text_input_state_map_.count(view) == 1);
96
97 Unregister(view);
98
99 if (active_view_ == view) {
100 DCHECK(text_input_state_map_[active_view_].type !=
101 ui::TEXT_INPUT_TYPE_NONE);
102 active_view_ = nullptr;
103 NotifyObserversAboutInputStateUpdate(view, true);
104 }
105 }
106
107 void TextInputManager::NotifyObserversAboutInputStateUpdate(
108 RenderWidgetHostViewBase* updated_view,
109 bool changed) {
110 FOR_EACH_OBSERVER(Observer, observer_list_,
111 OnTextInputStateUpdated(this, updated_view, changed));
112 }
113
114 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698