summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--remoting/client/normalizing_input_filter_cros.cc48
-rw-r--r--remoting/client/normalizing_input_filter_cros.h4
-rw-r--r--remoting/client/normalizing_input_filter_cros_unittest.cc63
3 files changed, 105 insertions, 10 deletions
diff --git a/remoting/client/normalizing_input_filter_cros.cc b/remoting/client/normalizing_input_filter_cros.cc
index 0b97652..8cb2229 100644
--- a/remoting/client/normalizing_input_filter_cros.cc
+++ b/remoting/client/normalizing_input_filter_cros.cc
@@ -17,11 +17,6 @@ static bool IsOsKey(uint32_t code) {
code == static_cast<uint32_t>(ui::DomCode::OS_RIGHT);
}
-// Returns true for the left-hand Alt key.
-static bool IsLeftAltKey(uint32_t code) {
- return code == static_cast<uint32_t>(ui::DomCode::ALT_LEFT);
-}
-
// Returns true for codes generated by EventRewriter::RewriteFunctionKeys().
static bool IsRewrittenFunctionKey(uint32_t code) {
return code >= static_cast<uint32_t>(ui::DomCode::F1) &&
@@ -96,6 +91,7 @@ NormalizingInputFilterCros::NormalizingInputFilterCros(
deferred_key_is_rewriting_(false),
modifying_key_(0),
left_alt_is_pressed_(false),
+ right_alt_is_pressed_(false),
previous_mouse_x_(-1),
previous_mouse_y_(-1) {
}
@@ -177,10 +173,17 @@ void NormalizingInputFilterCros::ProcessKeyDown(
SwitchRewritingKeyToModifying();
}
- if (IsLeftAltKey(event.usb_keycode()))
+ ui::DomCode dom_code = static_cast<ui::DomCode>(event.usb_keycode());
+ if (dom_code == ui::DomCode::ALT_LEFT) {
left_alt_is_pressed_ = true;
+ } else if (dom_code == ui::DomCode::ALT_RIGHT) {
+ right_alt_is_pressed_ = true;
+ }
- InputFilter::InjectKeyEvent(event);
+ protocol::KeyEvent updated_event = event;
+ UndoAltKeyMapping(&updated_event);
+
+ InputFilter::InjectKeyEvent(updated_event);
}
void NormalizingInputFilterCros::ProcessKeyUp(const protocol::KeyEvent& event) {
@@ -199,10 +202,17 @@ void NormalizingInputFilterCros::ProcessKeyUp(const protocol::KeyEvent& event) {
if (modifying_key_ == event.usb_keycode())
modifying_key_ = 0;
- if (IsLeftAltKey(event.usb_keycode()))
+ ui::DomCode dom_code = static_cast<ui::DomCode>(event.usb_keycode());
+ if (dom_code == ui::DomCode::ALT_LEFT) {
left_alt_is_pressed_ = false;
+ } else if (dom_code == ui::DomCode::ALT_RIGHT) {
+ right_alt_is_pressed_ = false;
+ }
+
+ protocol::KeyEvent updated_event = event;
+ UndoAltKeyMapping(&updated_event);
- InputFilter::InjectKeyEvent(event);
+ InputFilter::InjectKeyEvent(updated_event);
}
void NormalizingInputFilterCros::SwitchRewritingKeyToModifying() {
@@ -212,4 +222,24 @@ void NormalizingInputFilterCros::SwitchRewritingKeyToModifying() {
deferred_keydown_event_ = protocol::KeyEvent();
}
+void NormalizingInputFilterCros::UndoAltKeyMapping(protocol::KeyEvent* event) {
+ if (!left_alt_is_pressed_ && !right_alt_is_pressed_) {
+ return;
+ }
+
+ // If the keycode is one for which the Alt and Search keyboard shortcuts are
+ // the same, map it back to the original key.
+ switch (event->usb_keycode()) {
+ case static_cast<uint32_t>(ui::DomCode::PAGE_DOWN):
+ event->set_usb_keycode(static_cast<uint32_t>(ui::DomCode::ARROW_DOWN));
+ break;
+ case static_cast<uint32_t>(ui::DomCode::PAGE_UP):
+ event->set_usb_keycode(static_cast<uint32_t>(ui::DomCode::ARROW_UP));
+ break;
+ case static_cast<uint32_t>(ui::DomCode::DEL):
+ event->set_usb_keycode(static_cast<uint32_t>(ui::DomCode::BACKSPACE));
+ break;
+ }
+}
+
} // namespace remoting
diff --git a/remoting/client/normalizing_input_filter_cros.h b/remoting/client/normalizing_input_filter_cros.h
index e20eb59..0dfa805 100644
--- a/remoting/client/normalizing_input_filter_cros.h
+++ b/remoting/client/normalizing_input_filter_cros.h
@@ -36,6 +36,7 @@ class NormalizingInputFilterCros : public protocol::InputFilter {
void ProcessKeyUp(const protocol::KeyEvent& event);
void SwitchRewritingKeyToModifying();
+ void UndoAltKeyMapping(protocol::KeyEvent* event);
// Holds the keydown event for the most recent OSKey to have been pressed,
// while it is Rewriting, or we are not yet sure whether it is Normal,
@@ -50,8 +51,9 @@ class NormalizingInputFilterCros : public protocol::InputFilter {
// Stores the code of the OSKey while it is pressed for use as a Modifier.
uint32 modifying_key_;
- // True if the left Alt key is pressed.
+ // True if the left or right Alt keys are pressed, respectively.
bool left_alt_is_pressed_;
+ bool right_alt_is_pressed_;
// Previous mouse coordinates.
int previous_mouse_x_;
diff --git a/remoting/client/normalizing_input_filter_cros_unittest.cc b/remoting/client/normalizing_input_filter_cros_unittest.cc
index 44ded5a..be89a27 100644
--- a/remoting/client/normalizing_input_filter_cros_unittest.cc
+++ b/remoting/client/normalizing_input_filter_cros_unittest.cc
@@ -16,6 +16,7 @@ using remoting::protocol::InputStub;
using remoting::protocol::KeyEvent;
using remoting::protocol::MockInputStub;
using remoting::protocol::MouseEvent;
+using remoting::protocol::test::EqualsKeyEvent;
using remoting::protocol::test::EqualsKeyEventWithNumLock;
using remoting::protocol::test::EqualsMouseButtonEvent;
using remoting::protocol::test::EqualsMouseMoveEvent;
@@ -285,4 +286,66 @@ TEST(NormalizingInputFilterCrosTest, RightAltClick) {
processor->InjectKeyEvent(MakeKeyEvent(ui::DomCode::ALT_RIGHT, false));
}
+// Test that the Alt-key remapping for Up and Down is not applied.
+TEST(NormalizingInputFilterCrosTest, UndoAltPlusArrowRemapping) {
+ MockInputStub stub;
+ scoped_ptr<protocol::InputFilter> processor(
+ new NormalizingInputFilterCros(&stub));
+
+ {
+ InSequence s;
+
+ EXPECT_CALL(stub, InjectKeyEvent(EqualsKeyEvent(
+ ui::DomCode::ALT_LEFT, true)));
+ EXPECT_CALL(stub, InjectKeyEvent(EqualsKeyEvent(
+ ui::DomCode::ARROW_UP, true)));
+ EXPECT_CALL(stub, InjectKeyEvent(EqualsKeyEvent(
+ ui::DomCode::ARROW_UP, false)));
+ EXPECT_CALL(stub, InjectKeyEvent(EqualsKeyEvent(
+ ui::DomCode::ARROW_DOWN, true)));
+ EXPECT_CALL(stub, InjectKeyEvent(EqualsKeyEvent(
+ ui::DomCode::ARROW_DOWN, false)));
+ EXPECT_CALL(stub, InjectKeyEvent(EqualsKeyEvent(
+ ui::DomCode::BACKSPACE, true)));
+ EXPECT_CALL(stub, InjectKeyEvent(EqualsKeyEvent(
+ ui::DomCode::BACKSPACE, false)));
+ EXPECT_CALL(stub, InjectKeyEvent(EqualsKeyEvent(
+ ui::DomCode::ALT_LEFT, false)));
+
+ EXPECT_CALL(stub, InjectKeyEvent(EqualsKeyEvent(
+ ui::DomCode::ALT_RIGHT, true)));
+ EXPECT_CALL(stub, InjectKeyEvent(EqualsKeyEvent(
+ ui::DomCode::ARROW_UP, true)));
+ EXPECT_CALL(stub, InjectKeyEvent(EqualsKeyEvent(
+ ui::DomCode::ARROW_UP, false)));
+ EXPECT_CALL(stub, InjectKeyEvent(EqualsKeyEvent(
+ ui::DomCode::ARROW_DOWN, true)));
+ EXPECT_CALL(stub, InjectKeyEvent(EqualsKeyEvent(
+ ui::DomCode::ARROW_DOWN, false)));
+ EXPECT_CALL(stub, InjectKeyEvent(EqualsKeyEvent(
+ ui::DomCode::BACKSPACE, true)));
+ EXPECT_CALL(stub, InjectKeyEvent(EqualsKeyEvent(
+ ui::DomCode::BACKSPACE, false)));
+ EXPECT_CALL(stub, InjectKeyEvent(EqualsKeyEvent(
+ ui::DomCode::ALT_RIGHT, false)));
+ }
+
+ // Hold the left Alt key while pressing & releasing the PgUp, PgDown and
+ // Delete keys. This simulates the mapping that ChromeOS applies if the Up,
+ // Down and Backspace keys are pressed, respectively, while the Alt key is
+ // held.
+ processor->InjectKeyEvent(MakeKeyEvent(ui::DomCode::ALT_LEFT, true));
+ PressAndReleaseKey(processor.get(), ui::DomCode::PAGE_UP);
+ PressAndReleaseKey(processor.get(), ui::DomCode::PAGE_DOWN);
+ PressAndReleaseKey(processor.get(), ui::DomCode::DEL);
+ processor->InjectKeyEvent(MakeKeyEvent(ui::DomCode::ALT_LEFT, false));
+
+ // Repeat the test for the right Alt key.
+ processor->InjectKeyEvent(MakeKeyEvent(ui::DomCode::ALT_RIGHT, true));
+ PressAndReleaseKey(processor.get(), ui::DomCode::PAGE_UP);
+ PressAndReleaseKey(processor.get(), ui::DomCode::PAGE_DOWN);
+ PressAndReleaseKey(processor.get(), ui::DomCode::DEL);
+ processor->InjectKeyEvent(MakeKeyEvent(ui::DomCode::ALT_RIGHT, false));
+}
+
} // namespace remoting