Revert 185456 which broke win aura build.
[chromium-blink-merge.git] / ash / display / display_error_dialog.cc
blob604d86acf6d9d9d4c9017f8cae2d216b45ade1e0
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
3 // found in the LICENSE file.
5 #include "ash/display/display_error_dialog.h"
7 #include "ash/screen_ash.h"
8 #include "ash/shell.h"
9 #include "grit/ash_strings.h"
10 #include "ui/aura/root_window.h"
11 #include "ui/aura/window.h"
12 #include "ui/base/l10n/l10n_util.h"
13 #include "ui/base/ui_base_types.h"
14 #include "ui/gfx/display.h"
15 #include "ui/gfx/screen.h"
16 #include "ui/views/border.h"
17 #include "ui/views/controls/label.h"
18 #include "ui/views/widget/widget.h"
20 namespace ash {
21 namespace internal {
22 namespace {
24 // The width of the area to show the error message.
25 const int kDialogMessageWidthPixel = 300;
27 // The margin width from the error message to the edge of the dialog.
28 const int kDialogMessageMarginWidthPixel = 5;
30 DisplayErrorDialog* g_instance = NULL;
32 } // namespace
34 // static
35 void DisplayErrorDialog::ShowDialog() {
36 if (g_instance) {
37 DCHECK(g_instance->GetWidget());
38 g_instance->GetWidget()->StackAtTop();
39 g_instance->GetWidget()->Activate();
40 return;
43 gfx::Screen* screen = Shell::GetScreen();
44 const gfx::Display& target_display =
45 (screen->GetNumDisplays() > 1) ?
46 ScreenAsh::GetSecondaryDisplay() : screen->GetPrimaryDisplay();
48 g_instance = new DisplayErrorDialog();
49 views::Widget* widget = new views::Widget;
50 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
51 params.delegate = g_instance;
52 // Makes |widget| belong to the target display. Size and location are
53 // fixed by CenterWindow() below.
54 params.bounds = target_display.bounds();
55 DisplayController* display_controller =
56 Shell::GetInstance()->display_controller();
57 params.context =
58 display_controller->GetRootWindowForDisplayId(target_display.id());
59 params.keep_on_top = true;
60 widget->Init(params);
62 widget->GetNativeView()->SetName("DisplayErrorDialog");
63 widget->CenterWindow(widget->GetRootView()->GetPreferredSize());
64 widget->Show();
67 DisplayErrorDialog::DisplayErrorDialog() {
68 Shell::GetInstance()->display_controller()->AddObserver(this);
69 label_ = new views::Label(
70 l10n_util::GetStringUTF16(IDS_ASH_DISPLAY_FAILURE_ON_MIRRORING));
71 AddChildView(label_);
73 label_->SetMultiLine(true);
74 label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
75 label_->set_border(views::Border::CreateEmptyBorder(
76 kDialogMessageMarginWidthPixel,
77 kDialogMessageMarginWidthPixel,
78 kDialogMessageMarginWidthPixel,
79 kDialogMessageMarginWidthPixel));
80 label_->SizeToFit(kDialogMessageWidthPixel);
83 DisplayErrorDialog::~DisplayErrorDialog() {
84 Shell::GetInstance()->display_controller()->RemoveObserver(this);
85 g_instance = NULL;
88 int DisplayErrorDialog::GetDialogButtons() const {
89 return ui::DIALOG_BUTTON_OK;
92 ui::ModalType DisplayErrorDialog::GetModalType() const {
93 return ui::MODAL_TYPE_NONE;
96 gfx::Size DisplayErrorDialog::GetPreferredSize() {
97 return label_->GetPreferredSize();
100 void DisplayErrorDialog::OnDisplayConfigurationChanging() {
101 GetWidget()->Close();
104 // static
105 DisplayErrorDialog* DisplayErrorDialog::GetInstanceForTest() {
106 return g_instance;
109 } // namespace internal
110 } // namespace ash