diff options
author | andybons@chromium.org <andybons@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-12 05:18:50 +0000 |
---|---|---|
committer | andybons@chromium.org <andybons@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-12 05:18:50 +0000 |
commit | d64f2a0ea7adada3e5221782e4739a9b858c53fd (patch) | |
tree | 08ca665b6c99e92bc12217dad7db5ed016bfca51 /chrome/browser | |
parent | 87eacb992a5fcc517a29a7097937df217b6839ff (diff) | |
download | chromium_src-d64f2a0ea7adada3e5221782e4739a9b858c53fd.zip chromium_src-d64f2a0ea7adada3e5221782e4739a9b858c53fd.tar.gz chromium_src-d64f2a0ea7adada3e5221782e4739a9b858c53fd.tar.bz2 |
o Renames the bookmark bubble class to InfoBubble in a step to make it more reusable.
o Adds the ability to position the arrow of the bubble on the top right as well as the top left (default).
BUG=none
TEST=Nothing should change visually. This is prep for use by browser action popups and the first run UI.
Review URL: http://codereview.chromium.org/385060
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@31764 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/cocoa/bookmark_bubble_view.h | 11 | ||||
-rw-r--r-- | chrome/browser/cocoa/bookmark_bubble_window_unittest.mm | 25 | ||||
-rw-r--r-- | chrome/browser/cocoa/info_bubble_view.h | 21 | ||||
-rw-r--r-- | chrome/browser/cocoa/info_bubble_view.mm (renamed from chrome/browser/cocoa/bookmark_bubble_view.mm) | 35 | ||||
-rw-r--r-- | chrome/browser/cocoa/info_bubble_view_unittest.mm (renamed from chrome/browser/cocoa/bookmark_bubble_view_unittest.mm) | 14 | ||||
-rw-r--r-- | chrome/browser/cocoa/info_bubble_window.h (renamed from chrome/browser/cocoa/bookmark_bubble_window.h) | 5 | ||||
-rw-r--r-- | chrome/browser/cocoa/info_bubble_window.mm (renamed from chrome/browser/cocoa/bookmark_bubble_window.mm) | 10 | ||||
-rw-r--r-- | chrome/browser/cocoa/info_bubble_window_unittest.mm | 22 |
8 files changed, 87 insertions, 56 deletions
diff --git a/chrome/browser/cocoa/bookmark_bubble_view.h b/chrome/browser/cocoa/bookmark_bubble_view.h deleted file mode 100644 index 1e811a8..0000000 --- a/chrome/browser/cocoa/bookmark_bubble_view.h +++ /dev/null @@ -1,11 +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> - -// Content view for a Bookmark Bubble opened by clicking on the star -// toolbar button. This is where nonrectangular drawing happens. -@interface BookmarkBubbleView : NSView -@end - diff --git a/chrome/browser/cocoa/bookmark_bubble_window_unittest.mm b/chrome/browser/cocoa/bookmark_bubble_window_unittest.mm deleted file mode 100644 index bae4697..0000000 --- a/chrome/browser/cocoa/bookmark_bubble_window_unittest.mm +++ /dev/null @@ -1,25 +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_ptr.h" -#include "chrome/browser/cocoa/cocoa_test_helper.h" -#include "chrome/browser/cocoa/bookmark_bubble_window.h" - -class BookmarkBubbleWindowTest : public CocoaTest { -}; - -TEST_F(BookmarkBubbleWindowTest, Basics) { - BookmarkBubbleWindow* window = - [[BookmarkBubbleWindow alloc] initWithContentRect:NSMakeRect(0, 0, 10, 10) - styleMask:NSBorderlessWindowMask - backing:NSBackingStoreBuffered - defer:NO]; - EXPECT_TRUE([window canBecomeKeyWindow]); - EXPECT_FALSE([window canBecomeMainWindow]); - - EXPECT_TRUE([window isExcludedFromWindowsMenu]); - [window close]; -} - - diff --git a/chrome/browser/cocoa/info_bubble_view.h b/chrome/browser/cocoa/info_bubble_view.h new file mode 100644 index 0000000..fc95bc9 --- /dev/null +++ b/chrome/browser/cocoa/info_bubble_view.h @@ -0,0 +1,21 @@ +// 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> + +enum BubbleArrowLocation { + kTopLeft, + kTopRight, +}; + +// Content view for a bubble with an arrow showing arbitrary content. +// This is where nonrectangular drawing happens. +@interface InfoBubbleView : NSView { + @private + BubbleArrowLocation arrowLocation_; +} + +@property (assign, nonatomic) BubbleArrowLocation arrowLocation; + +@end diff --git a/chrome/browser/cocoa/bookmark_bubble_view.mm b/chrome/browser/cocoa/info_bubble_view.mm index 18f589c..e8c288d 100644 --- a/chrome/browser/cocoa/bookmark_bubble_view.mm +++ b/chrome/browser/cocoa/info_bubble_view.mm @@ -2,18 +2,30 @@ // 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_bubble_view.h" +#import "chrome/browser/cocoa/info_bubble_view.h" + +#include "base/logging.h" #import "third_party/GTM/AppKit/GTMTheme.h" namespace { -// TODO(jrg): confirm constants with UI dudes +// TODO(andybons): confirm constants with UI dudes const CGFloat kBubbleCornerRadius = 8.0; const CGFloat kBubbleArrowXOffset = 10.0; const CGFloat kBubbleArrowWidth = 15.0; const CGFloat kBubbleArrowHeight = 8.0; } -@implementation BookmarkBubbleView +@implementation InfoBubbleView + +@synthesize arrowLocation = arrowLocation_; + +- (id)initWithFrame:(NSRect)frameRect { + if ((self = [super initWithFrame:frameRect])) { + arrowLocation_ = kTopLeft; + } + + return self; +} - (void)drawRect:(NSRect)rect { // Make room for the border to be seen. @@ -27,9 +39,21 @@ const CGFloat kBubbleArrowHeight = 8.0; xRadius:kBubbleCornerRadius yRadius:kBubbleCornerRadius]; - // Add the bubble arrow (pointed at the star). + // Add the bubble arrow. + CGFloat dX; + switch (arrowLocation_) { + case kTopLeft: + dX = kBubbleArrowXOffset; + break; + case kTopRight: + dX = NSWidth(bounds) - kBubbleArrowXOffset - kBubbleArrowWidth; + break; + default: + NOTREACHED(); + break; + } NSPoint arrowStart = NSMakePoint(NSMinX(bounds), NSMaxY(bounds)); - arrowStart.x += kBubbleArrowXOffset; + arrowStart.x += dX; [bezier moveToPoint:NSMakePoint(arrowStart.x, arrowStart.y)]; [bezier lineToPoint:NSMakePoint(arrowStart.x + kBubbleArrowWidth/2.0, arrowStart.y + kBubbleArrowHeight)]; @@ -45,4 +69,3 @@ const CGFloat kBubbleArrowHeight = 8.0; } @end - diff --git a/chrome/browser/cocoa/bookmark_bubble_view_unittest.mm b/chrome/browser/cocoa/info_bubble_view_unittest.mm index f9083f7..2f07c8b 100644 --- a/chrome/browser/cocoa/bookmark_bubble_view_unittest.mm +++ b/chrome/browser/cocoa/info_bubble_view_unittest.mm @@ -3,24 +3,24 @@ // found in the LICENSE file. #include "base/scoped_nsobject.h" -#import "chrome/browser/cocoa/bookmark_bubble_view.h" +#import "chrome/browser/cocoa/info_bubble_view.h" #import "chrome/browser/cocoa/cocoa_test_helper.h" namespace { -class BookmarkBubbleViewTest : public CocoaTest { +class InfoBubbleViewTest : public CocoaTest { public: - BookmarkBubbleViewTest() { + InfoBubbleViewTest() { NSRect frame = NSMakeRect(0, 0, 100, 30); - scoped_nsobject<BookmarkBubbleView> view( - [[BookmarkBubbleView alloc] initWithFrame:frame]); + scoped_nsobject<InfoBubbleView> view( + [[InfoBubbleView alloc] initWithFrame:frame]); view_ = view.get(); [[test_window() contentView] addSubview:view_]; } - BookmarkBubbleView* view_; + InfoBubbleView* view_; }; -TEST_VIEW(BookmarkBubbleViewTest, view_); +TEST_VIEW(InfoBubbleViewTest, view_); } // namespace diff --git a/chrome/browser/cocoa/bookmark_bubble_window.h b/chrome/browser/cocoa/info_bubble_window.h index 5e667ad..bd549d1 100644 --- a/chrome/browser/cocoa/bookmark_bubble_window.h +++ b/chrome/browser/cocoa/info_bubble_window.h @@ -4,6 +4,7 @@ #import <Cocoa/Cocoa.h> -// Window for the bookmark bubble that comes up when you click on "STAR". -@interface BookmarkBubbleWindow : NSWindow +// A rounded window with an arrow used for example when you click on the STAR +// button or that pops up within our first-run UI. +@interface InfoBubbleWindow : NSWindow @end diff --git a/chrome/browser/cocoa/bookmark_bubble_window.mm b/chrome/browser/cocoa/info_bubble_window.mm index 4b2e372..9941c62 100644 --- a/chrome/browser/cocoa/bookmark_bubble_window.mm +++ b/chrome/browser/cocoa/info_bubble_window.mm @@ -2,9 +2,9 @@ // 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_bubble_window.h" +#import "chrome/browser/cocoa/info_bubble_window.h" -@implementation BookmarkBubbleWindow +@implementation InfoBubbleWindow - (id)initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)aStyle @@ -25,9 +25,9 @@ // According to // http://www.cocoabuilder.com/archive/message/cocoa/2006/6/19/165953, -// NSBorderlessWindowMask windows cannot become key or main. In our -// case, however, we don't want all of that behavior. (As an example, -// our bubble has buttons!) +// NSBorderlessWindowMask windows cannot become key or main. In our +// case, however, we don't want all of that behavior. As an example, +// our bubble could have buttons. - (BOOL)canBecomeKeyWindow { return YES; diff --git a/chrome/browser/cocoa/info_bubble_window_unittest.mm b/chrome/browser/cocoa/info_bubble_window_unittest.mm new file mode 100644 index 0000000..11a07fe --- /dev/null +++ b/chrome/browser/cocoa/info_bubble_window_unittest.mm @@ -0,0 +1,22 @@ +// 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_ptr.h" +#include "chrome/browser/cocoa/cocoa_test_helper.h" +#include "chrome/browser/cocoa/info_bubble_window.h" + +class InfoBubbleWindowTest : public CocoaTest {}; + +TEST_F(InfoBubbleWindowTest, Basics) { + InfoBubbleWindow* window = + [[InfoBubbleWindow alloc] initWithContentRect:NSMakeRect(0, 0, 10, 10) + styleMask:NSBorderlessWindowMask + backing:NSBackingStoreBuffered + defer:NO]; + EXPECT_TRUE([window canBecomeKeyWindow]); + EXPECT_FALSE([window canBecomeMainWindow]); + + EXPECT_TRUE([window isExcludedFromWindowsMenu]); + [window close]; +} |