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_controller.h" | 5 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_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/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 // related logic. | 122 // related logic. |
123 // - The BWC's |-layoutSubviews| needs to know how to position things. | 123 // - The BWC's |-layoutSubviews| needs to know how to position things. |
124 // - The BWC should implement |-bookmarkBar:didChangeFromState:toState:| and | 124 // - The BWC should implement |-bookmarkBar:didChangeFromState:toState:| and |
125 // |-bookmarkBar:willAnimateFromState:toState:| in order to inform the | 125 // |-bookmarkBar:willAnimateFromState:toState:| in order to inform the |
126 // toolbar of required changes. | 126 // toolbar of required changes. |
127 | 127 |
128 namespace { | 128 namespace { |
129 | 129 |
130 // Duration of the bookmark bar animations. | 130 // Duration of the bookmark bar animations. |
131 const NSTimeInterval kBookmarkBarAnimationDuration = 0.12; | 131 const NSTimeInterval kBookmarkBarAnimationDuration = 0.12; |
| 132 const NSTimeInterval kDragAndDropAnimationDuration = 0.25; |
132 | 133 |
133 void RecordAppLaunch(Profile* profile, GURL url) { | 134 void RecordAppLaunch(Profile* profile, GURL url) { |
134 DCHECK(profile->GetExtensionService()); | 135 DCHECK(profile->GetExtensionService()); |
135 const extensions::Extension* extension = | 136 const extensions::Extension* extension = |
136 profile->GetExtensionService()->GetInstalledApp(url); | 137 profile->GetExtensionService()->GetInstalledApp(url); |
137 if (!extension) | 138 if (!extension) |
138 return; | 139 return; |
139 | 140 |
140 CoreAppLauncherHandler::RecordAppLaunchType( | 141 CoreAppLauncherHandler::RecordAppLaunchType( |
141 extension_misc::APP_LAUNCH_BOOKMARK_BAR, | 142 extension_misc::APP_LAUNCH_BOOKMARK_BAR, |
(...skipping 1797 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1939 NSMaxX([appsPageShortcutButton_ frame]) + | 1940 NSMaxX([appsPageShortcutButton_ frame]) + |
1940 bookmarks::kBookmarkHorizontalPadding; | 1941 bookmarks::kBookmarkHorizontalPadding; |
1941 CGFloat paddingWidth = bookmarks::kDefaultBookmarkWidth; | 1942 CGFloat paddingWidth = bookmarks::kDefaultBookmarkWidth; |
1942 BookmarkButton* draggedButton = [BookmarkButton draggedButton]; | 1943 BookmarkButton* draggedButton = [BookmarkButton draggedButton]; |
1943 if (draggedButton) { | 1944 if (draggedButton) { |
1944 paddingWidth = std::min(bookmarks::kDefaultBookmarkWidth, | 1945 paddingWidth = std::min(bookmarks::kDefaultBookmarkWidth, |
1945 NSWidth([draggedButton frame])); | 1946 NSWidth([draggedButton frame])); |
1946 } | 1947 } |
1947 // Put all the buttons where they belong, with all buttons to the right | 1948 // Put all the buttons where they belong, with all buttons to the right |
1948 // of the insertion point shuffling right to make space for it. | 1949 // of the insertion point shuffling right to make space for it. |
| 1950 [NSAnimationContext beginGrouping]; |
| 1951 [[NSAnimationContext currentContext] |
| 1952 setDuration:kDragAndDropAnimationDuration]; |
1949 for (NSButton* button in buttons_.get()) { | 1953 for (NSButton* button in buttons_.get()) { |
1950 // Hidden buttons get no space. | 1954 // Hidden buttons get no space. |
1951 if ([button isHidden]) | 1955 if ([button isHidden]) |
1952 continue; | 1956 continue; |
1953 NSRect buttonFrame = [button frame]; | 1957 NSRect buttonFrame = [button frame]; |
1954 buttonFrame.origin.x = left; | 1958 buttonFrame.origin.x = left; |
1955 // Update "left" for next time around. | 1959 // Update "left" for next time around. |
1956 left += buttonFrame.size.width; | 1960 left += buttonFrame.size.width; |
1957 if (left > insertionPos_) | 1961 if (left > insertionPos_) |
1958 buttonFrame.origin.x += paddingWidth; | 1962 buttonFrame.origin.x += paddingWidth; |
1959 left += bookmarks::kBookmarkHorizontalPadding; | 1963 left += bookmarks::kBookmarkHorizontalPadding; |
1960 if (innerContentAnimationsEnabled_) | 1964 if (innerContentAnimationsEnabled_) |
1961 [[button animator] setFrame:buttonFrame]; | 1965 [[button animator] setFrame:buttonFrame]; |
1962 else | 1966 else |
1963 [button setFrame:buttonFrame]; | 1967 [button setFrame:buttonFrame]; |
1964 } | 1968 } |
| 1969 [NSAnimationContext endGrouping]; |
1965 } | 1970 } |
1966 } | 1971 } |
1967 | 1972 |
1968 // Put all visible bookmark bar buttons in their normal locations, either with | 1973 // Put all visible bookmark bar buttons in their normal locations, either with |
1969 // or without animation according to the |animate| flag. | 1974 // or without animation according to the |animate| flag. |
1970 // This is generally useful, so is called from various places internally. | 1975 // This is generally useful, so is called from various places internally. |
1971 - (void)resetAllButtonPositionsWithAnimation:(BOOL)animate { | 1976 - (void)resetAllButtonPositionsWithAnimation:(BOOL)animate { |
1972 | 1977 |
1973 // Position the apps bookmark if needed. | 1978 // Position the apps bookmark if needed. |
1974 CGFloat left = bookmarks::kBookmarkLeftMargin; | 1979 CGFloat left = bookmarks::kBookmarkLeftMargin; |
(...skipping 701 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2676 - (id<BookmarkButtonControllerProtocol>)controllerForNode: | 2681 - (id<BookmarkButtonControllerProtocol>)controllerForNode: |
2677 (const BookmarkNode*)node { | 2682 (const BookmarkNode*)node { |
2678 // See if it's in the bar, then if it is in the hierarchy of visible | 2683 // See if it's in the bar, then if it is in the hierarchy of visible |
2679 // folder menus. | 2684 // folder menus. |
2680 if (bookmarkModel_->bookmark_bar_node() == node) | 2685 if (bookmarkModel_->bookmark_bar_node() == node) |
2681 return self; | 2686 return self; |
2682 return [folderController_ controllerForNode:node]; | 2687 return [folderController_ controllerForNode:node]; |
2683 } | 2688 } |
2684 | 2689 |
2685 @end | 2690 @end |
OLD | NEW |