| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #import "chrome/browser/ui/cocoa/fullscreen/fullscreen_toolbar_visibility_lock_c
ontroller.h" |
| 6 |
| 7 #include "base/mac/scoped_nsobject.h" |
| 8 |
| 9 #import "chrome/browser/ui/cocoa/fullscreen/fullscreen_toolbar_animation_control
ler.h" |
| 10 #import "chrome/browser/ui/cocoa/fullscreen_toolbar_controller.h" |
| 11 |
| 12 @interface FullscreenToolbarVisibilityLockController () { |
| 13 // Stores the objects that are locking the toolbar visibility. |
| 14 base::scoped_nsobject<NSMutableSet> visibilityLocks_; |
| 15 |
| 16 // Our owner. |
| 17 FullscreenToolbarController* owner_; // weak |
| 18 |
| 19 // The object managing the fullscreen toolbar's animations. |
| 20 FullscreenToolbarAnimationController* animationController_; // weak |
| 21 } |
| 22 |
| 23 @end |
| 24 |
| 25 @implementation FullscreenToolbarVisibilityLockController |
| 26 |
| 27 - (instancetype) |
| 28 initWithFullscreenToolbarController:(FullscreenToolbarController*)owner |
| 29 animationController: |
| 30 (FullscreenToolbarAnimationController*)animationController { |
| 31 if ((self = [super init])) { |
| 32 animationController_ = animationController; |
| 33 owner_ = owner; |
| 34 |
| 35 // Create the toolbar visibility lock set; 10 is arbitrary, but should |
| 36 // hopefully be big enough to hold all locks that'll ever be needed. |
| 37 visibilityLocks_.reset([[NSMutableSet setWithCapacity:10] retain]); |
| 38 } |
| 39 |
| 40 return self; |
| 41 } |
| 42 |
| 43 - (BOOL)isToolbarVisibilityLocked { |
| 44 return [visibilityLocks_ count]; |
| 45 } |
| 46 |
| 47 - (BOOL)isToolbarVisibilityLockedForOwner:(id)owner { |
| 48 return [visibilityLocks_ containsObject:owner]; |
| 49 } |
| 50 |
| 51 - (void)lockToolbarVisibilityForOwner:(id)owner withAnimation:(BOOL)animate { |
| 52 if ([self isToolbarVisibilityLockedForOwner:owner]) |
| 53 return; |
| 54 |
| 55 [visibilityLocks_ addObject:owner]; |
| 56 |
| 57 if (animate) |
| 58 animationController_->AnimateToolbarIn(); |
| 59 else |
| 60 [owner_ updateToolbar]; |
| 61 } |
| 62 |
| 63 - (void)releaseToolbarVisibilityForOwner:(id)owner withAnimation:(BOOL)animate { |
| 64 if (![self isToolbarVisibilityLockedForOwner:owner]) |
| 65 return; |
| 66 |
| 67 [visibilityLocks_ removeObject:owner]; |
| 68 |
| 69 if (animate) |
| 70 animationController_->AnimateToolbarOutIfPossible(); |
| 71 else |
| 72 [owner_ updateToolbar]; |
| 73 } |
| 74 |
| 75 @end |
| OLD | NEW |