| 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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 // - |-doBookmarkBarAnimation| has most of the actual logic. | 121 // - |-doBookmarkBarAnimation| has most of the actual logic. |
| 122 // - |-getDesiredToolbarHeightCompression| and |-toolbarDividerOpacity| contain | 122 // - |-getDesiredToolbarHeightCompression| and |-toolbarDividerOpacity| contain |
| 123 // related logic. | 123 // related logic. |
| 124 // - The BWC's |-layoutSubviews| needs to know how to position things. | 124 // - The BWC's |-layoutSubviews| needs to know how to position things. |
| 125 // - The BWC should implement |-bookmarkBar:didChangeFromState:toState:| and | 125 // - The BWC should implement |-bookmarkBar:didChangeFromState:toState:| and |
| 126 // |-bookmarkBar:willAnimateFromState:toState:| in order to inform the | 126 // |-bookmarkBar:willAnimateFromState:toState:| in order to inform the |
| 127 // toolbar of required changes. | 127 // toolbar of required changes. |
| 128 | 128 |
| 129 namespace { | 129 namespace { |
| 130 | 130 |
| 131 // Overlap (in pixels) between the toolbar and the bookmark bar (when showing in |
| 132 // normal mode). |
| 133 const CGFloat kBookmarkBarOverlap = 3.0; |
| 134 |
| 131 // Duration of the bookmark bar animations. | 135 // Duration of the bookmark bar animations. |
| 132 const NSTimeInterval kBookmarkBarAnimationDuration = 0.12; | 136 const NSTimeInterval kBookmarkBarAnimationDuration = 0.12; |
| 133 | 137 |
| 134 void RecordAppLaunch(Profile* profile, GURL url) { | 138 void RecordAppLaunch(Profile* profile, GURL url) { |
| 135 DCHECK(profile->GetExtensionService()); | 139 DCHECK(profile->GetExtensionService()); |
| 136 const extensions::Extension* extension = | 140 const extensions::Extension* extension = |
| 137 profile->GetExtensionService()->GetInstalledApp(url); | 141 profile->GetExtensionService()->GetInstalledApp(url); |
| 138 if (!extension) | 142 if (!extension) |
| 139 return; | 143 return; |
| 140 | 144 |
| (...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 517 // between showing and detached. | 521 // between showing and detached. |
| 518 if ([self isAnimatingBetweenState:BookmarkBar::HIDDEN | 522 if ([self isAnimatingBetweenState:BookmarkBar::HIDDEN |
| 519 andState:BookmarkBar::SHOW] || | 523 andState:BookmarkBar::SHOW] || |
| 520 [self isAnimatingBetweenState:BookmarkBar::SHOW | 524 [self isAnimatingBetweenState:BookmarkBar::SHOW |
| 521 andState:BookmarkBar::DETACHED]) | 525 andState:BookmarkBar::DETACHED]) |
| 522 return 0; | 526 return 0; |
| 523 | 527 |
| 524 // If we ever need any other animation cases, code would go here. | 528 // If we ever need any other animation cases, code would go here. |
| 525 } | 529 } |
| 526 | 530 |
| 527 return [self isInState:BookmarkBar::SHOW] ? bookmarks::kBookmarkBarOverlap | 531 return [self isInState:BookmarkBar::SHOW] ? kBookmarkBarOverlap : 0; |
| 528 : 0; | |
| 529 } | 532 } |
| 530 | 533 |
| 531 - (CGFloat)toolbarDividerOpacity { | 534 - (CGFloat)toolbarDividerOpacity { |
| 532 // Some special cases.... | 535 // Some special cases.... |
| 533 if ([self isAnimationRunning]) { | 536 if ([self isAnimationRunning]) { |
| 534 // In general, the toolbar shouldn't show a divider while we're animating | 537 // In general, the toolbar shouldn't show a divider while we're animating |
| 535 // between showing and hidden. The exception is when our height is < 1, in | 538 // between showing and hidden. The exception is when our height is < 1, in |
| 536 // which case we can't draw it. It's all-or-nothing (no partial opacity). | 539 // which case we can't draw it. It's all-or-nothing (no partial opacity). |
| 537 if ([self isAnimatingBetweenState:BookmarkBar::HIDDEN | 540 if ([self isAnimatingBetweenState:BookmarkBar::HIDDEN |
| 538 andState:BookmarkBar::SHOW]) | 541 andState:BookmarkBar::SHOW]) |
| (...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 885 // (Private) | 888 // (Private) |
| 886 - (BOOL)doBookmarkBarAnimation { | 889 - (BOOL)doBookmarkBarAnimation { |
| 887 if ([self isAnimatingFromState:BookmarkBar::HIDDEN | 890 if ([self isAnimatingFromState:BookmarkBar::HIDDEN |
| 888 toState:BookmarkBar::SHOW]) { | 891 toState:BookmarkBar::SHOW]) { |
| 889 [[self backgroundGradientView] setShowsDivider:YES]; | 892 [[self backgroundGradientView] setShowsDivider:YES]; |
| 890 [[self view] setHidden:NO]; | 893 [[self view] setHidden:NO]; |
| 891 AnimatableView* view = [self animatableView]; | 894 AnimatableView* view = [self animatableView]; |
| 892 // Height takes into account the extra height we have since the toolbar | 895 // Height takes into account the extra height we have since the toolbar |
| 893 // only compresses when we're done. | 896 // only compresses when we're done. |
| 894 [view animateToNewHeight:(bookmarks::kBookmarkBarHeight - | 897 [view animateToNewHeight:(bookmarks::kBookmarkBarHeight - |
| 895 bookmarks::kBookmarkBarOverlap) | 898 kBookmarkBarOverlap) |
| 896 duration:kBookmarkBarAnimationDuration]; | 899 duration:kBookmarkBarAnimationDuration]; |
| 897 } else if ([self isAnimatingFromState:BookmarkBar::SHOW | 900 } else if ([self isAnimatingFromState:BookmarkBar::SHOW |
| 898 toState:BookmarkBar::HIDDEN]) { | 901 toState:BookmarkBar::HIDDEN]) { |
| 899 [[self backgroundGradientView] setShowsDivider:YES]; | 902 [[self backgroundGradientView] setShowsDivider:YES]; |
| 900 [[self view] setHidden:NO]; | 903 [[self view] setHidden:NO]; |
| 901 AnimatableView* view = [self animatableView]; | 904 AnimatableView* view = [self animatableView]; |
| 902 [view animateToNewHeight:0 | 905 [view animateToNewHeight:0 |
| 903 duration:kBookmarkBarAnimationDuration]; | 906 duration:kBookmarkBarAnimationDuration]; |
| 904 } else if ([self isAnimatingFromState:BookmarkBar::SHOW | 907 } else if ([self isAnimatingFromState:BookmarkBar::SHOW |
| 905 toState:BookmarkBar::DETACHED]) { | 908 toState:BookmarkBar::DETACHED]) { |
| 906 [[self backgroundGradientView] setShowsDivider:YES]; | 909 [[self backgroundGradientView] setShowsDivider:YES]; |
| 907 [[self view] setHidden:NO]; | 910 [[self view] setHidden:NO]; |
| 908 AnimatableView* view = [self animatableView]; | 911 AnimatableView* view = [self animatableView]; |
| 909 CGFloat newHeight = chrome::search::IsInstantExtendedAPIEnabled() | 912 CGFloat newHeight = chrome::search::IsInstantExtendedAPIEnabled() |
| 910 ? bookmarks::kSearchNewTabBookmarkBarHeight | 913 ? bookmarks::kSearchNewTabBookmarkBarHeight |
| 911 : chrome::kNTPBookmarkBarHeight; | 914 : chrome::kNTPBookmarkBarHeight; |
| 912 [view animateToNewHeight:newHeight | 915 [view animateToNewHeight:newHeight |
| 913 duration:kBookmarkBarAnimationDuration]; | 916 duration:kBookmarkBarAnimationDuration]; |
| 914 } else if ([self isAnimatingFromState:BookmarkBar::DETACHED | 917 } else if ([self isAnimatingFromState:BookmarkBar::DETACHED |
| 915 toState:BookmarkBar::SHOW]) { | 918 toState:BookmarkBar::SHOW]) { |
| 916 [[self backgroundGradientView] setShowsDivider:YES]; | 919 [[self backgroundGradientView] setShowsDivider:YES]; |
| 917 [[self view] setHidden:NO]; | 920 [[self view] setHidden:NO]; |
| 918 AnimatableView* view = [self animatableView]; | 921 AnimatableView* view = [self animatableView]; |
| 919 // Height takes into account the extra height we have since the toolbar | 922 // Height takes into account the extra height we have since the toolbar |
| 920 // only compresses when we're done. | 923 // only compresses when we're done. |
| 921 [view animateToNewHeight:(bookmarks::kBookmarkBarHeight - | 924 [view animateToNewHeight:(bookmarks::kBookmarkBarHeight - |
| 922 bookmarks::kBookmarkBarOverlap) | 925 kBookmarkBarOverlap) |
| 923 duration:kBookmarkBarAnimationDuration]; | 926 duration:kBookmarkBarAnimationDuration]; |
| 924 } else { | 927 } else { |
| 925 // Oops! An animation we don't know how to handle. | 928 // Oops! An animation we don't know how to handle. |
| 926 return NO; | 929 return NO; |
| 927 } | 930 } |
| 928 | 931 |
| 929 return YES; | 932 return YES; |
| 930 } | 933 } |
| 931 | 934 |
| 932 // Actually open the URL. This is the last chance for a unit test to | 935 // Actually open the URL. This is the last chance for a unit test to |
| (...skipping 1697 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2630 - (id<BookmarkButtonControllerProtocol>)controllerForNode: | 2633 - (id<BookmarkButtonControllerProtocol>)controllerForNode: |
| 2631 (const BookmarkNode*)node { | 2634 (const BookmarkNode*)node { |
| 2632 // See if it's in the bar, then if it is in the hierarchy of visible | 2635 // See if it's in the bar, then if it is in the hierarchy of visible |
| 2633 // folder menus. | 2636 // folder menus. |
| 2634 if (bookmarkModel_->bookmark_bar_node() == node) | 2637 if (bookmarkModel_->bookmark_bar_node() == node) |
| 2635 return self; | 2638 return self; |
| 2636 return [folderController_ controllerForNode:node]; | 2639 return [folderController_ controllerForNode:node]; |
| 2637 } | 2640 } |
| 2638 | 2641 |
| 2639 @end | 2642 @end |
| OLD | NEW |