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

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

Issue 11886051: Turned UiStrings into a singleton so that the continue window does not depend on ChromotingHost. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 7 years, 11 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/disconnect_window_mac.h ('k') | remoting/host/disconnect_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 #import "remoting/host/disconnect_window_mac.h" 7 #import "remoting/host/disconnect_window_mac.h"
8 8
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
11 #include "base/sys_string_conversions.h" 11 #include "base/sys_string_conversions.h"
12 #include "remoting/host/disconnect_window.h" 12 #include "remoting/host/disconnect_window.h"
13 #include "remoting/host/ui_strings.h" 13 #include "remoting/host/ui_strings.h"
14 14
15 @interface DisconnectWindowController() 15 @interface DisconnectWindowController()
16 - (BOOL)isRToL; 16 - (BOOL)isRToL;
17 - (void)Hide; 17 - (void)Hide;
18 @end 18 @end
19 19
20 namespace remoting { 20 namespace remoting {
21 21
22 class DisconnectWindowMac : public remoting::DisconnectWindow { 22 class DisconnectWindowMac : public remoting::DisconnectWindow {
23 public: 23 public:
24 DisconnectWindowMac(); 24 explicit DisconnectWindowMac(const UiStrings* ui_strings);
25 virtual ~DisconnectWindowMac(); 25 virtual ~DisconnectWindowMac();
26 26
27 virtual bool Show(const UiStrings& ui_strings, 27 virtual bool Show(const base::Closure& disconnect_callback,
28 const base::Closure& disconnect_callback,
29 const std::string& username) OVERRIDE; 28 const std::string& username) OVERRIDE;
30 virtual void Hide() OVERRIDE; 29 virtual void Hide() OVERRIDE;
31 30
32 private: 31 private:
33 DisconnectWindowController* window_controller_; 32 DisconnectWindowController* window_controller_;
34 33
34 // Points to the localized strings.
35 const UiStrings* ui_strings_;
36
35 DISALLOW_COPY_AND_ASSIGN(DisconnectWindowMac); 37 DISALLOW_COPY_AND_ASSIGN(DisconnectWindowMac);
36 }; 38 };
37 39
38 DisconnectWindowMac::DisconnectWindowMac() 40 DisconnectWindowMac::DisconnectWindowMac(const UiStrings* ui_strings)
39 : window_controller_(nil) { 41 : window_controller_(nil),
42 ui_strings_(ui_strings) {
40 } 43 }
41 44
42 DisconnectWindowMac::~DisconnectWindowMac() { 45 DisconnectWindowMac::~DisconnectWindowMac() {
43 Hide(); 46 Hide();
44 } 47 }
45 48
46 bool DisconnectWindowMac::Show(const UiStrings& ui_strings, 49 bool DisconnectWindowMac::Show(const base::Closure& disconnect_callback,
47 const base::Closure& disconnect_callback,
48 const std::string& username) { 50 const std::string& username) {
49 DCHECK(!disconnect_callback.is_null()); 51 DCHECK(!disconnect_callback.is_null());
50 DCHECK(window_controller_ == nil); 52 DCHECK(window_controller_ == nil);
51 53
52 window_controller_ = 54 window_controller_ =
53 [[DisconnectWindowController alloc] initWithUiStrings:ui_strings 55 [[DisconnectWindowController alloc] initWithUiStrings:ui_strings_
54 callback:disconnect_callback 56 callback:disconnect_callback
55 username:username]; 57 username:username];
56 [window_controller_ showWindow:nil]; 58 [window_controller_ showWindow:nil];
57 return true; 59 return true;
58 } 60 }
59 61
60 void DisconnectWindowMac::Hide() { 62 void DisconnectWindowMac::Hide() {
61 // DisconnectWindowController is responsible for releasing itself in its 63 // DisconnectWindowController is responsible for releasing itself in its
62 // windowWillClose: method. 64 // windowWillClose: method.
63 [window_controller_ Hide]; 65 [window_controller_ Hide];
64 window_controller_ = nil; 66 window_controller_ = nil;
65 } 67 }
66 68
67 scoped_ptr<DisconnectWindow> DisconnectWindow::Create() { 69 scoped_ptr<DisconnectWindow> DisconnectWindow::Create(
68 return scoped_ptr<DisconnectWindow>(new DisconnectWindowMac()); 70 const UiStrings* ui_strings) {
71 return scoped_ptr<DisconnectWindow>(new DisconnectWindowMac(ui_strings));
69 } 72 }
70 73
71 } // namespace remoting 74 } // namespace remoting
72 75
73 @implementation DisconnectWindowController 76 @implementation DisconnectWindowController
74 - (id)initWithUiStrings:(const remoting::UiStrings&)ui_strings 77 - (id)initWithUiStrings:(const remoting::UiStrings*)ui_strings
75 callback:(const base::Closure&)disconnect_callback 78 callback:(const base::Closure&)disconnect_callback
76 username:(const std::string&)username { 79 username:(const std::string&)username {
77 self = [super initWithWindowNibName:@"disconnect_window"]; 80 self = [super initWithWindowNibName:@"disconnect_window"];
78 if (self) { 81 if (self) {
79 rtl_ = (ui_strings.direction == remoting::UiStrings::RTL); 82 ui_strings_ = ui_strings;
80 disconnect_message_ = ui_strings.disconnect_message;
81 disconnect_button_text_ = ui_strings.disconnect_button_text;
82 disconnect_callback_ = disconnect_callback; 83 disconnect_callback_ = disconnect_callback;
83 username_ = UTF8ToUTF16(username); 84 username_ = UTF8ToUTF16(username);
84 } 85 }
85 return self; 86 return self;
86 } 87 }
87 88
88 - (void)dealloc { 89 - (void)dealloc {
89 [super dealloc]; 90 [super dealloc];
90 } 91 }
91 92
92 - (IBAction)stopSharing:(id)sender { 93 - (IBAction)stopSharing:(id)sender {
93 if (!disconnect_callback_.is_null()) { 94 if (!disconnect_callback_.is_null()) {
94 disconnect_callback_.Run(); 95 disconnect_callback_.Run();
95 } 96 }
96 } 97 }
97 98
98 - (BOOL)isRToL { 99 - (BOOL)isRToL {
99 return rtl_; 100 return ui_strings_->direction == remoting::UiStrings::RTL;
100 } 101 }
101 102
102 - (void)Hide { 103 - (void)Hide {
103 disconnect_callback_.Reset(); 104 disconnect_callback_.Reset();
104 [self close]; 105 [self close];
105 } 106 }
106 107
107 - (void)windowDidLoad { 108 - (void)windowDidLoad {
108 string16 text = ReplaceStringPlaceholders(disconnect_message_, username_, 109 string16 text = ReplaceStringPlaceholders(ui_strings_->disconnect_message,
109 NULL); 110 username_, NULL);
110 [connectedToField_ setStringValue:base::SysUTF16ToNSString(text)]; 111 [connectedToField_ setStringValue:base::SysUTF16ToNSString(text)];
111 112
112 [disconnectButton_ setTitle:base::SysUTF16ToNSString( 113 [disconnectButton_ setTitle:base::SysUTF16ToNSString(
113 disconnect_button_text_)]; 114 ui_strings_->disconnect_button_text)];
114 115
115 // Resize the window dynamically based on the content. 116 // Resize the window dynamically based on the content.
116 CGFloat oldConnectedWidth = NSWidth([connectedToField_ bounds]); 117 CGFloat oldConnectedWidth = NSWidth([connectedToField_ bounds]);
117 [connectedToField_ sizeToFit]; 118 [connectedToField_ sizeToFit];
118 NSRect connectedToFrame = [connectedToField_ frame]; 119 NSRect connectedToFrame = [connectedToField_ frame];
119 CGFloat newConnectedWidth = NSWidth(connectedToFrame); 120 CGFloat newConnectedWidth = NSWidth(connectedToFrame);
120 121
121 // Set a max width for the connected to text field. 122 // Set a max width for the connected to text field.
122 if (newConnectedWidth > 123 if (newConnectedWidth >
123 remoting::DisconnectWindow::kMaximumConnectedNameWidthInPixels) { 124 remoting::DisconnectWindow::kMaximumConnectedNameWidthInPixels) {
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 path = [NSBezierPath bezierPath]; 284 path = [NSBezierPath bezierPath];
284 [path moveToPoint:top]; 285 [path moveToPoint:top];
285 [path lineToPoint:bottom]; 286 [path lineToPoint:bottom];
286 [light setStroke]; 287 [light setStroke];
287 [path stroke]; 288 [path stroke];
288 289
289 [context setShouldAntialias:alias]; 290 [context setShouldAntialias:alias];
290 } 291 }
291 292
292 @end 293 @end
OLDNEW
« no previous file with comments | « remoting/host/disconnect_window_mac.h ('k') | remoting/host/disconnect_window_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698