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/bind.h" | 9 #include "base/bind.h" |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 11 #include "base/i18n/rtl.h" |
11 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
12 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
13 #include "base/strings/sys_string_conversions.h" | 14 #include "base/strings/sys_string_conversions.h" |
| 15 #include "remoting/base/string_resources.h" |
14 #include "remoting/host/client_session_control.h" | 16 #include "remoting/host/client_session_control.h" |
15 #include "remoting/host/host_window.h" | 17 #include "remoting/host/host_window.h" |
16 #include "remoting/host/ui_strings.h" | 18 #include "ui/base/l10n/l10n_util_mac.h" |
17 | 19 |
18 @interface DisconnectWindowController() | 20 @interface DisconnectWindowController() |
19 - (BOOL)isRToL; | 21 - (BOOL)isRToL; |
20 - (void)Hide; | 22 - (void)Hide; |
21 @end | 23 @end |
22 | 24 |
23 const int kMaximumConnectedNameWidthInPixels = 400; | 25 const int kMaximumConnectedNameWidthInPixels = 600; |
24 | 26 |
25 namespace remoting { | 27 namespace remoting { |
26 | 28 |
27 class DisconnectWindowMac : public HostWindow { | 29 class DisconnectWindowMac : public HostWindow { |
28 public: | 30 public: |
29 explicit DisconnectWindowMac(const UiStrings& ui_strings); | 31 DisconnectWindowMac(); |
30 virtual ~DisconnectWindowMac(); | 32 virtual ~DisconnectWindowMac(); |
31 | 33 |
32 // HostWindow overrides. | 34 // HostWindow overrides. |
33 virtual void Start( | 35 virtual void Start( |
34 const base::WeakPtr<ClientSessionControl>& client_session_control) | 36 const base::WeakPtr<ClientSessionControl>& client_session_control) |
35 OVERRIDE; | 37 OVERRIDE; |
36 | 38 |
37 private: | 39 private: |
38 // Localized UI strings. | |
39 UiStrings ui_strings_; | |
40 | |
41 DisconnectWindowController* window_controller_; | 40 DisconnectWindowController* window_controller_; |
42 | 41 |
43 DISALLOW_COPY_AND_ASSIGN(DisconnectWindowMac); | 42 DISALLOW_COPY_AND_ASSIGN(DisconnectWindowMac); |
44 }; | 43 }; |
45 | 44 |
46 DisconnectWindowMac::DisconnectWindowMac(const UiStrings& ui_strings) | 45 DisconnectWindowMac::DisconnectWindowMac() |
47 : ui_strings_(ui_strings), | 46 : window_controller_(nil) { |
48 window_controller_(nil) { | |
49 } | 47 } |
50 | 48 |
51 DisconnectWindowMac::~DisconnectWindowMac() { | 49 DisconnectWindowMac::~DisconnectWindowMac() { |
52 DCHECK(CalledOnValidThread()); | 50 DCHECK(CalledOnValidThread()); |
53 | 51 |
54 // DisconnectWindowController is responsible for releasing itself in its | 52 // DisconnectWindowController is responsible for releasing itself in its |
55 // windowWillClose: method. | 53 // windowWillClose: method. |
56 [window_controller_ Hide]; | 54 [window_controller_ Hide]; |
57 window_controller_ = nil; | 55 window_controller_ = nil; |
58 } | 56 } |
59 | 57 |
60 void DisconnectWindowMac::Start( | 58 void DisconnectWindowMac::Start( |
61 const base::WeakPtr<ClientSessionControl>& client_session_control) { | 59 const base::WeakPtr<ClientSessionControl>& client_session_control) { |
62 DCHECK(CalledOnValidThread()); | 60 DCHECK(CalledOnValidThread()); |
63 DCHECK(client_session_control); | 61 DCHECK(client_session_control); |
64 DCHECK(window_controller_ == nil); | 62 DCHECK(window_controller_ == nil); |
65 | 63 |
66 // Create the window. | 64 // Create the window. |
67 base::Closure disconnect_callback = | 65 base::Closure disconnect_callback = |
68 base::Bind(&ClientSessionControl::DisconnectSession, | 66 base::Bind(&ClientSessionControl::DisconnectSession, |
69 client_session_control); | 67 client_session_control); |
70 std::string client_jid = client_session_control->client_jid(); | 68 std::string client_jid = client_session_control->client_jid(); |
71 std::string username = client_jid.substr(0, client_jid.find('/')); | 69 std::string username = client_jid.substr(0, client_jid.find('/')); |
72 window_controller_ = | 70 window_controller_ = |
73 [[DisconnectWindowController alloc] initWithUiStrings:&ui_strings_ | 71 [[DisconnectWindowController alloc] initWithCallback:disconnect_callback |
74 callback:disconnect_callback | 72 username:username]; |
75 username:username]; | |
76 [window_controller_ showWindow:nil]; | 73 [window_controller_ showWindow:nil]; |
77 } | 74 } |
78 | 75 |
79 // static | 76 // static |
80 scoped_ptr<HostWindow> HostWindow::CreateDisconnectWindow( | 77 scoped_ptr<HostWindow> HostWindow::CreateDisconnectWindow() { |
81 const UiStrings& ui_strings) { | 78 return scoped_ptr<HostWindow>(new DisconnectWindowMac()); |
82 return scoped_ptr<HostWindow>(new DisconnectWindowMac(ui_strings)); | |
83 } | 79 } |
84 | 80 |
85 } // namespace remoting | 81 } // namespace remoting |
86 | 82 |
87 @implementation DisconnectWindowController | 83 @implementation DisconnectWindowController |
88 - (id)initWithUiStrings:(const remoting::UiStrings*)ui_strings | 84 - (id)initWithCallback:(const base::Closure&)disconnect_callback |
89 callback:(const base::Closure&)disconnect_callback | 85 username:(const std::string&)username { |
90 username:(const std::string&)username { | |
91 self = [super initWithWindowNibName:@"disconnect_window"]; | 86 self = [super initWithWindowNibName:@"disconnect_window"]; |
92 if (self) { | 87 if (self) { |
93 ui_strings_ = ui_strings; | |
94 disconnect_callback_ = disconnect_callback; | 88 disconnect_callback_ = disconnect_callback; |
95 username_ = UTF8ToUTF16(username); | 89 username_ = UTF8ToUTF16(username); |
96 } | 90 } |
97 return self; | 91 return self; |
98 } | 92 } |
99 | 93 |
100 - (void)dealloc { | 94 - (void)dealloc { |
101 [super dealloc]; | 95 [super dealloc]; |
102 } | 96 } |
103 | 97 |
104 - (IBAction)stopSharing:(id)sender { | 98 - (IBAction)stopSharing:(id)sender { |
105 if (!disconnect_callback_.is_null()) { | 99 if (!disconnect_callback_.is_null()) { |
106 disconnect_callback_.Run(); | 100 disconnect_callback_.Run(); |
107 } | 101 } |
108 } | 102 } |
109 | 103 |
110 - (BOOL)isRToL { | 104 - (BOOL)isRToL { |
111 return ui_strings_->direction == remoting::UiStrings::RTL; | 105 return base::i18n::IsRTL(); |
112 } | 106 } |
113 | 107 |
114 - (void)Hide { | 108 - (void)Hide { |
115 disconnect_callback_.Reset(); | 109 disconnect_callback_.Reset(); |
116 [self close]; | 110 [self close]; |
117 } | 111 } |
118 | 112 |
119 - (void)windowDidLoad { | 113 - (void)windowDidLoad { |
120 string16 text = ReplaceStringPlaceholders(ui_strings_->disconnect_message, | 114 [connectedToField_ setStringValue:l10n_util::GetNSStringF(IDR_MESSAGE_SHARED, |
121 username_, NULL); | 115 username_)]; |
122 [connectedToField_ setStringValue:base::SysUTF16ToNSString(text)]; | 116 [disconnectButton_ setTitle:l10n_util::GetNSString(IDR_STOP_SHARING_BUTTON)]; |
123 | |
124 [disconnectButton_ setTitle:base::SysUTF16ToNSString( | |
125 ui_strings_->disconnect_button_text)]; | |
126 | 117 |
127 // Resize the window dynamically based on the content. | 118 // Resize the window dynamically based on the content. |
128 CGFloat oldConnectedWidth = NSWidth([connectedToField_ bounds]); | 119 CGFloat oldConnectedWidth = NSWidth([connectedToField_ bounds]); |
129 [connectedToField_ sizeToFit]; | 120 [connectedToField_ sizeToFit]; |
130 NSRect connectedToFrame = [connectedToField_ frame]; | 121 NSRect connectedToFrame = [connectedToField_ frame]; |
131 CGFloat newConnectedWidth = NSWidth(connectedToFrame); | 122 CGFloat newConnectedWidth = NSWidth(connectedToFrame); |
132 | 123 |
133 // Set a max width for the connected to text field. | 124 // Set a max width for the connected to text field. |
134 if (newConnectedWidth > kMaximumConnectedNameWidthInPixels) { | 125 if (newConnectedWidth > kMaximumConnectedNameWidthInPixels) { |
135 newConnectedWidth = kMaximumConnectedNameWidthInPixels; | 126 newConnectedWidth = kMaximumConnectedNameWidthInPixels; |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 path = [NSBezierPath bezierPath]; | 284 path = [NSBezierPath bezierPath]; |
294 [path moveToPoint:top]; | 285 [path moveToPoint:top]; |
295 [path lineToPoint:bottom]; | 286 [path lineToPoint:bottom]; |
296 [light setStroke]; | 287 [light setStroke]; |
297 [path stroke]; | 288 [path stroke]; |
298 | 289 |
299 [context setShouldAntialias:alias]; | 290 [context setShouldAntialias:alias]; |
300 } | 291 } |
301 | 292 |
302 @end | 293 @end |
OLD | NEW |