| Index: chrome/browser/ui/screen_capture_notification_ui_win.cc
|
| diff --git a/remoting/host/disconnect_window_win.cc b/chrome/browser/ui/screen_capture_notification_ui_win.cc
|
| similarity index 66%
|
| copy from remoting/host/disconnect_window_win.cc
|
| copy to chrome/browser/ui/screen_capture_notification_ui_win.cc
|
| index effe964cdb2b14f2e31eedde3884b79ac595bcb3..9b5dee95cb91d60eec9c601e3addbc62a016612c 100644
|
| --- a/remoting/host/disconnect_window_win.cc
|
| +++ b/chrome/browser/ui/screen_capture_notification_ui_win.cc
|
| @@ -1,12 +1,13 @@
|
| -// 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.
|
|
|
| -#include "remoting/host/disconnect_window.h"
|
| +#include "chrome/browser/ui/screen_capture_notification_ui.h"
|
|
|
| #include <windows.h>
|
|
|
| #include "base/compiler_specific.h"
|
| +#include "base/i18n/rtl.h"
|
| #include "base/logging.h"
|
| #include "base/process_util.h"
|
| #include "base/string_util.h"
|
| @@ -14,17 +15,12 @@
|
| #include "base/win/scoped_gdi_object.h"
|
| #include "base/win/scoped_hdc.h"
|
| #include "base/win/scoped_select_object.h"
|
| -#include "remoting/host/ui_strings.h"
|
| -#include "remoting/host/win/core_resource.h"
|
| -
|
| -// TODO(garykac): Lots of duplicated code in this file and
|
| -// continue_window_win.cc. If we need to expand this then we should
|
| -// create a class with the shared code.
|
| +#include "chrome/app/chrome_dll_resource.h"
|
| +#include "grit/generated_resources.h"
|
| +#include "ui/base/l10n/l10n_util.h"
|
|
|
| namespace {
|
|
|
| -const int DISCONNECT_HOTKEY_ID = 1000;
|
| -
|
| // Maximum length of "Your desktop is shared with ..." message in UTF-16
|
| // characters.
|
| const size_t kMaxSharingWithTextLength = 100;
|
| @@ -34,46 +30,38 @@ const int kWindowBorderRadius = 14;
|
|
|
| } // namespace anonymous
|
|
|
| -namespace remoting {
|
| -
|
| -class DisconnectWindowWin : public DisconnectWindow {
|
| +class ScreenCaptureNotificationUIWin : public ScreenCaptureNotificationUI {
|
| public:
|
| - explicit DisconnectWindowWin(const UiStrings* ui_strings);
|
| - virtual ~DisconnectWindowWin();
|
| + ScreenCaptureNotificationUIWin();
|
| + virtual ~ScreenCaptureNotificationUIWin();
|
|
|
| - // DisconnectWindow interface.
|
| - 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:
|
| + private:
|
| static INT_PTR CALLBACK DialogProc(HWND hwnd, UINT message, WPARAM wparam,
|
| LPARAM lparam);
|
|
|
| BOOL OnDialogMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
|
|
|
| - // Creates the dialog window and registers the disconnect hot key.
|
| - bool BeginDialog(const std::string& username);
|
| + // Creates the dialog window.
|
| + bool BeginDialog(const string16& title);
|
|
|
| - // Closes the dialog, unregisters the hot key and invokes the disconnect
|
| - // callback, if set.
|
| + // Closes the dialog and invokes the disconnect callback, if set.
|
| void EndDialog();
|
|
|
| // Trys to position the dialog window above the taskbar.
|
| void SetDialogPosition();
|
|
|
| // Applies localization string and resizes the dialog.
|
| - bool SetStrings(const string16& username);
|
| + bool UpdateStrings(const string16& title);
|
|
|
| - base::Closure disconnect_callback_;
|
| + base::Closure stop_callback_;
|
| HWND hwnd_;
|
| - bool has_hotkey_;
|
| base::win::ScopedGDIObject<HPEN> border_pen_;
|
|
|
| - // Points to the localized strings.
|
| - const UiStrings* ui_strings_;
|
| -
|
| - DISALLOW_COPY_AND_ASSIGN(DisconnectWindowWin);
|
| + DISALLOW_COPY_AND_ASSIGN(ScreenCaptureNotificationUIWin);
|
| };
|
|
|
| static int GetControlTextWidth(HWND control) {
|
| @@ -89,41 +77,37 @@ static int GetControlTextWidth(HWND control) {
|
| return rect.right;
|
| }
|
|
|
| -DisconnectWindowWin::DisconnectWindowWin(const UiStrings* ui_strings)
|
| +ScreenCaptureNotificationUIWin::ScreenCaptureNotificationUIWin()
|
| : hwnd_(NULL),
|
| - has_hotkey_(false),
|
| border_pen_(CreatePen(PS_SOLID, 5,
|
| - RGB(0.13 * 255, 0.69 * 255, 0.11 * 255))),
|
| - ui_strings_(ui_strings) {
|
| + RGB(0.13 * 255, 0.69 * 255, 0.11 * 255))) {
|
| }
|
|
|
| -DisconnectWindowWin::~DisconnectWindowWin() {
|
| - Hide();
|
| +ScreenCaptureNotificationUIWin::~ScreenCaptureNotificationUIWin() {
|
| + stop_callback_.Reset();
|
| + EndDialog();
|
| }
|
|
|
| -bool DisconnectWindowWin::Show(const base::Closure& disconnect_callback,
|
| - const std::string& username) {
|
| - DCHECK(disconnect_callback_.is_null());
|
| - DCHECK(!disconnect_callback.is_null());
|
| +bool ScreenCaptureNotificationUIWin::Show(
|
| + const base::Closure& stop_callback,
|
| + const string16& title) {
|
| + DCHECK(stop_callback_.is_null());
|
| + DCHECK(!stop_callback.is_null());
|
|
|
| - disconnect_callback_ = disconnect_callback;
|
| + stop_callback_ = stop_callback;
|
|
|
| - if (BeginDialog(username)) {
|
| + if (BeginDialog(title)) {
|
| return true;
|
| } else {
|
| - Hide();
|
| + stop_callback_ = stop_callback;
|
| + EndDialog();
|
| return false;
|
| }
|
| }
|
|
|
| -void DisconnectWindowWin::Hide() {
|
| - // Clear the |disconnect_callback_| so it won't be invoked by EndDialog().
|
| - disconnect_callback_.Reset();
|
| - EndDialog();
|
| -}
|
| -
|
| -INT_PTR CALLBACK DisconnectWindowWin::DialogProc(HWND hwnd, UINT message,
|
| - WPARAM wparam, LPARAM lparam) {
|
| +INT_PTR CALLBACK ScreenCaptureNotificationUIWin::DialogProc(
|
| + HWND hwnd, UINT message,
|
| + WPARAM wparam, LPARAM lparam) {
|
| LONG_PTR self = NULL;
|
| if (message == WM_INITDIALOG) {
|
| self = lparam;
|
| @@ -132,29 +116,29 @@ INT_PTR CALLBACK DisconnectWindowWin::DialogProc(HWND hwnd, UINT message,
|
| SetLastError(ERROR_SUCCESS);
|
| LONG_PTR result = SetWindowLongPtr(hwnd, DWLP_USER, self);
|
| if (result == 0 && GetLastError() != ERROR_SUCCESS)
|
| - reinterpret_cast<DisconnectWindowWin*>(self)->EndDialog();
|
| + reinterpret_cast<ScreenCaptureNotificationUIWin*>(self)->EndDialog();
|
| } else {
|
| self = GetWindowLongPtr(hwnd, DWLP_USER);
|
| }
|
|
|
| if (self) {
|
| - return reinterpret_cast<DisconnectWindowWin*>(self)->OnDialogMessage(
|
| - hwnd, message, wparam, lparam);
|
| + return reinterpret_cast<ScreenCaptureNotificationUIWin*>(self)->
|
| + OnDialogMessage(hwnd, message, wparam, lparam);
|
| }
|
| return FALSE;
|
| }
|
|
|
| -BOOL DisconnectWindowWin::OnDialogMessage(HWND hwnd, UINT message,
|
| +BOOL ScreenCaptureNotificationUIWin::OnDialogMessage(HWND hwnd, UINT message,
|
| WPARAM wparam, LPARAM lparam) {
|
| switch (message) {
|
| // Ignore close messages.
|
| case WM_CLOSE:
|
| return TRUE;
|
|
|
| - // Handle the Disconnect button.
|
| + // Handle the Stop button.
|
| case WM_COMMAND:
|
| switch (LOWORD(wparam)) {
|
| - case IDC_DISCONNECT:
|
| + case IDC_SCREEN_CAPTURE_STOP:
|
| EndDialog();
|
| return TRUE;
|
| }
|
| @@ -164,8 +148,8 @@ BOOL DisconnectWindowWin::OnDialogMessage(HWND hwnd, UINT message,
|
| case WM_DESTROY:
|
| hwnd_ = NULL;
|
|
|
| - // Ensure that the disconnect callback is invoked even if somehow our
|
| - // window gets destroyed.
|
| + // Ensure that the stop callback is invoked even if somehow our window
|
| + // gets destroyed.
|
| EndDialog();
|
|
|
| return TRUE;
|
| @@ -181,11 +165,6 @@ BOOL DisconnectWindowWin::OnDialogMessage(HWND hwnd, UINT message,
|
| SetDialogPosition();
|
| return TRUE;
|
|
|
| - // Handle the disconnect hot-key.
|
| - case WM_HOTKEY:
|
| - EndDialog();
|
| - return TRUE;
|
| -
|
| // Let the window be draggable by its client area by responding
|
| // that the entire window is the title bar.
|
| case WM_NCHITTEST:
|
| @@ -210,13 +189,16 @@ BOOL DisconnectWindowWin::OnDialogMessage(HWND hwnd, UINT message,
|
| return FALSE;
|
| }
|
|
|
| -bool DisconnectWindowWin::BeginDialog(const std::string& username) {
|
| +bool ScreenCaptureNotificationUIWin::BeginDialog(const string16& title) {
|
| DCHECK(!hwnd_);
|
|
|
| + // TODO(sergeyu): Currently this code relies on resources for the dialog. Fix
|
| + // it to work without resources.
|
| +
|
| // Load the dialog resource so that we can modify the RTL flags if necessary.
|
| HMODULE module = base::GetModuleFromAddress(&DialogProc);
|
| - HRSRC dialog_resource =
|
| - FindResource(module, MAKEINTRESOURCE(IDD_DISCONNECT), RT_DIALOG);
|
| + HRSRC dialog_resource = FindResource(
|
| + module, MAKEINTRESOURCE(IDD_SCREEN_CAPTURE_NOTIFICATION), RT_DIALOG);
|
| if (!dialog_resource)
|
| return false;
|
|
|
| @@ -233,7 +215,7 @@ bool DisconnectWindowWin::BeginDialog(const std::string& username) {
|
| // standard headers, so we treat it as a generic pointer and manipulate the
|
| // correct offsets explicitly.
|
| scoped_array<unsigned char> rtl_dialog_template;
|
| - if (ui_strings_->direction == UiStrings::RTL) {
|
| + if (base::i18n::IsRTL()) {
|
| unsigned long dialog_template_size =
|
| SizeofResource(module, dialog_resource);
|
| rtl_dialog_template.reset(new unsigned char[dialog_template_size]);
|
| @@ -248,13 +230,7 @@ bool DisconnectWindowWin::BeginDialog(const std::string& username) {
|
| if (!hwnd_)
|
| return false;
|
|
|
| - // Set up handler for Ctrl-Alt-Esc shortcut.
|
| - if (!has_hotkey_ && RegisterHotKey(hwnd_, DISCONNECT_HOTKEY_ID,
|
| - MOD_ALT | MOD_CONTROL, VK_ESCAPE)) {
|
| - has_hotkey_ = true;
|
| - }
|
| -
|
| - if (!SetStrings(UTF8ToUTF16(username)))
|
| + if (!UpdateStrings(title))
|
| return false;
|
|
|
| SetDialogPosition();
|
| @@ -262,24 +238,19 @@ bool DisconnectWindowWin::BeginDialog(const std::string& username) {
|
| return IsWindowVisible(hwnd_) != FALSE;
|
| }
|
|
|
| -void DisconnectWindowWin::EndDialog() {
|
| - if (has_hotkey_) {
|
| - UnregisterHotKey(hwnd_, DISCONNECT_HOTKEY_ID);
|
| - has_hotkey_ = false;
|
| - }
|
| -
|
| +void ScreenCaptureNotificationUIWin::EndDialog() {
|
| if (hwnd_) {
|
| DestroyWindow(hwnd_);
|
| hwnd_ = NULL;
|
| }
|
|
|
| - if (!disconnect_callback_.is_null()) {
|
| - disconnect_callback_.Run();
|
| - disconnect_callback_.Reset();
|
| + if (!stop_callback_.is_null()) {
|
| + stop_callback_.Run();
|
| + stop_callback_.Reset();
|
| }
|
| }
|
|
|
| -void DisconnectWindowWin::SetDialogPosition() {
|
| +void ScreenCaptureNotificationUIWin::SetDialogPosition() {
|
| // Try to center the window above the task-bar. If that fails, use the
|
| // primary monitor. If that fails (very unlikely), use the default position.
|
| HWND taskbar = FindWindow(kShellTrayWindowName, NULL);
|
| @@ -297,33 +268,37 @@ void DisconnectWindowWin::SetDialogPosition() {
|
| }
|
| }
|
|
|
| -bool DisconnectWindowWin::SetStrings(const string16& username) {
|
| - if (!SetWindowText(hwnd_, ui_strings_->product_name.c_str()))
|
| +bool ScreenCaptureNotificationUIWin::UpdateStrings(const string16& title) {
|
| + string16 window_title =
|
| + l10n_util::GetStringFUTF16(IDS_MEDIA_SCREEN_CAPTURE_NOTIFICATION_TITLE,
|
| + title);
|
| + if (!SetWindowText(hwnd_, window_title.c_str()))
|
| return false;
|
|
|
| // Localize the disconnect button text and measure length of the old and new
|
| // labels.
|
| - HWND disconnect_button = GetDlgItem(hwnd_, IDC_DISCONNECT);
|
| - if (!disconnect_button)
|
| + HWND stop_button = GetDlgItem(hwnd_, IDC_SCREEN_CAPTURE_STOP);
|
| + if (!stop_button)
|
| return false;
|
| - int button_old_required_width = GetControlTextWidth(disconnect_button);
|
| - if (!SetWindowText(disconnect_button,
|
| - ui_strings_->disconnect_button_text.c_str())) {
|
| + int button_old_required_width = GetControlTextWidth(stop_button);
|
| + string16 button_label =
|
| + l10n_util::GetStringUTF16(IDS_MEDIA_SCREEN_CAPTURE_NOTIFICATION_STOP);
|
| + if (!SetWindowText(stop_button, button_label.c_str()))
|
| return false;
|
| - }
|
| - int button_new_required_width = GetControlTextWidth(disconnect_button);
|
| + int button_new_required_width = GetControlTextWidth(stop_button);
|
| int button_width_delta =
|
| button_new_required_width - button_old_required_width;
|
|
|
| // Format and truncate "Your desktop is shared with ..." message.
|
| - string16 text = ReplaceStringPlaceholders(ui_strings_->disconnect_message,
|
| - username, NULL);
|
| +
|
| + string16 text = l10n_util::GetStringFUTF16(
|
| + IDS_MEDIA_SCREEN_CAPTURE_NOTIFICATION_TEXT, title);
|
| if (text.length() > kMaxSharingWithTextLength)
|
| text.erase(kMaxSharingWithTextLength);
|
|
|
| // Set localized and truncated "Your desktop is shared with ..." message and
|
| // measure length of the old and new text.
|
| - HWND sharing_with_label = GetDlgItem(hwnd_, IDC_DISCONNECT_SHARINGWITH);
|
| + HWND sharing_with_label = GetDlgItem(hwnd_, IDC_SCREEN_CAPTURE_TEXT);
|
| if (!sharing_with_label)
|
| return false;
|
| int label_old_required_width = GetControlTextWidth(sharing_with_label);
|
| @@ -346,7 +321,7 @@ bool DisconnectWindowWin::SetStrings(const string16& username) {
|
|
|
| // Reposition the disconnect button as well.
|
| RECT button_rect;
|
| - if (!GetWindowRect(disconnect_button, &button_rect))
|
| + if (!GetWindowRect(stop_button, &button_rect))
|
| return false;
|
| int button_width = button_rect.right - button_rect.left;
|
| int button_height = button_rect.bottom - button_rect.top;
|
| @@ -355,7 +330,7 @@ bool DisconnectWindowWin::SetStrings(const string16& username) {
|
| reinterpret_cast<LPPOINT>(&button_rect), 2);
|
| if (!result && GetLastError() != ERROR_SUCCESS)
|
| return false;
|
| - if (!SetWindowPos(disconnect_button, NULL,
|
| + if (!SetWindowPos(stop_button, NULL,
|
| button_rect.left + label_width_delta, button_rect.top,
|
| button_width + button_width_delta, button_height,
|
| SWP_NOZORDER)) {
|
| @@ -385,9 +360,7 @@ bool DisconnectWindowWin::SetStrings(const string16& username) {
|
| return true;
|
| }
|
|
|
| -scoped_ptr<DisconnectWindow> DisconnectWindow::Create(
|
| - const UiStrings* ui_strings) {
|
| - return scoped_ptr<DisconnectWindow>(new DisconnectWindowWin(ui_strings));
|
| +scoped_ptr<ScreenCaptureNotificationUI> ScreenCaptureNotificationUI::Create() {
|
| + return scoped_ptr<ScreenCaptureNotificationUI>(
|
| + new ScreenCaptureNotificationUIWin());
|
| }
|
| -
|
| -} // namespace remoting
|
|
|