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