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

Side by Side Diff: chrome/browser/tab_contents/tab_contents_view_mac.mm

Issue 174364: Plumb the DragOperation through all the layers between the platform DnD code ... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 3 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 | Annotate | Revision Log
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 #include "chrome/browser/tab_contents/tab_contents_view_mac.h" 5 #include "chrome/browser/tab_contents/tab_contents_view_mac.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "chrome/browser/browser.h" // TODO(beng): this dependency is awful. 9 #include "chrome/browser/browser.h" // TODO(beng): this dependency is awful.
10 #include "chrome/browser/cocoa/sad_tab_view.h" 10 #include "chrome/browser/cocoa/sad_tab_view.h"
11 #import "chrome/browser/cocoa/web_drag_source.h" 11 #import "chrome/browser/cocoa/web_drag_source.h"
12 #import "chrome/browser/cocoa/web_drop_target.h" 12 #import "chrome/browser/cocoa/web_drop_target.h"
13 #include "chrome/browser/renderer_host/render_widget_host.h" 13 #include "chrome/browser/renderer_host/render_widget_host.h"
14 #include "chrome/browser/renderer_host/render_widget_host_view_mac.h" 14 #include "chrome/browser/renderer_host/render_widget_host_view_mac.h"
15 #include "chrome/browser/tab_contents/render_view_context_menu_mac.h" 15 #include "chrome/browser/tab_contents/render_view_context_menu_mac.h"
16 #include "chrome/browser/tab_contents/tab_contents.h" 16 #include "chrome/browser/tab_contents/tab_contents.h"
17 #include "chrome/common/notification_type.h" 17 #include "chrome/common/notification_type.h"
18 #include "chrome/common/notification_service.h" 18 #include "chrome/common/notification_service.h"
19 #include "chrome/common/render_messages.h" 19 #include "chrome/common/render_messages.h"
20 #import "third_party/mozilla/include/NSPasteboard+Utils.h" 20 #import "third_party/mozilla/include/NSPasteboard+Utils.h"
21 21
22 #include "chrome/common/temp_scaffolding_stubs.h" 22 #include "chrome/common/temp_scaffolding_stubs.h"
23 23
24 using WebKit::WebDragOperation;
25 using WebKit::WebDragOperationsMask;
26
27 // Ensure that the WebKit::WebDragOperation enum values stay in sync with
28 // NSDragOperation constants, since the code below static_casts between 'em.
29 #define COMPILE_ASSERT_MATCHING_ENUM(name) \
30 COMPILE_ASSERT(int(NS##name) == int(WebKit::Web##name), enum_mismatch_##name)
31 COMPILE_ASSERT_MATCHING_ENUM(DragOperationNone);
32 COMPILE_ASSERT_MATCHING_ENUM(DragOperationCopy);
33 COMPILE_ASSERT_MATCHING_ENUM(DragOperationLink);
34 COMPILE_ASSERT_MATCHING_ENUM(DragOperationGeneric);
35 COMPILE_ASSERT_MATCHING_ENUM(DragOperationPrivate);
36 COMPILE_ASSERT_MATCHING_ENUM(DragOperationMove);
37 COMPILE_ASSERT_MATCHING_ENUM(DragOperationDelete);
38 COMPILE_ASSERT_MATCHING_ENUM(DragOperationEvery);
39
24 @interface TabContentsViewCocoa (Private) 40 @interface TabContentsViewCocoa (Private)
25 - (id)initWithTabContentsViewMac:(TabContentsViewMac*)w; 41 - (id)initWithTabContentsViewMac:(TabContentsViewMac*)w;
26 - (void)processKeyboardEvent:(NSEvent*)event; 42 - (void)processKeyboardEvent:(NSEvent*)event;
27 - (void)registerDragTypes; 43 - (void)registerDragTypes;
28 - (void)setIsDropTarget:(BOOL)isTarget; 44 - (void)setCurrentDragOperation:(NSDragOperation)operation;
29 - (void)startDragWithDropData:(const WebDropData&)dropData; 45 - (void)startDragWithDropData:(const WebDropData&)dropData
46 dragOperationMask:(NSDragOperation)operationMask;
30 @end 47 @end
31 48
32 // static 49 // static
33 TabContentsView* TabContentsView::Create(TabContents* tab_contents) { 50 TabContentsView* TabContentsView::Create(TabContents* tab_contents) {
34 return new TabContentsViewMac(tab_contents); 51 return new TabContentsViewMac(tab_contents);
35 } 52 }
36 53
37 TabContentsViewMac::TabContentsViewMac(TabContents* tab_contents) 54 TabContentsViewMac::TabContentsViewMac(TabContents* tab_contents)
38 : TabContentsView(tab_contents) { 55 : TabContentsView(tab_contents) {
39 registrar_.Add(this, NotificationType::TAB_CONTENTS_CONNECTED, 56 registrar_.Add(this, NotificationType::TAB_CONTENTS_CONNECTED,
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 } 93 }
77 94
78 gfx::NativeWindow TabContentsViewMac::GetTopLevelNativeWindow() const { 95 gfx::NativeWindow TabContentsViewMac::GetTopLevelNativeWindow() const {
79 return [cocoa_view_.get() window]; 96 return [cocoa_view_.get() window];
80 } 97 }
81 98
82 void TabContentsViewMac::GetContainerBounds(gfx::Rect* out) const { 99 void TabContentsViewMac::GetContainerBounds(gfx::Rect* out) const {
83 *out = [cocoa_view_.get() NSRectToRect:[cocoa_view_.get() bounds]]; 100 *out = [cocoa_view_.get() NSRectToRect:[cocoa_view_.get() bounds]];
84 } 101 }
85 102
86 void TabContentsViewMac::StartDragging(const WebDropData& drop_data) { 103 void TabContentsViewMac::StartDragging(const WebDropData& drop_data,
104 WebDragOperationsMask allowed_operations) {
87 // The drag invokes a nested event loop, but we need to continue processing 105 // The drag invokes a nested event loop, but we need to continue processing
88 // events. 106 // events.
89 MessageLoop::current()->SetNestableTasksAllowed(true); 107 MessageLoop::current()->SetNestableTasksAllowed(true);
90 [cocoa_view_ startDragWithDropData:drop_data]; 108 NSDragOperation mask = static_cast<NSDragOperation>(allowed_operations);
109 [cocoa_view_ startDragWithDropData:drop_data
110 dragOperationMask:mask];
91 MessageLoop::current()->SetNestableTasksAllowed(false); 111 MessageLoop::current()->SetNestableTasksAllowed(false);
92 } 112 }
93 113
94 void TabContentsViewMac::OnContentsDestroy() { 114 void TabContentsViewMac::OnContentsDestroy() {
95 } 115 }
96 116
97 void TabContentsViewMac::RenderViewCreated(RenderViewHost* host) { 117 void TabContentsViewMac::RenderViewCreated(RenderViewHost* host) {
98 // We want updates whenever the intrinsic width of the webpage 118 // We want updates whenever the intrinsic width of the webpage
99 // changes. Put the RenderView into that mode. 119 // changes. Put the RenderView into that mode.
100 int routing_id = host->routing_id(); 120 int routing_id = host->routing_id();
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 latent_focus_view_.reset(); 179 latent_focus_view_.reset();
160 } else { 180 } else {
161 // TODO(shess): If location-bar gets focus by default, this will 181 // TODO(shess): If location-bar gets focus by default, this will
162 // select-all in the field. If there was a specific selection in 182 // select-all in the field. If there was a specific selection in
163 // the field when we navigated away from it, we should restore 183 // the field when we navigated away from it, we should restore
164 // that selection. 184 // that selection.
165 SetInitialFocus(); 185 SetInitialFocus();
166 } 186 }
167 } 187 }
168 188
169 void TabContentsViewMac::UpdateDragCursor(bool is_drop_target) { 189 void TabContentsViewMac::UpdateDragCursor(WebDragOperation operation) {
170 [cocoa_view_ setIsDropTarget:is_drop_target ? YES : NO]; 190 [cocoa_view_ setCurrentDragOperation: operation];
171 } 191 }
172 192
173 void TabContentsViewMac::GotFocus() { 193 void TabContentsViewMac::GotFocus() {
174 NOTIMPLEMENTED(); 194 NOTIMPLEMENTED();
175 } 195 }
176 196
177 // This is called when we the renderer asks us to take focus back (i.e., it has 197 // This is called when we the renderer asks us to take focus back (i.e., it has
178 // iterated past the last focusable element on the page). 198 // iterated past the last focusable element on the page).
179 void TabContentsViewMac::TakeFocus(bool reverse) { 199 void TabContentsViewMac::TakeFocus(bool reverse) {
180 if (reverse) { 200 if (reverse) {
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 } 282 }
263 283
264 // Registers for the view for the appropriate drag types. 284 // Registers for the view for the appropriate drag types.
265 // TODO(pinkerton): register for file drags. 285 // TODO(pinkerton): register for file drags.
266 - (void)registerDragTypes { 286 - (void)registerDragTypes {
267 NSArray* types = [NSArray arrayWithObjects:NSStringPboardType, 287 NSArray* types = [NSArray arrayWithObjects:NSStringPboardType,
268 NSHTMLPboardType, NSURLPboardType, nil]; 288 NSHTMLPboardType, NSURLPboardType, nil];
269 [self registerForDraggedTypes:types]; 289 [self registerForDraggedTypes:types];
270 } 290 }
271 291
272 - (void)setIsDropTarget:(BOOL)isTarget { 292 - (void)setCurrentDragOperation:(NSDragOperation)operation {
273 [dropTarget_ setIsDropTarget:isTarget]; 293 [dropTarget_ setCurrentOperation:operation];
274 } 294 }
275 295
276 - (TabContents*)tabContents { 296 - (TabContents*)tabContents {
277 return tabContentsView_->tab_contents(); 297 return tabContentsView_->tab_contents();
278 } 298 }
279 299
280 - (void)processKeyboardEvent:(NSEvent*)event { 300 - (void)processKeyboardEvent:(NSEvent*)event {
281 if ([event type] == NSKeyDown) 301 if ([event type] == NSKeyDown)
282 [super keyDown:event]; 302 [super keyDown:event];
283 else if ([event type] == NSKeyUp) 303 else if ([event type] == NSKeyUp)
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 338
319 - (void)paste:(id)sender { 339 - (void)paste:(id)sender {
320 [self tabContents]->Paste(); 340 [self tabContents]->Paste();
321 } 341 }
322 342
323 - (void)pasteboard:(NSPasteboard*)sender provideDataForType:(NSString*)type { 343 - (void)pasteboard:(NSPasteboard*)sender provideDataForType:(NSString*)type {
324 [dragSource_ lazyWriteToPasteboard:sender 344 [dragSource_ lazyWriteToPasteboard:sender
325 forType:type]; 345 forType:type];
326 } 346 }
327 347
328 - (void)startDragWithDropData:(const WebDropData&)dropData { 348 - (void)startDragWithDropData:(const WebDropData&)dropData
349 dragOperationMask:(NSDragOperation)operationMask {
329 dragSource_.reset([[WebDragSource alloc] 350 dragSource_.reset([[WebDragSource alloc]
330 initWithContentsView:self 351 initWithContentsView:self
331 dropData:&dropData 352 dropData:&dropData
332 pasteboard:[NSPasteboard pasteboardWithName:NSDragPboard]]); 353 pasteboard:[NSPasteboard pasteboardWithName:NSDragPboard]
354 dragOperationMask:operationMask]);
333 [dragSource_ startDrag]; 355 [dragSource_ startDrag];
334 } 356 }
335 357
336 // NSDraggingSource methods 358 // NSDraggingSource methods
337 359
338 // Returns what kind of drag operations are available. This is a required 360 // Returns what kind of drag operations are available. This is a required
339 // method for NSDraggingSource. 361 // method for NSDraggingSource.
340 - (NSDragOperation)draggingSourceOperationMaskForLocal:(BOOL)isLocal { 362 - (NSDragOperation)draggingSourceOperationMaskForLocal:(BOOL)isLocal {
341 // TODO(pinkerton): I think this is right... 363 return [dragSource_ draggingSourceOperationMaskForLocal:isLocal];
342 return NSDragOperationCopy;
343 } 364 }
344 365
345 // Called when a drag initiated in our view ends. 366 // Called when a drag initiated in our view ends.
346 - (void)draggedImage:(NSImage*)anImage 367 - (void)draggedImage:(NSImage*)anImage
347 endedAt:(NSPoint)screenPoint 368 endedAt:(NSPoint)screenPoint
348 operation:(NSDragOperation)operation { 369 operation:(NSDragOperation)operation {
349 [dragSource_ endDragAt:screenPoint 370 [dragSource_ endDragAt:screenPoint operation:operation];
350 isCancelled:(operation == NSDragOperationNone)];
351 371
352 // Might as well throw out this object now. 372 // Might as well throw out this object now.
353 dragSource_.reset(); 373 dragSource_.reset();
354 } 374 }
355 375
356 // Called when a drag initiated in our view moves. 376 // Called when a drag initiated in our view moves.
357 - (void)draggedImage:(NSImage*)draggedImage movedTo:(NSPoint)screenPoint { 377 - (void)draggedImage:(NSImage*)draggedImage movedTo:(NSPoint)screenPoint {
358 [dragSource_ moveDragTo:screenPoint]; 378 [dragSource_ moveDragTo:screenPoint];
359 } 379 }
360 380
(...skipping 24 matching lines...) Expand all
385 } 405 }
386 406
387 - (BOOL)performDragOperation:(id<NSDraggingInfo>)sender { 407 - (BOOL)performDragOperation:(id<NSDraggingInfo>)sender {
388 return [dropTarget_ performDragOperation:sender view:self]; 408 return [dropTarget_ performDragOperation:sender view:self];
389 } 409 }
390 410
391 // Tons of stuff goes here, where we grab events going on in Cocoaland and send 411 // Tons of stuff goes here, where we grab events going on in Cocoaland and send
392 // them into the C++ system. TODO(avi): all that jazz 412 // them into the C++ system. TODO(avi): all that jazz
393 413
394 @end 414 @end
OLDNEW
« no previous file with comments | « chrome/browser/tab_contents/tab_contents_view_mac.h ('k') | chrome/browser/tab_contents/web_drag_source.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698