Chromium Code Reviews| Index: content/browser/renderer_host/text_input_manager.h |
| diff --git a/content/browser/renderer_host/text_input_manager.h b/content/browser/renderer_host/text_input_manager.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..c90d9a540a1eefdfbed39afbf94a6c59a2ad1f3f |
| --- /dev/null |
| +++ b/content/browser/renderer_host/text_input_manager.h |
| @@ -0,0 +1,108 @@ |
| +// 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. |
| + |
| +#ifndef CONTENT_BROWSER_TEXT_INPUT_MANAGER_H__ |
|
Charlie Reis
2016/05/18 20:46:04
nit: Missing RENDERER_HOST
EhsanK
2016/05/24 20:42:46
Uh yes...I moved this file around a lot. Sorry. :)
|
| +#define CONTENT_BROWSER_TEXT_INPUT_MANAGER_H__ |
| + |
| +#include <unordered_map> |
| + |
| +#include "base/observer_list.h" |
| +#include "content/browser/renderer_host/render_widget_host_view_base_observer.h" |
| +#include "content/common/content_export.h" |
| +#include "content/common/text_input_state.h" |
| + |
| +namespace content { |
| + |
| +class RenderWidgetHostViewBase; |
| +class TestTextInputManagerObserver; |
|
Charlie Reis
2016/05/18 20:46:04
This shouldn't be needed.
EhsanK
2016/05/24 20:42:45
Done.
|
| + |
| +// A class which receives updates of Text Input State from multiple sources and |
|
Charlie Reis
2016/05/18 20:46:04
nit: Remove extra space.
Also, let's be consistent
EhsanK
2016/05/24 20:42:45
Acknowledged. I think to be consistent I should ha
|
| +// decides what the new text input state is. It also notifies the observers when |
| +// text input state is updated. |
| +class CONTENT_EXPORT TextInputManager |
| + : public RenderWidgetHostViewBaseObserver { |
|
Charlie Reis
2016/05/18 20:46:04
It's a bit unfortunate that these two classes need
EhsanK
2016/05/24 20:42:45
I was worried about the observing loop to become c
Charlie Reis
2016/05/26 06:22:03
Thanks-- it's much easier to follow with the obser
|
| + public: |
| + // The top-level tab RWHV should be an observer of TextInputManager to get |
|
Charlie Reis
2016/05/18 20:46:04
nit: The tab's top-level RWHV
EhsanK
2016/05/24 20:42:45
Done.
|
| + // notifications about changes in TextInputState or other IME related state |
| + // for child frames. |
| + class CONTENT_EXPORT Observer { |
| + public: |
| + // Called when the TextInputState for |view| has changed from its previous |
| + // value. The change is determined on each platform differently by only |
| + // considering the change in the value of a subset of fields in the |
| + // TextInputState. |
| + virtual void OnTextInputStateUpdated(TextInputManager* text_input_manager, |
|
Charlie Reis
2016/05/18 20:46:04
I'm curious why the |text_input_manager| parameter
EhsanK
2016/05/24 20:42:45
Yes that is all we do for now. The only possible c
Charlie Reis
2016/05/26 06:22:03
I think that only matters when you listen to more
|
| + RenderWidgetHostViewBase* view) {} |
| + |
| + // Called when a view has called UpdateTextInputState on TextInputManager, |
| + // regardless the call having lead to change in TextInputState. In some |
|
Charlie Reis
2016/05/18 20:46:04
nit: regardless of whether the call led to
EhsanK
2016/05/24 20:42:45
Done.
|
| + // platforms this is necessary as it gives the tab-level |view| the chance |
| + // do some other task, e.g., show IME if needed in Aura. |
| + virtual void OnTextInputStateUpdateCalled( |
|
Charlie Reis
2016/05/18 20:46:04
Why do we need both this and OnTextInputStateUpdat
EhsanK
2016/05/24 20:42:45
Hmm. I think I took the less efficient solution to
Charlie Reis
2016/05/26 06:22:03
I wouldn't worry about it unless there's a substan
|
| + TextInputManager* text_input_manager) {} |
| + |
| + // Notifies all the observers that |text_input_manager| is being destroyed. |
|
Charlie Reis
2016/05/18 20:46:04
Let's be consistent with how the other observer me
EhsanK
2016/05/24 20:42:45
Acknowledged.
|
| + // TODO(ekaramad): All RWHV should get this call, but only the top-level |
| + // RWHV for the outermost WebContents should be called on the other observer |
| + // methods. We should separate the two classes of observers when resolving |
| + // crbug.com/609846. |
| + virtual void OnDestroyingTextInputManager( |
| + TextInputManager* text_input_manager) {} |
| + }; |
| + |
| + explicit TextInputManager(); |
|
Charlie Reis
2016/05/18 20:46:04
No need for explicit unless you have a single para
EhsanK
2016/05/24 20:42:46
On 2016/05/18 20:46:04, Charlie Reis (slow to repl
|
| + ~TextInputManager() override; |
| + |
| + // Returns the current text input state corresponding to |active_source_|. |
|
Charlie Reis
2016/05/18 20:46:04
nit: TextInputState (here and below)
nit: s/|activ
EhsanK
2016/05/24 20:42:45
Done.
|
| + // Users of this method should not hold on to the pointer as it might become |
| + // dangling if the TextInputManager or |active_view_| might go away. |
| + const TextInputState* GetTextInputState(); |
| + |
| + // Returns the currently active view. The active view is the last |
| + // RenderWidgetHostViewBase which reported a |TextInputState.type| of other |
| + // than ui::TEXT_INPUT_TYPE_NONE. |
| + RenderWidgetHostViewBase* GetActiveView() const; |
|
Charlie Reis
2016/05/18 20:46:04
Can this ever be null? Looks like active_view_ is
EhsanK
2016/05/24 20:42:45
It is nullptr initially, and whenever we lose focu
|
| + |
| + // Updates the text input state for |view|. |
| + void UpdateTextInputState(RenderWidgetHostViewBase* view, |
| + const TextInputState& state); |
| + |
| + // Registers the given |view| for tracking its TextInputState. |
| + // TextInputManager will observe the lifetime of the |view|. |
| + void Register(RenderWidgetHostViewBase* view); |
| + |
| + // Clear text input state of |view| and removes TextInputManager from its |
| + // observer list. It is important to call this for any RWHV being tracked |
| + // before destruction of RWHV or TextInputManager. |
|
Charlie Reis
2016/05/18 20:46:04
"or TextInputManager" -> Should we add a DCHECK th
EhsanK
2016/05/24 20:42:45
It depends whether we want the un-registering to h
Charlie Reis
2016/05/26 06:22:03
Acknowledged.
|
| + void Unregister(RenderWidgetHostViewBase* view); |
| + |
| + // Returns true if |view| is already registered. |
| + bool IsRegisteredView(RenderWidgetHostViewBase* view) const; |
|
Charlie Reis
2016/05/18 20:46:04
nit: IsRegistered (to be consistent with Register
EhsanK
2016/05/24 20:42:45
Done.
|
| + |
| + void AddObserver(Observer* observer); |
| + void RemoveObserver(Observer* observer); |
| + |
| + private: |
| + friend class TestTextInputManagerObserver; |
| + |
| + // RenderWidgetHostViewObserver implementation. |
|
Charlie Reis
2016/05/18 20:46:04
nit: Missing "Base" from name.
EhsanK
2016/05/24 20:42:45
Yes sorry. But I removed this method following the
|
| + void OnRenderWidgetHostViewBaseDestroyed( |
| + RenderWidgetHostViewBase* view) override; |
| + |
| + void NotifyObserversAboutInputStateUpdate(RenderWidgetHostViewBase* view, |
| + bool state_changed); |
| + |
| + // The view with active text input state. |
| + RenderWidgetHostViewBase* active_view_; |
| + |
| + std::unordered_map<RenderWidgetHostViewBase*, TextInputState> |
| + text_input_state_map_; |
| + |
| + base::ObserverList<Observer> observer_list_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(TextInputManager); |
| +}; |
| +} |
| + |
| +#endif // CONTENT_BROWSER_TEXT_INPUT_MANAGER_H__ |