Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(136)

Side by Side Diff: chrome/browser/tab_contents/chrome_web_contents_view_gtk_delegate.cc

Issue 9586009: Move TabContentsViewGtk's delegate to content\public\browser. Also name it a delegate instead of a … (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "chrome/browser/tab_contents/chrome_tab_contents_view_wrapper_gtk.h" 5 #include "chrome/browser/tab_contents/chrome_web_contents_view_gtk_delegate.h"
6 6
7 #include "chrome/browser/browser_shutdown.h" 7 #include "chrome/browser/browser_shutdown.h"
8 #include "chrome/browser/tab_contents/render_view_context_menu_gtk.h" 8 #include "chrome/browser/tab_contents/render_view_context_menu_gtk.h"
9 #include "chrome/browser/tab_contents/web_drag_bookmark_handler_gtk.h" 9 #include "chrome/browser/tab_contents/web_drag_bookmark_handler_gtk.h"
10 #include "chrome/browser/ui/gtk/constrained_window_gtk.h" 10 #include "chrome/browser/ui/gtk/constrained_window_gtk.h"
11 #include "content/browser/renderer_host/render_view_host.h" 11 #include "content/browser/renderer_host/render_view_host.h"
12 #include "content/browser/tab_contents/tab_contents_view_gtk.h" 12 #include "content/browser/tab_contents/tab_contents_view_gtk.h"
13 #include "content/public/browser/render_process_host.h" 13 #include "content/public/browser/render_process_host.h"
14 #include "content/public/browser/render_widget_host_view.h" 14 #include "content/public/browser/render_widget_host_view.h"
15 #include "content/public/browser/web_contents.h" 15 #include "content/public/browser/web_contents.h"
16 #include "ui/base/gtk/gtk_floating_container.h" 16 #include "ui/base/gtk/gtk_floating_container.h"
17 17
18 ChromeTabContentsViewWrapperGtk::ChromeTabContentsViewWrapperGtk() 18 ChromeWebContentsViewGtkDelegate::ChromeWebContentsViewGtkDelegate()
19 : floating_(gtk_floating_container_new()), 19 : floating_(gtk_floating_container_new()),
20 view_(NULL), 20 view_(NULL),
21 constrained_window_(NULL) { 21 constrained_window_(NULL) {
22 gtk_widget_set_name(floating_.get(), "chrome-tab-contents-wrapper-view"); 22 gtk_widget_set_name(floating_.get(), "chrome-tab-contents-wrapper-view");
23 g_signal_connect(floating_.get(), "set-floating-position", 23 g_signal_connect(floating_.get(), "set-floating-position",
24 G_CALLBACK(OnSetFloatingPositionThunk), this); 24 G_CALLBACK(OnSetFloatingPositionThunk), this);
25 } 25 }
26 26
27 ChromeTabContentsViewWrapperGtk::~ChromeTabContentsViewWrapperGtk() { 27 ChromeWebContentsViewGtkDelegate::~ChromeWebContentsViewGtkDelegate() {
28 floating_.Destroy(); 28 floating_.Destroy();
29 } 29 }
30 30
31 void ChromeTabContentsViewWrapperGtk::AttachConstrainedWindow( 31 void ChromeWebContentsViewGtkDelegate::AttachConstrainedWindow(
32 ConstrainedWindowGtk* constrained_window) { 32 ConstrainedWindowGtk* constrained_window) {
33 DCHECK(constrained_window_ == NULL); 33 DCHECK(constrained_window_ == NULL);
34 34
35 constrained_window_ = constrained_window; 35 constrained_window_ = constrained_window;
36 gtk_floating_container_add_floating(GTK_FLOATING_CONTAINER(floating_.get()), 36 gtk_floating_container_add_floating(GTK_FLOATING_CONTAINER(floating_.get()),
37 constrained_window->widget()); 37 constrained_window->widget());
38 } 38 }
39 39
40 void ChromeTabContentsViewWrapperGtk::RemoveConstrainedWindow( 40 void ChromeWebContentsViewGtkDelegate::RemoveConstrainedWindow(
41 ConstrainedWindowGtk* constrained_window) { 41 ConstrainedWindowGtk* constrained_window) {
42 DCHECK(constrained_window == constrained_window_); 42 DCHECK(constrained_window == constrained_window_);
43 43
44 constrained_window_ = NULL; 44 constrained_window_ = NULL;
45 gtk_container_remove(GTK_CONTAINER(floating_.get()), 45 gtk_container_remove(GTK_CONTAINER(floating_.get()),
46 constrained_window->widget()); 46 constrained_window->widget());
47 } 47 }
48 48
49 void ChromeTabContentsViewWrapperGtk::WrapView( 49 void ChromeWebContentsViewGtkDelegate::WrapView(
50 content::TabContentsViewGtk* view) { 50 content::TabContentsViewGtk* view) {
51 view_ = view; 51 view_ = view;
52 52
53 gtk_container_add(GTK_CONTAINER(floating_.get()), 53 gtk_container_add(GTK_CONTAINER(floating_.get()),
54 view_->expanded_container()); 54 view_->expanded_container());
55 gtk_widget_show(floating_.get()); 55 gtk_widget_show(floating_.get());
56 } 56 }
57 57
58 gfx::NativeView ChromeTabContentsViewWrapperGtk::GetNativeView() const { 58 gfx::NativeView ChromeWebContentsViewGtkDelegate::GetNativeView() const {
59 return floating_.get(); 59 return floating_.get();
60 } 60 }
61 61
62 void ChromeTabContentsViewWrapperGtk::OnCreateViewForWidget() { 62 void ChromeWebContentsViewGtkDelegate::OnCreateViewForWidget() {
63 // We install a chrome specific handler to intercept bookmark drags for the 63 // We install a chrome specific handler to intercept bookmark drags for the
64 // bookmark manager/extension API. 64 // bookmark manager/extension API.
65 bookmark_handler_gtk_.reset(new WebDragBookmarkHandlerGtk); 65 bookmark_handler_gtk_.reset(new WebDragBookmarkHandlerGtk);
66 view_->SetDragDestDelegate(bookmark_handler_gtk_.get()); 66 view_->SetDragDestDelegate(bookmark_handler_gtk_.get());
67 } 67 }
68 68
69 void ChromeTabContentsViewWrapperGtk::Focus() { 69 void ChromeWebContentsViewGtkDelegate::Focus() {
70 if (!constrained_window_) { 70 if (!constrained_window_) {
71 GtkWidget* widget = view_->GetContentNativeView(); 71 GtkWidget* widget = view_->GetContentNativeView();
72 if (widget) 72 if (widget)
73 gtk_widget_grab_focus(widget); 73 gtk_widget_grab_focus(widget);
74 } 74 }
75 } 75 }
76 76
77 gboolean ChromeTabContentsViewWrapperGtk::OnNativeViewFocusEvent( 77 gboolean ChromeWebContentsViewGtkDelegate::OnNativeViewFocusEvent(
78 GtkWidget* widget, 78 GtkWidget* widget,
79 GtkDirectionType type, 79 GtkDirectionType type,
80 gboolean* return_value) { 80 gboolean* return_value) {
81 // If we are showing a constrained window, don't allow the native view to take 81 // If we are showing a constrained window, don't allow the native view to take
82 // focus. 82 // focus.
83 if (constrained_window_) { 83 if (constrained_window_) {
84 // If we return false, it will revert to the default handler, which will 84 // If we return false, it will revert to the default handler, which will
85 // take focus. We don't want that. But if we return true, the event will 85 // take focus. We don't want that. But if we return true, the event will
86 // stop being propagated, leaving focus wherever it is currently. That is 86 // stop being propagated, leaving focus wherever it is currently. That is
87 // also bad. So we return false to let the default handler run, but take 87 // also bad. So we return false to let the default handler run, but take
88 // focus first so as to trick it into thinking the view was already focused 88 // focus first so as to trick it into thinking the view was already focused
89 // and allowing the event to propagate. 89 // and allowing the event to propagate.
90 gtk_widget_grab_focus(widget); 90 gtk_widget_grab_focus(widget);
91 *return_value = FALSE; 91 *return_value = FALSE;
92 return TRUE; 92 return TRUE;
93 } 93 }
94 94
95 // Let the default TabContentsViewGtk::OnFocus() behaviour run. 95 // Let the default TabContentsViewGtk::OnFocus() behaviour run.
96 return FALSE; 96 return FALSE;
97 } 97 }
98 98
99 void ChromeTabContentsViewWrapperGtk::ShowContextMenu( 99 void ChromeWebContentsViewGtkDelegate::ShowContextMenu(
100 const content::ContextMenuParams& params) { 100 const content::ContextMenuParams& params) {
101 // Find out the RenderWidgetHostView that corresponds to the render widget on 101 // Find out the RenderWidgetHostView that corresponds to the render widget on
102 // which this context menu is showed, so that we can retrieve the last mouse 102 // which this context menu is showed, so that we can retrieve the last mouse
103 // down event on the render widget and use it as the timestamp of the 103 // down event on the render widget and use it as the timestamp of the
104 // activation event to show the context menu. 104 // activation event to show the context menu.
105 content::RenderWidgetHostView* view = NULL; 105 content::RenderWidgetHostView* view = NULL;
106 if (params.custom_context.render_widget_id != 106 if (params.custom_context.render_widget_id !=
107 content::CustomContextMenuContext::kCurrentRenderWidget) { 107 content::CustomContextMenuContext::kCurrentRenderWidget) {
108 IPC::Channel::Listener* listener = 108 IPC::Channel::Listener* listener =
109 view_->web_contents()->GetRenderProcessHost()->GetListenerByID( 109 view_->web_contents()->GetRenderProcessHost()->GetListenerByID(
(...skipping 11 matching lines...) Expand all
121 new RenderViewContextMenuGtk(view_->web_contents(), params, view)); 121 new RenderViewContextMenuGtk(view_->web_contents(), params, view));
122 context_menu_->Init(); 122 context_menu_->Init();
123 123
124 gfx::Rect bounds; 124 gfx::Rect bounds;
125 view_->GetContainerBounds(&bounds); 125 view_->GetContainerBounds(&bounds);
126 gfx::Point point = bounds.origin(); 126 gfx::Point point = bounds.origin();
127 point.Offset(params.x, params.y); 127 point.Offset(params.x, params.y);
128 context_menu_->Popup(point); 128 context_menu_->Popup(point);
129 } 129 }
130 130
131 void ChromeTabContentsViewWrapperGtk::OnSetFloatingPosition( 131 void ChromeWebContentsViewGtkDelegate::OnSetFloatingPosition(
132 GtkWidget* floating_container, GtkAllocation* allocation) { 132 GtkWidget* floating_container, GtkAllocation* allocation) {
133 if (!constrained_window_) 133 if (!constrained_window_)
134 return; 134 return;
135 135
136 // Place each ConstrainedWindow in the center of the view. 136 // Place each ConstrainedWindow in the center of the view.
137 GtkWidget* widget = constrained_window_->widget(); 137 GtkWidget* widget = constrained_window_->widget();
138 DCHECK(gtk_widget_get_parent(widget) == floating_.get()); 138 DCHECK(gtk_widget_get_parent(widget) == floating_.get());
139 139
140 GtkRequisition requisition; 140 GtkRequisition requisition;
141 gtk_widget_size_request(widget, &requisition); 141 gtk_widget_size_request(widget, &requisition);
142 142
143 GValue value = { 0, }; 143 GValue value = { 0, };
144 g_value_init(&value, G_TYPE_INT); 144 g_value_init(&value, G_TYPE_INT);
145 145
146 int child_x = std::max((allocation->width - requisition.width) / 2, 0); 146 int child_x = std::max((allocation->width - requisition.width) / 2, 0);
147 g_value_set_int(&value, child_x); 147 g_value_set_int(&value, child_x);
148 gtk_container_child_set_property(GTK_CONTAINER(floating_container), 148 gtk_container_child_set_property(GTK_CONTAINER(floating_container),
149 widget, "x", &value); 149 widget, "x", &value);
150 150
151 int child_y = std::max((allocation->height - requisition.height) / 2, 0); 151 int child_y = std::max((allocation->height - requisition.height) / 2, 0);
152 g_value_set_int(&value, child_y); 152 g_value_set_int(&value, child_y);
153 gtk_container_child_set_property(GTK_CONTAINER(floating_container), 153 gtk_container_child_set_property(GTK_CONTAINER(floating_container),
154 widget, "y", &value); 154 widget, "y", &value);
155 g_value_unset(&value); 155 g_value_unset(&value);
156 } 156 }
OLDNEW
« no previous file with comments | « chrome/browser/tab_contents/chrome_web_contents_view_gtk_delegate.h ('k') | chrome/browser/ui/gtk/constrained_window_gtk.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698