| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_bookmark_handler_gtk.h" | 5 #include "chrome/browser/tab_contents/web_drag_bookmark_handler_gtk.h" |
| 6 | 6 |
| 7 #include "chrome/browser/ui/browser.h" | 7 #include "chrome/browser/ui/browser.h" |
| 8 #include "chrome/browser/ui/browser_window.h" | 8 #include "chrome/browser/ui/browser_window.h" |
| 9 #include "chrome/browser/ui/gtk/bookmarks/bookmark_utils_gtk.h" | 9 #include "chrome/browser/ui/gtk/bookmarks/bookmark_utils_gtk.h" |
| 10 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h" | 10 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h" |
| 11 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 11 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 13 #include "ui/base/dragdrop/gtk_dnd_util.h" | 13 #include "ui/base/dragdrop/gtk_dnd_util.h" |
| 14 | 14 |
| 15 WebDragBookmarkHandlerGtk::WebDragBookmarkHandlerGtk() | 15 WebDragBookmarkHandlerGtk::WebDragBookmarkHandlerGtk() |
| 16 : tab_(NULL) { | 16 : tab_(NULL) { |
| 17 } | 17 } |
| 18 | 18 |
| 19 WebDragBookmarkHandlerGtk::~WebDragBookmarkHandlerGtk() {} | 19 WebDragBookmarkHandlerGtk::~WebDragBookmarkHandlerGtk() {} |
| 20 | 20 |
| 21 void WebDragBookmarkHandlerGtk::DragInitialize(TabContents* contents) { | 21 void WebDragBookmarkHandlerGtk::DragInitialize(TabContents* contents) { |
| 22 bookmark_drag_data_.Clear(); | 22 bookmark_drag_data_.Clear(); |
| 23 | 23 |
| 24 // Ideally we would want to initialize the the TabContentsWrapper member in | 24 // Ideally we would want to initialize the the TabContentsWrapper member in |
| 25 // the constructor. We cannot do that as the WebDragDestGtk object is | 25 // the constructor. We cannot do that as the WebDragDestGtk object is |
| 26 // created during the construction of the TabContents object. The | 26 // created during the construction of the TabContents object. The |
| 27 // TabContentsWrapper is created much later. | 27 // TabContentsWrapper is created much later. |
| 28 DCHECK(tab_ ? (tab_->tab_contents() == contents) : true); |
| 28 if (!tab_) | 29 if (!tab_) |
| 29 tab_ = TabContentsWrapper::GetCurrentWrapperForContents(contents); | 30 tab_ = TabContentsWrapper::GetCurrentWrapperForContents(contents); |
| 30 } | 31 } |
| 31 | 32 |
| 32 GdkAtom WebDragBookmarkHandlerGtk::GetBookmarkTargetAtom() const { | 33 GdkAtom WebDragBookmarkHandlerGtk::GetBookmarkTargetAtom() const { |
| 33 // For GTK, bookmark drag data is encoded as pickle and associated with | 34 // For GTK, bookmark drag data is encoded as pickle and associated with |
| 34 // ui::CHROME_BOOKMARK_ITEM. See bookmark_utils::WriteBookmarksToSelection() | 35 // ui::CHROME_BOOKMARK_ITEM. See bookmark_utils::WriteBookmarksToSelection() |
| 35 // for details. | 36 // for details. |
| 36 return ui::GetAtomForTarget(ui::CHROME_BOOKMARK_ITEM); | 37 return ui::GetAtomForTarget(ui::CHROME_BOOKMARK_ITEM); |
| 37 } | 38 } |
| 38 | 39 |
| 39 void WebDragBookmarkHandlerGtk::OnReceiveDataFromGtk(GtkSelectionData* data) { | 40 void WebDragBookmarkHandlerGtk::OnReceiveDataFromGtk(GtkSelectionData* data) { |
| 40 if (tab_) { | 41 if (tab_) { |
| 41 Profile* profile = tab_->profile(); | 42 Profile* profile = tab_->profile(); |
| 42 bookmark_drag_data_.ReadFromVector( | 43 bookmark_drag_data_.ReadFromVector( |
| 43 bookmark_utils::GetNodesFromSelection( | 44 bookmark_utils::GetNodesFromSelection( |
| 44 NULL, data, | 45 NULL, data, |
| 45 ui::CHROME_BOOKMARK_ITEM, | 46 ui::CHROME_BOOKMARK_ITEM, |
| 46 profile, NULL, NULL)); | 47 profile, NULL, NULL)); |
| 47 bookmark_drag_data_.SetOriginatingProfile(profile); | 48 bookmark_drag_data_.SetOriginatingProfile(profile); |
| 48 } | 49 } |
| 49 } | 50 } |
| 50 | 51 |
| 51 void WebDragBookmarkHandlerGtk::OnReceiveProcessedData(const GURL& url, | 52 void WebDragBookmarkHandlerGtk::OnReceiveProcessedData(const GURL& url, |
| 52 const string16& title) { | 53 const string16& title) { |
| 53 bookmark_drag_data_.ReadFromTuple(url, title); | 54 bookmark_drag_data_.ReadFromTuple(url, title); |
| 54 } | 55 } |
| 55 | 56 |
| 56 void WebDragBookmarkHandlerGtk::OnDragOver() { | 57 void WebDragBookmarkHandlerGtk::OnDragOver() { |
| 57 if (tab_ && tab_->bookmark_tab_helper()->GetBookmarkDragDelegate()) | 58 if (tab_ && tab_->bookmark_tab_helper()->GetBookmarkDragDelegate()) { |
| 58 tab_->bookmark_tab_helper()->GetBookmarkDragDelegate()->OnDragOver( | 59 tab_->bookmark_tab_helper()->GetBookmarkDragDelegate()->OnDragOver( |
| 59 bookmark_drag_data_); | 60 bookmark_drag_data_); |
| 61 } |
| 60 } | 62 } |
| 61 | 63 |
| 62 void WebDragBookmarkHandlerGtk::OnDragEnter() { | 64 void WebDragBookmarkHandlerGtk::OnDragEnter() { |
| 63 // This is non-null if tab_contents_ is showing an ExtensionWebUI with | 65 // This is non-null if tab_contents_ is showing an ExtensionWebUI with |
| 64 // support for (at the moment experimental) drag and drop extensions. | 66 // support for (at the moment experimental) drag and drop extensions. |
| 65 if (tab_ && tab_->bookmark_tab_helper()->GetBookmarkDragDelegate()) | 67 if (tab_ && tab_->bookmark_tab_helper()->GetBookmarkDragDelegate()) { |
| 66 tab_->bookmark_tab_helper()->GetBookmarkDragDelegate()->OnDragEnter( | 68 tab_->bookmark_tab_helper()->GetBookmarkDragDelegate()->OnDragEnter( |
| 67 bookmark_drag_data_); | 69 bookmark_drag_data_); |
| 70 } |
| 68 } | 71 } |
| 69 | 72 |
| 70 void WebDragBookmarkHandlerGtk::OnDrop() { | 73 void WebDragBookmarkHandlerGtk::OnDrop() { |
| 71 // This is non-null if tab_contents_ is showing an ExtensionWebUI with | 74 // This is non-null if tab_contents_ is showing an ExtensionWebUI with |
| 72 // support for (at the moment experimental) drag and drop extensions. | 75 // support for (at the moment experimental) drag and drop extensions. |
| 73 if (tab_) { | 76 if (tab_) { |
| 74 if (tab_->bookmark_tab_helper()->GetBookmarkDragDelegate()) { | 77 if (tab_->bookmark_tab_helper()->GetBookmarkDragDelegate()) { |
| 75 tab_->bookmark_tab_helper()->GetBookmarkDragDelegate()->OnDrop( | 78 tab_->bookmark_tab_helper()->GetBookmarkDragDelegate()->OnDrop( |
| 76 bookmark_drag_data_); | 79 bookmark_drag_data_); |
| 77 } | 80 } |
| 78 | 81 |
| 79 // Focus the target browser. | 82 // Focus the target browser. |
| 80 Browser* browser = Browser::GetBrowserForController( | 83 Browser* browser = Browser::GetBrowserForController( |
| 81 &tab_->controller(), NULL); | 84 &tab_->controller(), NULL); |
| 82 if (browser) | 85 if (browser) |
| 83 browser->window()->Show(); | 86 browser->window()->Show(); |
| 84 } | 87 } |
| 85 } | 88 } |
| 86 | 89 |
| 87 void WebDragBookmarkHandlerGtk::OnDragLeave() { | 90 void WebDragBookmarkHandlerGtk::OnDragLeave() { |
| 88 if (tab_ && tab_->bookmark_tab_helper()->GetBookmarkDragDelegate()) | 91 if (tab_ && tab_->bookmark_tab_helper()->GetBookmarkDragDelegate()) { |
| 89 tab_->bookmark_tab_helper()->GetBookmarkDragDelegate()->OnDragLeave( | 92 tab_->bookmark_tab_helper()->GetBookmarkDragDelegate()->OnDragLeave( |
| 90 bookmark_drag_data_); | 93 bookmark_drag_data_); |
| 94 } |
| 91 } | 95 } |
| OLD | NEW |