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 #import <Cocoa/Cocoa.h>
7 #include "base/memory/scoped_ptr.h"
10 class TabStripModelObserverBridge
;
12 // Base class for bubble controllers. Manages a xib that contains an
13 // InfoBubbleWindow which contains an InfoBubbleView. Contains code to close
14 // the bubble window on clicks outside of the window, and the like.
16 // 1. Create a new xib that contains a window. Change the window's class to
17 // InfoBubbleWindow. Give it a child view that autosizes to the window's full
18 // size, give it class InfoBubbleView. Make the controller the window's
20 // 2. Create a subclass of BaseBubbleController.
21 // 3. Change the xib's File Owner to your subclass.
22 // 4. Hook up the File Owner's |bubble_| to the InfoBubbleView in the xib.
23 @interface BaseBubbleController
: NSWindowController
<NSWindowDelegate
> {
25 NSWindow
* parentWindow_
; // weak
27 IBOutlet InfoBubbleView
* bubble_
; // to set arrow position
28 // Bridge for tab change notifications.
29 scoped_ptr
<TabStripModelObserverBridge
> tabStripObserverBridge_
;
31 // Non-nil only on 10.7+. Both weak, owned by AppKit.
32 // A local event tap that will dismiss the bubble when a click is delivered
33 // outside the window. This is needed because the window shares first
34 // responder with its parent.
36 // A notification observer that gets triggered when any window resigns key.
37 id resignationObserver_
;
38 // The controlled window should be the key window when it's opened. True by
40 BOOL shouldOpenAsKeyWindow_
;
41 // The bubble window should close if it (or its parent) resigns key status.
42 BOOL shouldCloseOnResignKey_
;
45 @
property(nonatomic
, readonly
) NSWindow
* parentWindow
;
46 // The point in base screen coordinates at which the bubble should open and the
48 @
property(nonatomic
, assign
) NSPoint anchorPoint
;
49 @
property(nonatomic
, readonly
) InfoBubbleView
* bubble
;
50 @
property(nonatomic
, assign
) BOOL shouldOpenAsKeyWindow
;
51 // Controls if the bubble auto-closes if the user clicks outside the bubble.
52 @
property(nonatomic
, assign
) BOOL shouldCloseOnResignKey
;
54 // Creates a bubble. |nibPath| is just the basename, e.g. @"FirstRunBubble".
55 // |anchoredAt| is in screen space. You need to call -showWindow: to make the
56 // bubble visible. It will autorelease itself when the user dismisses the
58 // This is the designated initializer.
59 - (id
)initWithWindowNibPath
:(NSString
*)nibPath
60 parentWindow
:(NSWindow
*)parentWindow
61 anchoredAt
:(NSPoint
)anchoredAt
;
64 // Creates a bubble. |nibPath| is just the basename, e.g. @"FirstRunBubble".
65 // |view| must be in a window. The bubble will point at |offset| relative to
66 // |view|'s lower left corner. You need to call -showWindow: to make the
67 // bubble visible. It will autorelease itself when the user dismisses the
69 - (id
)initWithWindowNibPath
:(NSString
*)nibPath
70 relativeToView
:(NSView
*)view
71 offset
:(NSPoint
)offset
;
74 // For subclasses that do not load from a XIB, this will simply set the instance
75 // variables appropriately. This will also replace the |-[self window]|'s
76 // contentView with an instance of InfoBubbleView.
77 - (id
)initWithWindow
:(NSWindow
*)theWindow
78 parentWindow
:(NSWindow
*)parentWindow
79 anchoredAt
:(NSPoint
)anchoredAt
;
81 // Creates an autoreleased separator view with a given frame. The height of the
83 - (NSBox
*)separatorWithFrame
:(NSRect
)frame
;
87 // Methods for use by subclasses.
88 @interface
BaseBubbleController (Protected
)
89 // Registers event taps *after* the window is shown so that the bubble is
90 // dismissed when it resigns key. This only needs to be called if
91 // |-showWindow:| is overriden and does not call super. Noop on OSes <10.7.
92 - (void)registerKeyStateEventTap
;