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

Side by Side Diff: chrome/browser/cocoa/browser_window_controller.mm

Issue 119363: Add a stack-based class for property disabling and re-enabling screen updatin... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 6 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
« base/base.gyp ('K') | « base/scoped_nsdisable_screen_updates.h ('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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 "base/mac_util.h" 5 #include "base/mac_util.h"
6 #include "base/scoped_nsdisable_screen_updates.h"
6 #include "base/sys_string_conversions.h" 7 #include "base/sys_string_conversions.h"
7 #include "chrome/app/chrome_dll_resource.h" // IDC_* 8 #include "chrome/app/chrome_dll_resource.h" // IDC_*
8 #include "chrome/browser/browser.h" 9 #include "chrome/browser/browser.h"
9 #include "chrome/browser/browser_list.h" 10 #include "chrome/browser/browser_list.h"
10 #include "chrome/browser/browser_process.h" 11 #include "chrome/browser/browser_process.h"
11 #include "chrome/browser/encoding_menu_controller.h" 12 #include "chrome/browser/encoding_menu_controller.h"
12 #include "chrome/browser/tab_contents/tab_contents.h" 13 #include "chrome/browser/tab_contents/tab_contents.h"
13 #include "chrome/browser/tab_contents/tab_contents_view.h" 14 #include "chrome/browser/tab_contents/tab_contents_view.h"
14 #include "chrome/browser/tabs/tab_strip_model.h" 15 #include "chrome/browser/tabs/tab_strip_model.h"
15 #import "chrome/browser/cocoa/bookmark_bar_controller.h" 16 #import "chrome/browser/cocoa/bookmark_bar_controller.h"
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 } 187 }
187 188
188 // Called when the user wants to close a window or from the shutdown process. 189 // Called when the user wants to close a window or from the shutdown process.
189 // The Browser object is in control of whether or not we're allowed to close. It 190 // The Browser object is in control of whether or not we're allowed to close. It
190 // may defer closing due to several states, such as onUnload handlers needing to 191 // may defer closing due to several states, such as onUnload handlers needing to
191 // be fired. If closing is deferred, the Browser will handle the processing 192 // be fired. If closing is deferred, the Browser will handle the processing
192 // required to get us to the closing state and (by watching for all the tabs 193 // required to get us to the closing state and (by watching for all the tabs
193 // going away) will again call to close the window when it's finally ready. 194 // going away) will again call to close the window when it's finally ready.
194 - (BOOL)windowShouldClose:(id)sender { 195 - (BOOL)windowShouldClose:(id)sender {
195 // Disable updates while closing all tabs to avoid flickering. 196 // Disable updates while closing all tabs to avoid flickering.
196 NSDisableScreenUpdates(); 197 base::ScopedNSDisableScreenUpdates disabler;
197 // Give beforeunload handlers the chance to cancel the close before we hide 198 // Give beforeunload handlers the chance to cancel the close before we hide
198 // the window below. 199 // the window below.
199 if (!browser_->ShouldCloseWindow()) 200 if (!browser_->ShouldCloseWindow())
200 return NO; 201 return NO;
201 202
202 // saveWindowPositionIfNeeded: only works if we are the last active 203 // saveWindowPositionIfNeeded: only works if we are the last active
203 // window, but orderOut: ends up activating another window, so we 204 // window, but orderOut: ends up activating another window, so we
204 // have to save the window position before we call orderOut:. 205 // have to save the window position before we call orderOut:.
205 [self saveWindowPositionIfNeeded]; 206 [self saveWindowPositionIfNeeded];
206 207
207 if (!browser_->tabstrip_model()->empty()) { 208 if (!browser_->tabstrip_model()->empty()) {
208 // Tab strip isn't empty. Hide the frame (so it appears to have closed 209 // Tab strip isn't empty. Hide the frame (so it appears to have closed
209 // immediately) and close all the tabs, allowing the renderers to shut 210 // immediately) and close all the tabs, allowing the renderers to shut
210 // down. When the tab strip is empty we'll be called back again. 211 // down. When the tab strip is empty we'll be called back again.
211 [[self window] orderOut:self]; 212 [[self window] orderOut:self];
212 browser_->OnWindowClosing(); 213 browser_->OnWindowClosing();
213 return NO; 214 return NO;
214 } 215 }
215 NSEnableScreenUpdates();
216 216
217 // the tab strip is empty, it's ok to close the window 217 // the tab strip is empty, it's ok to close the window
218 return YES; 218 return YES;
219 } 219 }
220 220
221 // Called right after our window became the main window. 221 // Called right after our window became the main window.
222 - (void)windowDidBecomeMain:(NSNotification *)notification { 222 - (void)windowDidBecomeMain:(NSNotification *)notification {
223 BrowserList::SetLastActive(browser_.get()); 223 BrowserList::SetLastActive(browser_.get());
224 [self saveWindowPositionIfNeeded]; 224 [self saveWindowPositionIfNeeded];
225 } 225 }
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 - (void)focusLocationBar { 455 - (void)focusLocationBar {
456 [toolbarController_ focusLocationBar]; 456 [toolbarController_ focusLocationBar];
457 } 457 }
458 458
459 - (void)layoutTabs { 459 - (void)layoutTabs {
460 [tabStripController_ layoutTabs]; 460 [tabStripController_ layoutTabs];
461 } 461 }
462 462
463 - (TabWindowController*)detachTabToNewWindow:(TabView*)tabView { 463 - (TabWindowController*)detachTabToNewWindow:(TabView*)tabView {
464 // Disable screen updates so that this appears as a single visual change. 464 // Disable screen updates so that this appears as a single visual change.
465 NSDisableScreenUpdates(); 465 base::ScopedNSDisableScreenUpdates disabler;
466 466
467 // Fetch the tab contents for the tab being dragged 467 // Fetch the tab contents for the tab being dragged
468 int index = [tabStripController_ indexForTabView:tabView]; 468 int index = [tabStripController_ indexForTabView:tabView];
469 TabContents* contents = browser_->tabstrip_model()->GetTabContentsAt(index); 469 TabContents* contents = browser_->tabstrip_model()->GetTabContentsAt(index);
470 470
471 // Set the window size. Need to do this before we detach the tab so it's 471 // Set the window size. Need to do this before we detach the tab so it's
472 // still in the window. We have to flip the coordinates as that's what 472 // still in the window. We have to flip the coordinates as that's what
473 // is expected by the Browser code. 473 // is expected by the Browser code.
474 NSWindow* sourceWindow = [tabView window]; 474 NSWindow* sourceWindow = [tabView window];
475 NSRect windowRect = [sourceWindow frame]; 475 NSRect windowRect = [sourceWindow frame];
(...skipping 24 matching lines...) Expand all
500 BrowserWindowController* controller = 500 BrowserWindowController* controller =
501 [newBrowser->window()->GetNativeHandle() delegate]; 501 [newBrowser->window()->GetNativeHandle() delegate];
502 DCHECK(controller && [controller isKindOfClass:[TabWindowController class]]); 502 DCHECK(controller && [controller isKindOfClass:[TabWindowController class]]);
503 503
504 // Force the added tab to the right size (remove stretching.) 504 // Force the added tab to the right size (remove stretching.)
505 tabRect.size.height = [TabStripController defaultTabHeight]; 505 tabRect.size.height = [TabStripController defaultTabHeight];
506 506
507 // And make sure we use the correct frame in the new view. 507 // And make sure we use the correct frame in the new view.
508 [[controller tabStripController] setFrameOfSelectedTab:tabRect]; 508 [[controller tabStripController] setFrameOfSelectedTab:tabRect];
509 509
510 NSEnableScreenUpdates();
511 return controller; 510 return controller;
512 } 511 }
513 512
514 513
515 - (void)insertPlaceholderForTab:(TabView*)tab 514 - (void)insertPlaceholderForTab:(TabView*)tab
516 frame:(NSRect)frame 515 frame:(NSRect)frame
517 yStretchiness:(CGFloat)yStretchiness { 516 yStretchiness:(CGFloat)yStretchiness {
518 [tabStripController_ insertPlaceholderForTab:tab 517 [tabStripController_ insertPlaceholderForTab:tab
519 frame:frame 518 frame:frame
520 yStretchiness:yStretchiness]; 519 yStretchiness:yStretchiness];
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
724 else if ([event deltaY] < -0.5) 723 else if ([event deltaY] < -0.5)
725 ; // TODO(pinkerton): figure out page-down 724 ; // TODO(pinkerton): figure out page-down
726 725
727 // Ensure the command is valid first (ExecuteCommand() won't do that) and 726 // Ensure the command is valid first (ExecuteCommand() won't do that) and
728 // then make it so. 727 // then make it so.
729 if (browser_->command_updater()->IsCommandEnabled(command)) 728 if (browser_->command_updater()->IsCommandEnabled(command))
730 browser_->ExecuteCommand(command); 729 browser_->ExecuteCommand(command);
731 } 730 }
732 731
733 @end 732 @end
OLDNEW
« base/base.gyp ('K') | « base/scoped_nsdisable_screen_updates.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698