New method: InputMethod::IsCandidatePopupOpen()

Supports a new method {ui,views}::InputMethod::IsCandidatePopupOpen(),
which returns true if a candidate window is open.

BUG=245578
TEST=Test manually.

Review URL: https://chromiumcodereview.appspot.com/17112021

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@207858 0039d316-1c4b-4281-b951-d872f2087c98
parent f16fcd76
...@@ -76,6 +76,10 @@ bool DummyInputMethod::CanComposeInline() const { ...@@ -76,6 +76,10 @@ bool DummyInputMethod::CanComposeInline() const {
return true; return true;
} }
bool DummyInputMethod::IsCandidatePopupOpen() const {
return false;
}
void DummyInputMethod::AddObserver(InputMethodObserver* observer) { void DummyInputMethod::AddObserver(InputMethodObserver* observer) {
} }
......
...@@ -37,6 +37,7 @@ class DummyInputMethod : public InputMethod { ...@@ -37,6 +37,7 @@ class DummyInputMethod : public InputMethod {
virtual bool IsActive() OVERRIDE; virtual bool IsActive() OVERRIDE;
virtual TextInputType GetTextInputType() const OVERRIDE; virtual TextInputType GetTextInputType() const OVERRIDE;
virtual bool CanComposeInline() const OVERRIDE; virtual bool CanComposeInline() const OVERRIDE;
virtual bool IsCandidatePopupOpen() const OVERRIDE;
virtual void AddObserver(InputMethodObserver* observer) OVERRIDE; virtual void AddObserver(InputMethodObserver* observer) OVERRIDE;
virtual void RemoveObserver(InputMethodObserver* observer) OVERRIDE; virtual void RemoveObserver(InputMethodObserver* observer) OVERRIDE;
......
...@@ -137,6 +137,10 @@ bool FakeInputMethod::IsActive() { ...@@ -137,6 +137,10 @@ bool FakeInputMethod::IsActive() {
return true; return true;
} }
bool FakeInputMethod::IsCandidatePopupOpen() const {
return false;
}
ui::TextInputType FakeInputMethod::GetTextInputType() const { ui::TextInputType FakeInputMethod::GetTextInputType() const {
return ui::TEXT_INPUT_TYPE_NONE; return ui::TEXT_INPUT_TYPE_NONE;
} }
......
...@@ -46,6 +46,7 @@ class UI_EXPORT FakeInputMethod : NON_EXPORTED_BASE(public InputMethod) { ...@@ -46,6 +46,7 @@ class UI_EXPORT FakeInputMethod : NON_EXPORTED_BASE(public InputMethod) {
virtual bool IsActive() OVERRIDE; virtual bool IsActive() OVERRIDE;
virtual ui::TextInputType GetTextInputType() const OVERRIDE; virtual ui::TextInputType GetTextInputType() const OVERRIDE;
virtual bool CanComposeInline() const OVERRIDE; virtual bool CanComposeInline() const OVERRIDE;
virtual bool IsCandidatePopupOpen() const OVERRIDE;
virtual void AddObserver(InputMethodObserver* observer) OVERRIDE; virtual void AddObserver(InputMethodObserver* observer) OVERRIDE;
virtual void RemoveObserver(InputMethodObserver* observer) OVERRIDE; virtual void RemoveObserver(InputMethodObserver* observer) OVERRIDE;
......
...@@ -147,6 +147,11 @@ class InputMethod { ...@@ -147,6 +147,11 @@ class InputMethod {
// Checks if the focused text input client supports inline composition. // Checks if the focused text input client supports inline composition.
virtual bool CanComposeInline() const = 0; virtual bool CanComposeInline() const = 0;
// Returns true if we know for sure that a candidate window (or IME suggest,
// etc.) is open. Returns false if no popup window is open or the detection
// of IME popups is not supported.
virtual bool IsCandidatePopupOpen() const = 0;
// Management of the observer list. // Management of the observer list.
virtual void AddObserver(InputMethodObserver* observer) = 0; virtual void AddObserver(InputMethodObserver* observer) = 0;
virtual void RemoveObserver(InputMethodObserver* observer) = 0; virtual void RemoveObserver(InputMethodObserver* observer) = 0;
......
...@@ -337,6 +337,11 @@ bool InputMethodIBus::IsActive() { ...@@ -337,6 +337,11 @@ bool InputMethodIBus::IsActive() {
return true; return true;
} }
bool InputMethodIBus::IsCandidatePopupOpen() const {
// TODO(yukishiino): Implement this method.
return false;
}
void InputMethodIBus::OnWillChangeFocusedClient(TextInputClient* focused_before, void InputMethodIBus::OnWillChangeFocusedClient(TextInputClient* focused_before,
TextInputClient* focused) { TextInputClient* focused) {
ConfirmCompositionText(); ConfirmCompositionText();
......
...@@ -54,6 +54,7 @@ class UI_EXPORT InputMethodIBus ...@@ -54,6 +54,7 @@ class UI_EXPORT InputMethodIBus
virtual std::string GetInputLocale() OVERRIDE; virtual std::string GetInputLocale() OVERRIDE;
virtual base::i18n::TextDirection GetInputTextDirection() OVERRIDE; virtual base::i18n::TextDirection GetInputTextDirection() OVERRIDE;
virtual bool IsActive() OVERRIDE; virtual bool IsActive() OVERRIDE;
virtual bool IsCandidatePopupOpen() const OVERRIDE;
protected: protected:
// chromeos::IBusDaemonController::Observer overrides. // chromeos::IBusDaemonController::Observer overrides.
......
...@@ -14,7 +14,7 @@ namespace ui { ...@@ -14,7 +14,7 @@ namespace ui {
InputMethodIMM32::InputMethodIMM32(internal::InputMethodDelegate* delegate, InputMethodIMM32::InputMethodIMM32(internal::InputMethodDelegate* delegate,
HWND toplevel_window_handle) HWND toplevel_window_handle)
: InputMethodWin(delegate, toplevel_window_handle), : InputMethodWin(delegate, toplevel_window_handle),
enabled_(false), enabled_(false), is_candidate_popup_open_(false),
composing_window_handle_(NULL) { composing_window_handle_(NULL) {
// In non-Aura environment, appropriate callbacks to OnFocus() and OnBlur() // In non-Aura environment, appropriate callbacks to OnFocus() and OnBlur()
// are not implemented yet. To work around this limitation, here we use // are not implemented yet. To work around this limitation, here we use
...@@ -71,6 +71,10 @@ bool InputMethodIMM32::OnUntranslatedIMEMessage( ...@@ -71,6 +71,10 @@ bool InputMethodIMM32::OnUntranslatedIMEMessage(
original_result = OnDeadChar( original_result = OnDeadChar(
event.message, event.wParam, event.lParam, &handled); event.message, event.wParam, event.lParam, &handled);
break; break;
case WM_IME_NOTIFY:
original_result = OnImeNotify(
event.message, event.wParam, event.lParam, &handled);
break;
default: default:
NOTREACHED() << "Unknown IME message:" << event.message; NOTREACHED() << "Unknown IME message:" << event.message;
break; break;
...@@ -121,6 +125,10 @@ void InputMethodIMM32::SetFocusedTextInputClient(TextInputClient* client) { ...@@ -121,6 +125,10 @@ void InputMethodIMM32::SetFocusedTextInputClient(TextInputClient* client) {
InputMethodWin::SetFocusedTextInputClient(client); InputMethodWin::SetFocusedTextInputClient(client);
} }
bool InputMethodIMM32::IsCandidatePopupOpen() const {
return is_candidate_popup_open_;
}
void InputMethodIMM32::OnWillChangeFocusedClient( void InputMethodIMM32::OnWillChangeFocusedClient(
TextInputClient* focused_before, TextInputClient* focused_before,
TextInputClient* focused) { TextInputClient* focused) {
...@@ -227,6 +235,25 @@ LRESULT InputMethodIMM32::OnImeEndComposition(HWND window_handle, ...@@ -227,6 +235,25 @@ LRESULT InputMethodIMM32::OnImeEndComposition(HWND window_handle,
return 0; return 0;
} }
LRESULT InputMethodIMM32::OnImeNotify(UINT message,
WPARAM wparam,
LPARAM lparam,
BOOL* handled) {
*handled = FALSE;
// Update |is_candidate_popup_open_|, whether a candidate window is open.
switch (wparam) {
case IMN_OPENCANDIDATE:
is_candidate_popup_open_ = true;
break;
case IMN_CLOSECANDIDATE:
is_candidate_popup_open_ = false;
break;
}
return 0;
}
void InputMethodIMM32::ConfirmCompositionText() { void InputMethodIMM32::ConfirmCompositionText() {
if (composing_window_handle_) if (composing_window_handle_)
ime_input_.CleanupComposition(composing_window_handle_); ime_input_.CleanupComposition(composing_window_handle_);
......
...@@ -30,6 +30,7 @@ class UI_EXPORT InputMethodIMM32 : public InputMethodWin { ...@@ -30,6 +30,7 @@ class UI_EXPORT InputMethodIMM32 : public InputMethodWin {
virtual void OnCaretBoundsChanged(const TextInputClient* client) OVERRIDE; virtual void OnCaretBoundsChanged(const TextInputClient* client) OVERRIDE;
virtual void CancelComposition(const TextInputClient* client) OVERRIDE; virtual void CancelComposition(const TextInputClient* client) OVERRIDE;
virtual void SetFocusedTextInputClient(TextInputClient* client) OVERRIDE; virtual void SetFocusedTextInputClient(TextInputClient* client) OVERRIDE;
virtual bool IsCandidatePopupOpen() const OVERRIDE;
protected: protected:
// Overridden from InputMethodBase: // Overridden from InputMethodBase:
...@@ -59,6 +60,10 @@ class UI_EXPORT InputMethodIMM32 : public InputMethodWin { ...@@ -59,6 +60,10 @@ class UI_EXPORT InputMethodIMM32 : public InputMethodWin {
WPARAM wparam, WPARAM wparam,
LPARAM lparam, LPARAM lparam,
BOOL* handled); BOOL* handled);
LRESULT OnImeNotify(UINT message,
WPARAM wparam,
LPARAM lparam,
BOOL* handled);
// Asks the client to confirm current composition text. // Asks the client to confirm current composition text.
void ConfirmCompositionText(); void ConfirmCompositionText();
...@@ -72,6 +77,9 @@ class UI_EXPORT InputMethodIMM32 : public InputMethodWin { ...@@ -72,6 +77,9 @@ class UI_EXPORT InputMethodIMM32 : public InputMethodWin {
bool enabled_; bool enabled_;
// True if we know for sure that a candidate window is open.
bool is_candidate_popup_open_;
// Window handle where composition is on-going. NULL when there is no // Window handle where composition is on-going. NULL when there is no
// composition. // composition.
HWND composing_window_handle_; HWND composing_window_handle_;
......
...@@ -93,6 +93,11 @@ void InputMethodTSF::SetFocusedTextInputClient(TextInputClient* client) { ...@@ -93,6 +93,11 @@ void InputMethodTSF::SetFocusedTextInputClient(TextInputClient* client) {
InputMethodWin::SetFocusedTextInputClient(client); InputMethodWin::SetFocusedTextInputClient(client);
} }
bool InputMethodTSF::IsCandidatePopupOpen() const {
// TODO(yukishiino): Implement this method.
return false;
}
void InputMethodTSF::OnWillChangeFocusedClient(TextInputClient* focused_before, void InputMethodTSF::OnWillChangeFocusedClient(TextInputClient* focused_before,
TextInputClient* focused) { TextInputClient* focused) {
if (IsWindowFocused(focused_before)) { if (IsWindowFocused(focused_before)) {
......
...@@ -28,6 +28,7 @@ class UI_EXPORT InputMethodTSF : public InputMethodWin { ...@@ -28,6 +28,7 @@ class UI_EXPORT InputMethodTSF : public InputMethodWin {
virtual void OnCaretBoundsChanged(const TextInputClient* client) OVERRIDE; virtual void OnCaretBoundsChanged(const TextInputClient* client) OVERRIDE;
virtual void CancelComposition(const TextInputClient* client) OVERRIDE; virtual void CancelComposition(const TextInputClient* client) OVERRIDE;
virtual void SetFocusedTextInputClient(TextInputClient* client) OVERRIDE; virtual void SetFocusedTextInputClient(TextInputClient* client) OVERRIDE;
virtual bool IsCandidatePopupOpen() const OVERRIDE;
// Overridden from InputMethodBase: // Overridden from InputMethodBase:
virtual void OnWillChangeFocusedClient(TextInputClient* focused_before, virtual void OnWillChangeFocusedClient(TextInputClient* focused_before,
......
...@@ -91,6 +91,10 @@ bool MockInputMethod::CanComposeInline() const { ...@@ -91,6 +91,10 @@ bool MockInputMethod::CanComposeInline() const {
return true; return true;
} }
bool MockInputMethod::IsCandidatePopupOpen() const {
return false;
}
void MockInputMethod::AddObserver(InputMethodObserver* observer) { void MockInputMethod::AddObserver(InputMethodObserver* observer) {
observer_list_.AddObserver(static_cast<Observer*>(observer)); observer_list_.AddObserver(static_cast<Observer*>(observer));
} }
......
...@@ -61,6 +61,7 @@ class UI_EXPORT MockInputMethod : NON_EXPORTED_BASE(public InputMethod) { ...@@ -61,6 +61,7 @@ class UI_EXPORT MockInputMethod : NON_EXPORTED_BASE(public InputMethod) {
virtual bool IsActive() OVERRIDE; virtual bool IsActive() OVERRIDE;
virtual TextInputType GetTextInputType() const OVERRIDE; virtual TextInputType GetTextInputType() const OVERRIDE;
virtual bool CanComposeInline() const OVERRIDE; virtual bool CanComposeInline() const OVERRIDE;
virtual bool IsCandidatePopupOpen() const OVERRIDE;
virtual void AddObserver(InputMethodObserver* observer) OVERRIDE; virtual void AddObserver(InputMethodObserver* observer) OVERRIDE;
virtual void RemoveObserver(InputMethodObserver* observer) OVERRIDE; virtual void RemoveObserver(InputMethodObserver* observer) OVERRIDE;
......
...@@ -113,6 +113,11 @@ class VIEWS_EXPORT InputMethod { ...@@ -113,6 +113,11 @@ class VIEWS_EXPORT InputMethod {
// ui::TEXT_INPUT_TYPE_NONE if there is no focused text input client. // ui::TEXT_INPUT_TYPE_NONE if there is no focused text input client.
virtual ui::TextInputType GetTextInputType() const = 0; virtual ui::TextInputType GetTextInputType() const = 0;
// Returns true if we know for sure that a candidate window (or IME suggest,
// etc.) is open. Returns false if no popup window is open or the detection
// of IME popups is not supported.
virtual bool IsCandidatePopupOpen() const = 0;
// Returns true if the input method is a mock instance used for testing. // Returns true if the input method is a mock instance used for testing.
virtual bool IsMock() const = 0; virtual bool IsMock() const = 0;
......
...@@ -94,6 +94,10 @@ bool InputMethodBridge::IsActive() { ...@@ -94,6 +94,10 @@ bool InputMethodBridge::IsActive() {
return host_->IsActive(); return host_->IsActive();
} }
bool InputMethodBridge::IsCandidatePopupOpen() const {
return host_->IsCandidatePopupOpen();
}
// Overridden from TextInputClient. Forward an event from the system-wide IME // Overridden from TextInputClient. Forward an event from the system-wide IME
// to the text input |client|, which is e.g. views::NativeTextfieldViews. // to the text input |client|, which is e.g. views::NativeTextfieldViews.
void InputMethodBridge::SetCompositionText( void InputMethodBridge::SetCompositionText(
......
...@@ -48,6 +48,7 @@ class InputMethodBridge : public InputMethodBase, ...@@ -48,6 +48,7 @@ class InputMethodBridge : public InputMethodBase,
virtual std::string GetInputLocale() OVERRIDE; virtual std::string GetInputLocale() OVERRIDE;
virtual base::i18n::TextDirection GetInputTextDirection() OVERRIDE; virtual base::i18n::TextDirection GetInputTextDirection() OVERRIDE;
virtual bool IsActive() OVERRIDE; virtual bool IsActive() OVERRIDE;
virtual bool IsCandidatePopupOpen() const OVERRIDE;
// Overridden from TextInputClient: // Overridden from TextInputClient:
virtual void SetCompositionText( virtual void SetCompositionText(
......
...@@ -27,6 +27,7 @@ InputMethodWin::InputMethodWin(internal::InputMethodDelegate* delegate, ...@@ -27,6 +27,7 @@ InputMethodWin::InputMethodWin(internal::InputMethodDelegate* delegate,
ui::InputMethod* host) ui::InputMethod* host)
: hwnd_(hwnd), : hwnd_(hwnd),
active_(false), active_(false),
is_candidate_popup_open_(false),
direction_(base::i18n::UNKNOWN_DIRECTION), direction_(base::i18n::UNKNOWN_DIRECTION),
pending_requested_direction_(base::i18n::UNKNOWN_DIRECTION), pending_requested_direction_(base::i18n::UNKNOWN_DIRECTION),
host_(host) { host_(host) {
...@@ -78,6 +79,10 @@ bool InputMethodWin::OnUntranslatedIMEMessage(const base::NativeEvent& event, ...@@ -78,6 +79,10 @@ bool InputMethodWin::OnUntranslatedIMEMessage(const base::NativeEvent& event,
original_result = OnImeRequest( original_result = OnImeRequest(
event.message, event.wParam, event.lParam, &handled); event.message, event.wParam, event.lParam, &handled);
break; break;
case WM_IME_NOTIFY:
original_result = OnImeNotify(
event.message, event.wParam, event.lParam, &handled);
break;
case WM_CHAR: case WM_CHAR:
case WM_SYSCHAR: case WM_SYSCHAR:
original_result = OnChar( original_result = OnChar(
...@@ -167,6 +172,10 @@ ui::TextInputClient* InputMethodWin::GetTextInputClient() const { ...@@ -167,6 +172,10 @@ ui::TextInputClient* InputMethodWin::GetTextInputClient() const {
return host_ ? host_->GetTextInputClient() : NULL; return host_ ? host_->GetTextInputClient() : NULL;
} }
bool InputMethodWin::IsCandidatePopupOpen() const {
return is_candidate_popup_open_;
}
void InputMethodWin::OnWillChangeFocus(View* focused_before, View* focused) { void InputMethodWin::OnWillChangeFocus(View* focused_before, View* focused) {
ConfirmCompositionText(); ConfirmCompositionText();
} }
...@@ -274,6 +283,23 @@ LRESULT InputMethodWin::OnImeRequest( ...@@ -274,6 +283,23 @@ LRESULT InputMethodWin::OnImeRequest(
} }
} }
LRESULT InputMethodWin::OnImeNotify(
UINT message, WPARAM wparam, LPARAM lparam, BOOL* handled) {
*handled = FALSE;
// Update |is_candidate_popup_open_|, whether a candidate window is open.
switch (wparam) {
case IMN_OPENCANDIDATE:
is_candidate_popup_open_ = true;
break;
case IMN_CLOSECANDIDATE:
is_candidate_popup_open_ = false;
break;
}
return 0;
}
LRESULT InputMethodWin::OnChar( LRESULT InputMethodWin::OnChar(
UINT message, WPARAM wparam, LPARAM lparam, BOOL* handled) { UINT message, WPARAM wparam, LPARAM lparam, BOOL* handled) {
*handled = TRUE; *handled = TRUE;
......
...@@ -44,6 +44,7 @@ class InputMethodWin : public InputMethodBase { ...@@ -44,6 +44,7 @@ class InputMethodWin : public InputMethodBase {
virtual std::string GetInputLocale() OVERRIDE; virtual std::string GetInputLocale() OVERRIDE;
virtual base::i18n::TextDirection GetInputTextDirection() OVERRIDE; virtual base::i18n::TextDirection GetInputTextDirection() OVERRIDE;
virtual bool IsActive() OVERRIDE; virtual bool IsActive() OVERRIDE;
virtual bool IsCandidatePopupOpen() const OVERRIDE;
// Overridden from InputMethodBase. // Overridden from InputMethodBase.
virtual ui::TextInputClient* GetTextInputClient() const OVERRIDE; virtual ui::TextInputClient* GetTextInputClient() const OVERRIDE;
...@@ -59,6 +60,8 @@ class InputMethodWin : public InputMethodBase { ...@@ -59,6 +60,8 @@ class InputMethodWin : public InputMethodBase {
UINT message, WPARAM wparam, LPARAM lparam, BOOL* handled); UINT message, WPARAM wparam, LPARAM lparam, BOOL* handled);
LRESULT OnImeRequest( LRESULT OnImeRequest(
UINT message, WPARAM wparam, LPARAM lparam, BOOL* handled); UINT message, WPARAM wparam, LPARAM lparam, BOOL* handled);
LRESULT OnImeNotify(
UINT message, WPARAM wparam, LPARAM lparam, BOOL* handled);
// For both WM_CHAR and WM_SYSCHAR // For both WM_CHAR and WM_SYSCHAR
LRESULT OnChar( LRESULT OnChar(
UINT message, WPARAM wparam, LPARAM lparam, BOOL* handled); UINT message, WPARAM wparam, LPARAM lparam, BOOL* handled);
...@@ -86,6 +89,9 @@ class InputMethodWin : public InputMethodBase { ...@@ -86,6 +89,9 @@ class InputMethodWin : public InputMethodBase {
// Indicates if the current input locale has an IME. // Indicates if the current input locale has an IME.
bool active_; bool active_;
// True if we know for sure that a candidate window is open.
bool is_candidate_popup_open_;
// Name of the current input locale. // Name of the current input locale.
std::string locale_; std::string locale_;
......
...@@ -132,6 +132,10 @@ bool MockInputMethod::IsActive() { ...@@ -132,6 +132,10 @@ bool MockInputMethod::IsActive() {
return active_; return active_;
} }
bool MockInputMethod::IsCandidatePopupOpen() const {
return false;
}
bool MockInputMethod::IsMock() const { bool MockInputMethod::IsMock() const {
return true; return true;
} }
......
...@@ -36,6 +36,7 @@ class VIEWS_EXPORT MockInputMethod : public InputMethodBase { ...@@ -36,6 +36,7 @@ class VIEWS_EXPORT MockInputMethod : public InputMethodBase {
virtual std::string GetInputLocale() OVERRIDE; virtual std::string GetInputLocale() OVERRIDE;
virtual base::i18n::TextDirection GetInputTextDirection() OVERRIDE; virtual base::i18n::TextDirection GetInputTextDirection() OVERRIDE;
virtual bool IsActive() OVERRIDE; virtual bool IsActive() OVERRIDE;
virtual bool IsCandidatePopupOpen() const OVERRIDE;
virtual bool IsMock() const OVERRIDE; virtual bool IsMock() const OVERRIDE;
bool focus_changed() const { return focus_changed_; } bool focus_changed() const { return focus_changed_; }
......
...@@ -264,6 +264,7 @@ class VIEWS_EXPORT HWNDMessageHandler : ...@@ -264,6 +264,7 @@ class VIEWS_EXPORT HWNDMessageHandler :
MESSAGE_HANDLER_EX(WM_IME_COMPOSITION, OnImeMessages) MESSAGE_HANDLER_EX(WM_IME_COMPOSITION, OnImeMessages)
MESSAGE_HANDLER_EX(WM_IME_ENDCOMPOSITION, OnImeMessages) MESSAGE_HANDLER_EX(WM_IME_ENDCOMPOSITION, OnImeMessages)
MESSAGE_HANDLER_EX(WM_IME_REQUEST, OnImeMessages) MESSAGE_HANDLER_EX(WM_IME_REQUEST, OnImeMessages)
MESSAGE_HANDLER_EX(WM_IME_NOTIFY, OnImeMessages)
MESSAGE_HANDLER_EX(WM_CHAR, OnImeMessages) MESSAGE_HANDLER_EX(WM_CHAR, OnImeMessages)
MESSAGE_HANDLER_EX(WM_SYSCHAR, OnImeMessages) MESSAGE_HANDLER_EX(WM_SYSCHAR, OnImeMessages)
MESSAGE_HANDLER_EX(WM_DEADCHAR, OnImeMessages) MESSAGE_HANDLER_EX(WM_DEADCHAR, OnImeMessages)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment