summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoryusukes@google.com <yusukes@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-12 11:16:30 +0000
committeryusukes@google.com <yusukes@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-12 11:16:30 +0000
commitcf85d2ad56269e4a220ed84f31745a293cf964dc (patch)
tree85526cc0415cb7ddc98fc71dbaccf16c9dda985c
parent1a5acea8faf7ad8af233f97a43920df0dea901f4 (diff)
downloadchromium_src-cf85d2ad56269e4a220ed84f31745a293cf964dc.zip
chromium_src-cf85d2ad56269e4a220ed84f31745a293cf964dc.tar.gz
chromium_src-cf85d2ad56269e4a220ed84f31745a293cf964dc.tar.bz2
Add RemoveHotkey method and its tests.
This is necessary for implementing 'engine specific hotkey': http://codereview.chromium.org/7865019/ BUG=chromium-os:13836 TEST=ran unit_tests. Review URL: http://codereview.chromium.org/7796036 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@100672 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/chromeos/input_method/hotkey_manager.cc14
-rw-r--r--chrome/browser/chromeos/input_method/hotkey_manager.h5
-rw-r--r--chrome/browser/chromeos/input_method/hotkey_manager_unittest.cc54
3 files changed, 72 insertions, 1 deletions
diff --git a/chrome/browser/chromeos/input_method/hotkey_manager.cc b/chrome/browser/chromeos/input_method/hotkey_manager.cc
index e45e2df..a1d2999 100644
--- a/chrome/browser/chromeos/input_method/hotkey_manager.cc
+++ b/chrome/browser/chromeos/input_method/hotkey_manager.cc
@@ -95,6 +95,20 @@ bool HotkeyManager::AddHotkey(int event_id,
std::make_pair(std::make_pair(keysym, modifiers), event_id)).second;
}
+bool HotkeyManager::RemoveHotkey(int event_id) {
+ bool result = false;
+ std::map<std::pair<uint32, uint32>, int>::iterator iter;
+ for (iter = hotkeys_.begin(); iter != hotkeys_.end();) {
+ if (iter->second == event_id) {
+ hotkeys_.erase(iter++);
+ result = true;
+ } else {
+ ++iter;
+ }
+ }
+ return result;
+}
+
bool HotkeyManager::FilterKeyEvent(const XEvent& key_event) {
bool is_key_press = true;
switch (key_event.type) {
diff --git a/chrome/browser/chromeos/input_method/hotkey_manager.h b/chrome/browser/chromeos/input_method/hotkey_manager.h
index 96de64f..bcee045 100644
--- a/chrome/browser/chromeos/input_method/hotkey_manager.h
+++ b/chrome/browser/chromeos/input_method/hotkey_manager.h
@@ -40,7 +40,10 @@ class HotkeyManager {
uint32 keysym, // one of XK_* in X11/keysymdef.h.
uint32 modifiers, // set of *Mask flags in X11/X.h, or zero.
bool trigger_on_key_press);
- // TODO(yusukes): Add RemoveHotkey function if we support crosbug.com/6267.
+
+ // Removes all hotkeys whose ID is |event_id|. Returns false if no such hotkey
+ // is registered.
+ bool RemoveHotkey(int event_id);
// Checks if |key_event| is a hotkey. If it is, Observer::HotkeyPressed() is
// called for each observers. This function returns true if the key_event
diff --git a/chrome/browser/chromeos/input_method/hotkey_manager_unittest.cc b/chrome/browser/chromeos/input_method/hotkey_manager_unittest.cc
index 590562f..604da4b 100644
--- a/chrome/browser/chromeos/input_method/hotkey_manager_unittest.cc
+++ b/chrome/browser/chromeos/input_method/hotkey_manager_unittest.cc
@@ -191,6 +191,60 @@ TEST(HotkeyManagerTest, TestAddTwoHotkeys) {
XK_a, 0x0, false));
}
+TEST(HotkeyManagerTest, TestRemoveHotkey1) {
+ TestableHotkeyManager manager;
+ EXPECT_TRUE(manager.AddHotkey(0, XK_a, 0x0, true));
+ EXPECT_TRUE(manager.AddHotkey(1, XK_b, 0x0, false));
+ EXPECT_EQ(0, manager.FilterKeyEventInternal(XK_a, 0x0, true));
+ EXPECT_EQ(TestableHotkeyManager::kFiltered, manager.FilterKeyEventInternal(
+ XK_a, 0x0, false));
+
+ // Remove the second hotkey and confirm that it is actually removed.
+ EXPECT_TRUE(manager.RemoveHotkey(1));
+ EXPECT_EQ(TestableHotkeyManager::kNoEvent, manager.FilterKeyEventInternal(
+ XK_b, 0x0, true));
+ EXPECT_EQ(TestableHotkeyManager::kNoEvent, manager.FilterKeyEventInternal(
+ XK_b, 0x0, false));
+ // Remove the first one as well.
+ EXPECT_TRUE(manager.RemoveHotkey(0));
+ EXPECT_EQ(TestableHotkeyManager::kNoEvent, manager.FilterKeyEventInternal(
+ XK_a, 0x0, true));
+ EXPECT_EQ(TestableHotkeyManager::kNoEvent, manager.FilterKeyEventInternal(
+ XK_a, 0x0, false));
+
+ // Can't remove a hotkey twice.
+ EXPECT_FALSE(manager.RemoveHotkey(0));
+ EXPECT_FALSE(manager.RemoveHotkey(1));
+ // "2" is not registered yet.
+ EXPECT_FALSE(manager.RemoveHotkey(2));
+}
+
+TEST(HotkeyManagerTest, TestRemoveHotkey2) {
+ TestableHotkeyManager manager;
+ // Add two hotkeys that have the same id "0".
+ EXPECT_TRUE(manager.AddHotkey(0, XK_a, 0x0, true));
+ EXPECT_TRUE(manager.AddHotkey(0, XK_b, 0x0, false));
+ EXPECT_EQ(0, manager.FilterKeyEventInternal(XK_a, 0x0, true));
+ EXPECT_EQ(TestableHotkeyManager::kFiltered, manager.FilterKeyEventInternal(
+ XK_a, 0x0, false));
+
+ // Remove the hotkey and confirm that it is actually removed.
+ EXPECT_TRUE(manager.RemoveHotkey(0));
+ EXPECT_EQ(TestableHotkeyManager::kNoEvent, manager.FilterKeyEventInternal(
+ XK_b, 0x0, true));
+ EXPECT_EQ(TestableHotkeyManager::kNoEvent, manager.FilterKeyEventInternal(
+ XK_b, 0x0, false));
+ EXPECT_EQ(TestableHotkeyManager::kNoEvent, manager.FilterKeyEventInternal(
+ XK_a, 0x0, true));
+ EXPECT_EQ(TestableHotkeyManager::kNoEvent, manager.FilterKeyEventInternal(
+ XK_a, 0x0, false));
+
+ // Can't remove a hotkey twice.
+ EXPECT_FALSE(manager.RemoveHotkey(0));
+ // "1" is not registered yet.
+ EXPECT_FALSE(manager.RemoveHotkey(1));
+}
+
// Press Shift, then press Alt. Release Alt first.
TEST(HotkeyManagerTest, TestAltShift1) {
scoped_ptr<TestableHotkeyManager> manager(CreateManager());