| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/browser/web_contents/web_contents_view_gtk.h" | 5 #include "content/browser/web_contents/web_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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 delegate_(delegate) { | 93 delegate_(delegate) { |
| 94 gtk_widget_set_name(expanded_.get(), "chrome-web-contents-view"); | 94 gtk_widget_set_name(expanded_.get(), "chrome-web-contents-view"); |
| 95 g_signal_connect(expanded_.get(), "size-allocate", | 95 g_signal_connect(expanded_.get(), "size-allocate", |
| 96 G_CALLBACK(OnSizeAllocateThunk), this); | 96 G_CALLBACK(OnSizeAllocateThunk), this); |
| 97 g_signal_connect(expanded_.get(), "child-size-request", | 97 g_signal_connect(expanded_.get(), "child-size-request", |
| 98 G_CALLBACK(OnChildSizeRequestThunk), this); | 98 G_CALLBACK(OnChildSizeRequestThunk), this); |
| 99 | 99 |
| 100 gtk_widget_show(expanded_.get()); | 100 gtk_widget_show(expanded_.get()); |
| 101 drag_source_.reset(new WebDragSourceGtk(web_contents)); | 101 drag_source_.reset(new WebDragSourceGtk(web_contents)); |
| 102 | 102 |
| 103 if (delegate_.get()) | 103 if (delegate_) |
| 104 delegate_->Initialize(expanded_.get(), &focus_store_); | 104 delegate_->Initialize(expanded_.get(), &focus_store_); |
| 105 } | 105 } |
| 106 | 106 |
| 107 WebContentsViewGtk::~WebContentsViewGtk() { | 107 WebContentsViewGtk::~WebContentsViewGtk() { |
| 108 expanded_.Destroy(); | 108 expanded_.Destroy(); |
| 109 } | 109 } |
| 110 | 110 |
| 111 gfx::NativeView WebContentsViewGtk::GetNativeView() const { | 111 gfx::NativeView WebContentsViewGtk::GetNativeView() const { |
| 112 if (delegate_.get()) | 112 if (delegate_) |
| 113 return delegate_->GetNativeView(); | 113 return delegate_->GetNativeView(); |
| 114 | 114 |
| 115 return expanded_.get(); | 115 return expanded_.get(); |
| 116 } | 116 } |
| 117 | 117 |
| 118 gfx::NativeView WebContentsViewGtk::GetContentNativeView() const { | 118 gfx::NativeView WebContentsViewGtk::GetContentNativeView() const { |
| 119 RenderWidgetHostView* rwhv = web_contents_->GetRenderWidgetHostView(); | 119 RenderWidgetHostView* rwhv = web_contents_->GetRenderWidgetHostView(); |
| 120 if (!rwhv) | 120 if (!rwhv) |
| 121 return NULL; | 121 return NULL; |
| 122 return rwhv->GetNativeView(); | 122 return rwhv->GetNativeView(); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 144 requested_size_.width(), requested_size_.height()); | 144 requested_size_.width(), requested_size_.height()); |
| 145 } | 145 } |
| 146 | 146 |
| 147 void WebContentsViewGtk::OnTabCrashed(base::TerminationStatus status, | 147 void WebContentsViewGtk::OnTabCrashed(base::TerminationStatus status, |
| 148 int error_code) { | 148 int error_code) { |
| 149 } | 149 } |
| 150 | 150 |
| 151 void WebContentsViewGtk::Focus() { | 151 void WebContentsViewGtk::Focus() { |
| 152 if (web_contents_->ShowingInterstitialPage()) { | 152 if (web_contents_->ShowingInterstitialPage()) { |
| 153 web_contents_->GetInterstitialPage()->Focus(); | 153 web_contents_->GetInterstitialPage()->Focus(); |
| 154 } else if (delegate_.get()) { | 154 } else if (delegate_) { |
| 155 delegate_->Focus(); | 155 delegate_->Focus(); |
| 156 } | 156 } |
| 157 } | 157 } |
| 158 | 158 |
| 159 void WebContentsViewGtk::SetInitialFocus() { | 159 void WebContentsViewGtk::SetInitialFocus() { |
| 160 if (web_contents_->FocusLocationBarByDefault()) | 160 if (web_contents_->FocusLocationBarByDefault()) |
| 161 web_contents_->SetFocusToLocationBar(false); | 161 web_contents_->SetFocusToLocationBar(false); |
| 162 else | 162 else |
| 163 Focus(); | 163 Focus(); |
| 164 } | 164 } |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 // the old one to create an identical copy. | 307 // the old one to create an identical copy. |
| 308 if (drag_dest_.get() && drag_dest_->widget() == content_view) | 308 if (drag_dest_.get() && drag_dest_->widget() == content_view) |
| 309 return; | 309 return; |
| 310 | 310 |
| 311 // Clear the currently connected drag drop signals by deleting the old | 311 // Clear the currently connected drag drop signals by deleting the old |
| 312 // drag_dest_ before creating the new one. | 312 // drag_dest_ before creating the new one. |
| 313 drag_dest_.reset(); | 313 drag_dest_.reset(); |
| 314 // Create the new drag_dest_. | 314 // Create the new drag_dest_. |
| 315 drag_dest_.reset(new WebDragDestGtk(web_contents_, content_view)); | 315 drag_dest_.reset(new WebDragDestGtk(web_contents_, content_view)); |
| 316 | 316 |
| 317 if (delegate_.get()) | 317 if (delegate_) |
| 318 drag_dest_->set_delegate(delegate_->GetDragDestDelegate()); | 318 drag_dest_->set_delegate(delegate_->GetDragDestDelegate()); |
| 319 } | 319 } |
| 320 | 320 |
| 321 // Called when the content view gtk widget is tabbed to, or after the call to | 321 // Called when the content view gtk widget is tabbed to, or after the call to |
| 322 // gtk_widget_child_focus() in TakeFocus(). We return true | 322 // gtk_widget_child_focus() in TakeFocus(). We return true |
| 323 // and grab focus if we don't have it. The call to | 323 // and grab focus if we don't have it. The call to |
| 324 // FocusThroughTabTraversal(bool) forwards the "move focus forward" effect to | 324 // FocusThroughTabTraversal(bool) forwards the "move focus forward" effect to |
| 325 // webkit. | 325 // webkit. |
| 326 gboolean WebContentsViewGtk::OnFocus(GtkWidget* widget, | 326 gboolean WebContentsViewGtk::OnFocus(GtkWidget* widget, |
| 327 GtkDirectionType focus) { | 327 GtkDirectionType focus) { |
| 328 // Give our view wrapper first chance at this event. | 328 // Give our view wrapper first chance at this event. |
| 329 if (delegate_.get()) { | 329 if (delegate_) { |
| 330 gboolean return_value = FALSE; | 330 gboolean return_value = FALSE; |
| 331 if (delegate_->OnNativeViewFocusEvent(widget, focus, &return_value)) | 331 if (delegate_->OnNativeViewFocusEvent(widget, focus, &return_value)) |
| 332 return return_value; | 332 return return_value; |
| 333 } | 333 } |
| 334 | 334 |
| 335 // If we already have focus, let the next widget have a shot at it. We will | 335 // If we already have focus, let the next widget have a shot at it. We will |
| 336 // reach this situation after the call to gtk_widget_child_focus() in | 336 // reach this situation after the call to gtk_widget_child_focus() in |
| 337 // TakeFocus(). | 337 // TakeFocus(). |
| 338 if (gtk_widget_is_focus(widget)) | 338 if (gtk_widget_is_focus(widget)) |
| 339 return FALSE; | 339 return FALSE; |
| 340 | 340 |
| 341 gtk_widget_grab_focus(widget); | 341 gtk_widget_grab_focus(widget); |
| 342 bool reverse = focus == GTK_DIR_TAB_BACKWARD; | 342 bool reverse = focus == GTK_DIR_TAB_BACKWARD; |
| 343 web_contents_->FocusThroughTabTraversal(reverse); | 343 web_contents_->FocusThroughTabTraversal(reverse); |
| 344 return TRUE; | 344 return TRUE; |
| 345 } | 345 } |
| 346 | 346 |
| 347 void WebContentsViewGtk::ShowContextMenu( | 347 void WebContentsViewGtk::ShowContextMenu( |
| 348 const ContextMenuParams& params, | 348 const ContextMenuParams& params, |
| 349 ContextMenuSourceType type) { | 349 ContextMenuSourceType type) { |
| 350 if (delegate_.get()) | 350 if (delegate_) |
| 351 delegate_->ShowContextMenu(params, type); | 351 delegate_->ShowContextMenu(params, type); |
| 352 else | 352 else |
| 353 DLOG(ERROR) << "Cannot show context menus without a delegate."; | 353 DLOG(ERROR) << "Cannot show context menus without a delegate."; |
| 354 } | 354 } |
| 355 | 355 |
| 356 void WebContentsViewGtk::ShowPopupMenu(const gfx::Rect& bounds, | 356 void WebContentsViewGtk::ShowPopupMenu(const gfx::Rect& bounds, |
| 357 int item_height, | 357 int item_height, |
| 358 double item_font_size, | 358 double item_font_size, |
| 359 int selected_item, | 359 int selected_item, |
| 360 const std::vector<WebMenuItem>& items, | 360 const std::vector<WebMenuItem>& items, |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 406 // We manually tell our RWHV to resize the renderer content. This avoids | 406 // We manually tell our RWHV to resize the renderer content. This avoids |
| 407 // spurious resizes from GTK+. | 407 // spurious resizes from GTK+. |
| 408 RenderWidgetHostView* rwhv = web_contents_->GetRenderWidgetHostView(); | 408 RenderWidgetHostView* rwhv = web_contents_->GetRenderWidgetHostView(); |
| 409 if (rwhv) | 409 if (rwhv) |
| 410 rwhv->SetSize(size); | 410 rwhv->SetSize(size); |
| 411 if (web_contents_->GetInterstitialPage()) | 411 if (web_contents_->GetInterstitialPage()) |
| 412 web_contents_->GetInterstitialPage()->SetSize(size); | 412 web_contents_->GetInterstitialPage()->SetSize(size); |
| 413 } | 413 } |
| 414 | 414 |
| 415 } // namespace content | 415 } // namespace content |
| OLD | NEW |