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

Side by Side Diff: webkit/glue/plugins/gtk_plugin_container_manager.cc

Issue 6012002: Move the NPAPI files from webkit/glue/plugins to webkit/plugins/npapi and put... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 10 years 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "webkit/glue/plugins/gtk_plugin_container_manager.h"
6
7 #include <gtk/gtk.h>
8
9 #include "base/logging.h"
10 #include "gfx/gtk_util.h"
11 #include "webkit/glue/plugins/gtk_plugin_container.h"
12 #include "webkit/glue/plugins/webplugin.h"
13
14 GtkPluginContainerManager::GtkPluginContainerManager() : host_widget_(NULL) {}
15
16 GtkPluginContainerManager::~GtkPluginContainerManager() {}
17
18 GtkWidget* GtkPluginContainerManager::CreatePluginContainer(
19 gfx::PluginWindowHandle id) {
20 DCHECK(host_widget_);
21 GtkWidget *widget = gtk_plugin_container_new();
22 plugin_window_to_widget_map_.insert(std::make_pair(id, widget));
23
24 // The Realize callback is responsible for adding the plug into the socket.
25 // The reason is 2-fold:
26 // - the plug can't be added until the socket is realized, but this may not
27 // happen until the socket is attached to a top-level window, which isn't the
28 // case for background tabs.
29 // - when dragging tabs, the socket gets unrealized, which breaks the XEMBED
30 // connection. We need to make it again when the tab is reattached, and the
31 // socket gets realized again.
32 //
33 // Note, the RealizeCallback relies on the plugin_window_to_widget_map_ to
34 // have the mapping.
35 g_signal_connect(widget, "realize",
36 G_CALLBACK(RealizeCallback), this);
37
38 // Don't destroy the widget when the plug is removed.
39 g_signal_connect(widget, "plug-removed",
40 G_CALLBACK(gtk_true), NULL);
41
42 gtk_container_add(GTK_CONTAINER(host_widget_), widget);
43 gtk_widget_show(widget);
44
45 return widget;
46 }
47
48 void GtkPluginContainerManager::DestroyPluginContainer(
49 gfx::PluginWindowHandle id) {
50 DCHECK(host_widget_);
51 GtkWidget* widget = MapIDToWidget(id);
52 if (widget)
53 gtk_widget_destroy(widget);
54
55 plugin_window_to_widget_map_.erase(id);
56 }
57
58 void GtkPluginContainerManager::MovePluginContainer(
59 const webkit_glue::WebPluginGeometry& move) {
60 DCHECK(host_widget_);
61 GtkWidget *widget = MapIDToWidget(move.window);
62 if (!widget)
63 return;
64
65 DCHECK(!GTK_WIDGET_NO_WINDOW(widget));
66
67 if (!move.visible) {
68 gtk_widget_hide(widget);
69 return;
70 }
71
72 gtk_widget_show(widget);
73
74 if (!move.rects_valid)
75 return;
76
77 // TODO(piman): if the widget hasn't been realized (e.g. the tab has been
78 // torn off and the parent gtk widget has been detached from the hierarchy),
79 // we lose the cutout information.
80 if (GTK_WIDGET_REALIZED(widget)) {
81 GdkRectangle clip_rect = move.clip_rect.ToGdkRectangle();
82 GdkRegion* clip_region = gdk_region_rectangle(&clip_rect);
83 gfx::SubtractRectanglesFromRegion(clip_region, move.cutout_rects);
84 gdk_window_shape_combine_region(widget->window, clip_region, 0, 0);
85 gdk_region_destroy(clip_region);
86 }
87
88 // Update the window position. Resizing is handled by WebPluginDelegate.
89 // TODO(deanm): Verify that we only need to move and not resize.
90 // TODO(evanm): we should cache the last shape and position and skip all
91 // of this business in the common case where nothing has changed.
92 int current_x, current_y;
93
94 // Until the above TODO is resolved, we can grab the last position
95 // off of the GtkFixed with a bit of hackery.
96 GValue value = {0};
97 g_value_init(&value, G_TYPE_INT);
98 gtk_container_child_get_property(GTK_CONTAINER(host_widget_), widget,
99 "x", &value);
100 current_x = g_value_get_int(&value);
101 gtk_container_child_get_property(GTK_CONTAINER(host_widget_), widget,
102 "y", &value);
103 current_y = g_value_get_int(&value);
104 g_value_unset(&value);
105
106 if (move.window_rect.x() != current_x ||
107 move.window_rect.y() != current_y) {
108 // Calling gtk_fixed_move unnecessarily is a no-no, as it causes the
109 // parent window to repaint!
110 gtk_fixed_move(GTK_FIXED(host_widget_),
111 widget,
112 move.window_rect.x(),
113 move.window_rect.y());
114 }
115
116 gtk_plugin_container_set_size(widget,
117 move.window_rect.width(),
118 move.window_rect.height());
119 }
120
121 GtkWidget* GtkPluginContainerManager::MapIDToWidget(
122 gfx::PluginWindowHandle id) {
123 PluginWindowToWidgetMap::const_iterator i =
124 plugin_window_to_widget_map_.find(id);
125 if (i != plugin_window_to_widget_map_.end())
126 return i->second;
127
128 LOG(ERROR) << "Request for widget host for unknown window id " << id;
129
130 return NULL;
131 }
132
133 gfx::PluginWindowHandle GtkPluginContainerManager::MapWidgetToID(
134 GtkWidget* widget) {
135 for (PluginWindowToWidgetMap::const_iterator i =
136 plugin_window_to_widget_map_.begin();
137 i != plugin_window_to_widget_map_.end(); ++i) {
138 if (i->second == widget)
139 return i->first;
140 }
141
142 LOG(ERROR) << "Request for id for unknown widget";
143 return 0;
144 }
145
146 // static
147 void GtkPluginContainerManager::RealizeCallback(GtkWidget* widget,
148 void* user_data) {
149 GtkPluginContainerManager* plugin_container_manager =
150 static_cast<GtkPluginContainerManager*>(user_data);
151
152 gfx::PluginWindowHandle id = plugin_container_manager->MapWidgetToID(widget);
153 if (id)
154 gtk_socket_add_id(GTK_SOCKET(widget), id);
155 }
OLDNEW
« no previous file with comments | « webkit/glue/plugins/gtk_plugin_container_manager.h ('k') | webkit/glue/plugins/npapi_extension_thunk.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698