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.
5 #ifndef CHROME_BROWSER_UI_COCOA_PANELS_PANEL_TITLEBAR_VIEW_COCOA_H_
6 #define CHROME_BROWSER_UI_COCOA_PANELS_PANEL_TITLEBAR_VIEW_COCOA_H_
8 #import <Cocoa/Cocoa.h>
10 #import "chrome/browser/ui/cocoa/panels/mouse_drag_controller.h"
11 #import "ui/base/cocoa/tracking_area.h"
13 @
class HoverImageButton
;
14 @
class MouseDragController
;
15 @
class PanelWindowControllerCocoa
;
17 // A class that works as a custom titlebar for Panels. It is placed on top of
18 // the regular Cocoa titlebar. It's the place for the close button, page
19 // favicon, title label and a button to minimize/restore the panel.
20 // It also facilitates dragging and minimization of the panels, and changes
21 // color as 'new activity' indicator.
22 // One way to have custom titlebar would be to use NSBorderlessWindow,
23 // but it seems to affect too many other behaviors (for example, it draws shadow
24 // differently based on being key window) so it appears easier to simply overlay
25 // the standard titlebar.
27 // This view overlays the titlebar on top. It is used to intercept
28 // mouse input to prevent reordering of the other browser windows when clicking
29 // on the titlebar (to minimize or reorder) while in a docked collection.
30 @interface PanelTitlebarOverlayView
: NSView
{
32 IBOutlet PanelWindowControllerCocoa
* controller_
;
33 BOOL disableReordering_
;
37 @interface RepaintAnimation
: NSAnimation
{
41 - (id
)initWithView
:(NSView
*)targetView duration
:(double) duration
;
42 - (void)setCurrentProgress
:(NSAnimationProgress
)progress
;
45 @interface PanelTitlebarViewCocoa
: NSView
47 MouseDragControllerClient
> {
49 IBOutlet PanelWindowControllerCocoa
* controller_
;
50 IBOutlet NSView
* icon_
;
51 IBOutlet NSTextField
* title_
;
52 IBOutlet HoverImageButton
* minimizeButton_
;
53 IBOutlet HoverImageButton
* restoreButton_
;
54 IBOutlet HoverImageButton
* customCloseButton_
;
55 // Transparent view on top of entire titlebar. It catches mouse events to
56 // prevent window activation by the system on mouseDown.
57 IBOutlet NSView
* overlay_
;
58 NSButton
* closeButton_
; // Created explicitly, not from NIB. Weak, destroyed
59 // when view is destroyed, as a subview.
60 ui::ScopedCrTrackingArea closeButtonTrackingArea_
;
61 BOOL isDrawingAttention_
;
63 // "Glint" animation is used in "Draw Attention" mode.
64 base::scoped_nsobject
<RepaintAnimation
> glintAnimation_
;
65 base::scoped_nsobject
<NSTimer
> glintAnimationTimer_
;
69 base::scoped_nsobject
<MouseDragController
> dragController_
;
72 // Callbacks from Close, Minimize, and Restore buttons.
73 - (void)onCloseButtonClick
:(id
)sender
;
74 - (void)onMinimizeButtonClick
:(id
)sender
;
75 - (void)onRestoreButtonClick
:(id
)sender
;
77 // Attaches this view to the controller_'s window as a titlebar.
80 - (void)setTitle
:(NSString
*)newTitle
;
81 - (void)setIcon
:(NSView
*)newIcon
;
85 // Set the visibility of the minimize and restore buttons.
86 - (void)setMinimizeButtonVisibility
:(BOOL
)visible
;
87 - (void)setRestoreButtonVisibility
:(BOOL
)visible
;
89 // Should be called when size of the titlebar changes.
90 - (void)updateCustomButtonsLayout
;
91 - (void)updateIconAndTitleLayout
;
93 // Various events that we'll need to redraw our titlebar for.
94 - (void)didChangeFrame
:(NSNotification
*)notification
;
95 - (void)didChangeMainWindow
:(NSNotification
*)notification
;
97 // Draw Attention methods - change appearance of titlebar to attract user.
98 - (void)drawAttention
;
99 - (void)stopDrawingAttention
;
100 - (BOOL
)isDrawingAttention
;
101 - (void)startGlintAnimation
;
102 - (void)restartGlintAnimation
:(NSTimer
*)timer
;
103 - (void)stopGlintAnimation
;
105 @end
// @interface PanelTitlebarView
107 // Methods which are either only for testing, or only public for testing.
108 @interface
PanelTitlebarViewCocoa(TestingAPI
)
110 - (PanelWindowControllerCocoa
*)controller
;
112 - (NSTextField
*)title
;
113 - (NSButton
*)closeButton
;
114 - (NSButton
*)minimizeButton
;
115 - (NSButton
*)restoreButton
;
117 // Simulates click on a close button. Used to test panel closing.
118 - (void)simulateCloseButtonClick
;
120 // NativePanelTesting support.
121 // |mouseLocation| is in Cocoa's screen coordinates.
122 - (void)pressLeftMouseButtonTitlebar
:(NSPoint
)mouseLocation
123 modifiers
:(int)modifierFlags
;
124 - (void)releaseLeftMouseButtonTitlebar
:(int)modifierFlags
;
125 - (void)dragTitlebar
:(NSPoint
)mouseLocation
;
126 - (void)cancelDragTitlebar
;
127 - (void)finishDragTitlebar
;
129 @end
// @interface PanelTitlebarViewCocoa(TestingAPI)
131 #endif // CHROME_BROWSER_UI_COCOA_PANELS_PANEL_TITLEBAR_VIEW_COCOA_H_