| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 #if defined(OS_WIN) | 5 #if defined(OS_WIN) |
| 6 #include <atlbase.h> | 6 #include <atlbase.h> |
| 7 #include <atlapp.h> | 7 #include <atlapp.h> |
| 8 #include <atlmisc.h> | 8 #include <atlmisc.h> |
| 9 #endif | 9 #endif |
| 10 | 10 |
| 11 #include "chrome/browser/tab_contents/web_drag_source.h" | 11 #include "chrome/browser/tab_contents/web_drag_source.h" |
| 12 | 12 |
| 13 #include "chrome/browser/renderer_host/render_view_host.h" | 13 #include "chrome/browser/renderer_host/render_view_host.h" |
| 14 #include "chrome/browser/tab_contents/tab_contents.h" | 14 #include "chrome/browser/tab_contents/tab_contents.h" |
| 15 #include "chrome/common/notification_type.h" | 15 #include "chrome/common/notification_type.h" |
| 16 #include "chrome/common/notification_service.h" | 16 #include "chrome/common/notification_service.h" |
| 17 | 17 |
| 18 using WebKit::WebDragOperationNone; |
| 19 using WebKit::WebDragOperationCopy; |
| 20 |
| 18 namespace { | 21 namespace { |
| 19 | 22 |
| 20 static void GetCursorPositions(gfx::NativeWindow wnd, gfx::Point* client, | 23 static void GetCursorPositions(gfx::NativeWindow wnd, gfx::Point* client, |
| 21 gfx::Point* screen) { | 24 gfx::Point* screen) { |
| 22 #if defined(OS_WIN) | 25 #if defined(OS_WIN) |
| 23 POINT cursor_pos; | 26 POINT cursor_pos; |
| 24 GetCursorPos(&cursor_pos); | 27 GetCursorPos(&cursor_pos); |
| 25 screen->SetPoint(cursor_pos.x, cursor_pos.y); | 28 screen->SetPoint(cursor_pos.x, cursor_pos.y); |
| 26 ScreenToClient(wnd, &cursor_pos); | 29 ScreenToClient(wnd, &cursor_pos); |
| 27 client->SetPoint(cursor_pos.x, cursor_pos.y); | 30 client->SetPoint(cursor_pos.x, cursor_pos.y); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 46 Source<TabContents>(tab_contents)); | 49 Source<TabContents>(tab_contents)); |
| 47 } | 50 } |
| 48 | 51 |
| 49 void WebDragSource::OnDragSourceCancel() { | 52 void WebDragSource::OnDragSourceCancel() { |
| 50 if (!render_view_host_) | 53 if (!render_view_host_) |
| 51 return; | 54 return; |
| 52 | 55 |
| 53 gfx::Point client; | 56 gfx::Point client; |
| 54 gfx::Point screen; | 57 gfx::Point screen; |
| 55 GetCursorPositions(source_wnd_, &client, &screen); | 58 GetCursorPositions(source_wnd_, &client, &screen); |
| 56 render_view_host_->DragSourceCancelledAt(client.x(), client.y(), | 59 render_view_host_->DragSourceEndedAt(client.x(), client.y(), |
| 57 screen.x(), screen.y()); | 60 screen.x(), screen.y(), |
| 61 WebDragOperationNone); |
| 58 } | 62 } |
| 59 | 63 |
| 60 void WebDragSource::OnDragSourceDrop() { | 64 void WebDragSource::OnDragSourceDrop() { |
| 61 if (!render_view_host_) | 65 if (!render_view_host_) |
| 62 return; | 66 return; |
| 63 | 67 |
| 64 gfx::Point client; | 68 gfx::Point client; |
| 65 gfx::Point screen; | 69 gfx::Point screen; |
| 66 GetCursorPositions(source_wnd_, &client, &screen); | 70 GetCursorPositions(source_wnd_, &client, &screen); |
| 67 render_view_host_->DragSourceEndedAt(client.x(), client.y(), | 71 render_view_host_->DragSourceEndedAt(client.x(), client.y(), |
| 68 screen.x(), screen.y()); | 72 screen.x(), screen.y(), |
| 73 WebDragOperationCopy); |
| 74 // TODO(jpa): This needs to be fixed to send the actual drag operation. |
| 69 } | 75 } |
| 70 | 76 |
| 71 void WebDragSource::OnDragSourceMove() { | 77 void WebDragSource::OnDragSourceMove() { |
| 72 if (!render_view_host_) | 78 if (!render_view_host_) |
| 73 return; | 79 return; |
| 74 | 80 |
| 75 gfx::Point client; | 81 gfx::Point client; |
| 76 gfx::Point screen; | 82 gfx::Point screen; |
| 77 GetCursorPositions(source_wnd_, &client, &screen); | 83 GetCursorPositions(source_wnd_, &client, &screen); |
| 78 render_view_host_->DragSourceMovedTo(client.x(), client.y(), | 84 render_view_host_->DragSourceMovedTo(client.x(), client.y(), |
| 79 screen.x(), screen.y()); | 85 screen.x(), screen.y()); |
| 80 } | 86 } |
| 81 | 87 |
| 82 void WebDragSource::Observe(NotificationType type, | 88 void WebDragSource::Observe(NotificationType type, |
| 83 const NotificationSource& source, const NotificationDetails& details) { | 89 const NotificationSource& source, const NotificationDetails& details) { |
| 84 if (NotificationType::TAB_CONTENTS_SWAPPED == type) { | 90 if (NotificationType::TAB_CONTENTS_SWAPPED == type) { |
| 85 // When the tab contents get swapped, our render view host goes away. | 91 // When the tab contents get swapped, our render view host goes away. |
| 86 // That's OK, we can continue the drag, we just can't send messages back to | 92 // That's OK, we can continue the drag, we just can't send messages back to |
| 87 // our drag source. | 93 // our drag source. |
| 88 render_view_host_ = NULL; | 94 render_view_host_ = NULL; |
| 89 } else if (NotificationType::TAB_CONTENTS_DISCONNECTED) { | 95 } else if (NotificationType::TAB_CONTENTS_DISCONNECTED) { |
| 90 NOTREACHED(); | 96 NOTREACHED(); |
| 91 } | 97 } |
| 92 } | 98 } |
| OLD | NEW |