summaryrefslogtreecommitdiffstats
path: root/chrome/browser/cocoa
diff options
context:
space:
mode:
authoravi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-25 14:23:41 +0000
committeravi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-25 14:23:41 +0000
commita4ae3e1139fb2cf09a9c5dc95baec927b47ab770 (patch)
tree732e449f1e510c1eab2d7e8802db97c4d632324a /chrome/browser/cocoa
parentef8ca82edcb77b5c78fbe8c3a87338713ad72890 (diff)
downloadchromium_src-a4ae3e1139fb2cf09a9c5dc95baec927b47ab770.zip
chromium_src-a4ae3e1139fb2cf09a9c5dc95baec927b47ab770.tar.gz
chromium_src-a4ae3e1139fb2cf09a9c5dc95baec927b47ab770.tar.bz2
Reverting r19244 as it unintentionally broke ui tests: OtherRedirectsDontForkProcess InEmptyFrame TestLifetimeOfDomAutomationController
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@19245 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa')
-rw-r--r--chrome/browser/cocoa/bookmark_bar_controller.mm8
-rw-r--r--chrome/browser/cocoa/cocoa_utils.h19
-rw-r--r--chrome/browser/cocoa/cocoa_utils.mm38
-rw-r--r--chrome/browser/cocoa/cocoa_utils_unittest.mm76
-rw-r--r--chrome/browser/cocoa/tab_strip_controller.mm26
5 files changed, 141 insertions, 26 deletions
diff --git a/chrome/browser/cocoa/bookmark_bar_controller.mm b/chrome/browser/cocoa/bookmark_bar_controller.mm
index ad92820..e30a1a2 100644
--- a/chrome/browser/cocoa/bookmark_bar_controller.mm
+++ b/chrome/browser/cocoa/bookmark_bar_controller.mm
@@ -10,10 +10,12 @@
#import "chrome/browser/cocoa/bookmark_bar_controller.h"
#import "chrome/browser/cocoa/bookmark_bar_view.h"
#import "chrome/browser/cocoa/bookmark_button_cell.h"
+#import "chrome/browser/cocoa/cocoa_utils.h"
#include "chrome/browser/profile.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/pref_service.h"
-#include "skia/ext/skia_utils_mac.h"
+
+using namespace CocoaUtils;
@interface BookmarkBarController(Private)
- (void)applyContentAreaOffset:(BOOL)apply;
@@ -165,7 +167,7 @@ const CGFloat kBookmarkHorizontalPadding = 8.0;
// (and their icons) are loaded on the IO thread to speed launch.
const SkBitmap& favicon = bookmarkModel_->GetFavIcon(node);
if (!favicon.isNull()) {
- NSImage* image = gfx::SkBitmapToNSImage(favicon);
+ NSImage* image = SkBitmapToNSImage(favicon);
if (image) {
[cell setImage:image];
[cell setImagePosition:NSImageLeft];
@@ -293,7 +295,7 @@ const CGFloat kBookmarkHorizontalPadding = 8.0;
void* pointer = [[cell representedObject] pointerValue];
BookmarkNode* cellnode = static_cast<BookmarkNode*>(pointer);
if (cellnode == node) {
- NSImage* image = gfx::SkBitmapToNSImage(bookmarkModel_->GetFavIcon(node));
+ NSImage* image = SkBitmapToNSImage(bookmarkModel_->GetFavIcon(node));
if (image) {
[cell setImage:image];
[cell setImagePosition:NSImageLeft];
diff --git a/chrome/browser/cocoa/cocoa_utils.h b/chrome/browser/cocoa/cocoa_utils.h
new file mode 100644
index 0000000..9f721d1
--- /dev/null
+++ b/chrome/browser/cocoa/cocoa_utils.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>
+#include "third_party/skia/include/core/SkBitmap.h"
+
+// Generic Cocoa utilities which fit nowhere else.
+
+namespace CocoaUtils {
+
+// Given an SkBitmap, return an autoreleased NSImage. This function
+// was not placed in
+// third_party/skia/src/utils/mac/SkCreateCGImageRef.cpp since that
+// would make Skia dependent on Cocoa.
+NSImage* SkBitmapToNSImage(const SkBitmap& icon);
+
+
+}; // namespace CocoaUtils
diff --git a/chrome/browser/cocoa/cocoa_utils.mm b/chrome/browser/cocoa/cocoa_utils.mm
new file mode 100644
index 0000000..9c7584d
--- /dev/null
+++ b/chrome/browser/cocoa/cocoa_utils.mm
@@ -0,0 +1,38 @@
+// 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/logging.h>
+#include "chrome/browser/cocoa/cocoa_utils.h"
+#import <QuartzCore/CIImage.h>
+#include "third_party/skia/include/utils/mac/SkCGUtils.h"
+#include "third_party/skia/include/core/SkColorPriv.h"
+
+namespace {
+
+// Callback passed to CGDataProviderCreateWithData()
+void ReleaseData(void* info, const void* pixelData, size_t size) {
+ // info is a non-const pixelData
+ if (info)
+ free(info);
+}
+
+}
+
+namespace CocoaUtils {
+
+NSImage* SkBitmapToNSImage(const SkBitmap& skiaBitmap) {
+ // First convert SkBitmap to CGImageRef.
+ CGImageRef cgimage = SkCreateCGImageRef(skiaBitmap);
+
+ // Now convert to NSImage.
+ NSBitmapImageRep* bitmap = [[[NSBitmapImageRep alloc]
+ initWithCGImage:cgimage] autorelease];
+ CFRelease(cgimage);
+ NSImage* image = [[[NSImage alloc] init] autorelease];
+ [image addRepresentation:bitmap];
+ return image;
+}
+
+} // namespace CocoaUtils
+
diff --git a/chrome/browser/cocoa/cocoa_utils_unittest.mm b/chrome/browser/cocoa/cocoa_utils_unittest.mm
new file mode 100644
index 0000000..41e188f
--- /dev/null
+++ b/chrome/browser/cocoa/cocoa_utils_unittest.mm
@@ -0,0 +1,76 @@
+// 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/cocoa_utils.h"
+#import "chrome/browser/cocoa/cocoa_test_helper.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace {
+
+class CocoaUtilsTest : public testing::Test {
+ public:
+ CocoaTestHelper cocoa_helper_; // Inits Cocoa, creates window, etc...
+
+ // If not red, is blue.
+ // If not tfbit (twenty-four-bit), is 444.
+ void ShapeHelper(int width, int height, bool isred, bool tfbit);
+};
+
+void CocoaUtilsTest::ShapeHelper(int width, int height,
+ bool isred, bool tfbit) {
+ SkBitmap thing;
+
+ if (tfbit)
+ thing.setConfig(SkBitmap::kARGB_8888_Config, width, height);
+ else
+ thing.setConfig(SkBitmap::kARGB_4444_Config, width, height);
+ thing.allocPixels();
+
+ if (isred)
+ thing.eraseRGB(0xff, 0, 0);
+ else
+ thing.eraseRGB(0, 0, 0xff);
+
+ // Confirm size
+ NSImage* image = CocoaUtils::SkBitmapToNSImage(thing);
+ EXPECT_DOUBLE_EQ([image size].width, (double)width);
+ EXPECT_DOUBLE_EQ([image size].height, (double)height);
+
+ // Get the color of a pixel and make sure it looks fine
+ [image lockFocus];
+
+ int x = width > 17 ? 17 : 0;
+ int y = height > 17 ? 17 : 0;
+ NSColor* color = NSReadPixel(NSMakePoint(x, y));
+ CGFloat red = 0, green = 0, blue = 0, alpha = 0;
+ [image unlockFocus];
+ [color getRed:&red green:&green blue:&blue alpha:&alpha];
+
+ // Be tolerant of floating point rounding, gamma, etc.
+ if (isred) {
+ EXPECT_GT(red, 0.8);
+ EXPECT_LT(blue, 0.2);
+ } else {
+ EXPECT_LT(red, 0.2);
+ EXPECT_GT(blue, 0.8);
+ }
+ EXPECT_LT(green, 0.2);
+ EXPECT_GT(alpha, 0.9);
+}
+
+
+TEST_F(CocoaUtilsTest, BitmapToNSImage_RedSquare64x64) {
+ ShapeHelper(64, 64, true, true);
+}
+
+TEST_F(CocoaUtilsTest, BitmapToNSImage_BlueRectangle199x19) {
+ ShapeHelper(199, 19, false, true);
+}
+
+TEST_F(CocoaUtilsTest, BitmapToNSImage_BlueRectangle444) {
+ ShapeHelper(200, 200, false, false);
+}
+
+
+} // namespace
diff --git a/chrome/browser/cocoa/tab_strip_controller.mm b/chrome/browser/cocoa/tab_strip_controller.mm
index a1fb188..90fced55 100644
--- a/chrome/browser/cocoa/tab_strip_controller.mm
+++ b/chrome/browser/cocoa/tab_strip_controller.mm
@@ -5,7 +5,6 @@
#import "chrome/browser/cocoa/tab_strip_controller.h"
#include "app/l10n_util.h"
-#include "base/mac_util.h"
#include "base/sys_string_conversions.h"
#include "chrome/app/chrome_dll_resource.h"
#include "chrome/browser/browser.h"
@@ -18,13 +17,10 @@
#import "chrome/browser/cocoa/tab_strip_model_observer_bridge.h"
#import "chrome/browser/cocoa/tab_view.h"
#import "chrome/browser/cocoa/throbber_view.h"
-#include "chrome/browser/tab_contents/navigation_controller.h"
-#include "chrome/browser/tab_contents/navigation_entry.h"
#include "chrome/browser/tab_contents/tab_contents.h"
#include "chrome/browser/tab_contents/tab_contents_view.h"
#include "chrome/browser/tabs/tab_strip_model.h"
#include "grit/generated_resources.h"
-#include "skia/ext/skia_utils_mac.h"
NSString* const kTabStripNumberOfTabsChanged = @"kTabStripNumberOfTabsChanged";
@@ -424,29 +420,13 @@ NSString* const kTabStripNumberOfTabsChanged = @"kTabStripNumberOfTabsChanged";
// A helper routine for creating an NSImageView to hold the fav icon for
// |contents|.
+// TODO(pinkerton): fill in with code to use the real favicon, not the default
+// for all cases.
- (NSImageView*)favIconImageViewForContents:(TabContents*)contents {
NSRect iconFrame = NSMakeRect(0, 0, 16, 16);
NSImageView* view = [[[NSImageView alloc] initWithFrame:iconFrame]
autorelease];
-
- NSImage* image = nil;
-
- NavigationEntry* navEntry = contents->controller().GetLastCommittedEntry();
- NavigationEntry::FaviconStatus favIcon = navEntry->favicon();
- const SkBitmap& bitmap = favIcon.bitmap();
- if (favIcon.is_valid() && !bitmap.isNull())
- image = gfx::SkBitmapToNSImage(bitmap);
-
- // Either we don't have a valid favicon or there was some issue converting it
- // from an SkBitmap. Either way, just show the default.
- if (!image) {
- NSBundle* bundle = mac_util::MainAppBundle();
- image = [[NSImage alloc] initByReferencingFile:
- [bundle pathForResource:@"nav" ofType:@"pdf"]];
- [image autorelease];
- }
-
- [view setImage:image];
+ [view setImage:[NSImage imageNamed:@"nav"]];
return view;
}