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