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 DisconnectCallback& 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 DisconnectCallback& 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; | 67 @property (nonatomic, assign) remoting::ChromotingHost* host; |
68 @property (nonatomic, assign) DisconnectCallback disconnect_callback; | |
dcaiafa
2012/05/11 20:10:38
This doesn't need to be a property. It's private a
alexeypa (please no reviews)
2012/05/11 20:19:29
Removed.
| |
65 @property (nonatomic, copy) NSString* username; | 69 @property (nonatomic, copy) NSString* username; |
66 | 70 |
67 - (BOOL)isRToL; | 71 - (BOOL)isRToL; |
68 | 72 |
69 @end | 73 @end |
70 | 74 |
71 @implementation DisconnectWindowController | 75 @implementation DisconnectWindowController |
72 | 76 |
73 @synthesize host = host_; | 77 @synthesize host = host_; |
78 @synthesize disconnect_callback = disconnect_callback_; | |
dcaiafa
2012/05/11 20:10:38
Again, not needed.
alexeypa (please no reviews)
2012/05/11 20:19:29
Done.
| |
74 @synthesize username = username_; | 79 @synthesize username = username_; |
75 | 80 |
76 - (id)initWithHost:(remoting::ChromotingHost*)host | 81 - (id)initWithHost:(remoting::ChromotingHost*)host |
82 callback:(const DisconnectCallback&)disconnect_callback | |
77 username:(NSString*)username { | 83 username:(NSString*)username { |
78 self = [super initWithWindowNibName:@"disconnect_window"]; | 84 self = [super initWithWindowNibName:@"disconnect_window"]; |
79 if (self) { | 85 if (self) { |
80 host_ = host; | 86 host_ = host; |
87 disconnect_callback_ = disconnect_callback; | |
81 username_ = [username copy]; | 88 username_ = [username copy]; |
82 } | 89 } |
83 return self; | 90 return self; |
84 } | 91 } |
85 | 92 |
86 - (void)dealloc { | 93 - (void)dealloc { |
87 [username_ release]; | 94 [username_ release]; |
88 [super dealloc]; | 95 [super dealloc]; |
89 } | 96 } |
90 | 97 |
91 - (IBAction)stopSharing:(id)sender { | 98 - (IBAction)stopSharing:(id)sender { |
92 if (self.host) { | 99 if (!self.disconnect_callback.is_null()) { |
dcaiafa
2012/05/11 20:10:38
To access the field directly, just drop the 'self.
alexeypa (please no reviews)
2012/05/11 20:19:29
Done.
| |
93 self.host->Shutdown(base::Closure()); | 100 self.disconnect_callback.Run(); |
94 self.host = NULL; | |
95 } | 101 } |
96 } | 102 } |
97 | 103 |
98 - (BOOL)isRToL { | 104 - (BOOL)isRToL { |
99 if (host_) { | 105 if (host_) { |
100 return host_->ui_strings().direction == remoting::UiStrings::RTL; | 106 return host_->ui_strings().direction == remoting::UiStrings::RTL; |
101 } else { | 107 } else { |
102 return false; | 108 return false; |
103 } | 109 } |
104 } | 110 } |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
289 path = [NSBezierPath bezierPath]; | 295 path = [NSBezierPath bezierPath]; |
290 [path moveToPoint:top]; | 296 [path moveToPoint:top]; |
291 [path lineToPoint:bottom]; | 297 [path lineToPoint:bottom]; |
292 [light setStroke]; | 298 [light setStroke]; |
293 [path stroke]; | 299 [path stroke]; |
294 | 300 |
295 [context setShouldAntialias:alias]; | 301 [context setShouldAntialias:alias]; |
296 } | 302 } |
297 | 303 |
298 @end | 304 @end |
OLD | NEW |