| 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/tab_contents/tab_contents_view_gtk.h" | 5 #include "content/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 |
| 11 #include <algorithm> | 11 #include <algorithm> |
| 12 | 12 |
| 13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
| 14 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
| 15 #include "build/build_config.h" | 15 #include "build/build_config.h" |
| 16 #include "content/browser/renderer_host/render_view_host_factory.h" | 16 #include "content/browser/renderer_host/render_view_host_factory.h" |
| 17 #include "content/browser/renderer_host/render_view_host_impl.h" | 17 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 18 #include "content/browser/renderer_host/render_widget_host_view_gtk.h" | 18 #include "content/browser/renderer_host/render_widget_host_view_gtk.h" |
| 19 #include "content/browser/tab_contents/interstitial_page_impl.h" | 19 #include "content/browser/tab_contents/interstitial_page_impl.h" |
| 20 #include "content/browser/tab_contents/tab_contents.h" | 20 #include "content/browser/tab_contents/tab_contents.h" |
| 21 #include "content/browser/tab_contents/web_drag_dest_gtk.h" | 21 #include "content/browser/tab_contents/web_drag_dest_gtk.h" |
| 22 #include "content/browser/tab_contents/web_drag_source_gtk.h" | 22 #include "content/browser/tab_contents/web_drag_source_gtk.h" |
| 23 #include "content/public/browser/web_contents_delegate.h" | 23 #include "content/public/browser/web_contents_delegate.h" |
| 24 #include "content/public/browser/web_contents_view_gtk_delegate.h" | 24 #include "content/public/browser/web_contents_view_delegate.h" |
| 25 #include "ui/base/gtk/gtk_expanded_container.h" | 25 #include "ui/base/gtk/gtk_expanded_container.h" |
| 26 #include "ui/gfx/point.h" | 26 #include "ui/gfx/point.h" |
| 27 #include "ui/gfx/rect.h" | 27 #include "ui/gfx/rect.h" |
| 28 #include "ui/gfx/size.h" | 28 #include "ui/gfx/size.h" |
| 29 #include "webkit/glue/webdropdata.h" | 29 #include "webkit/glue/webdropdata.h" |
| 30 | 30 |
| 31 using WebKit::WebDragOperation; | 31 using WebKit::WebDragOperation; |
| 32 using WebKit::WebDragOperationsMask; | 32 using WebKit::WebDragOperationsMask; |
| 33 using content::RenderWidgetHost; | 33 using content::RenderWidgetHost; |
| 34 using content::WebContents; | 34 using content::WebContents; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 delegate->ContentsZoomChange(event->direction == GDK_SCROLL_UP); | 73 delegate->ContentsZoomChange(event->direction == GDK_SCROLL_UP); |
| 74 return TRUE; | 74 return TRUE; |
| 75 } | 75 } |
| 76 | 76 |
| 77 } // namespace | 77 } // namespace |
| 78 | 78 |
| 79 namespace content { | 79 namespace content { |
| 80 | 80 |
| 81 TabContentsViewGtk::TabContentsViewGtk( | 81 TabContentsViewGtk::TabContentsViewGtk( |
| 82 content::WebContents* web_contents, | 82 content::WebContents* web_contents, |
| 83 content::WebContentsViewGtkDelegate* delegate) | 83 content::WebContentsViewDelegate* delegate) |
| 84 : tab_contents_(static_cast<TabContents*>(web_contents)), | 84 : tab_contents_(static_cast<TabContents*>(web_contents)), |
| 85 expanded_(gtk_expanded_container_new()), | 85 expanded_(gtk_expanded_container_new()), |
| 86 delegate_(delegate) { | 86 delegate_(delegate) { |
| 87 gtk_widget_set_name(expanded_.get(), "chrome-tab-contents-view"); | 87 gtk_widget_set_name(expanded_.get(), "chrome-tab-contents-view"); |
| 88 g_signal_connect(expanded_.get(), "size-allocate", | 88 g_signal_connect(expanded_.get(), "size-allocate", |
| 89 G_CALLBACK(OnSizeAllocateThunk), this); | 89 G_CALLBACK(OnSizeAllocateThunk), this); |
| 90 g_signal_connect(expanded_.get(), "child-size-request", | 90 g_signal_connect(expanded_.get(), "child-size-request", |
| 91 G_CALLBACK(OnChildSizeRequestThunk), this); | 91 G_CALLBACK(OnChildSizeRequestThunk), this); |
| 92 | 92 |
| 93 gtk_widget_show(expanded_.get()); | 93 gtk_widget_show(expanded_.get()); |
| 94 drag_source_.reset(new content::WebDragSourceGtk(web_contents)); | 94 drag_source_.reset(new content::WebDragSourceGtk(web_contents)); |
| 95 | 95 |
| 96 if (delegate_.get()) | 96 if (delegate_.get()) |
| 97 delegate_->WrapView(this); | 97 delegate_->Initialize(expanded_.get()); |
| 98 } | 98 } |
| 99 | 99 |
| 100 TabContentsViewGtk::~TabContentsViewGtk() { | 100 TabContentsViewGtk::~TabContentsViewGtk() { |
| 101 expanded_.Destroy(); | 101 expanded_.Destroy(); |
| 102 } | 102 } |
| 103 | 103 |
| 104 void TabContentsViewGtk::CreateView(const gfx::Size& initial_size) { | 104 void TabContentsViewGtk::CreateView(const gfx::Size& initial_size) { |
| 105 requested_size_ = initial_size; | 105 requested_size_ = initial_size; |
| 106 } | 106 } |
| 107 | 107 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 129 g_signal_connect(content_view, "scroll-event", | 129 g_signal_connect(content_view, "scroll-event", |
| 130 G_CALLBACK(OnMouseScroll), tab_contents_); | 130 G_CALLBACK(OnMouseScroll), tab_contents_); |
| 131 gtk_widget_add_events(content_view, GDK_LEAVE_NOTIFY_MASK | | 131 gtk_widget_add_events(content_view, GDK_LEAVE_NOTIFY_MASK | |
| 132 GDK_POINTER_MOTION_MASK); | 132 GDK_POINTER_MOTION_MASK); |
| 133 InsertIntoContentArea(content_view); | 133 InsertIntoContentArea(content_view); |
| 134 | 134 |
| 135 // Renderer target DnD. | 135 // Renderer target DnD. |
| 136 drag_dest_.reset(new content::WebDragDestGtk(tab_contents_, content_view)); | 136 drag_dest_.reset(new content::WebDragDestGtk(tab_contents_, content_view)); |
| 137 | 137 |
| 138 if (delegate_.get()) | 138 if (delegate_.get()) |
| 139 delegate_->OnCreateViewForWidget(); | 139 drag_dest_->set_delegate(delegate_->GetDragDestDelegate()); |
| 140 | 140 |
| 141 return view; | 141 return view; |
| 142 } | 142 } |
| 143 | 143 |
| 144 gfx::NativeView TabContentsViewGtk::GetNativeView() const { | 144 gfx::NativeView TabContentsViewGtk::GetNativeView() const { |
| 145 if (delegate_.get()) | 145 if (delegate_.get()) |
| 146 return delegate_->GetNativeView(); | 146 return delegate_->GetNativeView(); |
| 147 | 147 |
| 148 return expanded_.get(); | 148 return expanded_.get(); |
| 149 } | 149 } |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 // iterated past the last focusable element on the page). | 278 // iterated past the last focusable element on the page). |
| 279 void TabContentsViewGtk::TakeFocus(bool reverse) { | 279 void TabContentsViewGtk::TakeFocus(bool reverse) { |
| 280 if (!tab_contents_->GetDelegate()) | 280 if (!tab_contents_->GetDelegate()) |
| 281 return; | 281 return; |
| 282 if (!tab_contents_->GetDelegate()->TakeFocus(reverse)) { | 282 if (!tab_contents_->GetDelegate()->TakeFocus(reverse)) { |
| 283 gtk_widget_child_focus(GTK_WIDGET(GetTopLevelNativeWindow()), | 283 gtk_widget_child_focus(GTK_WIDGET(GetTopLevelNativeWindow()), |
| 284 reverse ? GTK_DIR_TAB_BACKWARD : GTK_DIR_TAB_FORWARD); | 284 reverse ? GTK_DIR_TAB_BACKWARD : GTK_DIR_TAB_FORWARD); |
| 285 } | 285 } |
| 286 } | 286 } |
| 287 | 287 |
| 288 void TabContentsViewGtk::SetDragDestDelegate( | |
| 289 content::WebDragDestDelegate* delegate) { | |
| 290 drag_dest_->set_delegate(delegate); | |
| 291 } | |
| 292 | |
| 293 void TabContentsViewGtk::InsertIntoContentArea(GtkWidget* widget) { | 288 void TabContentsViewGtk::InsertIntoContentArea(GtkWidget* widget) { |
| 294 gtk_container_add(GTK_CONTAINER(expanded_.get()), widget); | 289 gtk_container_add(GTK_CONTAINER(expanded_.get()), widget); |
| 295 } | 290 } |
| 296 | 291 |
| 297 // Called when the content view gtk widget is tabbed to, or after the call to | 292 // Called when the content view gtk widget is tabbed to, or after the call to |
| 298 // gtk_widget_child_focus() in TakeFocus(). We return true | 293 // gtk_widget_child_focus() in TakeFocus(). We return true |
| 299 // and grab focus if we don't have it. The call to | 294 // and grab focus if we don't have it. The call to |
| 300 // FocusThroughTabTraversal(bool) forwards the "move focus forward" effect to | 295 // FocusThroughTabTraversal(bool) forwards the "move focus forward" effect to |
| 301 // webkit. | 296 // webkit. |
| 302 gboolean TabContentsViewGtk::OnFocus(GtkWidget* widget, | 297 gboolean TabContentsViewGtk::OnFocus(GtkWidget* widget, |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 430 // We manually tell our RWHV to resize the renderer content. This avoids | 425 // We manually tell our RWHV to resize the renderer content. This avoids |
| 431 // spurious resizes from GTK+. | 426 // spurious resizes from GTK+. |
| 432 RenderWidgetHostView* rwhv = tab_contents_->GetRenderWidgetHostView(); | 427 RenderWidgetHostView* rwhv = tab_contents_->GetRenderWidgetHostView(); |
| 433 if (rwhv) | 428 if (rwhv) |
| 434 rwhv->SetSize(size); | 429 rwhv->SetSize(size); |
| 435 if (tab_contents_->GetInterstitialPage()) | 430 if (tab_contents_->GetInterstitialPage()) |
| 436 tab_contents_->GetInterstitialPage()->SetSize(size); | 431 tab_contents_->GetInterstitialPage()->SetSize(size); |
| 437 } | 432 } |
| 438 | 433 |
| 439 } // namespace content | 434 } // namespace content |
| OLD | NEW |