diff options
author | mukai@chromium.org <mukai@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-10-05 23:55:33 +0000 |
---|---|---|
committer | mukai@chromium.org <mukai@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-10-05 23:55:33 +0000 |
commit | c8732855e5ad0cfbc10838fa398145604d24bf6f (patch) | |
tree | 0f02f8390977240ba040de882c4dd9d174d2e37c /ash | |
parent | a657352b779646d4087e8ec46d03fa482ee4fe32 (diff) | |
download | chromium_src-c8732855e5ad0cfbc10838fa398145604d24bf6f.zip chromium_src-c8732855e5ad0cfbc10838fa398145604d24bf6f.tar.gz chromium_src-c8732855e5ad0cfbc10838fa398145604d24bf6f.tar.bz2 |
Adds DisplayErrorDialog to show the error message of the failure of mirroring to the users.
This CL depends on http://codereview.chromium.org/10989084/.
BUG=149061
Review URL: https://chromiumcodereview.appspot.com/10986087
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@160521 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash')
-rw-r--r-- | ash/ash.gyp | 2 | ||||
-rw-r--r-- | ash/ash_strings.grd | 3 | ||||
-rw-r--r-- | ash/display/display_error_dialog.cc | 101 | ||||
-rw-r--r-- | ash/display/display_error_dialog.h | 61 | ||||
-rw-r--r-- | ash/display/output_configurator_animation.cc | 2 |
5 files changed, 169 insertions, 0 deletions
diff --git a/ash/ash.gyp b/ash/ash.gyp index 5b446c3..14fc9a6 100644 --- a/ash/ash.gyp +++ b/ash/ash.gyp @@ -74,6 +74,8 @@ 'desktop_background/desktop_background_widget_controller.h', 'display/display_controller.cc', 'display/display_controller.h', + 'display/display_error_dialog.cc', + 'display/display_error_dialog.h', 'display/mouse_cursor_event_filter.cc', 'display/mouse_cursor_event_filter.h', 'display/multi_display_manager.cc', diff --git a/ash/ash_strings.grd b/ash/ash_strings.grd index a059472..04b433e 100644 --- a/ash/ash_strings.grd +++ b/ash/ash_strings.grd @@ -473,6 +473,9 @@ Press Search or Shift to cancel. <message name="IDS_ASH_MINIMIZE_WINDOW" desc="A help text to show that when the button gets clicked the window gets minimized."> Minimize </message> + <message name="IDS_ASH_DISPLAY_FAILURE_ON_MIRRORING" desc="An error message to show that the system failed to enter the mirroring mode."> + Can't duplicate image on attached monitors. No matching resolution found. + </message> </messages> </release> </grit> diff --git a/ash/display/display_error_dialog.cc b/ash/display/display_error_dialog.cc new file mode 100644 index 0000000..4933cd8 --- /dev/null +++ b/ash/display/display_error_dialog.cc @@ -0,0 +1,101 @@ +// Copyright (c) 2012 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 "ash/display/display_error_dialog.h" + +#include "ash/screen_ash.h" +#include "ash/shell.h" +#include "grit/ash_strings.h" +#include "ui/aura/window.h" +#include "ui/base/l10n/l10n_util.h" +#include "ui/base/ui_base_types.h" +#include "ui/gfx/display.h" +#include "ui/gfx/screen.h" +#include "ui/views/border.h" +#include "ui/views/controls/label.h" +#include "ui/views/widget/widget.h" + +namespace ash { +namespace internal { +namespace { + +// The width of the area to show the error message. +const int kDialogMessageWidthPixel = 300; + +// The margin width from the error message to the edge of the dialog. +const int kDialogMessageMarginWidthPixel = 5; + +DisplayErrorDialog* g_instance = NULL; + +} // namespace + +// static +void DisplayErrorDialog::ShowDialog() { + if (g_instance) { + DCHECK(g_instance->GetWidget()); + g_instance->GetWidget()->StackAtTop(); + g_instance->GetWidget()->Activate(); + return; + } + + const gfx::Display& secondary_display = ash::ScreenAsh::GetSecondaryDisplay(); + + g_instance = new DisplayErrorDialog(); + views::Widget* widget = new views::Widget; + views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); + params.delegate = g_instance; + // Makes |widget| belong to the secondary display. Size and location are + // fixed by CenterWindow() below. + params.bounds = secondary_display.bounds(); + params.keep_on_top = true; + widget->Init(params); + + widget->GetNativeView()->SetName("DisplayErrorDialog"); + widget->CenterWindow(widget->GetRootView()->GetPreferredSize()); + widget->Show(); +} + +DisplayErrorDialog::DisplayErrorDialog() { + Shell::GetInstance()->display_controller()->AddObserver(this); + label_ = new views::Label( + l10n_util::GetStringUTF16(IDS_ASH_DISPLAY_FAILURE_ON_MIRRORING)); + AddChildView(label_); + + label_->SetMultiLine(true); + label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); + label_->set_border(views::Border::CreateEmptyBorder( + kDialogMessageMarginWidthPixel, + kDialogMessageMarginWidthPixel, + kDialogMessageMarginWidthPixel, + kDialogMessageMarginWidthPixel)); + label_->SizeToFit(kDialogMessageWidthPixel); +} + +DisplayErrorDialog::~DisplayErrorDialog() { + Shell::GetInstance()->display_controller()->RemoveObserver(this); + g_instance = NULL; +} + +int DisplayErrorDialog::GetDialogButtons() const { + return ui::DIALOG_BUTTON_OK; +} + +ui::ModalType DisplayErrorDialog::GetModalType() const { + return ui::MODAL_TYPE_NONE; +} + +views::View* DisplayErrorDialog::GetContentsView() { + return this; +} + +gfx::Size DisplayErrorDialog::GetPreferredSize() { + return label_->GetPreferredSize(); +} + +void DisplayErrorDialog::OnDisplayConfigurationChanging() { + GetWidget()->Close(); +} + +} // namespace internal +} // namespace ash diff --git a/ash/display/display_error_dialog.h b/ash/display/display_error_dialog.h new file mode 100644 index 0000000..2fcbf20 --- /dev/null +++ b/ash/display/display_error_dialog.h @@ -0,0 +1,61 @@ +// Copyright (c) 2012 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. + +#ifndef ASH_DISPLAY_DISPLAY_ERROR_DIALOG_H_ +#define ASH_DISPLAY_DISPLAY_ERROR_DIALOG_H_ + +#include "ash/display/display_controller.h" +#include "base/compiler_specific.h" +#include "ui/views/window/dialog_delegate.h" + +namespace aura { +class RootWindow; +} // namespace aura + +namespace gfx { +class Display; +class Size; +} // namespace gfx + +namespace views { +class Label; +} // namespace views + +namespace ash { +namespace internal { + +// Dialog used to show an error messages when unable to change the display +// configuration to mirroring. +class DisplayErrorDialog : public views::DialogDelegateView, + public ash::DisplayController::Observer { + public: + // Shows the error dialog. + static void ShowDialog(); + + private: + DisplayErrorDialog(); + virtual ~DisplayErrorDialog(); + + // views::DialogDelegate overrides: + virtual int GetDialogButtons() const OVERRIDE; + + // views::WidgetDelegate overrides:: + virtual ui::ModalType GetModalType() const OVERRIDE; + virtual views::View* GetContentsView() OVERRIDE; + + // views::View overrides: + virtual gfx::Size GetPreferredSize() OVERRIDE; + + // ash::DisplayController::Observer overrides: + virtual void OnDisplayConfigurationChanging() OVERRIDE; + + views::Label* label_; + + DISALLOW_COPY_AND_ASSIGN(DisplayErrorDialog); +}; + +} // namespace internal +} // namespace ash + +#endif // ASH_DISPLAY_DISPLAY_ERROR_DIALOG_H_ diff --git a/ash/display/output_configurator_animation.cc b/ash/display/output_configurator_animation.cc index 9c19a50..5cd0779 100644 --- a/ash/display/output_configurator_animation.cc +++ b/ash/display/output_configurator_animation.cc @@ -4,6 +4,7 @@ #include "ash/display/output_configurator_animation.h" +#include "ash/display/display_error_dialog.h" #include "ash/shell.h" #include "ash/shell_window_ids.h" #include "base/bind.h" @@ -209,6 +210,7 @@ void OutputConfiguratorAnimation::OnDisplayModeChanged() { void OutputConfiguratorAnimation::OnDisplayModeChangeFailed() { if (!hiding_layers_.empty()) StartFadeInAnimation(); + DisplayErrorDialog::ShowDialog(); } void OutputConfiguratorAnimation::ClearHidingLayers() { |