| 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 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 @interface TabContentsViewCocoa (Private) | 49 @interface TabContentsViewCocoa (Private) |
| 50 - (id)initWithTabContentsViewMac:(TabContentsViewMac*)w; | 50 - (id)initWithTabContentsViewMac:(TabContentsViewMac*)w; |
| 51 - (void)registerDragTypes; | 51 - (void)registerDragTypes; |
| 52 - (void)setCurrentDragOperation:(NSDragOperation)operation; | 52 - (void)setCurrentDragOperation:(NSDragOperation)operation; |
| 53 - (void)startDragWithDropData:(const WebDropData&)dropData | 53 - (void)startDragWithDropData:(const WebDropData&)dropData |
| 54 dragOperationMask:(NSDragOperation)operationMask | 54 dragOperationMask:(NSDragOperation)operationMask |
| 55 image:(NSImage*)image | 55 image:(NSImage*)image |
| 56 offset:(NSPoint)offset; | 56 offset:(NSPoint)offset; |
| 57 - (void)cancelDeferredClose; | 57 - (void)cancelDeferredClose; |
| 58 - (void)closeTabAfterEvent; | 58 - (void)closeTabAfterEvent; |
| 59 - (void)viewDidBecomeFirstResponder:(NSNotification*)notification; |
| 59 @end | 60 @end |
| 60 | 61 |
| 61 // static | 62 // static |
| 62 TabContentsView* TabContentsView::Create(TabContents* tab_contents) { | 63 TabContentsView* TabContentsView::Create(TabContents* tab_contents) { |
| 63 return new TabContentsViewMac(tab_contents); | 64 return new TabContentsViewMac(tab_contents); |
| 64 } | 65 } |
| 65 | 66 |
| 66 TabContentsViewMac::TabContentsViewMac(TabContents* tab_contents) | 67 TabContentsViewMac::TabContentsViewMac(TabContents* tab_contents) |
| 67 : TabContentsView(tab_contents), | 68 : TabContentsView(tab_contents), |
| 68 preferred_width_(0) { | 69 preferred_width_(0) { |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 self = [super initWithFrame:NSZeroRect]; | 340 self = [super initWithFrame:NSZeroRect]; |
| 340 if (self != nil) { | 341 if (self != nil) { |
| 341 tabContentsView_ = w; | 342 tabContentsView_ = w; |
| 342 dropTarget_.reset( | 343 dropTarget_.reset( |
| 343 [[WebDropTarget alloc] initWithTabContents:[self tabContents]]); | 344 [[WebDropTarget alloc] initWithTabContents:[self tabContents]]); |
| 344 [self registerDragTypes]; | 345 [self registerDragTypes]; |
| 345 // TabContentsViewCocoa's ViewID may be changed to VIEW_ID_DEV_TOOLS_DOCKED | 346 // TabContentsViewCocoa's ViewID may be changed to VIEW_ID_DEV_TOOLS_DOCKED |
| 346 // by TabContentsController, so we can't just override -viewID method to | 347 // by TabContentsController, so we can't just override -viewID method to |
| 347 // return it. | 348 // return it. |
| 348 view_id_util::SetID(self, VIEW_ID_TAB_CONTAINER); | 349 view_id_util::SetID(self, VIEW_ID_TAB_CONTAINER); |
| 350 |
| 351 [[NSNotificationCenter defaultCenter] |
| 352 addObserver:self |
| 353 selector:@selector(viewDidBecomeFirstResponder:) |
| 354 name:kViewDidBecomeFirstResponder |
| 355 object:nil]; |
| 349 } | 356 } |
| 350 return self; | 357 return self; |
| 351 } | 358 } |
| 352 | 359 |
| 353 - (void)dealloc { | 360 - (void)dealloc { |
| 354 view_id_util::UnsetID(self); | 361 view_id_util::UnsetID(self); |
| 355 | 362 |
| 356 // Cancel any deferred tab closes, just in case. | 363 // Cancel any deferred tab closes, just in case. |
| 357 [self cancelDeferredClose]; | 364 [self cancelDeferredClose]; |
| 358 | 365 |
| 359 // This probably isn't strictly necessary, but can't hurt. | 366 // This probably isn't strictly necessary, but can't hurt. |
| 360 [self unregisterDraggedTypes]; | 367 [self unregisterDraggedTypes]; |
| 368 |
| 369 [[NSNotificationCenter defaultCenter] removeObserver:self]; |
| 370 |
| 361 [super dealloc]; | 371 [super dealloc]; |
| 362 } | 372 } |
| 363 | 373 |
| 364 // Registers for the view for the appropriate drag types. | 374 // Registers for the view for the appropriate drag types. |
| 365 - (void)registerDragTypes { | 375 - (void)registerDragTypes { |
| 366 NSArray* types = [NSArray arrayWithObjects:NSStringPboardType, | 376 NSArray* types = [NSArray arrayWithObjects:NSStringPboardType, |
| 367 NSHTMLPboardType, NSURLPboardType, nil]; | 377 NSHTMLPboardType, NSURLPboardType, nil]; |
| 368 [self registerForDraggedTypes:types]; | 378 [self registerForDraggedTypes:types]; |
| 369 } | 379 } |
| 370 | 380 |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 475 SEL aSel = @selector(closeTabAfterEvent); | 485 SEL aSel = @selector(closeTabAfterEvent); |
| 476 [NSObject cancelPreviousPerformRequestsWithTarget:self | 486 [NSObject cancelPreviousPerformRequestsWithTarget:self |
| 477 selector:aSel | 487 selector:aSel |
| 478 object:nil]; | 488 object:nil]; |
| 479 } | 489 } |
| 480 | 490 |
| 481 - (void)closeTabAfterEvent { | 491 - (void)closeTabAfterEvent { |
| 482 tabContentsView_->CloseTab(); | 492 tabContentsView_->CloseTab(); |
| 483 } | 493 } |
| 484 | 494 |
| 495 - (void)viewDidBecomeFirstResponder:(NSNotification*)notification { |
| 496 NSView* view = [notification object]; |
| 497 if (![[self subviews] containsObject:view]) |
| 498 return; |
| 499 |
| 500 NSSelectionDirection direction = |
| 501 [[[notification userInfo] objectForKey:kSelectionDirection] |
| 502 unsignedIntegerValue]; |
| 503 if (direction == NSDirectSelection) |
| 504 return; |
| 505 |
| 506 [self tabContents]-> |
| 507 FocusThroughTabTraversal(direction == NSSelectingPrevious); |
| 508 } |
| 509 |
| 485 @end | 510 @end |
| OLD | NEW |