Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1008)

Side by Side Diff: chrome/browser/ui/panels/panel_window_controller_cocoa.mm

Issue 7694014: Reland: Implement correct Panel closing sequence for Mac. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed random result of CreateClose unittest caused by using a freed object. Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/panels/panel_browsertest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/app/chrome_command_ids.h" // IDC_* 11 #include "chrome/app/chrome_command_ids.h" // IDC_*
12 #include "chrome/browser/tabs/tab_strip_model.h"
12 #include "chrome/browser/ui/browser.h" 13 #include "chrome/browser/ui/browser.h"
13 #import "chrome/browser/ui/cocoa/event_utils.h" 14 #import "chrome/browser/ui/cocoa/event_utils.h"
14 #import "chrome/browser/ui/cocoa/find_bar/find_bar_bridge.h" 15 #import "chrome/browser/ui/cocoa/find_bar/find_bar_bridge.h"
15 #import "chrome/browser/ui/cocoa/find_bar/find_bar_cocoa_controller.h" 16 #import "chrome/browser/ui/cocoa/find_bar/find_bar_cocoa_controller.h"
16 #include "chrome/browser/ui/panels/panel.h" 17 #include "chrome/browser/ui/panels/panel.h"
17 #include "chrome/browser/ui/panels/panel_browser_window_cocoa.h" 18 #include "chrome/browser/ui/panels/panel_browser_window_cocoa.h"
18 #import "chrome/browser/ui/panels/panel_titlebar_view_cocoa.h" 19 #import "chrome/browser/ui/panels/panel_titlebar_view_cocoa.h"
19 #include "chrome/browser/ui/toolbar/encoding_menu_controller.h" 20 #include "chrome/browser/ui/toolbar/encoding_menu_controller.h"
20 #include "content/browser/tab_contents/tab_contents.h" 21 #include "content/browser/tab_contents/tab_contents.h"
21 22
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 93
93 - (void)addFindBar:(FindBarCocoaController*)findBarCocoaController { 94 - (void)addFindBar:(FindBarCocoaController*)findBarCocoaController {
94 NSView* contentView = [[self window] contentView]; 95 NSView* contentView = [[self window] contentView];
95 [contentView addSubview:[findBarCocoaController view]]; 96 [contentView addSubview:[findBarCocoaController view]];
96 97
97 CGFloat maxY = NSMaxY([contentView frame]); 98 CGFloat maxY = NSMaxY([contentView frame]);
98 CGFloat maxWidth = NSWidth([contentView frame]); 99 CGFloat maxWidth = NSWidth([contentView frame]);
99 [findBarCocoaController positionFindBarViewAtMaxY:maxY maxWidth:maxWidth]; 100 [findBarCocoaController positionFindBarViewAtMaxY:maxY maxWidth:maxWidth];
100 } 101 }
101 102
102 - (void)closePanel {
103 windowShim_->panel()->Close();
104 }
105
106 - (void)windowWillClose:(NSNotification*)notification {
107 [self autorelease];
108 }
109
110 - (NSView*)tabContentsView { 103 - (NSView*)tabContentsView {
111 TabContents* contents = windowShim_->browser()->GetSelectedTabContents(); 104 TabContents* contents = windowShim_->browser()->GetSelectedTabContents();
112 CHECK(contents); 105 CHECK(contents);
113 NSView* tabContentView = contents->GetNativeView(); 106 NSView* tabContentView = contents->GetNativeView();
114 CHECK(tabContentView); 107 CHECK(tabContentView);
115 return tabContentView; 108 return tabContentView;
116 } 109 }
117 110
118 - (PanelTitlebarViewCocoa*)titlebarView { 111 - (PanelTitlebarViewCocoa*)titlebarView {
119 return titlebar_view_; 112 return titlebar_view_;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 // determined by the key flags. 162 // determined by the key flags.
170 - (void)commandDispatchUsingKeyModifiers:(id)sender { 163 - (void)commandDispatchUsingKeyModifiers:(id)sender {
171 DCHECK(sender); 164 DCHECK(sender);
172 NSEvent* event = [NSApp currentEvent]; 165 NSEvent* event = [NSApp currentEvent];
173 WindowOpenDisposition disposition = 166 WindowOpenDisposition disposition =
174 event_utils::WindowOpenDispositionFromNSEventWithFlags( 167 event_utils::WindowOpenDispositionFromNSEventWithFlags(
175 event, [event modifierFlags]); 168 event, [event modifierFlags]);
176 windowShim_->browser()->ExecuteCommandWithDisposition( 169 windowShim_->browser()->ExecuteCommandWithDisposition(
177 [sender tag], disposition); 170 [sender tag], disposition);
178 } 171 }
172
173 // Handler for the custom Close button.
174 - (void)closePanel {
175 windowShim_->panel()->Close();
176 }
177
178 // Called when the user wants to close the panel or from the shutdown process.
179 // The Browser object is in control of whether or not we're allowed to close. It
180 // may defer closing due to several states, such as onbeforeUnload handlers
181 // needing to be fired. If closing is deferred, the Browser will handle the
182 // processing required to get us to the closing state and (by watching for
183 // all the tabs going away) will again call to close the window when it's
184 // finally ready.
185 // This callback is only called if the standard Close button is enabled in XIB.
186 - (BOOL)windowShouldClose:(id)sender {
187 Browser* browser = windowShim_->browser();
188 // Give beforeunload handlers the chance to cancel the close before we hide
189 // the window below.
190 if (!browser->ShouldCloseWindow())
191 return NO;
192
193 if (!browser->tabstrip_model()->empty()) {
194 // Tab strip isn't empty. Make browser to close all the tabs, allowing the
195 // renderer to shut down and call us back again.
196 // The tab strip of Panel is not visible and contains only one tab but
197 // it still has to be closed.
198 browser->OnWindowClosing();
199 return NO;
200 }
201
202 // the tab strip is empty, it's ok to close the window
203 return YES;
204 }
205
206 // When windowShouldClose returns YES (or if controller receives direct 'close'
207 // signal), window will be unconditionally closed. Clean up.
208 - (void)windowWillClose:(NSNotification*)notification {
209 DCHECK(windowShim_->browser()->tabstrip_model()->empty());
210
211 windowShim_->didCloseNativeWindow();
212 [self autorelease];
213 }
214
179 @end 215 @end
OLDNEW
« no previous file with comments | « chrome/browser/ui/panels/panel_browsertest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698