Commit e9035537 authored by estade@chromium.org's avatar estade@chromium.org

GTK: Support for more drag targets in renderer destination.

BUG=http://crbug.com/15429
TEST=drag a file from konqueror to the web view; observe that it causes the browser to navigate there (assuming you don't drag it into an <input> field or something).

Review URL: http://codereview.chromium.org/155175

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@20108 0039d316-1c4b-4281-b951-d872f2087c98
parent 3f873e1c
...@@ -181,14 +181,21 @@ class WebDragDest { ...@@ -181,14 +181,21 @@ class WebDragDest {
if (context_ != context) { if (context_ != context) {
context_ = context; context_ = context;
drop_data_.reset(new WebDropData); drop_data_.reset(new WebDropData);
data_requests_ = 0;
is_drop_target_ = false; is_drop_target_ = false;
// TODO(estade): support other targets. When we start support URL drags, static int supported_targets[] = {
// we'll have to worry about interstitial pages (see web_drop_target.cc). GtkDndUtil::X_CHROME_TEXT_PLAIN,
data_requests_++; GtkDndUtil::X_CHROME_TEXT_URI_LIST,
gtk_drag_get_data(widget_, context, GtkDndUtil::X_CHROME_TEXT_HTML,
gdk_atom_intern("text/plain", FALSE), time); // TODO(estade): support image drags?
};
data_requests_ = arraysize(supported_targets);
for (size_t i = 0; i < arraysize(supported_targets); ++i) {
gtk_drag_get_data(widget_, context,
GtkDndUtil::GetAtomForTarget(supported_targets[i]),
time);
}
} else if (data_requests_ == 0) { } else if (data_requests_ == 0) {
tab_contents_->render_view_host()-> tab_contents_->render_view_host()->
DragTargetDragOver(ClientPoint(), ScreenPoint()); DragTargetDragOver(ClientPoint(), ScreenPoint());
...@@ -214,14 +221,42 @@ class WebDragDest { ...@@ -214,14 +221,42 @@ class WebDragDest {
data_requests_--; data_requests_--;
// If the source can't provide us with valid data for a requested target, // Decode the data.
// data->data will be NULL.
if (data->data) { if (data->data) {
drop_data_->plain_text = UTF8ToUTF16(std::string( // If the source can't provide us with valid data for a requested target,
reinterpret_cast<char*>(data->data), data->length)); // data->data will be NULL.
if (data->target ==
GtkDndUtil::GetAtomForTarget(GtkDndUtil::X_CHROME_TEXT_PLAIN)) {
guchar* text = gtk_selection_data_get_text(data);
if (text) {
drop_data_->plain_text = UTF8ToUTF16(std::string(
reinterpret_cast<char*>(text), data->length));
g_free(text);
}
} else if (data->target ==
GtkDndUtil::GetAtomForTarget(GtkDndUtil::X_CHROME_TEXT_URI_LIST)) {
gchar** uris = gtk_selection_data_get_uris(data);
if (uris) {
for (gchar** uri_iter = uris; *uri_iter; uri_iter++) {
// TODO(estade): Can the filenames have a non-UTF8 encoding?
drop_data_->filenames.push_back(UTF8ToUTF16(*uri_iter));
}
// Also, write the first URI as the URL.
if (uris[0])
drop_data_->url = GURL(uris[0]);
g_strfreev(uris);
}
} else if (data->target ==
GtkDndUtil::GetAtomForTarget(GtkDndUtil::X_CHROME_TEXT_HTML)) {
// TODO(estade): Can the html have a non-UTF8 encoding?
drop_data_->text_html = UTF8ToUTF16(std::string(
reinterpret_cast<char*>(data->data), data->length));
// We leave the base URL empty.
}
} }
if (data_requests_ == 0) { if (data_requests_ == 0) {
// Tell the renderer about the drag.
// |x| and |y| are seemingly arbitrary at this point. // |x| and |y| are seemingly arbitrary at this point.
tab_contents_->render_view_host()-> tab_contents_->render_view_host()->
DragTargetDragEnter(*drop_data_.get(), ClientPoint(), ScreenPoint()); DragTargetDragEnter(*drop_data_.get(), ClientPoint(), ScreenPoint());
...@@ -441,8 +476,7 @@ void TabContentsViewGtk::GetContainerBounds(gfx::Rect* out) const { ...@@ -441,8 +476,7 @@ void TabContentsViewGtk::GetContainerBounds(gfx::Rect* out) const {
} }
void TabContentsViewGtk::OnContentsDestroy() { void TabContentsViewGtk::OnContentsDestroy() {
// TODO(estade): Windows uses this function cancel pending drag-n-drop drags. // TODO(estade): Windows uses this for some sort of plugin-related stuff.
// We don't have drags yet, so do nothing for now.
} }
void TabContentsViewGtk::SetPageTitle(const std::wstring& title) { void TabContentsViewGtk::SetPageTitle(const std::wstring& title) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment