Allow keys with AltGr modifier to be inserted in Textfield

AltGr modifier is used to type alternative keys on certain keyboard
layouts so we don't consider keys with the AltGr modifier as a system
key.

R=oshima@chromium.org
BUG=529883

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

Cr-Commit-Position: refs/heads/master@{#349680}
diff --git a/content/browser/renderer_host/native_web_keyboard_event_aura.cc b/content/browser/renderer_host/native_web_keyboard_event_aura.cc
index d8536ad9..5f3d8bd9 100644
--- a/content/browser/renderer_host/native_web_keyboard_event_aura.cc
+++ b/content/browser/renderer_host/native_web_keyboard_event_aura.cc
@@ -85,8 +85,7 @@
   nativeKeyCode = character;
   text[0] = character;
   unmodifiedText[0] = character;
-  isSystemKey =
-      ui::IsSystemKeyModifier(state) && (state & ui::EF_ALTGR_DOWN) == 0;
+  isSystemKey = ui::IsSystemKeyModifier(state);
   setKeyIdentifierFromWindowsKeyCode();
 }
 
diff --git a/ui/events/base_event_utils.cc b/ui/events/base_event_utils.cc
index 30854bc..ffff0f1da 100644
--- a/ui/events/base_event_utils.cc
+++ b/ui/events/base_event_utils.cc
@@ -34,7 +34,10 @@
 }
 
 bool IsSystemKeyModifier(int flags) {
-  return (kSystemKeyModifierMask & flags) != 0;
+  // AltGr modifier is used to type alternative keys on certain keyboard layouts
+  // so we don't consider keys with the AltGr modifier as a system key.
+  return (kSystemKeyModifierMask & flags) != 0 &&
+         (EF_ALTGR_DOWN & flags) == 0;
 }
 
 }  // namespace ui
diff --git a/ui/views/controls/textfield/textfield.cc b/ui/views/controls/textfield/textfield.cc
index d3b684c4..c20ea81 100644
--- a/ui/views/controls/textfield/textfield.cc
+++ b/ui/views/controls/textfield/textfield.cc
@@ -1453,10 +1453,10 @@
   // Filter out all control characters, including tab and new line characters,
   // and all characters with Alt modifier (and Search on ChromeOS). But allow
   // characters with the AltGr modifier. On Windows AltGr is represented by
-  // Alt+Ctrl, and on Linux it's a different flag that we don't care about.
-  const bool should_insert_char =
-      ((ch >= 0x20 && ch < 0x7F) || ch > 0x9F) &&
-      !ui::IsSystemKeyModifier(flags);
+  // Alt+Ctrl or Right Alt, and on Linux it's a different flag that we don't
+  // care about.
+  const bool should_insert_char = ((ch >= 0x20 && ch < 0x7F) || ch > 0x9F) &&
+                                  !ui::IsSystemKeyModifier(flags);
   if (GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE || !should_insert_char)
     return;
 
diff --git a/ui/views/controls/textfield/textfield_unittest.cc b/ui/views/controls/textfield/textfield_unittest.cc
index 4bb9f54..42b629fc 100644
--- a/ui/views/controls/textfield/textfield_unittest.cc
+++ b/ui/views/controls/textfield/textfield_unittest.cc
@@ -727,6 +727,9 @@
   const int altgr = ui::EF_ALTGR_DOWN;
   const int shift = ui::EF_SHIFT_DOWN;
 
+  SendKeyPress(ui::VKEY_T, shift | alt | altgr);
+  SendKeyPress(ui::VKEY_H, alt);
+  SendKeyPress(ui::VKEY_E, altgr);
   SendKeyPress(ui::VKEY_T, shift);
   SendKeyPress(ui::VKEY_E, shift | altgr);
   SendKeyPress(ui::VKEY_X, 0);
@@ -737,9 +740,9 @@
   SendKeyPress(ui::VKEY_4, 0);
 
   if (TestingNativeCrOs())
-    EXPECT_STR_EQ("TEx34", textfield_->text());
+    EXPECT_STR_EQ("TeTEx34", textfield_->text());
   else
-    EXPECT_STR_EQ("TEx234", textfield_->text());
+    EXPECT_STR_EQ("TeTEx234", textfield_->text());
 }
 
 TEST_F(TextfieldTest, ControlAndSelectTest) {