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

Unified Diff: chrome/browser/chromeos/input_method/input_method_manager_impl.h

Issue 419293002: IME refactoring: ChromeOS introduce input methods State. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Cleanup. Created 6 years, 4 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: chrome/browser/chromeos/input_method/input_method_manager_impl.h
diff --git a/chrome/browser/chromeos/input_method/input_method_manager_impl.h b/chrome/browser/chromeos/input_method/input_method_manager_impl.h
index 54698e400be37fecc4bbeed613df313fabfd0fd2..44eb28535d27f54e03aab52d942fd2b67471d066 100644
--- a/chrome/browser/chromeos/input_method/input_method_manager_impl.h
+++ b/chrome/browser/chromeos/input_method/input_method_manager_impl.h
@@ -30,16 +30,108 @@ class ImeKeyboard;
class InputMethodManagerImpl : public InputMethodManager,
public CandidateWindowController::Observer {
public:
+ class State : public InputMethodManager::State {
Nikita (slow) 2014/08/13 10:56:41 As discussed, makes sense to rename as StateImpl.
Alexander Alekseev 2014/08/13 23:29:32 Done.
+ public:
+ State(InputMethodManagerImpl* manager, Profile* profile);
+
+ // Init new state as a copy of other.
+ void InitFrom(const State& other);
+
+ // Returns true if (manager_->state_ == this).
+ bool IsActive() const;
+
+ // Returns human-readable dump (for debug).
+ std::string Dump() const;
+
+ // Adds new input method to given list if possible
+ bool EnableInputMethodImpl(
+ const std::string& input_method_id,
+ std::vector<std::string>* new_active_input_method_ids) const;
+
+ // Returns true if |input_method_id| is in |active_input_method_ids|.
+ bool InputMethodIsActivated(const std::string& input_method_id);
+
+ // If |current_input_methodid_| is not in |input_method_ids|, switch to
+ // input_method_ids[0]. If the ID is equal to input_method_ids[N], switch to
+ // input_method_ids[N+1].
+ void SwitchToNextInputMethodInternal(
+ const std::vector<std::string>& input_method_ids,
+ const std::string& current_input_methodid);
+
+ // InputMethodManager::State overrides.
+ virtual void AddInputMethodExtension(
+ const std::string& extension_id,
+ const InputMethodDescriptors& descriptors,
+ InputMethodEngineInterface* instance) OVERRIDE;
+ virtual void RemoveInputMethodExtension(
+ const std::string& extension_id) OVERRIDE;
+ virtual void ChangeInputMethod(const std::string& input_method_id,
+ bool show_message) OVERRIDE;
+ virtual bool EnableInputMethod(
+ const std::string& new_active_input_method_id) OVERRIDE;
+ virtual void EnableLoginLayouts(
+ const std::string& language_code,
+ const std::vector<std::string>& initial_layouts) OVERRIDE;
+ virtual void EnableLockScreenLayouts() OVERRIDE;
+ virtual void GetInputMethodExtensions(
+ InputMethodDescriptors* result) OVERRIDE;
+ virtual scoped_ptr<InputMethodDescriptors> GetActiveInputMethods()
+ const OVERRIDE;
+ virtual const std::vector<std::string>& GetActiveInputMethodIds()
+ const OVERRIDE;
+ virtual const InputMethodDescriptor* GetInputMethodFromId(
+ const std::string& input_method_id) const OVERRIDE;
+ virtual size_t GetNumActiveInputMethods() const OVERRIDE;
+ virtual void SetEnabledExtensionImes(
+ std::vector<std::string>* ids) OVERRIDE;
+ virtual void SetInputMethodLoginDefault() OVERRIDE;
+ virtual void SetInputMethodLoginDefaultFromVPD(
+ const std::string& locale,
+ const std::string& layout) OVERRIDE;
+ virtual bool SwitchToNextInputMethod() OVERRIDE;
+ virtual bool SwitchToPreviousInputMethod(
+ const ui::Accelerator& accelerator) OVERRIDE;
+ virtual bool SwitchInputMethod(const ui::Accelerator& accelerator) OVERRIDE;
+ virtual InputMethodDescriptor GetCurrentInputMethod() const OVERRIDE;
+ virtual bool ReplaceEnabledInputMethods(
+ const std::vector<std::string>& new_active_input_method_ids) OVERRIDE;
+
+ // ------------------------- Data members.
+ Profile* const profile;
+
+ // The input method which was/is selected.
+ InputMethodDescriptor previous_input_method;
+ InputMethodDescriptor current_input_method;
+
+ // The active input method ids cache.
+ std::vector<std::string> active_input_method_ids;
+
+ // The list of enabled extension IMEs.
+ std::vector<std::string> enabled_extension_imes;
+
+ // Extra input methods that have been explicitly added to the menu, such as
+ // those created by extension.
+ std::map<std::string, InputMethodDescriptor> extra_input_methods;
+
+ private:
+ InputMethodManagerImpl* const manager_;
+
+ protected:
+ friend base::RefCounted<chromeos::input_method::InputMethodManager::State>;
+ virtual ~State();
+ };
+
// Constructs an InputMethodManager instance. The client is responsible for
- // calling |SetState| in response to relevant changes in browser state.
+ // calling |SetUISessionState| in response to relevant changes in browser
+ // state.
explicit InputMethodManagerImpl(scoped_ptr<InputMethodDelegate> delegate);
virtual ~InputMethodManagerImpl();
- // Receives notification of an InputMethodManager::State transition.
- void SetState(State new_state);
+ // Receives notification of an InputMethodManager::UISessionState transition.
+ void SetUISessionState(UISessionState new_ui_session);
// InputMethodManager override:
- virtual void InitializeComponentExtension() OVERRIDE;
+ virtual void InitializeComponentExtension(Profile* profile) OVERRIDE;
virtual void AddObserver(InputMethodManager::Observer* observer) OVERRIDE;
virtual void AddCandidateWindowObserver(
InputMethodManager::CandidateWindowObserver* observer) OVERRIDE;
@@ -48,39 +140,7 @@ class InputMethodManagerImpl : public InputMethodManager,
InputMethodManager::CandidateWindowObserver* observer) OVERRIDE;
virtual scoped_ptr<InputMethodDescriptors>
GetSupportedInputMethods() const OVERRIDE;
- virtual scoped_ptr<InputMethodDescriptors>
- GetActiveInputMethods() const OVERRIDE;
- virtual const std::vector<std::string>& GetActiveInputMethodIds() const
- OVERRIDE;
- virtual size_t GetNumActiveInputMethods() const OVERRIDE;
- virtual const InputMethodDescriptor* GetInputMethodFromId(
- const std::string& input_method_id) const OVERRIDE;
- virtual void EnableLoginLayouts(
- const std::string& language_code,
- const std::vector<std::string>& initial_layouts) OVERRIDE;
- virtual bool ReplaceEnabledInputMethods(
- const std::vector<std::string>& new_active_input_method_ids) OVERRIDE;
- virtual bool EnableInputMethod(const std::string& new_active_input_method_id)
- OVERRIDE;
- virtual void ChangeInputMethod(const std::string& input_method_id) OVERRIDE;
virtual void ActivateInputMethodMenuItem(const std::string& key) OVERRIDE;
- virtual void AddInputMethodExtension(
- const std::string& extension_id,
- const InputMethodDescriptors& descriptors,
- InputMethodEngineInterface* instance) OVERRIDE;
- virtual void RemoveInputMethodExtension(
- const std::string& extension_id) OVERRIDE;
- virtual void GetInputMethodExtensions(
- InputMethodDescriptors* result) OVERRIDE;
- virtual void SetEnabledExtensionImes(std::vector<std::string>* ids) OVERRIDE;
- virtual void SetInputMethodLoginDefault() OVERRIDE;
- virtual void SetInputMethodLoginDefaultFromVPD(
- const std::string& locale, const std::string& layout) OVERRIDE;
- virtual bool SwitchToNextInputMethod() OVERRIDE;
- virtual bool SwitchToPreviousInputMethod(
- const ui::Accelerator& accelerator) OVERRIDE;
- virtual bool SwitchInputMethod(const ui::Accelerator& accelerator) OVERRIDE;
- virtual InputMethodDescriptor GetCurrentInputMethod() const OVERRIDE;
virtual bool IsISOLevel5ShiftUsedByCurrentInputMethod() const OVERRIDE;
virtual bool IsAltGrUsedByCurrentInputMethod() const OVERRIDE;
@@ -93,6 +153,15 @@ class InputMethodManagerImpl : public InputMethodManager,
virtual bool MigrateInputMethods(
std::vector<std::string>* input_method_ids) OVERRIDE;
+ virtual scoped_refptr<InputMethodManager::State> GetDefaultState(
+ Profile* profile) OVERRIDE;
+
+ virtual scoped_refptr<InputMethodManager::State> GetActiveIMEState() OVERRIDE;
+ virtual scoped_refptr<InputMethodManager::State> CloneState(
+ const InputMethodManager::State* state) OVERRIDE;
+ virtual void SetState(
+ scoped_refptr<InputMethodManager::State> state) OVERRIDE;
+
// Sets |candidate_window_controller_|.
void SetCandidateWindowControllerForTesting(
CandidateWindowController* candidate_window_controller);
@@ -120,9 +189,6 @@ class InputMethodManagerImpl : public InputMethodManager,
// current input method as needed.
void OnScreenUnlocked();
- // Returns true if |input_method_id| is in |active_input_method_ids_|.
- bool InputMethodIsActivated(const std::string& input_method_id);
-
// Returns true if the given input method config value is a string list
// that only contains an input method ID of a keyboard layout.
bool ContainsOnlyKeyboardLayout(const std::vector<std::string>& value);
@@ -131,59 +197,35 @@ class InputMethodManagerImpl : public InputMethodManager,
// done.
void MaybeInitializeCandidateWindowController();
- // If |current_input_method_id_| is not in |input_method_ids|, switch to
- // input_method_ids[0]. If the ID is equal to input_method_ids[N], switch to
- // input_method_ids[N+1].
- void SwitchToNextInputMethodInternal(
- const std::vector<std::string>& input_method_ids,
- const std::string& current_input_method_id);
+ // Returns Input Method that best matches given id.
+ const InputMethodDescriptor* LookupInputMethod(
+ const std::string& input_method_id,
+ State* state);
// Change system input method.
- // Returns true if the system input method is changed.
- bool ChangeInputMethodInternal(const std::string& input_method_id,
- bool show_message);
+ void ChangeInputMethodInternal(const InputMethodDescriptor& descriptor,
+ bool show_message,
+ bool notify_menu);
// Loads necessary component extensions.
// TODO(nona): Support dynamical unloading.
- void LoadNecessaryComponentExtensions();
-
- // Adds new input method to given list if possible
- bool EnableInputMethodImpl(
- const std::string& input_method_id,
- std::vector<std::string>* new_active_input_method_ids) const;
+ void LoadNecessaryComponentExtensions(State*);
// Starts or stops the system input method framework as needed.
- // (after list of enabled input methods has been updated)
- void ReconfigureIMFramework();
+ // (after list of enabled input methods has been updated).
+ // If state is active, active input method is updated.
+ void ReconfigureIMFramework(State* state);
scoped_ptr<InputMethodDelegate> delegate_;
// The current browser status.
- State state_;
+ UISessionState ui_session_;
Shu Chen 2014/08/13 16:15:34 pls update the comment.
Alexander Alekseev 2014/08/13 23:29:32 Done.
// A list of objects that monitor the manager.
ObserverList<InputMethodManager::Observer> observers_;
ObserverList<CandidateWindowObserver> candidate_window_observers_;
- // The input method which was/is selected.
- InputMethodDescriptor previous_input_method_;
- InputMethodDescriptor current_input_method_;
- // The active input method ids cache.
- std::vector<std::string> active_input_method_ids_;
-
- // The list of enabled extension IMEs.
- std::vector<std::string> enabled_extension_imes_;
-
- // For screen locker. When the screen is locked, |previous_input_method_|,
- // |current_input_method_|, and |active_input_method_ids_| above are copied
- // to these "saved" variables.
- InputMethodDescriptor saved_previous_input_method_;
- InputMethodDescriptor saved_current_input_method_;
- std::vector<std::string> saved_active_input_method_ids_;
-
- // Extra input methods that have been explicitly added to the menu, such as
- // those created by extension.
- std::map<std::string, InputMethodDescriptor> extra_input_methods_;
+ scoped_refptr<State> state_;
// The candidate window. This will be deleted when the APP_TERMINATING
// message is sent.
@@ -203,9 +245,12 @@ class InputMethodManagerImpl : public InputMethodManager,
base::ThreadChecker thread_checker_;
base::WeakPtrFactory<InputMethodManagerImpl> weak_ptr_factory_;
Shu Chen 2014/08/13 16:15:33 add a blank line.
Alexander Alekseev 2014/08/13 23:29:32 Done.
-
// The engine map from extension_id to an engine.
- std::map<std::string, InputMethodEngineInterface*> engine_map_;
+ typedef std::map<std::string, InputMethodEngineInterface*> EngineMap;
+ EngineMap engine_map_;
+
+ // Default profile states.
+ std::map<Profile*, scoped_refptr<State> > default_states_;
Shu Chen 2014/08/13 16:15:34 Can you please add comments to explain for what do
Alexander Alekseev 2014/08/13 23:29:32 Before your recent CL, there were two independant
DISALLOW_COPY_AND_ASSIGN(InputMethodManagerImpl);
};

Powered by Google App Engine
This is Rietveld 408576698