OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <Carbon/Carbon.h> | 5 #import <Carbon/Carbon.h> |
6 | 6 |
7 #import "content/browser/web_contents/web_contents_view_mac.h" | 7 #import "content/browser/web_contents/web_contents_view_mac.h" |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 12 matching lines...) Expand all Loading... |
23 #include "content/public/browser/web_contents_view_delegate.h" | 23 #include "content/public/browser/web_contents_view_delegate.h" |
24 #include "skia/ext/skia_utils_mac.h" | 24 #include "skia/ext/skia_utils_mac.h" |
25 #import "third_party/mozilla/NSPasteboard+Utils.h" | 25 #import "third_party/mozilla/NSPasteboard+Utils.h" |
26 #include "ui/base/clipboard/custom_data_helper.h" | 26 #include "ui/base/clipboard/custom_data_helper.h" |
27 #import "ui/base/cocoa/focus_tracker.h" | 27 #import "ui/base/cocoa/focus_tracker.h" |
28 #include "ui/base/dragdrop/cocoa_dnd_util.h" | 28 #include "ui/base/dragdrop/cocoa_dnd_util.h" |
29 #include "ui/gfx/image/image_skia_util_mac.h" | 29 #include "ui/gfx/image/image_skia_util_mac.h" |
30 | 30 |
31 using WebKit::WebDragOperation; | 31 using WebKit::WebDragOperation; |
32 using WebKit::WebDragOperationsMask; | 32 using WebKit::WebDragOperationsMask; |
| 33 using content::DropData; |
33 using content::PopupMenuHelper; | 34 using content::PopupMenuHelper; |
34 using content::RenderViewHostFactory; | 35 using content::RenderViewHostFactory; |
35 using content::RenderWidgetHostView; | 36 using content::RenderWidgetHostView; |
36 using content::RenderWidgetHostViewMac; | 37 using content::RenderWidgetHostViewMac; |
37 using content::WebContents; | 38 using content::WebContents; |
38 using content::WebContentsImpl; | 39 using content::WebContentsImpl; |
39 using content::WebContentsViewMac; | 40 using content::WebContentsViewMac; |
40 | 41 |
41 // Ensure that the WebKit::WebDragOperation enum values stay in sync with | 42 // Ensure that the WebKit::WebDragOperation enum values stay in sync with |
42 // NSDragOperation constants, since the code below static_casts between 'em. | 43 // NSDragOperation constants, since the code below static_casts between 'em. |
43 #define COMPILE_ASSERT_MATCHING_ENUM(name) \ | 44 #define COMPILE_ASSERT_MATCHING_ENUM(name) \ |
44 COMPILE_ASSERT(int(NS##name) == int(WebKit::Web##name), enum_mismatch_##name) | 45 COMPILE_ASSERT(int(NS##name) == int(WebKit::Web##name), enum_mismatch_##name) |
45 COMPILE_ASSERT_MATCHING_ENUM(DragOperationNone); | 46 COMPILE_ASSERT_MATCHING_ENUM(DragOperationNone); |
46 COMPILE_ASSERT_MATCHING_ENUM(DragOperationCopy); | 47 COMPILE_ASSERT_MATCHING_ENUM(DragOperationCopy); |
47 COMPILE_ASSERT_MATCHING_ENUM(DragOperationLink); | 48 COMPILE_ASSERT_MATCHING_ENUM(DragOperationLink); |
48 COMPILE_ASSERT_MATCHING_ENUM(DragOperationGeneric); | 49 COMPILE_ASSERT_MATCHING_ENUM(DragOperationGeneric); |
49 COMPILE_ASSERT_MATCHING_ENUM(DragOperationPrivate); | 50 COMPILE_ASSERT_MATCHING_ENUM(DragOperationPrivate); |
50 COMPILE_ASSERT_MATCHING_ENUM(DragOperationMove); | 51 COMPILE_ASSERT_MATCHING_ENUM(DragOperationMove); |
51 COMPILE_ASSERT_MATCHING_ENUM(DragOperationDelete); | 52 COMPILE_ASSERT_MATCHING_ENUM(DragOperationDelete); |
52 COMPILE_ASSERT_MATCHING_ENUM(DragOperationEvery); | 53 COMPILE_ASSERT_MATCHING_ENUM(DragOperationEvery); |
53 | 54 |
54 @interface WebContentsViewCocoa (Private) | 55 @interface WebContentsViewCocoa (Private) |
55 - (id)initWithWebContentsViewMac:(WebContentsViewMac*)w; | 56 - (id)initWithWebContentsViewMac:(WebContentsViewMac*)w; |
56 - (void)registerDragTypes; | 57 - (void)registerDragTypes; |
57 - (void)setCurrentDragOperation:(NSDragOperation)operation; | 58 - (void)setCurrentDragOperation:(NSDragOperation)operation; |
58 - (WebDropData*)dropData; | 59 - (DropData*)dropData; |
59 - (void)startDragWithDropData:(const WebDropData&)dropData | 60 - (void)startDragWithDropData:(const DropData&)dropData |
60 dragOperationMask:(NSDragOperation)operationMask | 61 dragOperationMask:(NSDragOperation)operationMask |
61 image:(NSImage*)image | 62 image:(NSImage*)image |
62 offset:(NSPoint)offset; | 63 offset:(NSPoint)offset; |
63 - (void)cancelDeferredClose; | 64 - (void)cancelDeferredClose; |
64 - (void)clearWebContentsView; | 65 - (void)clearWebContentsView; |
65 - (void)closeTabAfterEvent; | 66 - (void)closeTabAfterEvent; |
66 - (void)viewDidBecomeFirstResponder:(NSNotification*)notification; | 67 - (void)viewDidBecomeFirstResponder:(NSNotification*)notification; |
67 @end | 68 @end |
68 | 69 |
69 namespace content { | 70 namespace content { |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 bounds.origin = [window convertBaseToScreen:bounds.origin]; | 118 bounds.origin = [window convertBaseToScreen:bounds.origin]; |
118 | 119 |
119 // Flip y to account for screen flip. | 120 // Flip y to account for screen flip. |
120 NSScreen* screen = [[NSScreen screens] objectAtIndex:0]; | 121 NSScreen* screen = [[NSScreen screens] objectAtIndex:0]; |
121 bounds.origin.y = [screen frame].size.height - bounds.origin.y | 122 bounds.origin.y = [screen frame].size.height - bounds.origin.y |
122 - bounds.size.height; | 123 - bounds.size.height; |
123 *out = gfx::Rect(NSRectToCGRect(bounds)); | 124 *out = gfx::Rect(NSRectToCGRect(bounds)); |
124 } | 125 } |
125 | 126 |
126 void WebContentsViewMac::StartDragging( | 127 void WebContentsViewMac::StartDragging( |
127 const WebDropData& drop_data, | 128 const DropData& drop_data, |
128 WebDragOperationsMask allowed_operations, | 129 WebDragOperationsMask allowed_operations, |
129 const gfx::ImageSkia& image, | 130 const gfx::ImageSkia& image, |
130 const gfx::Vector2d& image_offset, | 131 const gfx::Vector2d& image_offset, |
131 const DragEventSourceInfo& event_info) { | 132 const DragEventSourceInfo& event_info) { |
132 // By allowing nested tasks, the code below also allows Close(), | 133 // By allowing nested tasks, the code below also allows Close(), |
133 // which would deallocate |this|. The same problem can occur while | 134 // which would deallocate |this|. The same problem can occur while |
134 // processing -sendEvent:, so Close() is deferred in that case. | 135 // processing -sendEvent:, so Close() is deferred in that case. |
135 // Drags from web content do not come via -sendEvent:, this sets the | 136 // Drags from web content do not come via -sendEvent:, this sets the |
136 // same flag -sendEvent: would. | 137 // same flag -sendEvent: would. |
137 base::mac::ScopedSendingEvent sending_event_scoper; | 138 base::mac::ScopedSendingEvent sending_event_scoper; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 // TODO(shess): If location-bar gets focus by default, this will | 198 // TODO(shess): If location-bar gets focus by default, this will |
198 // select-all in the field. If there was a specific selection in | 199 // select-all in the field. If there was a specific selection in |
199 // the field when we navigated away from it, we should restore | 200 // the field when we navigated away from it, we should restore |
200 // that selection. | 201 // that selection. |
201 SetInitialFocus(); | 202 SetInitialFocus(); |
202 } | 203 } |
203 | 204 |
204 focus_tracker_.reset(nil); | 205 focus_tracker_.reset(nil); |
205 } | 206 } |
206 | 207 |
207 WebDropData* WebContentsViewMac::GetDropData() const { | 208 DropData* WebContentsViewMac::GetDropData() const { |
208 return [cocoa_view_ dropData]; | 209 return [cocoa_view_ dropData]; |
209 } | 210 } |
210 | 211 |
211 void WebContentsViewMac::UpdateDragCursor(WebDragOperation operation) { | 212 void WebContentsViewMac::UpdateDragCursor(WebDragOperation operation) { |
212 [cocoa_view_ setCurrentDragOperation: operation]; | 213 [cocoa_view_ setCurrentDragOperation: operation]; |
213 } | 214 } |
214 | 215 |
215 void WebContentsViewMac::GotFocus() { | 216 void WebContentsViewMac::GotFocus() { |
216 // This is only used in the views FocusManager stuff but it bleeds through | 217 // This is only used in the views FocusManager stuff but it bleeds through |
217 // all subclasses. http://crbug.com/21875 | 218 // all subclasses. http://crbug.com/21875 |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 NSFilenamesPboardType, | 419 NSFilenamesPboardType, |
419 ui::kWebCustomDataPboardType, | 420 ui::kWebCustomDataPboardType, |
420 nil]; | 421 nil]; |
421 [self registerForDraggedTypes:types]; | 422 [self registerForDraggedTypes:types]; |
422 } | 423 } |
423 | 424 |
424 - (void)setCurrentDragOperation:(NSDragOperation)operation { | 425 - (void)setCurrentDragOperation:(NSDragOperation)operation { |
425 [dragDest_ setCurrentOperation:operation]; | 426 [dragDest_ setCurrentOperation:operation]; |
426 } | 427 } |
427 | 428 |
428 - (WebDropData*)dropData { | 429 - (DropData*)dropData { |
429 return [dragDest_ currentDropData]; | 430 return [dragDest_ currentDropData]; |
430 } | 431 } |
431 | 432 |
432 - (WebContentsImpl*)webContents { | 433 - (WebContentsImpl*)webContents { |
433 if (webContentsView_ == NULL) | 434 if (webContentsView_ == NULL) |
434 return NULL; | 435 return NULL; |
435 return webContentsView_->web_contents(); | 436 return webContentsView_->web_contents(); |
436 } | 437 } |
437 | 438 |
438 - (void)mouseEvent:(NSEvent*)theEvent { | 439 - (void)mouseEvent:(NSEvent*)theEvent { |
(...skipping 21 matching lines...) Expand all Loading... |
460 // saves us the effort of overriding this method in every possible | 461 // saves us the effort of overriding this method in every possible |
461 // subview. | 462 // subview. |
462 return mouseDownCanMoveWindow_; | 463 return mouseDownCanMoveWindow_; |
463 } | 464 } |
464 | 465 |
465 - (void)pasteboard:(NSPasteboard*)sender provideDataForType:(NSString*)type { | 466 - (void)pasteboard:(NSPasteboard*)sender provideDataForType:(NSString*)type { |
466 [dragSource_ lazyWriteToPasteboard:sender | 467 [dragSource_ lazyWriteToPasteboard:sender |
467 forType:type]; | 468 forType:type]; |
468 } | 469 } |
469 | 470 |
470 - (void)startDragWithDropData:(const WebDropData&)dropData | 471 - (void)startDragWithDropData:(const DropData&)dropData |
471 dragOperationMask:(NSDragOperation)operationMask | 472 dragOperationMask:(NSDragOperation)operationMask |
472 image:(NSImage*)image | 473 image:(NSImage*)image |
473 offset:(NSPoint)offset { | 474 offset:(NSPoint)offset { |
474 dragSource_.reset([[WebDragSource alloc] | 475 dragSource_.reset([[WebDragSource alloc] |
475 initWithContents:[self webContents] | 476 initWithContents:[self webContents] |
476 view:self | 477 view:self |
477 dropData:&dropData | 478 dropData:&dropData |
478 image:image | 479 image:image |
479 offset:offset | 480 offset:offset |
480 pasteboard:[NSPasteboard pasteboardWithName:NSDragPboard] | 481 pasteboard:[NSPasteboard pasteboardWithName:NSDragPboard] |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
554 [[[notification userInfo] objectForKey:kSelectionDirection] | 555 [[[notification userInfo] objectForKey:kSelectionDirection] |
555 unsignedIntegerValue]; | 556 unsignedIntegerValue]; |
556 if (direction == NSDirectSelection) | 557 if (direction == NSDirectSelection) |
557 return; | 558 return; |
558 | 559 |
559 [self webContents]-> | 560 [self webContents]-> |
560 FocusThroughTabTraversal(direction == NSSelectingPrevious); | 561 FocusThroughTabTraversal(direction == NSSelectingPrevious); |
561 } | 562 } |
562 | 563 |
563 @end | 564 @end |
OLD | NEW |