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

Side by Side Diff: remoting/host/continue_window_mac.mm

Issue 20985002: Localized Chromoting Host on Mac and Linux. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 7 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 | Annotate | Revision Log
« no previous file with comments | « remoting/host/continue_window_gtk.cc ('k') | remoting/host/continue_window_win.cc » ('j') | 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 <Cocoa/Cocoa.h> 5 #import <Cocoa/Cocoa.h>
6 6
7 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/mac/scoped_nsautorelease_pool.h" 9 #include "base/mac/scoped_nsautorelease_pool.h"
10 #include "base/mac/scoped_nsobject.h" 10 #include "base/mac/scoped_nsobject.h"
11 #include "base/strings/sys_string_conversions.h" 11 #include "base/strings/sys_string_conversions.h"
12 #include "remoting/base/string_resources.h"
12 #include "remoting/host/continue_window.h" 13 #include "remoting/host/continue_window.h"
14 #include "ui/base/l10n/l10n_util_mac.h"
13 15
14 // Handles the ContinueWindow. 16 // Handles the ContinueWindow.
15 @interface ContinueWindowMacController : NSObject { 17 @interface ContinueWindowMacController : NSObject {
16 @private 18 @private
17 base::scoped_nsobject<NSMutableArray> shades_; 19 base::scoped_nsobject<NSMutableArray> shades_;
18 base::scoped_nsobject<NSAlert> continue_alert_; 20 base::scoped_nsobject<NSAlert> continue_alert_;
19 remoting::ContinueWindow* continue_window_; 21 remoting::ContinueWindow* continue_window_;
20 const remoting::UiStrings* ui_strings_;
21 } 22 }
22 23
23 - (id)initWithUiStrings:(const remoting::UiStrings*)ui_strings 24 - (id)initWithWindow:(remoting::ContinueWindow*)continue_window;
24 continue_window:(remoting::ContinueWindow*)continue_window;
25 - (void)show; 25 - (void)show;
26 - (void)hide; 26 - (void)hide;
27 - (void)onCancel:(id)sender; 27 - (void)onCancel:(id)sender;
28 - (void)onContinue:(id)sender; 28 - (void)onContinue:(id)sender;
29 @end 29 @end
30 30
31 namespace remoting { 31 namespace remoting {
32 32
33 // A bridge between C++ and ObjC implementations of ContinueWindow. 33 // A bridge between C++ and ObjC implementations of ContinueWindow.
34 // Everything important occurs in ContinueWindowMacController. 34 // Everything important occurs in ContinueWindowMacController.
35 class ContinueWindowMac : public ContinueWindow { 35 class ContinueWindowMac : public ContinueWindow {
36 public: 36 public:
37 explicit ContinueWindowMac(const UiStrings& ui_strings); 37 ContinueWindowMac();
38 virtual ~ContinueWindowMac(); 38 virtual ~ContinueWindowMac();
39 39
40 protected: 40 protected:
41 // ContinueWindow overrides. 41 // ContinueWindow overrides.
42 virtual void ShowUi() OVERRIDE; 42 virtual void ShowUi() OVERRIDE;
43 virtual void HideUi() OVERRIDE; 43 virtual void HideUi() OVERRIDE;
44 44
45 private: 45 private:
46 base::scoped_nsobject<ContinueWindowMacController> controller_; 46 base::scoped_nsobject<ContinueWindowMacController> controller_;
47 47
48 DISALLOW_COPY_AND_ASSIGN(ContinueWindowMac); 48 DISALLOW_COPY_AND_ASSIGN(ContinueWindowMac);
49 }; 49 };
50 50
51 ContinueWindowMac::ContinueWindowMac(const UiStrings& ui_strings) 51 ContinueWindowMac::ContinueWindowMac() {
52 : ContinueWindow(ui_strings) {
53 } 52 }
54 53
55 ContinueWindowMac::~ContinueWindowMac() { 54 ContinueWindowMac::~ContinueWindowMac() {
56 DCHECK(CalledOnValidThread()); 55 DCHECK(CalledOnValidThread());
57 } 56 }
58 57
59 void ContinueWindowMac::ShowUi() { 58 void ContinueWindowMac::ShowUi() {
60 DCHECK(CalledOnValidThread()); 59 DCHECK(CalledOnValidThread());
61 60
62 base::mac::ScopedNSAutoreleasePool pool; 61 base::mac::ScopedNSAutoreleasePool pool;
63 controller_.reset( 62 controller_.reset(
64 [[ContinueWindowMacController alloc] initWithUiStrings:&ui_strings() 63 [[ContinueWindowMacController alloc] initWithWindow:this]);
65 continue_window:this]);
66 [controller_ show]; 64 [controller_ show];
67 } 65 }
68 66
69 void ContinueWindowMac::HideUi() { 67 void ContinueWindowMac::HideUi() {
70 DCHECK(CalledOnValidThread()); 68 DCHECK(CalledOnValidThread());
71 69
72 base::mac::ScopedNSAutoreleasePool pool; 70 base::mac::ScopedNSAutoreleasePool pool;
73 [controller_ hide]; 71 [controller_ hide];
74 } 72 }
75 73
76 // static 74 // static
77 scoped_ptr<HostWindow> HostWindow::CreateContinueWindow( 75 scoped_ptr<HostWindow> HostWindow::CreateContinueWindow() {
78 const UiStrings& ui_strings) { 76 return scoped_ptr<HostWindow>(new ContinueWindowMac());
79 return scoped_ptr<HostWindow>(new ContinueWindowMac(ui_strings));
80 } 77 }
81 78
82 } // namespace remoting 79 } // namespace remoting
83 80
84 @implementation ContinueWindowMacController 81 @implementation ContinueWindowMacController
85 82
86 - (id)initWithUiStrings:(const remoting::UiStrings*)ui_strings 83 - (id)initWithWindow:(remoting::ContinueWindow*)continue_window {
87 continue_window:(remoting::ContinueWindow*)continue_window {
88 if ((self = [super init])) { 84 if ((self = [super init])) {
89 continue_window_ = continue_window; 85 continue_window_ = continue_window;
90 ui_strings_ = ui_strings;
91 } 86 }
92 return self; 87 return self;
93 } 88 }
94 89
95 - (void)show { 90 - (void)show {
96 // Generate window shade 91 // Generate window shade
97 NSArray* screens = [NSScreen screens]; 92 NSArray* screens = [NSScreen screens];
98 shades_.reset([[NSMutableArray alloc] initWithCapacity:[screens count]]); 93 shades_.reset([[NSMutableArray alloc] initWithCapacity:[screens count]]);
99 for (NSScreen *screen in screens) { 94 for (NSScreen *screen in screens) {
100 NSWindow* shade = 95 NSWindow* shade =
101 [[[NSWindow alloc] initWithContentRect:[screen frame] 96 [[[NSWindow alloc] initWithContentRect:[screen frame]
102 styleMask:NSBorderlessWindowMask 97 styleMask:NSBorderlessWindowMask
103 backing:NSBackingStoreBuffered 98 backing:NSBackingStoreBuffered
104 defer:NO 99 defer:NO
105 screen:screen] autorelease]; 100 screen:screen] autorelease];
106 [shade setReleasedWhenClosed:NO]; 101 [shade setReleasedWhenClosed:NO];
107 [shade setAlphaValue:0.8]; 102 [shade setAlphaValue:0.8];
108 [shade setOpaque:NO]; 103 [shade setOpaque:NO];
109 [shade setBackgroundColor:[NSColor blackColor]]; 104 [shade setBackgroundColor:[NSColor blackColor]];
110 // Raise the window shade above just about everything else. 105 // Raise the window shade above just about everything else.
111 // Leave the dock and menu bar exposed so the user has some basic level 106 // Leave the dock and menu bar exposed so the user has some basic level
112 // of control (like they can quit Chromium). 107 // of control (like they can quit Chromium).
113 [shade setLevel:NSModalPanelWindowLevel - 1]; 108 [shade setLevel:NSModalPanelWindowLevel - 1];
114 [shade orderFront:nil]; 109 [shade orderFront:nil];
115 [shades_ addObject:shade]; 110 [shades_ addObject:shade];
116 } 111 }
117 112
118 // Create alert. 113 // Create alert.
119 NSString* message = base::SysUTF16ToNSString(ui_strings_->continue_prompt);
120 NSString* continue_button_string = base::SysUTF16ToNSString(
121 ui_strings_->continue_button_text);
122 NSString* cancel_button_string = base::SysUTF16ToNSString(
123 ui_strings_->stop_sharing_button_text);
124 continue_alert_.reset([[NSAlert alloc] init]); 114 continue_alert_.reset([[NSAlert alloc] init]);
125 [continue_alert_ setMessageText:message]; 115 [continue_alert_ setMessageText:l10n_util::GetNSString(IDR_CONTINUE_PROMPT)];
126 116
127 NSButton* continue_button = 117 NSButton* continue_button =
128 [continue_alert_ addButtonWithTitle:continue_button_string]; 118 [continue_alert_ addButtonWithTitle:l10n_util::GetNSString(
119 IDR_CONTINUE_BUTTON)];
129 [continue_button setAction:@selector(onContinue:)]; 120 [continue_button setAction:@selector(onContinue:)];
130 [continue_button setTarget:self]; 121 [continue_button setTarget:self];
131 122
132 NSButton* cancel_button = 123 NSButton* cancel_button =
133 [continue_alert_ addButtonWithTitle:cancel_button_string]; 124 [continue_alert_ addButtonWithTitle:l10n_util::GetNSString(
125 IDR_STOP_SHARING_BUTTON)];
134 [cancel_button setAction:@selector(onCancel:)]; 126 [cancel_button setAction:@selector(onCancel:)];
135 [cancel_button setTarget:self]; 127 [cancel_button setTarget:self];
136 128
137 NSBundle *bundle = [NSBundle bundleForClass:[self class]]; 129 NSBundle *bundle = [NSBundle bundleForClass:[self class]];
138 NSString *imagePath = [bundle pathForResource:@"chromoting128" ofType:@"png"]; 130 NSString *imagePath = [bundle pathForResource:@"chromoting128" ofType:@"png"];
139 base::scoped_nsobject<NSImage> image( 131 base::scoped_nsobject<NSImage> image(
140 [[NSImage alloc] initByReferencingFile:imagePath]); 132 [[NSImage alloc] initByReferencingFile:imagePath]);
141 [continue_alert_ setIcon:image]; 133 [continue_alert_ setIcon:image];
142 [continue_alert_ layout]; 134 [continue_alert_ layout];
143 135
(...skipping 19 matching lines...) Expand all
163 [self hide]; 155 [self hide];
164 continue_window_->DisconnectSession(); 156 continue_window_->DisconnectSession();
165 } 157 }
166 158
167 - (void)onContinue:(id)sender { 159 - (void)onContinue:(id)sender {
168 [self hide]; 160 [self hide];
169 continue_window_->ContinueSession(); 161 continue_window_->ContinueSession();
170 } 162 }
171 163
172 @end 164 @end
OLDNEW
« no previous file with comments | « remoting/host/continue_window_gtk.cc ('k') | remoting/host/continue_window_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698