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 #include "chrome/browser/ui/cocoa/constrained_window/constrained_window_mac2.h" | 5 #include "chrome/browser/ui/cocoa/constrained_window/constrained_window_mac2.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "chrome/browser/ui/browser_finder.h" | 8 #include "chrome/browser/ui/browser_finder.h" |
9 #include "chrome/browser/ui/browser_window.h" | 9 #include "chrome/browser/ui/browser_window.h" |
10 #include "chrome/browser/ui/cocoa/constrained_window/constrained_window_sheet_co
ntroller.h" | 10 #include "chrome/browser/ui/cocoa/constrained_window/constrained_window_sheet_co
ntroller.h" |
11 #include "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h" | 11 #include "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h" |
12 #include "chrome/browser/ui/constrained_window_tab_helper.h" | 12 #include "chrome/browser/ui/constrained_window_tab_helper.h" |
13 #include "chrome/browser/ui/tab_contents/tab_contents.h" | |
14 #include "content/public/browser/web_contents.h" | 13 #include "content/public/browser/web_contents.h" |
15 #include "content/public/browser/web_contents_view.h" | 14 #include "content/public/browser/web_contents_view.h" |
16 | 15 |
17 ConstrainedWindowMac2::ConstrainedWindowMac2( | 16 ConstrainedWindowMac2::ConstrainedWindowMac2( |
18 TabContents* tab_contents, | 17 content::WebContents* web_contents, |
19 NSWindow* window) | 18 NSWindow* window) |
20 : tab_contents_(tab_contents), | 19 : web_contents_(web_contents), |
21 window_([window retain]) { | 20 window_([window retain]) { |
22 DCHECK(tab_contents); | 21 DCHECK(web_contents); |
23 DCHECK(window_.get()); | 22 DCHECK(window_.get()); |
| 23 ConstrainedWindowTabHelper::CreateForWebContents(web_contents); |
| 24 |
24 ConstrainedWindowTabHelper* constrained_window_tab_helper = | 25 ConstrainedWindowTabHelper* constrained_window_tab_helper = |
25 ConstrainedWindowTabHelper::FromWebContents(tab_contents->web_contents()); | 26 ConstrainedWindowTabHelper::FromWebContents(web_contents); |
26 constrained_window_tab_helper->AddConstrainedDialog(this); | 27 constrained_window_tab_helper->AddConstrainedDialog(this); |
27 } | 28 } |
28 | 29 |
29 void ConstrainedWindowMac2::ShowConstrainedWindow() { | 30 void ConstrainedWindowMac2::ShowConstrainedWindow() { |
30 NSWindow* parent_window = GetParentWindow(); | 31 NSWindow* parent_window = GetParentWindow(); |
31 DCHECK(parent_window); | 32 DCHECK(parent_window); |
32 NSView* parent_view = GetSheetParentViewForTabContents(tab_contents_); | 33 NSView* parent_view = GetSheetParentViewForWebContents(web_contents_); |
33 DCHECK(parent_view); | 34 DCHECK(parent_view); |
34 | 35 |
35 ConstrainedWindowSheetController* controller = | 36 ConstrainedWindowSheetController* controller = |
36 [ConstrainedWindowSheetController | 37 [ConstrainedWindowSheetController |
37 controllerForParentWindow:parent_window]; | 38 controllerForParentWindow:parent_window]; |
38 [controller showSheet:window_ forParentView:parent_view]; | 39 [controller showSheet:window_ forParentView:parent_view]; |
39 } | 40 } |
40 | 41 |
41 void ConstrainedWindowMac2::CloseConstrainedWindow() { | 42 void ConstrainedWindowMac2::CloseConstrainedWindow() { |
42 [[ConstrainedWindowSheetController controllerForSheet:window_] | 43 [[ConstrainedWindowSheetController controllerForSheet:window_] |
43 closeSheet:window_]; | 44 closeSheet:window_]; |
44 ConstrainedWindowTabHelper* constrained_window_tab_helper = | 45 ConstrainedWindowTabHelper* constrained_window_tab_helper = |
45 ConstrainedWindowTabHelper::FromWebContents( | 46 ConstrainedWindowTabHelper::FromWebContents(web_contents_); |
46 tab_contents_->web_contents()); | |
47 constrained_window_tab_helper->WillClose(this); | 47 constrained_window_tab_helper->WillClose(this); |
48 delete this; | 48 delete this; |
49 } | 49 } |
50 | 50 |
51 void ConstrainedWindowMac2::PulseConstrainedWindow() { | 51 void ConstrainedWindowMac2::PulseConstrainedWindow() { |
52 [[ConstrainedWindowSheetController controllerForSheet:window_] | 52 [[ConstrainedWindowSheetController controllerForSheet:window_] |
53 pulseSheet:window_]; | 53 pulseSheet:window_]; |
54 } | 54 } |
55 | 55 |
56 gfx::NativeWindow ConstrainedWindowMac2::GetNativeWindow() { | 56 gfx::NativeWindow ConstrainedWindowMac2::GetNativeWindow() { |
57 return window_; | 57 return window_; |
58 } | 58 } |
59 | 59 |
60 bool ConstrainedWindowMac2::CanShowConstrainedWindow() { | 60 bool ConstrainedWindowMac2::CanShowConstrainedWindow() { |
61 Browser* browser = | 61 Browser* browser = browser::FindBrowserWithWebContents(web_contents_); |
62 browser::FindBrowserWithWebContents(tab_contents_->web_contents()); | |
63 if (!browser) | 62 if (!browser) |
64 return true; | 63 return true; |
65 return !browser->window()->IsInstantTabShowing(); | 64 return !browser->window()->IsInstantTabShowing(); |
66 } | 65 } |
67 | 66 |
68 ConstrainedWindowMac2::~ConstrainedWindowMac2() { | 67 ConstrainedWindowMac2::~ConstrainedWindowMac2() { |
69 } | 68 } |
70 | 69 |
71 NSWindow* ConstrainedWindowMac2::GetParentWindow() const { | 70 NSWindow* ConstrainedWindowMac2::GetParentWindow() const { |
72 // Tab contents in a tabbed browser may not be inside a window. For this | 71 // Tab contents in a tabbed browser may not be inside a window. For this |
73 // reason use a browser window if possible. | 72 // reason use a browser window if possible. |
74 Browser* browser = | 73 Browser* browser = browser::FindBrowserWithWebContents(web_contents_); |
75 browser::FindBrowserWithWebContents(tab_contents_->web_contents()); | |
76 if (browser) | 74 if (browser) |
77 return browser->window()->GetNativeWindow(); | 75 return browser->window()->GetNativeWindow(); |
78 | 76 |
79 return tab_contents_->web_contents()->GetView()->GetTopLevelNativeWindow(); | 77 return web_contents_->GetView()->GetTopLevelNativeWindow(); |
80 } | 78 } |
OLD | NEW |