Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(89)

Side by Side Diff: chrome/browser/ui/cocoa/presentation_mode_controller.mm

Issue 1829583004: Fix for an issue with the Fullscreen Menu Bar on OSX (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/ui/cocoa/presentation_mode_controller.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/presentation_mode_controller.h" 5 #import "chrome/browser/ui/cocoa/presentation_mode_controller.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #import "base/mac/mac_util.h" 10 #import "base/mac/mac_util.h"
(...skipping 13 matching lines...) Expand all
24 24
25 // The activation zone for the main menu is 4 pixels high; if we make it any 25 // The activation zone for the main menu is 4 pixels high; if we make it any
26 // smaller, then the menu can be made to appear without the bar sliding down. 26 // smaller, then the menu can be made to appear without the bar sliding down.
27 const CGFloat kDropdownActivationZoneHeight = 4; 27 const CGFloat kDropdownActivationZoneHeight = 4;
28 const NSTimeInterval kDropdownAnimationDuration = 0.12; 28 const NSTimeInterval kDropdownAnimationDuration = 0.12;
29 const NSTimeInterval kMouseExitCheckDelay = 0.1; 29 const NSTimeInterval kMouseExitCheckDelay = 0.1;
30 // This show delay attempts to match the delay for the main menu. 30 // This show delay attempts to match the delay for the main menu.
31 const NSTimeInterval kDropdownShowDelay = 0.3; 31 const NSTimeInterval kDropdownShowDelay = 0.3;
32 const NSTimeInterval kDropdownHideDelay = 0.2; 32 const NSTimeInterval kDropdownHideDelay = 0.2;
33 33
34 // The event kind value for a undocumented menubar show/hide Carbon event.
35 const CGFloat kMenuBarRevealEventKind = 2004;
36
34 // The amount by which the floating bar is offset downwards (to avoid the menu) 37 // The amount by which the floating bar is offset downwards (to avoid the menu)
35 // in presentation mode. (We can't use |-[NSMenu menuBarHeight]| since it 38 // in presentation mode. (We can't use |-[NSMenu menuBarHeight]| since it
36 // returns 0 when the menu bar is hidden.) 39 // returns 0 when the menu bar is hidden.)
37 const CGFloat kFloatingBarVerticalOffset = 22; 40 const CGFloat kFloatingBarVerticalOffset = 22;
38 41
39 OSStatus MenuBarRevealHandler(EventHandlerCallRef handler, 42 OSStatus MenuBarRevealHandler(EventHandlerCallRef handler,
40 EventRef event, 43 EventRef event,
41 void* context) { 44 void* context) {
42 PresentationModeController* self = 45 PresentationModeController* self =
43 static_cast<PresentationModeController*>(context); 46 static_cast<PresentationModeController*>(context);
44 CGFloat revealFraction = 0; 47
45 GetEventParameter(event, 48 // If Chrome has multiple fullscreen windows in their own space, the Handler
46 FOUR_CHAR_CODE('rvlf'), 49 // becomes flaky and might start receiving kMenuBarRevealEventKind events
47 typeCGFloat, 50 // from another space. Since the menubar in the another space is in either a
48 NULL, 51 // shown or hidden state, it will give us a reveal fraction of 0.0 or 1.0.
49 sizeof(CGFloat), 52 // As such, we should ignore the kMenuBarRevealEventKind event if it gives
50 NULL, 53 // us a fraction of 0.0 or 1.0, and rely on kEventMenuBarShown and
51 &revealFraction); 54 // kEventMenuBarHidden to set these values.
52 [self setMenuBarRevealProgress:revealFraction]; 55 if ([self isOnActiveSpace]) {
56 if (GetEventKind(event) == kMenuBarRevealEventKind) {
57 CGFloat revealFraction = 0;
58 GetEventParameter(event, FOUR_CHAR_CODE('rvlf'), typeCGFloat, NULL,
59 sizeof(CGFloat), NULL, &revealFraction);
60 if (revealFraction > 0.0 && revealFraction < 1.0)
61 [self setMenuBarRevealProgress:revealFraction];
62 } else if (GetEventKind(event) == kEventMenuBarShown) {
63 [self setMenuBarRevealProgress:1.0];
64 } else {
65 [self setMenuBarRevealProgress:0.0];
66 }
67 }
68
53 return CallNextEventHandler(handler, event); 69 return CallNextEventHandler(handler, event);
54 } 70 }
55 71
56 } // end namespace 72 } // end namespace
57 73
58 // Helper class to manage animations for the dropdown bar. Calls 74 // Helper class to manage animations for the dropdown bar. Calls
59 // [PresentationModeController changeToolbarFraction] once per 75 // [PresentationModeController changeToolbarFraction] once per
60 // animation step. 76 // animation step.
61 @interface DropdownAnimation : NSAnimation { 77 @interface DropdownAnimation : NSAnimation {
62 @private 78 @private
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 // the window gains or loses main status as well as in |-cleanup|. 195 // the window gains or loses main status as well as in |-cleanup|.
180 - (void)showActiveWindowUI; 196 - (void)showActiveWindowUI;
181 - (void)hideActiveWindowUI; 197 - (void)hideActiveWindowUI;
182 198
183 // Whether the menu bar should be shown in immersive fullscreen for the screen 199 // Whether the menu bar should be shown in immersive fullscreen for the screen
184 // that contains the window. 200 // that contains the window.
185 - (BOOL)shouldShowMenubarInImmersiveFullscreen; 201 - (BOOL)shouldShowMenubarInImmersiveFullscreen;
186 202
187 @end 203 @end
188 204
189
190 @implementation PresentationModeController 205 @implementation PresentationModeController
191 206
192 @synthesize inPresentationMode = inPresentationMode_; 207 @synthesize inPresentationMode = inPresentationMode_;
193 @synthesize slidingStyle = slidingStyle_; 208 @synthesize slidingStyle = slidingStyle_;
194 @synthesize toolbarFraction = toolbarFraction_; 209 @synthesize toolbarFraction = toolbarFraction_;
195 210
196 - (id)initWithBrowserController:(BrowserWindowController*)controller 211 - (id)initWithBrowserController:(BrowserWindowController*)controller
197 style:(fullscreen_mac::SlidingStyle)style { 212 style:(fullscreen_mac::SlidingStyle)style {
198 if ((self = [super init])) { 213 if ((self = [super init])) {
199 browserController_ = controller; 214 browserController_ = controller;
200 systemFullscreenMode_ = base::mac::kFullScreenModeNormal; 215 systemFullscreenMode_ = base::mac::kFullScreenModeNormal;
201 slidingStyle_ = style; 216 slidingStyle_ = style;
202 } 217 }
203 218
204 // Let the world know what we're up to. 219 // Let the world know what we're up to.
205 [[NSNotificationCenter defaultCenter] 220 [[NSNotificationCenter defaultCenter]
206 postNotificationName:kWillEnterFullscreenNotification 221 postNotificationName:kWillEnterFullscreenNotification
207 object:nil]; 222 object:nil];
208 223
209 // Install the Carbon event handler for the undocumented menu bar show/hide 224 // Install the Carbon event handler for the menubar show, hide and
210 // event. 225 // undocumented reveal event.
211 EventTypeSpec eventSpec = {kEventClassMenu, 2004}; 226 EventTypeSpec eventSpecs[3];
212 InstallApplicationEventHandler(NewEventHandlerUPP(&MenuBarRevealHandler), 227
213 1, 228 eventSpecs[0].eventClass = kEventClassMenu;
214 &eventSpec, 229 eventSpecs[0].eventKind = kMenuBarRevealEventKind;
215 self, 230
216 &menuBarTrackingHandler_); 231 eventSpecs[1].eventClass = kEventClassMenu;
232 eventSpecs[1].eventKind = kEventMenuBarShown;
233
234 eventSpecs[2].eventClass = kEventClassMenu;
235 eventSpecs[2].eventKind = kEventMenuBarHidden;
236
237 InstallApplicationEventHandler(NewEventHandlerUPP(&MenuBarRevealHandler), 3,
238 eventSpecs, self, &menuBarTrackingHandler_);
239
217 return self; 240 return self;
218 } 241 }
219 242
220 - (void)dealloc { 243 - (void)dealloc {
221 RemoveEventHandler(menuBarTrackingHandler_); 244 RemoveEventHandler(menuBarTrackingHandler_);
222 DCHECK(!inPresentationMode_); 245 DCHECK(!inPresentationMode_);
223 DCHECK(!trackingArea_); 246 DCHECK(!trackingArea_);
224 [super dealloc]; 247 [super dealloc];
225 } 248 }
226 249
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 // the logic is correct and not fragile. 439 // the logic is correct and not fragile.
417 - (CGFloat)menubarOffset { 440 - (CGFloat)menubarOffset {
418 if ([browserController_ isInAppKitFullscreen]) 441 if ([browserController_ isInAppKitFullscreen])
419 return -std::floor(menubarFraction_ * [self floatingBarVerticalOffset]); 442 return -std::floor(menubarFraction_ * [self floatingBarVerticalOffset]);
420 443
421 return [self shouldShowMenubarInImmersiveFullscreen] 444 return [self shouldShowMenubarInImmersiveFullscreen]
422 ? -[self floatingBarVerticalOffset] 445 ? -[self floatingBarVerticalOffset]
423 : 0; 446 : 0;
424 } 447 }
425 448
449 - (BOOL)isOnActiveSpace {
450 return [browserController_ window].onActiveSpace;
451 }
452
426 // Used to activate the floating bar in presentation mode. 453 // Used to activate the floating bar in presentation mode.
427 - (void)mouseEntered:(NSEvent*)event { 454 - (void)mouseEntered:(NSEvent*)event {
428 DCHECK(inPresentationMode_); 455 DCHECK(inPresentationMode_);
429 456
430 // Having gotten a mouse entered, we no longer need to do exit checks. 457 // Having gotten a mouse entered, we no longer need to do exit checks.
431 [self cancelMouseExitCheck]; 458 [self cancelMouseExitCheck];
432 459
433 NSTrackingArea* trackingArea = [event trackingArea]; 460 NSTrackingArea* trackingArea = [event trackingArea];
434 if (trackingArea == trackingArea_) { 461 if (trackingArea == trackingArea_) {
435 // The tracking area shouldn't be active during animation. 462 // The tracking area shouldn't be active during animation.
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
746 [self updateMenuBarAndDockVisibility]; 773 [self updateMenuBarAndDockVisibility];
747 774
748 // TODO(rohitrao): Remove the Exit Fullscreen button. http://crbug.com/35956 775 // TODO(rohitrao): Remove the Exit Fullscreen button. http://crbug.com/35956
749 } 776 }
750 777
751 - (BOOL)shouldShowMenubarInImmersiveFullscreen { 778 - (BOOL)shouldShowMenubarInImmersiveFullscreen {
752 return [self doesScreenHaveMenuBar] && toolbarFraction_ > 0.99; 779 return [self doesScreenHaveMenuBar] && toolbarFraction_ > 0.99;
753 } 780 }
754 781
755 @end 782 @end
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/presentation_mode_controller.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698