diff options
author | pinkerton@chromium.org <pinkerton@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-16 19:39:42 +0000 |
---|---|---|
committer | pinkerton@chromium.org <pinkerton@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-16 19:39:42 +0000 |
commit | dc2e19a410569e30dc9ad317b92da275738722ad (patch) | |
tree | 11c61e8fbfaaf26a3404c5a0c3299ec6bddbeafc /chrome/browser/app_modal_dialog_mac.mm | |
parent | 0471c9f5171d457897bcf9f3448a0befb0ad427c (diff) | |
download | chromium_src-dc2e19a410569e30dc9ad317b92da275738722ad.zip chromium_src-dc2e19a410569e30dc9ad317b92da275738722ad.tar.gz chromium_src-dc2e19a410569e30dc9ad317b92da275738722ad.tar.bz2 |
Implement app modal dialogs on mac.
Review URL: http://codereview.chromium.org/79012
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@13869 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/app_modal_dialog_mac.mm')
-rw-r--r-- | chrome/browser/app_modal_dialog_mac.mm | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/chrome/browser/app_modal_dialog_mac.mm b/chrome/browser/app_modal_dialog_mac.mm new file mode 100644 index 0000000..81143cc --- /dev/null +++ b/chrome/browser/app_modal_dialog_mac.mm @@ -0,0 +1,106 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/app_modal_dialog.h" + +#import <Cocoa/Cocoa.h> + +#include "base/sys_string_conversions.h" +#include "chrome/common/l10n_util.h" +#include "chrome/common/message_box_flags.h" +#include "grit/generated_resources.h" + +// Helper object that receives the notification that the dialog/sheet is +// going away. Is responsible for cleaning itself up. +@interface AppModalDialogHelper : NSObject +@end + +@implementation AppModalDialogHelper +// |contextInfo| is the bridge back to the C++ AppModalDialog. When complete, +// autorelease to clean ourselves up. +- (void)sheetDidEnd:(NSWindow *)sheet + returnCode:(int)returnCode + contextInfo:(void*)contextInfo { + AppModalDialog* bridge = reinterpret_cast<AppModalDialog*>(contextInfo); + switch (returnCode) { + case NSAlertDefaultReturn: // OK + bridge->OnAccept(std::wstring(), false); + break; + case NSAlertOtherReturn: // Cancel + bridge->OnCancel(); + break; + default: + NOTREACHED(); + } + [self autorelease]; +} +@end + +AppModalDialog::~AppModalDialog() { +} + +void AppModalDialog::CreateAndShowDialog() { + // Determine the names of the dialog buttons based on the flags. "Default" + // is the OK button. "Other" is the cancel button. We don't use the + // "Alternate" button in NSRunAlertPanel. + // TODO(pinkerton): Need to find the right localized strings for these. + NSString* default_button = NSLocalizedString(@"OK", nil); + NSString* other_button = NSLocalizedString(@"Cancel", nil); + switch (dialog_flags_) { + case MessageBox::kIsJavascriptAlert: + // OK & Cancel are fine for these types of alerts. + break; + case MessageBox::kIsJavascriptConfirm: + if (is_before_unload_dialog_) { + std::string button_text = l10n_util::GetStringUTF8( + IDS_BEFOREUNLOAD_MESSAGEBOX_OK_BUTTON_LABEL); + default_button = base::SysUTF8ToNSString(button_text); + button_text = l10n_util::GetStringUTF8( + IDS_BEFOREUNLOAD_MESSAGEBOX_CANCEL_BUTTON_LABEL); + other_button = base::SysUTF8ToNSString(button_text); + } + break; + case MessageBox::kIsJavascriptPrompt: + // We need to make a custom message box for javascript prompts. Not + // sure how to handle this... + NOTIMPLEMENTED(); + break; + + default: + NOTREACHED(); + } + + // Create a helper which will receive the sheet ended selector. It will + // delete itself when done. It doesn't need anything passed to its init + // as it will get a contextInfo parameter. + AppModalDialogHelper* helper = [[AppModalDialogHelper alloc] init]; + + // Show the modal dialog. + NSString* title_str = base::SysWideToNSString(title_); + NSString* message_str = base::SysWideToNSString(message_text_); + NSBeginAlertSheet(title_str, default_button, nil, other_button, nil, + helper, @selector(sheetDidEnd:returnCode:contextInfo:), + nil, this, message_str); +} + +void AppModalDialog::ActivateModalDialog() { + NOTIMPLEMENTED(); +} + +void AppModalDialog::CloseModalDialog() { + NOTIMPLEMENTED(); +} + +int AppModalDialog::GetDialogButtons() { + NOTIMPLEMENTED(); + return 0; +} + +void AppModalDialog::AcceptWindow() { + NOTIMPLEMENTED(); +} + +void AppModalDialog::CancelWindow() { + NOTIMPLEMENTED(); +} |