Commit 9d8851d9 authored by rsesek@chromium.org's avatar rsesek@chromium.org

[Mac] Make ExtensionPopupController is-a BaseBubbleController to unify code.

BUG=36366
TEST=Everything about extensions works as before.

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@126911 0039d316-1c4b-4281-b951-d872f2087c98
parent 08376500
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
......@@ -30,7 +30,7 @@ class Bridge;
NSPoint anchor_;
IBOutlet InfoBubbleView* bubble_; // to set arrow position
// Bridge that listens for notifications.
scoped_ptr<BaseBubbleControllerInternal::Bridge> base_bridge_;
scoped_ptr<BaseBubbleControllerInternal::Bridge> baseBridge_;
}
@property(nonatomic, readonly) NSWindow* parentWindow;
......
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
......@@ -119,7 +119,7 @@ class Bridge : public content::NotificationObserver {
DCHECK(bubble_);
DCHECK_EQ(self, [[self window] delegate]);
base_bridge_.reset(new BaseBubbleControllerInternal::Bridge(self));
baseBridge_.reset(new BaseBubbleControllerInternal::Bridge(self));
[bubble_ setArrowLocation:info_bubble::kTopRight];
}
......
......@@ -11,7 +11,8 @@
#import "base/mac/cocoa_protocols.h"
#import "base/memory/scoped_nsobject.h"
#include "base/memory/scoped_ptr.h"
#include "chrome/browser/ui/cocoa/info_bubble_view.h"
#import "chrome/browser/ui/cocoa/base_bubble_controller.h"
#import "chrome/browser/ui/cocoa/info_bubble_view.h"
#include "googleurl/src/gurl.h"
......@@ -19,7 +20,6 @@ class Browser;
class DevtoolsNotificationBridge;
class ExtensionHost;
class ExtensionPopupContainer;
@class InfoBubbleWindow;
namespace content {
class NotificationRegistrar;
......@@ -32,18 +32,11 @@ class NotificationRegistrar;
//
// There can only be one browser action popup open at a time, so a static
// variable holds a reference to the current popup.
@interface ExtensionPopupController : NSWindowController<NSWindowDelegate> {
@interface ExtensionPopupController : BaseBubbleController {
@private
// The native extension view retrieved from the extension host. Weak.
NSView* extensionView_;
// The popup's parent window. Weak.
NSWindow* parentWindow_;
// Where the window is anchored. Right now it's the bottom center of the
// browser action button.
NSPoint anchor_;
// The current frame of the extension view. Cached to prevent setting the
// frame if the size hasn't changed.
NSRect extensionFrame_;
......
......@@ -119,34 +119,6 @@ class DevtoolsNotificationBridge : public content::NotificationObserver {
anchoredAt:(NSPoint)anchoredAt
arrowLocation:(info_bubble::BubbleArrowLocation)arrowLocation
devMode:(BOOL)devMode {
parentWindow_ = parentWindow;
anchor_ = [parentWindow convertBaseToScreen:anchoredAt];
host_.reset(host);
beingInspected_ = devMode;
scoped_nsobject<InfoBubbleView> view([[InfoBubbleView alloc] init]);
if (!view.get())
return nil;
[view setArrowLocation:arrowLocation];
extensionView_ = host->view()->native_view();
container_.reset(new ExtensionPopupContainer(self));
host->view()->set_container(container_.get());
NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
[center addObserver:self
selector:@selector(extensionViewFrameChanged)
name:NSViewFrameDidChangeNotification
object:extensionView_];
// Watch to see if the parent window closes, and if so, close this one.
[center addObserver:self
selector:@selector(parentWindowWillClose:)
name:NSWindowWillCloseNotification
object:parentWindow_];
[view addSubview:extensionView_];
scoped_nsobject<InfoBubbleWindow> window(
[[InfoBubbleWindow alloc]
initWithContentRect:NSZeroRect
......@@ -155,58 +127,63 @@ class DevtoolsNotificationBridge : public content::NotificationObserver {
defer:YES]);
if (!window.get())
return nil;
[window setDelegate:self];
[window setContentView:view];
self = [super initWithWindow:window];
if (beingInspected_) {
// Listen for the the devtools window closing.
notificationBridge_.reset(new DevtoolsNotificationBridge(self));
registrar_.reset(new content::NotificationRegistrar);
registrar_->Add(notificationBridge_.get(),
content::NOTIFICATION_DEVTOOLS_WINDOW_CLOSING,
content::Source<content::BrowserContext>(host->profile()));
registrar_->Add(notificationBridge_.get(),
chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING,
content::Source<Profile>(host->profile()));
anchoredAt = [parentWindow convertBaseToScreen:anchoredAt];
if ((self = [super initWithWindow:window
parentWindow:parentWindow
anchoredAt:anchoredAt])) {
host_.reset(host);
beingInspected_ = devMode;
InfoBubbleView* view = self.bubble;
[view setArrowLocation:arrowLocation];
extensionView_ = host->view()->native_view();
container_.reset(new ExtensionPopupContainer(self));
host->view()->set_container(container_.get());
NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
[center addObserver:self
selector:@selector(extensionViewFrameChanged)
name:NSViewFrameDidChangeNotification
object:extensionView_];
[view addSubview:extensionView_];
if (beingInspected_) {
// Listen for the the devtools window closing.
notificationBridge_.reset(new DevtoolsNotificationBridge(self));
registrar_.reset(new content::NotificationRegistrar);
registrar_->Add(notificationBridge_.get(),
content::NOTIFICATION_DEVTOOLS_WINDOW_CLOSING,
content::Source<content::BrowserContext>(
host->profile()));
registrar_->Add(notificationBridge_.get(),
chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING,
content::Source<Profile>(host->profile()));
}
}
return self;
}
- (void)showDevTools {
DevToolsWindow::OpenDevToolsWindow(host_->render_view_host());
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
[super dealloc];
}
- (void)parentWindowWillClose:(NSNotification*)notification {
[self close];
- (void)showDevTools {
DevToolsWindow::OpenDevToolsWindow(host_->render_view_host());
}
- (void)windowWillClose:(NSNotification *)notification {
[[NSNotificationCenter defaultCenter] removeObserver:self];
[gPopup autorelease];
[super windowWillClose:notification];
gPopup = nil;
if (host_->view())
host_->view()->set_container(NULL);
}
- (void)windowDidResignKey:(NSNotification *)notification {
NSWindow* window = [self window];
DCHECK_EQ([notification object], window);
// If the window isn't visible, it is already closed, and this notification
// has been sent as part of the closing operation, so no need to close.
if ([window isVisible] && !beingInspected_) {
[self close];
}
}
- (void)close {
[[[self window] parentWindow] removeChildWindow:[self window]];
[super close];
- (void)windowDidResignKey:(NSNotification*)notification {
if (!beingInspected_)
[super windowDidResignKey:notification];
}
- (BOOL)isClosing {
......@@ -291,7 +268,7 @@ class DevtoolsNotificationBridge : public content::NotificationObserver {
frame = [extensionView_ convertRectToBase:frame];
// Adjust the origin according to the height and width so that the arrow is
// positioned correctly at the middle and slightly down from the button.
NSPoint windowOrigin = anchor_;
NSPoint windowOrigin = self.anchorPoint;
NSSize offsets = NSMakeSize(info_bubble::kBubbleArrowXOffset +
info_bubble::kBubbleArrowWidth / 2.0,
info_bubble::kBubbleArrowHeight / 2.0);
......@@ -354,16 +331,6 @@ class DevtoolsNotificationBridge : public content::NotificationObserver {
[self onPreferredSizeChanged:pendingPreferredSize_];
}
// We want this to be a child of a browser window. addChildWindow: (called from
// this function) will bring the window on-screen; unfortunately,
// [NSWindowController showWindow:] will also bring it on-screen (but will cause
// unexpected changes to the window's position). We cannot have an
// addChildWindow: and a subsequent showWindow:. Thus, we have our own version.
- (void)showWindow:(id)sender {
[parentWindow_ addChildWindow:[self window] ordered:NSWindowAbove];
[[self window] makeKeyAndOrderFront:self];
}
- (void)windowDidResize:(NSNotification*)notification {
// Let the extension view know, so that it can tell plugins.
if (host_->view())
......
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