summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/cocoa/bookmark_bar_controller.h49
-rw-r--r--chrome/browser/cocoa/bookmark_bar_controller.mm111
-rw-r--r--chrome/browser/cocoa/bookmark_bar_state_controller.h6
-rw-r--r--chrome/browser/cocoa/bookmark_bar_state_controller.mm17
-rw-r--r--chrome/browser/cocoa/bookmark_bar_state_controller_unittest.mm4
-rw-r--r--chrome/browser/cocoa/browser_window_controller.h2
-rw-r--r--chrome/browser/cocoa/browser_window_controller.mm16
-rw-r--r--chrome/browser/cocoa/tab_contents_controller.h18
-rw-r--r--chrome/browser/cocoa/tab_contents_controller.mm50
-rw-r--r--chrome/browser/cocoa/tab_strip_controller.h14
-rw-r--r--chrome/browser/cocoa/tab_strip_controller.mm22
11 files changed, 191 insertions, 118 deletions
diff --git a/chrome/browser/cocoa/bookmark_bar_controller.h b/chrome/browser/cocoa/bookmark_bar_controller.h
new file mode 100644
index 0000000..6c8e4c0
--- /dev/null
+++ b/chrome/browser/cocoa/bookmark_bar_controller.h
@@ -0,0 +1,49 @@
+// 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.
+
+#ifndef CHROME_BROWSER_COCOA_BOOKMARK_BAR_CONTROLLER_H_
+#define CHROME_BROWSER_COCOA_BOOKMARK_BAR_CONTROLLER_H_
+
+#import <Cocoa/Cocoa.h>
+
+#include "base/scoped_nsobject.h"
+
+@class BookmarkBarStateController;
+class BookmarkModel;
+class Profile;
+@class ToolbarView;
+
+// A controller for the bookmark bar in the browser window. Handles showing
+// and hiding based on the preference in the given profile.
+
+@interface BookmarkBarController : NSObject {
+ @private
+ BookmarkModel* bookmarkModel_; // weak; part of the profile owned by the
+ // top-level Browser object.
+
+ // Controller for bookmark bar state, shared among all TabContents.
+ scoped_nsobject<BookmarkBarStateController> bookmarkBarStateController_;
+ BOOL contentAreaHasOffset_;
+
+ // TODO(jrg): write a BookmarkView
+ IBOutlet ToolbarView* /* BookmarkView* */ bookmarkView_;
+ IBOutlet NSView* contentArea_;
+}
+
+// Initializes the controller with the given browser profile and content view.
+- (id)initWithProfile:(Profile*)profile
+ contentArea:(NSView*)content;
+
+// Change the visibility state of the bookmark bar to |enable|.
+- (void)showBookmarkBar:(BOOL)enable;
+
+// Toggle the state of the bookmark bar.
+- (void)toggleBookmarkBar;
+
+// Returns whether or not the bookmark bar is visible.
+- (BOOL)isBookmarkBarVisible;
+
+@end
+
+#endif // CHROME_BROWSER_COCOA_BOOKMARK_BAR_CONTROLLER_H_
diff --git a/chrome/browser/cocoa/bookmark_bar_controller.mm b/chrome/browser/cocoa/bookmark_bar_controller.mm
new file mode 100644
index 0000000..74cc215
--- /dev/null
+++ b/chrome/browser/cocoa/bookmark_bar_controller.mm
@@ -0,0 +1,111 @@
+// 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 "chrome/browser/cocoa/bookmark_bar_controller.h"
+
+#import "chrome/browser/cocoa/bookmark_bar_state_controller.h"
+#import "chrome/browser/cocoa/toolbar_view.h"
+#include "chrome/browser/profile.h"
+
+@interface BookmarkBarController(Private)
+- (void)applyContentAreaOffset:(BOOL)apply;
+- (void)positionBar;
+@end
+
+@implementation BookmarkBarController
+
+- (id)initWithProfile:(Profile*)profile
+ contentArea:(NSView*)content {
+ if ((self = [super init])) {
+ bookmarkModel_ = profile->GetBookmarkModel();
+ contentArea_ = content;
+ bookmarkBarStateController_.reset([[BookmarkBarStateController alloc]
+ initWithProfile:profile]);
+ // 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);
+ bookmarkView_ = [[ToolbarView alloc] initWithFrame:frame];
+ [self positionBar];
+ if ([self isBookmarkBarVisible])
+ [self showBookmarkBar:YES];
+ [[[contentArea_ window] contentView] addSubview:bookmarkView_];
+ }
+ return self;
+}
+
+// Initializes the bookmark bar at the top edge of |contentArea_| and the
+// view's visibility to match the pref. This doesn't move the content view at
+// all, you need to call |-showBookmarkBar:| to do that.
+- (void)positionBar {
+ NSRect contentFrame = [contentArea_ frame];
+ NSRect barFrame = [bookmarkView_ frame];
+
+ // Hide or show bar based on initial visibility and set the resize flags.
+ [bookmarkView_ setAutoresizingMask:NSViewWidthSizable | NSViewMinYMargin];
+ [bookmarkView_ setHidden:[self isBookmarkBarVisible] ? NO : YES];
+
+ // Position the bar at the top of the content area, within the window's
+ // content view (as opposed to the tab strip, which is a sibling). We'll
+ // slide the content area down when we need to show this strip.
+ contentFrame.size.height -= barFrame.size.height;
+ barFrame.origin.y = NSMaxY(contentFrame);
+ barFrame.origin.x = 0;
+ barFrame.size.width = contentFrame.size.width;
+ [bookmarkView_ 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 {
+ contentAreaHasOffset_ = enable;
+ [[bookmarkView_ animator] setHidden:enable ? NO : YES];
+ [self applyContentAreaOffset:enable];
+
+ if (enable) {
+ // TODO(jrg): display something useful in the bookmark bar
+ // TODO(jrg): use a BookmarksView, not a ToolbarView
+ // TODO(jrg): don't draw a border around it
+ // TODO(jrg): ...
+ }
+}
+
+// Apply a contents box offset to make (or remove) room for the
+// 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 {
+ if (bookmarkView_ == nil) {
+ // We're too early, but awakeFromNib will call me again.
+ return;
+ }
+ if (!contentAreaHasOffset_ && apply) {
+ // There is no offset to unconditionally apply.
+ return;
+ }
+
+ int offset = [bookmarkView_ frame].size.height;
+ NSRect frame = [contentArea_ frame];
+ if (apply)
+ frame.size.height -= offset;
+ else
+ frame.size.height += offset;
+
+ // TODO(jrg): animate
+ [[contentArea_ animator] setFrame:frame];
+
+ [bookmarkView_ setNeedsDisplay:YES];
+ [contentArea_ setNeedsDisplay:YES];
+}
+
+- (BOOL)isBookmarkBarVisible {
+ return [bookmarkBarStateController_ visible];
+}
+
+- (void)toggleBookmarkBar {
+ [bookmarkBarStateController_ toggleBookmarkBar];
+ BOOL visible = [self isBookmarkBarVisible];
+ [self showBookmarkBar:visible ? YES : NO];
+}
+
+@end
diff --git a/chrome/browser/cocoa/bookmark_bar_state_controller.h b/chrome/browser/cocoa/bookmark_bar_state_controller.h
index b3aeafd..761d907 100644
--- a/chrome/browser/cocoa/bookmark_bar_state_controller.h
+++ b/chrome/browser/cocoa/bookmark_bar_state_controller.h
@@ -7,17 +7,17 @@
#import <Cocoa/Cocoa.h>
-class Browser;
+class Profile;
// A class to manage bookmark bar state (visible or not). State is
// shared among all tabs and saved in a preference.
@interface BookmarkBarStateController : NSObject {
@private
- Browser* browser_;
+ Profile* profile_;
BOOL visible_;
}
-- (id)initWithBrowser:(Browser *)browser;
+- (id)initWithProfile:(Profile *)browser;
// Return YES or NO reflecting visibility state of the bookmark bar.
- (BOOL)visible;
diff --git a/chrome/browser/cocoa/bookmark_bar_state_controller.mm b/chrome/browser/cocoa/bookmark_bar_state_controller.mm
index e4c6525..69d7aa2 100644
--- a/chrome/browser/cocoa/bookmark_bar_state_controller.mm
+++ b/chrome/browser/cocoa/bookmark_bar_state_controller.mm
@@ -3,19 +3,18 @@
// found in the LICENSE file.
#import "chrome/browser/cocoa/bookmark_bar_state_controller.h"
-#import "chrome/browser/bookmarks/bookmark_utils.h"
-#import "chrome/browser/browser.h"
-#import "chrome/common/pref_names.h"
-#import "chrome/common/pref_service.h"
-
+#include "chrome/browser/bookmarks/bookmark_utils.h"
+#include "chrome/browser/profile.h"
+#include "chrome/common/pref_names.h"
+#include "chrome/common/pref_service.h"
@implementation BookmarkBarStateController
-- (id)initWithBrowser:(Browser *)browser {
+- (id)initWithProfile:(Profile*)profile {
if ((self = [super init])) {
- browser_ = browser;
+ profile_ = profile;
// Initial visibility state comes from our preference.
- if (browser_->profile()->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar)) {
+ if (profile_->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar)) {
visible_ = YES;
}
}
@@ -29,7 +28,7 @@
// Whack and save a preference change. On Windows this call
// is made from BookmarkBarView.
- (void)togglePreference {
- bookmark_utils::ToggleWhenVisible(browser_->profile());
+ bookmark_utils::ToggleWhenVisible(profile_);
}
- (void)toggleBookmarkBar {
diff --git a/chrome/browser/cocoa/bookmark_bar_state_controller_unittest.mm b/chrome/browser/cocoa/bookmark_bar_state_controller_unittest.mm
index 8a86309..31ce077 100644
--- a/chrome/browser/cocoa/bookmark_bar_state_controller_unittest.mm
+++ b/chrome/browser/cocoa/bookmark_bar_state_controller_unittest.mm
@@ -29,8 +29,8 @@ class BookmarkBarStateControllerTest : public testing::Test {
TEST_F(BookmarkBarStateControllerTest, MainTest) {
Browser* browser = browser_test_helper_.GetBrowser();
NoPrefSaveBBStateController *c = [[[NoPrefSaveBBStateController alloc]
- initWithBrowser:browser]
- autorelease];
+ initWithProfile:browser->profile()]
+ autorelease];
EXPECT_TRUE(c);
EXPECT_FALSE(c->toggled_);
BOOL old_visible = [c visible];
diff --git a/chrome/browser/cocoa/browser_window_controller.h b/chrome/browser/cocoa/browser_window_controller.h
index aab0345..8bc7222 100644
--- a/chrome/browser/cocoa/browser_window_controller.h
+++ b/chrome/browser/cocoa/browser_window_controller.h
@@ -16,6 +16,7 @@
#include "base/scoped_ptr.h"
#import "chrome/browser/cocoa/tab_window_controller.h"
+@class BookmarkBarController;
class Browser;
class BrowserWindow;
class BrowserWindowCocoa;
@@ -44,6 +45,7 @@ class TabStripModelObserverBridge;
scoped_ptr<TabStripModelObserverBridge> tabObserver_;
scoped_ptr<BrowserWindowCocoa> windowShim_;
scoped_nsobject<ToolbarController> toolbarController_;
+ scoped_nsobject<BookmarkBarController> bookmarkController_;
scoped_nsobject<TabStripController> tabStripController_;
scoped_ptr<StatusBubble> statusBubble_;
}
diff --git a/chrome/browser/cocoa/browser_window_controller.mm b/chrome/browser/cocoa/browser_window_controller.mm
index 5be49d9..47b3ef9 100644
--- a/chrome/browser/cocoa/browser_window_controller.mm
+++ b/chrome/browser/cocoa/browser_window_controller.mm
@@ -8,6 +8,7 @@
#include "chrome/browser/tab_contents/web_contents.h"
#include "chrome/browser/tab_contents/web_contents_view.h"
#include "chrome/browser/tabs/tab_strip_model.h"
+#import "chrome/browser/cocoa/bookmark_bar_controller.h"
#import "chrome/browser/cocoa/browser_window_cocoa.h"
#import "chrome/browser/cocoa/browser_window_controller.h"
#import "chrome/browser/cocoa/status_bubble_mac.h"
@@ -78,7 +79,16 @@ const int kWindowGradientHeight = 24;
initWithModel:browser->toolbar_model()
commands:browser->command_updater()]);
[self positionToolbar];
- [self fixWindowGradient];
+
+ // After we've adjusted the toolbar, create a controller for the bookmark
+ // bar. It will show/hide itself based on the global preference and handle
+ // positioning itself (if visible) above the content area, which is why
+ // we need to do it after we've placed the toolbar.
+ bookmarkController_.reset([[BookmarkBarController alloc]
+ initWithProfile:browser_->profile()
+ contentArea:[self tabContentArea]]);
+
+ [self fixWindowGradient];
// Create the bridge for the status bubble.
statusBubble_.reset(new StatusBubbleMac([self window]));
@@ -302,12 +312,12 @@ const int kWindowGradientHeight = 24;
}
- (BOOL)isBookmarkBarVisible {
- return [tabStripController_ isBookmarkBarVisible];
+ return [bookmarkController_ isBookmarkBarVisible];
}
- (void)toggleBookmarkBar {
- [tabStripController_ toggleBookmarkBar];
+ [bookmarkController_ toggleBookmarkBar];
}
- (NSInteger)numberOfTabs {
diff --git a/chrome/browser/cocoa/tab_contents_controller.h b/chrome/browser/cocoa/tab_contents_controller.h
index f4098ed..2714ab9 100644
--- a/chrome/browser/cocoa/tab_contents_controller.h
+++ b/chrome/browser/cocoa/tab_contents_controller.h
@@ -7,14 +7,11 @@
#include <Cocoa/Cocoa.h>
-@class BookmarkView;
@class GrowBoxView;
-class BookmarkModel;
class TabContents;
class TabContentsCommandObserver;
class TabStripModel;
-@class ToolbarView;
// A class that controls the web contents of a tab. It manages displaying the
// native view for a given TabContents in |contentsBox_|.
@@ -24,24 +21,14 @@ class TabStripModel;
TabContentsCommandObserver* observer_; // nil if |commands_| is nil
TabContents* contents_; // weak
- BookmarkModel* bookmarkModel_; // weak; one per window
-
- // TODO(jrg): write a BookmarkView
- IBOutlet ToolbarView* /* BookmarkView* */ bookmarkView_;
-
IBOutlet NSBox* contentsBox_;
IBOutlet GrowBoxView* growBox_;
-
- // The contents box will have an offset if shrunk to make room for
- // the bookmark bar.
- BOOL contentsBoxHasOffset_;
}
// Create the contents of a tab represented by |contents| and loaded from the
// nib given by |name|.
- (id)initWithNibName:(NSString*)name
- contents:(TabContents*)contents
- bookmarkModel:(BookmarkModel*)bookmarkModel;
+ contents:(TabContents*)contents;
// Take this view (toolbar and web contents) full screen
- (IBAction)fullScreen:(id)sender;
@@ -60,9 +47,6 @@ class TabStripModel;
// in the coordinate system of the content area of this tab.
- (NSRect)growBoxRect;
-// Change the visibility state of the bookmark bar.
-- (void)toggleBookmarkBar:(BOOL)enable;
-
@end
#endif // CHROME_BROWSER_COCOA_TAB_COTNENTS_CONTROLLER_H_
diff --git a/chrome/browser/cocoa/tab_contents_controller.mm b/chrome/browser/cocoa/tab_contents_controller.mm
index c72b97d..cb51275 100644
--- a/chrome/browser/cocoa/tab_contents_controller.mm
+++ b/chrome/browser/cocoa/tab_contents_controller.mm
@@ -8,18 +8,12 @@
#include "chrome/browser/bookmarks/bookmark_model.h"
#include "chrome/browser/tab_contents/tab_contents.h"
-@interface TabContentsController(Private)
-- (void)applyContentsBoxOffset:(BOOL)apply;
-@end
-
@implementation TabContentsController
- (id)initWithNibName:(NSString*)name
- contents:(TabContents*)contents
- bookmarkModel:(BookmarkModel*)bookmarkModel {
+ contents:(TabContents*)contents {
if ((self = [super initWithNibName:name bundle:nil])) {
contents_ = contents;
- bookmarkModel_ = bookmarkModel;
}
return self;
}
@@ -32,7 +26,6 @@
- (void)awakeFromNib {
[contentsBox_ setContentView:contents_->GetNativeView()];
- [self applyContentsBoxOffset:YES];
}
// Returns YES if the tab represented by this controller is the front-most.
@@ -83,45 +76,4 @@
return localGrowBox;
}
-- (void)toggleBookmarkBar:(BOOL)enable {
- contentsBoxHasOffset_ = enable;
- [self applyContentsBoxOffset:enable];
-
- if (enable) {
- // TODO(jrg): display something useful in the bookmark bar
- // TODO(jrg): use a BookmarksView, not a ToolbarView
- // TODO(jrg): don't draw a border around it
- // TODO(jrg): ...
- }
-}
-
-// Apply a contents box offset to make (or remove) room for the
-// bookmark bar. If apply==YES, always make room (the contentsBox_ is
-// "full size"). If apply==NO we are trying to undo an offset. If no
-// offset there is nothing to undo.
-- (void)applyContentsBoxOffset:(BOOL)apply {
-
- if (bookmarkView_ == nil) {
- // We're too early, but awakeFromNib will call me again.
- return;
- }
- if (!contentsBoxHasOffset_ && apply) {
- // There is no offset to unconditionally apply.
- return;
- }
-
- int offset = [bookmarkView_ frame].size.height;
- NSRect frame = [contentsBox_ frame];
- if (apply)
- frame.size.height -= offset;
- else
- frame.size.height += offset;
-
- // TODO(jrg): animate
- [contentsBox_ setFrame:frame];
-
- [bookmarkView_ setNeedsDisplay:YES];
- [contentsBox_ setNeedsDisplay:YES];
-}
-
@end
diff --git a/chrome/browser/cocoa/tab_strip_controller.h b/chrome/browser/cocoa/tab_strip_controller.h
index dae7218..faa7132 100644
--- a/chrome/browser/cocoa/tab_strip_controller.h
+++ b/chrome/browser/cocoa/tab_strip_controller.h
@@ -12,11 +12,8 @@
#import "chrome/browser/cocoa/tab_controller_target.h"
@class TabStripView;
-@class BookmarkBarStateController;
-class BookmarkModel;
class Browser;
-class LocationBar;
class TabStripModelObserverBridge;
class TabStripModel;
class TabContents;
@@ -41,7 +38,6 @@ class ToolbarModel;
NSButton* newTabButton_; // weak, obtained from the nib.
scoped_ptr<TabStripModelObserverBridge> bridge_;
TabStripModel* tabModel_; // weak
- BookmarkModel* bookmarkModel_; // weak, one per profile (= one per Browser*)
// access to the TabContentsControllers (which own the parent view
// for the toolbar and associated tab contents) given an index. This needs
// to be kept in the same order as the tab strip's model as we will be
@@ -50,9 +46,6 @@ class ToolbarModel;
// an array of TabControllers which manage the actual tab views. As above,
// this is kept in the same order as the tab strip model.
scoped_nsobject<NSMutableArray> tabArray_;
-
- // Controller for bookmark bar state, shared among all TabContents.
- scoped_nsobject<BookmarkBarStateController> bookmarkBarStateController_;
}
// Initialize the controller with a view and browser that contains
@@ -68,13 +61,6 @@ class ToolbarModel;
// in the coordinate system of the content area of the currently selected tab.
- (NSRect)selectedTabGrowBoxRect;
-// Return a boolean (ObjC BOOL, not C++ bool) to say if the bookmark
-// bar is visible.
-- (BOOL)isBookmarkBarVisible;
-
-// Turn on or off the bookmark bar for *ALL* tabs.
-- (void)toggleBookmarkBar;
-
// Given a tab view in the strip, return its index. Returns -1 if not present.
- (NSInteger)indexForTabView:(NSView*)view;
diff --git a/chrome/browser/cocoa/tab_strip_controller.mm b/chrome/browser/cocoa/tab_strip_controller.mm
index 0fca35f..920438c 100644
--- a/chrome/browser/cocoa/tab_strip_controller.mm
+++ b/chrome/browser/cocoa/tab_strip_controller.mm
@@ -7,7 +7,6 @@
#import "base/sys_string_conversions.h"
#import "chrome/app/chrome_dll_resource.h"
#import "chrome/browser/browser.h"
-#import "chrome/browser/cocoa/bookmark_bar_state_controller.h"
#import "chrome/browser/cocoa/tab_strip_view.h"
#import "chrome/browser/cocoa/tab_cell.h"
#import "chrome/browser/cocoa/tab_contents_controller.h"
@@ -27,12 +26,9 @@
tabView_ = view;
switchView_ = switchView;
tabModel_ = browser->tabstrip_model();
- bookmarkModel_ = browser->profile()->GetBookmarkModel();
bridge_.reset(new TabStripModelObserverBridge(tabModel_, self));
tabContentsArray_.reset([[NSMutableArray alloc] init]);
tabArray_.reset([[NSMutableArray alloc] init]);
- bookmarkBarStateController_.reset([[BookmarkBarStateController alloc]
- initWithBrowser:browser]);
// Take the only child view present in the nib as the new tab button. For
// some reason, if the view is present in the nib apriori, it draws
// correctly. If we create it in code and add it to the tab view, it draws
@@ -212,11 +208,8 @@
// the new controller with |contents| so it can be looked up later.
TabContentsController* contentsController =
[[[TabContentsController alloc] initWithNibName:@"TabContents"
- contents:contents
- bookmarkModel:bookmarkModel_]
+ contents:contents]
autorelease];
- if ([self isBookmarkBarVisible])
- [contentsController toggleBookmarkBar:YES];
[tabContentsArray_ insertObject:contentsController atIndex:index];
// Make a new tab and add it to the strip. Keep track of its controller.
@@ -319,17 +312,4 @@
return [selectedController growBoxRect];
}
-- (BOOL)isBookmarkBarVisible {
- return [bookmarkBarStateController_ visible];
-}
-
-// Called from BrowserWindowController
-- (void)toggleBookmarkBar {
- [bookmarkBarStateController_ toggleBookmarkBar];
- BOOL visible = [self isBookmarkBarVisible];
- for (TabContentsController *controller in tabContentsArray_.get()) {
- [controller toggleBookmarkBar:visible];
- }
-}
-
@end