Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "views/widget/widget_gtk.h" | 5 #include "views/widget/widget_gtk.h" |
| 6 | 6 |
| 7 #include <gdk/gdk.h> | 7 #include <gdk/gdk.h> |
| 8 #include <gdk/gdkx.h> | 8 #include <gdk/gdkx.h> |
| 9 #include <X11/extensions/shape.h> | 9 #include <X11/extensions/shape.h> |
| 10 #include <X11/Xatom.h> | 10 #include <X11/Xatom.h> |
| (...skipping 1244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1255 return false; | 1255 return false; |
| 1256 | 1256 |
| 1257 // Only top-level Widget should have an InputMethod instance. | 1257 // Only top-level Widget should have an InputMethod instance. |
| 1258 if (input_method_.get()) | 1258 if (input_method_.get()) |
| 1259 input_method_->OnBlur(); | 1259 input_method_->OnBlur(); |
| 1260 return false; | 1260 return false; |
| 1261 } | 1261 } |
| 1262 | 1262 |
| 1263 gboolean WidgetGtk::OnKeyEvent(GtkWidget* widget, GdkEventKey* event) { | 1263 gboolean WidgetGtk::OnKeyEvent(GtkWidget* widget, GdkEventKey* event) { |
| 1264 KeyEvent key(reinterpret_cast<NativeEvent>(event)); | 1264 KeyEvent key(reinterpret_cast<NativeEvent>(event)); |
| 1265 if (input_method_.get()) | 1265 delegate->OnKeyEvent(key_event); |
| 1266 input_method_->DispatchKeyEvent(key); | |
| 1267 else | |
| 1268 DispatchKeyEventPostIME(key); | |
| 1269 | |
| 1270 // Returns true to prevent GtkWindow's default key event handler. | 1266 // Returns true to prevent GtkWindow's default key event handler. |
| 1271 return true; | 1267 return true; |
| 1272 } | 1268 } |
| 1273 | 1269 |
| 1274 gboolean WidgetGtk::OnQueryTooltip(GtkWidget* widget, | 1270 gboolean WidgetGtk::OnQueryTooltip(GtkWidget* widget, |
| 1275 gint x, | 1271 gint x, |
| 1276 gint y, | 1272 gint y, |
| 1277 gboolean keyboard_mode, | 1273 gboolean keyboard_mode, |
| 1278 GtkTooltip* tooltip) { | 1274 GtkTooltip* tooltip) { |
| 1279 return tooltip_manager_->ShowTooltip(x, y, keyboard_mode, tooltip); | 1275 return tooltip_manager_->ShowTooltip(x, y, keyboard_mode, tooltip); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1339 | 1335 |
| 1340 RootView* WidgetGtk::CreateRootView() { | 1336 RootView* WidgetGtk::CreateRootView() { |
| 1341 return new RootView(this); | 1337 return new RootView(this); |
| 1342 } | 1338 } |
| 1343 | 1339 |
| 1344 gfx::AcceleratedWidget WidgetGtk::GetAcceleratedWidget() { | 1340 gfx::AcceleratedWidget WidgetGtk::GetAcceleratedWidget() { |
| 1345 DCHECK(window_contents_ && window_contents_->window); | 1341 DCHECK(window_contents_ && window_contents_->window); |
| 1346 return GDK_WINDOW_XID(window_contents_->window); | 1342 return GDK_WINDOW_XID(window_contents_->window); |
| 1347 } | 1343 } |
| 1348 | 1344 |
| 1349 void WidgetGtk::DispatchKeyEventPostIME(const KeyEvent& key) { | 1345 bool WidgetGtk::DispatchKeyEventPostIME(const KeyEvent& key) { |
| 1350 // Always reset |should_handle_menu_key_release_| unless we are handling a | 1346 // Always reset |should_handle_menu_key_release_| unless we are handling a |
| 1351 // VKEY_MENU key release event. It ensures that VKEY_MENU accelerator can only | 1347 // VKEY_MENU key release event. It ensures that VKEY_MENU accelerator can only |
| 1352 // be activated when handling a VKEY_MENU key release event which is preceded | 1348 // be activated when handling a VKEY_MENU key release event which is preceded |
| 1353 // by an unhandled VKEY_MENU key press event. See also HandleKeyboardEvent(). | 1349 // by an unhandled VKEY_MENU key press event. See also HandleKeyboardEvent(). |
| 1354 if (key.key_code() != ui::VKEY_MENU || key.type() != ui::ET_KEY_RELEASED) | 1350 if (key.key_code() != ui::VKEY_MENU || key.type() != ui::ET_KEY_RELEASED) |
| 1355 should_handle_menu_key_release_ = false; | 1351 should_handle_menu_key_release_ = false; |
| 1356 | 1352 |
| 1357 bool handled = false; | |
| 1358 | |
| 1359 // Dispatch the key event to View hierarchy first. | 1353 // Dispatch the key event to View hierarchy first. |
| 1360 handled = GetRootView()->ProcessKeyEvent(key); | 1354 bool handled = Widget::DispatchKeyEventPostIME(key); |
| 1361 | 1355 |
| 1362 if (key.key_code() == ui::VKEY_PROCESSKEY || handled) | 1356 if (key.key_code() == ui::VKEY_PROCESSKEY || handled) |
|
Ben Goodger (Google)
2011/04/12 21:11:15
See my comment in widget.cc.
Once you make those
msw
2011/04/14 21:47:39
Not so, if I understand suzhe and InputHandlerGtk
| |
| 1363 return; | 1357 return handled; |
| 1364 | 1358 |
| 1365 // Dispatch the key event to native GtkWidget hierarchy. | 1359 // Dispatch the key event to native GtkWidget hierarchy. |
| 1366 // To prevent GtkWindow from handling the key event as a keybinding, we need | 1360 // To prevent GtkWindow from handling the key event as a keybinding, we need |
| 1367 // to bypass GtkWindow's default key event handler and dispatch the event | 1361 // to bypass GtkWindow's default key event handler and dispatch the event |
| 1368 // here. | 1362 // here. |
| 1369 GdkEventKey* event = reinterpret_cast<GdkEventKey*>(key.native_event()); | 1363 GdkEventKey* event = reinterpret_cast<GdkEventKey*>(key.native_event()); |
| 1370 if (!handled && event && GTK_IS_WINDOW(widget_)) | 1364 if (!handled && event && GTK_IS_WINDOW(widget_)) |
| 1371 handled = gtk_window_propagate_key_event(GTK_WINDOW(widget_), event); | 1365 handled = gtk_window_propagate_key_event(GTK_WINDOW(widget_), event); |
| 1372 | 1366 |
| 1373 // On Linux, in order to handle VKEY_MENU (Alt) accelerator key correctly and | 1367 // On Linux, in order to handle VKEY_MENU (Alt) accelerator key correctly and |
| 1374 // avoid issues like: http://crbug.com/40966 and http://crbug.com/49701, we | 1368 // avoid issues like: http://crbug.com/40966 and http://crbug.com/49701, we |
| 1375 // should only send the key event to the focus manager if it's not handled by | 1369 // should only send the key event to the focus manager if it's not handled by |
| 1376 // any View or native GtkWidget. | 1370 // any View or native GtkWidget. |
| 1377 // The flow is different when the focus is in a RenderWidgetHostViewGtk, which | 1371 // The flow is different when the focus is in a RenderWidgetHostViewGtk, which |
| 1378 // always consumes the key event and send it back to us later by calling | 1372 // always consumes the key event and send it back to us later by calling |
| 1379 // HandleKeyboardEvent() directly, if it's not handled by webkit. | 1373 // HandleKeyboardEvent() directly, if it's not handled by webkit. |
| 1380 if (!handled) | 1374 if (!handled) |
| 1381 handled = HandleKeyboardEvent(key); | 1375 handled = HandleKeyboardEvent(key); |
| 1382 | 1376 |
| 1383 // Dispatch the key event for bindings processing. | 1377 // Dispatch the key event for bindings processing. |
| 1384 if (!handled && event && GTK_IS_WINDOW(widget_)) | 1378 if (!handled && event && GTK_IS_WINDOW(widget_)) |
| 1385 gtk_bindings_activate_event(GTK_OBJECT(widget_), event); | 1379 handled = gtk_bindings_activate_event(GTK_OBJECT(widget_), event); |
| 1380 | |
| 1381 return handled; | |
| 1386 } | 1382 } |
| 1387 | 1383 |
| 1388 gboolean WidgetGtk::OnWindowPaint(GtkWidget* widget, GdkEventExpose* event) { | 1384 gboolean WidgetGtk::OnWindowPaint(GtkWidget* widget, GdkEventExpose* event) { |
| 1389 // Clear the background to be totally transparent. We don't need to | 1385 // Clear the background to be totally transparent. We don't need to |
| 1390 // paint the root view here as that is done by OnPaint. | 1386 // paint the root view here as that is done by OnPaint. |
| 1391 DCHECK(transparent_); | 1387 DCHECK(transparent_); |
| 1392 DrawTransparentBackground(widget, event); | 1388 DrawTransparentBackground(widget, event); |
| 1393 // The Keyboard layout view has a renderer that covers the entire | 1389 // The Keyboard layout view has a renderer that covers the entire |
| 1394 // window, which prevents OnPaint from being called on window_contents_, | 1390 // window, which prevents OnPaint from being called on window_contents_, |
| 1395 // so we need to remove the FREEZE_UPDATES property here. | 1391 // so we need to remove the FREEZE_UPDATES property here. |
| (...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1716 | 1712 |
| 1717 NativeWidget* native_widget = GetNativeWidgetForNativeView(native_view); | 1713 NativeWidget* native_widget = GetNativeWidgetForNativeView(native_view); |
| 1718 if (native_widget) | 1714 if (native_widget) |
| 1719 children->insert(native_widget); | 1715 children->insert(native_widget); |
| 1720 gtk_container_foreach(GTK_CONTAINER(native_view), | 1716 gtk_container_foreach(GTK_CONTAINER(native_view), |
| 1721 EnumerateChildWidgetsForNativeWidgets, | 1717 EnumerateChildWidgetsForNativeWidgets, |
| 1722 reinterpret_cast<gpointer>(children)); | 1718 reinterpret_cast<gpointer>(children)); |
| 1723 } | 1719 } |
| 1724 | 1720 |
| 1725 } // namespace views | 1721 } // namespace views |
| OLD | NEW |