Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "base/sys_string_conversions.h" | |
| 7 #include "chrome/browser/browser.h" // TODO(beng): this dependency is awful. | 8 #include "chrome/browser/browser.h" // TODO(beng): this dependency is awful. |
| 9 #include "chrome/browser/cocoa/nsimage_cache.h" | |
| 8 #include "chrome/browser/cocoa/sad_tab_view.h" | 10 #include "chrome/browser/cocoa/sad_tab_view.h" |
| 9 #include "chrome/browser/renderer_host/render_widget_host.h" | 11 #include "chrome/browser/renderer_host/render_widget_host.h" |
| 10 #include "chrome/browser/renderer_host/render_widget_host_view_mac.h" | 12 #include "chrome/browser/renderer_host/render_widget_host_view_mac.h" |
| 11 #include "chrome/browser/tab_contents/render_view_context_menu_mac.h" | 13 #include "chrome/browser/tab_contents/render_view_context_menu_mac.h" |
| 12 #include "chrome/browser/tab_contents/tab_contents.h" | 14 #include "chrome/browser/tab_contents/tab_contents.h" |
| 13 #include "chrome/common/notification_type.h" | 15 #include "chrome/common/notification_type.h" |
| 14 #include "chrome/common/notification_service.h" | 16 #include "chrome/common/notification_service.h" |
| 15 #include "chrome/common/render_messages.h" | 17 #include "chrome/common/render_messages.h" |
| 18 #import "third_party/mozilla/include/NSPasteboard+Utils.h" | |
| 16 | 19 |
| 17 #include "chrome/common/temp_scaffolding_stubs.h" | 20 #include "chrome/common/temp_scaffolding_stubs.h" |
| 18 | 21 |
| 19 @interface TabContentsViewCocoa (Private) | 22 @interface TabContentsViewCocoa (Private) |
| 20 - (id)initWithTabContentsViewMac:(TabContentsViewMac*)w; | 23 - (id)initWithTabContentsViewMac:(TabContentsViewMac*)w; |
| 21 - (void)processKeyboardEvent:(NSEvent*)event; | 24 - (void)processKeyboardEvent:(NSEvent*)event; |
| 22 @end | 25 @end |
| 23 | 26 |
| 24 // static | 27 // static |
| 25 TabContentsView* TabContentsView::Create(TabContents* tab_contents) { | 28 TabContentsView* TabContentsView::Create(TabContents* tab_contents) { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 71 } | 74 } |
| 72 | 75 |
| 73 gfx::NativeWindow TabContentsViewMac::GetTopLevelNativeWindow() const { | 76 gfx::NativeWindow TabContentsViewMac::GetTopLevelNativeWindow() const { |
| 74 return [cocoa_view_.get() window]; | 77 return [cocoa_view_.get() window]; |
| 75 } | 78 } |
| 76 | 79 |
| 77 void TabContentsViewMac::GetContainerBounds(gfx::Rect* out) const { | 80 void TabContentsViewMac::GetContainerBounds(gfx::Rect* out) const { |
| 78 *out = [cocoa_view_.get() NSRectToRect:[cocoa_view_.get() bounds]]; | 81 *out = [cocoa_view_.get() NSRectToRect:[cocoa_view_.get() bounds]]; |
| 79 } | 82 } |
| 80 | 83 |
| 84 // Returns a drag pasteboard filled with the appropriate data. The types are | |
| 85 // 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.
| |
| 86 NSPasteboard* TabContentsViewMac::FillDragData( | |
| 87 const WebDropData& drop_data) { | |
| 88 NSPasteboard* pasteboard = [NSPasteboard pasteboardWithName:NSDragPboard]; | |
| 89 [pasteboard declareTypes:[NSArray array] owner:nil]; | |
| 90 | |
| 91 // URL. | |
| 92 if (drop_data.url.is_valid()) { | |
| 93 // TODO(pinkerton/jrg): special javascript: handling for bookmark bar. Win | |
| 94 // doesn't allow you to drop js: bookmarks on the desktop (since they're | |
| 95 // meaningless) but does allow you to drop them on the bookmark bar (where | |
| 96 // they're intended to go generally). We need to figure out a private | |
| 97 // flavor for Bookmark dragging and then flag this down in the drag source. | |
| 98 [pasteboard addTypes:[NSArray arrayWithObject:NSURLPboardType] | |
| 99 owner:nil]; | |
| 100 NSString* url = base::SysUTF8ToNSString(drop_data.url.spec()); | |
| 101 NSString* title = base::SysUTF16ToNSString(drop_data.url_title); | |
| 102 [pasteboard setURLs:[NSArray arrayWithObject:url] | |
| 103 withTitles:[NSArray arrayWithObject:title]]; | |
| 104 } | |
| 105 | |
| 106 // HTML. | |
| 107 if (!drop_data.text_html.empty()) { | |
| 108 [pasteboard addTypes:[NSArray arrayWithObject:NSHTMLPboardType] | |
| 109 owner:nil]; | |
| 110 [pasteboard setString:base::SysUTF16ToNSString(drop_data.text_html) | |
| 111 forType:NSHTMLPboardType]; | |
| 112 } | |
| 113 | |
| 114 // Files. | |
| 115 // TODO(pinkerton): image drags, data is in drop_data.file_contents. | |
| 116 | |
| 117 // Plain text. | |
| 118 if (!drop_data.plain_text.empty()) { | |
| 119 [pasteboard addTypes:[NSArray arrayWithObject:NSStringPboardType] | |
| 120 owner:nil]; | |
| 121 [pasteboard setString:base::SysUTF16ToNSString(drop_data.plain_text) | |
| 122 forType:NSStringPboardType]; | |
| 123 } | |
| 124 return pasteboard; | |
| 125 } | |
| 126 | |
| 81 void TabContentsViewMac::StartDragging(const WebDropData& drop_data) { | 127 void TabContentsViewMac::StartDragging(const WebDropData& drop_data) { |
| 82 NOTIMPLEMENTED(); | 128 // Create an image to use for the drag. |
| 129 // TODO(pinkerton): Generate the proper image. This one will do in a pinch. | |
| 130 NSImage* dragImage = nsimage_cache::ImageNamed(@"nav.pdf"); | |
| 83 | 131 |
| 84 // Until we have d'n'd implemented, just immediately pretend we're | 132 NSPasteboard* pasteboard = FillDragData(drop_data); |
| 85 // already done with the drag and drop so we don't get stuck | 133 |
| 86 // thinking we're in mid-drag. | 134 // Tell the view to start a drag using |cocoa_view_| as the drag source. The |
| 87 // TODO(port): remove me when the above NOTIMPLEMENTED is fixed. | 135 // source will get notified when the drag completes (success or failure) so |
| 88 if (tab_contents()->render_view_host()) | 136 // it can tell the render view host the drag is done. Windows does this with |
| 89 tab_contents()->render_view_host()->DragSourceSystemDragEnded(); | 137 // a nested event loop, we get called back. |
| 138 NSEvent* currentEvent = [NSApp currentEvent]; | |
| 139 NSPoint mousePoint = [currentEvent locationInWindow]; | |
| 140 mousePoint = [cocoa_view_ convertPoint:mousePoint fromView:nil]; | |
| 141 [cocoa_view_ dragImage:dragImage at:mousePoint offset:NSZeroSize | |
| 142 event:currentEvent pasteboard:pasteboard source:cocoa_view_ | |
| 143 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.
| |
| 90 } | 144 } |
| 91 | 145 |
| 92 void TabContentsViewMac::OnContentsDestroy() { | 146 void TabContentsViewMac::OnContentsDestroy() { |
| 93 } | 147 } |
| 94 | 148 |
| 95 void TabContentsViewMac::RenderViewCreated(RenderViewHost* host) { | 149 void TabContentsViewMac::RenderViewCreated(RenderViewHost* host) { |
| 96 // We want updates whenever the intrinsic width of the webpage | 150 // We want updates whenever the intrinsic width of the webpage |
| 97 // changes. Put the RenderView into that mode. | 151 // changes. Put the RenderView into that mode. |
| 98 int routing_id = host->routing_id(); | 152 int routing_id = host->routing_id(); |
| 99 host->Send(new ViewMsg_EnableIntrinsicWidthChangedMode(routing_id)); | 153 host->Send(new ViewMsg_EnableIntrinsicWidthChangedMode(routing_id)); |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 283 } | 337 } |
| 284 | 338 |
| 285 - (void)copy:(id)sender { | 339 - (void)copy:(id)sender { |
| 286 TabContentsView_->tab_contents()->Copy(); | 340 TabContentsView_->tab_contents()->Copy(); |
| 287 } | 341 } |
| 288 | 342 |
| 289 - (void)paste:(id)sender { | 343 - (void)paste:(id)sender { |
| 290 TabContentsView_->tab_contents()->Paste(); | 344 TabContentsView_->tab_contents()->Paste(); |
| 291 } | 345 } |
| 292 | 346 |
| 347 // NSDraggingSource methods | |
| 348 | |
| 349 // Returns what kind of drag operations are available. This is a required | |
| 350 // method for NSDraggingSource. | |
| 351 - (NSDragOperation)draggingSourceOperationMaskForLocal:(BOOL)isLocal { | |
| 352 // TODO(pinkerton): I think this is right... | |
| 353 return NSDragOperationCopy; | |
| 354 } | |
| 355 | |
| 356 // Called when a drag initiated in our view ends. We need to make sure that | |
| 357 // we tell WebCore so that it can go about processing things as normal. | |
| 358 - (void)draggedImage:(NSImage*)anImage | |
| 359 endedAt:(NSPoint)aPoint | |
| 360 operation:(NSDragOperation)operation { | |
| 361 RenderViewHost* rvh = TabContentsView_->tab_contents()->render_view_host(); | |
| 362 if (rvh) | |
| 363 rvh->DragSourceSystemDragEnded(); | |
| 364 } | |
| 365 | |
| 366 // NSDraggingDestination methods | |
| 367 | |
| 368 - (NSDragOperation)draggingEntered:(id<NSDraggingInfo>)sender { | |
| 369 return NSDragOperationCopy; | |
| 370 } | |
| 371 | |
| 372 - (void)draggingExited:(id<NSDraggingInfo>)sender { | |
| 373 | |
|
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.
| |
| 374 } | |
| 375 | |
| 376 - (NSDragOperation)draggingUpdated:(id<NSDraggingInfo>)sender { | |
| 377 return NSDragOperationCopy; | |
| 378 } | |
| 379 | |
| 380 - (BOOL)performDragOperation:(id<NSDraggingInfo>)sender { | |
| 381 // 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.
| |
| 382 return NO; | |
| 383 } | |
| 384 | |
| 293 // Tons of stuff goes here, where we grab events going on in Cocoaland and send | 385 // Tons of stuff goes here, where we grab events going on in Cocoaland and send |
| 294 // them into the C++ system. TODO(avi): all that jazz | 386 // them into the C++ system. TODO(avi): all that jazz |
| 295 | 387 |
| 296 @end | 388 @end |
| OLD | NEW |