OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ash/display/display_error_dialog.h" | 5 #include "ash/display/display_error_dialog.h" |
6 | 6 |
7 #include "ash/screen_ash.h" | 7 #include "ash/screen_ash.h" |
8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
9 #include "grit/ash_strings.h" | 9 #include "grit/ash_strings.h" |
| 10 #include "ui/aura/root_window.h" |
10 #include "ui/aura/window.h" | 11 #include "ui/aura/window.h" |
11 #include "ui/base/l10n/l10n_util.h" | 12 #include "ui/base/l10n/l10n_util.h" |
12 #include "ui/base/ui_base_types.h" | 13 #include "ui/base/ui_base_types.h" |
13 #include "ui/gfx/display.h" | 14 #include "ui/gfx/display.h" |
14 #include "ui/gfx/screen.h" | 15 #include "ui/gfx/screen.h" |
15 #include "ui/views/border.h" | 16 #include "ui/views/border.h" |
16 #include "ui/views/controls/label.h" | 17 #include "ui/views/controls/label.h" |
17 #include "ui/views/widget/widget.h" | 18 #include "ui/views/widget/widget.h" |
18 | 19 |
19 namespace ash { | 20 namespace ash { |
(...skipping 12 matching lines...) Expand all Loading... |
32 | 33 |
33 // static | 34 // static |
34 void DisplayErrorDialog::ShowDialog() { | 35 void DisplayErrorDialog::ShowDialog() { |
35 if (g_instance) { | 36 if (g_instance) { |
36 DCHECK(g_instance->GetWidget()); | 37 DCHECK(g_instance->GetWidget()); |
37 g_instance->GetWidget()->StackAtTop(); | 38 g_instance->GetWidget()->StackAtTop(); |
38 g_instance->GetWidget()->Activate(); | 39 g_instance->GetWidget()->Activate(); |
39 return; | 40 return; |
40 } | 41 } |
41 | 42 |
42 const gfx::Display& secondary_display = ash::ScreenAsh::GetSecondaryDisplay(); | 43 gfx::Screen* screen = Shell::GetScreen(); |
| 44 const gfx::Display& target_display = |
| 45 (screen->GetNumDisplays() > 1) ? |
| 46 ScreenAsh::GetSecondaryDisplay() : screen->GetPrimaryDisplay(); |
43 | 47 |
44 g_instance = new DisplayErrorDialog(); | 48 g_instance = new DisplayErrorDialog(); |
45 views::Widget* widget = new views::Widget; | 49 views::Widget* widget = new views::Widget; |
46 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); | 50 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); |
47 params.delegate = g_instance; | 51 params.delegate = g_instance; |
48 // Makes |widget| belong to the secondary display. Size and location are | 52 // Makes |widget| belong to the target display. Size and location are |
49 // fixed by CenterWindow() below. | 53 // fixed by CenterWindow() below. |
50 params.bounds = secondary_display.bounds(); | 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()); |
51 params.keep_on_top = true; | 59 params.keep_on_top = true; |
52 widget->Init(params); | 60 widget->Init(params); |
53 | 61 |
54 widget->GetNativeView()->SetName("DisplayErrorDialog"); | 62 widget->GetNativeView()->SetName("DisplayErrorDialog"); |
55 widget->CenterWindow(widget->GetRootView()->GetPreferredSize()); | 63 widget->CenterWindow(widget->GetRootView()->GetPreferredSize()); |
56 widget->Show(); | 64 widget->Show(); |
57 } | 65 } |
58 | 66 |
59 DisplayErrorDialog::DisplayErrorDialog() { | 67 DisplayErrorDialog::DisplayErrorDialog() { |
60 Shell::GetInstance()->display_controller()->AddObserver(this); | 68 Shell::GetInstance()->display_controller()->AddObserver(this); |
(...skipping 25 matching lines...) Expand all Loading... |
86 } | 94 } |
87 | 95 |
88 gfx::Size DisplayErrorDialog::GetPreferredSize() { | 96 gfx::Size DisplayErrorDialog::GetPreferredSize() { |
89 return label_->GetPreferredSize(); | 97 return label_->GetPreferredSize(); |
90 } | 98 } |
91 | 99 |
92 void DisplayErrorDialog::OnDisplayConfigurationChanging() { | 100 void DisplayErrorDialog::OnDisplayConfigurationChanging() { |
93 GetWidget()->Close(); | 101 GetWidget()->Close(); |
94 } | 102 } |
95 | 103 |
| 104 // static |
| 105 DisplayErrorDialog* DisplayErrorDialog::GetInstanceForTest() { |
| 106 return g_instance; |
| 107 } |
| 108 |
96 } // namespace internal | 109 } // namespace internal |
97 } // namespace ash | 110 } // namespace ash |
OLD | NEW |