| 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" |
| 11 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_sheet_con
troller.h" | 11 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_sheet_con
troller.h" |
| 12 #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h" | 12 #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h" |
| 13 #include "chrome/browser/ui/web_contents_modal_dialog_manager.h" | 13 #include "chrome/browser/ui/web_contents_modal_dialog_manager.h" |
| 14 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
| 15 #include "content/public/browser/notification_source.h" | 15 #include "content/public/browser/notification_source.h" |
| 16 #include "content/public/browser/notification_types.h" | 16 #include "content/public/browser/notification_types.h" |
| 17 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
| 18 #include "content/public/browser/web_contents_view.h" | 18 #include "content/public/browser/web_contents_view.h" |
| 19 | 19 |
| 20 ConstrainedWindowMac::ConstrainedWindowMac( | 20 ConstrainedWindowMac::ConstrainedWindowMac( |
| 21 ConstrainedWindowMacDelegate* delegate, | 21 ConstrainedWindowMacDelegate* delegate, |
| 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 dummyView_([NSView alloc]), |
| 27 pending_show_(false) { | 28 pending_show_(false) { |
| 28 DCHECK(web_contents); | 29 DCHECK(web_contents); |
| 29 DCHECK(sheet_.get()); | 30 DCHECK(sheet_.get()); |
| 30 WebContentsModalDialogManager* web_contents_modal_dialog_manager = | 31 WebContentsModalDialogManager* web_contents_modal_dialog_manager = |
| 31 WebContentsModalDialogManager::FromWebContents(web_contents); | 32 WebContentsModalDialogManager::FromWebContents(web_contents); |
| 32 web_contents_modal_dialog_manager->AddDialog(this); | 33 web_contents_modal_dialog_manager->AddDialog(this); |
| 33 | 34 |
| 34 registrar_.Add(this, | 35 registrar_.Add(this, |
| 35 content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED, | 36 content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED, |
| 36 content::Source<content::WebContents>(web_contents)); | 37 content::Source<content::WebContents>(web_contents)); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 } | 70 } |
| 70 | 71 |
| 71 void ConstrainedWindowMac::FocusWebContentsModalDialog() { | 72 void ConstrainedWindowMac::FocusWebContentsModalDialog() { |
| 72 } | 73 } |
| 73 | 74 |
| 74 void ConstrainedWindowMac::PulseWebContentsModalDialog() { | 75 void ConstrainedWindowMac::PulseWebContentsModalDialog() { |
| 75 [[ConstrainedWindowSheetController controllerForSheet:sheet_] | 76 [[ConstrainedWindowSheetController controllerForSheet:sheet_] |
| 76 pulseSheet:sheet_]; | 77 pulseSheet:sheet_]; |
| 77 } | 78 } |
| 78 | 79 |
| 79 gfx::NativeWindow ConstrainedWindowMac::GetNativeWindow() { | 80 gfx::NativeView ConstrainedWindowMac::GetNativeView() { |
| 80 NOTREACHED(); | 81 // TODO(wittman): Return a NSView that is meaningful and unique to the window, |
| 81 return nil; | 82 // and remove dummyView_. |
| 83 return dummyView_.get(); |
| 82 } | 84 } |
| 83 | 85 |
| 84 void ConstrainedWindowMac::Observe( | 86 void ConstrainedWindowMac::Observe( |
| 85 int type, | 87 int type, |
| 86 const content::NotificationSource& source, | 88 const content::NotificationSource& source, |
| 87 const content::NotificationDetails& details) { | 89 const content::NotificationDetails& details) { |
| 88 if (type != content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED) { | 90 if (type != content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED) { |
| 89 NOTREACHED(); | 91 NOTREACHED(); |
| 90 return; | 92 return; |
| 91 } | 93 } |
| 92 | 94 |
| 93 if (pending_show_) { | 95 if (pending_show_) { |
| 94 pending_show_ = false; | 96 pending_show_ = false; |
| 95 ShowWebContentsModalDialog(); | 97 ShowWebContentsModalDialog(); |
| 96 } | 98 } |
| 97 } | 99 } |
| 98 | 100 |
| 99 NSWindow* ConstrainedWindowMac::GetParentWindow() const { | 101 NSWindow* ConstrainedWindowMac::GetParentWindow() const { |
| 100 // Tab contents in a tabbed browser may not be inside a window. For this | 102 // Tab contents in a tabbed browser may not be inside a window. For this |
| 101 // reason use a browser window if possible. | 103 // reason use a browser window if possible. |
| 102 Browser* browser = chrome::FindBrowserWithWebContents(web_contents_); | 104 Browser* browser = chrome::FindBrowserWithWebContents(web_contents_); |
| 103 if (browser) | 105 if (browser) |
| 104 return browser->window()->GetNativeWindow(); | 106 return browser->window()->GetNativeWindow(); |
| 105 | 107 |
| 106 return web_contents_->GetView()->GetTopLevelNativeWindow(); | 108 return web_contents_->GetView()->GetTopLevelNativeWindow(); |
| 107 } | 109 } |
| OLD | NEW |