summaryrefslogtreecommitdiffstats
path: root/chrome/browser/cocoa/wrench_menu_controller.mm
diff options
context:
space:
mode:
authorrsesek@chromium.org <rsesek@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-18 18:36:57 +0000
committerrsesek@chromium.org <rsesek@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-18 18:36:57 +0000
commit0755672a1e8bad7e9efd4b932836ab51a25cca18 (patch)
treef0a6f0c68c9899e3fe460c870e825ce5e1c1755e /chrome/browser/cocoa/wrench_menu_controller.mm
parent9bf103edf104b4e4174a3ba22da9af6816858033 (diff)
downloadchromium_src-0755672a1e8bad7e9efd4b932836ab51a25cca18.zip
chromium_src-0755672a1e8bad7e9efd4b932836ab51a25cca18.tar.gz
chromium_src-0755672a1e8bad7e9efd4b932836ab51a25cca18.tar.bz2
[Mac] Don't close the Wrench menu after using the zoom buttons if the menu was opened sticky.
This runs the Task that updates the zoom information in the UI thread outside of the normal MessageLoop and instead runs it on the native run loop. R=mark BUG=48679 TEST=Open Wrench menu with a click. Use zoom buttons. Menu stays open and page zooms. Other buttons still close menu. TEST=Open Wrench menu with click-hold-drag. Hover and release on zoom buttons. Menu closes and page zooms. Review URL: http://codereview.chromium.org/3183013 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@56566 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa/wrench_menu_controller.mm')
-rw-r--r--chrome/browser/cocoa/wrench_menu_controller.mm63
1 files changed, 56 insertions, 7 deletions
diff --git a/chrome/browser/cocoa/wrench_menu_controller.mm b/chrome/browser/cocoa/wrench_menu_controller.mm
index cb0059a..4966157 100644
--- a/chrome/browser/cocoa/wrench_menu_controller.mm
+++ b/chrome/browser/cocoa/wrench_menu_controller.mm
@@ -13,18 +13,53 @@
#import "chrome/browser/cocoa/menu_tracked_root_view.h"
#import "chrome/browser/cocoa/toolbar_controller.h"
#include "chrome/browser/wrench_menu_model.h"
+#include "chrome/common/notification_observer.h"
+#include "chrome/common/notification_service.h"
+#include "chrome/common/notification_source.h"
+#include "chrome/common/notification_type.h"
#include "grit/chromium_strings.h"
#include "grit/generated_resources.h"
@interface WrenchMenuController (Private)
- (void)adjustPositioning;
- (void)performCommandDispatch:(NSNumber*)tag;
+- (NSButton*)zoomDisplay;
@end
+namespace WrenchMenuControllerInternal {
+
+class ZoomLevelObserver : public NotificationObserver {
+ public:
+ explicit ZoomLevelObserver(WrenchMenuController* controller)
+ : controller_(controller) {
+ registrar_.Add(this, NotificationType::ZOOM_LEVEL_CHANGED,
+ NotificationService::AllSources());
+ }
+
+ void Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details) {
+ DCHECK_EQ(type.value, NotificationType::ZOOM_LEVEL_CHANGED);
+ WrenchMenuModel* wrenchMenuModel = [controller_ wrenchMenuModel];
+ wrenchMenuModel->UpdateZoomControls();
+ const string16 level =
+ wrenchMenuModel->GetLabelForCommandId(IDC_ZOOM_PERCENT_DISPLAY);
+ [[controller_ zoomDisplay] setTitle:SysUTF16ToNSString(level)];
+ }
+
+ private:
+ NotificationRegistrar registrar_;
+ WrenchMenuController* controller_; // Weak; owns this.
+};
+
+} // namespace WrenchMenuControllerInternal
+
@implementation WrenchMenuController
- (id)init {
- self = [super init];
+ if ((self = [super init])) {
+ observer_.reset(new WrenchMenuControllerInternal::ZoomLevelObserver(self));
+ }
return self;
}
@@ -98,12 +133,22 @@
// NSCarbonMenuWindow; this screws up the typical |-commandDispatch:| system.
- (IBAction)dispatchWrenchMenuCommand:(id)sender {
NSInteger tag = [sender tag];
- // The custom views within the Wrench menu are abnormal and keep the menu open
- // after a target-action. Close the menu manually.
- // TODO(rsesek): It'd be great if the zoom buttons didn't have to close the
- // menu. See http://crbug.com/48679 for more info.
- [menu_ cancelTracking];
- [self dispatchCommandInternal:tag];
+ if (sender == zoomPlus_ || sender == zoomMinus_) {
+ // Do a direct dispatch rather than scheduling on the outermost run loop,
+ // which would not get hit until after the menu had closed.
+ [self performCommandDispatch:[NSNumber numberWithInt:tag]];
+
+ // The zoom buttons should not close the menu if opened sticky.
+ if ([sender respondsToSelector:@selector(isTracking)] &&
+ [sender performSelector:@selector(isTracking)]) {
+ [menu_ cancelTracking];
+ }
+ } else {
+ // The custom views within the Wrench menu are abnormal and keep the menu
+ // open after a target-action. Close the menu manually.
+ [menu_ cancelTracking];
+ [self dispatchCommandInternal:tag];
+ }
}
- (void)dispatchCommandInternal:(NSInteger)tag {
@@ -197,4 +242,8 @@
[[editCut_ superview] setFrame:parentFrame];
}
+- (NSButton*)zoomDisplay {
+ return zoomDisplay_;
+}
+
@end // @implementation WrenchMenuController