Home | History | Annotate | Download | only in cocoa
      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
      3 // found in the LICENSE file.
      4 
      5 #ifndef CHROME_BROWSER_UI_COCOA_CONFIRM_QUIT_PANEL_CONTROLLER_H_
      6 #define CHROME_BROWSER_UI_COCOA_CONFIRM_QUIT_PANEL_CONTROLLER_H_
      7 
      8 #import <Cocoa/Cocoa.h>
      9 
     10 #import "base/mac/cocoa_protocols.h"
     11 #include "ui/base/models/accelerator_cocoa.h"
     12 
     13 @class ConfirmQuitFrameView;
     14 
     15 namespace confirm_quit {
     16 
     17 enum ConfirmQuitMetric {
     18   // The user quit without having the feature enabled.
     19   kNoConfirm = 0,
     20   // The user held Cmd+Q for the entire duration.
     21   kHoldDuration,
     22   // The user hit Cmd+Q twice for the accelerated path.
     23   kDoubleTap,
     24   // The user tapped Cmd+Q once and then held it.
     25   kTapHold,
     26 
     27   kSampleCount
     28 };
     29 
     30 // Records the histogram value for the above metric.
     31 void RecordHistogram(ConfirmQuitMetric sample);
     32 
     33 }  // namespace confirm_quit
     34 
     35 // The ConfirmQuitPanelController manages the black HUD window that tells users
     36 // to "Hold Cmd+Q to Quit".
     37 @interface ConfirmQuitPanelController : NSWindowController<NSWindowDelegate> {
     38  @private
     39   // The content view of the window that this controller manages.
     40   ConfirmQuitFrameView* contentView_;  // Weak, owned by the window.
     41 }
     42 
     43 // Returns a singleton instance of the Controller. This will create one if it
     44 // does not currently exist.
     45 + (ConfirmQuitPanelController*)sharedController;
     46 
     47 // Checks whether the |event| should trigger the feature.
     48 + (BOOL)eventTriggersFeature:(NSEvent*)event;
     49 
     50 // Runs a modal loop that brings up the panel and handles the logic for if and
     51 // when to terminate. Returns NSApplicationTerminateReply for use in
     52 // -[NSApplicationDelegate applicationShouldTerminate:].
     53 - (NSApplicationTerminateReply)runModalLoopForApplication:(NSApplication*)app;
     54 
     55 // Shows the window.
     56 - (void)showWindow:(id)sender;
     57 
     58 // If the user did not confirm quit, send this message to give the user
     59 // instructions on how to quit.
     60 - (void)dismissPanel;
     61 
     62 // Returns the Accelerator for the Quit menu item.
     63 + (ui::AcceleratorCocoa)quitAccelerator;
     64 
     65 // Returns a string representation fit for display of |+quitAccelerator|.
     66 + (NSString*)keyCommandString;
     67 
     68 @end
     69 
     70 @interface ConfirmQuitPanelController (UnitTesting)
     71 + (NSString*)keyCombinationForAccelerator:(const ui::AcceleratorCocoa&)item;
     72 @end
     73 
     74 #endif  // CHROME_BROWSER_UI_COCOA_CONFIRM_QUIT_PANEL_CONTROLLER_H_
     75