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

Side by Side Diff: chrome/browser/ui/cocoa/confirm_quit_panel_controller.mm

Issue 1865213004: Convert //chrome/browser/ui from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 8 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
OLDNEW
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 #import <Cocoa/Cocoa.h> 5 #import <Cocoa/Cocoa.h>
6 #import <QuartzCore/QuartzCore.h> 6 #import <QuartzCore/QuartzCore.h>
7 7
8 #import "chrome/browser/ui/cocoa/confirm_quit_panel_controller.h" 8 #import "chrome/browser/ui/cocoa/confirm_quit_panel_controller.h"
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 @end 168 @end
169 169
170 // Private Interface /////////////////////////////////////////////////////////// 170 // Private Interface ///////////////////////////////////////////////////////////
171 171
172 @interface ConfirmQuitPanelController (Private) 172 @interface ConfirmQuitPanelController (Private)
173 - (void)animateFadeOut; 173 - (void)animateFadeOut;
174 - (NSEvent*)pumpEventQueueForKeyUp:(NSApplication*)app untilDate:(NSDate*)date; 174 - (NSEvent*)pumpEventQueueForKeyUp:(NSApplication*)app untilDate:(NSDate*)date;
175 - (void)hideAllWindowsForApplication:(NSApplication*)app 175 - (void)hideAllWindowsForApplication:(NSApplication*)app
176 withDuration:(NSTimeInterval)duration; 176 withDuration:(NSTimeInterval)duration;
177 // Returns the Accelerator for the Quit menu item. 177 // Returns the Accelerator for the Quit menu item.
178 + (scoped_ptr<ui::PlatformAcceleratorCocoa>)quitAccelerator; 178 + (std::unique_ptr<ui::PlatformAcceleratorCocoa>)quitAccelerator;
179 @end 179 @end
180 180
181 ConfirmQuitPanelController* g_confirmQuitPanelController = nil; 181 ConfirmQuitPanelController* g_confirmQuitPanelController = nil;
182 182
183 //////////////////////////////////////////////////////////////////////////////// 183 ////////////////////////////////////////////////////////////////////////////////
184 184
185 @implementation ConfirmQuitPanelController 185 @implementation ConfirmQuitPanelController
186 186
187 + (ConfirmQuitPanelController*)sharedController { 187 + (ConfirmQuitPanelController*)sharedController {
188 if (!g_confirmQuitPanelController) { 188 if (!g_confirmQuitPanelController) {
(...skipping 30 matching lines...) Expand all
219 } 219 }
220 return self; 220 return self;
221 } 221 }
222 222
223 + (BOOL)eventTriggersFeature:(NSEvent*)event { 223 + (BOOL)eventTriggersFeature:(NSEvent*)event {
224 if ([event type] != NSKeyDown) 224 if ([event type] != NSKeyDown)
225 return NO; 225 return NO;
226 ui::PlatformAcceleratorCocoa eventAccelerator( 226 ui::PlatformAcceleratorCocoa eventAccelerator(
227 [event charactersIgnoringModifiers], 227 [event charactersIgnoringModifiers],
228 [event modifierFlags] & NSDeviceIndependentModifierFlagsMask); 228 [event modifierFlags] & NSDeviceIndependentModifierFlagsMask);
229 scoped_ptr<ui::PlatformAcceleratorCocoa> quitAccelerator( 229 std::unique_ptr<ui::PlatformAcceleratorCocoa> quitAccelerator(
230 [self quitAccelerator]); 230 [self quitAccelerator]);
231 return quitAccelerator->Equals(eventAccelerator); 231 return quitAccelerator->Equals(eventAccelerator);
232 } 232 }
233 233
234 - (NSApplicationTerminateReply)runModalLoopForApplication:(NSApplication*)app { 234 - (NSApplicationTerminateReply)runModalLoopForApplication:(NSApplication*)app {
235 base::scoped_nsobject<ConfirmQuitPanelController> keepAlive([self retain]); 235 base::scoped_nsobject<ConfirmQuitPanelController> keepAlive([self retain]);
236 236
237 // If this is the second of two such attempts to quit within a certain time 237 // If this is the second of two such attempts to quit within a certain time
238 // interval, then just quit. 238 // interval, then just quit.
239 // Time of last quit attempt, if any. 239 // Time of last quit attempt, if any.
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 } 356 }
357 357
358 - (void)animationDidStop:(CAAnimation*)theAnimation finished:(BOOL)finished { 358 - (void)animationDidStop:(CAAnimation*)theAnimation finished:(BOOL)finished {
359 [self close]; 359 [self close];
360 } 360 }
361 361
362 // This looks at the Main Menu and determines what the user has set as the 362 // This looks at the Main Menu and determines what the user has set as the
363 // key combination for quit. It then gets the modifiers and builds a string 363 // key combination for quit. It then gets the modifiers and builds a string
364 // to display them. 364 // to display them.
365 + (NSString*)keyCommandString { 365 + (NSString*)keyCommandString {
366 scoped_ptr<ui::PlatformAcceleratorCocoa> accelerator([self quitAccelerator]); 366 std::unique_ptr<ui::PlatformAcceleratorCocoa> accelerator(
367 [self quitAccelerator]);
367 return [[self class] keyCombinationForAccelerator:*accelerator]; 368 return [[self class] keyCombinationForAccelerator:*accelerator];
368 } 369 }
369 370
370 // Runs a nested loop that pumps the event queue until the next KeyUp event. 371 // Runs a nested loop that pumps the event queue until the next KeyUp event.
371 - (NSEvent*)pumpEventQueueForKeyUp:(NSApplication*)app untilDate:(NSDate*)date { 372 - (NSEvent*)pumpEventQueueForKeyUp:(NSApplication*)app untilDate:(NSDate*)date {
372 return [app nextEventMatchingMask:NSKeyUpMask 373 return [app nextEventMatchingMask:NSKeyUpMask
373 untilDate:date 374 untilDate:date
374 inMode:NSEventTrackingRunLoopMode 375 inMode:NSEventTrackingRunLoopMode
375 dequeue:YES]; 376 dequeue:YES];
376 } 377 }
377 378
378 // Iterates through the list of open windows and hides them all. 379 // Iterates through the list of open windows and hides them all.
379 - (void)hideAllWindowsForApplication:(NSApplication*)app 380 - (void)hideAllWindowsForApplication:(NSApplication*)app
380 withDuration:(NSTimeInterval)duration { 381 withDuration:(NSTimeInterval)duration {
381 FadeAllWindowsAnimation* animation = 382 FadeAllWindowsAnimation* animation =
382 [[FadeAllWindowsAnimation alloc] initWithApplication:app 383 [[FadeAllWindowsAnimation alloc] initWithApplication:app
383 animationDuration:duration]; 384 animationDuration:duration];
384 // Releases itself when the animation stops. 385 // Releases itself when the animation stops.
385 [animation startAnimation]; 386 [animation startAnimation];
386 } 387 }
387 388
388 // This looks at the Main Menu and determines what the user has set as the 389 // This looks at the Main Menu and determines what the user has set as the
389 // key combination for quit. It then gets the modifiers and builds an object 390 // key combination for quit. It then gets the modifiers and builds an object
390 // to hold the data. 391 // to hold the data.
391 + (scoped_ptr<ui::PlatformAcceleratorCocoa>)quitAccelerator { 392 + (std::unique_ptr<ui::PlatformAcceleratorCocoa>)quitAccelerator {
392 NSMenu* mainMenu = [NSApp mainMenu]; 393 NSMenu* mainMenu = [NSApp mainMenu];
393 // Get the application menu (i.e. Chromium). 394 // Get the application menu (i.e. Chromium).
394 NSMenu* appMenu = [[mainMenu itemAtIndex:0] submenu]; 395 NSMenu* appMenu = [[mainMenu itemAtIndex:0] submenu];
395 for (NSMenuItem* item in [appMenu itemArray]) { 396 for (NSMenuItem* item in [appMenu itemArray]) {
396 // Find the Quit item. 397 // Find the Quit item.
397 if ([item action] == @selector(terminate:)) { 398 if ([item action] == @selector(terminate:)) {
398 return scoped_ptr<ui::PlatformAcceleratorCocoa>( 399 return std::unique_ptr<ui::PlatformAcceleratorCocoa>(
399 new ui::PlatformAcceleratorCocoa([item keyEquivalent], 400 new ui::PlatformAcceleratorCocoa([item keyEquivalent],
400 [item keyEquivalentModifierMask])); 401 [item keyEquivalentModifierMask]));
401 } 402 }
402 } 403 }
403 // Default to Cmd+Q. 404 // Default to Cmd+Q.
404 return scoped_ptr<ui::PlatformAcceleratorCocoa>( 405 return std::unique_ptr<ui::PlatformAcceleratorCocoa>(
405 new ui::PlatformAcceleratorCocoa(@"q", NSCommandKeyMask)); 406 new ui::PlatformAcceleratorCocoa(@"q", NSCommandKeyMask));
406 } 407 }
407 408
408 + (NSString*)keyCombinationForAccelerator: 409 + (NSString*)keyCombinationForAccelerator:
409 (const ui::PlatformAcceleratorCocoa&)item { 410 (const ui::PlatformAcceleratorCocoa&)item {
410 NSMutableString* string = [NSMutableString string]; 411 NSMutableString* string = [NSMutableString string];
411 NSUInteger modifiers = item.modifier_mask(); 412 NSUInteger modifiers = item.modifier_mask();
412 413
413 if (modifiers & NSCommandKeyMask) 414 if (modifiers & NSCommandKeyMask)
414 [string appendString:@"\u2318"]; 415 [string appendString:@"\u2318"];
415 if (modifiers & NSControlKeyMask) 416 if (modifiers & NSControlKeyMask)
416 [string appendString:@"\u2303"]; 417 [string appendString:@"\u2303"];
417 if (modifiers & NSAlternateKeyMask) 418 if (modifiers & NSAlternateKeyMask)
418 [string appendString:@"\u2325"]; 419 [string appendString:@"\u2325"];
419 if (modifiers & NSShiftKeyMask) 420 if (modifiers & NSShiftKeyMask)
420 [string appendString:@"\u21E7"]; 421 [string appendString:@"\u21E7"];
421 422
422 [string appendString:[item.characters() uppercaseString]]; 423 [string appendString:[item.characters() uppercaseString]];
423 return string; 424 return string;
424 } 425 }
425 426
426 @end 427 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698