| 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_source_win.h" | 5 #include "chrome/browser/tab_contents/web_drag_source_win.h" |
| 6 | 6 |
| 7 #include "base/task.h" | 7 #include "base/task.h" |
| 8 #include "chrome/browser/tab_contents/web_drag_utils_win.h" | 8 #include "chrome/browser/tab_contents/web_drag_utils_win.h" |
| 9 #include "content/browser/browser_thread.h" | 9 #include "content/browser/browser_thread.h" |
| 10 #include "content/browser/renderer_host/render_view_host.h" | 10 #include "content/browser/renderer_host/render_view_host.h" |
| 11 #include "content/browser/tab_contents/tab_contents.h" | 11 #include "content/browser/tab_contents/tab_contents.h" |
| 12 #include "content/common/content_notification_types.h" |
| 12 #include "content/common/notification_source.h" | 13 #include "content/common/notification_source.h" |
| 13 #include "content/common/notification_type.h" | |
| 14 | 14 |
| 15 using WebKit::WebDragOperationNone; | 15 using WebKit::WebDragOperationNone; |
| 16 | 16 |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 static void GetCursorPositions(gfx::NativeWindow wnd, gfx::Point* client, | 19 static void GetCursorPositions(gfx::NativeWindow wnd, gfx::Point* client, |
| 20 gfx::Point* screen) { | 20 gfx::Point* screen) { |
| 21 POINT cursor_pos; | 21 POINT cursor_pos; |
| 22 GetCursorPos(&cursor_pos); | 22 GetCursorPos(&cursor_pos); |
| 23 screen->SetPoint(cursor_pos.x, cursor_pos.y); | 23 screen->SetPoint(cursor_pos.x, cursor_pos.y); |
| 24 ScreenToClient(wnd, &cursor_pos); | 24 ScreenToClient(wnd, &cursor_pos); |
| 25 client->SetPoint(cursor_pos.x, cursor_pos.y); | 25 client->SetPoint(cursor_pos.x, cursor_pos.y); |
| 26 } | 26 } |
| 27 | 27 |
| 28 } // namespace | 28 } // namespace |
| 29 | 29 |
| 30 /////////////////////////////////////////////////////////////////////////////// | 30 /////////////////////////////////////////////////////////////////////////////// |
| 31 // WebDragSource, public: | 31 // WebDragSource, public: |
| 32 | 32 |
| 33 WebDragSource::WebDragSource(gfx::NativeWindow source_wnd, | 33 WebDragSource::WebDragSource(gfx::NativeWindow source_wnd, |
| 34 TabContents* tab_contents) | 34 TabContents* tab_contents) |
| 35 : ui::DragSource(), | 35 : ui::DragSource(), |
| 36 source_wnd_(source_wnd), | 36 source_wnd_(source_wnd), |
| 37 render_view_host_(tab_contents->render_view_host()), | 37 render_view_host_(tab_contents->render_view_host()), |
| 38 effect_(DROPEFFECT_NONE) { | 38 effect_(DROPEFFECT_NONE) { |
| 39 registrar_.Add(this, NotificationType::TAB_CONTENTS_SWAPPED, | 39 registrar_.Add(this, content::NOTIFICATION_TAB_CONTENTS_SWAPPED, |
| 40 Source<TabContents>(tab_contents)); | 40 Source<TabContents>(tab_contents)); |
| 41 registrar_.Add(this, NotificationType::TAB_CONTENTS_DISCONNECTED, | 41 registrar_.Add(this, content::NOTIFICATION_TAB_CONTENTS_DISCONNECTED, |
| 42 Source<TabContents>(tab_contents)); | 42 Source<TabContents>(tab_contents)); |
| 43 } | 43 } |
| 44 | 44 |
| 45 WebDragSource::~WebDragSource() { | 45 WebDragSource::~WebDragSource() { |
| 46 } | 46 } |
| 47 | 47 |
| 48 void WebDragSource::OnDragSourceCancel() { | 48 void WebDragSource::OnDragSourceCancel() { |
| 49 // Delegate to the UI thread if we do drag-and-drop in the background thread. | 49 // Delegate to the UI thread if we do drag-and-drop in the background thread. |
| 50 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 50 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| 51 BrowserThread::PostTask( | 51 BrowserThread::PostTask( |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 if (!render_view_host_) | 100 if (!render_view_host_) |
| 101 return; | 101 return; |
| 102 | 102 |
| 103 gfx::Point client; | 103 gfx::Point client; |
| 104 gfx::Point screen; | 104 gfx::Point screen; |
| 105 GetCursorPositions(source_wnd_, &client, &screen); | 105 GetCursorPositions(source_wnd_, &client, &screen); |
| 106 render_view_host_->DragSourceMovedTo(client.x(), client.y(), | 106 render_view_host_->DragSourceMovedTo(client.x(), client.y(), |
| 107 screen.x(), screen.y()); | 107 screen.x(), screen.y()); |
| 108 } | 108 } |
| 109 | 109 |
| 110 void WebDragSource::Observe(NotificationType type, | 110 void WebDragSource::Observe(int type, |
| 111 const NotificationSource& source, const NotificationDetails& details) { | 111 const NotificationSource& source, const NotificationDetails& details) { |
| 112 if (NotificationType::TAB_CONTENTS_SWAPPED == type) { | 112 if (content::NOTIFICATION_TAB_CONTENTS_SWAPPED == type) { |
| 113 // When the tab contents get swapped, our render view host goes away. | 113 // When the tab contents get swapped, our render view host goes away. |
| 114 // That's OK, we can continue the drag, we just can't send messages back to | 114 // That's OK, we can continue the drag, we just can't send messages back to |
| 115 // our drag source. | 115 // our drag source. |
| 116 render_view_host_ = NULL; | 116 render_view_host_ = NULL; |
| 117 } else if (NotificationType::TAB_CONTENTS_DISCONNECTED == type) { | 117 } else if (content::NOTIFICATION_TAB_CONTENTS_DISCONNECTED == type) { |
| 118 // This could be possible when we close the tab and the source is still | 118 // This could be possible when we close the tab and the source is still |
| 119 // being used in DoDragDrop at the time that the virtual file is being | 119 // being used in DoDragDrop at the time that the virtual file is being |
| 120 // downloaded. | 120 // downloaded. |
| 121 render_view_host_ = NULL; | 121 render_view_host_ = NULL; |
| 122 } | 122 } |
| 123 } | 123 } |
| OLD | NEW |