diff options
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/app/nibs/en.lproj/MainMenu.xib | 47 | ||||
-rw-r--r-- | chrome/browser/cocoa/bookmark_bar_controller.h | 20 | ||||
-rw-r--r-- | chrome/browser/cocoa/bookmark_bar_controller.mm | 71 | ||||
-rw-r--r-- | chrome/browser/cocoa/browser_window_cocoa.mm | 5 | ||||
-rw-r--r-- | chrome/browser/cocoa/browser_window_cocoa_unittest.mm | 30 | ||||
-rw-r--r-- | chrome/browser/cocoa/browser_window_controller.h | 11 | ||||
-rw-r--r-- | chrome/browser/cocoa/browser_window_controller.mm | 108 | ||||
-rw-r--r-- | chrome/browser/cocoa/browser_window_controller_unittest.mm | 27 | ||||
-rw-r--r-- | chrome/browser/cocoa/fullscreen_window.h | 19 | ||||
-rw-r--r-- | chrome/browser/cocoa/fullscreen_window.mm | 43 | ||||
-rw-r--r-- | chrome/browser/cocoa/fullscreen_window_unittest.mm | 27 | ||||
-rw-r--r-- | chrome/browser/cocoa/tab_contents_controller.h | 3 | ||||
-rw-r--r-- | chrome/browser/cocoa/tab_contents_controller.mm | 8 | ||||
-rw-r--r-- | chrome/chrome.gyp | 5 |
14 files changed, 365 insertions, 59 deletions
diff --git a/chrome/app/nibs/en.lproj/MainMenu.xib b/chrome/app/nibs/en.lproj/MainMenu.xib index 08ab766..41feeeb 100644 --- a/chrome/app/nibs/en.lproj/MainMenu.xib +++ b/chrome/app/nibs/en.lproj/MainMenu.xib @@ -8,7 +8,7 @@ <string key="IBDocument.HIToolboxVersion">353.00</string> <object class="NSMutableArray" key="IBDocument.EditedObjectIDs"> <bool key="EncodedWithXMLCoder">YES</bool> - <integer value="29"/> + <integer value="296"/> </object> <object class="NSArray" key="IBDocument.PluginDependencies"> <bool key="EncodedWithXMLCoder">YES</bool> @@ -750,10 +750,12 @@ <object class="NSMenuItem" id="530225222"> <reference key="NSMenu" ref="466310130"/> <string key="NSTitle">Full Screen</string> - <string key="NSKeyEquiv"/> + <string type="base64-UTF8" key="NSKeyEquiv">75yOA</string> + <int key="NSKeyEquivModMask">1048576</int> <int key="NSMnemonicLoc">2147483647</int> <reference key="NSOnImage" ref="353210768"/> <reference key="NSMixedImage" ref="549394948"/> + <int key="NSTag">34030</int> </object> <object class="NSMenuItem" id="407239884"> <reference key="NSMenu" ref="466310130"/> @@ -1592,6 +1594,14 @@ </object> <object class="IBConnectionRecord"> <object class="IBActionConnection" key="connection"> + <string key="label">commandDispatch:</string> + <reference key="source" ref="1014"/> + <reference key="destination" ref="530225222"/> + </object> + <int key="connectionID">630</int> + </object> + <object class="IBConnectionRecord"> + <object class="IBActionConnection" key="connection"> <string key="label">orderFrontStandardAboutPanel:</string> <reference key="source" ref="168151378"/> <reference key="destination" ref="238522557"/> @@ -2740,7 +2750,7 @@ <reference ref="9"/> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <reference ref="9"/> - <string>{{687, 801}, {243, 263}}</string> + <string>{{647, 825}, {243, 263}}</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <reference ref="9"/> <string>{{197, 734}, {243, 243}}</string> @@ -2790,13 +2800,13 @@ <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <reference ref="9"/> <string>{{525, 802}, {197, 73}}</string> - <string>{{499, 1088}, {535, 20}}</string> + <string>{{530, 1365}, {535, 20}}</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <reference ref="9"/> <string>{74, 862}</string> <string>{{11, 977}, {478, 20}}</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> - <string>{{731, 851}, {273, 213}}</string> + <string>{{722, 1152}, {287, 213}}</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>{{475, 832}, {234, 43}}</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> @@ -2921,7 +2931,7 @@ </object> </object> <nil key="sourceID"/> - <int key="maxID">629</int> + <int key="maxID">630</int> </object> <object class="IBClassDescriber" key="IBDocument.Classes"> <object class="NSMutableArray" key="referencedPartialClassDescriptions"> @@ -2963,6 +2973,31 @@ </object> </object> <object class="IBPartialClassDescription"> + <string key="className">DownloadShelfController</string> + <string key="superclassName">NSViewController</string> + <object class="NSMutableDictionary" key="actions"> + <bool key="EncodedWithXMLCoder">YES</bool> + <object class="NSMutableArray" key="dict.sortedKeys"> + <bool key="EncodedWithXMLCoder">YES</bool> + <string>hide:</string> + <string>show:</string> + </object> + <object class="NSMutableArray" key="dict.values"> + <bool key="EncodedWithXMLCoder">YES</bool> + <string>id</string> + <string>id</string> + </object> + </object> + <object class="NSMutableDictionary" key="outlets"> + <string key="NS.key.0">showAllDownloadsLink_</string> + <string key="NS.object.0">NSTextView</string> + </object> + <object class="IBClassDescriptionSource" key="sourceIdentifier"> + <string key="majorKey">IBProjectSource</string> + <string key="minorKey">browser/cocoa/download_shelf_controller.h</string> + </object> + </object> + <object class="IBPartialClassDescription"> <string key="className">FirstResponder</string> <string key="superclassName">NSObject</string> <object class="NSMutableDictionary" key="actions"> diff --git a/chrome/browser/cocoa/bookmark_bar_controller.h b/chrome/browser/cocoa/bookmark_bar_controller.h index 87ac43e..d7a93d4 100644 --- a/chrome/browser/cocoa/bookmark_bar_controller.h +++ b/chrome/browser/cocoa/bookmark_bar_controller.h @@ -16,6 +16,7 @@ class BookmarkModel; class BookmarkNode; @class BookmarkBarView; class Profile; +class PrefService; // The interface for an object which can open URLs for a bookmark. @protocol BookmarkURLOpener @@ -30,12 +31,18 @@ class Profile; @private BookmarkModel* bookmarkModel_; // weak; part of the profile owned by the // top-level Browser object. + PrefService* preferences_; // (ditto) - // Currently these two are always the same, but they mean slightly - // different things. contentAreaHasOffset_ is an implementation - // detail of bookmark bar visibility. + // Currently these two are always the same when not in fullscreen + // mode, but they mean slightly different things. + // contentAreaHasOffset_ is an implementation detail of bookmark bar + // show state. BOOL contentViewHasOffset_; - BOOL barIsVisible_; + BOOL barShouldBeShown_; + + // If the bar is disabled, we hide it and ignore show/hide commands. + // Set when using fullscreen mode. + BOOL barIsEnabled_; // The view of the bookmark bar itself. // Not made into a scoped_nsobject since I may move it into a nib. @@ -70,6 +77,11 @@ class Profile; // Toggle the state of the bookmark bar. - (void)toggleBookmarkBar; +// Turn on or off the bookmark bar and prevent or reallow its +// appearance. On disable, toggle off if shown. On enable, show only +// if needed. For fullscreen mode. +- (void)setBookmarkBarEnabled:(BOOL)enabled; + @end // Redirects from BookmarkBarBridge, the C++ object which glues us to diff --git a/chrome/browser/cocoa/bookmark_bar_controller.mm b/chrome/browser/cocoa/bookmark_bar_controller.mm index e3a4bed..d2805ec 100644 --- a/chrome/browser/cocoa/bookmark_bar_controller.mm +++ b/chrome/browser/cocoa/bookmark_bar_controller.mm @@ -16,9 +16,9 @@ #include "skia/ext/skia_utils_mac.h" @interface BookmarkBarController(Private) -- (void)applyContentAreaOffset:(BOOL)apply; +- (void)applyContentAreaOffset:(BOOL)apply immediately:(BOOL)immediately; - (void)positionBar; -- (void)showBookmarkBar:(BOOL)enable; +- (void)showBookmarkBar:(BOOL)enable immediately:(BOOL)immediately; @end namespace { @@ -38,13 +38,16 @@ const CGFloat kBookmarkHorizontalPadding = 8.0; bookmarkModel_ = profile->GetBookmarkModel(); contentView_ = content; delegate_ = delegate; + // Be sure to enable the bar before trying to show it... + barIsEnabled_ = YES; // Create and initialize the view's position. Show it if appropriate. // TODO(jrg): put it in a nib if necessary. NSRect frame = NSMakeRect(0, 0, 0, 30); bookmarkBarView_ = [[BookmarkBarView alloc] initWithFrame:frame]; [self positionBar]; - if (profile->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar)) - [self showBookmarkBar:YES]; + preferences_ = profile->GetPrefs(); + if (preferences_->GetBoolean(prefs::kShowBookmarkBar)) + [self showBookmarkBar:YES immediately:NO]; [[[contentView_ window] contentView] addSubview:bookmarkBarView_]; } // Don't pass ourself along until our init is done. @@ -64,7 +67,7 @@ const CGFloat kBookmarkHorizontalPadding = 8.0; - (void)positionBar { // Hide or show bar based on initial visibility and set the resize flags. [bookmarkBarView_ setAutoresizingMask:NSViewWidthSizable | NSViewMinYMargin]; - [bookmarkBarView_ setHidden:!barIsVisible_]; + [bookmarkBarView_ setHidden:!barShouldBeShown_]; // Set the bar's height to zero and position it at the top of the // content area, within the window's content view (as opposed to the @@ -86,16 +89,21 @@ const CGFloat kBookmarkHorizontalPadding = 8.0; [bookmarkBarView_ setFrame:barFrame]; } -// Show or hide the bar based on the value of |enable|. Handles animating the -// resize of the content view. -- (void)showBookmarkBar:(BOOL)enable { - contentViewHasOffset_ = enable; - [bookmarkBarView_ setHidden:enable ? NO : YES]; - [self applyContentAreaOffset:enable]; - - barIsVisible_ = enable; - if (enable) { - [self loaded:bookmarkModel_]; +// Show or hide the bar based on the value of |show|. Handles +// animating the resize of the content view. if |immediately| is YES, +// make changes immediately instead of using an animator. If the bar +// is disabled, do absolutely nothing. The routine which enables the +// bar will show it if relevant using other mechanisms (the pref) to +// determine desired state. +- (void)showBookmarkBar:(BOOL)show immediately:(BOOL)immediately { + if (barIsEnabled_) { + contentViewHasOffset_ = show; + [bookmarkBarView_ setHidden:show ? NO : YES]; + [self applyContentAreaOffset:show immediately:immediately]; + barShouldBeShown_ = show; + if (show) { + [self loaded:bookmarkModel_]; + } } } @@ -103,7 +111,7 @@ const CGFloat kBookmarkHorizontalPadding = 8.0; // bookmark bar. If apply==YES, always make room (the contentView_ is // "full size"). If apply==NO we are trying to undo an offset. If no // offset there is nothing to undo. -- (void)applyContentAreaOffset:(BOOL)apply { +- (void)applyContentAreaOffset:(BOOL)apply immediately:(BOOL)immediately { if (bookmarkBarView_ == nil) { // We're too early, but awakeFromNib will call me again. return; @@ -119,20 +127,41 @@ const CGFloat kBookmarkHorizontalPadding = 8.0; else frame.size.height += kBookmarkBarHeight; - [[contentView_ animator] setFrame:frame]; + if (immediately) { + [contentView_ setFrame:frame]; + [contentView_ setNeedsDisplay:YES]; + } else { + [[contentView_ animator] setFrame:frame]; + } + [bookmarkBarView_ setNeedsDisplay:YES]; [contentView_ setNeedsDisplay:YES]; } - (BOOL)isBookmarkBarVisible { - return barIsVisible_; + return barShouldBeShown_; } // We don't change a preference; we only change visibility. // Preference changing (global state) is handled in // BrowserWindowCocoa::ToggleBookmarkBar(). - (void)toggleBookmarkBar { - [self showBookmarkBar:!barIsVisible_]; + [self showBookmarkBar:!barShouldBeShown_ immediately:NO]; +} + +- (void)setBookmarkBarEnabled:(BOOL)enabled { + if (enabled) { + // Enabling the bar; set enabled then show if needed. + barIsEnabled_ = YES; + if (preferences_->GetBoolean(prefs::kShowBookmarkBar)) + [self showBookmarkBar:YES immediately:YES]; + } else { + // Disabling the bar; hide if visible. + if ([self isBookmarkBarVisible]) { + [self showBookmarkBar:NO immediately:YES]; + } + barIsEnabled_ = NO; + } } // Delete all items from the bookmark bar. @@ -250,8 +279,8 @@ const CGFloat kBookmarkHorizontalPadding = 8.0; // TODO(jrg): for now this is brute force. - (void)loaded:(BookmarkModel*)model { DCHECK(model == bookmarkModel_); - // Do nothing if not visible or too early - if ((barIsVisible_ == NO) || !model->IsLoaded()) + // Do nothing if not active or too early + if ((barShouldBeShown_ == NO) || !model->IsLoaded()) return; // Else brute force nuke and build. const BookmarkNode* node = model->GetBookmarkBarNode(); diff --git a/chrome/browser/cocoa/browser_window_cocoa.mm b/chrome/browser/cocoa/browser_window_cocoa.mm index 1f7c799..fdb40de 100644 --- a/chrome/browser/cocoa/browser_window_cocoa.mm +++ b/chrome/browser/cocoa/browser_window_cocoa.mm @@ -123,12 +123,11 @@ bool BrowserWindowCocoa::IsMaximized() const { } void BrowserWindowCocoa::SetFullscreen(bool fullscreen) { - NOTIMPLEMENTED(); + [controller_ setFullscreen:fullscreen]; } bool BrowserWindowCocoa::IsFullscreen() const { - NOTIMPLEMENTED(); - return false; + return !![controller_ isFullscreen]; } gfx::Rect BrowserWindowCocoa::GetRootWindowResizerRect() const { diff --git a/chrome/browser/cocoa/browser_window_cocoa_unittest.mm b/chrome/browser/cocoa/browser_window_cocoa_unittest.mm index 4308bc2..059be46 100644 --- a/chrome/browser/cocoa/browser_window_cocoa_unittest.mm +++ b/chrome/browser/cocoa/browser_window_cocoa_unittest.mm @@ -90,4 +90,34 @@ TEST_F(BrowserWindowCocoaTest, TestBookmarkBarVisible) { EXPECT_EQ(before, bwc->IsBookmarkBarVisible()); } +@interface FakeController : NSWindowController { + BOOL fullscreen_; +} +@end + +@implementation FakeController +- (void)setFullscreen:(BOOL)fullscreen { + fullscreen_ = fullscreen; +} +- (BOOL)isFullscreen { + return fullscreen_; +} +@end + +TEST_F(BrowserWindowCocoaTest, TestFullscreen) { + scoped_nsobject<FakeController> fake_controller_([[FakeController alloc] + init]); + BrowserWindowCocoaPong *bwc = new BrowserWindowCocoaPong( + browser_helper_.browser(), + (BrowserWindowController*)fake_controller_.get(), + cocoa_helper_.window()); + scoped_ptr<BrowserWindowCocoaPong> scoped_bwc(bwc); + + EXPECT_FALSE(bwc->IsFullscreen()); + bwc->SetFullscreen(true); + EXPECT_TRUE(bwc->IsFullscreen()); + bwc->SetFullscreen(false); + EXPECT_FALSE(bwc->IsFullscreen()); +} + /* TODO(???): test other methods of BrowserWindowCocoa */ diff --git a/chrome/browser/cocoa/browser_window_controller.h b/chrome/browser/cocoa/browser_window_controller.h index ab90f2e..c7b24f1 100644 --- a/chrome/browser/cocoa/browser_window_controller.h +++ b/chrome/browser/cocoa/browser_window_controller.h @@ -44,6 +44,7 @@ class TabStripModelObserverBridge; // their destruction sequence. scoped_ptr<Browser> browser_; scoped_nsobject<NSWindow> window_; + scoped_nsobject<NSWindow> fullscreen_window_; scoped_ptr<TabStripModelObserverBridge> tabObserver_; scoped_ptr<BrowserWindowCocoa> windowShim_; scoped_nsobject<ToolbarController> toolbarController_; @@ -53,6 +54,7 @@ class TabStripModelObserverBridge; scoped_ptr<StatusBubble> statusBubble_; scoped_nsobject<DownloadShelfController> downloadShelfController_; BOOL ownsBrowser_; // Only ever NO when testing + BOOL fullscreen_; } // Load the browser window nib and do any Cocoa-specific initialization. @@ -109,6 +111,12 @@ class TabStripModelObserverBridge; // BrowserWindowController. - (void)addFindBar:(FindBarCocoaController*)findBarCocoaController; +// Enters (or exits) fullscreen mode. +- (void)setFullscreen:(BOOL)fullscreen; + +// Returns fullscreen state. +- (BOOL)isFullscreen; + @end @@ -117,6 +125,9 @@ class TabStripModelObserverBridge; // Allows us to initWithBrowser withOUT taking ownership of the browser. - (id)initWithBrowser:(Browser*)browser takeOwnership:(BOOL)ownIt; +// Return an autoreleased NSWindow suitable for fullscreen use. +- (NSWindow*)fullscreenWindow; + @end // BrowserWindowController(TestingAPI) #endif // CHROME_BROWSER_COCOA_BROWSER_WINDOW_CONTROLLER_H_ diff --git a/chrome/browser/cocoa/browser_window_controller.mm b/chrome/browser/cocoa/browser_window_controller.mm index 6a58402..3532141 100644 --- a/chrome/browser/cocoa/browser_window_controller.mm +++ b/chrome/browser/cocoa/browser_window_controller.mm @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include <Carbon/Carbon.h> + #include "base/mac_util.h" #include "base/scoped_nsdisable_screen_updates.h" #include "base/sys_string_conversions.h" @@ -20,6 +22,7 @@ #import "chrome/browser/cocoa/download_shelf_controller.h" #import "chrome/browser/cocoa/find_bar_cocoa_controller.h" #include "chrome/browser/cocoa/find_bar_bridge.h" +#import "chrome/browser/cocoa/fullscreen_window.h" #import "chrome/browser/cocoa/status_bubble_mac.h" #import "chrome/browser/cocoa/tab_strip_model_observer_bridge.h" #import "chrome/browser/cocoa/tab_strip_view.h" @@ -53,6 +56,7 @@ const int kWindowGradientHeight = 24; @interface BrowserWindowController(Private) - (void)positionToolbar; +- (void)removeToolbar; - (void)installIncognitoBadge; // Leopard's gradient heuristic gets confused by our tabs and makes the title @@ -607,6 +611,63 @@ willPositionSheet:(NSWindow *)sheet [findBarCocoaController_ positionFindBarView:[self tabContentArea]]; } +// Adjust the UI for fullscreen mode. E.g. when going fullscreen, +// remove the toolbar. When stopping fullscreen, add it back in. +- (void)adjustUIForFullscreen:(BOOL)fullscreen { + if (fullscreen) { + // Disable showing of the bookmark bar. This does not toggle the + // preference. + [bookmarkBarController_ setBookmarkBarEnabled:NO]; + // Make room for more content area. + [self removeToolbar]; + // Hide the menubar, and allow it to un-hide when moving the mouse + // to the top of the screen. Does this eliminate the need for an + // info bubble describing how to exit fullscreen mode? + SetSystemUIMode(kUIModeAllHidden, kUIOptionAutoShowMenuBar); + } else { + SetSystemUIMode(kUIModeNormal, 0); + [self positionToolbar]; + [bookmarkBarController_ setBookmarkBarEnabled:YES]; + } +} + +- (NSWindow*)fullscreenWindow { + return [[[FullscreenWindow alloc] initForScreen:[[self window] screen]] + autorelease]; +} + +- (void)setFullscreen:(BOOL)fullscreen { + fullscreen_ = fullscreen; + if (fullscreen) { + // Minimize our UI + [self adjustUIForFullscreen:fullscreen]; + // Move content to a new fullscreen window + NSView* content = [[self window] contentView]; + fullscreen_window_.reset([[self fullscreenWindow] retain]); + [content removeFromSuperview]; + [fullscreen_window_ setContentView:content]; + [self setWindow:fullscreen_window_.get()]; + // Show one window, hide the other. + [fullscreen_window_ makeKeyAndOrderFront:self]; + [content setNeedsDisplay:YES]; + [window_ orderOut:self]; + } else { + [self adjustUIForFullscreen:fullscreen]; + NSView* content = [fullscreen_window_ contentView]; + [content removeFromSuperview]; + [window_ setContentView:content]; + [self setWindow:window_.get()]; + [window_ makeKeyAndOrderFront:self]; + [content setNeedsDisplay:YES]; + [fullscreen_window_ close]; + fullscreen_window_.reset(nil); + } +} + +- (BOOL)isFullscreen { + return fullscreen_; +} + // Called by the bookmark bar to open a URL. - (void)openBookmarkURL:(const GURL&)url disposition:(WindowOpenDisposition)disposition { @@ -661,26 +722,47 @@ willPositionSheet:(NSWindow *)sheet @implementation BrowserWindowController (Private) -// Position |toolbarView_| below the tab strip, but not as a sibling. The -// toolbar is part of the window's contentView, mainly because we want the -// opacity during drags to be the same as the web content. -- (void)positionToolbar { +// If |add| is YES: +// Position |toolbarView_| below the tab strip, but not as a +// sibling. The toolbar is part of the window's contentView, mainly +// because we want the opacity during drags to be the same as the web +// content. This can be used for either the initial add or a +// reposition. +// If |add| is NO: +// Remove the toolbar from it's parent view (the window's content view). +// Called when going fullscreen and we need to minimize UI. +- (void)positionOrRemoveToolbar:(BOOL)add { NSView* contentView = [self tabContentArea]; NSRect contentFrame = [contentView frame]; NSView* toolbarView = [toolbarController_ view]; NSRect toolbarFrame = [toolbarView frame]; - // Shrink the content area by the height of the toolbar. - contentFrame.size.height -= toolbarFrame.size.height; + // Shrink or grow the content area by the height of the toolbar. + if (add) + contentFrame.size.height -= toolbarFrame.size.height; + else + contentFrame.size.height += toolbarFrame.size.height; [contentView setFrame:contentFrame]; - // Move the toolbar above the content area, within the window's content view - // (as opposed to the tab strip, which is a sibling). - toolbarFrame.origin.y = NSMaxY(contentFrame); - toolbarFrame.origin.x = 0; - toolbarFrame.size.width = contentFrame.size.width; - [toolbarView setFrame:toolbarFrame]; - [[[self window] contentView] addSubview:toolbarView]; + if (add) { + // Move the toolbar above the content area, within the window's content view + // (as opposed to the tab strip, which is a sibling). + toolbarFrame.origin.y = NSMaxY(contentFrame); + toolbarFrame.origin.x = 0; + toolbarFrame.size.width = contentFrame.size.width; + [toolbarView setFrame:toolbarFrame]; + [[[self window] contentView] addSubview:toolbarView]; + } else { + [toolbarView removeFromSuperview]; + } +} + +- (void)positionToolbar { + [self positionOrRemoveToolbar:YES]; +} + +- (void)removeToolbar { + [self positionOrRemoveToolbar:NO]; } // If the browser is in incognito mode, install the image view to decordate diff --git a/chrome/browser/cocoa/browser_window_controller_unittest.mm b/chrome/browser/cocoa/browser_window_controller_unittest.mm index 0dff06d..d640922 100644 --- a/chrome/browser/cocoa/browser_window_controller_unittest.mm +++ b/chrome/browser/cocoa/browser_window_controller_unittest.mm @@ -50,4 +50,31 @@ TEST_F(BrowserWindowControllerTest, TestSaveWindowPosition) { EXPECT_TRUE(prefs->GetDictionary(prefs::kBrowserWindowPlacement) != NULL); } +@interface BrowserWindowControllerFakeFullscreen : BrowserWindowController { +} +@end +@implementation BrowserWindowControllerFakeFullscreen +// This isn't needed to pass the test, but does prevent an actual +// fullscreen from happening. +- (NSWindow*)fullscreenWindow { + return nil; +} +@end + +TEST_F(BrowserWindowControllerTest, TestFullscreen) { + // Note use of "controller", not "controller_" + scoped_nsobject<BrowserWindowController> controller; + controller.reset([[BrowserWindowControllerFakeFullscreen alloc] + initWithBrowser:browser_helper_.browser() + takeOwnership:NO]); + EXPECT_FALSE([controller isFullscreen]); + [controller setFullscreen:YES]; + EXPECT_TRUE([controller isFullscreen]); + [controller setFullscreen:NO]; + EXPECT_FALSE([controller isFullscreen]); + + // Confirm the real fullscreen command doesn't return nil + EXPECT_TRUE([controller_ fullscreenWindow]); +} + /* TODO(???): test other methods of BrowserWindowController */ diff --git a/chrome/browser/cocoa/fullscreen_window.h b/chrome/browser/cocoa/fullscreen_window.h new file mode 100644 index 0000000..1f944e4 --- /dev/null +++ b/chrome/browser/cocoa/fullscreen_window.h @@ -0,0 +1,19 @@ +// Copyright (c) 2009 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. + +#include <Cocoa/Cocoa.h> + +// A FullscreenWindow is a borderless window suitable for going +// fullscreen. The returned window is NOT release when closed and is +// not initially visible. +@interface FullscreenWindow : NSWindow + +// Initialize a FullscreenWindow for the given screen. +// Designated initializer. +- (id)initForScreen:(NSScreen*)screen; + +@end + + + diff --git a/chrome/browser/cocoa/fullscreen_window.mm b/chrome/browser/cocoa/fullscreen_window.mm new file mode 100644 index 0000000..3c5fbdb --- /dev/null +++ b/chrome/browser/cocoa/fullscreen_window.mm @@ -0,0 +1,43 @@ +// Copyright (c) 2009 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. + +#include "chrome/browser/cocoa/fullscreen_window.h" + +@implementation FullscreenWindow + +// Make sure our designated initializer gets called. +- (id)init { + return [self initForScreen:[NSScreen mainScreen]]; +} + +- (id)initForScreen:(NSScreen*)screen { + NSRect contentRect; + contentRect.origin = NSZeroPoint; + contentRect.size = [screen frame].size; + + if ((self = [super initWithContentRect:contentRect + styleMask:NSBorderlessWindowMask + backing:NSBackingStoreBuffered + defer:YES + screen:screen])) { + [self setReleasedWhenClosed:NO]; + } + return self; +} + +// According to +// http://www.cocoabuilder.com/archive/message/cocoa/2006/6/19/165953, +// NSBorderlessWindowMask windows cannot become key or main. +// In our case, however, we don't want that behavior, so we override +// canBecomeKeyWindow and canBecomeMainWindow. + +- (BOOL)canBecomeKeyWindow { + return YES; +} + +- (BOOL)canBecomeMainWindow { + return YES; +} + +@end diff --git a/chrome/browser/cocoa/fullscreen_window_unittest.mm b/chrome/browser/cocoa/fullscreen_window_unittest.mm new file mode 100644 index 0000000..c12f1fd --- /dev/null +++ b/chrome/browser/cocoa/fullscreen_window_unittest.mm @@ -0,0 +1,27 @@ +// Copyright (c) 2009 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. + +#include "base/scoped_ptr.h" +#include "chrome/browser/cocoa/cocoa_test_helper.h" +#include "chrome/browser/cocoa/fullscreen_window.h" +#include "testing/gtest/include/gtest/gtest.h" + +class FullscreenWindowTest : public testing::Test { + public: + CocoaTestHelper cocoa_helper_; +}; + +TEST_F(FullscreenWindowTest, Basics) { + scoped_nsobject<FullscreenWindow> window_; + window_.reset([[FullscreenWindow alloc] init]); + + EXPECT_EQ([NSScreen mainScreen], [window_ screen]); + EXPECT_TRUE([window_ canBecomeKeyWindow]); + EXPECT_TRUE([window_ canBecomeMainWindow]); + EXPECT_EQ(NSBorderlessWindowMask, [window_ styleMask]); + EXPECT_FALSE([window_ isReleasedWhenClosed]); + EXPECT_TRUE(NSEqualRects([[NSScreen mainScreen] frame], [window_ frame])); +} + + diff --git a/chrome/browser/cocoa/tab_contents_controller.h b/chrome/browser/cocoa/tab_contents_controller.h index 0cd2e2c..f79b9ea 100644 --- a/chrome/browser/cocoa/tab_contents_controller.h +++ b/chrome/browser/cocoa/tab_contents_controller.h @@ -27,9 +27,6 @@ class TabStripModel; - (id)initWithNibName:(NSString*)name contents:(TabContents*)contents; -// Take this view (toolbar and web contents) full screen -- (IBAction)fullScreen:(id)sender; - // Called when the tab contents is about to be put into the view hierarchy as // the selected tab. Handles things such as ensuring the toolbar is correctly // enabled. diff --git a/chrome/browser/cocoa/tab_contents_controller.mm b/chrome/browser/cocoa/tab_contents_controller.mm index a51796d..b2ac634 100644 --- a/chrome/browser/cocoa/tab_contents_controller.mm +++ b/chrome/browser/cocoa/tab_contents_controller.mm @@ -37,14 +37,6 @@ return [[self view] superview] ? YES : NO; } -- (IBAction)fullScreen:(id)sender { - if ([[self view] isInFullScreenMode]) { - [[self view] exitFullScreenModeWithOptions:nil]; - } else { - [[self view] enterFullScreenMode:[NSScreen mainScreen] withOptions:nil]; - } -} - - (void)willBecomeSelectedTab { } diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp index a94f441..e221965 100644 --- a/chrome/chrome.gyp +++ b/chrome/chrome.gyp @@ -742,6 +742,8 @@ 'browser/cocoa/find_bar_view.mm', 'browser/cocoa/first_run_dialog.h', 'browser/cocoa/first_run_dialog.mm', + 'browser/cocoa/fullscreen_window.h', + 'browser/cocoa/fullscreen_window.mm', 'browser/cocoa/gradient_button_cell.h', 'browser/cocoa/gradient_button_cell.mm', 'browser/cocoa/hung_renderer_controller.h', @@ -3407,6 +3409,7 @@ 'browser/cocoa/find_bar_bridge_unittest.mm', 'browser/cocoa/find_bar_cocoa_controller_unittest.mm', 'browser/cocoa/find_bar_view_unittest.mm', + 'browser/cocoa/fullscreen_window_unittest.mm', 'browser/cocoa/hung_renderer_controller_unittest.mm', 'browser/cocoa/location_bar_cell_unittest.mm', 'browser/cocoa/location_bar_view_mac_unittest.mm', @@ -3631,7 +3634,7 @@ 'browser/tab_contents/navigation_controller_unittest.cc', 'browser/task_manager_unittest.cc', 'third_party/hunspell/google/hunspell_tests.cc', - + # Compact Language Detection (cld) is not supported in mac yet. '../third_party/cld/bar/toolbar/cld/i18n/encodings/compact_lang_det/compact_lang_det_unittest_small.cc', ], |