diff options
author | erg@chromium.org <erg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-09 18:01:08 +0000 |
---|---|---|
committer | erg@chromium.org <erg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-09 18:01:08 +0000 |
commit | 3302102a21dcdae93f17f2db57ba32ba0e8dd1da (patch) | |
tree | e8f3b5e53324e77a3dc6502a0d555e93a25261b2 | |
parent | 9398185452c106c0f464747fd76d70f3d212143a (diff) | |
download | chromium_src-3302102a21dcdae93f17f2db57ba32ba0e8dd1da.zip chromium_src-3302102a21dcdae93f17f2db57ba32ba0e8dd1da.tar.gz chromium_src-3302102a21dcdae93f17f2db57ba32ba0e8dd1da.tar.bz2 |
Mac: Theme the bookmark bar on the new tab page.
- XIB change: The controller has a connection to buttonView_.
- BrowserThemeProviderMac: Fix a bug where we weren't returning
default colors; we returned nil instead.
- The majority of the implementation is actually the cross platform
NtpBackgroundUtil::PaintBackgroundDetachedMode. We do platform
specific drawing on top of the background, though.
TEST=BookmarkBarToolbarViewTest.DisplayAsFloatingBarWithNoImage
TEST=BookmarkBarToolbarViewTest.DisplayAsFloatingBarWithBgImage
BUG=http://crbug.com/17625
Review URL: http://codereview.chromium.org/266027
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@28560 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/app/nibs/BookmarkBar.xib | 31 | ||||
-rw-r--r-- | chrome/browser/browser_theme_provider_mac.mm | 27 | ||||
-rw-r--r-- | chrome/browser/cocoa/bookmark_bar_constants.h | 27 | ||||
-rw-r--r-- | chrome/browser/cocoa/bookmark_bar_controller.h | 12 | ||||
-rw-r--r-- | chrome/browser/cocoa/bookmark_bar_controller.mm | 29 | ||||
-rw-r--r-- | chrome/browser/cocoa/bookmark_bar_toolbar_view.h | 31 | ||||
-rw-r--r-- | chrome/browser/cocoa/bookmark_bar_toolbar_view.mm | 86 | ||||
-rw-r--r-- | chrome/browser/cocoa/bookmark_bar_toolbar_view_unittest.mm | 101 | ||||
-rw-r--r-- | chrome/browser/dom_ui/dom_ui_theme_source.cc | 4 | ||||
-rwxr-xr-x | chrome/chrome.gyp | 1 |
10 files changed, 299 insertions, 50 deletions
diff --git a/chrome/app/nibs/BookmarkBar.xib b/chrome/app/nibs/BookmarkBar.xib index 852f709..0163b28 100644 --- a/chrome/app/nibs/BookmarkBar.xib +++ b/chrome/app/nibs/BookmarkBar.xib @@ -2,15 +2,15 @@ <archive type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="7.03"> <data> <int key="IBDocument.SystemTarget">1050</int> - <string key="IBDocument.SystemVersion">9G3553</string> + <string key="IBDocument.SystemVersion">9L31a</string> <string key="IBDocument.InterfaceBuilderVersion">677</string> - <string key="IBDocument.AppKitVersion">949.43</string> + <string key="IBDocument.AppKitVersion">949.54</string> <string key="IBDocument.HIToolboxVersion">353.00</string> <object class="NSMutableArray" key="IBDocument.EditedObjectIDs"> <bool key="EncodedWithXMLCoder">YES</bool> <integer value="18"/> - <integer value="4"/> <integer value="1"/> + <integer value="4"/> </object> <object class="NSArray" key="IBDocument.PluginDependencies"> <bool key="EncodedWithXMLCoder">YES</bool> @@ -626,6 +626,14 @@ </object> <int key="connectionID">93</int> </object> + <object class="IBConnectionRecord"> + <object class="IBOutletConnection" key="connection"> + <string key="label">buttonView_</string> + <reference key="source" ref="620641226"/> + <reference key="destination" ref="610146462"/> + </object> + <int key="connectionID">94</int> + </object> </object> <object class="IBMutableOrderedSet" key="objectRecords"> <object class="NSArray" key="orderedObjects"> @@ -948,7 +956,7 @@ <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> - <string>{{145, 138}, {600, 144}}</string> + <string>{{1111, 613}, {600, 144}}</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> @@ -1012,7 +1020,7 @@ </object> </object> <nil key="sourceID"/> - <int key="maxID">93</int> + <int key="maxID">94</int> </object> <object class="IBClassDescriber" key="IBDocument.Classes"> <object class="NSMutableArray" key="referencedPartialClassDescriptions"> @@ -1089,8 +1097,17 @@ <string key="className">BookmarkBarToolbarView</string> <string key="superclassName">BackgroundGradientView</string> <object class="NSMutableDictionary" key="outlets"> - <string key="NS.key.0">controller_</string> - <string key="NS.object.0">id</string> + <bool key="EncodedWithXMLCoder">YES</bool> + <object class="NSMutableArray" key="dict.sortedKeys"> + <bool key="EncodedWithXMLCoder">YES</bool> + <string>buttonView_</string> + <string>controller_</string> + </object> + <object class="NSMutableArray" key="dict.values"> + <bool key="EncodedWithXMLCoder">YES</bool> + <string>BookmarkBarView</string> + <string>id</string> + </object> </object> <object class="IBClassDescriptionSource" key="sourceIdentifier"> <string key="majorKey">IBProjectSource</string> diff --git a/chrome/browser/browser_theme_provider_mac.mm b/chrome/browser/browser_theme_provider_mac.mm index 6df0336..e27f4ae 100644 --- a/chrome/browser/browser_theme_provider_mac.mm +++ b/chrome/browser/browser_theme_provider_mac.mm @@ -75,22 +75,17 @@ NSColor* BrowserThemeProvider::GetNSColor(int id) { if (found != nscolor_cache_.end()) return found->second; - ColorMap::iterator color_iter = colors_.find(GetColorKey(id)); - if (color_iter != colors_.end()) { - const SkColor& sk_color = color_iter->second; - - - NSColor* color = [NSColor - colorWithCalibratedRed:SkColorGetR(sk_color)/255.0 - green:SkColorGetG(sk_color)/255.0 - blue:SkColorGetB(sk_color)/255.0 - alpha:SkColorGetA(sk_color)/255.0]; - - // We loaded successfully. Cache the color. - if (color) { - nscolor_cache_[id] = [color retain]; - return color; - } + SkColor sk_color = GetColor(id); + NSColor* color = [NSColor + colorWithCalibratedRed:SkColorGetR(sk_color)/255.0 + green:SkColorGetG(sk_color)/255.0 + blue:SkColorGetB(sk_color)/255.0 + alpha:SkColorGetA(sk_color)/255.0]; + + // We loaded successfully. Cache the color. + if (color) { + nscolor_cache_[id] = [color retain]; + return color; } return nil; diff --git a/chrome/browser/cocoa/bookmark_bar_constants.h b/chrome/browser/cocoa/bookmark_bar_constants.h new file mode 100644 index 0000000..ba1b576 --- /dev/null +++ b/chrome/browser/cocoa/bookmark_bar_constants.h @@ -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. + +// Constants used for positioning the bookmark bar. These aren't placed in a +// different file because they're conditionally included in cross platform code +// and thus no Objective-C++ stuff. + +#ifndef CHROME_BROWSER_COCOA_BOOKMARK_BAR_CONSTANTS_H_ +#define CHROME_BROWSER_COCOA_BOOKMARK_BAR_CONSTANTS_H_ + +namespace bookmarks { + +// Our height, when opened in "always visible" mode. +const int kBookmarkBarHeight = 28; + +// Our height, when visible in "new tab page" mode. +const int kNTPBookmarkBarHeight = 40; + +// The amount of space between the inner bookmark bar and the outer toolbar on +// new tab pages. +const int kNTPBookmarkBarPadding = + (kNTPBookmarkBarHeight - kBookmarkBarHeight) / 2; + +} // namespace bookmarks + +#endif // CHROME_BROWSER_COCOA_BOOKMARK_BAR_CONSTANTS_H_ diff --git a/chrome/browser/cocoa/bookmark_bar_controller.h b/chrome/browser/cocoa/bookmark_bar_controller.h index 783b98c..b8986f1 100644 --- a/chrome/browser/cocoa/bookmark_bar_controller.h +++ b/chrome/browser/cocoa/bookmark_bar_controller.h @@ -11,6 +11,7 @@ #include "base/scoped_nsobject.h" #include "base/scoped_ptr.h" #include "chrome/browser/cocoa/bookmark_bar_bridge.h" +#import "chrome/browser/cocoa/bookmark_bar_toolbar_view.h" #include "chrome/browser/cocoa/tab_strip_model_observer_bridge.h" #include "webkit/glue/window_open_disposition.h" @@ -34,17 +35,10 @@ class PrefService; disposition:(WindowOpenDisposition)disposition; @end -// An interface to allow mocking of a BookmarkBarController by the -// BookmarkBarToolbarView. -@protocol BookmarkBarFloating -// Returns true if the bookmark bar should be drawn as if it's a disconnected -// bookmark bar on the New Tag Page. -- (BOOL)drawAsFloatingBar; -@end - // A controller for the bookmark bar in the browser window. Handles showing // and hiding based on the preference in the given profile. -@interface BookmarkBarController : NSViewController<BookmarkBarFloating> { +@interface BookmarkBarController : + NSViewController<BookmarkBarToolbarViewController> { @private Browser* browser_; // weak; owned by its window BookmarkModel* bookmarkModel_; // weak; part of the profile owned by the diff --git a/chrome/browser/cocoa/bookmark_bar_controller.mm b/chrome/browser/cocoa/bookmark_bar_controller.mm index f150334..0872b3a 100644 --- a/chrome/browser/cocoa/bookmark_bar_controller.mm +++ b/chrome/browser/cocoa/bookmark_bar_controller.mm @@ -12,7 +12,9 @@ #include "chrome/browser/browser.h" #include "chrome/browser/browser_list.h" #import "chrome/browser/cocoa/bookmark_bar_bridge.h" +#import "chrome/browser/cocoa/bookmark_bar_constants.h" #import "chrome/browser/cocoa/bookmark_bar_controller.h" +#import "chrome/browser/cocoa/bookmark_bar_toolbar_view.h" #import "chrome/browser/cocoa/bookmark_bar_view.h" #import "chrome/browser/cocoa/bookmark_button_cell.h" #import "chrome/browser/cocoa/bookmark_editor_controller.h" @@ -24,6 +26,7 @@ #import "chrome/browser/cocoa/view_resizer.h" #include "chrome/browser/profile.h" #include "chrome/browser/tab_contents/tab_contents.h" +#include "chrome/browser/tab_contents/tab_contents_view.h" #include "chrome/common/pref_names.h" #include "chrome/common/pref_service.h" #include "grit/generated_resources.h" @@ -53,12 +56,6 @@ namespace { -// Our height, when opened in "always visible" mode. -const int kBookmarkBarHeight = 28; - -// Our height, when visible in "new tab page" mode. -const int kNTPBookmarkBarHeight = 40; - // Magic numbers from Cole const CGFloat kDefaultBookmarkWidth = 150.0; const CGFloat kBookmarkVerticalPadding = 2.0; @@ -171,6 +168,9 @@ const CGFloat kBookmarkHorizontalPadding = 1.0; CGFloat height = show ? [self preferredHeight] : 0; [resizeDelegate_ resizeView:[self view] newHeight:height]; [[self view] setHidden:show ? NO : YES]; + + DCHECK([[self view] isKindOfClass:[BookmarkBarToolbarView class]]); + [(BookmarkBarToolbarView*)[self view] layoutViews]; } // We don't change a preference; we only change visibility. @@ -196,7 +196,17 @@ const CGFloat kBookmarkHorizontalPadding = 1.0; } - (BOOL)isAlwaysVisible { - return browser_ && browser_->profile()->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar); + return browser_ && + browser_->profile()->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar); +} + +- (int)currentTabContentsHeight { + return browser_->GetSelectedTabContents()->view()->GetContainerSize(). + height(); +} + +- (ThemeProvider*)themeProvider { + return browser_->profile()->GetThemeProvider(); } - (BOOL)drawAsFloatingBar { @@ -246,7 +256,8 @@ const CGFloat kBookmarkHorizontalPadding = 1.0; } - (int)preferredHeight { - return [self isAlwaysVisible] ? kBookmarkBarHeight : kNTPBookmarkBarHeight; + return [self isAlwaysVisible] ? bookmarks::kBookmarkBarHeight : + bookmarks::kNTPBookmarkBarHeight; } - (void)selectTabWithContents:(TabContents*)newContents @@ -552,7 +563,7 @@ const CGFloat kBookmarkHorizontalPadding = 1.0; NSRect bounds = [[self view] bounds]; // TODO: be smarter about this; the animator delays the right height if (bounds.size.height == 0) - bounds.size.height = kBookmarkBarHeight; + bounds.size.height = bookmarks::kBookmarkBarHeight; NSRect frame = NSInsetRect(bounds, kBookmarkHorizontalPadding, kBookmarkVerticalPadding); diff --git a/chrome/browser/cocoa/bookmark_bar_toolbar_view.h b/chrome/browser/cocoa/bookmark_bar_toolbar_view.h index 2808cc5..cfc9288 100644 --- a/chrome/browser/cocoa/bookmark_bar_toolbar_view.h +++ b/chrome/browser/cocoa/bookmark_bar_toolbar_view.h @@ -15,11 +15,40 @@ #import "chrome/browser/cocoa/background_gradient_view.h" @protocol BookmarkBarFloating; +@class BookmarkBarView; +class TabContents; +class ThemeProvider; + +// An interface to allow mocking of a BookmarkBarController by the +// BookmarkBarToolbarView. +@protocol BookmarkBarToolbarViewController +// Displaying the bookmark toolbar background in floating mode requires the +// size of the currently selected tab to properly calculate where the +// background image is joined. +- (int)currentTabContentsHeight; + +// Current theme provider, passed to the cross platform NtpBackgroundUtil class. +- (ThemeProvider*)themeProvider; + +// Returns true if the bookmark bar should be drawn as if it's a disconnected +// bookmark bar on the New Tag Page. +- (BOOL)drawAsFloatingBar; +@end @interface BookmarkBarToolbarView : BackgroundGradientView { @private - IBOutlet id<BookmarkBarFloating> controller_; + // The controller which tells us how we should be drawing (as normal or as a + // floating bar). + IBOutlet id<BookmarkBarToolbarViewController> controller_; + + // The bookmark bar's contents. + IBOutlet BookmarkBarView* buttonView_; } + +// Called by our controller to layout our subviews, so that on new tab pages, +// we have a border. +- (void)layoutViews; + @end #endif // CHROME_BROWSER_COCOA_BOOKMARK_BAR_TOOLBAR_VIEW_H_ diff --git a/chrome/browser/cocoa/bookmark_bar_toolbar_view.mm b/chrome/browser/cocoa/bookmark_bar_toolbar_view.mm index e40607b..4a652aa 100644 --- a/chrome/browser/cocoa/bookmark_bar_toolbar_view.mm +++ b/chrome/browser/cocoa/bookmark_bar_toolbar_view.mm @@ -4,18 +4,98 @@ #import "chrome/browser/cocoa/bookmark_bar_toolbar_view.h" +#include "app/gfx/canvas_paint.h" +#include "app/theme_provider.h" +#include "base/gfx/rect.h" +#include "chrome/browser/browser_theme_provider.h" +#import "chrome/browser/cocoa/browser_window_controller.h" +#import "chrome/browser/cocoa/bookmark_bar_constants.h" #import "chrome/browser/cocoa/bookmark_bar_controller.h" +#include "chrome/browser/ntp_background_util.h" +#import "third_party/GTM/AppKit/GTMTheme.h" + +const CGFloat kBorderRadius = 3.0; + +@interface BookmarkBarToolbarView (Private) +- (void)drawRectAsFloating:(NSRect)rect; +@end @implementation BookmarkBarToolbarView +- (BOOL)isOpaque { + return YES; +} + - (void)drawRect:(NSRect)rect { if ([controller_ drawAsFloatingBar]) { - // TODO(erg): Deal with themes. http://crbug.com/17625 - [[NSColor colorWithDeviceRed:1.0 green:1.0 blue:1.0 alpha:1.0] set]; - NSRectFill(rect); + [self drawRectAsFloating:rect]; } else { [super drawRect:rect]; } } +- (void)layoutViews { + if ([controller_ drawAsFloatingBar]) { + // The internal bookmark bar should have padding to center it. + NSRect frame = [self frame]; + [buttonView_ setFrame: + NSMakeRect(bookmarks::kNTPBookmarkBarPadding, + bookmarks::kNTPBookmarkBarPadding, + NSWidth(frame) - + bookmarks::kNTPBookmarkBarPadding, + NSHeight(frame) - + bookmarks::kNTPBookmarkBarPadding)]; + } else { + // The frame of our child should be equal to our frame. + NSRect frame = [self frame]; + [buttonView_ setFrame:NSMakeRect(0, 0, NSWidth(frame), NSHeight(frame))]; + } +} + +@end + + +@implementation BookmarkBarToolbarView (Private) + +- (void)drawRectAsFloating:(NSRect)rect { + NSRect bounds = [self bounds]; + + ThemeProvider* themeProvider = [controller_ themeProvider]; + if (!themeProvider) + return; + + NSGraphicsContext* theContext = [NSGraphicsContext currentContext]; + [theContext saveGraphicsState]; + + // Draw the background + { + // CanvasPaint draws to the NSGraphicsContext during its destructor, so + // explicitly scope this. + gfx::CanvasPaint canvas(rect, true); + gfx::Rect area(0, 0, NSWidth(rect), NSHeight(rect)); + + NtpBackgroundUtil::PaintBackgroundDetachedMode(themeProvider, &canvas, + area, [controller_ currentTabContentsHeight]); + } + + // Draw our bookmark bar border on top of the background. + NSRect frame_rect = + NSMakeRect(bookmarks::kNTPBookmarkBarPadding, + bookmarks::kNTPBookmarkBarPadding, + NSWidth(bounds) - 2 * bookmarks::kNTPBookmarkBarPadding, + NSHeight(bounds) - 2 * bookmarks::kNTPBookmarkBarPadding); + // Now draw a beizer path with rounded rectangles around the area + NSBezierPath* border = + [NSBezierPath bezierPathWithRoundedRect:frame_rect + xRadius:kBorderRadius + yRadius:kBorderRadius]; + [themeProvider->GetNSColor(BrowserThemeProvider::COLOR_TOOLBAR) set];; + [border fill]; + + [themeProvider->GetNSColor(BrowserThemeProvider::COLOR_NTP_HEADER) set]; + [border stroke]; + + [theContext restoreGraphicsState]; +} + @end // @implementation BookmarkBarToolbarView diff --git a/chrome/browser/cocoa/bookmark_bar_toolbar_view_unittest.mm b/chrome/browser/cocoa/bookmark_bar_toolbar_view_unittest.mm index 8a2d6ef..c2b83bf 100644 --- a/chrome/browser/cocoa/bookmark_bar_toolbar_view_unittest.mm +++ b/chrome/browser/cocoa/bookmark_bar_toolbar_view_unittest.mm @@ -4,33 +4,69 @@ #import <Cocoa/Cocoa.h> +#include "app/theme_provider.h" #include "base/scoped_nsobject.h" +#include "chrome/browser/browser_theme_provider.h" #import "chrome/browser/cocoa/bookmark_bar_controller.h" #import "chrome/browser/cocoa/bookmark_bar_toolbar_view.h" #import "chrome/browser/cocoa/cocoa_test_helper.h" +#include "grit/theme_resources.h" +#include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" #include "testing/platform_test.h" +#include "third_party/skia/include/core/SkBitmap.h" +#include "third_party/skia/include/core/SkColor.h" + +using ::testing::_; +using ::testing::DoAll; +using ::testing::Return; +using ::testing::SetArgumentPointee; + +// When testing the floating drawing, we need to have a source of +// theme data. +class MockThemeProvider : public ThemeProvider { + public: + // Cross platform methods + MOCK_METHOD1(Init, void(Profile*)); + MOCK_METHOD1(GetBitmapNamed, SkBitmap*(int)); + MOCK_METHOD1(GetColor, SkColor(int)); + MOCK_METHOD2(GetDisplayProperty, bool(int, int*)); + MOCK_METHOD0(ShouldUseNativeFrame, bool()); + MOCK_METHOD1(HasCustomImage, bool(int)); + MOCK_METHOD2(GetRawData, bool(int, std::vector<unsigned char>*)); + + // OSX stuff + MOCK_METHOD1(GetNSImageNamed, NSImage*(int)); + MOCK_METHOD1(GetNSColor, NSColor*(int)); + MOCK_METHOD1(GetNSColorTint, NSColor*(int)); +}; // Allows us to inject our fake controller below. @interface BookmarkBarToolbarView (TestingAPI) --(void)setController:(id<BookmarkBarFloating>)controller; +-(void)setController:(id<BookmarkBarToolbarViewController>)controller; @end @implementation BookmarkBarToolbarView (TestingAPI) --(void)setController:(id<BookmarkBarFloating>)controller { +-(void)setController:(id<BookmarkBarToolbarViewController>)controller { controller_ = controller; } @end // Allows us to control which way the view is rendered. @interface DrawFloatingFakeController : - NSObject<BookmarkBarFloating> { + NSObject<BookmarkBarToolbarViewController> { + int current_tab_contents_height_; + ThemeProvider* theme_provider_; BOOL drawAsFloating_; } +@property(assign) int currentTabContentsHeight; +@property(assign) ThemeProvider* themeProvider; @property(assign) BOOL drawAsFloatingBar; @end @implementation DrawFloatingFakeController +@synthesize currentTabContentsHeight = current_tab_contents_height_; +@synthesize themeProvider = theme_provider_; @synthesize drawAsFloatingBar = drawAsFloating_; @end @@ -38,7 +74,7 @@ class BookmarkBarToolbarViewTest : public PlatformTest { public: BookmarkBarToolbarViewTest() { controller_.reset([[DrawFloatingFakeController alloc] init]); - NSRect frame = NSMakeRect(0, 0, 100, 30); + NSRect frame = NSMakeRect(0, 0, 400, 40); view_.reset([[BookmarkBarToolbarView alloc] initWithFrame:frame]); [cocoa_helper_.contentView() addSubview:view_.get()]; [view_.get() setController:controller_.get()]; @@ -64,7 +100,62 @@ TEST_F(BookmarkBarToolbarViewTest, DisplayAsNormalBar) { } // Test drawing (part 2), mostly to ensure nothing leaks or crashes. -TEST_F(BookmarkBarToolbarViewTest, DisplayAsDisconnectedBar) { +TEST_F(BookmarkBarToolbarViewTest, DisplayAsFloatingBarWithNoImage) { [controller_.get() setDrawAsFloatingBar:YES]; + + // Tests where we don't have a background image, only a color. + MockThemeProvider provider; + EXPECT_CALL(provider, GetColor(BrowserThemeProvider::COLOR_NTP_BACKGROUND)) + .WillRepeatedly(Return(SK_ColorWHITE)); + EXPECT_CALL(provider, HasCustomImage(IDR_THEME_NTP_BACKGROUND)) + .WillRepeatedly(Return(false)); + [controller_.get() setThemeProvider:&provider]; + + [view_ display]; +} + +// Actions used in DisplayAsFloatingBarWithBgImage. +ACTION(SetBackgroundTiling) { + *arg1 = BrowserThemeProvider::NO_REPEAT; + return true; +} + +ACTION(SetAlignLeft) { + *arg1 = BrowserThemeProvider::ALIGN_LEFT; + return true; +} + +// Test drawing (part 3), mostly to ensure nothing leaks or crashes. +TEST_F(BookmarkBarToolbarViewTest, DisplayAsFloatingBarWithBgImage) { + [controller_.get() setDrawAsFloatingBar:YES]; + + // Tests where we have a background image, with positioning information. + MockThemeProvider provider; + + // Advertise having an image. + EXPECT_CALL(provider, GetColor(BrowserThemeProvider::COLOR_NTP_BACKGROUND)) + .WillRepeatedly(Return(SK_ColorRED)); + EXPECT_CALL(provider, HasCustomImage(IDR_THEME_NTP_BACKGROUND)) + .WillRepeatedly(Return(true)); + + // Return the correct tiling/alignment information. + EXPECT_CALL(provider, + GetDisplayProperty(BrowserThemeProvider::NTP_BACKGROUND_TILING, _)) + .WillRepeatedly(SetBackgroundTiling()); + EXPECT_CALL(provider, + GetDisplayProperty(BrowserThemeProvider::NTP_BACKGROUND_ALIGNMENT, _)) + .WillRepeatedly(SetAlignLeft()); + + // Create a dummy bitmap full of not-red to blit with. + SkBitmap fake_bg; + fake_bg.setConfig(SkBitmap::kARGB_8888_Config, 800, 800); + fake_bg.allocPixels(); + fake_bg.eraseColor(SK_ColorGREEN); + EXPECT_CALL(provider, GetBitmapNamed(IDR_THEME_NTP_BACKGROUND)) + .WillRepeatedly(Return(&fake_bg)); + + [controller_.get() setThemeProvider:&provider]; + [controller_.get() setCurrentTabContentsHeight:200]; + [view_ display]; } diff --git a/chrome/browser/dom_ui/dom_ui_theme_source.cc b/chrome/browser/dom_ui/dom_ui_theme_source.cc index 565a8fb..dfe9128 100644 --- a/chrome/browser/dom_ui/dom_ui_theme_source.cc +++ b/chrome/browser/dom_ui/dom_ui_theme_source.cc @@ -24,6 +24,8 @@ #include "chrome/browser/views/bookmark_bar_view.h" #elif defined(OS_LINUX) #include "chrome/browser/gtk/bookmark_bar_gtk.h" +#elif defined(OS_MACOSX) +#include "chrome/browser/cocoa/bookmark_bar_constants.h" #endif // Path for the New Tab CSS. When we get more than a few of these, we should @@ -278,6 +280,8 @@ std::string DOMUIThemeSource::GetNewTabBackgroundCSS(bool bar_attached) { int offset = BookmarkBarView::kNewtabBarHeight; #elif defined(OS_LINUX) int offset = BookmarkBarGtk::kBookmarkBarNTPHeight; +#elif defined(OS_MACOSX) + int offset = bookmarks::kNTPBookmarkBarHeight; #else int offset = 0; #endif diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp index c6959dc..a2cfd42 100755 --- a/chrome/chrome.gyp +++ b/chrome/chrome.gyp @@ -987,6 +987,7 @@ 'browser/cocoa/blocked_popup_container_controller.mm', 'browser/cocoa/bookmark_bar_bridge.h', 'browser/cocoa/bookmark_bar_bridge.mm', + 'browser/cocoa/bookmark_bar_constants.h', 'browser/cocoa/bookmark_bar_controller.h', 'browser/cocoa/bookmark_bar_controller.mm', 'browser/cocoa/bookmark_bar_view.h', |