| 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/bookmark_utils_gtk.h" | 5 #include "chrome/browser/gtk/bookmark_utils_gtk.h" |
| 6 | 6 |
| 7 #include "app/gtk_dnd_util.h" | 7 #include "app/gtk_dnd_util.h" |
| 8 #include "app/l10n_util.h" | 8 #include "app/l10n_util.h" |
| 9 #include "app/resource_bundle.h" | 9 #include "app/resource_bundle.h" |
| 10 #include "base/pickle.h" | 10 #include "base/pickle.h" |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 gtk_util::SetLabelColor(label, NULL); | 191 gtk_util::SetLabelColor(label, NULL); |
| 192 } else { | 192 } else { |
| 193 GdkColor color = provider->GetGdkColor( | 193 GdkColor color = provider->GetGdkColor( |
| 194 BrowserThemeProvider::COLOR_BOOKMARK_TEXT); | 194 BrowserThemeProvider::COLOR_BOOKMARK_TEXT); |
| 195 gtk_util::SetLabelColor(label, &color); | 195 gtk_util::SetLabelColor(label, &color); |
| 196 } | 196 } |
| 197 } | 197 } |
| 198 | 198 |
| 199 // DnD-related ----------------------------------------------------------------- | 199 // DnD-related ----------------------------------------------------------------- |
| 200 | 200 |
| 201 int GetCodeMask(bool folder) { |
| 202 int rv = gtk_dnd_util::CHROME_BOOKMARK_ITEM; |
| 203 if (!folder) { |
| 204 rv |= gtk_dnd_util::TEXT_URI_LIST | |
| 205 gtk_dnd_util::TEXT_PLAIN | |
| 206 gtk_dnd_util::NETSCAPE_URL; |
| 207 } |
| 208 return rv; |
| 209 } |
| 210 |
| 201 void WriteBookmarkToSelection(const BookmarkNode* node, | 211 void WriteBookmarkToSelection(const BookmarkNode* node, |
| 202 GtkSelectionData* selection_data, | 212 GtkSelectionData* selection_data, |
| 203 guint target_type, | 213 guint target_type, |
| 204 Profile* profile) { | 214 Profile* profile) { |
| 205 DCHECK(node); | 215 DCHECK(node); |
| 206 std::vector<const BookmarkNode*> nodes; | 216 std::vector<const BookmarkNode*> nodes; |
| 207 nodes.push_back(node); | 217 nodes.push_back(node); |
| 208 WriteBookmarksToSelection(nodes, selection_data, target_type, profile); | 218 WriteBookmarksToSelection(nodes, selection_data, target_type, profile); |
| 209 } | 219 } |
| 210 | 220 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 } | 275 } |
| 266 } | 276 } |
| 267 | 277 |
| 268 std::vector<const BookmarkNode*> GetNodesFromSelection( | 278 std::vector<const BookmarkNode*> GetNodesFromSelection( |
| 269 GdkDragContext* context, | 279 GdkDragContext* context, |
| 270 GtkSelectionData* selection_data, | 280 GtkSelectionData* selection_data, |
| 271 guint target_type, | 281 guint target_type, |
| 272 Profile* profile, | 282 Profile* profile, |
| 273 gboolean* delete_selection_data, | 283 gboolean* delete_selection_data, |
| 274 gboolean* dnd_success) { | 284 gboolean* dnd_success) { |
| 275 *delete_selection_data = FALSE; | 285 if (delete_selection_data) |
| 276 *dnd_success = FALSE; | 286 *delete_selection_data = FALSE; |
| 287 if (dnd_success) |
| 288 *dnd_success = FALSE; |
| 277 | 289 |
| 278 if ((selection_data != NULL) && (selection_data->length >= 0)) { | 290 if ((selection_data != NULL) && (selection_data->length >= 0)) { |
| 279 if (context->action == GDK_ACTION_MOVE) { | 291 if (context && delete_selection_data && context->action == GDK_ACTION_MOVE) |
| 280 *delete_selection_data = TRUE; | 292 *delete_selection_data = TRUE; |
| 281 } | |
| 282 | 293 |
| 283 switch (target_type) { | 294 switch (target_type) { |
| 284 case gtk_dnd_util::CHROME_BOOKMARK_ITEM: { | 295 case gtk_dnd_util::CHROME_BOOKMARK_ITEM: { |
| 285 *dnd_success = TRUE; | 296 if (dnd_success) |
| 297 *dnd_success = TRUE; |
| 286 Pickle pickle(reinterpret_cast<char*>(selection_data->data), | 298 Pickle pickle(reinterpret_cast<char*>(selection_data->data), |
| 287 selection_data->length); | 299 selection_data->length); |
| 288 BookmarkDragData drag_data; | 300 BookmarkDragData drag_data; |
| 289 drag_data.ReadFromPickle(&pickle); | 301 drag_data.ReadFromPickle(&pickle); |
| 290 return drag_data.GetNodes(profile); | 302 return drag_data.GetNodes(profile); |
| 291 } | 303 } |
| 292 default: { | 304 default: { |
| 293 DLOG(ERROR) << "Unsupported drag received type: " << target_type; | 305 DLOG(ERROR) << "Unsupported drag received type: " << target_type; |
| 294 } | 306 } |
| 295 } | 307 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 314 std::vector<GURL> urls; | 326 std::vector<GURL> urls; |
| 315 gtk_dnd_util::ExtractURIList(selection_data, &urls); | 327 gtk_dnd_util::ExtractURIList(selection_data, &urls); |
| 316 for (size_t i = 0; i < urls.size(); ++i) { | 328 for (size_t i = 0; i < urls.size(); ++i) { |
| 317 std::string title = GetNameForURL(urls[i]); | 329 std::string title = GetNameForURL(urls[i]); |
| 318 model->AddURL(parent, idx++, UTF8ToWide(title), urls[i]); | 330 model->AddURL(parent, idx++, UTF8ToWide(title), urls[i]); |
| 319 } | 331 } |
| 320 return true; | 332 return true; |
| 321 } | 333 } |
| 322 | 334 |
| 323 } // namespace bookmark_utils | 335 } // namespace bookmark_utils |
| OLD | NEW |