Home | History | Annotate | Download | only in panels
      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
      3 // found in the LICENSE file.
      4 
      5 #ifndef CHROME_BROWSER_UI_COCOA_PANELS_PANEL_WINDOW_CONTROLLER_COCOA_H_
      6 #define CHROME_BROWSER_UI_COCOA_PANELS_PANEL_WINDOW_CONTROLLER_COCOA_H_
      7 
      8 // A class acting as the Objective-C controller for the Panel window
      9 // object. Handles interactions between Cocoa and the cross-platform
     10 // code. Each window has a single titlebar and is managed/owned by Panel.
     11 
     12 #import <Cocoa/Cocoa.h>
     13 
     14 #include "base/mac/scoped_nsobject.h"
     15 #include "base/memory/scoped_ptr.h"
     16 #import "chrome/browser/ui/cocoa/chrome_browser_window.h"
     17 #include "chrome/browser/ui/panels/panel.h"
     18 #import "ui/base/cocoa/tracking_area.h"
     19 
     20 class PanelCocoa;
     21 @class PanelTitlebarViewCocoa;
     22 
     23 @interface PanelWindowCocoaImpl : ChromeBrowserWindow {
     24 }
     25 @end
     26 
     27 @interface PanelWindowControllerCocoa : NSWindowController
     28                                             <NSWindowDelegate,
     29                                              NSAnimationDelegate> {
     30  @private
     31   IBOutlet PanelTitlebarViewCocoa* titlebar_view_;
     32   scoped_ptr<PanelCocoa> windowShim_;
     33   base::scoped_nsobject<NSString> pendingWindowTitle_;
     34   NSViewAnimation* boundsAnimation_;  // Lifetime controlled manually, needs
     35                                       // more then just |release| to terminate.
     36   BOOL animateOnBoundsChange_;
     37   BOOL throbberShouldSpin_;
     38   BOOL playingMinimizeAnimation_;
     39   float animationStopToShowTitlebarOnly_;
     40   BOOL canBecomeKeyWindow_;
     41   // Allow a panel to become key if activated via Panel logic, as opposed
     42   // to by default system selection. The system will prefer a panel
     43   // window over other application windows due to panels having a higher
     44   // priority NSWindowLevel, so we distinguish between the two scenarios.
     45   BOOL activationRequestedByPanel_;
     46   // Is user resizing in progress?
     47   BOOL userResizing_;
     48   // Tracks the whole window in order to receive NSMouseMoved event.
     49   ui::ScopedCrTrackingArea trackingArea_;
     50 }
     51 
     52 // Load the window nib and do any Cocoa-specific initialization.
     53 - (id)initWithPanel:(PanelCocoa*)window;
     54 
     55 - (Panel*)panel;
     56 
     57 - (void)webContentsInserted:(content::WebContents*)contents;
     58 - (void)webContentsDetached:(content::WebContents*)contents;
     59 
     60 - (void)updateWebContentsViewFrame;
     61 
     62 // Sometimes (when we animate the size of the window) we want to stop resizing
     63 // the WebContents's Cocoa view to avoid unnecessary rendering and issues
     64 // that can be caused by sizes near 0.
     65 - (void)disableWebContentsViewAutosizing;
     66 - (void)enableWebContentsViewAutosizing;
     67 
     68 // Shows the window for the first time. Only happens once.
     69 - (void)revealAnimatedWithFrame:(const NSRect&)frame;
     70 
     71 - (void)updateTitleBar;
     72 - (void)updateIcon;
     73 - (void)updateThrobber:(BOOL)shouldSpin;
     74 - (void)updateTitleBarMinimizeRestoreButtonVisibility;
     75 
     76 // Initiate the closing of the panel, starting from the platform-independent
     77 // layer. This will take care of PanelManager, other panels and close the
     78 // native window at the end.
     79 - (void)closePanel;
     80 
     81 // Minimize/Restore the panel or all panels, depending on the modifier.
     82 // Invoked when the minimize/restore button is clicked.
     83 - (void)minimizeButtonClicked:(int)modifierFlags;
     84 - (void)restoreButtonClicked:(int)modifierFlags;
     85 
     86 // Uses nonblocking animation for moving the Panels. It's especially
     87 // important in case of dragging a Panel when other Panels should 'slide out',
     88 // indicating the potential drop slot.
     89 // |frame| is in screen coordinates, same as [window frame].
     90 // |animate| controls if the bounds animation is needed or not.
     91 - (void)setPanelFrame:(NSRect)frame
     92               animate:(BOOL)animate;
     93 
     94 // Used by PanelTitlebarViewCocoa when user rearranges the Panels by dragging.
     95 // |mouseLocation| is in Cocoa's screen coordinates.
     96 - (void)startDrag:(NSPoint)mouseLocation;
     97 - (void)endDrag:(BOOL)cancelled;
     98 - (void)drag:(NSPoint)mouseLocation;
     99 
    100 // Accessor for titlebar view.
    101 - (PanelTitlebarViewCocoa*)titlebarView;
    102 // Returns the height of titlebar, used to show the titlebar in
    103 // "Draw Attention" state.
    104 - (int)titlebarHeightInScreenCoordinates;
    105 
    106 // Invoked when user clicks on the titlebar. Attempts to flip the
    107 // Minimized/Restored states.
    108 - (void)onTitlebarMouseClicked:(int)modifierFlags;
    109 
    110 // Invoked when user double-clicks on the titlebar.
    111 - (void)onTitlebarDoubleClicked:(int)modifierFlags;
    112 
    113 // NSAnimationDelegate method, invoked when bounds animation is finished.
    114 - (void)animationDidEnd:(NSAnimation*)animation;
    115 // Terminates current bounds animation, if any.
    116 - (void)terminateBoundsAnimation;
    117 
    118 - (BOOL)isAnimatingBounds;
    119 
    120 // Sets/Removes the Key status from the panel to some other window.
    121 - (void)activate;
    122 - (void)deactivate;
    123 
    124 // Changes the canBecomeKeyWindow state
    125 - (void)preventBecomingKeyWindow:(BOOL)prevent;
    126 
    127 // See Panel::FullScreenModeChanged.
    128 - (void)fullScreenModeChanged:(bool)isFullScreen;
    129 
    130 // Helper for NSWindow, returns NO for minimized panels in some cases, so they
    131 // are not un-minimized when another panel is minimized.
    132 - (BOOL)canBecomeKeyWindow;
    133 
    134 // Returns true if Panel requested activation of the window.
    135 - (BOOL)activationRequestedByPanel;
    136 
    137 // Adjust NSStatusWindowLevel based on whether panel is always on top
    138 // and whether the panel is minimized. The first version wraps the second
    139 // version using the current panel expanstion state.
    140 - (void)updateWindowLevel;
    141 - (void)updateWindowLevel:(BOOL)panelIsMinimized;
    142 
    143 // Adjusts NSWindowCollectionBehavior based on whether panel is always on top.
    144 - (void)updateWindowCollectionBehavior;
    145 
    146 // Updates the tracking area per the window size change. This is needed in
    147 // order to receive the NSMouseMoved notification.
    148 - (void)updateTrackingArea;
    149 
    150 // Turns on/off shadow effect around the window shape.
    151 - (void)showShadow:(BOOL)show;
    152 
    153 // Minimize the window to the dock.
    154 - (void)miniaturize;
    155 // Returns true if the window is minimized to the dock.
    156 - (BOOL)isMiniaturized;
    157 
    158 // Returns true if the user-resizing is allowed for the edge/corner close to
    159 // current mouse location.
    160 - (BOOL)canResizeByMouseAtCurrentLocation;
    161 
    162 - (NSRect)frameRectForContentRect:(NSRect)contentRect;
    163 - (NSRect)contentRectForFrameRect:(NSRect)frameRect;
    164 
    165 @end  // @interface PanelWindowController
    166 
    167 #endif  // CHROME_BROWSER_UI_COCOA_PANELS_PANEL_WINDOW_CONTROLLER_COCOA_H_
    168