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

Unified 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 (Removing TextInputManager::Observer::OnTextInputManagerDestroyed) 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/renderer_host/text_input_manager.cc
diff --git a/content/browser/renderer_host/text_input_manager.cc b/content/browser/renderer_host/text_input_manager.cc
new file mode 100644
index 0000000000000000000000000000000000000000..b65f4d1c1f4de3980f3adf509bd6cb0b23b9e0e8
--- /dev/null
+++ b/content/browser/renderer_host/text_input_manager.cc
@@ -0,0 +1,113 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/browser/renderer_host/text_input_manager.h"
+
+#include "content/browser/renderer_host/render_widget_host_view_base.h"
+
+namespace content {
+
+namespace {
+
+bool AreDifferentTextInputStates(const content::TextInputState& old_state,
+ const content::TextInputState& new_state) {
+#if defined(USE_AURA)
+ return old_state.type != new_state.type || old_state.mode != new_state.mode ||
+ old_state.flags != new_state.flags ||
+ old_state.can_compose_inline != new_state.can_compose_inline;
+#else
+ // TODO(ekaramad): Implement this logic for other platforms.
+ return true;
+#endif
+}
+
+} // namespace
+
+TextInputManager::TextInputManager() : active_view_(nullptr) {}
+
+TextInputManager::~TextInputManager() {}
+
+const TextInputState* TextInputManager::GetTextInputState() {
+ return !!active_view_ ? &text_input_state_map_[active_view_] : nullptr;
+}
+
+RenderWidgetHostViewBase* TextInputManager::GetActiveView() const {
+ return active_view_;
+}
+
+void TextInputManager::UpdateTextInputState(
+ RenderWidgetHostViewBase* view,
+ const TextInputState& text_input_state) {
+ DCHECK(text_input_state_map_.count(view) == 1);
+
+ bool changed = AreDifferentTextInputStates(text_input_state_map_[view],
+ text_input_state);
+
+ text_input_state_map_[view] = text_input_state;
+
+ // Only change |active_view_| if this new text input state is not none.
+ if (text_input_state.type != ui::TEXT_INPUT_TYPE_NONE)
+ active_view_ = view;
+
+ // If the |active_view_| loses state, then there is no active sources.
+ if (active_view_ == view && text_input_state.type == ui::TEXT_INPUT_TYPE_NONE)
+ active_view_ = nullptr;
+
+ text_input_state_map_[view] = text_input_state;
+ NotifyObserversAboutInputStateUpdate(view, changed);
+}
+
+void TextInputManager::Register(RenderWidgetHostViewBase* view) {
+ DCHECK(text_input_state_map_.count(view) == 0);
+
+ text_input_state_map_[view] = TextInputState();
+ view->AddObserver(this);
+}
+
+void TextInputManager::Unregister(RenderWidgetHostViewBase* view) {
+ DCHECK(text_input_state_map_.count(view) == 1);
+
+ text_input_state_map_.erase(view);
+ if (active_view_ == view) {
+ active_view_ = nullptr;
+ NotifyObserversAboutInputStateUpdate(view, true);
+ }
+ view->RemoveObserver(this);
+}
+
+bool TextInputManager::IsRegisteredView(
+ const RenderWidgetHostViewBase* view) const {
+ return text_input_state_map_.count(view) == 1;
+}
+
+void TextInputManager::AddObserver(Observer* observer) {
+ observer_list_.AddObserver(observer);
+}
+
+void TextInputManager::RemoveObserver(Observer* observer) {
+ observer_list_.RemoveObserver(observer);
+}
+
+void TextInputManager::OnRenderWidgetHostViewBaseDestroyed(
+ RenderWidgetHostViewBase* view) {
+ DCHECK(text_input_state_map_.count(view) == 1);
+
+ Unregister(view);
+
+ if (active_view_ == view) {
+ DCHECK(text_input_state_map_[active_view_].type !=
+ ui::TEXT_INPUT_TYPE_NONE);
+ active_view_ = nullptr;
+ NotifyObserversAboutInputStateUpdate(view, true);
+ }
+}
+
+void TextInputManager::NotifyObserversAboutInputStateUpdate(
+ RenderWidgetHostViewBase* updated_view,
+ bool changed) {
+ FOR_EACH_OBSERVER(Observer, observer_list_,
+ OnTextInputStateUpdated(this, updated_view, changed));
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698