Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(122)

Side by Side Diff: chrome/browser/tab_contents/web_drag_source.cc

Issue 159040: Fix another d&d crash that happens when the tab contents (Closed)
Patch Set: revise comment Created 11 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
15 #include "chrome/common/notification_type.h"
16 #include "chrome/common/notification_service.h"
14 17
15 namespace { 18 namespace {
16 19
17 static void GetCursorPositions(gfx::NativeWindow wnd, gfx::Point* client, 20 static void GetCursorPositions(gfx::NativeWindow wnd, gfx::Point* client,
18 gfx::Point* screen) { 21 gfx::Point* screen) {
19 #if defined(OS_WIN) 22 #if defined(OS_WIN)
20 POINT cursor_pos; 23 POINT cursor_pos;
21 GetCursorPos(&cursor_pos); 24 GetCursorPos(&cursor_pos);
22 screen->SetPoint(cursor_pos.x, cursor_pos.y); 25 screen->SetPoint(cursor_pos.x, cursor_pos.y);
23 ScreenToClient(wnd, &cursor_pos); 26 ScreenToClient(wnd, &cursor_pos);
24 client->SetPoint(cursor_pos.x, cursor_pos.y); 27 client->SetPoint(cursor_pos.x, cursor_pos.y);
25 #else 28 #else
26 // TODO(port): Get the cursor positions. 29 // TODO(port): Get the cursor positions.
27 NOTIMPLEMENTED(); 30 NOTIMPLEMENTED();
28 #endif 31 #endif
29 } 32 }
30 33
31 } // namespace 34 } // namespace
32 /////////////////////////////////////////////////////////////////////////////// 35 ///////////////////////////////////////////////////////////////////////////////
33 // WebDragSource, public: 36 // WebDragSource, public:
34 37
35 WebDragSource::WebDragSource(gfx::NativeWindow source_wnd, 38 WebDragSource::WebDragSource(gfx::NativeWindow source_wnd,
36 RenderViewHost* render_view_host) 39 TabContents* tab_contents)
37 : BaseDragSource(), 40 : BaseDragSource(),
38 source_wnd_(source_wnd), 41 source_wnd_(source_wnd),
39 render_view_host_(render_view_host) { 42 render_view_host_(tab_contents->render_view_host()) {
43 registrar_.Add(this, NotificationType::TAB_CONTENTS_SWAPPED,
44 Source<TabContents>(tab_contents));
45 registrar_.Add(this, NotificationType::TAB_CONTENTS_DISCONNECTED,
46 Source<TabContents>(tab_contents));
40 } 47 }
41 48
42 void WebDragSource::OnDragSourceCancel() { 49 void WebDragSource::OnDragSourceCancel() {
50 if (!render_view_host_)
51 return;
52
43 gfx::Point client; 53 gfx::Point client;
44 gfx::Point screen; 54 gfx::Point screen;
45 GetCursorPositions(source_wnd_, &client, &screen); 55 GetCursorPositions(source_wnd_, &client, &screen);
46 render_view_host_->DragSourceCancelledAt(client.x(), client.y(), 56 render_view_host_->DragSourceCancelledAt(client.x(), client.y(),
47 screen.x(), screen.y()); 57 screen.x(), screen.y());
48 } 58 }
49 59
50 void WebDragSource::OnDragSourceDrop() { 60 void WebDragSource::OnDragSourceDrop() {
61 if (!render_view_host_)
62 return;
63
51 gfx::Point client; 64 gfx::Point client;
52 gfx::Point screen; 65 gfx::Point screen;
53 GetCursorPositions(source_wnd_, &client, &screen); 66 GetCursorPositions(source_wnd_, &client, &screen);
54 render_view_host_->DragSourceEndedAt(client.x(), client.y(), 67 render_view_host_->DragSourceEndedAt(client.x(), client.y(),
55 screen.x(), screen.y()); 68 screen.x(), screen.y());
56 } 69 }
57 70
58 void WebDragSource::OnDragSourceMove() { 71 void WebDragSource::OnDragSourceMove() {
72 if (!render_view_host_)
73 return;
74
59 gfx::Point client; 75 gfx::Point client;
60 gfx::Point screen; 76 gfx::Point screen;
61 GetCursorPositions(source_wnd_, &client, &screen); 77 GetCursorPositions(source_wnd_, &client, &screen);
62 render_view_host_->DragSourceMovedTo(client.x(), client.y(), 78 render_view_host_->DragSourceMovedTo(client.x(), client.y(),
63 screen.x(), screen.y()); 79 screen.x(), screen.y());
64 } 80 }
81
82 void WebDragSource::Observe(NotificationType type,
83 const NotificationSource& source, const NotificationDetails& details) {
84 if (NotificationType::TAB_CONTENTS_SWAPPED == type) {
85 // 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
87 // our drag source.
88 render_view_host_ = NULL;
89 } else if (NotificationType::TAB_CONTENTS_DISCONNECTED) {
90 NOTREACHED();
91 }
92 }
OLDNEW
« no previous file with comments | « chrome/browser/tab_contents/web_drag_source.h ('k') | chrome/browser/views/tab_contents/tab_contents_view_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698