Index: ash/display/display_error_dialog.cc |
diff --git a/ash/display/display_error_dialog.cc b/ash/display/display_error_dialog.cc |
index 604d86acf6d9d9d4c9017f8cae2d216b45ade1e0..59b74ff927fe39fed04ad8f8a12a1278a04e8072 100644 |
--- a/ash/display/display_error_dialog.cc |
+++ b/ash/display/display_error_dialog.cc |
@@ -27,28 +27,20 @@ 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()->Activate(); |
- return; |
- } |
- |
+DisplayErrorDialog* DisplayErrorDialog::ShowDialog( |
+ chromeos::OutputState new_state) { |
gfx::Screen* screen = Shell::GetScreen(); |
const gfx::Display& target_display = |
(screen->GetNumDisplays() > 1) ? |
ScreenAsh::GetSecondaryDisplay() : screen->GetPrimaryDisplay(); |
- g_instance = new DisplayErrorDialog(); |
+ DisplayErrorDialog* dialog = new DisplayErrorDialog(new_state); |
views::Widget* widget = new views::Widget; |
views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); |
- params.delegate = g_instance; |
+ params.delegate = dialog; |
// Makes |widget| belong to the target display. Size and location are |
// fixed by CenterWindow() below. |
params.bounds = target_display.bounds(); |
@@ -62,12 +54,32 @@ void DisplayErrorDialog::ShowDialog() { |
widget->GetNativeView()->SetName("DisplayErrorDialog"); |
widget->CenterWindow(widget->GetRootView()->GetPreferredSize()); |
widget->Show(); |
+ return dialog; |
} |
-DisplayErrorDialog::DisplayErrorDialog() { |
+void DisplayErrorDialog::UpdateMessageForState( |
+ chromeos::OutputState new_state) { |
+ int message_id = -1; |
+ switch (new_state) { |
+ case chromeos::STATE_DUAL_MIRROR: |
+ message_id = IDS_ASH_DISPLAY_FAILURE_ON_MIRRORING; |
+ break; |
+ case chromeos::STATE_DUAL_PRIMARY_ONLY: |
+ case chromeos::STATE_DUAL_SECONDARY_ONLY: |
+ message_id = IDS_ASH_DISPLAY_FAILURE_ON_EXTENDED; |
+ break; |
+ default: |
+ message_id = IDS_ASH_DISPLAY_FAILURE_UNKNOWN; |
oshima
2013/02/14 00:01:50
Can you document when this can happen?
Jun Mukai
2013/02/14 00:54:03
Done.
|
+ } |
+ label_->SetText(l10n_util::GetStringUTF16(message_id)); |
+ label_->SizeToFit(kDialogMessageWidthPixel); |
+ Layout(); |
+ SchedulePaint(); |
+} |
+ |
+DisplayErrorDialog::DisplayErrorDialog(chromeos::OutputState new_state) { |
Shell::GetInstance()->display_controller()->AddObserver(this); |
- label_ = new views::Label( |
- l10n_util::GetStringUTF16(IDS_ASH_DISPLAY_FAILURE_ON_MIRRORING)); |
+ label_ = new views::Label(); |
AddChildView(label_); |
label_->SetMultiLine(true); |
@@ -77,12 +89,12 @@ DisplayErrorDialog::DisplayErrorDialog() { |
kDialogMessageMarginWidthPixel, |
kDialogMessageMarginWidthPixel, |
kDialogMessageMarginWidthPixel)); |
- label_->SizeToFit(kDialogMessageWidthPixel); |
+ |
+ UpdateMessageForState(new_state); |
} |
DisplayErrorDialog::~DisplayErrorDialog() { |
Shell::GetInstance()->display_controller()->RemoveObserver(this); |
- g_instance = NULL; |
} |
int DisplayErrorDialog::GetDialogButtons() const { |
@@ -101,9 +113,30 @@ void DisplayErrorDialog::OnDisplayConfigurationChanging() { |
GetWidget()->Close(); |
} |
-// static |
-DisplayErrorDialog* DisplayErrorDialog::GetInstanceForTest() { |
- return g_instance; |
+DisplayErrorObserver::DisplayErrorObserver() |
+ : dialog_(NULL) { |
+} |
+ |
+DisplayErrorObserver::~DisplayErrorObserver() { |
+} |
+ |
+void DisplayErrorObserver::OnDisplayModeChangeFailed( |
+ chromeos::OutputState new_state) { |
+ if (dialog_) { |
+ DCHECK(dialog_->GetWidget()); |
+ dialog_->UpdateMessageForState(new_state); |
+ dialog_->GetWidget()->StackAtTop(); |
+ dialog_->GetWidget()->Activate(); |
+ } else { |
+ dialog_ = DisplayErrorDialog::ShowDialog(new_state); |
+ } |
+} |
+ |
+void DisplayErrorObserver::OnWidgetClosing(views::Widget* widget) { |
+ if (dialog_ && dialog_->GetWidget() == widget) { |
oshima
2013/02/14 00:01:50
can dialog_->GetWidget() != widget happen? do you
Jun Mukai
2013/02/14 00:54:03
Done.
|
+ widget->RemoveObserver(this); |
+ dialog_ = NULL; |
+ } |
} |
} // namespace internal |