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 | |
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
-rw-r--r-- | chrome/app/nibs/en.lproj/TabView.xib | 96 | ||||
-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 |
9 files changed, 121 insertions, 54 deletions
diff --git a/chrome/app/nibs/en.lproj/TabView.xib b/chrome/app/nibs/en.lproj/TabView.xib index 4b5a3ca..ff144f7 100644 --- a/chrome/app/nibs/en.lproj/TabView.xib +++ b/chrome/app/nibs/en.lproj/TabView.xib @@ -2,13 +2,13 @@ <archive type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="7.03"> <data> <int key="IBDocument.SystemTarget">1050</int> - <string key="IBDocument.SystemVersion">9F33</string> + <string key="IBDocument.SystemVersion">9G55</string> <string key="IBDocument.InterfaceBuilderVersion">677</string> - <string key="IBDocument.AppKitVersion">949.34</string> - <string key="IBDocument.HIToolboxVersion">352.00</string> + <string key="IBDocument.AppKitVersion">949.43</string> + <string key="IBDocument.HIToolboxVersion">353.00</string> <object class="NSMutableArray" key="IBDocument.EditedObjectIDs"> <bool key="EncodedWithXMLCoder">YES</bool> - <integer value="18"/> + <integer value="1"/> </object> <object class="NSArray" key="IBDocument.PluginDependencies"> <bool key="EncodedWithXMLCoder">YES</bool> @@ -110,6 +110,34 @@ <double key="NSMinValue">1.600000e+01</double> <double key="NSMaxValue">1.000000e+02</double> </object> + <object class="NSButton" id="1054640993"> + <reference key="NSNextResponder" ref="1005"/> + <int key="NSvFlags">297</int> + <string key="NSFrame">{{134, 7}, {10, 10}}</string> + <reference key="NSSuperview" ref="1005"/> + <bool key="NSEnabled">YES</bool> + <object class="NSButtonCell" key="NSCell" id="348599947"> + <int key="NSCellFlags">67239424</int> + <int key="NSCellFlags2">134217728</int> + <string key="NSContents">Close</string> + <object class="NSFont" key="NSSupport"> + <string key="NSName">LucidaGrande</string> + <double key="NSSize">1.300000e+01</double> + <int key="NSfFlags">1044</int> + </object> + <reference key="NSControlView" ref="1054640993"/> + <int key="NSButtonFlags">-2042347265</int> + <int key="NSButtonFlags2">134</int> + <object class="NSCustomResource" key="NSNormalImage"> + <string key="NSClassName">NSImage</string> + <string key="NSResourceName">NSStopProgressTemplate</string> + </object> + <string key="NSAlternateContents"/> + <string key="NSKeyEquivalent"/> + <int key="NSPeriodicDelay">400</int> + <int key="NSPeriodicInterval">75</int> + </object> + </object> </object> <string key="NSFrameSize">{160, 25}</string> <reference key="NSSuperview"/> @@ -236,6 +264,22 @@ </object> <int key="connectionID">47</int> </object> + <object class="IBConnectionRecord"> + <object class="IBOutletConnection" key="connection"> + <string key="label">closeButton_</string> + <reference key="source" ref="1005"/> + <reference key="destination" ref="1054640993"/> + </object> + <int key="connectionID">52</int> + </object> + <object class="IBConnectionRecord"> + <object class="IBActionConnection" key="connection"> + <string key="label">closeTab:</string> + <reference key="source" ref="1001"/> + <reference key="destination" ref="1054640993"/> + </object> + <int key="connectionID">54</int> + </object> </object> <object class="IBMutableOrderedSet" key="objectRecords"> <object class="NSArray" key="orderedObjects"> @@ -274,6 +318,7 @@ <reference ref="569334633"/> <reference ref="58797509"/> <reference ref="279592484"/> + <reference ref="1054640993"/> </object> <reference key="parent" ref="1002"/> </object> @@ -310,6 +355,20 @@ <reference key="object" ref="707804163"/> <reference key="parent" ref="279592484"/> </object> + <object class="IBObjectRecord"> + <int key="objectID">50</int> + <reference key="object" ref="1054640993"/> + <object class="NSMutableArray" key="children"> + <bool key="EncodedWithXMLCoder">YES</bool> + <reference ref="348599947"/> + </object> + <reference key="parent" ref="1005"/> + </object> + <object class="IBObjectRecord"> + <int key="objectID">51</int> + <reference key="object" ref="348599947"/> + <reference key="parent" ref="1054640993"/> + </object> </object> </object> <object class="NSMutableDictionary" key="flattenedProperties"> @@ -329,13 +388,15 @@ <string>17.IBPluginDependency</string> <string>18.CustomClassName</string> <string>18.IBPluginDependency</string> + <string>50.IBPluginDependency</string> + <string>51.IBPluginDependency</string> </object> <object class="NSMutableArray" key="dict.values"> <bool key="EncodedWithXMLCoder">YES</bool> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>com.apple.InterfaceBuilderKit</string> <string>com.apple.InterfaceBuilderKit</string> - <string>{{833, 498}, {160, 25}}</string> + <string>{{831, 498}, {160, 25}}</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <boolean value="NO"/> <string>{628, 654}</string> @@ -345,6 +406,8 @@ <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>TabCell</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> + <string>com.apple.InterfaceBuilder.CocoaPlugin</string> + <string>com.apple.InterfaceBuilder.CocoaPlugin</string> </object> </object> <object class="NSMutableDictionary" key="unlocalizedProperties"> @@ -367,7 +430,7 @@ </object> </object> <nil key="sourceID"/> - <int key="maxID">49</int> + <int key="maxID">54</int> </object> <object class="IBClassDescriber" key="IBDocument.Classes"> <object class="NSMutableArray" key="referencedPartialClassDescriptions"> @@ -383,6 +446,10 @@ <object class="IBPartialClassDescription"> <string key="className">TabController</string> <string key="superclassName">NSViewController</string> + <object class="NSMutableDictionary" key="actions"> + <string key="NS.key.0">closeTab:</string> + <string key="NS.object.0">id</string> + </object> <object class="NSMutableDictionary" key="outlets"> <bool key="EncodedWithXMLCoder">YES</bool> <object class="NSMutableArray" key="dict.sortedKeys"> @@ -408,9 +475,22 @@ <object class="IBPartialClassDescription"> <string key="className">TabView</string> <string key="superclassName">NSView</string> + <object class="NSMutableDictionary" key="actions"> + <string key="NS.key.0">closeTab:</string> + <string key="NS.object.0">id</string> + </object> <object class="NSMutableDictionary" key="outlets"> - <string key="NS.key.0">controller_</string> - <string key="NS.object.0">TabController</string> + <bool key="EncodedWithXMLCoder">YES</bool> + <object class="NSMutableArray" key="dict.sortedKeys"> + <bool key="EncodedWithXMLCoder">YES</bool> + <string>closeButton_</string> + <string>controller_</string> + </object> + <object class="NSMutableArray" key="dict.values"> + <bool key="EncodedWithXMLCoder">YES</bool> + <string>NSButton</string> + <string>TabController</string> + </object> </object> <object class="IBClassDescriptionSource" key="sourceIdentifier"> <string key="majorKey">IBProjectSource</string> 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; } |