diff options
author | pinkerton@chromium.org <pinkerton@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-27 16:34:45 +0000 |
---|---|---|
committer | pinkerton@chromium.org <pinkerton@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-27 16:34:45 +0000 |
commit | 31f2bff6d9c109d6b4eb91cc0549c9d5b076ed5c (patch) | |
tree | 25f89dfb2e4cf781d019f839ac7dd320f196e234 /chrome/browser | |
parent | 280a4207de1c817dc7177cd75b6e7b295092ce30 (diff) | |
download | chromium_src-31f2bff6d9c109d6b4eb91cc0549c9d5b076ed5c.zip chromium_src-31f2bff6d9c109d6b4eb91cc0549c9d5b076ed5c.tar.gz chromium_src-31f2bff6d9c109d6b4eb91cc0549c9d5b076ed5c.tar.bz2 |
Hook up close button in tabs. Patch from rohitrao@google.com.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@12656 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/cocoa/browser_window_controller.mm | 2 | ||||
-rw-r--r-- | chrome/browser/cocoa/tab_cell.mm | 32 | ||||
-rw-r--r-- | chrome/browser/cocoa/tab_controller.h | 8 | ||||
-rw-r--r-- | chrome/browser/cocoa/tab_controller.mm | 12 | ||||
-rw-r--r-- | chrome/browser/cocoa/tab_strip_controller.h | 4 | ||||
-rw-r--r-- | chrome/browser/cocoa/tab_strip_controller.mm | 9 | ||||
-rw-r--r-- | chrome/browser/cocoa/tab_view.h | 4 | ||||
-rw-r--r-- | chrome/browser/cocoa/tab_view.mm | 8 |
8 files changed, 33 insertions, 46 deletions
diff --git a/chrome/browser/cocoa/browser_window_controller.mm b/chrome/browser/cocoa/browser_window_controller.mm index 06c629a..b749e17 100644 --- a/chrome/browser/cocoa/browser_window_controller.mm +++ b/chrome/browser/cocoa/browser_window_controller.mm @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#import "chrome/app/chrome_dll_resource.h" // IDC_* +#include "chrome/app/chrome_dll_resource.h" // IDC_* #include "chrome/browser/browser.h" #include "chrome/browser/browser_list.h" #include "chrome/browser/tabs/tab_strip_model.h" diff --git a/chrome/browser/cocoa/tab_cell.mm b/chrome/browser/cocoa/tab_cell.mm index f5895d3..0600c21 100644 --- a/chrome/browser/cocoa/tab_cell.mm +++ b/chrome/browser/cocoa/tab_cell.mm @@ -119,38 +119,6 @@ inView:controlView]; } -- (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView { - [super drawInteriorWithFrame:cellFrame inView:controlView]; - - void* voidContext = [[NSGraphicsContext currentContext] graphicsPort]; - CGContextRef c = static_cast<CGContextRef>(voidContext); - - // Build the rect for where we draw the close (x). - // TODO(alcor): This should be retrieved from a method that can also be called - // for hit-testing. Right now it also will overlap content if the page title - // is wide enough. - const int kCloseRectSize = 8; - NSRect closeRect, restRect; - NSDivideRect(cellFrame, &closeRect, &restRect, NSHeight(cellFrame), - NSMaxXEdge); - closeRect = NSInsetRect(closeRect, kCloseRectSize, kCloseRectSize); - - NSGradient *gradient = - [[GTMTheme defaultTheme] gradientForStyle:GTMThemeStyleTabBarSelected - active:YES]; - NSColor *color = [gradient interpolatedColorAtLocation:0.5]; - CGFloat luminance = [color gtm_luminance]; - - // Draw the (x). Fade the images as they move toward the contrasty ends of - // the spectrum - CGContextSetAlpha(c, 1.0 - fabsf(0.5 - luminance)); - CGContextBeginTransparencyLayer(c, NULL); - [self drawImage:[NSImage imageNamed:@"NSStopProgressTemplate"] - withFrame:closeRect - inView:controlView]; - CGContextEndTransparencyLayer(c); -} - - (void)highlight:(BOOL)flag withFrame:(NSRect)cellFrame inView:(NSView *)controlView { diff --git a/chrome/browser/cocoa/tab_controller.h b/chrome/browser/cocoa/tab_controller.h index 0760ccd..82f3bb5 100644 --- a/chrome/browser/cocoa/tab_controller.h +++ b/chrome/browser/cocoa/tab_controller.h @@ -8,6 +8,7 @@ #import <Cocoa/Cocoa.h> @class TabView; +@protocol TabControllerTarget; // A class that manages a single tab in the tab strip. Set its target/action // to be sent a message when the tab is selected by the user clicking. Setting @@ -17,12 +18,11 @@ @interface TabController : NSViewController { @private IBOutlet NSButton *backgroundButton_; - IBOutlet NSButton *closeButton_; IBOutlet NSProgressIndicator *progressIndicator_; BOOL selected_; BOOL loading_; NSImage *image_; - id target_; // weak, where actions are sent, eg selectTab: + id<TabControllerTarget> target_; // weak, where actions are sent SEL action_; // selector sent when tab is seleted by clicking } @@ -39,6 +39,10 @@ // The view associated with this controller, pre-casted as a TabView - (TabView *)tabView; +// Closes the associated TabView by relaying the message to |target_| to +// perform the close. +- (IBAction)closeTab:(id)sender; + @end #endif // CHROME_BROWSER_COCOA_TAB_CONTROLLER_H_ diff --git a/chrome/browser/cocoa/tab_controller.mm b/chrome/browser/cocoa/tab_controller.mm index 9021a2e..7d0f5e5 100644 --- a/chrome/browser/cocoa/tab_controller.mm +++ b/chrome/browser/cocoa/tab_controller.mm @@ -3,6 +3,7 @@ // found in the LICENSE file. #import "chrome/browser/cocoa/tab_controller.h" +#import "chrome/browser/cocoa/tab_controller_target.h" @implementation TabController @@ -36,13 +37,16 @@ [[self view] addSubview:backgroundButton_ positioned:NSWindowBelow relativeTo:nil]; - // TODO(alcor): figure out what to do with the close button v. cell. Note - // there is no close button in the nib at the moment. - [closeButton_ setWantsLayer:YES]; - [closeButton_ setAlphaValue:0.2]; [self setSelected:NO]; } +- (IBAction)closeTab:(id)sender { + if ([[self target] respondsToSelector:@selector(closeTab:)]) { + [[self target] performSelector:@selector(closeTab:) + withObject:[self view]]; + } +} + - (void)setSelected:(BOOL)selected { if (selected_ != selected) { selected_ = selected; diff --git a/chrome/browser/cocoa/tab_strip_controller.h b/chrome/browser/cocoa/tab_strip_controller.h index 1d6686a..89504fd 100644 --- a/chrome/browser/cocoa/tab_strip_controller.h +++ b/chrome/browser/cocoa/tab_strip_controller.h @@ -7,6 +7,8 @@ #import <Cocoa/Cocoa.h> +#import "chrome/browser/cocoa/tab_controller_target.h" + @class TabStripView; @class BookmarkBarStateController; @@ -30,7 +32,7 @@ class ToolbarModel; // the single child of the contentView is swapped around to hold the contents // (toolbar and all) representing that tab. -@interface TabStripController : NSObject { +@interface TabStripController : NSObject <TabControllerTarget> { @private TabContents* currentTab_; // weak, tab for which we're showing state TabStripView* tabView_; // weak diff --git a/chrome/browser/cocoa/tab_strip_controller.mm b/chrome/browser/cocoa/tab_strip_controller.mm index a11279f..46a98df 100644 --- a/chrome/browser/cocoa/tab_strip_controller.mm +++ b/chrome/browser/cocoa/tab_strip_controller.mm @@ -165,11 +165,18 @@ class TabStripBridge : public TabStripModelObserver { // Called when the user clicks a tab. Tell the model the selection has changed, // which feeds back into us via a notification. - (void)selectTab:(id)sender { - int index = [self indexForTabView:sender]; // for testing... + int index = [self indexForTabView:sender]; if (index >= 0 && tabModel_->ContainsIndex(index)) tabModel_->SelectTabContentsAt(index, true); } +// Called when the user closes a tab. Asks the model to close the tab. +- (void)closeTab:(id)sender { + int index = [self indexForTabView:sender]; + if (index >= 0 && tabModel_->ContainsIndex(index)) + tabModel_->CloseTabContentsAt(index); +} + // Lay out all tabs in the order of their TabContentsControllers, which matches // the ordering in the TabStripModel. This call isn't that expensive, though // it is O(n) in the number of tabs. Tabs will animate to their new position diff --git a/chrome/browser/cocoa/tab_view.h b/chrome/browser/cocoa/tab_view.h index a1ddee7..fda144f 100644 --- a/chrome/browser/cocoa/tab_view.h +++ b/chrome/browser/cocoa/tab_view.h @@ -16,8 +16,10 @@ @interface TabView : NSView { @private IBOutlet TabController* controller_; + // TODO(rohitrao): Add this button to a CoreAnimation layer so we can fade it + // in and out on mouseovers. + IBOutlet NSButton* closeButton_; } - @end #endif // CHROME_BROWSER_COCOA_TAB_VIEW_H_ diff --git a/chrome/browser/cocoa/tab_view.mm b/chrome/browser/cocoa/tab_view.mm index 26ec367..fa624a7 100644 --- a/chrome/browser/cocoa/tab_view.mm +++ b/chrome/browser/cocoa/tab_view.mm @@ -29,11 +29,11 @@ return YES; } -// Determines which view a click in our frame actually hit. It's always this -// view, never a child. -// TODO(alcor): Figure out what to do with the close button. Are we using a -// NSButton for it, or drawing it ourselves with a cell? +// Determines which view a click in our frame actually hit. It's either this +// view or our child close button. - (NSView *)hitTest:(NSPoint)aPoint { + NSPoint viewPoint = [self convertPoint:aPoint fromView:[self superview]]; + if (NSPointInRect(viewPoint, [closeButton_ frame])) return closeButton_; if (NSPointInRect(aPoint, [self frame])) return self; return nil; } |