OLD | NEW |
---|---|
(Empty) | |
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. | |
4 | |
5 #include "ash/display/display_error_dialog.h" | |
6 | |
7 #include "ash/screen_ash.h" | |
8 #include "ash/shell.h" | |
9 #include "grit/ash_strings.h" | |
10 #include "ui/aura/window.h" | |
11 #include "ui/base/l10n/l10n_util.h" | |
12 #include "ui/base/ui_base_types.h" | |
13 #include "ui/gfx/display.h" | |
14 #include "ui/gfx/screen.h" | |
15 #include "ui/views/border.h" | |
16 #include "ui/views/controls/label.h" | |
17 #include "ui/views/widget/widget.h" | |
18 | |
19 namespace ash { | |
20 namespace internal { | |
21 namespace { | |
22 | |
23 // The width of the area to show the error message. | |
24 const int kDialogMessageWidthPixel = 300; | |
25 | |
26 // The margin width from the error message to the edge of the dialog. | |
27 const int kDialogMessageMarginWidthPixel = 5; | |
28 | |
29 DisplayErrorDialog* g_instance = NULL; | |
30 | |
31 } // namespace | |
32 | |
33 // static | |
34 void DisplayErrorDialog::ShowDialog() { | |
35 if (g_instance) { | |
36 DCHECK(g_instance->GetWidget()); | |
37 g_instance->GetWidget()->StackAtTop(); | |
38 g_instance->GetWidget()->GetNativeWindow()->Focus(); | |
sky
2012/10/05 15:26:15
g_instance->GetWidget()->Activate();
Jun Mukai
2012/10/05 20:30:50
Done.
| |
39 return; | |
40 } | |
41 | |
42 const gfx::Display& secondary_display = ash::ScreenAsh::GetSecondaryDisplay(); | |
43 | |
44 g_instance = new DisplayErrorDialog(); | |
45 views::Widget* widget = new views::Widget; | |
46 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); | |
47 params.delegate = g_instance; | |
48 // Makes |widget| belong to the secondary display. Size and location are | |
49 // fixed by CenterWindow() below. | |
50 params.bounds = secondary_display.bounds(); | |
51 params.keep_on_top = true; | |
52 widget->Init(params); | |
53 | |
54 widget->GetNativeView()->SetName("DisplayErrorDialog"); | |
55 widget->CenterWindow(widget->GetRootView()->GetPreferredSize()); | |
56 widget->Show(); | |
57 } | |
58 | |
59 DisplayErrorDialog::DisplayErrorDialog() { | |
60 Shell::GetInstance()->display_controller()->AddObserver(this); | |
61 label_ = new views::Label( | |
62 l10n_util::GetStringUTF16(IDS_ASH_DISPLAY_FAILURE_ON_MIRRORING)); | |
63 AddChildView(label_); | |
64 | |
65 label_->SetMultiLine(true); | |
66 label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | |
67 label_->set_border(views::Border::CreateEmptyBorder( | |
68 kDialogMessageMarginWidthPixel, | |
69 kDialogMessageMarginWidthPixel, | |
70 kDialogMessageMarginWidthPixel, | |
71 kDialogMessageMarginWidthPixel)); | |
72 label_->SizeToFit(kDialogMessageWidthPixel); | |
73 } | |
74 | |
75 DisplayErrorDialog::~DisplayErrorDialog() { | |
76 Shell::GetInstance()->display_controller()->RemoveObserver(this); | |
77 g_instance = NULL; | |
78 } | |
79 | |
80 int DisplayErrorDialog::GetDialogButtons() const { | |
81 return ui::DIALOG_BUTTON_OK; | |
82 } | |
83 | |
84 ui::ModalType DisplayErrorDialog::GetModalType() const { | |
85 return ui::MODAL_TYPE_NONE; | |
86 } | |
87 | |
88 views::View* DisplayErrorDialog::GetContentsView() { | |
89 return this; | |
90 } | |
91 | |
92 gfx::Size DisplayErrorDialog::GetPreferredSize() { | |
93 return label_->GetPreferredSize(); | |
94 } | |
95 | |
96 void DisplayErrorDialog::OnDisplayConfigurationChanging() { | |
97 GetWidget()->Close(); | |
98 } | |
99 | |
100 } // namespace internal | |
101 } // namespace ash | |
OLD | NEW |