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

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

Issue 8344061: content: Split off ChromeTabContentsViewGtk from TabContentsViewGtk. This new (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fix clang Created 9 years, 1 month 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
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/tab_contents/chrome_tab_contents_view_wrapper_gtk.h"
6
7 #include "chrome/browser/browser_shutdown.h"
8 #include "chrome/browser/tab_contents/render_view_context_menu_gtk.h"
9 #include "chrome/browser/tab_contents/tab_contents_view_gtk.h"
10 #include "chrome/browser/tab_contents/web_drag_bookmark_handler_gtk.h"
11 #include "chrome/browser/ui/gtk/constrained_window_gtk.h"
12 #include "content/browser/renderer_host/render_view_host.h"
13 #include "content/browser/tab_contents/interstitial_page.h"
14 #include "content/browser/tab_contents/tab_contents.h"
15 #include "ui/base/gtk/gtk_floating_container.h"
16
17 ChromeTabContentsViewWrapperGtk::ChromeTabContentsViewWrapperGtk()
18 : floating_(gtk_floating_container_new()),
19 view_(NULL),
20 constrained_window_(NULL) {
21 gtk_widget_set_name(floating_.get(), "chrome-tab-contents-wrapper-view");
22 g_signal_connect(floating_.get(), "set-floating-position",
23 G_CALLBACK(OnSetFloatingPositionThunk), this);
24 }
25
26 ChromeTabContentsViewWrapperGtk::~ChromeTabContentsViewWrapperGtk() {
27 floating_.Destroy();
28 }
29
30 void ChromeTabContentsViewWrapperGtk::AttachConstrainedWindow(
31 ConstrainedWindowGtk* constrained_window) {
32 DCHECK(constrained_window_ == NULL);
33
34 constrained_window_ = constrained_window;
35 gtk_floating_container_add_floating(GTK_FLOATING_CONTAINER(floating_.get()),
36 constrained_window->widget());
37 }
38
39 void ChromeTabContentsViewWrapperGtk::RemoveConstrainedWindow(
40 ConstrainedWindowGtk* constrained_window) {
41 DCHECK(constrained_window == constrained_window_);
42
43 constrained_window_ = NULL;
44 gtk_container_remove(GTK_CONTAINER(floating_.get()),
45 constrained_window->widget());
46 }
47
48 void ChromeTabContentsViewWrapperGtk::WrapView(TabContentsViewGtk* view) {
49 view_ = view;
50
51 gtk_container_add(GTK_CONTAINER(floating_.get()),
52 view_->expanded_container());
53 gtk_widget_show(floating_.get());
54 }
55
56 gfx::NativeView ChromeTabContentsViewWrapperGtk::GetNativeView() const {
57 return floating_.get();
58 }
59
60 void ChromeTabContentsViewWrapperGtk::OnCreateViewForWidget() {
61 // We install a chrome specific handler to intercept bookmark drags for the
62 // bookmark manager/extension API.
63 bookmark_handler_gtk_.reset(new WebDragBookmarkHandlerGtk);
64 view_->SetDragDestDelegate(bookmark_handler_gtk_.get());
65 }
66
67 void ChromeTabContentsViewWrapperGtk::Focus() {
68 if (!constrained_window_) {
69 GtkWidget* widget = view_->GetContentNativeView();
70 if (widget)
71 gtk_widget_grab_focus(widget);
72 }
73 }
74
75 gboolean ChromeTabContentsViewWrapperGtk::OnNativeViewFocusEvent(
76 GtkWidget* widget,
77 GtkDirectionType type,
78 gboolean* return_value) {
79 // If we are showing a constrained window, don't allow the native view to take
80 // focus.
81 if (constrained_window_) {
82 // If we return false, it will revert to the default handler, which will
83 // take focus. We don't want that. But if we return true, the event will
84 // stop being propagated, leaving focus wherever it is currently. That is
85 // also bad. So we return false to let the default handler run, but take
86 // focus first so as to trick it into thinking the view was already focused
87 // and allowing the event to propagate.
88 gtk_widget_grab_focus(widget);
89 *return_value = FALSE;
90 return TRUE;
91 }
92
93 // Let the default TabContentsViewGtk::OnFocus() behaviour run.
94 return FALSE;
95 }
96
97 void ChromeTabContentsViewWrapperGtk::ShowContextMenu(
98 const ContextMenuParams& params) {
99 // Find out the RenderWidgetHostView that corresponds to the render widget on
100 // which this context menu is showed, so that we can retrieve the last mouse
101 // down event on the render widget and use it as the timestamp of the
102 // activation event to show the context menu.
103 RenderWidgetHostView* view = NULL;
104 if (params.custom_context.render_widget_id !=
105 webkit_glue::CustomContextMenuContext::kCurrentRenderWidget) {
106 IPC::Channel::Listener* listener =
107 view_->tab_contents()->render_view_host()->process()->GetListenerByID(
108 params.custom_context.render_widget_id);
109 if (!listener) {
110 NOTREACHED();
111 return;
112 }
113 view = static_cast<RenderWidgetHost*>(listener)->view();
114 } else {
115 view = view_->tab_contents()->GetRenderWidgetHostView();
116 }
117 if (!view)
118 return;
119
120 context_menu_.reset(new RenderViewContextMenuGtk(
121 view_->tab_contents(), params, GDK_CURRENT_TIME));
122 context_menu_->Init();
123
124 gfx::Rect bounds;
125 view_->GetContainerBounds(&bounds);
126 gfx::Point point = bounds.origin();
127 point.Offset(params.x, params.y);
128 context_menu_->Popup(point);
129 }
130
131 void ChromeTabContentsViewWrapperGtk::OnSetFloatingPosition(
132 GtkWidget* floating_container, GtkAllocation* allocation) {
133 if (!constrained_window_)
134 return;
135
136 // Place each ConstrainedWindow in the center of the view.
137 GtkWidget* widget = constrained_window_->widget();
138 DCHECK(widget->parent == floating_.get());
139
140 GtkRequisition requisition;
141 gtk_widget_size_request(widget, &requisition);
142
143 GValue value = { 0, };
144 g_value_init(&value, G_TYPE_INT);
145
146 int child_x = std::max((allocation->width - requisition.width) / 2, 0);
147 g_value_set_int(&value, child_x);
148 gtk_container_child_set_property(GTK_CONTAINER(floating_container),
149 widget, "x", &value);
150
151 int child_y = std::max((allocation->height - requisition.height) / 2, 0);
152 g_value_set_int(&value, child_y);
153 gtk_container_child_set_property(GTK_CONTAINER(floating_container),
154 widget, "y", &value);
155 g_value_unset(&value);
156 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698