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/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 UiStrings& ui_strings, |
28 const base::Closure& disconnect_callback, | 28 const base::Closure& disconnect_callback, |
29 const std::string& username) OVERRIDE; | 29 const std::string& username) OVERRIDE; |
30 virtual void Hide() OVERRIDE; | 30 virtual void Hide() OVERRIDE; |
31 | 31 |
32 private: | 32 private: |
33 DisconnectWindowController* window_controller_; | 33 DisconnectWindowController* window_controller_; |
34 | 34 |
| 35 // Points to the localized strings. |
| 36 const UiStrings* ui_strings_; |
| 37 |
35 DISALLOW_COPY_AND_ASSIGN(DisconnectWindowMac); | 38 DISALLOW_COPY_AND_ASSIGN(DisconnectWindowMac); |
36 }; | 39 }; |
37 | 40 |
38 DisconnectWindowMac::DisconnectWindowMac() | 41 DisconnectWindowMac::DisconnectWindowMac(const UiStrings* ui_strings) |
39 : window_controller_(nil) { | 42 : window_controller_(nil), |
| 43 ui_strings_(ui_strings) { |
40 } | 44 } |
41 | 45 |
42 DisconnectWindowMac::~DisconnectWindowMac() { | 46 DisconnectWindowMac::~DisconnectWindowMac() { |
43 Hide(); | 47 Hide(); |
44 } | 48 } |
45 | 49 |
46 bool DisconnectWindowMac::Show(const UiStrings& ui_strings, | 50 bool DisconnectWindowMac::Show(const base::Closure& disconnect_callback, |
47 const base::Closure& disconnect_callback, | |
48 const std::string& username) { | 51 const std::string& username) { |
49 DCHECK(!disconnect_callback.is_null()); | 52 DCHECK(!disconnect_callback.is_null()); |
50 DCHECK(window_controller_ == nil); | 53 DCHECK(window_controller_ == nil); |
51 | 54 |
52 window_controller_ = | 55 window_controller_ = |
53 [[DisconnectWindowController alloc] initWithUiStrings:ui_strings | 56 [[DisconnectWindowController alloc] initWithUiStrings:ui_strings_ |
54 callback:disconnect_callback | 57 callback:disconnect_callback |
55 username:username]; | 58 username:username]; |
56 [window_controller_ showWindow:nil]; | 59 [window_controller_ showWindow:nil]; |
57 return true; | 60 return true; |
58 } | 61 } |
59 | 62 |
60 void DisconnectWindowMac::Hide() { | 63 void DisconnectWindowMac::Hide() { |
61 // DisconnectWindowController is responsible for releasing itself in its | 64 // DisconnectWindowController is responsible for releasing itself in its |
62 // windowWillClose: method. | 65 // windowWillClose: method. |
63 [window_controller_ Hide]; | 66 [window_controller_ Hide]; |
64 window_controller_ = nil; | 67 window_controller_ = nil; |
65 } | 68 } |
66 | 69 |
67 scoped_ptr<DisconnectWindow> DisconnectWindow::Create() { | 70 scoped_ptr<DisconnectWindow> DisconnectWindow::Create( |
68 return scoped_ptr<DisconnectWindow>(new DisconnectWindowMac()); | 71 const UiStrings* ui_strings) { |
| 72 return scoped_ptr<DisconnectWindow>(new DisconnectWindowMac(ui_strings)); |
69 } | 73 } |
70 | 74 |
71 } // namespace remoting | 75 } // namespace remoting |
72 | 76 |
73 @implementation DisconnectWindowController | 77 @implementation DisconnectWindowController |
74 - (id)initWithUiStrings:(const remoting::UiStrings&)ui_strings | 78 - (id)initWithUiStrings:(const remoting::UiStrings*)ui_strings |
75 callback:(const base::Closure&)disconnect_callback | 79 callback:(const base::Closure&)disconnect_callback |
76 username:(const std::string&)username { | 80 username:(const std::string&)username { |
77 self = [super initWithWindowNibName:@"disconnect_window"]; | 81 self = [super initWithWindowNibName:@"disconnect_window"]; |
78 if (self) { | 82 if (self) { |
79 rtl_ = (ui_strings.direction == remoting::UiStrings::RTL); | 83 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; | 84 disconnect_callback_ = disconnect_callback; |
83 username_ = UTF8ToUTF16(username); | 85 username_ = UTF8ToUTF16(username); |
84 } | 86 } |
85 return self; | 87 return self; |
86 } | 88 } |
87 | 89 |
88 - (void)dealloc { | 90 - (void)dealloc { |
89 [super dealloc]; | 91 [super dealloc]; |
90 } | 92 } |
91 | 93 |
92 - (IBAction)stopSharing:(id)sender { | 94 - (IBAction)stopSharing:(id)sender { |
93 if (!disconnect_callback_.is_null()) { | 95 if (!disconnect_callback_.is_null()) { |
94 disconnect_callback_.Run(); | 96 disconnect_callback_.Run(); |
95 } | 97 } |
96 } | 98 } |
97 | 99 |
98 - (BOOL)isRToL { | 100 - (BOOL)isRToL { |
99 return rtl_; | 101 return ui_strings_->direction == remoting::UiStrings::RTL; |
100 } | 102 } |
101 | 103 |
102 - (void)Hide { | 104 - (void)Hide { |
103 disconnect_callback_.Reset(); | 105 disconnect_callback_.Reset(); |
104 [self close]; | 106 [self close]; |
105 } | 107 } |
106 | 108 |
107 - (void)windowDidLoad { | 109 - (void)windowDidLoad { |
108 string16 text = ReplaceStringPlaceholders(disconnect_message_, username_, | 110 string16 text = ReplaceStringPlaceholders(ui_strings_->disconnect_message, |
109 NULL); | 111 username_, NULL); |
110 [connectedToField_ setStringValue:base::SysUTF16ToNSString(text)]; | 112 [connectedToField_ setStringValue:base::SysUTF16ToNSString(text)]; |
111 | 113 |
112 [disconnectButton_ setTitle:base::SysUTF16ToNSString( | 114 [disconnectButton_ setTitle:base::SysUTF16ToNSString( |
113 disconnect_button_text_)]; | 115 ui_strings_->disconnect_button_text)]; |
114 | 116 |
115 // Resize the window dynamically based on the content. | 117 // Resize the window dynamically based on the content. |
116 CGFloat oldConnectedWidth = NSWidth([connectedToField_ bounds]); | 118 CGFloat oldConnectedWidth = NSWidth([connectedToField_ bounds]); |
117 [connectedToField_ sizeToFit]; | 119 [connectedToField_ sizeToFit]; |
118 NSRect connectedToFrame = [connectedToField_ frame]; | 120 NSRect connectedToFrame = [connectedToField_ frame]; |
119 CGFloat newConnectedWidth = NSWidth(connectedToFrame); | 121 CGFloat newConnectedWidth = NSWidth(connectedToFrame); |
120 | 122 |
121 // Set a max width for the connected to text field. | 123 // Set a max width for the connected to text field. |
122 if (newConnectedWidth > | 124 if (newConnectedWidth > |
123 remoting::DisconnectWindow::kMaximumConnectedNameWidthInPixels) { | 125 remoting::DisconnectWindow::kMaximumConnectedNameWidthInPixels) { |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 path = [NSBezierPath bezierPath]; | 285 path = [NSBezierPath bezierPath]; |
284 [path moveToPoint:top]; | 286 [path moveToPoint:top]; |
285 [path lineToPoint:bottom]; | 287 [path lineToPoint:bottom]; |
286 [light setStroke]; | 288 [light setStroke]; |
287 [path stroke]; | 289 [path stroke]; |
288 | 290 |
289 [context setShouldAntialias:alias]; | 291 [context setShouldAntialias:alias]; |
290 } | 292 } |
291 | 293 |
292 @end | 294 @end |
OLD | NEW |