Implements InputMethodTSF::IsCandidatePopupOpen().

This CL is almost the same as http://crrev.com/17573006, which was reverted because of a unit test breakage.

BUG=245578
TEST=Test manually.

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@217091 0039d316-1c4b-4281-b951-d872f2087c98
parent 2afa7717
......@@ -6,12 +6,35 @@
#include "ui/base/ime/text_input_client.h"
#include "ui/base/ime/win/tsf_bridge.h"
#include "ui/base/ime/win/tsf_event_router.h"
namespace ui {
class InputMethodTSF::TSFEventObserver : public TSFEventRouterObserver {
public:
TSFEventObserver() : is_candidate_popup_open_(false) {}
// Returns true if we know for sure that a candidate window (or IME suggest,
// etc.) is open.
bool IsCandidatePopupOpen() const { return is_candidate_popup_open_; }
// Overridden from TSFEventRouterObserver:
virtual void OnCandidateWindowCountChanged(size_t window_count) OVERRIDE {
is_candidate_popup_open_ = (window_count != 0);
}
private:
// True if we know for sure that a candidate window is open.
bool is_candidate_popup_open_;
DISALLOW_COPY_AND_ASSIGN(TSFEventObserver);
};
InputMethodTSF::InputMethodTSF(internal::InputMethodDelegate* delegate,
HWND toplevel_window_handle)
: InputMethodWin(delegate, toplevel_window_handle) {
: InputMethodWin(delegate, toplevel_window_handle),
tsf_event_observer_(new TSFEventObserver()),
tsf_event_router_(new TSFEventRouter(tsf_event_observer_.get())) {
// In non-Aura environment, appropriate callbacks to OnFocus() and OnBlur()
// are not implemented yet. To work around this limitation, here we use
// "always focused" model.
......@@ -20,16 +43,23 @@ InputMethodTSF::InputMethodTSF(internal::InputMethodDelegate* delegate,
InputMethodWin::OnFocus();
}
InputMethodTSF::~InputMethodTSF() {}
void InputMethodTSF::OnFocus() {
// Ignore OnFocus event for "always focused" model. See the comment in the
// constructor.
// Do not call baseclass' OnFocus() and discard the event being in
// "always focused" model. See the comment in the constructor.
// TODO(ime): Implement OnFocus once the callers are fixed.
tsf_event_router_->SetManager(
ui::TSFBridge::GetInstance()->GetThreadManager());
}
void InputMethodTSF::OnBlur() {
// Ignore OnBlur event for "always focused" model. See the comment in the
// constructor.
// Do not call baseclass' OnBlur() and discard the event being in
// "always focused" model. See the comment in the constructor.
// TODO(ime): Implement OnFocus once the callers are fixed.
tsf_event_router_->SetManager(NULL);
}
bool InputMethodTSF::OnUntranslatedIMEMessage(
......@@ -99,8 +129,7 @@ void InputMethodTSF::SetFocusedTextInputClient(TextInputClient* client) {
}
bool InputMethodTSF::IsCandidatePopupOpen() const {
// TODO(yukishiino): Implement this method.
return false;
return tsf_event_observer_->IsCandidatePopupOpen();
}
void InputMethodTSF::OnWillChangeFocusedClient(TextInputClient* focused_before,
......
......@@ -9,15 +9,19 @@
#include <string>
#include "base/memory/scoped_ptr.h"
#include "ui/base/ime/input_method_win.h"
namespace ui {
class TSFEventRouter;
// An InputMethod implementation based on Windows TSF API.
class UI_EXPORT InputMethodTSF : public InputMethodWin {
public:
InputMethodTSF(internal::InputMethodDelegate* delegate,
HWND toplevel_window_handle);
virtual ~InputMethodTSF();
// Overridden from InputMethod:
virtual void OnFocus() OVERRIDE;
......@@ -37,6 +41,8 @@ class UI_EXPORT InputMethodTSF : public InputMethodWin {
TextInputClient* focused) OVERRIDE;
private:
class TSFEventObserver;
// Asks the client to confirm current composition text.
void ConfirmCompositionText();
......@@ -44,6 +50,10 @@ class UI_EXPORT InputMethodTSF : public InputMethodWin {
// focus.
bool IsWindowFocused(const TextInputClient* client) const;
// TSF event router and observer.
scoped_ptr<TSFEventObserver> tsf_event_observer_;
scoped_ptr<TSFEventRouter> tsf_event_router_;
DISALLOW_COPY_AND_ASSIGN(InputMethodTSF);
};
......
......@@ -193,6 +193,7 @@ void TSFEventRouter::Delegate::SetManager(
base::win::ScopedComPtr<ITfDocumentMgr> document_manager;
if (FAILED(thread_manager->GetFocus(document_manager.Receive())) ||
!document_manager.get() ||
FAILED(document_manager->GetBase(context_.Receive())) ||
FAILED(context_source_.QueryFrom(context_)))
return;
......
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