OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/ui/cocoa/constrained_window/constrained_window_controlle
r.h" | 5 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_controlle
r.h" |
6 | 6 |
7 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_wi
ndow.h" | 7 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_wi
ndow.h" |
8 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_mac2.h" | 8 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_mac2.h" |
9 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_sheet_con
troller.h" | 9 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_sheet_con
troller.h" |
10 #include "chrome/browser/ui/tab_contents/tab_contents.h" | |
11 | 10 |
12 @interface ConstrainedWindowController () | 11 @interface ConstrainedWindowController () |
13 - (void)onEmbeddedViewFrameDidChange:(NSNotification*)note; | 12 - (void)onEmbeddedViewFrameDidChange:(NSNotification*)note; |
14 @end | 13 @end |
15 | 14 |
16 @implementation ConstrainedWindowController | 15 @implementation ConstrainedWindowController |
17 | 16 |
18 - (id)initWithParentWebContents:(content::WebContents*)parentWebContents | 17 - (id)initWithParentWebContents:(content::WebContents*)parentWebContents |
19 embeddedView:(NSView*)embeddedView { | 18 embeddedView:(NSView*)embeddedView { |
20 scoped_nsobject<NSWindow> window([[ConstrainedWindowCustomWindow alloc] | 19 scoped_nsobject<NSWindow> window([[ConstrainedWindowCustomWindow alloc] |
21 initWithContentRect:[embeddedView bounds]]); | 20 initWithContentRect:[embeddedView bounds]]); |
22 if ((self = [super initWithWindow:window])) { | 21 if ((self = [super initWithWindow:window])) { |
23 embeddedView_.reset([embeddedView retain]); | 22 embeddedView_.reset([embeddedView retain]); |
24 [[window contentView] addSubview:embeddedView]; | 23 [[window contentView] addSubview:embeddedView]; |
25 | 24 |
26 [embeddedView setPostsFrameChangedNotifications:YES]; | 25 [embeddedView setPostsFrameChangedNotifications:YES]; |
27 [[NSNotificationCenter defaultCenter] | 26 [[NSNotificationCenter defaultCenter] |
28 addObserver:self | 27 addObserver:self |
29 selector:@selector(onEmbeddedViewFrameDidChange:) | 28 selector:@selector(onEmbeddedViewFrameDidChange:) |
30 name:NSViewFrameDidChangeNotification | 29 name:NSViewFrameDidChangeNotification |
31 object:embeddedView]; | 30 object:embeddedView]; |
32 | 31 |
33 constrainedWindow_ = new ConstrainedWindowMac2( | 32 constrainedWindow_ = new ConstrainedWindowMac2(parentWebContents, window); |
34 TabContents::FromWebContents(parentWebContents), window); | |
35 } | 33 } |
36 return self; | 34 return self; |
37 } | 35 } |
38 | 36 |
39 - (void)dealloc { | 37 - (void)dealloc { |
40 [[NSNotificationCenter defaultCenter] removeObserver:self]; | 38 [[NSNotificationCenter defaultCenter] removeObserver:self]; |
41 [super dealloc]; | 39 [super dealloc]; |
42 } | 40 } |
43 | 41 |
44 - (void)close { | 42 - (void)close { |
45 if (constrainedWindow_) { | 43 if (constrainedWindow_) { |
46 constrainedWindow_->CloseConstrainedWindow(); | 44 constrainedWindow_->CloseConstrainedWindow(); |
47 constrainedWindow_ = NULL; | 45 constrainedWindow_ = NULL; |
48 } | 46 } |
49 } | 47 } |
50 | 48 |
51 - (void)onEmbeddedViewFrameDidChange:(NSNotification*)note { | 49 - (void)onEmbeddedViewFrameDidChange:(NSNotification*)note { |
52 NSSize newSize = [embeddedView_ frame].size; | 50 NSSize newSize = [embeddedView_ frame].size; |
53 [[ConstrainedWindowSheetController controllerForSheet:[self window]] | 51 [[ConstrainedWindowSheetController controllerForSheet:[self window]] |
54 setSheet:[self window] | 52 setSheet:[self window] |
55 windowSize:newSize]; | 53 windowSize:newSize]; |
56 } | 54 } |
57 | 55 |
58 @end | 56 @end |
OLD | NEW |