| 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) | 11 @interface PreviewableContentsController(PrivateMethods) |
| 12 // Shows or hides the "close preview" button. Adds the button to the view | 12 // Shows or hides the "close preview" button. Adds the button to the view |
| 13 // hierarchy, if needed. | 13 // hierarchy, if needed. |
| 14 - (void)showCloseButton:(BOOL)show; | 14 - (void)showCloseButton:(BOOL)show; |
| 15 @end | 15 @end |
| 16 | 16 |
| 17 @implementation PreviewableContentsController | 17 @implementation PreviewableContentsController |
| 18 | 18 |
| 19 @synthesize activeContainer = activeContainer_; | 19 @synthesize activeContainer = activeContainer_; |
| 20 | 20 |
| 21 - (id)init { | 21 - (id)init { |
| 22 if ((self = [super initWithNibName:@"PreviewableContents" | 22 if ((self = [super initWithNibName:@"PreviewableContents" |
| 23 bundle:mac_util::MainAppBundle()])) { | 23 bundle:mac_util::MainAppBundle()])) { |
| 24 } | 24 } |
| 25 return self; | 25 return self; |
| 26 } | 26 } |
| 27 | 27 |
| 28 - (void)showPreview:(TabContents*)preview { | 28 - (void)showPreview:(TabContents*)preview { |
| 29 DCHECK(preview); | 29 DCHECK(preview); |
| 30 |
| 31 // Remove any old preview contents before showing the new one. |
| 32 if (previewContents_) |
| 33 [previewContents_->GetNativeView() removeFromSuperview]; |
| 34 |
| 30 previewContents_ = preview; | 35 previewContents_ = preview; |
| 31 | |
| 32 NSView* previewView = previewContents_->GetNativeView(); | 36 NSView* previewView = previewContents_->GetNativeView(); |
| 33 [previewView setFrame:[[self view] bounds]]; | 37 [previewView setFrame:[[self view] bounds]]; |
| 34 | 38 |
| 35 // Hide the active container, add the preview contents, and show the tear | 39 // Hide the active container, add the preview contents, and show the tear |
| 36 // image. | 40 // image. |
| 37 [activeContainer_ setHidden:YES]; | 41 [activeContainer_ setHidden:YES]; |
| 38 [[self view] addSubview:previewView]; | 42 [[self view] addSubview:previewView]; |
| 39 [self showCloseButton:YES]; | 43 [self showCloseButton:YES]; |
| 40 } | 44 } |
| 41 | 45 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 // Add the close button to the upper left corner. | 80 // Add the close button to the upper left corner. |
| 77 NSView* view = [self view]; | 81 NSView* view = [self view]; |
| 78 NSRect frame = [closeButton_ frame]; | 82 NSRect frame = [closeButton_ frame]; |
| 79 frame.origin.x = NSMinX([view bounds]); | 83 frame.origin.x = NSMinX([view bounds]); |
| 80 frame.origin.y = NSMaxY([view bounds]) - NSHeight(frame); | 84 frame.origin.y = NSMaxY([view bounds]) - NSHeight(frame); |
| 81 [closeButton_ setFrame:frame]; | 85 [closeButton_ setFrame:frame]; |
| 82 [view addSubview:closeButton_]; | 86 [view addSubview:closeButton_]; |
| 83 } | 87 } |
| 84 | 88 |
| 85 @end | 89 @end |
| OLD | NEW |