diff options
author | viettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-12 03:51:11 +0000 |
---|---|---|
committer | viettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-12 03:51:11 +0000 |
commit | 1ce4d64fbdf3bcc6bb8124eae5d98d7d978abf03 (patch) | |
tree | 6ea4abdd5a9c9380f70a90a5f0715ad894dfdd2a /chrome/browser | |
parent | 6c7c90919e51243c91e11ef6f4b14f9d6857fdfc (diff) | |
download | chromium_src-1ce4d64fbdf3bcc6bb8124eae5d98d7d978abf03.zip chromium_src-1ce4d64fbdf3bcc6bb8124eae5d98d7d978abf03.tar.gz chromium_src-1ce4d64fbdf3bcc6bb8124eae5d98d7d978abf03.tar.bz2 |
Mac: remove extension shelf code.
Otherwise, I'll shortly have to update it and test other changes against the extension shelf (or let bitrot set in).
The extension shelf was removed from Chrome/Chromium. This code was left in for possible future use since doing so posed no cost. The corresponding code remains in the Windows version (for experimental purposes), but has also been removed from the Linux version. If this code is ever needed again, this patch will be the one to try to revert.
BUG=30178
TEST=Trybots, to make sure everything still compiles and unit tests run cleanly.
Review URL: http://codereview.chromium.org/495004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@34407 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
6 files changed, 4 insertions, 499 deletions
diff --git a/chrome/browser/cocoa/browser_window_controller.h b/chrome/browser/cocoa/browser_window_controller.h index 72fa734..988b53f 100644 --- a/chrome/browser/cocoa/browser_window_controller.h +++ b/chrome/browser/cocoa/browser_window_controller.h @@ -29,7 +29,6 @@ class BrowserWindowCocoa; @class ChromeBrowserWindow; class ConstrainedWindowMac; @class DownloadShelfController; -@class ExtensionShelfController; @class FindBarCocoaController; @class GTMWindowSheetController; @class InfoBarContainerController; @@ -65,7 +64,6 @@ class TabStripModelObserverBridge; scoped_nsobject<FindBarCocoaController> findBarCocoaController_; scoped_nsobject<InfoBarContainerController> infoBarContainerController_; scoped_nsobject<DownloadShelfController> downloadShelfController_; - scoped_nsobject<ExtensionShelfController> extensionShelfController_; scoped_nsobject<BookmarkBarController> bookmarkBarController_; // Strong. StatusBubble is a special case of a strong reference that diff --git a/chrome/browser/cocoa/browser_window_controller.mm b/chrome/browser/cocoa/browser_window_controller.mm index e3682a9..bb615ac 100644 --- a/chrome/browser/cocoa/browser_window_controller.mm +++ b/chrome/browser/cocoa/browser_window_controller.mm @@ -31,7 +31,6 @@ #import "chrome/browser/cocoa/chrome_browser_window.h" #import "chrome/browser/cocoa/download_shelf_controller.h" #import "chrome/browser/cocoa/event_utils.h" -#import "chrome/browser/cocoa/extension_shelf_controller.h" #import "chrome/browser/cocoa/fast_resize_view.h" #import "chrome/browser/cocoa/find_bar_cocoa_controller.h" #include "chrome/browser/cocoa/find_bar_bridge.h" @@ -265,15 +264,6 @@ willPositionSheet:(NSWindow*)sheet // |-awakeFromNib|. [self updateBookmarkBarVisibilityWithAnimation:NO]; - if (browser_->SupportsWindowFeature(Browser::FEATURE_EXTENSIONSHELF)) { - // Create the extension shelf. - extensionShelfController_.reset([[ExtensionShelfController alloc] - initWithBrowser:browser_.get() - resizeDelegate:self]); - [[[self window] contentView] addSubview:[extensionShelfController_ view]]; - [extensionShelfController_ wasInsertedIntoWindow]; - } - // Force a relayout of all the various bars. [self layoutSubviews]; @@ -651,7 +641,6 @@ willPositionSheet:(NSWindow*)sheet DCHECK(view); DCHECK(view == [toolbarController_ view] || view == [infoBarContainerController_ view] || - view == [extensionShelfController_ view] || view == [downloadShelfController_ view] || view == [bookmarkBarController_ view]); @@ -1646,17 +1635,7 @@ willPositionSheet:(NSWindow*)sheet [bookmarkBarController_ layoutSubviews]; } - // Place the extension shelf at the bottom of the view, if it exists. - if (extensionShelfController_.get()) { - NSView* extensionView = [extensionShelfController_ view]; - NSRect extensionFrame = [extensionView frame]; - extensionFrame.origin.y = minY; - extensionFrame.size.width = NSWidth(contentFrame); - [extensionView setFrame:extensionFrame]; - minY += NSHeight(extensionFrame); - } - - // Place the download shelf above the extension shelf, if it exists. + // If there's a download shelf, place it at the bottom of the view. if (downloadShelfController_.get()) { NSView* downloadView = [downloadShelfController_ view]; NSRect downloadFrame = [downloadView frame]; diff --git a/chrome/browser/cocoa/browser_window_controller_unittest.mm b/chrome/browser/cocoa/browser_window_controller_unittest.mm index 394ef1d..5ad4050 100644 --- a/chrome/browser/cocoa/browser_window_controller_unittest.mm +++ b/chrome/browser/cocoa/browser_window_controller_unittest.mm @@ -32,7 +32,6 @@ - (NSView*)toolbarView; - (NSView*)bookmarkView; - (BOOL)bookmarkBarVisible; -- (NSView*)extensionShelfView; @end @implementation BrowserWindowController (ExposedForTesting) @@ -55,10 +54,6 @@ - (BOOL)bookmarkBarVisible { return [bookmarkBarController_ isVisible]; } - -- (NSView*)extensionShelfView { - return [extensionShelfController_ view]; -} @end class BrowserWindowControllerTest : public CocoaTest { @@ -166,18 +161,16 @@ TEST_F(BrowserWindowControllerTest, TestIncognitoWidthSpace) { #endif namespace { -// Verifies that the toolbar, infobar, tab content area, download shelf, and -// extension shelf completely fill their window's contentView. +// Verifies that the toolbar, infobar, tab content area, and download shelf +// completely fill their window's contentView. void CheckViewPositions(BrowserWindowController* controller) { NSRect contentView = [[[controller window] contentView] bounds]; NSRect toolbar = [[controller toolbarView] frame]; NSRect infobar = [[controller infoBarContainerView] frame]; NSRect contentArea = [[controller tabContentArea] frame]; NSRect download = [[[controller downloadShelf] view] frame]; - NSRect extension = [[controller extensionShelfView] frame]; - EXPECT_EQ(NSMinY(contentView), NSMinY(extension)); - EXPECT_EQ(NSMaxY(extension), NSMinY(download)); + EXPECT_EQ(NSMinY(contentView), NSMinY(download)); EXPECT_EQ(NSMaxY(download), NSMinY(contentArea)); EXPECT_EQ(NSMaxY(contentArea), NSMinY(infobar)); @@ -326,7 +319,6 @@ TEST_F(BrowserWindowControllerTest, TestResizeViews) { NSView* contentView = [[tabstrip window] contentView]; NSView* toolbar = [controller_ toolbarView]; NSView* infobar = [controller_ infoBarContainerView]; - NSView* extensionShelf = [controller_ extensionShelfView]; // We need to muck with the views a bit to put us in a consistent state before // we start resizing. In particular, we need to move the tab strip to be @@ -347,10 +339,6 @@ TEST_F(BrowserWindowControllerTest, TestResizeViews) { [controller_ layoutSubviews]; CheckViewPositions(controller_); - // Add an extension shelf and recheck. - [controller_ resizeView:extensionShelf newHeight:40]; - CheckViewPositions(controller_); - // Expand the infobar to 60px and recheck [controller_ resizeView:infobar newHeight:60]; CheckViewPositions(controller_); @@ -380,7 +368,6 @@ TEST_F(BrowserWindowControllerTest, TestResizeViewsWithBookmarkBar) { NSView* toolbar = [controller_ toolbarView]; NSView* bookmark = [controller_ bookmarkView]; NSView* infobar = [controller_ infoBarContainerView]; - NSView* extensionShelf = [controller_ extensionShelfView]; // We need to muck with the views a bit to put us in a consistent state before // we start resizing. In particular, we need to move the tab strip to be @@ -405,10 +392,6 @@ TEST_F(BrowserWindowControllerTest, TestResizeViewsWithBookmarkBar) { [controller_ resizeView:bookmark newHeight:40]; CheckViewPositions(controller_); - // Add an extension shelf and recheck. - [controller_ resizeView:extensionShelf newHeight:40]; - CheckViewPositions(controller_); - // Expand the infobar to 60px and recheck [controller_ resizeView:infobar newHeight:60]; CheckViewPositions(controller_); diff --git a/chrome/browser/cocoa/extension_shelf_controller.h b/chrome/browser/cocoa/extension_shelf_controller.h deleted file mode 100644 index a533c7a..0000000 --- a/chrome/browser/cocoa/extension_shelf_controller.h +++ /dev/null @@ -1,49 +0,0 @@ -// 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. - -#import <Cocoa/Cocoa.h> - -#include "base/scoped_ptr.h" -#import "chrome/browser/cocoa/view_resizer.h" - -class Browser; -class ExtensionShelfMac; - -// A controller for the extension shelf. After creating on object of this class, -// insert its |view| into a superview and call |wasInsertedIntoWindow|. After -// that, the controller automatically registers itself in the extensions -// subsystem and manages displaying toolstrips in the extension shelf. -@interface ExtensionShelfController : NSViewController { - @private - CGFloat shelfHeight_; - - scoped_ptr<ExtensionShelfMac> bridge_; - - // Delegate that handles resizing our view. - id<ViewResizer> resizeDelegate_; - - Browser* browser_; -} - -// Initializes a new ExtensionShelfController. -- (id)initWithBrowser:(Browser*)browser - resizeDelegate:(id<ViewResizer>)resizeDelegate; - -// Makes the extension shelf view managed by this class visible. -- (IBAction)show:(id)sender; - -// Makes the extension shelf view managed by this class invisible. -- (IBAction)hide:(id)sender; - -// Returns the height this shelf has when it's visible (which is different from -// the frame's height if the shelf is hidden). -- (CGFloat)height; - -// Call this once this shelf's view has been inserted into a superview. It will -// create the internal bridge object to chrome's extension system and call -// cacheDisplayInRect:toBitmapImageRep: on the |view|, which requires that it is -// in a superview. -- (void)wasInsertedIntoWindow; - -@end diff --git a/chrome/browser/cocoa/extension_shelf_controller.mm b/chrome/browser/cocoa/extension_shelf_controller.mm deleted file mode 100644 index da02fae..0000000 --- a/chrome/browser/cocoa/extension_shelf_controller.mm +++ /dev/null @@ -1,356 +0,0 @@ -// 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. - -#import "extension_shelf_controller.h" - -#include "base/mac_util.h" -#include "chrome/browser/browser.h" -#include "chrome/browser/extensions/extension_shelf_model.h" -#include "skia/ext/skia_utils_mac.h" - -namespace { - -const int kExtensionShelfPaddingTop = 1; -const int kToolstripPadding = 2; - -} - -// This class manages the extensions ("toolstrips") on the shelf. It listens to -// events sent by the extension system, and acts as a bridge between that and -// the cocoa world. -class ExtensionShelfMac : public ExtensionShelfModelObserver { - public: - ExtensionShelfMac(Browser* browser, ExtensionShelfController* controller); - virtual ~ExtensionShelfMac(); - - // ExtensionShelfModelObserver - virtual void ToolstripInsertedAt(ExtensionHost* toolstrip, int index); - virtual void ToolstripRemovingAt(ExtensionHost* toolstrip, int index); - virtual void ToolstripMoved(ExtensionHost* toolstrip, - int from_index, - int to_index); - virtual void ToolstripChangedAt(ExtensionHost* toolstrip, int index); - virtual void ExtensionShelfEmpty(); - virtual void ShelfModelReloaded(); - virtual void ShelfModelDeleting(); - - // Determines what is our target height and sets it. - void AdjustHeight(); - - private: - class Toolstrip; - - void Show(); - void Hide(); - - // Create the contents of the extension shelf. - void Init(Profile* profile); - - // Loads the background image into memory, or does nothing if already loaded. - void InitBackground(); - - // Re-inserts all toolstrips from the model. Must be called when the shelf - // contains no toolstrips. - void LoadFromModel(); - - void DeleteToolstrips(); - - Toolstrip* ToolstripAtIndex(int index); - - ExtensionShelfController* controller_; // weak, owns us - - Browser* browser_; // weak - - // Lazily-initialized background for toolstrips. - scoped_ptr<SkBitmap> background_; - - // The model representing the toolstrips on the shelf. - ExtensionShelfModel* model_; // weak - - // Set of toolstrip views which are really on the shelf. - std::set<Toolstrip*> toolstrips_; - - // Stores if we are currently layouting items. - bool is_adjusting_height_; - - DISALLOW_COPY_AND_ASSIGN(ExtensionShelfMac); -}; - -// This class represents a single extension ("toolstrip") on the extension -// shelf. -class ExtensionShelfMac::Toolstrip { - public: - explicit Toolstrip(ExtensionHost* host) - : host_(host) { - DCHECK(host_->view()); - Init(); - } - - // Inserts the native NSView belonging to this extension into the view that - // belongs to |controller|. Makes sure the controller is notified when the - // extension's |frame| changes. - void AddToolstripToController(ExtensionShelfController* controller); - - // Removes the native NSView belonging to this extension from the view that - // belongs to |controller|. Removes |controller| as a frame size observer. - void RemoveToolstripFromController(ExtensionShelfController* controller); - - // Sets the image that is used by the extension. - void SetBackground(const SkBitmap& background) { - host_->view()->SetBackground(background); - } - - // Returns the native NSView belonging to this extension. - gfx::NativeView native_view() { - return host_->view()->native_view(); - } - - private: - void Init(); - - ExtensionHost* host_; // weak - - const std::string extension_name_; - - private: - DISALLOW_COPY_AND_ASSIGN(Toolstrip); -}; - -void ExtensionShelfMac::Toolstrip::AddToolstripToController( - ExtensionShelfController* controller) { - NSView* toolstrip_view = host_->view()->native_view(); - [[controller view] addSubview:toolstrip_view]; - - [[NSNotificationCenter defaultCenter] - addObserver:controller - selector:@selector(updateVisibility:) - name:NSViewFrameDidChangeNotification - object:toolstrip_view]; -} - -void ExtensionShelfMac::Toolstrip::RemoveToolstripFromController( - ExtensionShelfController* controller) { - [host_->view()->native_view() removeFromSuperview]; - - [[NSNotificationCenter defaultCenter] - removeObserver:controller - name:NSViewFrameDidChangeNotification - object:host_->view()->native_view()]; -} - -void ExtensionShelfMac::Toolstrip::Init() { - host_->view()->set_is_toolstrip(true); -} - -ExtensionShelfMac::ExtensionShelfMac(Browser* browser, - ExtensionShelfController* controller) - : controller_(controller), - browser_(browser), - model_(browser->extension_shelf_model()), - is_adjusting_height_(false) { - if (model_) // Can be NULL in tests. - Init(browser_->profile()); -} - -ExtensionShelfMac::~ExtensionShelfMac() { - DeleteToolstrips(); - if (model_) - model_->RemoveObserver(this); -} - -void ExtensionShelfMac::Show() { - [controller_ show:nil]; -} - -void ExtensionShelfMac::Hide() { - [controller_ hide:nil]; -} - -void ExtensionShelfMac::ToolstripInsertedAt(ExtensionHost* host, - int index) { - InitBackground(); - Toolstrip* toolstrip = new Toolstrip(host); - toolstrip->SetBackground(*background_.get()); - toolstrip->AddToolstripToController(controller_); - toolstrips_.insert(toolstrip); - model_->SetToolstripDataAt(index, toolstrip); - - AdjustHeight(); -} - -void ExtensionShelfMac::ToolstripRemovingAt(ExtensionHost* host, - int index) { - Toolstrip* toolstrip = ToolstripAtIndex(index); - toolstrip->RemoveToolstripFromController(controller_); - toolstrips_.erase(toolstrip); - model_->SetToolstripDataAt(index, NULL); - delete toolstrip; - - AdjustHeight(); -} - -void ExtensionShelfMac::ToolstripMoved(ExtensionHost* host, - int from_index, - int to_index) { - // TODO(thakis): Implement reordering toolstrips. - AdjustHeight(); -} - -void ExtensionShelfMac::ToolstripChangedAt( - ExtensionHost* toolstrip, int index) { - // TODO(thakis): Implement changing toolstrips. - AdjustHeight(); -} - -void ExtensionShelfMac::ExtensionShelfEmpty() { - AdjustHeight(); -} - -void ExtensionShelfMac::ShelfModelReloaded() { - DeleteToolstrips(); - LoadFromModel(); -} - -void ExtensionShelfMac::ShelfModelDeleting() { - DeleteToolstrips(); - model_->RemoveObserver(this); - model_ = NULL; -} - -void ExtensionShelfMac::Init(Profile* profile) { - LoadFromModel(); - model_->AddObserver(this); -} - -void ExtensionShelfMac::InitBackground() { - if (background_.get()) - return; - - // If this is called while the shelf is invisible, shortly resize the shelf so - // that it can paint itself. - NSRect current_frame = [[controller_ view] frame]; - if (current_frame.size.height < [controller_ height]) { - NSRect new_frame = current_frame; - new_frame.size.height = [controller_ height]; - [[controller_ view] setFrame:new_frame]; - } - - // The background is tiled horizontally in the toolstrip. Hence, its width - // should not be too small so that tiling is fast, and not too large, so that - // not too much memory is needed -- but the exact width doesn't really matter. - const CGFloat kBackgroundTileWidth = 100; - - // Paint shelf background into an SkBitmap. If we decide to keep the shelf, we - // need to do this for both the "main window" and "not main window" shadings. - NSRect background_rect = NSMakeRect( - 0, 0, - kBackgroundTileWidth, [controller_ height] - kExtensionShelfPaddingTop); - NSBitmapImageRep* bitmap_rep = [[controller_ view] - bitmapImageRepForCachingDisplayInRect:background_rect]; - - [[controller_ view] cacheDisplayInRect:background_rect - toBitmapImageRep:bitmap_rep]; - background_.reset(new SkBitmap(gfx::CGImageToSkBitmap([bitmap_rep CGImage]))); - - // Restore old frame. - [[controller_ view] setFrame:current_frame]; -} - -void ExtensionShelfMac::AdjustHeight() { - if (model_->empty() || toolstrips_.empty()) { - // It's possible that |model_| is not empty, but |toolstrips_| are empty - // when removing the last toolstrip. - DCHECK(toolstrips_.empty()); - Hide(); - return; - } - - if (is_adjusting_height_) - return; - is_adjusting_height_ = true; - - Show(); - - // Lay out items horizontally from left to right. This method's name is - // misleading, but matches linux and windows for now. - CGFloat x = 0; - for (std::set<Toolstrip*>::iterator iter = toolstrips_.begin(); - iter != toolstrips_.end(); ++iter) { - NSView* view = (*iter)->native_view(); - NSRect frame = [view frame]; - frame.origin.x = x; - frame.origin.y = 0; - frame.size.height = [controller_ height] - kExtensionShelfPaddingTop; - [view setFrame:frame]; - x += frame.size.width + kToolstripPadding; - } - - is_adjusting_height_ = false; -} - -void ExtensionShelfMac::LoadFromModel() { - DCHECK(toolstrips_.empty()); - int count = model_->count(); - for (int i = 0; i < count; ++i) - ToolstripInsertedAt(model_->ToolstripAt(i).host, i); - AdjustHeight(); -} - -void ExtensionShelfMac::DeleteToolstrips() { - for (std::set<Toolstrip*>::iterator iter = toolstrips_.begin(); - iter != toolstrips_.end(); ++iter) { - (*iter)->RemoveToolstripFromController(controller_); - delete *iter; - } - toolstrips_.clear(); -} - -ExtensionShelfMac::Toolstrip* ExtensionShelfMac::ToolstripAtIndex(int index) { - return static_cast<Toolstrip*>(model_->ToolstripAt(index).data); -} - - -@implementation ExtensionShelfController - -- (id)initWithBrowser:(Browser*)browser - resizeDelegate:(id<ViewResizer>)resizeDelegate { - if ((self = [super initWithNibName:@"ExtensionShelf" - bundle:mac_util::MainAppBundle()])) { - resizeDelegate_ = resizeDelegate; - browser_ = browser; - shelfHeight_ = [[self view] bounds].size.height; - - NSRect frame = [[self view] frame]; - frame.size.height = 0; - [[self view] setFrame:frame]; - } - return self; -} - -- (void)wasInsertedIntoWindow { - // The bridge_ calls cacheDisplayInRect:toBitmapImageRep:, which requires that - // the view is in a superview to work. Hence, create the bridge object no - // sooner. - DCHECK(bridge_.get() == NULL); - bridge_.reset(new ExtensionShelfMac(browser_, self)); -} - -- (IBAction)show:(id)sender { - [resizeDelegate_ resizeView:[self view] newHeight:shelfHeight_]; -} - -- (IBAction)hide:(id)sender { - [resizeDelegate_ resizeView:[self view] newHeight:0]; -} - -- (CGFloat)height { - return shelfHeight_; -} - -- (void)updateVisibility:(id)sender { - if (bridge_.get()) - bridge_->AdjustHeight(); -} - -@end diff --git a/chrome/browser/cocoa/extension_shelf_controller_unittest.mm b/chrome/browser/cocoa/extension_shelf_controller_unittest.mm deleted file mode 100644 index 765f9af..0000000 --- a/chrome/browser/cocoa/extension_shelf_controller_unittest.mm +++ /dev/null @@ -1,50 +0,0 @@ -// 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_nsobject.h" -#include "chrome/browser/cocoa/browser_test_helper.h" -#import "chrome/browser/cocoa/cocoa_test_helper.h" -#import "chrome/browser/cocoa/extension_shelf_controller.h" -#import "chrome/browser/cocoa/view_resizer_pong.h" - -namespace { - -class ExtensionShelfControllerTest : public CocoaTest { - public: - ExtensionShelfControllerTest() { - resizeDelegate_.reset([[ViewResizerPong alloc] init]); - - NSRect frame = NSMakeRect(0, 0, 100, 30); - controller_.reset([[ExtensionShelfController alloc] - initWithBrowser:helper_.browser() - resizeDelegate:resizeDelegate_.get()]); - NSView* view = [controller_ view]; - EXPECT_TRUE(view); - [[test_window() contentView] addSubview:view]; - } - - BrowserTestHelper helper_; - scoped_nsobject<ExtensionShelfController> controller_; - scoped_nsobject<ViewResizerPong> resizeDelegate_; -}; - -TEST_VIEW(ExtensionShelfControllerTest, [controller_ view]); - -// Check that |hide:| tells the delegate to set the shelf's height to zero. -TEST_F(ExtensionShelfControllerTest, HideSetsHeightToZero) { - [resizeDelegate_ setHeight:10]; - [controller_ hide:nil]; - EXPECT_EQ(0, [resizeDelegate_ height]); -} - -// Check that |show:| tells the delegate to set the shelf's height to the -// shelf's desired height. -TEST_F(ExtensionShelfControllerTest, ShowSetsHeightToHeight) { - [resizeDelegate_ setHeight:0]; - [controller_ show:nil]; - EXPECT_GT([controller_ height], 0); - EXPECT_EQ([controller_ height], [resizeDelegate_ height]); -} - -} // namespace |