| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_controller.h" | 5 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_controller.h" |
| 6 | 6 |
| 7 #include "base/mac/bundle_locations.h" | 7 #include "base/mac/bundle_locations.h" |
| 8 #include "base/mac/mac_util.h" | 8 #include "base/mac/mac_util.h" |
| 9 #include "base/strings/sys_string_conversions.h" | 9 #include "base/strings/sys_string_conversions.h" |
| 10 #import "chrome/browser/bookmarks/bookmark_model_factory.h" | 10 #import "chrome/browser/bookmarks/bookmark_model_factory.h" |
| (...skipping 744 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 755 if (metrics.canScrollUp || metrics.canScrollDown) | 755 if (metrics.canScrollUp || metrics.canScrollDown) |
| 756 [self addOrUpdateScrollTracking]; | 756 [self addOrUpdateScrollTracking]; |
| 757 else | 757 else |
| 758 [self removeScrollTracking]; | 758 [self removeScrollTracking]; |
| 759 } | 759 } |
| 760 } | 760 } |
| 761 | 761 |
| 762 - (void)adjustWindowForButtonCount:(NSUInteger)buttonCount { | 762 - (void)adjustWindowForButtonCount:(NSUInteger)buttonCount { |
| 763 NSRect folderFrame = [folderView_ frame]; | 763 NSRect folderFrame = [folderView_ frame]; |
| 764 CGFloat newMenuHeight = | 764 CGFloat newMenuHeight = |
| 765 (CGFloat)[self menuHeightForButtonCount:[buttons_ count]]; | 765 (CGFloat)[self menuHeightForButtonCount:buttonCount]; |
| 766 CGFloat deltaMenuHeight = newMenuHeight - NSHeight(folderFrame); | 766 CGFloat deltaMenuHeight = newMenuHeight - NSHeight(folderFrame); |
| 767 // If the height has changed then also change the origin, and adjust the | 767 // If the height has changed then also change the origin, and adjust the |
| 768 // scroll (if scrolling). | 768 // scroll (if scrolling). |
| 769 if ([self canScrollUp]) { | 769 if ([self canScrollUp]) { |
| 770 NSPoint scrollPoint = [scrollView_ documentVisibleRect].origin; | 770 NSPoint scrollPoint = [scrollView_ documentVisibleRect].origin; |
| 771 scrollPoint.y += deltaMenuHeight; | 771 scrollPoint.y += deltaMenuHeight; |
| 772 [[scrollView_ documentView] scrollPoint:scrollPoint]; | 772 [[scrollView_ documentView] scrollPoint:scrollPoint]; |
| 773 } | 773 } |
| 774 folderFrame.size.height += deltaMenuHeight; | 774 folderFrame.size.height += deltaMenuHeight; |
| 775 [folderView_ setFrameSize:folderFrame.size]; | 775 [folderView_ setFrameSize:folderFrame.size]; |
| (...skipping 1153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1929 // Search for and adjust submenus, if necessary. | 1929 // Search for and adjust submenus, if necessary. |
| 1930 NSInteger buttonCount = [buttons_ count]; | 1930 NSInteger buttonCount = [buttons_ count]; |
| 1931 if (buttonCount) { | 1931 if (buttonCount) { |
| 1932 BookmarkButton* subButton = [folderController_ parentButton]; | 1932 BookmarkButton* subButton = [folderController_ parentButton]; |
| 1933 for (NSButton* aButton in buttons_.get()) { | 1933 for (NSButton* aButton in buttons_.get()) { |
| 1934 // If this button is showing its menu then we need to move the menu, too. | 1934 // If this button is showing its menu then we need to move the menu, too. |
| 1935 if (aButton == subButton) | 1935 if (aButton == subButton) |
| 1936 [folderController_ | 1936 [folderController_ |
| 1937 offsetFolderMenuWindow:NSMakeSize(0.0, chrome::kBookmarkBarHeight)]; | 1937 offsetFolderMenuWindow:NSMakeSize(0.0, chrome::kBookmarkBarHeight)]; |
| 1938 } | 1938 } |
| 1939 } else { | 1939 } else if (parentButton_ != [barController_ otherBookmarksButton]) { |
| 1940 // If all nodes have been removed from this folder then add in the | 1940 // If all nodes have been removed from this folder then add in the |
| 1941 // 'empty' placeholder button. | 1941 // 'empty' placeholder button except for "Other bookmarks" folder |
| 1942 // as we are going to hide it. |
| 1942 NSRect buttonFrame = | 1943 NSRect buttonFrame = |
| 1943 GetFirstButtonFrameForHeight([self menuHeightForButtonCount:1]); | 1944 GetFirstButtonFrameForHeight([self menuHeightForButtonCount:1]); |
| 1944 BookmarkButton* button = [self makeButtonForNode:nil | 1945 BookmarkButton* button = [self makeButtonForNode:nil |
| 1945 frame:buttonFrame]; | 1946 frame:buttonFrame]; |
| 1946 [buttons_ addObject:button]; | 1947 [buttons_ addObject:button]; |
| 1947 [folderView_ addSubview:button]; | 1948 [folderView_ addSubview:button]; |
| 1948 buttonCount = 1; | 1949 buttonCount = 1; |
| 1949 } | 1950 } |
| 1950 | 1951 |
| 1951 [self adjustWindowForButtonCount:buttonCount]; | 1952 // buttonCount will be 0 if "Other bookmarks" folder is empty, so close |
| 1953 // the folder before hiding it. |
| 1954 if (buttonCount == 0) |
| 1955 [barController_ closeBookmarkFolder:nil]; |
| 1956 else if (buttonCount > 0) |
| 1957 [self adjustWindowForButtonCount:buttonCount]; |
| 1952 | 1958 |
| 1953 if (animate && !ignoreAnimations_) | 1959 if (animate && !ignoreAnimations_) |
| 1954 NSShowAnimationEffect(NSAnimationEffectDisappearingItemDefault, poofPoint, | 1960 NSShowAnimationEffect(NSAnimationEffectDisappearingItemDefault, poofPoint, |
| 1955 NSZeroSize, nil, nil, nil); | 1961 NSZeroSize, nil, nil, nil); |
| 1956 } | 1962 } |
| 1957 | 1963 |
| 1958 - (id<BookmarkButtonControllerProtocol>)controllerForNode: | 1964 - (id<BookmarkButtonControllerProtocol>)controllerForNode: |
| 1959 (const BookmarkNode*)node { | 1965 (const BookmarkNode*)node { |
| 1960 // See if we are holding this node, otherwise see if it is in our | 1966 // See if we are holding this node, otherwise see if it is in our |
| 1961 // hierarchy of visible folder menus. | 1967 // hierarchy of visible folder menus. |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1992 | 1998 |
| 1993 - (void)setIgnoreAnimations:(BOOL)ignore { | 1999 - (void)setIgnoreAnimations:(BOOL)ignore { |
| 1994 ignoreAnimations_ = ignore; | 2000 ignoreAnimations_ = ignore; |
| 1995 } | 2001 } |
| 1996 | 2002 |
| 1997 - (BookmarkButton*)buttonThatMouseIsIn { | 2003 - (BookmarkButton*)buttonThatMouseIsIn { |
| 1998 return buttonThatMouseIsIn_; | 2004 return buttonThatMouseIsIn_; |
| 1999 } | 2005 } |
| 2000 | 2006 |
| 2001 @end // BookmarkBarFolderController | 2007 @end // BookmarkBarFolderController |
| OLD | NEW |