Commit 06ca64cf authored by falken@chromium.org's avatar falken@chromium.org

(Chrome OS) Notify when the candidate window is opened/closed.

This will allow for IME/omnibox coordination, as the omnibox can observe when
the candidate window is open.

Currently, there is no distinction between the suggest window and candidate
window in these events, but it can be changed later.

BUG=chromium-os:17763
TEST=


Review URL: http://codereview.chromium.org/8840002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@113572 0039d316-1c4b-4281-b951-d872f2087c98
parent 65427246
......@@ -602,11 +602,16 @@ class CandidateWindowController::Impl : public CandidateWindowView::Observer,
// Initializes the candidate window. Returns true on success.
bool Init();
void AddObserver(CandidateWindowController::Observer* observer);
void RemoveObserver(CandidateWindowController::Observer* observer);
private:
// CandidateWindowView::Observer implementation.
virtual void OnCandidateCommitted(int index,
int button,
int flags);
virtual void OnCandidateWindowOpened();
virtual void OnCandidateWindowClosed();
// Creates the candidate window view.
void CreateView();
......@@ -640,6 +645,8 @@ class CandidateWindowController::Impl : public CandidateWindowView::Observer,
// own |infolist_window_|.
scoped_ptr<views::Widget> infolist_frame_;
ObserverList<CandidateWindowController::Observer> observers_;
DISALLOW_COPY_AND_ASSIGN(Impl);
};
......@@ -879,15 +886,23 @@ void CandidateWindowView::Init() {
}
void CandidateWindowView::HideAll() {
bool was_visible = IsCandidateWindowOpen();
parent_frame_->Hide();
if (was_visible) {
FOR_EACH_OBSERVER(Observer, observers_, OnCandidateWindowClosed());
}
}
void CandidateWindowView::HideLookupTable() {
bool was_visible = IsCandidateWindowOpen();
candidate_area_->Hide();
if (preedit_area_->IsShown())
ResizeAndMoveParentFrame();
else
parent_frame_->Hide();
if (was_visible) {
FOR_EACH_OBSERVER(Observer, observers_, OnCandidateWindowClosed());
}
}
InformationTextArea* CandidateWindowView::GetAuxiliaryTextArea() {
......@@ -928,9 +943,13 @@ void CandidateWindowView::UpdatePreeditText(const std::string& utf8_text) {
}
void CandidateWindowView::ShowLookupTable() {
bool was_visible = IsCandidateWindowOpen();
candidate_area_->Show();
ResizeAndMoveParentFrame();
parent_frame_->Show();
if (!was_visible) {
FOR_EACH_OBSERVER(Observer, observers_, OnCandidateWindowOpened());
}
}
bool CandidateWindowView::ShouldUpdateCandidateViews(
......@@ -1168,6 +1187,10 @@ void CandidateWindowView::MaybeInitializeCandidateViews(
layout->Layout(candidate_area_contents);
}
bool CandidateWindowView::IsCandidateWindowOpen() const {
return candidate_area_->IsVisible() && candidate_area_->IsShown();
}
void CandidateWindowView::SelectCandidateAt(int index_in_page) {
const int current_page_index = ComputePageIndex(lookup_table_);
if (current_page_index < 0) {
......@@ -1709,6 +1732,26 @@ void CandidateWindowController::Impl::OnCandidateCommitted(int index,
ibus_ui_controller_->NotifyCandidateClicked(index, button, flags);
}
void CandidateWindowController::Impl::OnCandidateWindowOpened() {
FOR_EACH_OBSERVER(CandidateWindowController::Observer, observers_,
CandidateWindowOpened());
}
void CandidateWindowController::Impl::OnCandidateWindowClosed() {
FOR_EACH_OBSERVER(CandidateWindowController::Observer, observers_,
CandidateWindowClosed());
}
void CandidateWindowController::Impl::AddObserver(
CandidateWindowController::Observer* observer) {
observers_.AddObserver(observer);
}
void CandidateWindowController::Impl::RemoveObserver(
CandidateWindowController::Observer* observer) {
observers_.RemoveObserver(observer);
}
void CandidateWindowController::Impl::OnConnectionChange(bool connected) {
if (!connected) {
candidate_window_->HideAll();
......@@ -1728,5 +1771,15 @@ bool CandidateWindowController::Init() {
return impl_->Init();
}
void CandidateWindowController::AddObserver(
CandidateWindowController::Observer* observer) {
impl_->AddObserver(observer);
}
void CandidateWindowController::RemoveObserver(
CandidateWindowController::Observer* observer) {
impl_->RemoveObserver(observer);
}
} // namespace input_method
} // namespace chromeos
......@@ -21,12 +21,23 @@ namespace input_method {
// rendering the candidate view is deleted.
class CandidateWindowController {
public:
class Observer {
public:
virtual ~Observer() {}
virtual void CandidateWindowOpened() = 0;
virtual void CandidateWindowClosed() = 0;
};
CandidateWindowController();
virtual ~CandidateWindowController();
// Initializes the candidate window. Returns true on success.
bool Init();
void AddObserver(Observer* observer);
void RemoveObserver(Observer* observer);
private:
class Impl;
Impl* impl_;
......
......@@ -26,6 +26,9 @@ class CandidateWindowView : public views::View {
// See comments at NotifyCandidateClicked() in chromeos_input_method_ui.h
// for details about the parameters.
virtual void OnCandidateCommitted(int index, int button, int flag) = 0;
virtual void OnCandidateWindowOpened() = 0;
virtual void OnCandidateWindowClosed() = 0;
};
explicit CandidateWindowView(views::Widget* parent_frame);
......@@ -137,6 +140,8 @@ class CandidateWindowView : public views::View {
// Returns the appropriate area (header or footer) to put auxiliary texts.
InformationTextArea* GetAuxiliaryTextArea();
bool IsCandidateWindowOpen() const;
// The lookup table (candidates).
InputMethodLookupTable lookup_table_;
......
......@@ -129,10 +129,14 @@ namespace chromeos {
namespace input_method {
// The implementation of InputMethodManager.
class InputMethodManagerImpl : public HotkeyManager::Observer,
public InputMethodManager,
public content::NotificationObserver,
public IBusController::Observer {
class InputMethodManagerImpl
: public HotkeyManager::Observer,
public InputMethodManager,
public content::NotificationObserver,
#if !defined(USE_VIRTUAL_KEYBOARD)
public CandidateWindowController::Observer,
#endif
public IBusController::Observer {
public:
InputMethodManagerImpl()
: ibus_controller_(IBusController::Create()),
......@@ -178,6 +182,10 @@ class InputMethodManagerImpl : public HotkeyManager::Observer,
virtual ~InputMethodManagerImpl() {
hotkey_manager_.RemoveObserver(this);
ibus_controller_->RemoveObserver(this);
#if !defined(USE_VIRTUAL_KEYBOARD)
if (candidate_window_controller_.get())
candidate_window_controller_->RemoveObserver(this);
#endif
}
virtual void AddObserver(InputMethodManager::Observer* observer) {
......@@ -188,6 +196,16 @@ class InputMethodManagerImpl : public HotkeyManager::Observer,
observers_.RemoveObserver(observer);
}
virtual void AddCandidateWindowObserver(
InputMethodManager::CandidateWindowObserver* observer) {
candidate_window_observers_.AddObserver(observer);
}
virtual void RemoveCandidateWindowObserver(
InputMethodManager::CandidateWindowObserver* observer) {
candidate_window_observers_.RemoveObserver(observer);
}
virtual void AddPreLoginPreferenceObserver(
InputMethodManager::PreferenceObserver* observer) {
if (!pre_login_preference_observers_.size()) {
......@@ -529,6 +547,18 @@ class InputMethodManagerImpl : public HotkeyManager::Observer,
}
}
virtual void CandidateWindowOpened() {
FOR_EACH_OBSERVER(InputMethodManager::CandidateWindowObserver,
candidate_window_observers_,
CandidateWindowOpened(this));
}
virtual void CandidateWindowClosed() {
FOR_EACH_OBSERVER(InputMethodManager::CandidateWindowObserver,
candidate_window_observers_,
CandidateWindowClosed(this));
}
virtual void SwitchToNextInputMethod() {
// Sanity checks.
if (active_input_method_ids_.empty()) {
......@@ -1105,7 +1135,9 @@ class InputMethodManagerImpl : public HotkeyManager::Observer,
#if !defined(USE_VIRTUAL_KEYBOARD)
if (!candidate_window_controller_.get()) {
candidate_window_controller_.reset(new CandidateWindowController);
if (!candidate_window_controller_->Init()) {
if (candidate_window_controller_->Init()) {
candidate_window_controller_->AddObserver(this);
} else {
LOG(WARNING) << "Failed to initialize the candidate window controller";
}
}
......@@ -1181,6 +1213,8 @@ class InputMethodManagerImpl : public HotkeyManager::Observer,
notification_registrar_.RemoveAll();
StopInputMethodDaemon();
#if !defined(USE_VIRTUAL_KEYBOARD)
if (candidate_window_controller_.get())
candidate_window_controller_->RemoveObserver(this);
candidate_window_controller_.reset(NULL);
#endif
}
......@@ -1301,6 +1335,8 @@ class InputMethodManagerImpl : public HotkeyManager::Observer,
// allow allow callbacks when the input method status changes.
scoped_ptr<IBusController> ibus_controller_;
ObserverList<InputMethodManager::Observer> observers_;
ObserverList<InputMethodManager::CandidateWindowObserver>
candidate_window_observers_;
ObserverList<PreferenceObserver> pre_login_preference_observers_;
ObserverList<PreferenceObserver> post_login_preference_observers_;
ObserverList<VirtualKeyboardObserver> virtual_keyboard_observers_;
......
......@@ -54,6 +54,20 @@ class InputMethodManager {
const ImePropertyList& current_ime_properties) = 0;
};
// CandidateWindowObserver is notified of events related to the candidate
// window. These events won't occur when the virtual keyboard is used,
// since it controls its own candidate window.
class CandidateWindowObserver {
public:
virtual ~CandidateWindowObserver() {}
// Called when the candidate window is opened.
virtual void CandidateWindowOpened(InputMethodManager* manager) = 0;
// Called when the candidate window is closed.
virtual void CandidateWindowClosed(InputMethodManager* manager) = 0;
};
class PreferenceObserver {
public:
virtual ~PreferenceObserver() {}
......@@ -85,11 +99,15 @@ class InputMethodManager {
// Adds an observer to receive notifications of input method related
// changes as desribed in the Observer class above.
virtual void AddObserver(Observer* observer) = 0;
virtual void AddCandidateWindowObserver(
CandidateWindowObserver* observer) = 0;
virtual void AddPreLoginPreferenceObserver(PreferenceObserver* observer) = 0;
virtual void AddPostLoginPreferenceObserver(PreferenceObserver* observer) = 0;
virtual void AddVirtualKeyboardObserver(
VirtualKeyboardObserver* observer) = 0;
virtual void RemoveObserver(Observer* observer) = 0;
virtual void RemoveCandidateWindowObserver(
CandidateWindowObserver* observer) = 0;
virtual void RemovePreLoginPreferenceObserver(
PreferenceObserver* observer) = 0;
virtual void RemovePostLoginPreferenceObserver(
......
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