OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 #include "chrome/browser/cocoa/constrained_window_mac.h" | 5 #include "chrome/browser/cocoa/constrained_window_mac.h" |
6 | 6 |
7 #import "chrome/browser/cocoa/browser_window_controller.h" | 7 #import "chrome/browser/cocoa/browser_window_controller.h" |
8 #include "chrome/browser/tab_contents/tab_contents.h" | 8 #include "chrome/browser/tab_contents/tab_contents.h" |
9 #include "chrome/browser/tab_contents/tab_contents_view.h" | 9 #include "chrome/browser/tab_contents/tab_contents_view.h" |
10 #import "third_party/GTM/AppKit/GTMWindowSheetController.h" | 10 #import "third_party/GTM/AppKit/GTMWindowSheetController.h" |
(...skipping 28 matching lines...) Expand all Loading... |
39 ConstrainedWindow* ConstrainedWindow::CreateConstrainedDialog( | 39 ConstrainedWindow* ConstrainedWindow::CreateConstrainedDialog( |
40 TabContents* parent, | 40 TabContents* parent, |
41 ConstrainedWindowMacDelegate* delegate) { | 41 ConstrainedWindowMacDelegate* delegate) { |
42 return new ConstrainedWindowMac(parent, delegate); | 42 return new ConstrainedWindowMac(parent, delegate); |
43 } | 43 } |
44 | 44 |
45 ConstrainedWindowMac::ConstrainedWindowMac( | 45 ConstrainedWindowMac::ConstrainedWindowMac( |
46 TabContents* owner, ConstrainedWindowMacDelegate* delegate) | 46 TabContents* owner, ConstrainedWindowMacDelegate* delegate) |
47 : owner_(owner), | 47 : owner_(owner), |
48 delegate_(delegate), | 48 delegate_(delegate), |
49 controller_(nil) { | 49 controller_(nil), |
| 50 should_be_visible_(false) { |
50 DCHECK(owner); | 51 DCHECK(owner); |
51 DCHECK(delegate); | 52 DCHECK(delegate); |
| 53 } |
| 54 |
| 55 ConstrainedWindowMac::~ConstrainedWindowMac() {} |
| 56 |
| 57 void ConstrainedWindowMac::ShowConstrainedWindow() { |
| 58 should_be_visible_ = true; |
52 | 59 |
53 // The TabContents only has a native window if it is currently visible. In | 60 // The TabContents only has a native window if it is currently visible. In |
54 // this case, open the sheet now. Else, Realize() will be called later, when | 61 // this case, open the sheet now. Else, Realize() will be called later, when |
55 // our tab becomes visible. | 62 // our tab becomes visible. |
56 NSWindow* browserWindow = owner_->view()->GetTopLevelNativeWindow(); | 63 NSWindow* browserWindow = owner_->view()->GetTopLevelNativeWindow(); |
57 NSWindowController* controller = [browserWindow windowController]; | 64 NSWindowController* controller = [browserWindow windowController]; |
58 if (controller != nil) { | 65 if (controller != nil) { |
59 DCHECK([controller isKindOfClass:[BrowserWindowController class]]); | 66 DCHECK([controller isKindOfClass:[BrowserWindowController class]]); |
60 Realize(static_cast<BrowserWindowController*>(controller)); | 67 Realize(static_cast<BrowserWindowController*>(controller)); |
61 } | 68 } |
62 } | 69 } |
63 | 70 |
64 ConstrainedWindowMac::~ConstrainedWindowMac() {} | |
65 | |
66 void ConstrainedWindowMac::CloseConstrainedWindow() { | 71 void ConstrainedWindowMac::CloseConstrainedWindow() { |
67 // Note: controller_ can be `nil` here if the sheet was never realized. That's | 72 // Note: controller_ can be `nil` here if the sheet was never realized. That's |
68 // ok. | 73 // ok. |
69 [controller_ removeConstrainedWindow:this]; | 74 [controller_ removeConstrainedWindow:this]; |
70 delegate_->DeleteDelegate(); | 75 delegate_->DeleteDelegate(); |
71 owner_->WillClose(this); | 76 owner_->WillClose(this); |
72 | 77 |
73 delete this; | 78 delete this; |
74 } | 79 } |
75 | 80 |
76 void ConstrainedWindowMac::Realize(BrowserWindowController* controller) { | 81 void ConstrainedWindowMac::Realize(BrowserWindowController* controller) { |
| 82 if (!should_be_visible_) |
| 83 return; |
| 84 |
77 if (controller_ != nil) { | 85 if (controller_ != nil) { |
78 DCHECK(controller_ == controller); | 86 DCHECK(controller_ == controller); |
79 return; | 87 return; |
80 } | 88 } |
81 DCHECK(controller != nil); | 89 DCHECK(controller != nil); |
82 | 90 |
83 // Remember the controller we're adding ourselves to, so that we can later | 91 // Remember the controller we're adding ourselves to, so that we can later |
84 // remove us from it. | 92 // remove us from it. |
85 controller_ = controller; | 93 controller_ = controller; |
86 [controller_ attachConstrainedWindow:this]; | 94 [controller_ attachConstrainedWindow:this]; |
87 delegate_->set_sheet_open(true); | 95 delegate_->set_sheet_open(true); |
88 } | 96 } |
OLD | NEW |