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