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

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

Issue 12328161: [Mac] Use private, undocumented Carbon events to make the presentation mode animation better. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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 | Annotate | Revision Log
« 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"
11 #import "chrome/browser/ui/cocoa/browser_window_controller.h" 11 #import "chrome/browser/ui/cocoa/browser_window_controller.h"
12 #include "chrome/common/chrome_switches.h" 12 #include "chrome/common/chrome_switches.h"
13 #import "third_party/GTM/AppKit/GTMNSAnimation+Duration.h" 13 #import "third_party/GTM/AppKit/GTMNSAnimation+Duration.h"
14 14
15 NSString* const kWillEnterFullscreenNotification = 15 NSString* const kWillEnterFullscreenNotification =
16 @"WillEnterFullscreenNotification"; 16 @"WillEnterFullscreenNotification";
17 NSString* const kWillLeaveFullscreenNotification = 17 NSString* const kWillLeaveFullscreenNotification =
18 @"WillLeaveFullscreenNotification"; 18 @"WillLeaveFullscreenNotification";
19 19
20 namespace { 20 namespace {
21
21 // The activation zone for the main menu is 4 pixels high; if we make it any 22 // The activation zone for the main menu is 4 pixels high; if we make it any
22 // smaller, then the menu can be made to appear without the bar sliding down. 23 // smaller, then the menu can be made to appear without the bar sliding down.
23 const CGFloat kDropdownActivationZoneHeight = 4; 24 const CGFloat kDropdownActivationZoneHeight = 4;
24 const NSTimeInterval kDropdownAnimationDuration = 0.12; 25 const NSTimeInterval kDropdownAnimationDuration = 0.12;
25 const NSTimeInterval kMouseExitCheckDelay = 0.1; 26 const NSTimeInterval kMouseExitCheckDelay = 0.1;
26 // This show delay attempts to match the delay for the main menu. 27 // This show delay attempts to match the delay for the main menu.
27 const NSTimeInterval kDropdownShowDelay = 0.3; 28 const NSTimeInterval kDropdownShowDelay = 0.3;
28 const NSTimeInterval kDropdownHideDelay = 0.2; 29 const NSTimeInterval kDropdownHideDelay = 0.2;
29 30
30 // The amount by which the floating bar is offset downwards (to avoid the menu) 31 // The amount by which the floating bar is offset downwards (to avoid the menu)
31 // in presentation mode. (We can't use |-[NSMenu menuBarHeight]| since it 32 // in presentation mode. (We can't use |-[NSMenu menuBarHeight]| since it
32 // returns 0 when the menu bar is hidden.) 33 // returns 0 when the menu bar is hidden.)
33 const CGFloat kFloatingBarVerticalOffset = 22; 34 const CGFloat kFloatingBarVerticalOffset = 22;
34 35
35 } // end namespace 36 OSStatus MenuBarRevealHandler(EventHandlerCallRef handler,
37 EventRef event,
38 void* context) {
39 PresentationModeController* self =
40 static_cast<PresentationModeController*>(context);
41 CGFloat reveal = 0;
42 GetEventParameter(event, FOUR_CHAR_CODE('rvlf'), typeCGFloat, NULL,
43 sizeof(CGFloat), NULL, &reveal);
44 if ([self inPresentationMode])
45 [self changeFloatingBarShownFraction:reveal];
46 return CallNextEventHandler(handler, event);
47 }
48
49 } // namespace
36 50
37 51
38 // Helper class to manage animations for the dropdown bar. Calls 52 // Helper class to manage animations for the dropdown bar. Calls
39 // [PresentationModeController changeFloatingBarShownFraction] once per 53 // [PresentationModeController changeFloatingBarShownFraction] once per
40 // animation step. 54 // animation step.
41 @interface DropdownAnimation : NSAnimation { 55 @interface DropdownAnimation : NSAnimation {
42 @private 56 @private
43 PresentationModeController* controller_; 57 PresentationModeController* controller_;
44 CGFloat startFraction_; 58 CGFloat startFraction_;
45 CGFloat endFraction_; 59 CGFloat endFraction_;
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 176
163 177
164 @implementation PresentationModeController 178 @implementation PresentationModeController
165 179
166 @synthesize inPresentationMode = inPresentationMode_; 180 @synthesize inPresentationMode = inPresentationMode_;
167 181
168 - (id)initWithBrowserController:(BrowserWindowController*)controller { 182 - (id)initWithBrowserController:(BrowserWindowController*)controller {
169 if ((self = [super init])) { 183 if ((self = [super init])) {
170 browserController_ = controller; 184 browserController_ = controller;
171 systemFullscreenMode_ = base::mac::kFullScreenModeNormal; 185 systemFullscreenMode_ = base::mac::kFullScreenModeNormal;
186
187 EventTypeSpec eventSpec = { kEventClassMenu, 2004 };
188 InstallApplicationEventHandler(NewEventHandlerUPP(&MenuBarRevealHandler),
189 1, &eventSpec,
190 self, &menuBarTrackingHandler_);
172 } 191 }
173 192
174 // Let the world know what we're up to. 193 // Let the world know what we're up to.
175 [[NSNotificationCenter defaultCenter] 194 [[NSNotificationCenter defaultCenter]
176 postNotificationName:kWillEnterFullscreenNotification 195 postNotificationName:kWillEnterFullscreenNotification
177 object:nil]; 196 object:nil];
178 197
179 return self; 198 return self;
180 } 199 }
181 200
182 - (void)dealloc { 201 - (void)dealloc {
202 RemoveEventHandler(menuBarTrackingHandler_);
203 menuBarTrackingHandler_ = NULL;
204
183 DCHECK(!inPresentationMode_); 205 DCHECK(!inPresentationMode_);
184 DCHECK(!trackingArea_); 206 DCHECK(!trackingArea_);
185 [super dealloc]; 207 [super dealloc];
186 } 208 }
187 209
188 - (void)enterPresentationModeForContentView:(NSView*)contentView 210 - (void)enterPresentationModeForContentView:(NSView*)contentView
189 showDropdown:(BOOL)showDropdown { 211 showDropdown:(BOOL)showDropdown {
190 DCHECK(!inPresentationMode_); 212 DCHECK(!inPresentationMode_);
191 enteringPresentationMode_ = YES; 213 enteringPresentationMode_ = YES;
192 inPresentationMode_ = YES; 214 inPresentationMode_ = YES;
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 470
449 // In all other cases, we want to cancel any running animation (which may be 471 // In all other cases, we want to cancel any running animation (which may be
450 // to show or to hide). 472 // to show or to hide).
451 [currentAnimation_ stopAnimation]; 473 [currentAnimation_ stopAnimation];
452 474
453 // Now, if it happens to already be in the right state, there's nothing more 475 // Now, if it happens to already be in the right state, there's nothing more
454 // to do. 476 // to do.
455 if ([browserController_ floatingBarShownFraction] == fraction) 477 if ([browserController_ floatingBarShownFraction] == fraction)
456 return; 478 return;
457 479
480 /*
458 // Create the animation and set it up. 481 // Create the animation and set it up.
459 currentAnimation_.reset( 482 currentAnimation_.reset(
460 [[DropdownAnimation alloc] initWithFraction:fraction 483 [[DropdownAnimation alloc] initWithFraction:fraction
461 fullDuration:kDropdownAnimationDuration 484 fullDuration:kDropdownAnimationDuration
462 animationCurve:NSAnimationEaseOut 485 animationCurve:NSAnimationEaseOut
463 controller:self]); 486 controller:self]);
464 DCHECK(currentAnimation_); 487 DCHECK(currentAnimation_);
465 [currentAnimation_ setAnimationBlockingMode:NSAnimationNonblocking]; 488 [currentAnimation_ setAnimationBlockingMode:NSAnimationNonblocking];
466 [currentAnimation_ setDelegate:self]; 489 [currentAnimation_ setDelegate:self];
467 490
468 // If there is an existing tracking area, remove it. We do not track mouse 491 // If there is an existing tracking area, remove it. We do not track mouse
469 // movements during animations (see class comment in the header file). 492 // movements during animations (see class comment in the header file).
470 [self removeTrackingAreaIfNecessary]; 493 [self removeTrackingAreaIfNecessary];
471 494
472 [currentAnimation_ startAnimation]; 495 [currentAnimation_ startAnimation];
496 */
473 } 497 }
474 498
475 - (void)scheduleShowForMouse { 499 - (void)scheduleShowForMouse {
476 [browserController_ lockBarVisibilityForOwner:self 500 [browserController_ lockBarVisibilityForOwner:self
477 withAnimation:YES 501 withAnimation:YES
478 delay:YES]; 502 delay:YES];
479 } 503 }
480 504
481 - (void)scheduleHideForMouse { 505 - (void)scheduleHideForMouse {
482 [browserController_ releaseBarVisibilityForOwner:self 506 [browserController_ releaseBarVisibilityForOwner:self
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 - (void)hideActiveWindowUI { 669 - (void)hideActiveWindowUI {
646 if (systemFullscreenMode_ != base::mac::kFullScreenModeNormal) { 670 if (systemFullscreenMode_ != base::mac::kFullScreenModeNormal) {
647 base::mac::ReleaseFullScreen(systemFullscreenMode_); 671 base::mac::ReleaseFullScreen(systemFullscreenMode_);
648 systemFullscreenMode_ = base::mac::kFullScreenModeNormal; 672 systemFullscreenMode_ = base::mac::kFullScreenModeNormal;
649 } 673 }
650 674
651 // TODO(rohitrao): Remove the Exit Fullscreen button. http://crbug.com/35956 675 // TODO(rohitrao): Remove the Exit Fullscreen button. http://crbug.com/35956
652 } 676 }
653 677
654 @end 678 @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