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#import <Cocoa/Cocoa.h> 6 7#import "base/mac/cocoa_protocols.h" 8#include "base/memory/scoped_ptr.h" 9 10namespace BaseBubbleControllerInternal { 11class Bridge; 12} 13 14@class InfoBubbleView; 15 16// Base class for bubble controllers. Manages a xib that contains an 17// InfoBubbleWindow which contains an InfoBubbleView. Contains code to close 18// the bubble window on clicks outside of the window, and the like. 19// To use this class: 20// 1. Create a new xib that contains a window. Change the window's class to 21// InfoBubbleWindow. Give it a child view that autosizes to the window's full 22// size, give it class InfoBubbleView. Make the controller the window's 23// delegate. 24// 2. Create a subclass of BaseBubbleController. 25// 3. Change the xib's File Owner to your subclass. 26// 4. Hook up the File Owner's |bubble_| to the InfoBubbleView in the xib. 27@interface BaseBubbleController : NSWindowController<NSWindowDelegate> { 28 @private 29 NSWindow* parentWindow_; // weak 30 NSPoint anchor_; 31 IBOutlet InfoBubbleView* bubble_; // to set arrow position 32 // Bridge that listens for notifications. 33 scoped_ptr<BaseBubbleControllerInternal::Bridge> base_bridge_; 34} 35 36@property(nonatomic, readonly) NSWindow* parentWindow; 37@property(nonatomic, assign) NSPoint anchorPoint; 38@property(nonatomic, readonly) InfoBubbleView* bubble; 39 40// Creates a bubble. |nibPath| is just the basename, e.g. @"FirstRunBubble". 41// |anchoredAt| is in screen space. You need to call -showWindow: to make the 42// bubble visible. It will autorelease itself when the user dismisses the 43// bubble. 44// This is the designated initializer. 45- (id)initWithWindowNibPath:(NSString*)nibPath 46 parentWindow:(NSWindow*)parentWindow 47 anchoredAt:(NSPoint)anchoredAt; 48 49 50// Creates a bubble. |nibPath| is just the basename, e.g. @"FirstRunBubble". 51// |view| must be in a window. The bubble will point at |offset| relative to 52// |view|'s lower left corner. You need to call -showWindow: to make the 53// bubble visible. It will autorelease itself when the user dismisses the 54// bubble. 55- (id)initWithWindowNibPath:(NSString*)nibPath 56 relativeToView:(NSView*)view 57 offset:(NSPoint)offset; 58 59 60// For subclasses that do not load from a XIB, this will simply set the instance 61// variables appropriately. This will also replace the |-[self window]|'s 62// contentView with an instance of InfoBubbleView. 63- (id)initWithWindow:(NSWindow*)theWindow 64 parentWindow:(NSWindow*)parentWindow 65 anchoredAt:(NSPoint)anchoredAt; 66 67@end 68