Chromium Code Reviews| Index: ash/display/display_error_dialog.cc |
| diff --git a/ash/display/display_error_dialog.cc b/ash/display/display_error_dialog.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..4a8471a6360aaefb52e918d88c67173f246a9a4a |
| --- /dev/null |
| +++ b/ash/display/display_error_dialog.cc |
| @@ -0,0 +1,115 @@ |
| +// 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 "grit/ash_strings.h" |
| +#include "ui/aura/display_manager.h" |
| +#include "ui/aura/env.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()->GetNativeWindow()->Focus(); |
| + 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() { |
| + aura::Env::GetInstance()->display_manager()->AddObserver(this); |
| + views::View* container = GetContentsView(); |
| + label_ = new views::Label( |
| + l10n_util::GetStringUTF16(IDS_ASH_DISPLAY_FAILURE_ON_MIRRORING)); |
| + container->AddChildView(label_); |
|
oshima
2012/10/04 20:28:14
I think you should just add label_ to this.
GetCon
Jun Mukai
2012/10/04 20:39:49
Done.
|
| + |
| + label_->SetMultiLine(true); |
| + label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
| + label_->set_border(views::Border::CreateEmptyBorder( |
| + kDialogMessageMarginWidthPixel, |
| + kDialogMessageMarginWidthPixel, |
| + kDialogMessageMarginWidthPixel, |
| + kDialogMessageMarginWidthPixel)); |
| + label_->SizeToFit(kDialogMessageWidthPixel); |
| +} |
| + |
| +DisplayErrorDialog::~DisplayErrorDialog() { |
| + aura::Env::GetInstance()->display_manager()->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(); |
| +} |
| + |
| +void DisplayErrorDialog::OnDisplayBoundsChanged(const gfx::Display& display) { |
| + GetWidget()->Close(); |
| +} |
| + |
| +void DisplayErrorDialog::OnDisplayAdded(const gfx::Display& new_display) { |
| + GetWidget()->Close(); |
| +} |
| + |
| +void DisplayErrorDialog::OnDisplayRemoved(const gfx::Display& old_display) { |
|
oshima
2012/10/04 20:28:14
I believe you don't need these three (OnDisplayBou
Jun Mukai
2012/10/04 20:39:49
You're right... removed.
|
| + GetWidget()->Close(); |
| +} |
| + |
| +} // namespace internal |
| +} // namespace ash |