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

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

Issue 1029004: GTK: implement extension bookmark manager drag api.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/web_drag_dest_gtk.h" 5 #include "chrome/browser/tab_contents/web_drag_dest_gtk.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "app/gtk_dnd_util.h" 9 #include "app/gtk_dnd_util.h"
10 #include "base/file_path.h" 10 #include "base/file_path.h"
11 #include "base/utf_string_conversions.h" 11 #include "base/utf_string_conversions.h"
12 #include "chrome/browser/gtk/bookmark_utils_gtk.h"
12 #include "chrome/browser/gtk/gtk_util.h" 13 #include "chrome/browser/gtk/gtk_util.h"
13 #include "chrome/browser/renderer_host/render_view_host.h" 14 #include "chrome/browser/renderer_host/render_view_host.h"
14 #include "chrome/browser/tab_contents/tab_contents.h" 15 #include "chrome/browser/tab_contents/tab_contents.h"
15 #include "net/base/net_util.h" 16 #include "net/base/net_util.h"
16 17
17 using WebKit::WebDragOperation; 18 using WebKit::WebDragOperation;
18 using WebKit::WebDragOperationCopy; 19 using WebKit::WebDragOperationCopy;
19 using WebKit::WebDragOperationMove; 20 using WebKit::WebDragOperationMove;
20 using WebKit::WebDragOperationNone; 21 using WebKit::WebDragOperationNone;
21 22
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 // wrong. 54 // wrong.
54 is_drop_target_ = operation != WebDragOperationNone; 55 is_drop_target_ = operation != WebDragOperationNone;
55 gdk_drag_status(context_, is_drop_target_ ? GDK_ACTION_COPY : 56 gdk_drag_status(context_, is_drop_target_ ? GDK_ACTION_COPY :
56 static_cast<GdkDragAction>(0), 57 static_cast<GdkDragAction>(0),
57 drag_over_time_); 58 drag_over_time_);
58 } 59 }
59 } 60 }
60 61
61 void WebDragDestGtk::DragLeave() { 62 void WebDragDestGtk::DragLeave() {
62 tab_contents_->render_view_host()->DragTargetDragLeave(); 63 tab_contents_->render_view_host()->DragTargetDragLeave();
64
65 if (tab_contents_->GetBookmarkDragDelegate()) {
66 tab_contents_->GetBookmarkDragDelegate()->OnDragLeave(bookmark_drag_data_);
67 }
63 } 68 }
64 69
65 gboolean WebDragDestGtk::OnDragMotion(GtkWidget* sender, 70 gboolean WebDragDestGtk::OnDragMotion(GtkWidget* sender,
66 GdkDragContext* context, 71 GdkDragContext* context,
67 gint x, gint y, 72 gint x, gint y,
68 guint time) { 73 guint time) {
69 if (context_ != context) { 74 if (context_ != context) {
70 context_ = context; 75 context_ = context;
71 drop_data_.reset(new WebDropData); 76 drop_data_.reset(new WebDropData);
72 is_drop_target_ = false; 77 is_drop_target_ = false;
73 78
74 static int supported_targets[] = { 79 static int supported_targets[] = {
75 gtk_dnd_util::TEXT_PLAIN, 80 gtk_dnd_util::TEXT_PLAIN,
76 gtk_dnd_util::TEXT_URI_LIST, 81 gtk_dnd_util::TEXT_URI_LIST,
77 gtk_dnd_util::TEXT_HTML, 82 gtk_dnd_util::TEXT_HTML,
78 gtk_dnd_util::NETSCAPE_URL, 83 gtk_dnd_util::NETSCAPE_URL,
79 gtk_dnd_util::CHROME_NAMED_URL, 84 gtk_dnd_util::CHROME_NAMED_URL,
85 gtk_dnd_util::CHROME_BOOKMARK_ITEM,
80 // TODO(estade): support image drags? 86 // TODO(estade): support image drags?
81 }; 87 };
82 88
83 data_requests_ = arraysize(supported_targets); 89 data_requests_ = arraysize(supported_targets);
84 for (size_t i = 0; i < arraysize(supported_targets); ++i) { 90 for (size_t i = 0; i < arraysize(supported_targets); ++i) {
85 gtk_drag_get_data(widget_, context, 91 gtk_drag_get_data(widget_, context,
86 gtk_dnd_util::GetAtomForTarget(supported_targets[i]), 92 gtk_dnd_util::GetAtomForTarget(supported_targets[i]),
87 time); 93 time);
88 } 94 }
89 } else if (data_requests_ == 0) { 95 } else if (data_requests_ == 0) {
96 // TODO(snej): Pass appropriate DragOperation instead of hardcoding
90 tab_contents_->render_view_host()-> 97 tab_contents_->render_view_host()->
91 DragTargetDragOver(gtk_util::ClientPoint(widget_), 98 DragTargetDragOver(gtk_util::ClientPoint(widget_),
92 gtk_util::ScreenPoint(widget_), 99 gtk_util::ScreenPoint(widget_),
93 static_cast<WebDragOperation>( 100 static_cast<WebDragOperation>(
94 WebDragOperationCopy | WebDragOperationMove)); 101 WebDragOperationCopy | WebDragOperationMove));
95 // TODO(snej): Pass appropriate DragOperation instead of hardcoding 102 if (tab_contents_->GetBookmarkDragDelegate())
103 tab_contents_->GetBookmarkDragDelegate()->OnDragOver(bookmark_drag_data_);
96 drag_over_time_ = time; 104 drag_over_time_ = time;
97 } 105 }
98 106
99 // Pretend we are a drag destination because we don't want to wait for 107 // Pretend we are a drag destination because we don't want to wait for
100 // the renderer to tell us if we really are or not. 108 // the renderer to tell us if we really are or not.
101 return TRUE; 109 return TRUE;
102 } 110 }
103 111
104 void WebDragDestGtk::OnDragDataReceived( 112 void WebDragDestGtk::OnDragDataReceived(
105 GtkWidget* sender, GdkDragContext* context, gint x, gint y, 113 GtkWidget* sender, GdkDragContext* context, gint x, gint y,
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 size_t split = netscape_url.find_first_of('\n'); 161 size_t split = netscape_url.find_first_of('\n');
154 if (split != std::string::npos) { 162 if (split != std::string::npos) {
155 drop_data_->url_title = UTF8ToUTF16(netscape_url.substr(0, split)); 163 drop_data_->url_title = UTF8ToUTF16(netscape_url.substr(0, split));
156 if (split < netscape_url.size() - 1) 164 if (split < netscape_url.size() - 1)
157 drop_data_->url = GURL(netscape_url.substr(split + 1)); 165 drop_data_->url = GURL(netscape_url.substr(split + 1));
158 } 166 }
159 } else if (data->target == 167 } else if (data->target ==
160 gtk_dnd_util::GetAtomForTarget(gtk_dnd_util::CHROME_NAMED_URL)) { 168 gtk_dnd_util::GetAtomForTarget(gtk_dnd_util::CHROME_NAMED_URL)) {
161 gtk_dnd_util::ExtractNamedURL(data, 169 gtk_dnd_util::ExtractNamedURL(data,
162 &drop_data_->url, &drop_data_->url_title); 170 &drop_data_->url, &drop_data_->url_title);
171 } else if (data->target ==
172 gtk_dnd_util::GetAtomForTarget(
173 gtk_dnd_util::CHROME_BOOKMARK_ITEM)) {
174 bookmark_drag_data_.ReadFromVector(
175 bookmark_utils::GetNodesFromSelection(
176 NULL, data,
177 gtk_dnd_util::CHROME_BOOKMARK_ITEM,
178 tab_contents_->profile(), NULL, NULL));
179 bookmark_drag_data_.SetOriginatingProfile(tab_contents_->profile());
163 } 180 }
164 } 181 }
165 182
166 if (data_requests_ == 0) { 183 if (data_requests_ == 0) {
167 // Tell the renderer about the drag. 184 // Tell the renderer about the drag.
168 // |x| and |y| are seemingly arbitrary at this point. 185 // |x| and |y| are seemingly arbitrary at this point.
186 // TODO(snej): Pass appropriate DragOperation instead of hardcoding.
169 tab_contents_->render_view_host()-> 187 tab_contents_->render_view_host()->
170 DragTargetDragEnter(*drop_data_.get(), 188 DragTargetDragEnter(*drop_data_.get(),
171 gtk_util::ClientPoint(widget_), 189 gtk_util::ClientPoint(widget_),
172 gtk_util::ScreenPoint(widget_), 190 gtk_util::ScreenPoint(widget_),
173 static_cast<WebDragOperation>( 191 static_cast<WebDragOperation>(
174 WebDragOperationCopy | WebDragOperationMove)); 192 WebDragOperationCopy | WebDragOperationMove));
175 // TODO(snej): Pass appropriate DragOperation instead of hardcoding 193
194 // This is non-null if tab_contents_ is showing an ExtensionDOMUI with
195 // support for (at the moment experimental) drag and drop extensions.
196 if (tab_contents_->GetBookmarkDragDelegate()) {
197 tab_contents_->GetBookmarkDragDelegate()->OnDragEnter(
198 bookmark_drag_data_);
199 }
200
176 drag_over_time_ = time; 201 drag_over_time_ = time;
177 } 202 }
178 } 203 }
179 204
180 // The drag has left our widget; forward this information to the renderer. 205 // The drag has left our widget; forward this information to the renderer.
181 void WebDragDestGtk::OnDragLeave(GtkWidget* sender, GdkDragContext* context, 206 void WebDragDestGtk::OnDragLeave(GtkWidget* sender, GdkDragContext* context,
182 guint time) { 207 guint time) {
183 // Set |context_| to NULL to make sure we will recognize the next DragMotion 208 // Set |context_| to NULL to make sure we will recognize the next DragMotion
184 // as an enter. 209 // as an enter.
185 context_ = NULL; 210 context_ = NULL;
186 drop_data_.reset(); 211 drop_data_.reset();
187 // When GTK sends us a drag-drop signal, it is shortly (and synchronously) 212 // When GTK sends us a drag-drop signal, it is shortly (and synchronously)
188 // preceded by a drag-leave. The renderer doesn't like getting the signals 213 // preceded by a drag-leave. The renderer doesn't like getting the signals
189 // in this order so delay telling it about the drag-leave till we are sure 214 // in this order so delay telling it about the drag-leave till we are sure
190 // we are not getting a drop as well. 215 // we are not getting a drop as well.
191 MessageLoop::current()->PostTask(FROM_HERE, 216 MessageLoop::current()->PostTask(FROM_HERE,
192 method_factory_.NewRunnableMethod(&WebDragDestGtk::DragLeave)); 217 method_factory_.NewRunnableMethod(&WebDragDestGtk::DragLeave));
193 } 218 }
194 219
195 // Called by GTK when the user releases the mouse, executing a drop. 220 // Called by GTK when the user releases the mouse, executing a drop.
196 gboolean WebDragDestGtk::OnDragDrop(GtkWidget* sender, GdkDragContext* context, 221 gboolean WebDragDestGtk::OnDragDrop(GtkWidget* sender, GdkDragContext* context,
197 gint x, gint y, guint time) { 222 gint x, gint y, guint time) {
198 // Cancel that drag leave! 223 // Cancel that drag leave!
199 method_factory_.RevokeAll(); 224 method_factory_.RevokeAll();
200 225
201 tab_contents_->render_view_host()-> 226 tab_contents_->render_view_host()->
202 DragTargetDrop(gtk_util::ClientPoint(widget_), 227 DragTargetDrop(gtk_util::ClientPoint(widget_),
203 gtk_util::ScreenPoint(widget_)); 228 gtk_util::ScreenPoint(widget_));
204 229
230 // This is non-null if tab_contents_ is showing an ExtensionDOMUI with
231 // support for (at the moment experimental) drag and drop extensions.
232 if (tab_contents_->GetBookmarkDragDelegate())
233 tab_contents_->GetBookmarkDragDelegate()->OnDrop(bookmark_drag_data_);
234
205 // The second parameter is just an educated guess, but at least we will 235 // The second parameter is just an educated guess, but at least we will
206 // get the drag-end animation right sometimes. 236 // get the drag-end animation right sometimes.
207 gtk_drag_finish(context, is_drop_target_, FALSE, time); 237 gtk_drag_finish(context, is_drop_target_, FALSE, time);
208 return TRUE; 238 return TRUE;
209 } 239 }
OLDNEW
« no previous file with comments | « chrome/browser/tab_contents/web_drag_dest_gtk.h ('k') | chrome/browser/tab_contents/web_drop_target_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698