1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "chrome/browser/ui/views/dropdown_bar_host.h" 6 7 #include <gdk/gdkkeysyms.h> 8 9 #include "chrome/browser/ui/views/frame/browser_view.h" 10 #include "content/browser/tab_contents/tab_contents.h" 11 #include "views/widget/widget.h" 12 #include "views/controls/textfield/textfield.h" 13 14 #if defined(TOUCH_UI) 15 #include "ui/base/keycodes/keyboard_code_conversion_gtk.h" 16 #endif 17 18 views::Widget* DropdownBarHost::CreateHost() { 19 views::Widget::CreateParams params(views::Widget::CreateParams::TYPE_CONTROL); 20 // We own the host. 21 params.delete_on_destroy = false; 22 return views::Widget::CreateWidget(params); 23 } 24 25 void DropdownBarHost::SetWidgetPositionNative(const gfx::Rect& new_pos, 26 bool no_redraw) { 27 host_->SetBounds(new_pos); 28 host_->Show(); 29 } 30 31 NativeWebKeyboardEvent DropdownBarHost::GetKeyboardEvent( 32 const TabContents* contents, 33 const views::KeyEvent& key_event) { 34 #if defined(TOUCH_UI) 35 // TODO(oshima): This is a copy from 36 // RenderWidgetHostViewViews::OnKeyPressed(). 37 // Refactor and eliminate the dup code. 38 NativeWebKeyboardEvent wke; 39 wke.type = WebKit::WebInputEvent::KeyDown; 40 wke.windowsKeyCode = key_event.key_code(); 41 wke.setKeyIdentifierFromWindowsKeyCode(); 42 43 wke.text[0] = wke.unmodifiedText[0] = 44 static_cast<unsigned short>(gdk_keyval_to_unicode( 45 ui::GdkKeyCodeForWindowsKeyCode(key_event.key_code(), 46 key_event.IsShiftDown() ^ key_event.IsCapsLockDown()))); 47 48 // Due to a bug in GDK, gdk_keyval_to_unicode(keyval) returns 0 if keyval 49 // is GDK_Return. It should instead return '\r'. This is causing 50 // http://code.google.com/p/chromium/issues/detail?id=75779 51 // Hence, the ugly hack below. 52 // TODO(varunjain): remove the hack when the GDK bug 53 // https://bugzilla.gnome.org/show_bug.cgi?id=644836 gets sorted out. 54 if (key_event.key_code() == ui::VKEY_RETURN) { 55 wke.text[0] = wke.unmodifiedText[0] = '\r'; 56 } 57 58 return wke; 59 #else 60 return NativeWebKeyboardEvent(&key_event.native_event()->key); 61 #endif 62 } 63