| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #include "chrome/browser/tab_contents/tab_contents_view_mac.h" | 7 #include "chrome/browser/tab_contents/tab_contents_view_mac.h" |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #import "base/chrome_application_mac.h" | 11 #import "base/chrome_application_mac.h" |
| 12 #include "chrome/browser/browser.h" // TODO(beng): this dependency is awful. | 12 #include "chrome/browser/browser.h" // TODO(beng): this dependency is awful. |
| 13 #import "chrome/browser/cocoa/focus_tracker.h" | 13 #import "chrome/browser/cocoa/focus_tracker.h" |
| 14 #import "chrome/browser/cocoa/chrome_browser_window.h" | 14 #import "chrome/browser/cocoa/chrome_browser_window.h" |
| 15 #import "chrome/browser/cocoa/browser_window_controller.h" | 15 #import "chrome/browser/cocoa/browser_window_controller.h" |
| 16 #include "chrome/browser/global_keyboard_shortcuts_mac.h" | 16 #include "chrome/browser/global_keyboard_shortcuts_mac.h" |
| 17 #include "chrome/browser/cocoa/sad_tab_controller.h" | 17 #include "chrome/browser/cocoa/sad_tab_controller.h" |
| 18 #import "chrome/browser/cocoa/web_drag_source.h" | 18 #import "chrome/browser/cocoa/web_drag_source.h" |
| 19 #import "chrome/browser/cocoa/web_drop_target.h" | 19 #import "chrome/browser/cocoa/web_drop_target.h" |
| 20 #include "chrome/browser/renderer_host/render_view_host.h" | 20 #include "chrome/browser/renderer_host/render_view_host.h" |
| 21 #include "chrome/browser/renderer_host/render_view_host_factory.h" | 21 #include "chrome/browser/renderer_host/render_view_host_factory.h" |
| 22 #include "chrome/browser/renderer_host/render_widget_host.h" | 22 #include "chrome/browser/renderer_host/render_widget_host.h" |
| 23 #include "chrome/browser/renderer_host/render_widget_host_view_mac.h" | 23 #include "chrome/browser/renderer_host/render_widget_host_view_mac.h" |
| 24 #include "chrome/browser/tab_contents/render_view_context_menu_mac.h" | 24 #include "chrome/browser/tab_contents/render_view_context_menu_mac.h" |
| 25 #include "chrome/browser/tab_contents/tab_contents.h" | 25 #include "chrome/browser/tab_contents/tab_contents.h" |
| 26 #include "chrome/common/notification_type.h" | 26 #include "chrome/common/notification_type.h" |
| 27 #include "chrome/common/notification_service.h" | 27 #include "chrome/common/notification_service.h" |
| 28 #include "chrome/common/render_messages.h" | 28 #include "chrome/common/render_messages.h" |
| 29 #include "skia/ext/skia_utils_mac.h" |
| 29 #import "third_party/mozilla/include/NSPasteboard+Utils.h" | 30 #import "third_party/mozilla/include/NSPasteboard+Utils.h" |
| 30 | 31 |
| 31 using WebKit::WebDragOperation; | 32 using WebKit::WebDragOperation; |
| 32 using WebKit::WebDragOperationsMask; | 33 using WebKit::WebDragOperationsMask; |
| 33 | 34 |
| 34 // Ensure that the WebKit::WebDragOperation enum values stay in sync with | 35 // Ensure that the WebKit::WebDragOperation enum values stay in sync with |
| 35 // NSDragOperation constants, since the code below static_casts between 'em. | 36 // NSDragOperation constants, since the code below static_casts between 'em. |
| 36 #define COMPILE_ASSERT_MATCHING_ENUM(name) \ | 37 #define COMPILE_ASSERT_MATCHING_ENUM(name) \ |
| 37 COMPILE_ASSERT(int(NS##name) == int(WebKit::Web##name), enum_mismatch_##name) | 38 COMPILE_ASSERT(int(NS##name) == int(WebKit::Web##name), enum_mismatch_##name) |
| 38 COMPILE_ASSERT_MATCHING_ENUM(DragOperationNone); | 39 COMPILE_ASSERT_MATCHING_ENUM(DragOperationNone); |
| 39 COMPILE_ASSERT_MATCHING_ENUM(DragOperationCopy); | 40 COMPILE_ASSERT_MATCHING_ENUM(DragOperationCopy); |
| 40 COMPILE_ASSERT_MATCHING_ENUM(DragOperationLink); | 41 COMPILE_ASSERT_MATCHING_ENUM(DragOperationLink); |
| 41 COMPILE_ASSERT_MATCHING_ENUM(DragOperationGeneric); | 42 COMPILE_ASSERT_MATCHING_ENUM(DragOperationGeneric); |
| 42 COMPILE_ASSERT_MATCHING_ENUM(DragOperationPrivate); | 43 COMPILE_ASSERT_MATCHING_ENUM(DragOperationPrivate); |
| 43 COMPILE_ASSERT_MATCHING_ENUM(DragOperationMove); | 44 COMPILE_ASSERT_MATCHING_ENUM(DragOperationMove); |
| 44 COMPILE_ASSERT_MATCHING_ENUM(DragOperationDelete); | 45 COMPILE_ASSERT_MATCHING_ENUM(DragOperationDelete); |
| 45 COMPILE_ASSERT_MATCHING_ENUM(DragOperationEvery); | 46 COMPILE_ASSERT_MATCHING_ENUM(DragOperationEvery); |
| 46 | 47 |
| 47 @interface TabContentsViewCocoa (Private) | 48 @interface TabContentsViewCocoa (Private) |
| 48 - (id)initWithTabContentsViewMac:(TabContentsViewMac*)w; | 49 - (id)initWithTabContentsViewMac:(TabContentsViewMac*)w; |
| 49 - (void)registerDragTypes; | 50 - (void)registerDragTypes; |
| 50 - (void)setCurrentDragOperation:(NSDragOperation)operation; | 51 - (void)setCurrentDragOperation:(NSDragOperation)operation; |
| 51 - (void)startDragWithDropData:(const WebDropData&)dropData | 52 - (void)startDragWithDropData:(const WebDropData&)dropData |
| 52 dragOperationMask:(NSDragOperation)operationMask; | 53 dragOperationMask:(NSDragOperation)operationMask |
| 54 image:(NSImage*)image |
| 55 offset:(NSPoint)offset; |
| 53 - (void)cancelDeferredClose; | 56 - (void)cancelDeferredClose; |
| 54 - (void)closeTabAfterEvent; | 57 - (void)closeTabAfterEvent; |
| 55 @end | 58 @end |
| 56 | 59 |
| 57 // static | 60 // static |
| 58 TabContentsView* TabContentsView::Create(TabContents* tab_contents) { | 61 TabContentsView* TabContentsView::Create(TabContents* tab_contents) { |
| 59 return new TabContentsViewMac(tab_contents); | 62 return new TabContentsViewMac(tab_contents); |
| 60 } | 63 } |
| 61 | 64 |
| 62 TabContentsViewMac::TabContentsViewMac(TabContents* tab_contents) | 65 TabContentsViewMac::TabContentsViewMac(TabContents* tab_contents) |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 // By allowing nested tasks, the code below also allows Close(), | 137 // By allowing nested tasks, the code below also allows Close(), |
| 135 // which would deallocate |this|. The same problem can occur while | 138 // which would deallocate |this|. The same problem can occur while |
| 136 // processing -sendEvent:, so Close() is deferred in that case. | 139 // processing -sendEvent:, so Close() is deferred in that case. |
| 137 // Drags from web content do not come via -sendEvent:, this sets the | 140 // Drags from web content do not come via -sendEvent:, this sets the |
| 138 // same flag -sendEvent: would. | 141 // same flag -sendEvent: would. |
| 139 chrome_application_mac::ScopedSendingEvent sendingEventScoper; | 142 chrome_application_mac::ScopedSendingEvent sendingEventScoper; |
| 140 | 143 |
| 141 // The drag invokes a nested event loop, arrange to continue | 144 // The drag invokes a nested event loop, arrange to continue |
| 142 // processing events. | 145 // processing events. |
| 143 MessageLoop::ScopedNestableTaskAllower allow(MessageLoop::current()); | 146 MessageLoop::ScopedNestableTaskAllower allow(MessageLoop::current()); |
| 144 // TODO(estade): make use of |image| and |image_offset|. | |
| 145 NSDragOperation mask = static_cast<NSDragOperation>(allowed_operations); | 147 NSDragOperation mask = static_cast<NSDragOperation>(allowed_operations); |
| 148 NSPoint offset = NSPointFromCGPoint(image_offset.ToCGPoint()); |
| 146 [cocoa_view_ startDragWithDropData:drop_data | 149 [cocoa_view_ startDragWithDropData:drop_data |
| 147 dragOperationMask:mask]; | 150 dragOperationMask:mask |
| 151 image:gfx::SkBitmapToNSImage(image) |
| 152 offset:offset]; |
| 148 } | 153 } |
| 149 | 154 |
| 150 void TabContentsViewMac::RenderViewCreated(RenderViewHost* host) { | 155 void TabContentsViewMac::RenderViewCreated(RenderViewHost* host) { |
| 151 // We want updates whenever the intrinsic width of the webpage | 156 // We want updates whenever the intrinsic width of the webpage |
| 152 // changes. Put the RenderView into that mode. | 157 // changes. Put the RenderView into that mode. |
| 153 int routing_id = host->routing_id(); | 158 int routing_id = host->routing_id(); |
| 154 host->Send(new ViewMsg_EnablePreferredSizeChangedMode(routing_id)); | 159 host->Send(new ViewMsg_EnablePreferredSizeChangedMode(routing_id)); |
| 155 } | 160 } |
| 156 | 161 |
| 157 void TabContentsViewMac::SetPageTitle(const std::wstring& title) { | 162 void TabContentsViewMac::SetPageTitle(const std::wstring& title) { |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 // subview. | 374 // subview. |
| 370 return NO; | 375 return NO; |
| 371 } | 376 } |
| 372 | 377 |
| 373 - (void)pasteboard:(NSPasteboard*)sender provideDataForType:(NSString*)type { | 378 - (void)pasteboard:(NSPasteboard*)sender provideDataForType:(NSString*)type { |
| 374 [dragSource_ lazyWriteToPasteboard:sender | 379 [dragSource_ lazyWriteToPasteboard:sender |
| 375 forType:type]; | 380 forType:type]; |
| 376 } | 381 } |
| 377 | 382 |
| 378 - (void)startDragWithDropData:(const WebDropData&)dropData | 383 - (void)startDragWithDropData:(const WebDropData&)dropData |
| 379 dragOperationMask:(NSDragOperation)operationMask { | 384 dragOperationMask:(NSDragOperation)operationMask |
| 385 image:(NSImage*)image |
| 386 offset:(NSPoint)offset { |
| 380 dragSource_.reset([[WebDragSource alloc] | 387 dragSource_.reset([[WebDragSource alloc] |
| 381 initWithContentsView:self | 388 initWithContentsView:self |
| 382 dropData:&dropData | 389 dropData:&dropData |
| 390 image:image |
| 391 offset:offset |
| 383 pasteboard:[NSPasteboard pasteboardWithName:NSDragPboard] | 392 pasteboard:[NSPasteboard pasteboardWithName:NSDragPboard] |
| 384 dragOperationMask:operationMask]); | 393 dragOperationMask:operationMask]); |
| 385 [dragSource_ startDrag]; | 394 [dragSource_ startDrag]; |
| 386 } | 395 } |
| 387 | 396 |
| 388 // NSDraggingSource methods | 397 // NSDraggingSource methods |
| 389 | 398 |
| 390 // Returns what kind of drag operations are available. This is a required | 399 // Returns what kind of drag operations are available. This is a required |
| 391 // method for NSDraggingSource. | 400 // method for NSDraggingSource. |
| 392 - (NSDragOperation)draggingSourceOperationMaskForLocal:(BOOL)isLocal { | 401 - (NSDragOperation)draggingSourceOperationMaskForLocal:(BOOL)isLocal { |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 443 [NSObject cancelPreviousPerformRequestsWithTarget:self | 452 [NSObject cancelPreviousPerformRequestsWithTarget:self |
| 444 selector:aSel | 453 selector:aSel |
| 445 object:nil]; | 454 object:nil]; |
| 446 } | 455 } |
| 447 | 456 |
| 448 - (void)closeTabAfterEvent { | 457 - (void)closeTabAfterEvent { |
| 449 tabContentsView_->CloseTab(); | 458 tabContentsView_->CloseTab(); |
| 450 } | 459 } |
| 451 | 460 |
| 452 @end | 461 @end |
| OLD | NEW |