| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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/fullscreen/fullscreen_menubar_tracker.h" | 5 #import "chrome/browser/ui/cocoa/fullscreen/fullscreen_menubar_tracker.h" |
| 6 | 6 |
| 7 #include <Carbon/Carbon.h> | 7 #include <Carbon/Carbon.h> |
| 8 | 8 |
| 9 #include "base/mac/mac_util.h" |
| 9 #include "base/macros.h" | 10 #include "base/macros.h" |
| 10 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 11 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
| 11 #import "chrome/browser/ui/cocoa/fullscreen/fullscreen_toolbar_controller.h" | 12 #import "chrome/browser/ui/cocoa/fullscreen/fullscreen_toolbar_controller.h" |
| 13 #import "chrome/browser/ui/cocoa/fullscreen/fullscreen_toolbar_visibility_lock_c
ontroller.h" |
| 12 #include "ui/base/cocoa/appkit_utils.h" | 14 #include "ui/base/cocoa/appkit_utils.h" |
| 13 | 15 |
| 14 namespace { | 16 namespace { |
| 15 | 17 |
| 16 // The event kind value for a undocumented menubar show/hide Carbon event. | 18 // The event kind value for a undocumented menubar show/hide Carbon event. |
| 17 const CGFloat kMenuBarRevealEventKind = 2004; | 19 const CGFloat kMenuBarRevealEventKind = 2004; |
| 18 | 20 |
| 19 OSStatus MenuBarRevealHandler(EventHandlerCallRef handler, | 21 OSStatus MenuBarRevealHandler(EventHandlerCallRef handler, |
| 20 EventRef event, | 22 EventRef event, |
| 21 void* context) { | 23 void* context) { |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 | 131 |
| 130 if (ui::IsCGFloatEqual(progress, 1.0)) | 132 if (ui::IsCGFloatEqual(progress, 1.0)) |
| 131 state_ = FullscreenMenubarState::SHOWN; | 133 state_ = FullscreenMenubarState::SHOWN; |
| 132 else if (ui::IsCGFloatEqual(progress, 0.0)) | 134 else if (ui::IsCGFloatEqual(progress, 0.0)) |
| 133 state_ = FullscreenMenubarState::HIDDEN; | 135 state_ = FullscreenMenubarState::HIDDEN; |
| 134 else if (progress < menubarFraction_) | 136 else if (progress < menubarFraction_) |
| 135 state_ = FullscreenMenubarState::HIDING; | 137 state_ = FullscreenMenubarState::HIDING; |
| 136 else if (progress > menubarFraction_) | 138 else if (progress > menubarFraction_) |
| 137 state_ = FullscreenMenubarState::SHOWING; | 139 state_ = FullscreenMenubarState::SHOWING; |
| 138 | 140 |
| 141 // In 10.12. the toolbar to be janky since the UI doesn't update until the |
| 142 // menubar finished revealing itself. To smooth things out, animate the |
| 143 // toolbar in/out by locking/releasing its visibility instead of relying on |
| 144 // the menubar fraction. |
| 145 // TODO(spqchan): Figure out why it's not updating and make the toolbar drop |
| 146 // down in sync with the menubar. See crbug.com/672254. |
| 147 if (base::mac::IsOS10_12()) { |
| 148 if (state_ == FullscreenMenubarState::SHOWING) { |
| 149 [[owner_ visibilityLockController] lockToolbarVisibilityForOwner:self |
| 150 withAnimation:YES]; |
| 151 } else if (state_ == FullscreenMenubarState::HIDING) { |
| 152 [[owner_ visibilityLockController] releaseToolbarVisibilityForOwner:self |
| 153 withAnimation:YES]; |
| 154 } |
| 155 } |
| 156 |
| 139 menubarFraction_ = progress; | 157 menubarFraction_ = progress; |
| 140 | |
| 141 [owner_ updateToolbarLayout]; | 158 [owner_ updateToolbarLayout]; |
| 142 } | 159 } |
| 143 | 160 |
| 144 - (BOOL)isMouseOnScreen { | 161 - (BOOL)isMouseOnScreen { |
| 145 return NSMouseInRect([NSEvent mouseLocation], | 162 return NSMouseInRect([NSEvent mouseLocation], |
| 146 [[browserWindowController_ window] screen].frame, false); | 163 [[browserWindowController_ window] screen].frame, false); |
| 147 } | 164 } |
| 148 | 165 |
| 149 - (void)activeSpaceDidChange:(NSNotification*)notification { | 166 - (void)activeSpaceDidChange:(NSNotification*)notification { |
| 150 menubarFraction_ = 0.0; | 167 menubarFraction_ = 0.0; |
| 151 state_ = FullscreenMenubarState::HIDDEN; | 168 state_ = FullscreenMenubarState::HIDDEN; |
| 169 [[owner_ visibilityLockController] releaseToolbarVisibilityForOwner:self |
| 170 withAnimation:NO]; |
| 152 [owner_ updateToolbarLayout]; | 171 [owner_ updateToolbarLayout]; |
| 153 } | 172 } |
| 154 | 173 |
| 155 @end | 174 @end |
| OLD | NEW |