Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2787)

Unified Diff: chrome/browser/ui/cocoa/screen_capture_notification_ui_cocoa.mm

Issue 12453019: Copy remoting notification bar to chrome and use it for screen capture API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/cocoa/screen_capture_notification_ui_cocoa.mm
diff --git a/remoting/host/disconnect_window_mac.mm b/chrome/browser/ui/cocoa/screen_capture_notification_ui_cocoa.mm
similarity index 48%
copy from remoting/host/disconnect_window_mac.mm
copy to chrome/browser/ui/cocoa/screen_capture_notification_ui_cocoa.mm
index 12a4f5fc7ab6432bc17b934cb0a95c8dc64d0301..158a23de59f540066c0c88c1f04828a95c7bd0dc 100644
--- a/remoting/host/disconnect_window_mac.mm
+++ b/chrome/browser/ui/cocoa/screen_capture_notification_ui_cocoa.mm
@@ -1,87 +1,77 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import <Cocoa/Cocoa.h>
-#import "remoting/host/disconnect_window_mac.h"
+#include "chrome/browser/ui/cocoa/screen_capture_notification_ui_cocoa.h"
#include "base/compiler_specific.h"
+#include "base/i18n/rtl.h"
+#include "base/mac/bundle_locations.h"
#include "base/string_util.h"
#include "base/sys_string_conversions.h"
-#include "remoting/host/disconnect_window.h"
-#include "remoting/host/ui_strings.h"
+#include "grit/generated_resources.h"
+#include "ui/base/l10n/l10n_util.h"
-@interface DisconnectWindowController()
-- (BOOL)isRToL;
+@interface ScreenCaptureNotificationController()
- (void)Hide;
@end
-namespace remoting {
-
-class DisconnectWindowMac : public remoting::DisconnectWindow {
+class ScreenCaptureNotificationUICocoa : public ScreenCaptureNotificationUI {
public:
- explicit DisconnectWindowMac(const UiStrings* ui_strings);
- virtual ~DisconnectWindowMac();
+ ScreenCaptureNotificationUICocoa();
+ virtual ~ScreenCaptureNotificationUICocoa();
- virtual bool Show(const base::Closure& disconnect_callback,
- const std::string& username) OVERRIDE;
- virtual void Hide() OVERRIDE;
+ // ScreenCaptureNotificationUI interface.
+ virtual bool Show(const base::Closure& stop_callback,
+ const string16& title) OVERRIDE;
private:
- DisconnectWindowController* window_controller_;
-
- // Points to the localized strings.
- const UiStrings* ui_strings_;
+ ScreenCaptureNotificationController* window_controller_;
- DISALLOW_COPY_AND_ASSIGN(DisconnectWindowMac);
+ DISALLOW_COPY_AND_ASSIGN(ScreenCaptureNotificationUICocoa);
};
-DisconnectWindowMac::DisconnectWindowMac(const UiStrings* ui_strings)
- : window_controller_(nil),
- ui_strings_(ui_strings) {
+ScreenCaptureNotificationUICocoa::ScreenCaptureNotificationUICocoa()
+ : window_controller_(nil) {
}
-DisconnectWindowMac::~DisconnectWindowMac() {
- Hide();
+ScreenCaptureNotificationUICocoa::~ScreenCaptureNotificationUICocoa() {
+ // ScreenCaptureNotificationController is responsible for releasing itself in
+ // its windowWillClose: method.
+ [window_controller_ Hide];
+ window_controller_ = nil;
}
-bool DisconnectWindowMac::Show(const base::Closure& disconnect_callback,
- const std::string& username) {
- DCHECK(!disconnect_callback.is_null());
+bool ScreenCaptureNotificationUICocoa::Show(const base::Closure& stop_callback,
+ const string16& title) {
+ DCHECK(!stop_callback.is_null());
DCHECK(window_controller_ == nil);
window_controller_ =
- [[DisconnectWindowController alloc] initWithUiStrings:ui_strings_
- callback:disconnect_callback
- username:username];
+ [[ScreenCaptureNotificationController alloc]
+ initWithCallback:stop_callback
+ title:title];
[window_controller_ showWindow:nil];
return true;
}
-void DisconnectWindowMac::Hide() {
- // DisconnectWindowController is responsible for releasing itself in its
- // windowWillClose: method.
- [window_controller_ Hide];
- window_controller_ = nil;
-}
-
-scoped_ptr<DisconnectWindow> DisconnectWindow::Create(
- const UiStrings* ui_strings) {
- return scoped_ptr<DisconnectWindow>(new DisconnectWindowMac(ui_strings));
+scoped_ptr<ScreenCaptureNotificationUI> ScreenCaptureNotificationUI::Create() {
+ return scoped_ptr<ScreenCaptureNotificationUI>(
+ new ScreenCaptureNotificationUICocoa());
}
-} // namespace remoting
-
-@implementation DisconnectWindowController
-- (id)initWithUiStrings:(const remoting::UiStrings*)ui_strings
- callback:(const base::Closure&)disconnect_callback
- username:(const std::string&)username {
- self = [super initWithWindowNibName:@"disconnect_window"];
+@implementation ScreenCaptureNotificationController
+- (id)initWithCallback:(const base::Closure&)stop_callback
+ title:(const string16&)title {
+ NSString* nibpath =
+ [base::mac::FrameworkBundle() pathForResource:@"ScreenCaptureNotification"
+ ofType:@"nib"];
+ self = [super initWithWindowNibPath:nibpath owner:self];
if (self) {
- ui_strings_ = ui_strings;
- disconnect_callback_ = disconnect_callback;
- username_ = UTF8ToUTF16(username);
+ stop_callback_ = stop_callback;
+ title_ = title;
}
return self;
}
@@ -91,68 +81,64 @@ scoped_ptr<DisconnectWindow> DisconnectWindow::Create(
}
- (IBAction)stopSharing:(id)sender {
- if (!disconnect_callback_.is_null()) {
- disconnect_callback_.Run();
+ if (!stop_callback_.is_null()) {
+ stop_callback_.Run();
}
}
-- (BOOL)isRToL {
- return ui_strings_->direction == remoting::UiStrings::RTL;
-}
-
- (void)Hide {
- disconnect_callback_.Reset();
+ stop_callback_.Reset();
[self close];
}
- (void)windowDidLoad {
- string16 text = ReplaceStringPlaceholders(ui_strings_->disconnect_message,
- username_, NULL);
- [connectedToField_ setStringValue:base::SysUTF16ToNSString(text)];
+ string16 text = l10n_util::GetStringFUTF16(
+ IDS_MEDIA_SCREEN_CAPTURE_NOTIFICATION_TEXT, title_);
+ [statusField_ setStringValue:base::SysUTF16ToNSString(text)];
- [disconnectButton_ setTitle:base::SysUTF16ToNSString(
- ui_strings_->disconnect_button_text)];
+ string16 button_label =
+ l10n_util::GetStringUTF16(IDS_MEDIA_SCREEN_CAPTURE_NOTIFICATION_STOP);
+ [stopButton_ setTitle:base::SysUTF16ToNSString(button_label)];
// Resize the window dynamically based on the content.
- CGFloat oldConnectedWidth = NSWidth([connectedToField_ bounds]);
- [connectedToField_ sizeToFit];
- NSRect connectedToFrame = [connectedToField_ frame];
- CGFloat newConnectedWidth = NSWidth(connectedToFrame);
+ CGFloat oldConnectedWidth = NSWidth([statusField_ bounds]);
+ [statusField_ sizeToFit];
+ NSRect statusFrame = [statusField_ frame];
+ CGFloat newConnectedWidth = NSWidth(statusFrame);
// Set a max width for the connected to text field.
- if (newConnectedWidth >
- remoting::DisconnectWindow::kMaximumConnectedNameWidthInPixels) {
- newConnectedWidth
- = remoting::DisconnectWindow::kMaximumConnectedNameWidthInPixels;
- connectedToFrame.size.width = newConnectedWidth;
- [connectedToField_ setFrame:connectedToFrame];
+ const int kMaximumStatusWidth = 400;
+ if (newConnectedWidth > kMaximumStatusWidth) {
+ newConnectedWidth = kMaximumStatusWidth;
+ statusFrame.size.width = newConnectedWidth;
+ [statusField_ setFrame:statusFrame];
}
- CGFloat oldDisconnectWidth = NSWidth([disconnectButton_ bounds]);
- [disconnectButton_ sizeToFit];
- NSRect disconnectFrame = [disconnectButton_ frame];
- CGFloat newDisconnectWidth = NSWidth(disconnectFrame);
+ CGFloat oldstopWidth = NSWidth([stopButton_ bounds]);
+ [stopButton_ sizeToFit];
+ NSRect stopFrame = [stopButton_ frame];
+ CGFloat newStopWidth = NSWidth(stopFrame);
- // Move the disconnect button appropriately.
- disconnectFrame.origin.x += newConnectedWidth - oldConnectedWidth;
- [disconnectButton_ setFrame:disconnectFrame];
+ // Move the stop button appropriately.
+ stopFrame.origin.x += newConnectedWidth - oldConnectedWidth;
+ [stopButton_ setFrame:stopFrame];
- // Then resize the window appropriately
+ // Then resize the window appropriately.
NSWindow *window = [self window];
NSRect windowFrame = [window frame];
windowFrame.size.width += (newConnectedWidth - oldConnectedWidth +
- newDisconnectWidth - oldDisconnectWidth);
+ newStopWidth - oldstopWidth);
[window setFrame:windowFrame display:NO];
- if ([self isRToL]) {
+ if (base::i18n::IsRTL()) {
// Handle right to left case
- CGFloat buttonInset = NSWidth(windowFrame) - NSMaxX(disconnectFrame);
+ CGFloat buttonInset = NSWidth(windowFrame) - NSMaxX(stopFrame);
CGFloat buttonTextSpacing
- = NSMinX(disconnectFrame) - NSMaxX(connectedToFrame);
- disconnectFrame.origin.x = buttonInset;
- connectedToFrame.origin.x = NSMaxX(disconnectFrame) + buttonTextSpacing;
- [connectedToField_ setFrame:connectedToFrame];
- [disconnectButton_ setFrame:disconnectFrame];
+ = NSMinX(stopFrame) - NSMaxX(statusFrame);
+ stopFrame.origin.x = buttonInset;
+ statusFrame.origin.x = NSMaxX(stopFrame) + buttonTextSpacing;
+ [statusField_ setFrame:statusFrame];
+ [stopButton_ setFrame:stopFrame];
}
// Center the window at the bottom of the screen, above the dock (if present).
@@ -171,16 +157,11 @@ scoped_ptr<DisconnectWindow> DisconnectWindow::Create(
@end
-@interface DisconnectWindow()
-- (BOOL)isRToL;
-@end
-
-@implementation DisconnectWindow
-
+@implementation ScreenCaptureNotificationWindow
- (id)initWithContentRect:(NSRect)contentRect
styleMask:(NSUInteger)aStyle
backing:(NSBackingStoreType)bufferingType
- defer:(BOOL)flag {
+ defer:(BOOL)flag {
// Pass NSBorderlessWindowMask for the styleMask to remove the title bar.
self = [super initWithContentRect:contentRect
styleMask:NSBorderlessWindowMask
@@ -198,26 +179,9 @@ scoped_ptr<DisconnectWindow> DisconnectWindow::Create(
}
return self;
}
-
-- (BOOL)isRToL {
- DCHECK([[self windowController] respondsToSelector:@selector(isRToL)]);
- return [[self windowController] isRToL];
-}
-
@end
-
-@interface DisconnectView()
-- (BOOL)isRToL;
-@end
-
-@implementation DisconnectView
-
-- (BOOL)isRToL {
- DCHECK([[self window] isKindOfClass:[DisconnectWindow class]]);
- return [static_cast<DisconnectWindow*>([self window]) isRToL];
-}
-
+@implementation ScreenCaptureNotificationView
- (void)drawRect:(NSRect)rect {
// All magic numbers taken from screen shots provided by UX.
NSRect bounds = NSInsetRect([self bounds], 1, 1);
@@ -251,8 +215,8 @@ scoped_ptr<DisconnectWindow> DisconnectWindow::Create(
[context setShouldAntialias:NO];
// Handle bidirectional locales properly.
- CGFloat inset = [self isRToL] ? NSMaxX(bounds) - kBaseInset - kDragHandleWidth
- : kBaseInset;
+ CGFloat inset = base::i18n::IsRTL() ?
+ NSMaxX(bounds) - kBaseInset - kDragHandleWidth : kBaseInset;
NSPoint top = NSMakePoint(inset, NSMidY(bounds) - kHeight / 2.0);
NSPoint bottom = NSMakePoint(inset, top.y + kHeight);

Powered by Google App Engine
This is Rietveld 408576698