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_layout_manager.h" |
| 6 |
| 7 #include "base/command_line.h" |
| 8 #import "base/mac/mac_util.h" |
| 9 #include "base/mac/sdk_forward_declarations.h" |
| 10 #include "chrome/browser/profiles/profile.h" |
| 11 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
| 12 #import "chrome/browser/ui/cocoa/fullscreen/fullscreen_toolbar_animation_manager
.h" |
| 13 #import "chrome/browser/ui/cocoa/fullscreen/fullscreen_menubar_tracker.h" |
| 14 #import "chrome/browser/ui/cocoa/fullscreen/fullscreen_toolbar_mouse_tracker.h" |
| 15 #import "chrome/browser/ui/cocoa/fullscreen/fullscreen_toolbar_visibility_locks_
controller.h" |
| 16 #import "chrome/browser/ui/cocoa/fullscreen/immersive_fullscreen_controller.h" |
| 17 #include "chrome/common/chrome_switches.h" |
| 18 #include "chrome/common/pref_names.h" |
| 19 #import "ui/base/cocoa/nsview_additions.h" |
| 20 |
| 21 namespace { |
| 22 |
| 23 // The amount by which the toolbar is offset downwards (to avoid the menu) |
| 24 // when the toolbar style is TOOLBAR_HIDDEN. (We can't use |
| 25 // |-[NSMenu menuBarHeight]| since it returns 0 when the menu bar is hidden.) |
| 26 const CGFloat kToolbarVerticalOffset = -22; |
| 27 |
| 28 } // end namespace |
| 29 |
| 30 ////////////////////////////////////////////////////////////////// |
| 31 // FullscreenToolbarLayoutManager, public: |
| 32 |
| 33 FullscreenToolbarLayoutManager::FullscreenToolbarLayoutManager( |
| 34 BrowserWindowController* controller) |
| 35 : browser_controller_(controller), in_fullscreen_(false) { |
| 36 animation_manager_.reset(new FullscreenToolbarAnimationManager(this)); |
| 37 toolbar_visibility_locks_.reset( |
| 38 [[FullscreenToolbarVisibilityLocksController alloc] |
| 39 initWithFullscreenToolbarLayoutManager:this |
| 40 animationManager:animation_manager_.get()]); |
| 41 } |
| 42 |
| 43 FullscreenToolbarLayoutManager::~FullscreenToolbarLayoutManager() { |
| 44 DCHECK(!in_fullscreen_); |
| 45 browser_controller_ = nil; |
| 46 } |
| 47 |
| 48 void FullscreenToolbarLayoutManager::EnterFullscreenMode() { |
| 49 DCHECK(!in_fullscreen_); |
| 50 in_fullscreen_ = true; |
| 51 |
| 52 if ([browser_controller_ isInImmersiveFullscreen]) { |
| 53 immersive_fullscreen_controller_.reset( |
| 54 [[ImmersiveFullscreenController alloc] |
| 55 initWithBrowserController:browser_controller_]); |
| 56 [immersive_fullscreen_controller_ updateMenuBarAndDockVisibility]; |
| 57 } else { |
| 58 mouse_tracker_.reset([[FullscreenToolbarMouseTracker alloc] |
| 59 initWithFullscreenToolbarLayoutManager:this |
| 60 toolbarAnimationManager:animation_manager_.get()]); |
| 61 |
| 62 menubar_tracker_.reset([[FullscreenMenubarTracker alloc] |
| 63 initWithFullscreenToolbarLayoutManager:this]); |
| 64 } |
| 65 |
| 66 UpdateToolbarStyle(); |
| 67 } |
| 68 |
| 69 void FullscreenToolbarLayoutManager::ExitFullscreenMode() { |
| 70 DCHECK(in_fullscreen_); |
| 71 in_fullscreen_ = false; |
| 72 CleanUp(); |
| 73 } |
| 74 |
| 75 void FullscreenToolbarLayoutManager::RevealToolbarForTabStripChanges() { |
| 76 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 77 switches::kEnableFullscreenToolbarReveal)) { |
| 78 return; |
| 79 } |
| 80 |
| 81 animation_manager_->AnimateToolbarForTabstripChanges(); |
| 82 } |
| 83 |
| 84 FullscreenToolbarLayout FullscreenToolbarLayoutManager::ComputeToolbarLayout() |
| 85 const { |
| 86 FullscreenToolbarLayout layout; |
| 87 |
| 88 layout.toolbarStyle = toolbar_style_; |
| 89 layout.toolbarFraction = ComputeToolbarFraction(); |
| 90 |
| 91 CGFloat menubar_fraction; |
| 92 if (menubar_tracker_.get()) { |
| 93 menubar_fraction = [menubar_tracker_ menubarFraction]; |
| 94 } else { |
| 95 menubar_fraction = |
| 96 [immersive_fullscreen_controller_ shouldShowMenubar] ? 1 : 0; |
| 97 } |
| 98 |
| 99 layout.menubarOffset = std::floor(menubar_fraction * kToolbarVerticalOffset); |
| 100 |
| 101 return layout; |
| 102 } |
| 103 |
| 104 bool FullscreenToolbarLayoutManager::MustShowFullscreenToolbar() const { |
| 105 if (!in_fullscreen_) |
| 106 return NO; |
| 107 |
| 108 if (toolbar_style_ == FullscreenToolbarStyle::TOOLBAR_PRESENT) |
| 109 return YES; |
| 110 |
| 111 if (toolbar_style_ == FullscreenToolbarStyle::TOOLBAR_NONE) |
| 112 return NO; |
| 113 |
| 114 FullscreenMenubarState menubarState = [menubar_tracker_ state]; |
| 115 return menubarState == FullscreenMenubarState::SHOWN || |
| 116 [mouse_tracker_ mouseInsideTrackingArea] || |
| 117 [toolbar_visibility_locks_ isToolbarVisibilityLocked]; |
| 118 } |
| 119 |
| 120 void FullscreenToolbarLayoutManager::UpdateFullscreenToolbarFrame( |
| 121 NSRect frame) { |
| 122 if (mouse_tracker_.get()) |
| 123 [mouse_tracker_ updateToolbarFrame:frame]; |
| 124 } |
| 125 |
| 126 void FullscreenToolbarLayoutManager::Layout() { |
| 127 if (!in_fullscreen_) |
| 128 return; |
| 129 |
| 130 [browser_controller_ layoutSubviews]; |
| 131 [mouse_tracker_ updateTrackingArea]; |
| 132 animation_manager_->UpdateToolbarFraction(ComputeToolbarFraction()); |
| 133 } |
| 134 |
| 135 void FullscreenToolbarLayoutManager::UpdateToolbarStyle() { |
| 136 FullscreenToolbarStyle old_style = toolbar_style_; |
| 137 |
| 138 PrefService* prefs = [browser_controller_ profile]->GetPrefs(); |
| 139 shouldShowFullscreenToolbar_ = |
| 140 prefs->GetBoolean(prefs::kShowFullscreenToolbar); |
| 141 |
| 142 if ([browser_controller_ isFullscreenForTabContentOrExtension]) { |
| 143 toolbar_style_ = FullscreenToolbarStyle::TOOLBAR_NONE; |
| 144 } else { |
| 145 toolbar_style_ = shouldShowFullscreenToolbar_ |
| 146 ? FullscreenToolbarStyle::TOOLBAR_PRESENT |
| 147 : FullscreenToolbarStyle::TOOLBAR_HIDDEN; |
| 148 } |
| 149 |
| 150 if (old_style != toolbar_style_) |
| 151 Layout(); |
| 152 } |
| 153 |
| 154 ////////////////////////////////////////////////////////////////// |
| 155 // FullscreenToolbarLayoutManager, private: |
| 156 |
| 157 CGFloat FullscreenToolbarLayoutManager::ComputeToolbarFraction() const { |
| 158 if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode)) |
| 159 return 0.0; |
| 160 |
| 161 if (!in_fullscreen_) |
| 162 return 0.0; |
| 163 |
| 164 switch (toolbar_style_) { |
| 165 case FullscreenToolbarStyle::TOOLBAR_PRESENT: |
| 166 return 1.0; |
| 167 case FullscreenToolbarStyle::TOOLBAR_NONE: |
| 168 return 0.0; |
| 169 case FullscreenToolbarStyle::TOOLBAR_HIDDEN: |
| 170 if (MustShowFullscreenToolbar()) |
| 171 return 1.0; |
| 172 |
| 173 if (animation_manager_->IsAnimationRunning()) |
| 174 return animation_manager_->GetToolbarFraction(); |
| 175 |
| 176 return [menubar_tracker_ menubarFraction]; |
| 177 } |
| 178 } |
| 179 |
| 180 void FullscreenToolbarLayoutManager::CleanUp() { |
| 181 mouse_tracker_.reset(); |
| 182 menubar_tracker_.reset(); |
| 183 animation_manager_->StopAnimationAndTimer(); |
| 184 immersive_fullscreen_controller_.reset(); |
| 185 } |
OLD | NEW |