Commit adb3145c authored by sail@chromium.org's avatar sail@chromium.org

Cocoa: Support constrained windows for platform apps

This CL adds support for constrained windows to ShellWindowController which is used by platform apps.

BUG=140593
TEST=Verified that constrained windows on tab windows still work. Ran the media gallery test app and verified that opening constrained windows inside a shell window worked.


Review URL: https://chromiumcodereview.appspot.com/10823176

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@151191 0039d316-1c4b-4281-b951-d872f2087c98
parent b1c225fa
......@@ -18,6 +18,7 @@
#import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.h"
#import "chrome/browser/ui/cocoa/bookmarks/bookmark_bubble_controller.h"
#import "chrome/browser/ui/cocoa/browser_command_executor.h"
#import "chrome/browser/ui/cocoa/constrained_window_mac.h"
#import "chrome/browser/ui/cocoa/fullscreen_exit_bubble_controller.h"
#import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h"
#import "chrome/browser/ui/cocoa/tabs/tab_window_controller.h"
......@@ -31,7 +32,6 @@ class Browser;
class BrowserWindow;
class BrowserWindowCocoa;
@class ChromeToMobileBubbleController;
class ConstrainedWindowMac;
@class DevToolsController;
@class DownloadShelfController;
@class FindBarCocoaController;
......@@ -55,7 +55,8 @@ class WebContents;
BookmarkBarControllerDelegate,
BrowserCommandExecutor,
ViewResizer,
TabStripControllerDelegate> {
TabStripControllerDelegate,
ConstrainedWindowSupport> {
@private
// The ordering of these members is important as it determines the order in
// which they are destroyed. |browser_| needs to be destroyed last as most of
......
......@@ -12,12 +12,28 @@
#include "base/memory/scoped_nsobject.h"
#include "chrome/browser/ui/constrained_window.h"
@class BrowserWindowController;
class ConstrainedWindowMac;
@class GTMWindowSheetController;
@class NSView;
@class NSWindow;
class TabContents;
// Window controllers that allow hosting constrained windows should
// implement this protocol.
@protocol ConstrainedWindowSupport
// Requests that |window| is opened as a per-tab sheet to the current tab.
- (void)attachConstrainedWindow:(ConstrainedWindowMac*)window;
// Closes the tab sheet |window| and potentially shows the next sheet in the
// tab's sheet queue.
- (void)removeConstrainedWindow:(ConstrainedWindowMac*)window;
// Returns NO if constrained windows cannot be attached to this window.
- (BOOL)canAttachConstrainedWindow;
@end
// Base class for constrained dialog delegates. Never inherit from this
// directly.
class ConstrainedWindowMacDelegate {
......@@ -124,7 +140,7 @@ class ConstrainedWindowMac : public ConstrainedWindow {
ConstrainedWindowMacDelegate* delegate() { return delegate_; }
// Makes the constrained window visible, if it is not yet visible.
void Realize(BrowserWindowController* controller);
void Realize(NSWindowController<ConstrainedWindowSupport>* controller);
private:
friend class ConstrainedWindow;
......@@ -136,7 +152,7 @@ class ConstrainedWindowMac : public ConstrainedWindow {
ConstrainedWindowMacDelegate* delegate_;
// Controller of the window that contains this sheet.
BrowserWindowController* controller_;
NSWindowController<ConstrainedWindowSupport>* controller_;
// Stores if |ShowConstrainedWindow()| was called.
bool should_be_visible_;
......
......@@ -4,7 +4,6 @@
#include "chrome/browser/ui/cocoa/constrained_window_mac.h"
#import "chrome/browser/ui/cocoa/browser_window_controller.h"
#include "chrome/browser/ui/constrained_window_tab_helper.h"
#include "chrome/browser/ui/tab_contents/tab_contents.h"
#include "content/public/browser/web_contents.h"
......@@ -105,12 +104,26 @@ void ConstrainedWindowMac::ShowConstrainedWindow() {
// The WebContents only has a native window if it is currently visible. In
// this case, open the sheet now. Else, Realize() will be called later, when
// our tab becomes visible.
NSWindow* browserWindow =
NSWindow* window =
tab_contents_->web_contents()->GetView()->GetTopLevelNativeWindow();
BrowserWindowController* browser_controller =
[BrowserWindowController browserWindowControllerForWindow:browserWindow];
if ([browser_controller canAttachConstrainedWindow])
Realize(browser_controller);
NSWindowController<ConstrainedWindowSupport>* window_controller = nil;
while (window) {
if ([[window windowController] conformsToProtocol:
@protocol(ConstrainedWindowSupport)]) {
window_controller = [window windowController];
break;
}
window = [window parentWindow];
}
// It's valid for the window to be nil. For example, background tabs don't
// have a window set. However, if a window exists then there should always
// be a window controller that implements the ConstrainedWindowSupport
// protocol.
DCHECK(!window || window_controller);
if ([window_controller canAttachConstrainedWindow])
Realize(window_controller);
}
void ConstrainedWindowMac::CloseConstrainedWindow() {
......@@ -131,7 +144,8 @@ void ConstrainedWindowMac::CloseConstrainedWindow() {
delete this;
}
void ConstrainedWindowMac::Realize(BrowserWindowController* controller) {
void ConstrainedWindowMac::Realize(
NSWindowController<ConstrainedWindowSupport>* controller) {
if (!should_be_visible_)
return;
......
......@@ -9,18 +9,25 @@
#include <vector>
#include "base/memory/scoped_nsobject.h"
#include "chrome/browser/ui/cocoa/constrained_window_mac.h"
#include "chrome/browser/ui/extensions/shell_window.h"
#include "chrome/common/extensions/draggable_region.h"
#include "ui/gfx/rect.h"
#import "third_party/GTM/AppKit/GTMWindowSheetController.h"
class Profile;
class ShellWindowCocoa;
// A window controller for a minimal window to host a web app view. Passes
// Objective-C notifications to the C++ bridge.
@interface ShellWindowController : NSWindowController<NSWindowDelegate> {
@interface ShellWindowController : NSWindowController
<NSWindowDelegate,
GTMWindowSheetControllerDelegate,
ConstrainedWindowSupport> {
@private
ShellWindowCocoa* shellWindow_; // Weak; owns self.
// Manages per-window sheets.
scoped_nsobject<GTMWindowSheetController> sheetController_;
}
@property(assign, nonatomic) ShellWindowCocoa* shellWindow;
......
......@@ -9,6 +9,7 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/cocoa/browser_window_utils.h"
#include "chrome/browser/ui/cocoa/extensions/extension_view_mac.h"
#include "chrome/browser/ui/tab_contents/tab_contents.h"
#include "chrome/common/extensions/extension.h"
#include "content/public/browser/render_widget_host_view.h"
#include "content/public/browser/web_contents.h"
......@@ -48,6 +49,29 @@
shellWindow_->WindowDidResignKey();
}
- (void)gtm_systemRequestsVisibilityForView:(NSView*)view {
[[self window] makeKeyAndOrderFront:self];
}
- (void)attachConstrainedWindow:(ConstrainedWindowMac*)window {
if (!sheetController_.get()) {
sheetController_.reset([[GTMWindowSheetController alloc]
initWithWindow:[self window]
delegate:self]);
}
NSView* tabContentsView =
[window->owner()->web_contents()->GetNativeView() superview];
window->delegate()->RunSheet(sheetController_, tabContentsView);
}
- (void)removeConstrainedWindow:(ConstrainedWindowMac*)window {
}
- (BOOL)canAttachConstrainedWindow {
return YES;
}
@end
@interface ShellNSWindow : UnderlayOpenGLHostingWindow
......
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