Skip to content

Commit

Permalink
Use onActivate event to carry screen type instead of onFocus for IME …
Browse files Browse the repository at this point in the history
…extensions.

The original solution to let onFocus event carry screen type has a bug:
If no input field is focused after unlock, the IME extension doesn't receive
onFocus event and thus doesn't know about the screen type changed from 'lock'
to 'normal'. And A11y virtual keyboard can be opened without focusing an input
field.

BUG=401968
TEST=Verified on linux_chromeos.

Review URL: https://codereview.chromium.org/457673003

Cr-Commit-Position: refs/heads/master@{#288562}
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@288562 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
shuchen@chromium.org committed Aug 9, 2014
1 parent 3a868f2 commit 1b4adf3
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ void InputMethodManagerImpl::RemoveCandidateWindowObserver(
candidate_window_observers_.RemoveObserver(observer);
}

InputMethodManager::State InputMethodManagerImpl::GetState() {
return state_;
}

void InputMethodManagerImpl::SetState(State new_state) {
const State old_state = state_;
state_ = new_state;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class InputMethodManagerImpl : public InputMethodManager,
void SetState(State new_state);

// InputMethodManager override:
virtual State GetState() OVERRIDE;
virtual void InitializeComponentExtension() OVERRIDE;
virtual void AddObserver(InputMethodManager::Observer* observer) OVERRIDE;
virtual void AddCandidateWindowObserver(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ MockInputMethodManager::~MockInputMethodManager() {
void MockInputMethodManager::InitializeComponentExtension() {
}

InputMethodManager::State MockInputMethodManager::GetState() {
return InputMethodManager::STATE_BROWSER_SCREEN;
}

void MockInputMethodManager::AddObserver(
InputMethodManager::Observer* observer) {
++add_observer_count_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class MockInputMethodManager : public InputMethodManager {
virtual ~MockInputMethodManager();

// InputMethodManager override:
virtual State GetState() OVERRIDE;
virtual void InitializeComponentExtension() OVERRIDE;
virtual void AddObserver(InputMethodManager::Observer* observer) OVERRIDE;
virtual void AddCandidateWindowObserver(
Expand Down
42 changes: 22 additions & 20 deletions chrome/browser/extensions/api/input_ime/input_ime_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,9 @@ class ImeObserver : public InputMethodEngineInterface::Observer {
if (extension_id_.empty())
return;

scoped_ptr<base::ListValue> args(
input_ime::OnActivate::Create(component_id));
scoped_ptr<base::ListValue> args(input_ime::OnActivate::Create(
component_id,
input_ime::OnActivate::ParseScreen(GetCurrentScreenType())));

DispatchEventToExtension(
extension_id_, input_ime::OnActivate::kEventName, args.Pass());
Expand Down Expand Up @@ -140,24 +141,6 @@ class ImeObserver : public InputMethodEngineInterface::Observer {

scoped_ptr<base::ListValue> args(input_ime::OnFocus::Create(context_value));

// The component IME extensions need to know the current screen type (e.g.
// lock screen, login screen, etc.) so that its on-screen keyboard page
// won't open new windows/pages. See crbug.com/395621.
base::DictionaryValue* val = NULL;
if (args->GetDictionary(0, &val)) {
std::string screen_type;
if (!UserManager::Get()->IsUserLoggedIn()) {
screen_type = "login";
} else if (chromeos::ScreenLocker::default_screen_locker() &&
chromeos::ScreenLocker::default_screen_locker()->locked()) {
screen_type = "lock";
} else if (UserAddingScreen::Get()->IsRunning()) {
screen_type = "secondary-login";
}
if (!screen_type.empty())
val->SetStringWithoutPathExpansion("screen", screen_type);
}

DispatchEventToExtension(
extension_id_, input_ime::OnFocus::kEventName, args.Pass());
}
Expand Down Expand Up @@ -326,6 +309,25 @@ class ImeObserver : public InputMethodEngineInterface::Observer {
return false;
}

// The component IME extensions need to know the current screen type (e.g.
// lock screen, login screen, etc.) so that its on-screen keyboard page
// won't open new windows/pages. See crbug.com/395621.
std::string GetCurrentScreenType() {
switch (chromeos::input_method::InputMethodManager::Get()->GetState()) {
case chromeos::input_method::InputMethodManager::STATE_LOGIN_SCREEN:
return "login";
case chromeos::input_method::InputMethodManager::STATE_LOCK_SCREEN:
return "lock";
case chromeos::input_method::InputMethodManager::STATE_BROWSER_SCREEN:
return UserAddingScreen::Get()->IsRunning() ? "secondary-login"
: "normal";
case chromeos::input_method::InputMethodManager::STATE_TERMINATING:
return "normal";
}
NOTREACHED() << "New screen type is added. Please add new entry above.";
return "normal";
}

std::string extension_id_;

DISALLOW_COPY_AND_ASSIGN(ImeObserver);
Expand Down
6 changes: 6 additions & 0 deletions chrome/common/extensions/api/input_ime.json
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,12 @@
"type": "string",
"name": "engineID",
"description": "ID of the engine receiving the event"
},
{
"type": "string",
"name": "screen",
"enum": ["normal", "login", "lock", "secondary-login"],
"description": "The screen type under which the IME is activated."
}
]
},
Expand Down
3 changes: 3 additions & 0 deletions chromeos/ime/input_method_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ class CHROMEOS_EXPORT InputMethodManager {
// Initialize component extensions.
virtual void InitializeComponentExtension() = 0;

// Get the current UI session state (e.g. login screen, lock screen, etc.).
virtual State GetState() = 0;

// Adds an observer to receive notifications of input method related
// changes as desribed in the Observer class above.
virtual void AddObserver(Observer* observer) = 0;
Expand Down

0 comments on commit 1b4adf3

Please sign in to comment.