| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 - (void)registerDragTypes; | 54 - (void)registerDragTypes; |
| 55 - (void)setCurrentDragOperation:(NSDragOperation)operation; | 55 - (void)setCurrentDragOperation:(NSDragOperation)operation; |
| 56 - (void)startDragWithDropData:(const WebDropData&)dropData | 56 - (void)startDragWithDropData:(const WebDropData&)dropData |
| 57 dragOperationMask:(NSDragOperation)operationMask | 57 dragOperationMask:(NSDragOperation)operationMask |
| 58 image:(NSImage*)image | 58 image:(NSImage*)image |
| 59 offset:(NSPoint)offset; | 59 offset:(NSPoint)offset; |
| 60 - (void)cancelDeferredClose; | 60 - (void)cancelDeferredClose; |
| 61 - (void)clearTabContentsView; | 61 - (void)clearTabContentsView; |
| 62 - (void)closeTabAfterEvent; | 62 - (void)closeTabAfterEvent; |
| 63 - (void)viewDidBecomeFirstResponder:(NSNotification*)notification; | 63 - (void)viewDidBecomeFirstResponder:(NSNotification*)notification; |
| 64 // Notify the RenderWidgetHost that the frame was updated so it can resize |
| 65 // its contents. |
| 66 - (void)renderWidgetHostWasResized; |
| 64 @end | 67 @end |
| 65 | 68 |
| 66 namespace tab_contents_view_mac { | 69 namespace tab_contents_view_mac { |
| 67 TabContentsView* CreateTabContentsView(TabContents* tab_contents) { | 70 TabContentsView* CreateTabContentsView(TabContents* tab_contents) { |
| 68 return new TabContentsViewMac(tab_contents); | 71 return new TabContentsViewMac(tab_contents); |
| 69 } | 72 } |
| 70 } | 73 } |
| 71 | 74 |
| 72 TabContentsViewMac::TabContentsViewMac(TabContents* tab_contents) | 75 TabContentsViewMac::TabContentsViewMac(TabContents* tab_contents) |
| 73 : tab_contents_(tab_contents), | 76 : tab_contents_(tab_contents), |
| 74 preferred_width_(0) { | 77 preferred_width_(0) { |
| 75 registrar_.Add(this, content::NOTIFICATION_TAB_CONTENTS_CONNECTED, | 78 registrar_.Add(this, content::NOTIFICATION_TAB_CONTENTS_CONNECTED, |
| 76 content::Source<TabContents>(tab_contents)); | 79 content::Source<TabContents>(tab_contents)); |
| 77 } | 80 } |
| 78 | 81 |
| 79 TabContentsViewMac::~TabContentsViewMac() { | 82 TabContentsViewMac::~TabContentsViewMac() { |
| 80 // This handles the case where a renderer close call was deferred | 83 // This handles the case where a renderer close call was deferred |
| 81 // while the user was operating a UI control which resulted in a | 84 // while the user was operating a UI control which resulted in a |
| 82 // close. In that case, the Cocoa view outlives the | 85 // close. In that case, the Cocoa view outlives the |
| 83 // TabContentsViewMac instance due to Cocoa retain count. | 86 // TabContentsViewMac instance due to Cocoa retain count. |
| 84 [cocoa_view_ cancelDeferredClose]; | 87 [cocoa_view_ cancelDeferredClose]; |
| 85 [cocoa_view_ clearTabContentsView]; | 88 [cocoa_view_ clearTabContentsView]; |
| 86 } | 89 } |
| 87 | 90 |
| 88 void TabContentsViewMac::CreateView(const gfx::Size& initial_size) { | 91 void TabContentsViewMac::CreateView(const gfx::Size& initial_size) { |
| 89 TabContentsViewCocoa* view = | 92 TabContentsViewCocoa* view = |
| 90 [[TabContentsViewCocoa alloc] initWithTabContentsViewMac:this]; | 93 [[TabContentsViewCocoa alloc] initWithTabContentsViewMac:this]; |
| 91 [view setAutoresizingMask:(NSViewWidthSizable | NSViewHeightSizable)]; | |
| 92 cocoa_view_.reset(view); | 94 cocoa_view_.reset(view); |
| 93 } | 95 } |
| 94 | 96 |
| 95 RenderWidgetHostView* TabContentsViewMac::CreateViewForWidget( | 97 RenderWidgetHostView* TabContentsViewMac::CreateViewForWidget( |
| 96 RenderWidgetHost* render_widget_host) { | 98 RenderWidgetHost* render_widget_host) { |
| 97 if (render_widget_host->view()) { | 99 if (render_widget_host->view()) { |
| 98 // During testing, the view will already be set up in most cases to the | 100 // During testing, the view will already be set up in most cases to the |
| 99 // test view, so we don't want to clobber it with a real one. To verify that | 101 // test view, so we don't want to clobber it with a real one. To verify that |
| 100 // this actually is happening (and somebody isn't accidentally creating the | 102 // this actually is happening (and somebody isn't accidentally creating the |
| 101 // view twice), we check for the RVH Factory, which will be set when we're | 103 // view twice), we check for the RVH Factory, which will be set when we're |
| (...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 507 initWithContents:[self tabContents] | 509 initWithContents:[self tabContents] |
| 508 view:self | 510 view:self |
| 509 dropData:&dropData | 511 dropData:&dropData |
| 510 image:image | 512 image:image |
| 511 offset:offset | 513 offset:offset |
| 512 pasteboard:[NSPasteboard pasteboardWithName:NSDragPboard] | 514 pasteboard:[NSPasteboard pasteboardWithName:NSDragPboard] |
| 513 dragOperationMask:operationMask]); | 515 dragOperationMask:operationMask]); |
| 514 [dragSource_ startDrag]; | 516 [dragSource_ startDrag]; |
| 515 } | 517 } |
| 516 | 518 |
| 519 - (void)setFrameWithDeferredUpdate:(NSRect)frameRect { |
| 520 [super setFrame:frameRect]; |
| 521 [self performSelector:@selector(renderWidgetHostWasResized) |
| 522 withObject:nil |
| 523 afterDelay:0]; |
| 524 } |
| 525 |
| 526 - (void)renderWidgetHostWasResized { |
| 527 TabContents* tabContents = [self tabContents]; |
| 528 if (tabContents->render_view_host()) |
| 529 tabContents->render_view_host()->WasResized(); |
| 530 } |
| 531 |
| 517 // NSDraggingSource methods | 532 // NSDraggingSource methods |
| 518 | 533 |
| 519 // Returns what kind of drag operations are available. This is a required | 534 // Returns what kind of drag operations are available. This is a required |
| 520 // method for NSDraggingSource. | 535 // method for NSDraggingSource. |
| 521 - (NSDragOperation)draggingSourceOperationMaskForLocal:(BOOL)isLocal { | 536 - (NSDragOperation)draggingSourceOperationMaskForLocal:(BOOL)isLocal { |
| 522 if (dragSource_.get()) | 537 if (dragSource_.get()) |
| 523 return [dragSource_ draggingSourceOperationMaskForLocal:isLocal]; | 538 return [dragSource_ draggingSourceOperationMaskForLocal:isLocal]; |
| 524 // No web drag source - this is the case for dragging a file from the | 539 // No web drag source - this is the case for dragging a file from the |
| 525 // downloads manager. Default to copy operation. Note: It is desirable to | 540 // downloads manager. Default to copy operation. Note: It is desirable to |
| 526 // allow the user to either move or copy, but this requires additional | 541 // allow the user to either move or copy, but this requires additional |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 597 [[[notification userInfo] objectForKey:kSelectionDirection] | 612 [[[notification userInfo] objectForKey:kSelectionDirection] |
| 598 unsignedIntegerValue]; | 613 unsignedIntegerValue]; |
| 599 if (direction == NSDirectSelection) | 614 if (direction == NSDirectSelection) |
| 600 return; | 615 return; |
| 601 | 616 |
| 602 [self tabContents]-> | 617 [self tabContents]-> |
| 603 FocusThroughTabTraversal(direction == NSSelectingPrevious); | 618 FocusThroughTabTraversal(direction == NSSelectingPrevious); |
| 604 } | 619 } |
| 605 | 620 |
| 606 @end | 621 @end |
| OLD | NEW |