Chromium Code Reviews| 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/display_manager.h" | |
| 10 #include "ui/aura/env.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" | |
| 19 | |
| 20 namespace ash { | |
| 21 namespace internal { | |
| 22 namespace { | |
| 23 | |
| 24 // The width of the area to show the error message. | |
| 25 const int kDialogMessageWidthPixel = 300; | |
| 26 | |
| 27 // The margin width from the error message to the edge of the dialog. | |
| 28 const int kDialogMessageMarginWidthPixel = 5; | |
| 29 | |
| 30 DisplayErrorDialog* g_instance = NULL; | |
| 31 | |
| 32 } // namespace | |
| 33 | |
| 34 // static | |
| 35 void DisplayErrorDialog::ShowDialog() { | |
| 36 if (g_instance) { | |
| 37 DCHECK(g_instance->GetWidget()); | |
| 38 g_instance->GetWidget()->StackAtTop(); | |
| 39 g_instance->GetWidget()->GetNativeWindow()->Focus(); | |
| 40 return; | |
| 41 } | |
| 42 | |
| 43 const gfx::Display& secondary_display = ash::ScreenAsh::GetSecondaryDisplay(); | |
| 44 | |
| 45 g_instance = new DisplayErrorDialog(); | |
| 46 views::Widget* widget = new views::Widget; | |
| 47 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); | |
| 48 params.delegate = g_instance; | |
| 49 // Makes |widget| belong to the secondary display. Size and location are | |
| 50 // fixed by CenterWindow() below. | |
| 51 params.bounds = secondary_display.bounds(); | |
| 52 params.keep_on_top = true; | |
| 53 widget->Init(params); | |
| 54 | |
| 55 widget->GetNativeView()->SetName("DisplayErrorDialog"); | |
| 56 widget->CenterWindow(widget->GetRootView()->GetPreferredSize()); | |
| 57 widget->Show(); | |
| 58 } | |
| 59 | |
| 60 DisplayErrorDialog::DisplayErrorDialog() { | |
| 61 aura::Env::GetInstance()->display_manager()->AddObserver(this); | |
| 62 views::View* container = GetContentsView(); | |
| 63 label_ = new views::Label( | |
| 64 l10n_util::GetStringUTF16(IDS_ASH_DISPLAY_FAILURE_ON_MIRRORING)); | |
| 65 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.
| |
| 66 | |
| 67 label_->SetMultiLine(true); | |
| 68 label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | |
| 69 label_->set_border(views::Border::CreateEmptyBorder( | |
| 70 kDialogMessageMarginWidthPixel, | |
| 71 kDialogMessageMarginWidthPixel, | |
| 72 kDialogMessageMarginWidthPixel, | |
| 73 kDialogMessageMarginWidthPixel)); | |
| 74 label_->SizeToFit(kDialogMessageWidthPixel); | |
| 75 } | |
| 76 | |
| 77 DisplayErrorDialog::~DisplayErrorDialog() { | |
| 78 aura::Env::GetInstance()->display_manager()->RemoveObserver(this); | |
| 79 g_instance = NULL; | |
| 80 } | |
| 81 | |
| 82 int DisplayErrorDialog::GetDialogButtons() const { | |
| 83 return ui::DIALOG_BUTTON_OK; | |
| 84 } | |
| 85 | |
| 86 ui::ModalType DisplayErrorDialog::GetModalType() const { | |
| 87 return ui::MODAL_TYPE_NONE; | |
| 88 } | |
| 89 | |
| 90 views::View* DisplayErrorDialog::GetContentsView() { | |
| 91 return this; | |
| 92 } | |
| 93 | |
| 94 gfx::Size DisplayErrorDialog::GetPreferredSize() { | |
| 95 return label_->GetPreferredSize(); | |
| 96 } | |
| 97 | |
| 98 void DisplayErrorDialog::OnDisplayConfigurationChanging() { | |
| 99 GetWidget()->Close(); | |
| 100 } | |
| 101 | |
| 102 void DisplayErrorDialog::OnDisplayBoundsChanged(const gfx::Display& display) { | |
| 103 GetWidget()->Close(); | |
| 104 } | |
| 105 | |
| 106 void DisplayErrorDialog::OnDisplayAdded(const gfx::Display& new_display) { | |
| 107 GetWidget()->Close(); | |
| 108 } | |
| 109 | |
| 110 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.
| |
| 111 GetWidget()->Close(); | |
| 112 } | |
| 113 | |
| 114 } // namespace internal | |
| 115 } // namespace ash | |
| OLD | NEW |