summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormrossetti@chromium.org <mrossetti@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-26 20:09:18 +0000
committermrossetti@chromium.org <mrossetti@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-26 20:09:18 +0000
commita8e4a8fa39604cd309e1e3d62cf9c552dcfe541d (patch)
tree9ac98acea8834eff2c6298f931d03324b06fab21
parent6a0ee4ec5905be6182b20218da1c276fc7e457fd (diff)
downloadchromium_src-a8e4a8fa39604cd309e1e3d62cf9c552dcfe541d.zip
chromium_src-a8e4a8fa39604cd309e1e3d62cf9c552dcfe541d.tar.gz
chromium_src-a8e4a8fa39604cd309e1e3d62cf9c552dcfe541d.tar.bz2
Resize the "For quick access..." and "Import bookmarks now..." components shown in the bookmark bar when there are no bookmarks in the bar, when the window resizes. Show ellipses when each gets trimmed and hide them when they get too small.
BookmarkBar.xib changes: Connect the "Import bookmarks now..." button up to the importBookmarksButton_ outlet in the BookmarkBarView. BUG=32557 TEST=1) Start up a browser with no bookmarks on the bookmarks bar. 2) Verify that the "For quick access..." and "Import bookmarks now..." test fully shows. 3) Start shrinking the width of the browser window. 4) Verify that the "Import bookmarks now..." text is shrunk/clipped and finally disappears as the window gets narrower. 5) Continue shrinking the width and verify that the "For quick access..." text is shrunk/clipped with ellipses as the window gets narrower. 6) Grow the window and verify that the "For quick access..." reappears and then the "Import book now..." does. Review URL: http://codereview.chromium.org/2243002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@48316 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/app/nibs/BookmarkBar.xib38
-rw-r--r--chrome/browser/cocoa/bookmark_bar_controller.h6
-rw-r--r--chrome/browser/cocoa/bookmark_bar_controller.mm49
-rw-r--r--chrome/browser/cocoa/bookmark_bar_controller_unittest.mm19
-rw-r--r--chrome/browser/cocoa/bookmark_bar_view.h2
-rw-r--r--chrome/browser/cocoa/bookmark_bar_view.mm4
-rw-r--r--chrome/browser/cocoa/hyperlink_button_cell.mm15
7 files changed, 121 insertions, 12 deletions
diff --git a/chrome/app/nibs/BookmarkBar.xib b/chrome/app/nibs/BookmarkBar.xib
index b9700e7..8a8fce6 100644
--- a/chrome/app/nibs/BookmarkBar.xib
+++ b/chrome/app/nibs/BookmarkBar.xib
@@ -58,8 +58,8 @@
<reference key="NSSuperview" ref="1023728927"/>
<bool key="NSEnabled">YES</bool>
<object class="NSTextFieldCell" key="NSCell" id="458754719">
- <int key="NSCellFlags">605158976</int>
- <int key="NSCellFlags2">272761856</int>
+ <int key="NSCellFlags">604110400</int>
+ <int key="NSCellFlags2">272762880</int>
<string key="NSContents">^IDS_BOOKMARKS_NO_ITEMS</string>
<object class="NSFont" key="NSSupport" id="26">
<string key="NSName">LucidaGrande</string>
@@ -94,8 +94,8 @@
<reference key="NSSuperview" ref="1023728927"/>
<bool key="NSEnabled">YES</bool>
<object class="NSButtonCell" key="NSCell" id="976310023">
- <int key="NSCellFlags">67239424</int>
- <int key="NSCellFlags2">134348800</int>
+ <int key="NSCellFlags">67239488</int>
+ <int key="NSCellFlags2">133120</int>
<string key="NSContents">^IDS_BOOKMARK_BAR_IMPORT_LINK</string>
<reference key="NSSupport" ref="26"/>
<reference key="NSControlView" ref="1020224577"/>
@@ -845,6 +845,14 @@
</object>
<int key="connectionID">135</int>
</object>
+ <object class="IBConnectionRecord">
+ <object class="IBOutletConnection" key="connection">
+ <string key="label">importBookmarksButton_</string>
+ <reference key="source" ref="610146462"/>
+ <reference key="destination" ref="1020224577"/>
+ </object>
+ <int key="connectionID">136</int>
+ </object>
</object>
<object class="IBMutableOrderedSet" key="objectRecords">
<object class="NSArray" key="orderedObjects">
@@ -1323,7 +1331,7 @@
</object>
</object>
<nil key="sourceID"/>
- <int key="maxID">135</int>
+ <int key="maxID">136</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
@@ -1428,6 +1436,13 @@
</object>
</object>
<object class="IBPartialClassDescription">
+ <string key="className">BookmarkBarController</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier" id="1046231818">
+ <string key="majorKey">IBProjectSource</string>
+ <string key="minorKey">browser/cocoa/bookmark_bar_unittest_helper.h</string>
+ </object>
+ </object>
+ <object class="IBPartialClassDescription">
<string key="className">BookmarkBarToolbarView</string>
<string key="superclassName">AnimatableView</string>
<object class="NSMutableDictionary" key="outlets">
@@ -1447,12 +1462,14 @@
<object class="NSMutableArray" key="dict.sortedKeys">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>controller_</string>
+ <string>importBookmarksButton_</string>
<string>noItemContainer</string>
<string>noItemTextfield_</string>
</object>
<object class="NSMutableArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>BookmarkBarController</string>
+ <string>NSButton</string>
<string>NSView</string>
<string>NSTextField</string>
</object>
@@ -1472,6 +1489,10 @@
</object>
<object class="IBPartialClassDescription">
<string key="className">BookmarkButton</string>
+ <reference key="sourceIdentifier" ref="1046231818"/>
+ </object>
+ <object class="IBPartialClassDescription">
+ <string key="className">BookmarkButton</string>
<string key="superclassName">DraggableButton</string>
<object class="NSMutableDictionary" key="outlets">
<string key="NS.key.0">delegate_</string>
@@ -1626,6 +1647,13 @@
<string key="className">NSObject</string>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBProjectSource</string>
+ <string key="minorKey">browser/cocoa/objc_zombie.h</string>
+ </object>
+ </object>
+ <object class="IBPartialClassDescription">
+ <string key="className">NSObject</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBProjectSource</string>
<string key="minorKey">browser/cocoa/status_bubble_mac.h</string>
</object>
</object>
diff --git a/chrome/browser/cocoa/bookmark_bar_controller.h b/chrome/browser/cocoa/bookmark_bar_controller.h
index 51ebf6f..48e19b3 100644
--- a/chrome/browser/cocoa/bookmark_bar_controller.h
+++ b/chrome/browser/cocoa/bookmark_bar_controller.h
@@ -189,10 +189,13 @@ willAnimateFromState:(bookmarks::VisualState)oldState
// signal us to close the bookmark bar folder menus?
BOOL watchingForExitEvent_;
- IBOutlet BookmarkBarView* buttonView_;
+ IBOutlet BookmarkBarView* buttonView_; // Contains 'no items' text fields.
IBOutlet BookmarkButton* offTheSideButton_; // aka the chevron.
IBOutlet NSMenu* buttonContextMenu_;
+ NSRect originalNoItemsRect_; // Original, pre-resized field rect.
+ NSRect originalImportBookmarksRect_; // Original, pre-resized field rect.
+
// "Other bookmarks" button on the right side.
scoped_nsobject<NSButton> otherBookmarksButton_;
@@ -357,6 +360,7 @@ willAnimateFromState:(bookmarks::VisualState)oldState
- (void)updateTheme:(ThemeProvider*)themeProvider;
- (BookmarkButton*)buttonForDroppingOnAtPoint:(NSPoint)point;
- (BOOL)isEventAnExitEvent:(NSEvent*)event;
+- (BOOL)shrinkOrHideView:(NSView*)view forMaxX:(CGFloat)maxViewX;
// The following are for testing purposes only and are not used internally.
- (NSMenu *)menuForFolderNode:(const BookmarkNode*)node;
diff --git a/chrome/browser/cocoa/bookmark_bar_controller.mm b/chrome/browser/cocoa/bookmark_bar_controller.mm
index dd6a904..84c4845 100644
--- a/chrome/browser/cocoa/bookmark_bar_controller.mm
+++ b/chrome/browser/cocoa/bookmark_bar_controller.mm
@@ -281,6 +281,11 @@ const NSTimeInterval kBookmarkBarAnimationDuration = 0.12;
// We are enabled by default.
barIsEnabled_ = YES;
+ // Remember the original sizes of the 'no items' and 'import bookmarks'
+ // fields to aid in resizing when the window frame changes.
+ originalNoItemsRect_ = [[buttonView_ noItemTextfield] frame];
+ originalImportBookmarksRect_ = [[buttonView_ importBookmarksButton] frame];
+
// To make life happier when the bookmark bar is floating, the chevron is a
// child of the button view.
[offTheSideButton_ removeFromSuperview];
@@ -1212,6 +1217,45 @@ const NSTimeInterval kBookmarkBarAnimationDuration = 0.12;
[self centerNoItemsLabel];
}
+// Determine if the given |view| can completely fit within the constraint of
+// maximum x, given by |maxViewX|, and, if not, narrow the view up to a minimum
+// width. If the minimum width is not achievable then hide the view. Return YES
+// if the view was hidden.
+- (BOOL)shrinkOrHideView:(NSView*)view forMaxX:(CGFloat)maxViewX {
+ BOOL wasHidden = NO;
+ // See if the view needs to be narrowed.
+ NSRect frame = [view frame];
+ if (NSMaxX(frame) > maxViewX) {
+ // Resize if more than 30 pixels are showing, otherwise hide.
+ if (NSMinX(frame) + 30.0 < maxViewX) {
+ frame.size.width = maxViewX - NSMinX(frame);
+ [view setFrame:frame];
+ } else {
+ [view setHidden:YES];
+ wasHidden = YES;
+ }
+ }
+ return wasHidden;
+}
+
+// Adjust the horizontal width and the visibility of the "For quick access"
+// text field and "Import bookmarks..." button based on the current width
+// of the containing |buttonView_| (which is affected by window width).
+- (void)adjustNoItemContainerWidthsForMaxX:(CGFloat)maxViewX {
+ if (![[buttonView_ noItemContainer] isHidden]) {
+ // Reset initial frames for the two items, then adjust as necessary.
+ NSTextField* noItemTextfield = [buttonView_ noItemTextfield];
+ [noItemTextfield setFrame:originalNoItemsRect_];
+ [noItemTextfield setHidden:NO];
+ NSButton* importBookmarksButton = [buttonView_ importBookmarksButton];
+ [importBookmarksButton setFrame:originalImportBookmarksRect_];
+ [importBookmarksButton setHidden:NO];
+ // Check each to see if they need to be shrunk or hidden.
+ if ([self shrinkOrHideView:importBookmarksButton forMaxX:maxViewX])
+ [self shrinkOrHideView:noItemTextfield forMaxX:maxViewX];
+ }
+}
+
- (void)redistributeButtonsOnBarAsNeeded {
const BookmarkNode* node = bookmarkModel_->GetBookmarkBarNode();
NSInteger barCount = node->GetChildCount();
@@ -1259,6 +1303,11 @@ const NSTimeInterval kBookmarkBarAnimationDuration = 0.12;
[buttons_ addObject:button];
[buttonView_ addSubview:button];
}
+
+ // While we're here, adjust the horizontal width and the visibility
+ // of the "For quick access" and "Import bookmarks..." text fields.
+ if (![buttons_ count])
+ [self adjustNoItemContainerWidthsForMaxX:maxViewX];
}
#pragma mark Private Methods Exposed for Testing
diff --git a/chrome/browser/cocoa/bookmark_bar_controller_unittest.mm b/chrome/browser/cocoa/bookmark_bar_controller_unittest.mm
index 300d01c..5c2e8cc 100644
--- a/chrome/browser/cocoa/bookmark_bar_controller_unittest.mm
+++ b/chrome/browser/cocoa/bookmark_bar_controller_unittest.mm
@@ -1593,6 +1593,25 @@ TEST_F(BookmarkBarControllerTest, MoveRemoveAddButtons) {
EXPECT_EQ(oldDisplayedButtons, [bar_ displayedButtonCount]);
}
+TEST_F(BookmarkBarControllerTest, ShrinkOrHideView) {
+ NSRect viewFrame = NSMakeRect(0.0, 0.0, 500.0, 50.0);
+ NSView* view = [[[NSView alloc] initWithFrame:viewFrame] autorelease];
+ EXPECT_FALSE([view isHidden]);
+ [bar_ shrinkOrHideView:view forMaxX:500.0];
+ EXPECT_EQ(500.0, NSWidth([view frame]));
+ EXPECT_FALSE([view isHidden]);
+ [bar_ shrinkOrHideView:view forMaxX:450.0];
+ EXPECT_EQ(450.0, NSWidth([view frame]));
+ EXPECT_FALSE([view isHidden]);
+ [bar_ shrinkOrHideView:view forMaxX:40.0];
+ EXPECT_EQ(40.0, NSWidth([view frame]));
+ EXPECT_FALSE([view isHidden]);
+ [bar_ shrinkOrHideView:view forMaxX:31.0];
+ EXPECT_EQ(31.0, NSWidth([view frame]));
+ EXPECT_FALSE([view isHidden]);
+ [bar_ shrinkOrHideView:view forMaxX:29.0];
+ EXPECT_TRUE([view isHidden]);
+}
class BookmarkBarControllerOpenAllTest : public BookmarkBarControllerTest {
public:
diff --git a/chrome/browser/cocoa/bookmark_bar_view.h b/chrome/browser/cocoa/bookmark_bar_view.h
index 1e0bd3d..437b708 100644
--- a/chrome/browser/cocoa/bookmark_bar_view.h
+++ b/chrome/browser/cocoa/bookmark_bar_view.h
@@ -19,9 +19,11 @@
IBOutlet BookmarkBarController* controller_;
IBOutlet NSTextField* noItemTextfield_;
+ IBOutlet NSButton* importBookmarksButton_;
NSView* noItemContainer_;
}
- (NSTextField*)noItemTextfield;
+- (NSButton*)importBookmarksButton;
- (BookmarkBarController*)controller;
@property (assign, nonatomic) IBOutlet NSView* noItemContainer;
diff --git a/chrome/browser/cocoa/bookmark_bar_view.mm b/chrome/browser/cocoa/bookmark_bar_view.mm
index 6923081..f2f2ea5 100644
--- a/chrome/browser/cocoa/bookmark_bar_view.mm
+++ b/chrome/browser/cocoa/bookmark_bar_view.mm
@@ -95,6 +95,10 @@
return noItemTextfield_;
}
+-(NSButton*)importBookmarksButton {
+ return importBookmarksButton_;
+}
+
- (BookmarkBarController*)controller {
return controller_;
}
diff --git a/chrome/browser/cocoa/hyperlink_button_cell.mm b/chrome/browser/cocoa/hyperlink_button_cell.mm
index a087d29..12c4fec 100644
--- a/chrome/browser/cocoa/hyperlink_button_cell.mm
+++ b/chrome/browser/cocoa/hyperlink_button_cell.mm
@@ -81,15 +81,18 @@
];
}
-// Override the drawing point for the cell so that the custom style attributes
-// can always be applied.
+// Override the drawing for the cell so that the custom style attributes
+// can always be applied and so that ellipses will appear when appropriate.
- (NSRect)drawTitle:(NSAttributedString*)title
withFrame:(NSRect)frame
inView:(NSView*)controlView {
- scoped_nsobject<NSAttributedString> attrString(
- [[NSAttributedString alloc] initWithString:[title string]
- attributes:[self linkAttributes]]);
- return [super drawTitle:attrString.get() withFrame:frame inView:controlView];
+ NSDictionary* linkAttributes = [self linkAttributes];
+ NSString* plainTitle = [title string];
+ [plainTitle drawWithRect:frame
+ options:(NSStringDrawingUsesLineFragmentOrigin |
+ NSStringDrawingTruncatesLastVisibleLine)
+ attributes:linkAttributes];
+ return frame;
}
// Override the default behavior to draw the border. Instead, change the cursor.