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