| 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 "chrome/browser/cocoa/previewable_contents_controller.h" | 5 #import "chrome/browser/cocoa/previewable_contents_controller.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/mac_util.h" | 8 #include "base/mac_util.h" |
| 9 #include "chrome/browser/tab_contents/tab_contents.h" | 9 #include "chrome/browser/tab_contents/tab_contents.h" |
| 10 | 10 |
| 11 @interface PreviewableContentsController(PrivateMethods) | |
| 12 // Shows or hides the "close preview" button. Adds the button to the view | |
| 13 // hierarchy, if needed. | |
| 14 - (void)showCloseButton:(BOOL)show; | |
| 15 @end | |
| 16 | |
| 17 @implementation PreviewableContentsController | 11 @implementation PreviewableContentsController |
| 18 | 12 |
| 19 @synthesize activeContainer = activeContainer_; | 13 @synthesize activeContainer = activeContainer_; |
| 20 | 14 |
| 21 - (id)init { | 15 - (id)init { |
| 22 if ((self = [super initWithNibName:@"PreviewableContents" | 16 if ((self = [super initWithNibName:@"PreviewableContents" |
| 23 bundle:mac_util::MainAppBundle()])) { | 17 bundle:mac_util::MainAppBundle()])) { |
| 24 } | 18 } |
| 25 return self; | 19 return self; |
| 26 } | 20 } |
| 27 | 21 |
| 28 - (void)showPreview:(TabContents*)preview { | 22 - (void)showPreview:(TabContents*)preview { |
| 29 DCHECK(preview); | 23 DCHECK(preview); |
| 30 | 24 |
| 31 // Remove any old preview contents before showing the new one. | 25 // Remove any old preview contents before showing the new one. |
| 32 if (previewContents_) | 26 if (previewContents_) |
| 33 [previewContents_->GetNativeView() removeFromSuperview]; | 27 [previewContents_->GetNativeView() removeFromSuperview]; |
| 34 | 28 |
| 35 previewContents_ = preview; | 29 previewContents_ = preview; |
| 36 NSView* previewView = previewContents_->GetNativeView(); | 30 NSView* previewView = previewContents_->GetNativeView(); |
| 37 [previewView setFrame:[[self view] bounds]]; | 31 [previewView setFrame:[[self view] bounds]]; |
| 38 | 32 |
| 39 // Hide the active container, add the preview contents, and show the tear | 33 // Hide the active container and add the preview contents. |
| 40 // image. | |
| 41 [activeContainer_ setHidden:YES]; | 34 [activeContainer_ setHidden:YES]; |
| 42 [[self view] addSubview:previewView]; | 35 [[self view] addSubview:previewView]; |
| 43 [self showCloseButton:YES]; | |
| 44 } | 36 } |
| 45 | 37 |
| 46 - (void)hidePreview { | 38 - (void)hidePreview { |
| 47 DCHECK(previewContents_); | 39 DCHECK(previewContents_); |
| 48 | 40 |
| 49 // Remove the preview contents, hide the tear image, and reshow the active | 41 // Remove the preview contents and reshow the active container. |
| 50 // container. | |
| 51 [self showCloseButton:NO]; | |
| 52 [previewContents_->GetNativeView() removeFromSuperview]; | 42 [previewContents_->GetNativeView() removeFromSuperview]; |
| 53 [activeContainer_ setHidden:NO]; | 43 [activeContainer_ setHidden:NO]; |
| 54 | 44 |
| 55 previewContents_ = nil; | 45 previewContents_ = nil; |
| 56 } | 46 } |
| 57 | 47 |
| 58 - (IBAction)closePreview:(id)sender { | |
| 59 // Hiding right now leads to crashes. | |
| 60 // TODO(rohitrao): Actually hide the preview. | |
| 61 } | |
| 62 | |
| 63 - (BOOL)isShowingPreview { | 48 - (BOOL)isShowingPreview { |
| 64 return previewContents_ != nil; | 49 return previewContents_ != nil; |
| 65 } | 50 } |
| 66 | 51 |
| 67 @end | 52 @end |
| 68 | |
| 69 @implementation PreviewableContentsController(PrivateMethods) | |
| 70 | |
| 71 - (void)showCloseButton:(BOOL)show { | |
| 72 if (!show) { | |
| 73 [closeButton_ removeFromSuperview]; | |
| 74 return; | |
| 75 } | |
| 76 | |
| 77 if ([closeButton_ superview]) | |
| 78 return; // Already in the view hierarchy. | |
| 79 | |
| 80 // Add the close button to the upper left corner. | |
| 81 NSView* view = [self view]; | |
| 82 NSRect frame = [closeButton_ frame]; | |
| 83 frame.origin.x = NSMinX([view bounds]); | |
| 84 frame.origin.y = NSMaxY([view bounds]) - NSHeight(frame); | |
| 85 [closeButton_ setFrame:frame]; | |
| 86 [view addSubview:closeButton_]; | |
| 87 } | |
| 88 | |
| 89 @end | |
| OLD | NEW |