OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 23 matching lines...) Expand all Loading... |
34 #include "gfx/point.h" | 34 #include "gfx/point.h" |
35 #include "gfx/rect.h" | 35 #include "gfx/rect.h" |
36 #include "gfx/size.h" | 36 #include "gfx/size.h" |
37 #include "webkit/glue/webdropdata.h" | 37 #include "webkit/glue/webdropdata.h" |
38 | 38 |
39 using WebKit::WebDragOperation; | 39 using WebKit::WebDragOperation; |
40 using WebKit::WebDragOperationsMask; | 40 using WebKit::WebDragOperationsMask; |
41 | 41 |
42 namespace { | 42 namespace { |
43 | 43 |
44 // Called when the content view gtk widget is tabbed to, or after the call to | |
45 // gtk_widget_child_focus() in TakeFocus(). We return true | |
46 // and grab focus if we don't have it. The call to | |
47 // FocusThroughTabTraversal(bool) forwards the "move focus forward" effect to | |
48 // webkit. | |
49 gboolean OnFocus(GtkWidget* widget, GtkDirectionType focus, | |
50 TabContents* tab_contents) { | |
51 // If we already have focus, let the next widget have a shot at it. We will | |
52 // reach this situation after the call to gtk_widget_child_focus() in | |
53 // TakeFocus(). | |
54 if (gtk_widget_is_focus(widget)) | |
55 return FALSE; | |
56 | |
57 gtk_widget_grab_focus(widget); | |
58 bool reverse = focus == GTK_DIR_TAB_BACKWARD; | |
59 tab_contents->FocusThroughTabTraversal(reverse); | |
60 return TRUE; | |
61 } | |
62 | |
63 // Called when the mouse leaves the widget. We notify our delegate. | 44 // Called when the mouse leaves the widget. We notify our delegate. |
64 gboolean OnLeaveNotify(GtkWidget* widget, GdkEventCrossing* event, | 45 gboolean OnLeaveNotify(GtkWidget* widget, GdkEventCrossing* event, |
65 TabContents* tab_contents) { | 46 TabContents* tab_contents) { |
66 if (tab_contents->delegate()) | 47 if (tab_contents->delegate()) |
67 tab_contents->delegate()->ContentsMouseEvent( | 48 tab_contents->delegate()->ContentsMouseEvent( |
68 tab_contents, gfx::Point(event->x_root, event->y_root), false); | 49 tab_contents, gfx::Point(event->x_root, event->y_root), false); |
69 return FALSE; | 50 return FALSE; |
70 } | 51 } |
71 | 52 |
72 // Called when the mouse moves within the widget. We notify our delegate. | 53 // Called when the mouse moves within the widget. We notify our delegate. |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 // view twice), we check for the RVH Factory, which will be set when we're | 139 // view twice), we check for the RVH Factory, which will be set when we're |
159 // making special ones (which go along with the special views). | 140 // making special ones (which go along with the special views). |
160 DCHECK(RenderViewHostFactory::has_factory()); | 141 DCHECK(RenderViewHostFactory::has_factory()); |
161 return render_widget_host->view(); | 142 return render_widget_host->view(); |
162 } | 143 } |
163 | 144 |
164 RenderWidgetHostViewGtk* view = | 145 RenderWidgetHostViewGtk* view = |
165 new RenderWidgetHostViewGtk(render_widget_host); | 146 new RenderWidgetHostViewGtk(render_widget_host); |
166 view->InitAsChild(); | 147 view->InitAsChild(); |
167 gfx::NativeView content_view = view->native_view(); | 148 gfx::NativeView content_view = view->native_view(); |
168 g_signal_connect(content_view, "focus", | 149 g_signal_connect(content_view, "focus", G_CALLBACK(OnFocusThunk), this); |
169 G_CALLBACK(OnFocus), tab_contents()); | |
170 g_signal_connect(content_view, "leave-notify-event", | 150 g_signal_connect(content_view, "leave-notify-event", |
171 G_CALLBACK(OnLeaveNotify), tab_contents()); | 151 G_CALLBACK(OnLeaveNotify), tab_contents()); |
172 g_signal_connect(content_view, "motion-notify-event", | 152 g_signal_connect(content_view, "motion-notify-event", |
173 G_CALLBACK(OnMouseMove), tab_contents()); | 153 G_CALLBACK(OnMouseMove), tab_contents()); |
174 g_signal_connect(content_view, "scroll-event", | 154 g_signal_connect(content_view, "scroll-event", |
175 G_CALLBACK(OnMouseScroll), tab_contents()); | 155 G_CALLBACK(OnMouseScroll), tab_contents()); |
176 gtk_widget_add_events(content_view, GDK_LEAVE_NOTIFY_MASK | | 156 gtk_widget_add_events(content_view, GDK_LEAVE_NOTIFY_MASK | |
177 GDK_POINTER_MOTION_MASK); | 157 GDK_POINTER_MOTION_MASK); |
178 g_signal_connect(content_view, "button-press-event", | 158 g_signal_connect(content_view, "button-press-event", |
179 G_CALLBACK(OnMouseDownThunk), this); | 159 G_CALLBACK(OnMouseDownThunk), this); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 // sizing information on to the renderer. | 216 // sizing information on to the renderer. |
237 requested_size_ = size; | 217 requested_size_ = size; |
238 RenderWidgetHostView* rwhv = tab_contents()->GetRenderWidgetHostView(); | 218 RenderWidgetHostView* rwhv = tab_contents()->GetRenderWidgetHostView(); |
239 if (rwhv) | 219 if (rwhv) |
240 rwhv->SetSize(size); | 220 rwhv->SetSize(size); |
241 } | 221 } |
242 | 222 |
243 void TabContentsViewGtk::Focus() { | 223 void TabContentsViewGtk::Focus() { |
244 if (tab_contents()->showing_interstitial_page()) { | 224 if (tab_contents()->showing_interstitial_page()) { |
245 tab_contents()->interstitial_page()->Focus(); | 225 tab_contents()->interstitial_page()->Focus(); |
246 } else { | 226 } else if (!constrained_window_) { |
247 GtkWidget* widget = GetContentNativeView(); | 227 GtkWidget* widget = GetContentNativeView(); |
248 if (widget) | 228 if (widget) |
249 gtk_widget_grab_focus(widget); | 229 gtk_widget_grab_focus(widget); |
250 } | 230 } |
251 } | 231 } |
252 | 232 |
253 void TabContentsViewGtk::SetInitialFocus() { | 233 void TabContentsViewGtk::SetInitialFocus() { |
254 if (tab_contents()->FocusLocationBarByDefault()) | 234 if (tab_contents()->FocusLocationBarByDefault()) |
255 tab_contents()->SetFocusToLocationBar(false); | 235 tab_contents()->SetFocusToLocationBar(false); |
256 else | 236 else |
257 Focus(); | 237 Focus(); |
258 } | 238 } |
259 | 239 |
260 void TabContentsViewGtk::StoreFocus() { | 240 void TabContentsViewGtk::StoreFocus() { |
261 focus_store_.Store(GetNativeView()); | 241 focus_store_.Store(GetNativeView()); |
262 } | 242 } |
263 | 243 |
264 void TabContentsViewGtk::RestoreFocus() { | 244 void TabContentsViewGtk::RestoreFocus() { |
265 if (focus_store_.widget()) | 245 if (focus_store_.widget()) |
266 gtk_widget_grab_focus(focus_store_.widget()); | 246 gtk_widget_grab_focus(focus_store_.widget()); |
267 else | 247 else |
268 SetInitialFocus(); | 248 SetInitialFocus(); |
269 } | 249 } |
270 | 250 |
| 251 void TabContentsViewGtk::SetFocusedWidget(GtkWidget* widget) { |
| 252 focus_store_.SetWidget(widget); |
| 253 } |
| 254 |
271 void TabContentsViewGtk::UpdateDragCursor(WebDragOperation operation) { | 255 void TabContentsViewGtk::UpdateDragCursor(WebDragOperation operation) { |
272 drag_dest_->UpdateDragStatus(operation); | 256 drag_dest_->UpdateDragStatus(operation); |
273 } | 257 } |
274 | 258 |
275 void TabContentsViewGtk::GotFocus() { | 259 void TabContentsViewGtk::GotFocus() { |
276 // This is only used in the views FocusManager stuff but it bleeds through | 260 // This is only used in the views FocusManager stuff but it bleeds through |
277 // all subclasses. http://crbug.com/21875 | 261 // all subclasses. http://crbug.com/21875 |
278 } | 262 } |
279 | 263 |
280 // This is called when we the renderer asks us to take focus back (i.e., it has | 264 // This is called when we the renderer asks us to take focus back (i.e., it has |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 drag_source_->StartDragging(drop_data, ops, &last_mouse_down_, image, | 309 drag_source_->StartDragging(drop_data, ops, &last_mouse_down_, image, |
326 image_offset); | 310 image_offset); |
327 } | 311 } |
328 | 312 |
329 // ----------------------------------------------------------------------------- | 313 // ----------------------------------------------------------------------------- |
330 | 314 |
331 void TabContentsViewGtk::InsertIntoContentArea(GtkWidget* widget) { | 315 void TabContentsViewGtk::InsertIntoContentArea(GtkWidget* widget) { |
332 gtk_container_add(GTK_CONTAINER(expanded_), widget); | 316 gtk_container_add(GTK_CONTAINER(expanded_), widget); |
333 } | 317 } |
334 | 318 |
| 319 // Called when the content view gtk widget is tabbed to, or after the call to |
| 320 // gtk_widget_child_focus() in TakeFocus(). We return true |
| 321 // and grab focus if we don't have it. The call to |
| 322 // FocusThroughTabTraversal(bool) forwards the "move focus forward" effect to |
| 323 // webkit. |
| 324 gboolean TabContentsViewGtk::OnFocus(GtkWidget* widget, |
| 325 GtkDirectionType focus) { |
| 326 // If we are showing a constrained window, don't allow the native view to take |
| 327 // focus. |
| 328 if (constrained_window_) { |
| 329 // If we return false, it will revert to the default handler, which will |
| 330 // take focus. We don't want that. But if we return true, the event will |
| 331 // stop being propagated, leaving focus wherever it is currently. That is |
| 332 // also bad. So we return false to let the default handler run, but take |
| 333 // focus first so as to trick it into thinking the view was already focused |
| 334 // and allowing the event to propagate. |
| 335 gtk_widget_grab_focus(widget); |
| 336 return FALSE; |
| 337 } |
| 338 |
| 339 // If we already have focus, let the next widget have a shot at it. We will |
| 340 // reach this situation after the call to gtk_widget_child_focus() in |
| 341 // TakeFocus(). |
| 342 if (gtk_widget_is_focus(widget)) |
| 343 return FALSE; |
| 344 |
| 345 gtk_widget_grab_focus(widget); |
| 346 bool reverse = focus == GTK_DIR_TAB_BACKWARD; |
| 347 tab_contents()->FocusThroughTabTraversal(reverse); |
| 348 return TRUE; |
| 349 } |
| 350 |
335 gboolean TabContentsViewGtk::OnMouseDown(GtkWidget* widget, | 351 gboolean TabContentsViewGtk::OnMouseDown(GtkWidget* widget, |
336 GdkEventButton* event) { | 352 GdkEventButton* event) { |
337 last_mouse_down_ = *event; | 353 last_mouse_down_ = *event; |
338 return FALSE; | 354 return FALSE; |
339 } | 355 } |
340 | 356 |
341 void TabContentsViewGtk::OnChildSizeRequest(GtkWidget* widget, | 357 void TabContentsViewGtk::OnChildSizeRequest(GtkWidget* widget, |
342 GtkWidget* child, | 358 GtkWidget* child, |
343 GtkRequisition* requisition) { | 359 GtkRequisition* requisition) { |
344 if (tab_contents()->delegate()) { | 360 if (tab_contents()->delegate()) { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 gtk_container_child_set_property(GTK_CONTAINER(floating_container), | 402 gtk_container_child_set_property(GTK_CONTAINER(floating_container), |
387 widget, "x", &value); | 403 widget, "x", &value); |
388 | 404 |
389 int child_y = std::max(half_view_height - (requisition.height / 2), 0); | 405 int child_y = std::max(half_view_height - (requisition.height / 2), 0); |
390 g_value_set_int(&value, child_y); | 406 g_value_set_int(&value, child_y); |
391 gtk_container_child_set_property(GTK_CONTAINER(floating_container), | 407 gtk_container_child_set_property(GTK_CONTAINER(floating_container), |
392 widget, "y", &value); | 408 widget, "y", &value); |
393 g_value_unset(&value); | 409 g_value_unset(&value); |
394 } | 410 } |
395 } | 411 } |
OLD | NEW |