OLD | NEW |
| (Empty) |
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_TITLEBAR_VIEW_COCOA_H_ | |
6 #define CHROME_BROWSER_UI_COCOA_PANELS_PANEL_TITLEBAR_VIEW_COCOA_H_ | |
7 | |
8 #import <Cocoa/Cocoa.h> | |
9 | |
10 #import "chrome/browser/ui/cocoa/panels/mouse_drag_controller.h" | |
11 #import "ui/base/cocoa/tracking_area.h" | |
12 | |
13 @class HoverImageButton; | |
14 @class MouseDragController; | |
15 @class PanelWindowControllerCocoa; | |
16 | |
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. | |
26 | |
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 { | |
31 @private | |
32 IBOutlet PanelWindowControllerCocoa* controller_; | |
33 BOOL disableReordering_; | |
34 } | |
35 @end | |
36 | |
37 @interface RepaintAnimation : NSAnimation { | |
38 @private | |
39 NSView* targetView_; | |
40 } | |
41 - (id)initWithView:(NSView*)targetView duration:(double) duration; | |
42 - (void)setCurrentProgress:(NSAnimationProgress)progress; | |
43 @end | |
44 | |
45 @interface PanelTitlebarViewCocoa : NSView | |
46 <NSAnimationDelegate, | |
47 MouseDragControllerClient> { | |
48 @private | |
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_; | |
62 | |
63 // "Glint" animation is used in "Draw Attention" mode. | |
64 base::scoped_nsobject<RepaintAnimation> glintAnimation_; | |
65 base::scoped_nsobject<NSTimer> glintAnimationTimer_; | |
66 int glintCounter_; | |
67 | |
68 // Drag support. | |
69 base::scoped_nsobject<MouseDragController> dragController_; | |
70 } | |
71 | |
72 // Callbacks from Close, Minimize, and Restore buttons. | |
73 - (void)onCloseButtonClick:(id)sender; | |
74 - (void)onMinimizeButtonClick:(id)sender; | |
75 - (void)onRestoreButtonClick:(id)sender; | |
76 | |
77 // Attaches this view to the controller_'s window as a titlebar. | |
78 - (void)attach; | |
79 | |
80 - (void)setTitle:(NSString*)newTitle; | |
81 - (void)setIcon:(NSView*)newIcon; | |
82 | |
83 - (NSView*)icon; | |
84 | |
85 // Set the visibility of the minimize and restore buttons. | |
86 - (void)setMinimizeButtonVisibility:(BOOL)visible; | |
87 - (void)setRestoreButtonVisibility:(BOOL)visible; | |
88 | |
89 // Should be called when size of the titlebar changes. | |
90 - (void)updateCustomButtonsLayout; | |
91 - (void)updateIconAndTitleLayout; | |
92 | |
93 // Various events that we'll need to redraw our titlebar for. | |
94 - (void)didChangeFrame:(NSNotification*)notification; | |
95 - (void)didChangeMainWindow:(NSNotification*)notification; | |
96 | |
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; | |
104 | |
105 @end // @interface PanelTitlebarView | |
106 | |
107 // Methods which are either only for testing, or only public for testing. | |
108 @interface PanelTitlebarViewCocoa(TestingAPI) | |
109 | |
110 - (PanelWindowControllerCocoa*)controller; | |
111 | |
112 - (NSTextField*)title; | |
113 - (NSButton*)closeButton; | |
114 - (NSButton*)minimizeButton; | |
115 - (NSButton*)restoreButton; | |
116 | |
117 // Simulates click on a close button. Used to test panel closing. | |
118 - (void)simulateCloseButtonClick; | |
119 | |
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; | |
128 | |
129 @end // @interface PanelTitlebarViewCocoa(TestingAPI) | |
130 | |
131 #endif // CHROME_BROWSER_UI_COCOA_PANELS_PANEL_TITLEBAR_VIEW_COCOA_H_ | |
OLD | NEW |