Commit fae2d2f9 authored by rsesek@chromium.org's avatar rsesek@chromium.org

[Mac] Make ExtensionInstalledBubbleController is-a BaseBubbleController.

XIB changes:
* Change ExtensionInstalledBubbleController to have BaseBubbleController as a 
  parent class.
* Set the bubble_ outlet on the new base class and delete infoBubbleView_.

BUG=36366
TEST=Install an extension with a browser action. Bubble appears at browser action and behaves as before.
TEST=Install bundled extensions and make sure the bubble appears at the wrench menu.
TEST=Install an omnibox keyword extension and bubble appears at the lock icon.

Review URL: http://codereview.chromium.org/9705038

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@126919 0039d316-1c4b-4281-b951-d872f2087c98
parent 8a08fa1f
...@@ -34,6 +34,8 @@ class Bridge; ...@@ -34,6 +34,8 @@ class Bridge;
} }
@property(nonatomic, readonly) NSWindow* parentWindow; @property(nonatomic, readonly) NSWindow* parentWindow;
// The point in base screen coordinates at which the bubble should open and the
// arrow tip points.
@property(nonatomic, assign) NSPoint anchorPoint; @property(nonatomic, assign) NSPoint anchorPoint;
@property(nonatomic, readonly) InfoBubbleView* bubble; @property(nonatomic, readonly) InfoBubbleView* bubble;
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#import "base/mac/cocoa_protocols.h" #import "base/mac/cocoa_protocols.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#import "chrome/browser/ui/cocoa/browser_window_controller.h" #import "chrome/browser/ui/cocoa/browser_window_controller.h"
#import "chrome/browser/ui/cocoa/base_bubble_controller.h"
#include "third_party/skia/include/core/SkBitmap.h" #include "third_party/skia/include/core/SkBitmap.h"
class Browser; class Browser;
...@@ -43,16 +44,14 @@ typedef enum { ...@@ -43,16 +44,14 @@ typedef enum {
kBundle, kBundle,
} ExtensionType; } ExtensionType;
} } // namespace extension_installed_bubble
// Controller for the extension installed bubble. This bubble pops up after // Controller for the extension installed bubble. This bubble pops up after
// an extension has been installed to inform the user that the install happened // an extension has been installed to inform the user that the install happened
// properly, and to let the user know how to manage this extension in the // properly, and to let the user know how to manage this extension in the
// future. // future.
@interface ExtensionInstalledBubbleController : @interface ExtensionInstalledBubbleController : BaseBubbleController {
NSWindowController<NSWindowDelegate> {
@private @private
NSWindow* parentWindow_; // weak
const Extension* extension_; // weak const Extension* extension_; // weak
const extensions::BundleInstaller* bundle_; // weak const extensions::BundleInstaller* bundle_; // weak
Browser* browser_; // weak Browser* browser_; // weak
...@@ -71,7 +70,6 @@ typedef enum { ...@@ -71,7 +70,6 @@ typedef enum {
scoped_ptr<ExtensionLoadedNotificationObserver> extensionObserver_; scoped_ptr<ExtensionLoadedNotificationObserver> extensionObserver_;
// References below are weak, being obtained from the nib. // References below are weak, being obtained from the nib.
IBOutlet InfoBubbleView* infoBubbleView_;
IBOutlet HoverCloseButton* closeButton_; IBOutlet HoverCloseButton* closeButton_;
IBOutlet NSImageView* iconImage_; IBOutlet NSImageView* iconImage_;
IBOutlet NSTextField* extensionInstalledMsg_; IBOutlet NSTextField* extensionInstalledMsg_;
...@@ -110,7 +108,7 @@ typedef enum { ...@@ -110,7 +108,7 @@ typedef enum {
@end @end
@interface ExtensionInstalledBubbleController(ExposedForTesting) @interface ExtensionInstalledBubbleController (ExposedForTesting)
- (void)removePageActionPreviewIfNecessary; - (void)removePageActionPreviewIfNecessary;
- (NSWindow*)initializeWindow; - (NSWindow*)initializeWindow;
......
...@@ -92,11 +92,9 @@ class ExtensionLoadedNotificationObserver ...@@ -92,11 +92,9 @@ class ExtensionLoadedNotificationObserver
icon:(SkBitmap)icon { icon:(SkBitmap)icon {
NSString* nibName = bundle ? @"ExtensionInstalledBubbleBundle" : NSString* nibName = bundle ? @"ExtensionInstalledBubbleBundle" :
@"ExtensionInstalledBubble"; @"ExtensionInstalledBubble";
NSString* nibPath = [base::mac::FrameworkBundle() pathForResource:nibName if ((self = [super initWithWindowNibPath:nibName
ofType:@"nib"]; parentWindow:parentWindow
if ((self = [super initWithWindowNibPath:nibPath owner:self])) { anchoredAt:NSZeroPoint])) {
DCHECK(parentWindow);
parentWindow_ = parentWindow;
extension_ = extension; extension_ = extension;
bundle_ = bundle; bundle_ = bundle;
DCHECK(browser); DCHECK(browser);
...@@ -124,55 +122,28 @@ class ExtensionLoadedNotificationObserver ...@@ -124,55 +122,28 @@ class ExtensionLoadedNotificationObserver
extensionObserver_.reset(new ExtensionLoadedNotificationObserver( extensionObserver_.reset(new ExtensionLoadedNotificationObserver(
self, browser->profile())); self, browser->profile()));
} }
// Watch to see if the parent window closes, and if so, close this one.
NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
[center addObserver:self
selector:@selector(parentWindowWillClose:)
name:NSWindowWillCloseNotification
object:parentWindow_];
} }
return self; return self;
} }
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
[super dealloc];
}
- (void)close {
[[[self window] parentWindow] removeChildWindow:[self window]];
[super close];
}
- (void)parentWindowWillClose:(NSNotification*)notification {
[self close];
}
- (void)windowWillClose:(NSNotification*)notification { - (void)windowWillClose:(NSNotification*)notification {
// Turn off page action icon preview when the window closes, unless we // Turn off page action icon preview when the window closes, unless we
// already removed it when the window resigned key status. // already removed it when the window resigned key status.
[self removePageActionPreviewIfNecessary]; [self removePageActionPreviewIfNecessary];
extension_ = NULL; extension_ = NULL;
browser_ = NULL; browser_ = NULL;
parentWindow_ = nil;
// We caught a close so we don't need to watch for the parent closing. [super windowWillClose:notification];
[[NSNotificationCenter defaultCenter] removeObserver:self];
[self autorelease];
} }
// The controller is the delegate of the window, so it receives "did resign // The controller is the delegate of the window, so it receives "did resign
// key" notifications. When key is resigned, close the window. // key" notifications. When key is resigned, close the window.
- (void)windowDidResignKey:(NSNotification*)notification { - (void)windowDidResignKey:(NSNotification*)notification {
NSWindow* window = [self window];
DCHECK_EQ([notification object], window);
DCHECK([window isVisible]);
// If the browser window is closing, we need to remove the page action // If the browser window is closing, we need to remove the page action
// immediately, otherwise the closing animation may overlap with // immediately, otherwise the closing animation may overlap with
// browser destruction. // browser destruction.
[self removePageActionPreviewIfNecessary]; [self removePageActionPreviewIfNecessary];
[self close]; [super windowDidResignKey:notification];
} }
- (IBAction)closeWindow:(id)sender { - (IBAction)closeWindow:(id)sender {
...@@ -264,7 +235,7 @@ class ExtensionLoadedNotificationObserver ...@@ -264,7 +235,7 @@ class ExtensionLoadedNotificationObserver
// Load nib and calculate height based on messages to be shown. // Load nib and calculate height based on messages to be shown.
NSWindow* window = [self initializeWindow]; NSWindow* window = [self initializeWindow];
int newWindowHeight = [self calculateWindowHeight]; int newWindowHeight = [self calculateWindowHeight];
[infoBubbleView_ setFrameSize:NSMakeSize( [self.bubble setFrameSize:NSMakeSize(
NSWidth([[window contentView] bounds]), newWindowHeight)]; NSWidth([[window contentView] bounds]), newWindowHeight)];
NSSize windowDelta = NSMakeSize( NSSize windowDelta = NSMakeSize(
0, newWindowHeight - NSHeight([[window contentView] bounds])); 0, newWindowHeight - NSHeight([[window contentView] bounds]));
...@@ -277,19 +248,9 @@ class ExtensionLoadedNotificationObserver ...@@ -277,19 +248,9 @@ class ExtensionLoadedNotificationObserver
[self setMessageFrames:newWindowHeight]; [self setMessageFrames:newWindowHeight];
// Find window origin, taking into account bubble size and arrow location. // Find window origin, taking into account bubble size and arrow location.
NSPoint origin = self.anchorPoint =
[parentWindow_ convertBaseToScreen:[self calculateArrowPoint]]; [self.parentWindow convertBaseToScreen:[self calculateArrowPoint]];
NSSize offsets = NSMakeSize(info_bubble::kBubbleArrowXOffset + [super showWindow:sender];
info_bubble::kBubbleArrowWidth / 2.0, 0);
offsets = [[window contentView] convertSize:offsets toView:nil];
if ([infoBubbleView_ arrowLocation] == info_bubble::kTopRight)
origin.x -= NSWidth([window frame]) - offsets.width;
origin.y -= NSHeight([window frame]);
[window setFrameOrigin:origin];
[parentWindow_ addChildWindow:window
ordered:NSWindowAbove];
[window makeKeyAndOrderFront:self];
} }
// Finish nib loading, set arrow location and load icon into window. This // Finish nib loading, set arrow location and load icon into window. This
...@@ -298,9 +259,9 @@ class ExtensionLoadedNotificationObserver ...@@ -298,9 +259,9 @@ class ExtensionLoadedNotificationObserver
NSWindow* window = [self window]; // completes nib load NSWindow* window = [self window]; // completes nib load
if (type_ == extension_installed_bubble::kOmniboxKeyword) { if (type_ == extension_installed_bubble::kOmniboxKeyword) {
[infoBubbleView_ setArrowLocation:info_bubble::kTopLeft]; [self.bubble setArrowLocation:info_bubble::kTopLeft];
} else { } else {
[infoBubbleView_ setArrowLocation:info_bubble::kTopRight]; [self.bubble setArrowLocation:info_bubble::kTopRight];
} }
if (type_ == extension_installed_bubble::kBundle) if (type_ == extension_installed_bubble::kBundle)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment