Skip to content

Commit

Permalink
Reverting r19244 as it unintentionally broke ui tests: OtherRedirects…
Browse files Browse the repository at this point in the history
…DontForkProcess InEmptyFrame TestLifetimeOfDomAutomationController

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@19245 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
avi@chromium.org committed Jun 25, 2009
1 parent ef8ca82 commit a4ae3e1
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 56 deletions.
8 changes: 5 additions & 3 deletions chrome/browser/cocoa/bookmark_bar_controller.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -165,7 +167,7 @@ - (NSCell *)cellForBookmarkNode:(BookmarkNode*)node frame:(NSRect)frame {
// (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];
Expand Down Expand Up @@ -293,7 +295,7 @@ - (void)nodeFavIconLoaded:(BookmarkModel*)model
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];
Expand Down
19 changes: 19 additions & 0 deletions chrome/browser/cocoa/cocoa_utils.h
Original file line number Diff line number Diff line change
@@ -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
38 changes: 38 additions & 0 deletions chrome/browser/cocoa/cocoa_utils.mm
Original file line number Diff line number Diff line change
@@ -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

Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,23 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "skia/ext/skia_utils_mac.mm"
#import "chrome/browser/cocoa/cocoa_utils.h"
#import "chrome/browser/cocoa/cocoa_test_helper.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace {

class SkiaUtilsMacTest : public testing::Test {
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 SkiaUtilsMacTest::ShapeHelper(int width, int height,
bool isred, bool tfbit) {
void CocoaUtilsTest::ShapeHelper(int width, int height,
bool isred, bool tfbit) {
SkBitmap thing;

if (tfbit)
Expand All @@ -30,7 +33,7 @@
thing.eraseRGB(0, 0, 0xff);

// Confirm size
NSImage* image = gfx::SkBitmapToNSImage(thing);
NSImage* image = CocoaUtils::SkBitmapToNSImage(thing);
EXPECT_DOUBLE_EQ([image size].width, (double)width);
EXPECT_DOUBLE_EQ([image size].height, (double)height);

Expand All @@ -56,16 +59,18 @@
EXPECT_GT(alpha, 0.9);
}

TEST_F(SkiaUtilsMacTest, BitmapToNSImage_RedSquare64x64) {

TEST_F(CocoaUtilsTest, BitmapToNSImage_RedSquare64x64) {
ShapeHelper(64, 64, true, true);
}

TEST_F(SkiaUtilsMacTest, BitmapToNSImage_BlueRectangle199x19) {
TEST_F(CocoaUtilsTest, BitmapToNSImage_BlueRectangle199x19) {
ShapeHelper(199, 19, false, true);
}

TEST_F(SkiaUtilsMacTest, BitmapToNSImage_BlueRectangle444) {
TEST_F(CocoaUtilsTest, BitmapToNSImage_BlueRectangle444) {
ShapeHelper(200, 200, false, false);
}


} // namespace
26 changes: 3 additions & 23 deletions chrome/browser/cocoa/tab_strip_controller.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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";

Expand Down Expand Up @@ -424,29 +420,13 @@ - (void)tabDetachedWithContents:(TabContents*)contents

// 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;
}

Expand Down
3 changes: 3 additions & 0 deletions chrome/chrome.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,8 @@
'browser/cocoa/clear_browsing_data_controller.h',
'browser/cocoa/clear_browsing_data_controller.mm',
'browser/cocoa/cocoa_test_helper.h',
'browser/cocoa/cocoa_utils.h',
'browser/cocoa/cocoa_utils.mm',
'browser/cocoa/command_observer_bridge.h',
'browser/cocoa/command_observer_bridge.mm',
'browser/cocoa/custom_home_pages_model.h',
Expand Down Expand Up @@ -3374,6 +3376,7 @@
'browser/cocoa/bookmark_menu_cocoa_controller_unittest.mm',
'browser/cocoa/browser_window_cocoa_unittest.mm',
'browser/cocoa/browser_window_controller_unittest.mm',
'browser/cocoa/cocoa_utils_unittest.mm',
'browser/cocoa/command_observer_bridge_unittest.mm',
'browser/cocoa/custom_home_pages_model_unittest.mm',
'browser/cocoa/download_shelf_mac_unittest.mm',
Expand Down
3 changes: 0 additions & 3 deletions skia/ext/skia_utils_mac.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@ SkBitmap CGImageToSkBitmap(CGImageRef image);
#ifdef __OBJC__
// Draws an NSImage with a given size into a SkBitmap.
SkBitmap NSImageToSkBitmap(NSImage* image, NSSize size, bool is_opaque);

// Given an SkBitmap, return an autoreleased NSImage.
NSImage* SkBitmapToNSImage(const SkBitmap& icon);
#endif

} // namespace gfx
Expand Down
15 changes: 0 additions & 15 deletions skia/ext/skia_utils_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
#include "base/scoped_cftyperef.h"
#include "base/scoped_ptr.h"
#include "skia/ext/bitmap_platform_device_mac.h"
#include "third_party/skia/include/utils/mac/SkCGUtils.h"
#include "third_party/skia/include/core/SkColorPriv.h"

namespace gfx {

Expand Down Expand Up @@ -167,17 +165,4 @@ SkBitmap NSImageToSkBitmap(NSImage* image, NSSize size, bool is_opaque) {
return bitmap;
}

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 gfx
5 changes: 1 addition & 4 deletions webkit/tools/test_shell/test_shell.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -521,10 +521,7 @@
'../webcore_unit_tests/XBMImageDecoder_unittest.cpp',
'image_decoder_unittest.cc',
'image_decoder_unittest.h',
],
'sources': [
'../../../skia/ext/skia_utils_mac_unittest.mm',
],
]
}],
['OS=="win"', {
'msvs_disabled_warnings': [ 4800 ],
Expand Down

0 comments on commit a4ae3e1

Please sign in to comment.