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