OLD | NEW |
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/chromoting_host.h" | 12 #include "remoting/host/chromoting_host.h" |
13 #include "remoting/host/disconnect_window.h" | 13 #include "remoting/host/disconnect_window.h" |
14 | 14 |
15 namespace remoting { | 15 namespace remoting { |
16 | 16 |
17 class DisconnectWindowMac : public remoting::DisconnectWindow { | 17 class DisconnectWindowMac : public remoting::DisconnectWindow { |
18 public: | 18 public: |
19 DisconnectWindowMac(); | 19 DisconnectWindowMac(); |
20 virtual ~DisconnectWindowMac(); | 20 virtual ~DisconnectWindowMac(); |
21 | 21 |
22 virtual void Show(remoting::ChromotingHost* host, | 22 virtual void Show(ChromotingHost* host, |
| 23 const base::Closure& disconnect_callback, |
23 const std::string& username) OVERRIDE; | 24 const std::string& username) OVERRIDE; |
24 virtual void Hide() OVERRIDE; | 25 virtual void Hide() OVERRIDE; |
25 | 26 |
26 private: | 27 private: |
27 DisconnectWindowController* window_controller_; | 28 DisconnectWindowController* window_controller_; |
28 | 29 |
29 DISALLOW_COPY_AND_ASSIGN(DisconnectWindowMac); | 30 DISALLOW_COPY_AND_ASSIGN(DisconnectWindowMac); |
30 }; | 31 }; |
31 | 32 |
32 DisconnectWindowMac::DisconnectWindowMac() | 33 DisconnectWindowMac::DisconnectWindowMac() |
33 : window_controller_(nil) { | 34 : window_controller_(nil) { |
34 } | 35 } |
35 | 36 |
36 DisconnectWindowMac::~DisconnectWindowMac() { | 37 DisconnectWindowMac::~DisconnectWindowMac() { |
37 [window_controller_ close]; | 38 [window_controller_ close]; |
38 } | 39 } |
39 | 40 |
40 void DisconnectWindowMac::Show(remoting::ChromotingHost* host, | 41 void DisconnectWindowMac::Show(ChromotingHost* host, |
| 42 const base::Closure& disconnect_callback, |
41 const std::string& username) { | 43 const std::string& username) { |
42 CHECK(window_controller_ == nil); | 44 CHECK(window_controller_ == nil); |
43 NSString* nsUsername = base::SysUTF8ToNSString(username); | 45 NSString* nsUsername = base::SysUTF8ToNSString(username); |
44 window_controller_ = | 46 window_controller_ = |
45 [[DisconnectWindowController alloc] initWithHost:host | 47 [[DisconnectWindowController alloc] initWithHost:host |
| 48 callback:disconnect_callback |
46 username:nsUsername]; | 49 username:nsUsername]; |
47 [window_controller_ showWindow:nil]; | 50 [window_controller_ showWindow:nil]; |
48 } | 51 } |
49 | 52 |
50 void DisconnectWindowMac::Hide() { | 53 void DisconnectWindowMac::Hide() { |
51 // DisconnectWindowController is responsible for releasing itself in its | 54 // DisconnectWindowController is responsible for releasing itself in its |
52 // windowWillClose: method. | 55 // windowWillClose: method. |
53 [window_controller_ close]; | 56 [window_controller_ close]; |
54 window_controller_ = nil; | 57 window_controller_ = nil; |
55 } | 58 } |
56 | 59 |
57 scoped_ptr<DisconnectWindow> DisconnectWindow::Create() { | 60 scoped_ptr<DisconnectWindow> DisconnectWindow::Create() { |
58 return scoped_ptr<DisconnectWindow>(new DisconnectWindowMac()); | 61 return scoped_ptr<DisconnectWindow>(new DisconnectWindowMac()); |
59 } | 62 } |
60 | 63 |
61 } // namespace remoting | 64 } // namespace remoting |
62 | 65 |
63 @interface DisconnectWindowController() | 66 @interface DisconnectWindowController() |
64 @property (nonatomic, assign) remoting::ChromotingHost* host; | |
65 @property (nonatomic, copy) NSString* username; | |
66 | |
67 - (BOOL)isRToL; | 67 - (BOOL)isRToL; |
68 | |
69 @end | 68 @end |
70 | 69 |
71 @implementation DisconnectWindowController | 70 @implementation DisconnectWindowController |
72 | |
73 @synthesize host = host_; | |
74 @synthesize username = username_; | |
75 | |
76 - (id)initWithHost:(remoting::ChromotingHost*)host | 71 - (id)initWithHost:(remoting::ChromotingHost*)host |
| 72 callback:(const base::Closure&)disconnect_callback |
77 username:(NSString*)username { | 73 username:(NSString*)username { |
78 self = [super initWithWindowNibName:@"disconnect_window"]; | 74 self = [super initWithWindowNibName:@"disconnect_window"]; |
79 if (self) { | 75 if (self) { |
80 host_ = host; | 76 host_ = host; |
| 77 disconnect_callback_ = disconnect_callback; |
81 username_ = [username copy]; | 78 username_ = [username copy]; |
82 } | 79 } |
83 return self; | 80 return self; |
84 } | 81 } |
85 | 82 |
86 - (void)dealloc { | 83 - (void)dealloc { |
87 [username_ release]; | 84 [username_ release]; |
88 [super dealloc]; | 85 [super dealloc]; |
89 } | 86 } |
90 | 87 |
91 - (IBAction)stopSharing:(id)sender { | 88 - (IBAction)stopSharing:(id)sender { |
92 if (self.host) { | 89 if (host_ != NULL && !disconnect_callback_.is_null()) { |
93 self.host->Shutdown(base::Closure()); | 90 disconnect_callback_.Run(); |
94 self.host = NULL; | |
95 } | 91 } |
96 } | 92 } |
97 | 93 |
98 - (BOOL)isRToL { | 94 - (BOOL)isRToL { |
99 if (host_) { | 95 if (host_) { |
100 return host_->ui_strings().direction == remoting::UiStrings::RTL; | 96 return host_->ui_strings().direction == remoting::UiStrings::RTL; |
101 } else { | 97 } else { |
102 return false; | 98 return false; |
103 } | 99 } |
104 } | 100 } |
105 | 101 |
106 - (void)close { | 102 - (void)close { |
107 self.host = NULL; | 103 host_ = NULL; |
108 [super close]; | 104 [super close]; |
109 } | 105 } |
110 | 106 |
111 - (void)windowDidLoad { | 107 - (void)windowDidLoad { |
112 string16 text = ReplaceStringPlaceholders( | 108 string16 text = ReplaceStringPlaceholders( |
113 host_->ui_strings().disconnect_message, | 109 host_->ui_strings().disconnect_message, |
114 base::SysNSStringToUTF16(self.username), | 110 base::SysNSStringToUTF16(username_), |
115 NULL); | 111 NULL); |
116 [connectedToField_ setStringValue:base::SysUTF16ToNSString(text)]; | 112 [connectedToField_ setStringValue:base::SysUTF16ToNSString(text)]; |
117 | 113 |
118 [disconnectButton_ setTitle:base::SysUTF16ToNSString( | 114 [disconnectButton_ setTitle:base::SysUTF16ToNSString( |
119 host_->ui_strings().disconnect_button_text_plus_shortcut)]; | 115 host_->ui_strings().disconnect_button_text_plus_shortcut)]; |
120 | 116 |
121 // Resize the window dynamically based on the content. | 117 // Resize the window dynamically based on the content. |
122 CGFloat oldConnectedWidth = NSWidth([connectedToField_ bounds]); | 118 CGFloat oldConnectedWidth = NSWidth([connectedToField_ bounds]); |
123 [connectedToField_ sizeToFit]; | 119 [connectedToField_ sizeToFit]; |
124 NSRect connectedToFrame = [connectedToField_ frame]; | 120 NSRect connectedToFrame = [connectedToField_ frame]; |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 path = [NSBezierPath bezierPath]; | 285 path = [NSBezierPath bezierPath]; |
290 [path moveToPoint:top]; | 286 [path moveToPoint:top]; |
291 [path lineToPoint:bottom]; | 287 [path lineToPoint:bottom]; |
292 [light setStroke]; | 288 [light setStroke]; |
293 [path stroke]; | 289 [path stroke]; |
294 | 290 |
295 [context setShouldAntialias:alias]; | 291 [context setShouldAntialias:alias]; |
296 } | 292 } |
297 | 293 |
298 @end | 294 @end |
OLD | NEW |