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_mac.h" | 5 #include "chrome/browser/ui/cocoa/constrained_window/constrained_window_mac.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 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_sheet.h" | 10 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_sheet.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 content::WebContents* web_contents, | 22 content::WebContents* web_contents, |
23 id<ConstrainedWindowSheet> sheet) | 23 id<ConstrainedWindowSheet> sheet) |
24 : delegate_(delegate), | 24 : delegate_(delegate), |
25 web_contents_(web_contents), | 25 web_contents_(web_contents), |
26 sheet_([sheet retain]), | 26 sheet_([sheet retain]), |
27 pending_show_(false) { | 27 pending_show_(false) { |
28 DCHECK(web_contents); | 28 DCHECK(web_contents); |
29 DCHECK(sheet_.get()); | 29 DCHECK(sheet_.get()); |
30 ConstrainedWindowTabHelper* constrained_window_tab_helper = | 30 ConstrainedWindowTabHelper* constrained_window_tab_helper = |
31 ConstrainedWindowTabHelper::FromWebContents(web_contents); | 31 ConstrainedWindowTabHelper::FromWebContents(web_contents); |
32 constrained_window_tab_helper->AddConstrainedDialog(this); | 32 constrained_window_tab_helper->AddDialog(this); |
33 | 33 |
34 registrar_.Add(this, | 34 registrar_.Add(this, |
35 content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED, | 35 content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED, |
36 content::Source<content::WebContents>(web_contents)); | 36 content::Source<content::WebContents>(web_contents)); |
37 } | 37 } |
38 | 38 |
39 ConstrainedWindowMac::~ConstrainedWindowMac() { | 39 ConstrainedWindowMac::~ConstrainedWindowMac() { |
40 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 40 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
41 } | 41 } |
42 | 42 |
43 void ConstrainedWindowMac::ShowConstrainedWindow() { | 43 void ConstrainedWindowMac::ShowWebContentsModalDialog() { |
44 NSWindow* parent_window = GetParentWindow(); | 44 NSWindow* parent_window = GetParentWindow(); |
45 NSView* parent_view = GetSheetParentViewForWebContents(web_contents_); | 45 NSView* parent_view = GetSheetParentViewForWebContents(web_contents_); |
46 if (!parent_window || !parent_view) { | 46 if (!parent_window || !parent_view) { |
47 pending_show_ = true; | 47 pending_show_ = true; |
48 return; | 48 return; |
49 } | 49 } |
50 | 50 |
51 ConstrainedWindowSheetController* controller = | 51 ConstrainedWindowSheetController* controller = |
52 [ConstrainedWindowSheetController | 52 [ConstrainedWindowSheetController |
53 controllerForParentWindow:parent_window]; | 53 controllerForParentWindow:parent_window]; |
54 [controller showSheet:sheet_ forParentView:parent_view]; | 54 [controller showSheet:sheet_ forParentView:parent_view]; |
55 } | 55 } |
56 | 56 |
57 void ConstrainedWindowMac::CloseConstrainedWindow() { | 57 void ConstrainedWindowMac::CloseWebContentsModalDialog() { |
58 // This function may be called even if the constrained window was never shown. | 58 // This function may be called even if the constrained window was never shown. |
59 // Unset |pending_show_| to prevent the window from being reshown. | 59 // Unset |pending_show_| to prevent the window from being reshown. |
60 pending_show_ = false; | 60 pending_show_ = false; |
61 | 61 |
62 [[ConstrainedWindowSheetController controllerForSheet:sheet_] | 62 [[ConstrainedWindowSheetController controllerForSheet:sheet_] |
63 closeSheet:sheet_]; | 63 closeSheet:sheet_]; |
64 ConstrainedWindowTabHelper* constrained_window_tab_helper = | 64 ConstrainedWindowTabHelper* constrained_window_tab_helper = |
65 ConstrainedWindowTabHelper::FromWebContents(web_contents_); | 65 ConstrainedWindowTabHelper::FromWebContents(web_contents_); |
66 constrained_window_tab_helper->WillClose(this); | 66 constrained_window_tab_helper->WillClose(this); |
67 if (delegate_) | 67 if (delegate_) |
68 delegate_->OnConstrainedWindowClosed(this); | 68 delegate_->OnConstrainedWindowClosed(this); |
69 } | 69 } |
70 | 70 |
71 void ConstrainedWindowMac::PulseConstrainedWindow() { | 71 void ConstrainedWindowMac::PulseWebContentsModalDialog() { |
72 [[ConstrainedWindowSheetController controllerForSheet:sheet_] | 72 [[ConstrainedWindowSheetController controllerForSheet:sheet_] |
73 pulseSheet:sheet_]; | 73 pulseSheet:sheet_]; |
74 } | 74 } |
75 | 75 |
76 gfx::NativeWindow ConstrainedWindowMac::GetNativeWindow() { | 76 gfx::NativeWindow ConstrainedWindowMac::GetNativeWindow() { |
77 NOTREACHED(); | 77 NOTREACHED(); |
78 return nil; | 78 return nil; |
79 } | 79 } |
80 | 80 |
81 bool ConstrainedWindowMac::CanShowConstrainedWindow() { | 81 bool ConstrainedWindowMac::CanShowWebContentsModalDialog() { |
82 Browser* browser = chrome::FindBrowserWithWebContents(web_contents_); | 82 Browser* browser = chrome::FindBrowserWithWebContents(web_contents_); |
83 if (!browser) | 83 if (!browser) |
84 return true; | 84 return true; |
85 return !browser->window()->IsInstantTabShowing(); | 85 return !browser->window()->IsInstantTabShowing(); |
86 } | 86 } |
87 | 87 |
88 void ConstrainedWindowMac::Observe( | 88 void ConstrainedWindowMac::Observe( |
89 int type, | 89 int type, |
90 const content::NotificationSource& source, | 90 const content::NotificationSource& source, |
91 const content::NotificationDetails& details) { | 91 const content::NotificationDetails& details) { |
92 if (type != content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED) { | 92 if (type != content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED) { |
93 NOTREACHED(); | 93 NOTREACHED(); |
94 return; | 94 return; |
95 } | 95 } |
96 | 96 |
97 if (pending_show_) { | 97 if (pending_show_) { |
98 pending_show_ = false; | 98 pending_show_ = false; |
99 ShowConstrainedWindow(); | 99 ShowWebContentsModalDialog(); |
100 } | 100 } |
101 } | 101 } |
102 | 102 |
103 NSWindow* ConstrainedWindowMac::GetParentWindow() const { | 103 NSWindow* ConstrainedWindowMac::GetParentWindow() const { |
104 // Tab contents in a tabbed browser may not be inside a window. For this | 104 // Tab contents in a tabbed browser may not be inside a window. For this |
105 // reason use a browser window if possible. | 105 // reason use a browser window if possible. |
106 Browser* browser = chrome::FindBrowserWithWebContents(web_contents_); | 106 Browser* browser = chrome::FindBrowserWithWebContents(web_contents_); |
107 if (browser) | 107 if (browser) |
108 return browser->window()->GetNativeWindow(); | 108 return browser->window()->GetNativeWindow(); |
109 | 109 |
110 return web_contents_->GetView()->GetTopLevelNativeWindow(); | 110 return web_contents_->GetView()->GetTopLevelNativeWindow(); |
111 } | 111 } |
OLD | NEW |