| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/app_menu/app_menu_controller.h" | 5 #import "chrome/browser/ui/cocoa/app_menu/app_menu_controller.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/mac/bundle_locations.h" | 10 #include "base/mac/bundle_locations.h" |
| 11 #include "base/mac/objc_release_properties.h" | |
| 12 #include "base/macros.h" | 11 #include "base/macros.h" |
| 13 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 14 #include "base/metrics/histogram_macros.h" | 13 #include "base/metrics/histogram_macros.h" |
| 15 #include "base/metrics/user_metrics.h" | 14 #include "base/metrics/user_metrics.h" |
| 16 #include "base/scoped_observer.h" | 15 #include "base/scoped_observer.h" |
| 17 #include "base/strings/string16.h" | 16 #include "base/strings/string16.h" |
| 18 #include "base/strings/sys_string_conversions.h" | 17 #include "base/strings/sys_string_conversions.h" |
| 19 #include "base/threading/thread_task_runner_handle.h" | 18 #include "base/threading/thread_task_runner_handle.h" |
| 20 #include "chrome/app/chrome_command_ids.h" | 19 #include "chrome/app/chrome_command_ids.h" |
| 21 #import "chrome/browser/app_controller_mac.h" | 20 #import "chrome/browser/app_controller_mac.h" |
| (...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 595 @synthesize zoomPlus = zoomPlus_; | 594 @synthesize zoomPlus = zoomPlus_; |
| 596 @synthesize zoomDisplay = zoomDisplay_; | 595 @synthesize zoomDisplay = zoomDisplay_; |
| 597 @synthesize zoomMinus = zoomMinus_; | 596 @synthesize zoomMinus = zoomMinus_; |
| 598 @synthesize zoomFullScreen = zoomFullScreen_; | 597 @synthesize zoomFullScreen = zoomFullScreen_; |
| 599 @synthesize toolbarActionsOverflowItem = toolbarActionsOverflowItem_; | 598 @synthesize toolbarActionsOverflowItem = toolbarActionsOverflowItem_; |
| 600 @synthesize overflowActionsContainerView = overflowActionsContainerView_; | 599 @synthesize overflowActionsContainerView = overflowActionsContainerView_; |
| 601 | 600 |
| 602 - (id)initWithController:(AppMenuController*)controller { | 601 - (id)initWithController:(AppMenuController*)controller { |
| 603 if ((self = [super initWithNibName:@"AppMenu" | 602 if ((self = [super initWithNibName:@"AppMenu" |
| 604 bundle:base::mac::FrameworkBundle()])) { | 603 bundle:base::mac::FrameworkBundle()])) { |
| 604 propertyReleaser_.Init(self, [AppMenuButtonViewController class]); |
| 605 controller_ = controller; | 605 controller_ = controller; |
| 606 [[NSNotificationCenter defaultCenter] | 606 [[NSNotificationCenter defaultCenter] |
| 607 addObserver:self | 607 addObserver:self |
| 608 selector:@selector(containerSuperviewFrameChanged:) | 608 selector:@selector(containerSuperviewFrameChanged:) |
| 609 name:NSViewFrameDidChangeNotification | 609 name:NSViewFrameDidChangeNotification |
| 610 object:[overflowActionsContainerView_ superview]]; | 610 object:[overflowActionsContainerView_ superview]]; |
| 611 } | 611 } |
| 612 return self; | 612 return self; |
| 613 } | 613 } |
| 614 | 614 |
| 615 - (void)dealloc { | 615 - (void)dealloc { |
| 616 [[NSNotificationCenter defaultCenter] removeObserver:self]; | 616 [[NSNotificationCenter defaultCenter] removeObserver:self]; |
| 617 base::mac::ReleaseProperties(self); | |
| 618 [super dealloc]; | 617 [super dealloc]; |
| 619 } | 618 } |
| 620 | 619 |
| 621 - (IBAction)dispatchAppMenuCommand:(id)sender { | 620 - (IBAction)dispatchAppMenuCommand:(id)sender { |
| 622 [controller_ dispatchAppMenuCommand:sender]; | 621 [controller_ dispatchAppMenuCommand:sender]; |
| 623 } | 622 } |
| 624 | 623 |
| 625 - (void)containerSuperviewFrameChanged:(NSNotification*)notification { | 624 - (void)containerSuperviewFrameChanged:(NSNotification*)notification { |
| 626 // AppKit menus were probably never designed with a view like the browser | 625 // AppKit menus were probably never designed with a view like the browser |
| 627 // actions container in mind, and, as a result, we come across a few oddities. | 626 // actions container in mind, and, as a result, we come across a few oddities. |
| 628 // One of these is that the container's superview will, on some versions of | 627 // One of these is that the container's superview will, on some versions of |
| 629 // OSX, change frame position sometime after the the menu begins tracking | 628 // OSX, change frame position sometime after the the menu begins tracking |
| 630 // (and thus, after all our ability to adjust it normally). Throw in the | 629 // (and thus, after all our ability to adjust it normally). Throw in the |
| 631 // towel, and simply don't let the frame move from where it's supposed to be. | 630 // towel, and simply don't let the frame move from where it's supposed to be. |
| 632 // TODO(devlin): Yet another Cocoa hack. It'd be good to find a workaround, | 631 // TODO(devlin): Yet another Cocoa hack. It'd be good to find a workaround, |
| 633 // but unlikely unless we replace the Cocoa menu implementation. | 632 // but unlikely unless we replace the Cocoa menu implementation. |
| 634 NSView* containerSuperview = [overflowActionsContainerView_ superview]; | 633 NSView* containerSuperview = [overflowActionsContainerView_ superview]; |
| 635 if (NSMinX([containerSuperview frame]) != 0) | 634 if (NSMinX([containerSuperview frame]) != 0) |
| 636 [containerSuperview setFrameOrigin:NSZeroPoint]; | 635 [containerSuperview setFrameOrigin:NSZeroPoint]; |
| 637 } | 636 } |
| 638 | 637 |
| 639 @end // @implementation AppMenuButtonViewController | 638 @end // @implementation AppMenuButtonViewController |
| OLD | NEW |