Chromium Code Reviews| 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/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 11 #include "base/memory/weak_ptr.h" | |
| 10 #include "base/string_util.h" | 12 #include "base/string_util.h" |
| 11 #include "base/strings/sys_string_conversions.h" | 13 #include "base/strings/sys_string_conversions.h" |
| 12 #include "remoting/host/disconnect_window.h" | 14 #include "remoting/host/client_session_control.h" |
| 15 #include "remoting/host/host_window.h" | |
| 13 #include "remoting/host/ui_strings.h" | 16 #include "remoting/host/ui_strings.h" |
| 14 | 17 |
| 15 @interface DisconnectWindowController() | 18 @interface DisconnectWindowController() |
| 16 - (BOOL)isRToL; | 19 - (BOOL)isRToL; |
| 17 - (void)Hide; | 20 - (void)Hide; |
| 18 @end | 21 @end |
| 19 | 22 |
| 23 const int kMaximumConnectedNameWidthInPixels = 400; | |
| 24 | |
| 20 namespace remoting { | 25 namespace remoting { |
| 21 | 26 |
| 22 class DisconnectWindowMac : public remoting::DisconnectWindow { | 27 class DisconnectWindowMac : public HostWindow { |
| 23 public: | 28 public: |
| 24 explicit DisconnectWindowMac(const UiStrings* ui_strings); | 29 explicit DisconnectWindowMac(const UiStrings& ui_strings); |
| 25 virtual ~DisconnectWindowMac(); | 30 virtual ~DisconnectWindowMac(); |
| 26 | 31 |
| 27 virtual bool Show(const base::Closure& disconnect_callback, | 32 // HostWindow overrides. |
| 28 const std::string& username) OVERRIDE; | 33 virtual void Start( |
| 29 virtual void Hide() OVERRIDE; | 34 const base::WeakPtr<ClientSessionControl>& client_session_control) |
| 35 OVERRIDE; | |
| 30 | 36 |
| 31 private: | 37 private: |
| 38 // Localized UI strings. | |
| 39 UiStrings ui_strings_; | |
| 40 | |
| 32 DisconnectWindowController* window_controller_; | 41 DisconnectWindowController* window_controller_; |
| 33 | 42 |
| 34 // Points to the localized strings. | |
| 35 const UiStrings* ui_strings_; | |
| 36 | |
| 37 DISALLOW_COPY_AND_ASSIGN(DisconnectWindowMac); | 43 DISALLOW_COPY_AND_ASSIGN(DisconnectWindowMac); |
| 38 }; | 44 }; |
| 39 | 45 |
| 40 DisconnectWindowMac::DisconnectWindowMac(const UiStrings* ui_strings) | 46 DisconnectWindowMac::DisconnectWindowMac(const UiStrings& ui_strings) |
| 41 : window_controller_(nil), | 47 : ui_strings_(ui_strings), |
| 42 ui_strings_(ui_strings) { | 48 window_controller_(NULL) { |
|
Sergey Ulanov
2013/04/04 00:10:03
s/NULL/nil/
alexeypa (please no reviews)
2013/04/04 16:56:40
Done.
| |
| 43 } | 49 } |
| 44 | 50 |
| 45 DisconnectWindowMac::~DisconnectWindowMac() { | 51 DisconnectWindowMac::~DisconnectWindowMac() { |
| 46 Hide(); | 52 DCHECK(CalledOnValidThread()); |
| 47 } | |
| 48 | 53 |
| 49 bool DisconnectWindowMac::Show(const base::Closure& disconnect_callback, | |
| 50 const std::string& username) { | |
| 51 DCHECK(!disconnect_callback.is_null()); | |
| 52 DCHECK(window_controller_ == nil); | |
| 53 | |
| 54 window_controller_ = | |
| 55 [[DisconnectWindowController alloc] initWithUiStrings:ui_strings_ | |
| 56 callback:disconnect_callback | |
| 57 username:username]; | |
| 58 [window_controller_ showWindow:nil]; | |
| 59 return true; | |
| 60 } | |
| 61 | |
| 62 void DisconnectWindowMac::Hide() { | |
| 63 // DisconnectWindowController is responsible for releasing itself in its | 54 // DisconnectWindowController is responsible for releasing itself in its |
| 64 // windowWillClose: method. | 55 // windowWillClose: method. |
| 65 [window_controller_ Hide]; | 56 [window_controller_ Hide]; |
| 66 window_controller_ = nil; | 57 window_controller_ = nil; |
| 67 } | 58 } |
| 68 | 59 |
| 69 scoped_ptr<DisconnectWindow> DisconnectWindow::Create( | 60 void DisconnectWindowMac::Start( |
| 70 const UiStrings* ui_strings) { | 61 const base::WeakPtr<ClientSessionControl>& client_session_control) { |
| 71 return scoped_ptr<DisconnectWindow>(new DisconnectWindowMac(ui_strings)); | 62 DCHECK(CalledOnValidThread()); |
| 63 DCHECK(client_session_control); | |
| 64 DCHECK(!disconnect_window_); | |
| 65 | |
| 66 // Create the window. | |
| 67 base::Closure disconnect_callback = | |
| 68 base::Bind(&ClientSessionControl::DisconnectSession, | |
| 69 client_session_control); | |
| 70 std::string client_jid = client_session_control->client_jid(); | |
| 71 std::string username = client_jid.substr(0, client_jid.find('/')); | |
| 72 window_controller_ = | |
| 73 [[DisconnectWindowController alloc] initWithUiStrings:&ui_strings_ | |
| 74 callback:disconnect_callback | |
| 75 username:username]; | |
| 76 [window_controller_ showWindow:nil]; | |
| 77 } | |
| 78 | |
| 79 // static | |
| 80 scoped_ptr<HostWindow> HostWindow::CreateDisconnectWindow( | |
| 81 const UiStrings& ui_strings) { | |
| 82 return scoped_ptr<HostWindow>(new DisconnectWindowMac(ui_strings)); | |
| 72 } | 83 } |
| 73 | 84 |
| 74 } // namespace remoting | 85 } // namespace remoting |
| 75 | 86 |
| 76 @implementation DisconnectWindowController | 87 @implementation DisconnectWindowController |
| 77 - (id)initWithUiStrings:(const remoting::UiStrings*)ui_strings | 88 - (id)initWithUiStrings:(const remoting::UiStrings*)ui_strings |
| 78 callback:(const base::Closure&)disconnect_callback | 89 callback:(const base::Closure&)disconnect_callback |
| 79 username:(const std::string&)username { | 90 username:(const std::string&)username { |
| 80 self = [super initWithWindowNibName:@"disconnect_window"]; | 91 self = [super initWithWindowNibName:@"disconnect_window"]; |
| 81 if (self) { | 92 if (self) { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 113 [disconnectButton_ setTitle:base::SysUTF16ToNSString( | 124 [disconnectButton_ setTitle:base::SysUTF16ToNSString( |
| 114 ui_strings_->disconnect_button_text)]; | 125 ui_strings_->disconnect_button_text)]; |
| 115 | 126 |
| 116 // Resize the window dynamically based on the content. | 127 // Resize the window dynamically based on the content. |
| 117 CGFloat oldConnectedWidth = NSWidth([connectedToField_ bounds]); | 128 CGFloat oldConnectedWidth = NSWidth([connectedToField_ bounds]); |
| 118 [connectedToField_ sizeToFit]; | 129 [connectedToField_ sizeToFit]; |
| 119 NSRect connectedToFrame = [connectedToField_ frame]; | 130 NSRect connectedToFrame = [connectedToField_ frame]; |
| 120 CGFloat newConnectedWidth = NSWidth(connectedToFrame); | 131 CGFloat newConnectedWidth = NSWidth(connectedToFrame); |
| 121 | 132 |
| 122 // Set a max width for the connected to text field. | 133 // Set a max width for the connected to text field. |
| 123 if (newConnectedWidth > | 134 if (newConnectedWidth > kMaximumConnectedNameWidthInPixels) { |
| 124 remoting::DisconnectWindow::kMaximumConnectedNameWidthInPixels) { | 135 newConnectedWidth = kMaximumConnectedNameWidthInPixels; |
| 125 newConnectedWidth | |
| 126 = remoting::DisconnectWindow::kMaximumConnectedNameWidthInPixels; | |
| 127 connectedToFrame.size.width = newConnectedWidth; | 136 connectedToFrame.size.width = newConnectedWidth; |
| 128 [connectedToField_ setFrame:connectedToFrame]; | 137 [connectedToField_ setFrame:connectedToFrame]; |
| 129 } | 138 } |
| 130 | 139 |
| 131 CGFloat oldDisconnectWidth = NSWidth([disconnectButton_ bounds]); | 140 CGFloat oldDisconnectWidth = NSWidth([disconnectButton_ bounds]); |
| 132 [disconnectButton_ sizeToFit]; | 141 [disconnectButton_ sizeToFit]; |
| 133 NSRect disconnectFrame = [disconnectButton_ frame]; | 142 NSRect disconnectFrame = [disconnectButton_ frame]; |
| 134 CGFloat newDisconnectWidth = NSWidth(disconnectFrame); | 143 CGFloat newDisconnectWidth = NSWidth(disconnectFrame); |
| 135 | 144 |
| 136 // Move the disconnect button appropriately. | 145 // Move the disconnect button appropriately. |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 284 path = [NSBezierPath bezierPath]; | 293 path = [NSBezierPath bezierPath]; |
| 285 [path moveToPoint:top]; | 294 [path moveToPoint:top]; |
| 286 [path lineToPoint:bottom]; | 295 [path lineToPoint:bottom]; |
| 287 [light setStroke]; | 296 [light setStroke]; |
| 288 [path stroke]; | 297 [path stroke]; |
| 289 | 298 |
| 290 [context setShouldAntialias:alias]; | 299 [context setShouldAntialias:alias]; |
| 291 } | 300 } |
| 292 | 301 |
| 293 @end | 302 @end |
| OLD | NEW |