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

Unified Diff: chrome/browser/tab_contents/tab_contents_view_mac.mm

Issue 149565: Allow dragging text/url content out of the browser. Dragging back in not yet ... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/tab_contents/tab_contents_view_mac.h ('k') | chrome/chrome.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/tab_contents/tab_contents_view_mac.mm
===================================================================
--- chrome/browser/tab_contents/tab_contents_view_mac.mm (revision 20373)
+++ chrome/browser/tab_contents/tab_contents_view_mac.mm (working copy)
@@ -4,7 +4,9 @@
#include "chrome/browser/tab_contents/tab_contents_view_mac.h"
+#include "base/sys_string_conversions.h"
#include "chrome/browser/browser.h" // TODO(beng): this dependency is awful.
+#include "chrome/browser/cocoa/nsimage_cache.h"
#include "chrome/browser/cocoa/sad_tab_view.h"
#include "chrome/browser/renderer_host/render_widget_host.h"
#include "chrome/browser/renderer_host/render_widget_host_view_mac.h"
@@ -13,6 +15,7 @@
#include "chrome/common/notification_type.h"
#include "chrome/common/notification_service.h"
#include "chrome/common/render_messages.h"
+#import "third_party/mozilla/include/NSPasteboard+Utils.h"
#include "chrome/common/temp_scaffolding_stubs.h"
@@ -78,15 +81,66 @@
*out = [cocoa_view_.get() NSRectToRect:[cocoa_view_.get() bounds]];
}
+// Returns a drag pasteboard filled with the appropriate data. The types are
+// populated in decending order of richness.
stuartmorgan 2009/07/13 21:43:32 Isn't HTML richer than a URL?
pink (ping after 24hrs) 2009/07/13 21:57:57 Done.
+NSPasteboard* TabContentsViewMac::FillDragData(
+ const WebDropData& drop_data) {
+ NSPasteboard* pasteboard = [NSPasteboard pasteboardWithName:NSDragPboard];
+ [pasteboard declareTypes:[NSArray array] owner:nil];
+
+ // URL.
+ if (drop_data.url.is_valid()) {
+ // TODO(pinkerton/jrg): special javascript: handling for bookmark bar. Win
+ // doesn't allow you to drop js: bookmarks on the desktop (since they're
+ // meaningless) but does allow you to drop them on the bookmark bar (where
+ // they're intended to go generally). We need to figure out a private
+ // flavor for Bookmark dragging and then flag this down in the drag source.
+ [pasteboard addTypes:[NSArray arrayWithObject:NSURLPboardType]
+ owner:nil];
+ NSString* url = base::SysUTF8ToNSString(drop_data.url.spec());
+ NSString* title = base::SysUTF16ToNSString(drop_data.url_title);
+ [pasteboard setURLs:[NSArray arrayWithObject:url]
+ withTitles:[NSArray arrayWithObject:title]];
+ }
+
+ // HTML.
+ if (!drop_data.text_html.empty()) {
+ [pasteboard addTypes:[NSArray arrayWithObject:NSHTMLPboardType]
+ owner:nil];
+ [pasteboard setString:base::SysUTF16ToNSString(drop_data.text_html)
+ forType:NSHTMLPboardType];
+ }
+
+ // Files.
+ // TODO(pinkerton): image drags, data is in drop_data.file_contents.
+
+ // Plain text.
+ if (!drop_data.plain_text.empty()) {
+ [pasteboard addTypes:[NSArray arrayWithObject:NSStringPboardType]
+ owner:nil];
+ [pasteboard setString:base::SysUTF16ToNSString(drop_data.plain_text)
+ forType:NSStringPboardType];
+ }
+ return pasteboard;
+}
+
void TabContentsViewMac::StartDragging(const WebDropData& drop_data) {
- NOTIMPLEMENTED();
+ // Create an image to use for the drag.
+ // TODO(pinkerton): Generate the proper image. This one will do in a pinch.
+ NSImage* dragImage = nsimage_cache::ImageNamed(@"nav.pdf");
- // Until we have d'n'd implemented, just immediately pretend we're
- // already done with the drag and drop so we don't get stuck
- // thinking we're in mid-drag.
- // TODO(port): remove me when the above NOTIMPLEMENTED is fixed.
- if (tab_contents()->render_view_host())
- tab_contents()->render_view_host()->DragSourceSystemDragEnded();
+ NSPasteboard* pasteboard = FillDragData(drop_data);
+
+ // Tell the view to start a drag using |cocoa_view_| as the drag source. The
+ // source will get notified when the drag completes (success or failure) so
+ // it can tell the render view host the drag is done. Windows does this with
+ // a nested event loop, we get called back.
+ NSEvent* currentEvent = [NSApp currentEvent];
+ NSPoint mousePoint = [currentEvent locationInWindow];
+ mousePoint = [cocoa_view_ convertPoint:mousePoint fromView:nil];
+ [cocoa_view_ dragImage:dragImage at:mousePoint offset:NSZeroSize
+ event:currentEvent pasteboard:pasteboard source:cocoa_view_
+ slideBack:YES];
stuartmorgan 2009/07/13 21:43:32 Isn't our style either one line, or one argument p
pink (ping after 24hrs) 2009/07/13 21:57:57 Done.
}
void TabContentsViewMac::OnContentsDestroy() {
@@ -290,6 +344,44 @@
TabContentsView_->tab_contents()->Paste();
}
+// NSDraggingSource methods
+
+// Returns what kind of drag operations are available. This is a required
+// method for NSDraggingSource.
+- (NSDragOperation)draggingSourceOperationMaskForLocal:(BOOL)isLocal {
+ // TODO(pinkerton): I think this is right...
+ return NSDragOperationCopy;
+}
+
+// Called when a drag initiated in our view ends. We need to make sure that
+// we tell WebCore so that it can go about processing things as normal.
+- (void)draggedImage:(NSImage*)anImage
+ endedAt:(NSPoint)aPoint
+ operation:(NSDragOperation)operation {
+ RenderViewHost* rvh = TabContentsView_->tab_contents()->render_view_host();
+ if (rvh)
+ rvh->DragSourceSystemDragEnded();
+}
+
+// NSDraggingDestination methods
+
+- (NSDragOperation)draggingEntered:(id<NSDraggingInfo>)sender {
+ return NSDragOperationCopy;
+}
+
+- (void)draggingExited:(id<NSDraggingInfo>)sender {
+
stuartmorgan 2009/07/13 21:43:32 Why is there an empty and TODO-less method?
pink (ping after 24hrs) 2009/07/13 21:57:57 Done.
+}
+
+- (NSDragOperation)draggingUpdated:(id<NSDraggingInfo>)sender {
+ return NSDragOperationCopy;
+}
+
+- (BOOL)performDragOperation:(id<NSDraggingInfo>)sender {
+ // TODO(pinkerton): Force drops to be rejected until that's hooked up.
stuartmorgan 2009/07/13 21:43:32 Seems like this is describing the current behavior
pink (ping after 24hrs) 2009/07/13 21:57:57 Done.
+ return NO;
+}
+
// Tons of stuff goes here, where we grab events going on in Cocoaland and send
// them into the C++ system. TODO(avi): all that jazz
« no previous file with comments | « chrome/browser/tab_contents/tab_contents_view_mac.h ('k') | chrome/chrome.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698