| OLD | NEW |
| 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/gtk/tab_contents_drag_source.h" | 5 #include "chrome/browser/gtk/tab_contents_drag_source.h" |
| 6 | 6 |
| 7 #include "app/gtk_dnd_util.h" | 7 #include "app/gtk_dnd_util.h" |
| 8 #include "base/mime_util.h" | 8 #include "base/mime_util.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "chrome/browser/renderer_host/render_view_host_delegate.h" | 10 #include "chrome/browser/renderer_host/render_view_host_delegate.h" |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 tab_contents()->render_view_host()->DragSourceMovedTo( | 120 tab_contents()->render_view_host()->DragSourceMovedTo( |
| 121 client.x(), client.y(), | 121 client.x(), client.y(), |
| 122 static_cast<int>(event_motion->x_root), | 122 static_cast<int>(event_motion->x_root), |
| 123 static_cast<int>(event_motion->y_root)); | 123 static_cast<int>(event_motion->y_root)); |
| 124 } | 124 } |
| 125 } | 125 } |
| 126 | 126 |
| 127 void TabContentsDragSource::OnDragDataGet( | 127 void TabContentsDragSource::OnDragDataGet( |
| 128 GdkDragContext* context, GtkSelectionData* selection_data, | 128 GdkDragContext* context, GtkSelectionData* selection_data, |
| 129 guint target_type, guint time) { | 129 guint target_type, guint time) { |
| 130 const int bits_per_byte = 8; | 130 const int kBitsPerByte = 8; |
| 131 | 131 |
| 132 switch (target_type) { | 132 switch (target_type) { |
| 133 case GtkDndUtil::TEXT_PLAIN: { | 133 case GtkDndUtil::TEXT_PLAIN: { |
| 134 std::string utf8_text = UTF16ToUTF8(drop_data_->plain_text); | 134 std::string utf8_text = UTF16ToUTF8(drop_data_->plain_text); |
| 135 gtk_selection_data_set_text(selection_data, utf8_text.c_str(), | 135 gtk_selection_data_set_text(selection_data, utf8_text.c_str(), |
| 136 utf8_text.length()); | 136 utf8_text.length()); |
| 137 break; | 137 break; |
| 138 } | 138 } |
| 139 | 139 |
| 140 case GtkDndUtil::TEXT_HTML: { | 140 case GtkDndUtil::TEXT_HTML: { |
| 141 // TODO(estade): change relative links to be absolute using | 141 // TODO(estade): change relative links to be absolute using |
| 142 // |html_base_url|. | 142 // |html_base_url|. |
| 143 std::string utf8_text = UTF16ToUTF8(drop_data_->text_html); | 143 std::string utf8_text = UTF16ToUTF8(drop_data_->text_html); |
| 144 gtk_selection_data_set(selection_data, | 144 gtk_selection_data_set(selection_data, |
| 145 GtkDndUtil::GetAtomForTarget( | 145 GtkDndUtil::GetAtomForTarget( |
| 146 GtkDndUtil::TEXT_HTML), | 146 GtkDndUtil::TEXT_HTML), |
| 147 bits_per_byte, | 147 kBitsPerByte, |
| 148 reinterpret_cast<const guchar*>(utf8_text.c_str()), | 148 reinterpret_cast<const guchar*>(utf8_text.c_str()), |
| 149 utf8_text.length()); | 149 utf8_text.length()); |
| 150 break; | 150 break; |
| 151 } | 151 } |
| 152 | 152 |
| 153 case GtkDndUtil::TEXT_URI_LIST: | 153 case GtkDndUtil::TEXT_URI_LIST: |
| 154 case GtkDndUtil::CHROME_NAMED_URL: { | 154 case GtkDndUtil::CHROME_NAMED_URL: |
| 155 case GtkDndUtil::NETSCAPE_URL: { |
| 155 GtkDndUtil::WriteURLWithName(selection_data, drop_data_->url, | 156 GtkDndUtil::WriteURLWithName(selection_data, drop_data_->url, |
| 156 drop_data_->url_title, target_type); | 157 drop_data_->url_title, target_type); |
| 157 break; | 158 break; |
| 158 } | 159 } |
| 159 | 160 |
| 160 case GtkDndUtil::NETSCAPE_URL: { | |
| 161 // _NETSCAPE_URL format is URL + \n + title. | |
| 162 std::string utf8_text = drop_data_->url.spec() + "\n" + UTF16ToUTF8( | |
| 163 drop_data_->url_title); | |
| 164 gtk_selection_data_set(selection_data, | |
| 165 selection_data->target, | |
| 166 bits_per_byte, | |
| 167 reinterpret_cast<const guchar*>(utf8_text.c_str()), | |
| 168 utf8_text.length()); | |
| 169 break; | |
| 170 } | |
| 171 | |
| 172 case GtkDndUtil::CHROME_WEBDROP_FILE_CONTENTS: { | 161 case GtkDndUtil::CHROME_WEBDROP_FILE_CONTENTS: { |
| 173 gtk_selection_data_set( | 162 gtk_selection_data_set( |
| 174 selection_data, | 163 selection_data, |
| 175 drag_file_mime_type_, bits_per_byte, | 164 drag_file_mime_type_, kBitsPerByte, |
| 176 reinterpret_cast<const guchar*>(drop_data_->file_contents.data()), | 165 reinterpret_cast<const guchar*>(drop_data_->file_contents.data()), |
| 177 drop_data_->file_contents.length()); | 166 drop_data_->file_contents.length()); |
| 178 break; | 167 break; |
| 179 } | 168 } |
| 180 | 169 |
| 181 default: | 170 default: |
| 182 NOTREACHED(); | 171 NOTREACHED(); |
| 183 } | 172 } |
| 184 } | 173 } |
| 185 | 174 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 214 | 203 |
| 215 if (tab_contents()->render_view_host()) | 204 if (tab_contents()->render_view_host()) |
| 216 tab_contents()->render_view_host()->DragSourceSystemDragEnded(); | 205 tab_contents()->render_view_host()->DragSourceSystemDragEnded(); |
| 217 | 206 |
| 218 drop_data_.reset(); | 207 drop_data_.reset(); |
| 219 } | 208 } |
| 220 | 209 |
| 221 gfx::NativeView TabContentsDragSource::GetContentNativeView() const { | 210 gfx::NativeView TabContentsDragSource::GetContentNativeView() const { |
| 222 return tab_contents_view_->GetContentNativeView(); | 211 return tab_contents_view_->GetContentNativeView(); |
| 223 } | 212 } |
| OLD | NEW |