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;
}
@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, readonly) InfoBubbleView* bubble;
......
......@@ -11,6 +11,7 @@
#import "base/mac/cocoa_protocols.h"
#include "base/memory/scoped_ptr.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"
class Browser;
......@@ -43,16 +44,14 @@ typedef enum {
kBundle,
} ExtensionType;
}
} // namespace extension_installed_bubble
// Controller for the extension installed bubble. This bubble pops up after
// 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
// future.
@interface ExtensionInstalledBubbleController :
NSWindowController<NSWindowDelegate> {
@interface ExtensionInstalledBubbleController : BaseBubbleController {
@private
NSWindow* parentWindow_; // weak
const Extension* extension_; // weak
const extensions::BundleInstaller* bundle_; // weak
Browser* browser_; // weak
......@@ -71,7 +70,6 @@ typedef enum {
scoped_ptr<ExtensionLoadedNotificationObserver> extensionObserver_;
// References below are weak, being obtained from the nib.
IBOutlet InfoBubbleView* infoBubbleView_;
IBOutlet HoverCloseButton* closeButton_;
IBOutlet NSImageView* iconImage_;
IBOutlet NSTextField* extensionInstalledMsg_;
......@@ -110,7 +108,7 @@ typedef enum {
@end
@interface ExtensionInstalledBubbleController(ExposedForTesting)
@interface ExtensionInstalledBubbleController (ExposedForTesting)
- (void)removePageActionPreviewIfNecessary;
- (NSWindow*)initializeWindow;
......
......@@ -92,11 +92,9 @@ class ExtensionLoadedNotificationObserver
icon:(SkBitmap)icon {
NSString* nibName = bundle ? @"ExtensionInstalledBubbleBundle" :
@"ExtensionInstalledBubble";
NSString* nibPath = [base::mac::FrameworkBundle() pathForResource:nibName
ofType:@"nib"];
if ((self = [super initWithWindowNibPath:nibPath owner:self])) {
DCHECK(parentWindow);
parentWindow_ = parentWindow;
if ((self = [super initWithWindowNibPath:nibName
parentWindow:parentWindow
anchoredAt:NSZeroPoint])) {
extension_ = extension;
bundle_ = bundle;
DCHECK(browser);
......@@ -124,55 +122,28 @@ class ExtensionLoadedNotificationObserver
extensionObserver_.reset(new ExtensionLoadedNotificationObserver(
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;
}
- (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 {
// Turn off page action icon preview when the window closes, unless we
// already removed it when the window resigned key status.
[self removePageActionPreviewIfNecessary];
extension_ = NULL;
browser_ = NULL;
parentWindow_ = nil;
// We caught a close so we don't need to watch for the parent closing.
[[NSNotificationCenter defaultCenter] removeObserver:self];
[self autorelease];
[super windowWillClose:notification];
}
// The controller is the delegate of the window, so it receives "did resign
// key" notifications. When key is resigned, close the window.
- (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
// immediately, otherwise the closing animation may overlap with
// browser destruction.
[self removePageActionPreviewIfNecessary];
[self close];
[super windowDidResignKey:notification];
}
- (IBAction)closeWindow:(id)sender {
......@@ -264,7 +235,7 @@ class ExtensionLoadedNotificationObserver
// Load nib and calculate height based on messages to be shown.
NSWindow* window = [self initializeWindow];
int newWindowHeight = [self calculateWindowHeight];
[infoBubbleView_ setFrameSize:NSMakeSize(
[self.bubble setFrameSize:NSMakeSize(
NSWidth([[window contentView] bounds]), newWindowHeight)];
NSSize windowDelta = NSMakeSize(
0, newWindowHeight - NSHeight([[window contentView] bounds]));
......@@ -277,19 +248,9 @@ class ExtensionLoadedNotificationObserver
[self setMessageFrames:newWindowHeight];
// Find window origin, taking into account bubble size and arrow location.
NSPoint origin =
[parentWindow_ convertBaseToScreen:[self calculateArrowPoint]];
NSSize offsets = NSMakeSize(info_bubble::kBubbleArrowXOffset +
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];
self.anchorPoint =
[self.parentWindow convertBaseToScreen:[self calculateArrowPoint]];
[super showWindow:sender];
}
// Finish nib loading, set arrow location and load icon into window. This
......@@ -298,9 +259,9 @@ class ExtensionLoadedNotificationObserver
NSWindow* window = [self window]; // completes nib load
if (type_ == extension_installed_bubble::kOmniboxKeyword) {
[infoBubbleView_ setArrowLocation:info_bubble::kTopLeft];
[self.bubble setArrowLocation:info_bubble::kTopLeft];
} else {
[infoBubbleView_ setArrowLocation:info_bubble::kTopRight];
[self.bubble setArrowLocation:info_bubble::kTopRight];
}
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