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

Side by Side Diff: chrome/browser/cocoa/download_request_dialog_delegate_mac.mm

Issue 159780: Add support for constrained windows on os x, based on Avi's GTMWindowSheetController. (Closed)
Patch Set: Merge with ToT Created 11 years, 4 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
OLDNEW
(Empty)
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/cocoa/download_request_dialog_delegate_mac.h"
6
7 #import <Cocoa/Cocoa.h>
8
9 #include "app/l10n_util_mac.h"
10 #include "app/message_box_flags.h"
11 #include "base/sys_string_conversions.h"
12 #include "chrome/browser/tab_contents/constrained_window.h"
13 #include "chrome/browser/tab_contents/tab_contents.h"
14 #include "grit/generated_resources.h"
15 #include "views/controls/message_box_view.h"
16
17 @interface SheetCallback : NSObject {
18 DownloadRequestDialogDelegateMac* target_; // weak
19 }
20 - (id)initWithTarget:(DownloadRequestDialogDelegateMac*)target;
21 - (void) alertDidEnd:(NSAlert *)alert
22 returnCode:(int)returnCode
23 contextInfo:(void *)contextInfo;
24 @end
25
26 @implementation SheetCallback
27 - (id)initWithTarget:(DownloadRequestDialogDelegateMac*)target {
28 if ((self = [super init]) != nil) {
29 target_ = target;
30 }
31 return self;
32 }
33 - (void) alertDidEnd:(NSAlert *)alert
34 returnCode:(int)returnCode
35 contextInfo:(void *)contextInfo {
36 target_->SheetDidEnd(returnCode);
37 }
38 @end
39
40
41 // static
42 DownloadRequestDialogDelegate* DownloadRequestDialogDelegate::Create(
43 TabContents* tab,
44 DownloadRequestManager::TabDownloadState* host) {
45 return new DownloadRequestDialogDelegateMac(tab, host);
46 }
47
48 DownloadRequestDialogDelegateMac::DownloadRequestDialogDelegateMac(
49 TabContents* tab,
50 DownloadRequestManager::TabDownloadState* host)
51 : DownloadRequestDialogDelegate(host),
52 ConstrainedWindowMacDelegateSystemSheet(
53 [[[SheetCallback alloc] initWithTarget:this] autorelease],
54 @selector(alertDidEnd:returnCode:contextInfo:)),
55 responded_(false) {
56
57 // Set up alert.
58 NSAlert* alert = [[[NSAlert alloc] init] autorelease];
59 [alert addButtonWithTitle:
60 l10n_util::GetNSStringWithFixup(IDS_MULTI_DOWNLOAD_WARNING_ALLOW)];
61 NSButton* denyButton = [alert addButtonWithTitle:
62 l10n_util::GetNSStringWithFixup(IDS_MULTI_DOWNLOAD_WARNING_DENY)];
63 [alert setMessageText:
64 l10n_util::GetNSStringWithFixup(IDS_MULTI_DOWNLOAD_WARNING)];
65 [alert setAlertStyle:NSInformationalAlertStyle];
66
67 // Cocoa automatically gives ESC as a key equivalent to buttons with the text
68 // "Cancel". Since we use a different text, we have to set this ourselves.
69 NSString* escapeKey = @"\e";
70 [denyButton setKeyEquivalent:escapeKey];
71
72 set_sheet(alert);
73
74 // Display alert in a per-tab sheet.
75 window_ = tab->CreateConstrainedDialog(this);
76 }
77
78 void DownloadRequestDialogDelegateMac::CloseWindow() {
79 window_->CloseConstrainedWindow();
80 }
81
82 void DownloadRequestDialogDelegateMac::DeleteDelegate() {
83 if (is_sheet_open()) {
84 // Close sheet if it's still open.
85 [NSApp endSheet:[(NSAlert*)sheet() window]]; // class SheetDidEnd().
86 DCHECK(responded_);
87 }
88 if (!responded_) {
89 // Happens if the sheet was never visible
90 responded_ = true;
91 DoCancel();
92 }
93 DCHECK(!host_);
94 delete this;
95 }
96
97 void DownloadRequestDialogDelegateMac::SheetDidEnd(int returnCode) {
98 DCHECK(!responded_);
99 if (returnCode == NSAlertFirstButtonReturn) {
100 DoAccept();
101 } else {
102 DoCancel();
103 }
104 responded_ = true;
105 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698