OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "chrome/browser/tab_contents/tab_contents_view_gtk.h" | 5 #include "chrome/browser/tab_contents/tab_contents_view_gtk.h" |
6 | 6 |
7 #include <gdk/gdk.h> | 7 #include <gdk/gdk.h> |
8 #include <gdk/gdkkeysyms.h> | 8 #include <gdk/gdkkeysyms.h> |
9 #include <gtk/gtk.h> | 9 #include <gtk/gtk.h> |
10 | 10 |
(...skipping 86 matching lines...) Loading... |
97 // Used with gtk_container_foreach to change the sizes of the children of | 97 // Used with gtk_container_foreach to change the sizes of the children of |
98 // |fixed_|. | 98 // |fixed_|. |
99 void SetSizeRequest(GtkWidget* widget, gpointer userdata) { | 99 void SetSizeRequest(GtkWidget* widget, gpointer userdata) { |
100 gfx::Size* size = static_cast<gfx::Size*>(userdata); | 100 gfx::Size* size = static_cast<gfx::Size*>(userdata); |
101 if (widget->allocation.width != size->width() || | 101 if (widget->allocation.width != size->width() || |
102 widget->allocation.height != size->height()) { | 102 widget->allocation.height != size->height()) { |
103 gtk_widget_set_size_request(widget, size->width(), size->height()); | 103 gtk_widget_set_size_request(widget, size->width(), size->height()); |
104 } | 104 } |
105 } | 105 } |
106 | 106 |
107 int GdkEventKeyToLayoutIndependentKeyval(const GdkEventKey* event) { | |
108 // This function is a copy of WebKit::gdkEventToWindowsKeyCode() but returns | |
109 // a GDK key value instead of a Windows virtual key code. | |
110 static const int kHardwareCodeToGdkKeyval[] = { | |
111 0, // 0x00: | |
112 0, // 0x01: | |
113 0, // 0x02: | |
114 0, // 0x03: | |
115 0, // 0x04: | |
116 0, // 0x05: | |
117 0, // 0x06: | |
118 0, // 0x07: | |
119 0, // 0x08: | |
120 0, // 0x09: GDK_Escape | |
121 GDK_1, // 0x0A: GDK_1 | |
122 GDK_2, // 0x0B: GDK_2 | |
123 GDK_3, // 0x0C: GDK_3 | |
124 GDK_4, // 0x0D: GDK_4 | |
125 GDK_5, // 0x0E: GDK_5 | |
126 GDK_6, // 0x0F: GDK_6 | |
127 GDK_7, // 0x10: GDK_7 | |
128 GDK_8, // 0x11: GDK_8 | |
129 GDK_9, // 0x12: GDK_9 | |
130 GDK_0, // 0x13: GDK_0 | |
131 GDK_minus, // 0x14: GDK_minus | |
132 GDK_equal, // 0x15: GDK_equal | |
133 0, // 0x16: GDK_BackSpace | |
134 0, // 0x17: GDK_Tab | |
135 GDK_q, // 0x18: GDK_q | |
136 GDK_w, // 0x19: GDK_w | |
137 GDK_e, // 0x1A: GDK_e | |
138 GDK_r, // 0x1B: GDK_r | |
139 GDK_t, // 0x1C: GDK_t | |
140 GDK_y, // 0x1D: GDK_y | |
141 GDK_u, // 0x1E: GDK_u | |
142 GDK_i, // 0x1F: GDK_i | |
143 GDK_o, // 0x20: GDK_o | |
144 GDK_p, // 0x21: GDK_p | |
145 GDK_bracketleft, // 0x22: GDK_bracketleft | |
146 GDK_bracketright, // 0x23: GDK_bracketright | |
147 0, // 0x24: GDK_Return | |
148 0, // 0x25: GDK_Control_L | |
149 GDK_a, // 0x26: GDK_a | |
150 GDK_s, // 0x27: GDK_s | |
151 GDK_d, // 0x28: GDK_d | |
152 GDK_f, // 0x29: GDK_f | |
153 GDK_g, // 0x2A: GDK_g | |
154 GDK_h, // 0x2B: GDK_h | |
155 GDK_j, // 0x2C: GDK_j | |
156 GDK_k, // 0x2D: GDK_k | |
157 GDK_l, // 0x2E: GDK_l | |
158 GDK_semicolon, // 0x2F: GDK_semicolon | |
159 GDK_apostrophe, // 0x30: GDK_apostrophe | |
160 GDK_grave, // 0x31: GDK_grave | |
161 0, // 0x32: GDK_Shift_L | |
162 GDK_backslash, // 0x33: GDK_backslash | |
163 GDK_z, // 0x34: GDK_z | |
164 GDK_x, // 0x35: GDK_x | |
165 GDK_c, // 0x36: GDK_c | |
166 GDK_v, // 0x37: GDK_v | |
167 GDK_b, // 0x38: GDK_b | |
168 GDK_n, // 0x39: GDK_n | |
169 GDK_m, // 0x3A: GDK_m | |
170 GDK_comma, // 0x3B: GDK_comma | |
171 GDK_period, // 0x3C: GDK_period | |
172 GDK_slash, // 0x3D: GDK_slash | |
173 0, // 0x3E: GDK_Shift_R | |
174 }; | |
175 | |
176 // If this |event->keyval| represents an ASCII character, we use it for | |
177 // accelerators. Otherwise, we look up a table from a hardware keycode to | |
178 // keyval and use its result. | |
179 wchar_t c = gdk_keyval_to_unicode(event->keyval); | |
180 if (c <= 0x7F) | |
181 return event->keyval; | |
182 | |
183 if (event->hardware_keycode < arraysize(kHardwareCodeToGdkKeyval)) { | |
184 int keyval = kHardwareCodeToGdkKeyval[event->hardware_keycode]; | |
185 if (keyval) | |
186 return keyval; | |
187 } | |
188 | |
189 return event->keyval; | |
190 } | |
191 | |
192 } // namespace | 107 } // namespace |
193 | 108 |
194 // A helper class that handles DnD for drops in the renderer. In GTK parlance, | 109 // A helper class that handles DnD for drops in the renderer. In GTK parlance, |
195 // this handles destination-side DnD, but not source-side DnD. | 110 // this handles destination-side DnD, but not source-side DnD. |
196 class WebDragDest { | 111 class WebDragDest { |
197 public: | 112 public: |
198 explicit WebDragDest(TabContents* tab_contents, GtkWidget* widget) | 113 explicit WebDragDest(TabContents* tab_contents, GtkWidget* widget) |
199 : tab_contents_(tab_contents), | 114 : tab_contents_(tab_contents), |
200 widget_(widget), | 115 widget_(widget), |
201 context_(NULL), | 116 context_(NULL), |
(...skipping 445 matching lines...) Loading... |
647 // Since GtkIMContext signal handlers don't use GdkEventKey objects, its | 562 // Since GtkIMContext signal handlers don't use GdkEventKey objects, its |
648 // |event.os_event| values are dummy values (or NULL.) | 563 // |event.os_event| values are dummy values (or NULL.) |
649 // We should filter out these pseudo key events to prevent unexpected | 564 // We should filter out these pseudo key events to prevent unexpected |
650 // behaviors caused by them. | 565 // behaviors caused by them. |
651 if (event.type == WebKit::WebInputEvent::Char) | 566 if (event.type == WebKit::WebInputEvent::Char) |
652 return; | 567 return; |
653 | 568 |
654 BrowserWindowGtk* browser_window = | 569 BrowserWindowGtk* browser_window = |
655 BrowserWindowGtk::GetBrowserWindowForNativeWindow(window); | 570 BrowserWindowGtk::GetBrowserWindowForNativeWindow(window); |
656 DCHECK(browser_window); | 571 DCHECK(browser_window); |
657 browser_window->HandleAccelerator( | 572 browser_window->HandleAccelerator(event.os_event); |
658 GdkEventKeyToLayoutIndependentKeyval(event.os_event), | |
659 static_cast<GdkModifierType>(event.os_event->state)); | |
660 } | 573 } |
661 | 574 |
662 void TabContentsViewGtk::Observe(NotificationType type, | 575 void TabContentsViewGtk::Observe(NotificationType type, |
663 const NotificationSource& source, | 576 const NotificationSource& source, |
664 const NotificationDetails& details) { | 577 const NotificationDetails& details) { |
665 switch (type.value) { | 578 switch (type.value) { |
666 case NotificationType::TAB_CONTENTS_CONNECTED: { | 579 case NotificationType::TAB_CONTENTS_CONNECTED: { |
667 // No need to remove the SadTabGtk's widget from the container since | 580 // No need to remove the SadTabGtk's widget from the container since |
668 // the new RenderWidgetHostViewGtk instance already removed all the | 581 // the new RenderWidgetHostViewGtk instance already removed all the |
669 // vbox's children. | 582 // vbox's children. |
(...skipping 99 matching lines...) Loading... |
769 gtk_container_child_set_property(GTK_CONTAINER(floating_container), | 682 gtk_container_child_set_property(GTK_CONTAINER(floating_container), |
770 widget, "x", &value); | 683 widget, "x", &value); |
771 | 684 |
772 int child_y = std::max(half_view_height - (requisition.height / 2), 0); | 685 int child_y = std::max(half_view_height - (requisition.height / 2), 0); |
773 g_value_set_int(&value, child_y); | 686 g_value_set_int(&value, child_y); |
774 gtk_container_child_set_property(GTK_CONTAINER(floating_container), | 687 gtk_container_child_set_property(GTK_CONTAINER(floating_container), |
775 widget, "y", &value); | 688 widget, "y", &value); |
776 g_value_unset(&value); | 689 g_value_unset(&value); |
777 } | 690 } |
778 } | 691 } |
OLD | NEW |