| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/panels/panel_window_controller_cocoa.h" | 5 #include "chrome/browser/ui/panels/panel_window_controller_cocoa.h" |
| 6 | 6 |
| 7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/mac/mac_util.h" | 10 #include "base/mac/mac_util.h" |
| 11 #include "chrome/browser/tabs/tab_strip_model.h" |
| 11 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
| 12 #import "chrome/browser/ui/cocoa/find_bar/find_bar_bridge.h" | 13 #import "chrome/browser/ui/cocoa/find_bar/find_bar_bridge.h" |
| 13 #import "chrome/browser/ui/cocoa/find_bar/find_bar_cocoa_controller.h" | 14 #import "chrome/browser/ui/cocoa/find_bar/find_bar_cocoa_controller.h" |
| 14 #include "chrome/browser/ui/panels/panel.h" | 15 #include "chrome/browser/ui/panels/panel.h" |
| 15 #include "chrome/browser/ui/panels/panel_browser_window_cocoa.h" | 16 #include "chrome/browser/ui/panels/panel_browser_window_cocoa.h" |
| 16 #import "chrome/browser/ui/panels/panel_titlebar_view_cocoa.h" | 17 #import "chrome/browser/ui/panels/panel_titlebar_view_cocoa.h" |
| 17 #include "content/browser/tab_contents/tab_contents.h" | 18 #include "content/browser/tab_contents/tab_contents.h" |
| 18 | 19 |
| 19 const int kMinimumWindowSize = 1; | 20 const int kMinimumWindowSize = 1; |
| 20 | 21 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 | 90 |
| 90 - (void)addFindBar:(FindBarCocoaController*)findBarCocoaController { | 91 - (void)addFindBar:(FindBarCocoaController*)findBarCocoaController { |
| 91 NSView* contentView = [[self window] contentView]; | 92 NSView* contentView = [[self window] contentView]; |
| 92 [contentView addSubview:[findBarCocoaController view]]; | 93 [contentView addSubview:[findBarCocoaController view]]; |
| 93 | 94 |
| 94 CGFloat maxY = NSMaxY([contentView frame]); | 95 CGFloat maxY = NSMaxY([contentView frame]); |
| 95 CGFloat maxWidth = NSWidth([contentView frame]); | 96 CGFloat maxWidth = NSWidth([contentView frame]); |
| 96 [findBarCocoaController positionFindBarViewAtMaxY:maxY maxWidth:maxWidth]; | 97 [findBarCocoaController positionFindBarViewAtMaxY:maxY maxWidth:maxWidth]; |
| 97 } | 98 } |
| 98 | 99 |
| 99 - (void)closePanel { | |
| 100 windowShim_->panel()->Close(); | |
| 101 } | |
| 102 | |
| 103 - (void)windowWillClose:(NSNotification*)notification { | |
| 104 [self autorelease]; | |
| 105 } | |
| 106 | |
| 107 - (NSView*)tabContentsView { | 100 - (NSView*)tabContentsView { |
| 108 TabContents* contents = windowShim_->browser()->GetSelectedTabContents(); | 101 TabContents* contents = windowShim_->browser()->GetSelectedTabContents(); |
| 109 CHECK(contents); | 102 CHECK(contents); |
| 110 NSView* tabContentView = contents->GetNativeView(); | 103 NSView* tabContentView = contents->GetNativeView(); |
| 111 CHECK(tabContentView); | 104 CHECK(tabContentView); |
| 112 return tabContentView; | 105 return tabContentView; |
| 113 } | 106 } |
| 114 | 107 |
| 115 - (PanelTitlebarViewCocoa*)titlebarView { | 108 - (PanelTitlebarViewCocoa*)titlebarView { |
| 116 return titlebar_view_; | 109 return titlebar_view_; |
| 117 } | 110 } |
| 111 |
| 112 // Handler for the custom Close button. |
| 113 - (void)closePanel { |
| 114 windowShim_->panel()->Close(); |
| 115 } |
| 116 |
| 117 // Called when the user wants to close the panel or from the shutdown process. |
| 118 // The Browser object is in control of whether or not we're allowed to close. It |
| 119 // may defer closing due to several states, such as onbeforeUnload handlers |
| 120 // needing to be fired. If closing is deferred, the Browser will handle the |
| 121 // processing required to get us to the closing state and (by watching for |
| 122 // all the tabs going away) will again call to close the window when it's |
| 123 // finally ready. |
| 124 // This callback is only called if the standard Close button is enabled in XIB. |
| 125 - (BOOL)windowShouldClose:(id)sender { |
| 126 Browser* browser = windowShim_->browser(); |
| 127 // Give beforeunload handlers the chance to cancel the close before we hide |
| 128 // the window below. |
| 129 if (!browser->ShouldCloseWindow()) |
| 130 return NO; |
| 131 |
| 132 if (!browser->tabstrip_model()->empty()) { |
| 133 // Tab strip isn't empty. Make browser to close all the tabs, allowing the |
| 134 // renderer to shut down and call us back again. |
| 135 // The tab strip of Panel is not visible and contains only one tab but |
| 136 // it still has to be closed. |
| 137 browser->OnWindowClosing(); |
| 138 return NO; |
| 139 } |
| 140 |
| 141 // the tab strip is empty, it's ok to close the window |
| 142 return YES; |
| 143 } |
| 144 |
| 145 // When windowShouldClose returns YES (or if controller receives direct 'close' |
| 146 // signal), window will be unconditionally closed. Clean up. |
| 147 - (void)windowWillClose:(NSNotification*)notification { |
| 148 DCHECK(windowShim_->browser()->tabstrip_model()->empty()); |
| 149 |
| 150 windowShim_->didCloseNativeWindow(); |
| 151 [self autorelease]; |
| 152 } |
| 153 |
| 118 @end | 154 @end |
| OLD | NEW |