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

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: Rebase (Code changed during CQ Dry-run) Created 4 years, 6 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 the logic for other platforms (crbug.com/578168).
21 NOTREACHED();
22 return true;
23 #endif
24 }
25
26 } // namespace
27
28 TextInputManager::TextInputManager() : active_view_(nullptr) {}
29
30 TextInputManager::~TextInputManager() {
31 // If there is an active view, we should unregister it first so that the
32 // the tab's top-level RWHV will be notified about |TextInputState.type|
33 // resetting to none (i.e., we do not have an active RWHV anymore).
34 if (active_view_)
35 Unregister(active_view_);
36
37 // Unregister all the remaining views.
38 std::vector<RenderWidgetHostViewBase*> views;
39 for (auto pair : text_input_state_map_)
40 views.push_back(pair.first);
41
42 for (auto view : views)
43 Unregister(view);
44 }
45
46 const TextInputState* TextInputManager::GetTextInputState() {
47 return !!active_view_ ? &text_input_state_map_[active_view_] : nullptr;
48 }
49
50 RenderWidgetHostViewBase* TextInputManager::GetActiveView() const {
51 return active_view_;
52 }
53
54 void TextInputManager::UpdateTextInputState(
55 RenderWidgetHostViewBase* view,
56 const TextInputState& text_input_state) {
57 DCHECK(IsRegistered(view));
58
59 // Since |view| is registgered, we already have a previous value for its
60 // TextInputState.
61 bool changed = AreDifferentTextInputStates(text_input_state_map_[view],
62 text_input_state);
63
64 text_input_state_map_[view] = text_input_state;
65
66 // |active_view_| is only updated when the state for |view| is not none.
67 if (text_input_state.type != ui::TEXT_INPUT_TYPE_NONE)
68 active_view_ = view;
69
70 // If the state for |active_view_| is none, then we no longer have an
71 // |active_view_|.
72 if (active_view_ == view && text_input_state.type == ui::TEXT_INPUT_TYPE_NONE)
73 active_view_ = nullptr;
74
75 NotifyObserversAboutInputStateUpdate(view, changed);
76 }
77
78 void TextInputManager::Register(RenderWidgetHostViewBase* view) {
79 DCHECK(!IsRegistered(view));
80
81 text_input_state_map_[view] = TextInputState();
82 }
83
84 void TextInputManager::Unregister(RenderWidgetHostViewBase* view) {
85 DCHECK(IsRegistered(view));
86
87 text_input_state_map_.erase(view);
88 if (active_view_ == view) {
89 active_view_ = nullptr;
90 NotifyObserversAboutInputStateUpdate(view, true);
91 }
92 view->DidUnregisterFromTextInputManager(this);
93 }
94
95 bool TextInputManager::IsRegistered(RenderWidgetHostViewBase* view) const {
96 return text_input_state_map_.count(view) == 1;
97 }
98
99 void TextInputManager::AddObserver(Observer* observer) {
100 observer_list_.AddObserver(observer);
101 }
102
103 void TextInputManager::RemoveObserver(Observer* observer) {
104 observer_list_.RemoveObserver(observer);
105 }
106
107 void TextInputManager::NotifyObserversAboutInputStateUpdate(
108 RenderWidgetHostViewBase* updated_view,
109 bool did_update_state) {
110 FOR_EACH_OBSERVER(
111 Observer, observer_list_,
112 OnUpdateTextInputStateCalled(this, updated_view, did_update_state));
113 }
114
115 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/text_input_manager.h ('k') | content/browser/web_contents/web_contents_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698