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

Side by Side Diff: chrome/browser/ui/cocoa/tab_contents/web_drop_target.mm

Issue 8430013: Split Mac WebDropTarget into two, content and chrome. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: changes Created 9 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/cocoa/tab_contents/web_drop_target.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #import "chrome/browser/ui/cocoa/tab_contents/web_drop_target.h" 5 #import "chrome/browser/ui/cocoa/tab_contents/web_drop_target.h"
6 6
7 #include "base/sys_string_conversions.h" 7 #include "base/sys_string_conversions.h"
8 #include "chrome/browser/bookmarks/bookmark_node_data.h"
9 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h"
10 #include "chrome/browser/ui/browser.h"
11 #include "chrome/browser/ui/browser_window.h"
12 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
13 #include "content/browser/renderer_host/render_view_host.h" 8 #include "content/browser/renderer_host/render_view_host.h"
14 #include "content/browser/tab_contents/tab_contents.h" 9 #include "content/browser/tab_contents/tab_contents.h"
10 #include "content/browser/tab_contents/web_drag_dest_delegate.h"
15 #import "third_party/mozilla/NSPasteboard+Utils.h" 11 #import "third_party/mozilla/NSPasteboard+Utils.h"
16 #import "ui/base/dragdrop/cocoa_dnd_util.h" 12 #import "ui/base/dragdrop/cocoa_dnd_util.h"
17 #include "webkit/glue/webdropdata.h" 13 #include "webkit/glue/webdropdata.h"
18 #include "webkit/glue/window_open_disposition.h" 14 #include "webkit/glue/window_open_disposition.h"
19 15
20 using WebKit::WebDragOperationsMask; 16 using WebKit::WebDragOperationsMask;
21 17
22 @implementation WebDropTarget 18 @implementation WebDropTarget
23 19
24 // |contents| is the TabContents representing this tab, used to communicate 20 // |contents| is the TabContents representing this tab, used to communicate
25 // drag&drop messages to WebCore and handle navigation on a successful drop 21 // drag&drop messages to WebCore and handle navigation on a successful drop
26 // (if necessary). 22 // (if necessary).
27 - (id)initWithTabContents:(TabContents*)contents { 23 - (id)initWithTabContents:(TabContents*)contents {
28 if ((self = [super init])) { 24 if ((self = [super init])) {
29 tabContents_ = contents; 25 tabContents_ = contents;
30 } 26 }
31 return self; 27 return self;
32 } 28 }
33 29
30 - (void)setDragDelegate:(content::WebDragDestDelegate*)delegate {
31 delegate_ = delegate;
32 }
33
34 // Call to set whether or not we should allow the drop. Takes effect the 34 // Call to set whether or not we should allow the drop. Takes effect the
35 // next time |-draggingUpdated:| is called. 35 // next time |-draggingUpdated:| is called.
36 - (void)setCurrentOperation: (NSDragOperation)operation { 36 - (void)setCurrentOperation: (NSDragOperation)operation {
37 current_operation_ = operation; 37 current_operation_ = operation;
38 } 38 }
39 39
40 // Given a point in window coordinates and a view in that window, return a 40 // Given a point in window coordinates and a view in that window, return a
41 // flipped point in the coordinate system of |view|. 41 // flipped point in the coordinate system of |view|.
42 - (NSPoint)flipWindowPointToView:(const NSPoint&)windowPoint 42 - (NSPoint)flipWindowPointToView:(const NSPoint&)windowPoint
43 view:(NSView*)view { 43 view:(NSView*)view {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 // Save off the RVH so we can tell if it changes during a drag. If it does, 77 // Save off the RVH so we can tell if it changes during a drag. If it does,
78 // we need to send a new enter message in draggingUpdated:. 78 // we need to send a new enter message in draggingUpdated:.
79 currentRVH_ = tabContents_->render_view_host(); 79 currentRVH_ = tabContents_->render_view_host();
80 80
81 if ([self onlyAllowsNavigation]) { 81 if ([self onlyAllowsNavigation]) {
82 if ([[info draggingPasteboard] containsURLData]) 82 if ([[info draggingPasteboard] containsURLData])
83 return NSDragOperationCopy; 83 return NSDragOperationCopy;
84 return NSDragOperationNone; 84 return NSDragOperationNone;
85 } 85 }
86 86
87 if (!tab_) 87 if (delegate_) {
88 tab_ = TabContentsWrapper::GetCurrentWrapperForContents(tabContents_); 88 delegate_->DragInitialize(tabContents_);
89 89 delegate_->OnDragEnter();
90 // If the tab is showing the bookmark manager, send BookmarkDrag events 90 }
91 BookmarkTabHelper::BookmarkDrag* dragDelegate =
92 tab_ ? tab_->bookmark_tab_helper()->GetBookmarkDragDelegate() : NULL;
93 BookmarkNodeData dragData;
94 if(dragDelegate && dragData.ReadFromDragClipboard())
95 dragDelegate->OnDragEnter(dragData);
96 91
97 // Fill out a WebDropData from pasteboard. 92 // Fill out a WebDropData from pasteboard.
98 WebDropData data; 93 WebDropData data;
99 [self populateWebDropData:&data fromPasteboard:[info draggingPasteboard]]; 94 [self populateWebDropData:&data fromPasteboard:[info draggingPasteboard]];
100 95
101 // Create the appropriate mouse locations for WebCore. The draggingLocation 96 // Create the appropriate mouse locations for WebCore. The draggingLocation
102 // is in window coordinates. Both need to be flipped. 97 // is in window coordinates. Both need to be flipped.
103 NSPoint windowPoint = [info draggingLocation]; 98 NSPoint windowPoint = [info draggingLocation];
104 NSPoint viewPoint = [self flipWindowPointToView:windowPoint view:view]; 99 NSPoint viewPoint = [self flipWindowPointToView:windowPoint view:view];
105 NSPoint screenPoint = [self flipWindowPointToScreen:windowPoint view:view]; 100 NSPoint screenPoint = [self flipWindowPointToScreen:windowPoint view:view];
106 NSDragOperation mask = [info draggingSourceOperationMask]; 101 NSDragOperation mask = [info draggingSourceOperationMask];
107 tabContents_->render_view_host()->DragTargetDragEnter(data, 102 tabContents_->render_view_host()->DragTargetDragEnter(data,
108 gfx::Point(viewPoint.x, viewPoint.y), 103 gfx::Point(viewPoint.x, viewPoint.y),
109 gfx::Point(screenPoint.x, screenPoint.y), 104 gfx::Point(screenPoint.x, screenPoint.y),
110 static_cast<WebDragOperationsMask>(mask)); 105 static_cast<WebDragOperationsMask>(mask));
111 106
112 // We won't know the true operation (whether the drag is allowed) until we 107 // We won't know the true operation (whether the drag is allowed) until we
113 // hear back from the renderer. For now, be optimistic: 108 // hear back from the renderer. For now, be optimistic:
114 current_operation_ = NSDragOperationCopy; 109 current_operation_ = NSDragOperationCopy;
115 return current_operation_; 110 return current_operation_;
116 } 111 }
117 112
118 - (void)draggingExited:(id<NSDraggingInfo>)info { 113 - (void)draggingExited:(id<NSDraggingInfo>)info {
119 DCHECK(currentRVH_); 114 DCHECK(currentRVH_);
120 if (currentRVH_ != tabContents_->render_view_host()) 115 if (currentRVH_ != tabContents_->render_view_host())
121 return; 116 return;
122 117
123 // Nothing to do in the interstitial case. 118 // Nothing to do in the interstitial case.
124 119
120 if (delegate_)
121 delegate_->OnDragLeave();
122
125 tabContents_->render_view_host()->DragTargetDragLeave(); 123 tabContents_->render_view_host()->DragTargetDragLeave();
126 } 124 }
127 125
128 - (NSDragOperation)draggingUpdated:(id<NSDraggingInfo>)info 126 - (NSDragOperation)draggingUpdated:(id<NSDraggingInfo>)info
129 view:(NSView*)view { 127 view:(NSView*)view {
130 DCHECK(currentRVH_); 128 DCHECK(currentRVH_);
131 if (currentRVH_ != tabContents_->render_view_host()) 129 if (currentRVH_ != tabContents_->render_view_host())
132 [self draggingEntered:info view:view]; 130 [self draggingEntered:info view:view];
133 131
134 if ([self onlyAllowsNavigation]) { 132 if ([self onlyAllowsNavigation]) {
135 if ([[info draggingPasteboard] containsURLData]) 133 if ([[info draggingPasteboard] containsURLData])
136 return NSDragOperationCopy; 134 return NSDragOperationCopy;
137 return NSDragOperationNone; 135 return NSDragOperationNone;
138 } 136 }
139 137
140 // Create the appropriate mouse locations for WebCore. The draggingLocation 138 // Create the appropriate mouse locations for WebCore. The draggingLocation
141 // is in window coordinates. 139 // is in window coordinates.
142 NSPoint windowPoint = [info draggingLocation]; 140 NSPoint windowPoint = [info draggingLocation];
143 NSPoint viewPoint = [self flipWindowPointToView:windowPoint view:view]; 141 NSPoint viewPoint = [self flipWindowPointToView:windowPoint view:view];
144 NSPoint screenPoint = [self flipWindowPointToScreen:windowPoint view:view]; 142 NSPoint screenPoint = [self flipWindowPointToScreen:windowPoint view:view];
145 NSDragOperation mask = [info draggingSourceOperationMask]; 143 NSDragOperation mask = [info draggingSourceOperationMask];
146 tabContents_->render_view_host()->DragTargetDragOver( 144 tabContents_->render_view_host()->DragTargetDragOver(
147 gfx::Point(viewPoint.x, viewPoint.y), 145 gfx::Point(viewPoint.x, viewPoint.y),
148 gfx::Point(screenPoint.x, screenPoint.y), 146 gfx::Point(screenPoint.x, screenPoint.y),
149 static_cast<WebDragOperationsMask>(mask)); 147 static_cast<WebDragOperationsMask>(mask));
150 148
151 // If the tab is showing the bookmark manager, send BookmarkDrag events 149 if (delegate_)
152 BookmarkTabHelper::BookmarkDrag* dragDelegate = 150 delegate_->OnDragOver();
153 tab_ ? tab_->bookmark_tab_helper()->GetBookmarkDragDelegate() : NULL; 151
154 BookmarkNodeData dragData;
155 if(dragDelegate && dragData.ReadFromDragClipboard())
156 dragDelegate->OnDragOver(dragData);
157 return current_operation_; 152 return current_operation_;
158 } 153 }
159 154
160 - (BOOL)performDragOperation:(id<NSDraggingInfo>)info 155 - (BOOL)performDragOperation:(id<NSDraggingInfo>)info
161 view:(NSView*)view { 156 view:(NSView*)view {
162 if (currentRVH_ != tabContents_->render_view_host()) 157 if (currentRVH_ != tabContents_->render_view_host())
163 [self draggingEntered:info view:view]; 158 [self draggingEntered:info view:view];
164 159
165 // Check if we only allow navigation and navigate to a url on the pasteboard. 160 // Check if we only allow navigation and navigate to a url on the pasteboard.
166 if ([self onlyAllowsNavigation]) { 161 if ([self onlyAllowsNavigation]) {
167 NSPasteboard* pboard = [info draggingPasteboard]; 162 NSPasteboard* pboard = [info draggingPasteboard];
168 if ([pboard containsURLData]) { 163 if ([pboard containsURLData]) {
169 GURL url; 164 GURL url;
170 ui::PopulateURLAndTitleFromPasteboard(&url, NULL, pboard, YES); 165 ui::PopulateURLAndTitleFromPasteboard(&url, NULL, pboard, YES);
171 tabContents_->OpenURL(url, GURL(), CURRENT_TAB, 166 tabContents_->OpenURL(url, GURL(), CURRENT_TAB,
172 content::PAGE_TRANSITION_AUTO_BOOKMARK); 167 content::PAGE_TRANSITION_AUTO_BOOKMARK);
173 return YES; 168 return YES;
174 } 169 }
175 return NO; 170 return NO;
176 } 171 }
177 172
178 // If the tab is showing the bookmark manager, send BookmarkDrag events 173 if (delegate_)
179 BookmarkTabHelper::BookmarkDrag* dragDelegate = 174 delegate_->OnDrop();
180 tab_ ? tab_->bookmark_tab_helper()->GetBookmarkDragDelegate() : NULL;
181 BookmarkNodeData dragData;
182 if(dragDelegate && dragData.ReadFromDragClipboard())
183 dragDelegate->OnDrop(dragData);
184 175
185 currentRVH_ = NULL; 176 currentRVH_ = NULL;
186 177
187 // Create the appropriate mouse locations for WebCore. The draggingLocation 178 // Create the appropriate mouse locations for WebCore. The draggingLocation
188 // is in window coordinates. Both need to be flipped. 179 // is in window coordinates. Both need to be flipped.
189 NSPoint windowPoint = [info draggingLocation]; 180 NSPoint windowPoint = [info draggingLocation];
190 NSPoint viewPoint = [self flipWindowPointToView:windowPoint view:view]; 181 NSPoint viewPoint = [self flipWindowPointToView:windowPoint view:view];
191 NSPoint screenPoint = [self flipWindowPointToScreen:windowPoint view:view]; 182 NSPoint screenPoint = [self flipWindowPointToScreen:windowPoint view:view];
192 tabContents_->render_view_host()->DragTargetDrop( 183 tabContents_->render_view_host()->DragTargetDrop(
193 gfx::Point(viewPoint.x, viewPoint.y), 184 gfx::Point(viewPoint.x, viewPoint.y),
194 gfx::Point(screenPoint.x, screenPoint.y)); 185 gfx::Point(screenPoint.x, screenPoint.y));
195 186
196 // Focus the target browser.
197 Browser* browser = Browser::GetBrowserForController(
198 &tabContents_->controller(), NULL);
199 if (browser)
200 browser->window()->Show();
201
202 return YES; 187 return YES;
203 } 188 }
204 189
205 // Given |data|, which should not be nil, fill it in using the contents of the 190 // Given |data|, which should not be nil, fill it in using the contents of the
206 // given pasteboard. 191 // given pasteboard.
207 - (void)populateWebDropData:(WebDropData*)data 192 - (void)populateWebDropData:(WebDropData*)data
208 fromPasteboard:(NSPasteboard*)pboard { 193 fromPasteboard:(NSPasteboard*)pboard {
209 DCHECK(data); 194 DCHECK(data);
210 DCHECK(pboard); 195 DCHECK(pboard);
211 NSArray* types = [pboard types]; 196 NSArray* types = [pboard types];
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 if (exists && !isDir) 229 if (exists && !isDir)
245 data->filenames.push_back(base::SysNSStringToUTF16(filename)); 230 data->filenames.push_back(base::SysNSStringToUTF16(filename));
246 } 231 }
247 } 232 }
248 } 233 }
249 234
250 // TODO(pinkerton): Get file contents. http://crbug.com/34661 235 // TODO(pinkerton): Get file contents. http://crbug.com/34661
251 } 236 }
252 237
253 @end 238 @end
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/tab_contents/web_drop_target.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698