Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(30)

Side by Side Diff: athena/system/shutdown_dialog.cc

Issue 665803003: Revert of Support modal windows (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git/+/master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « athena/system/shutdown_dialog.h ('k') | athena/system/status_icon_container_view.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "athena/system/shutdown_dialog.h" 5 #include "athena/system/shutdown_dialog.h"
6 6
7 #include "athena/screen/public/screen_manager.h" 7 #include "athena/screen/public/screen_manager.h"
8 #include "athena/strings/grit/athena_strings.h" 8 #include "athena/strings/grit/athena_strings.h"
9 #include "chromeos/dbus/dbus_thread_manager.h" 9 #include "chromeos/dbus/dbus_thread_manager.h"
10 #include "chromeos/dbus/power_manager_client.h" 10 #include "chromeos/dbus/power_manager_client.h"
11 #include "ui/base/l10n/l10n_util.h" 11 #include "ui/base/l10n/l10n_util.h"
12 #include "ui/gfx/font_list.h" 12 #include "ui/gfx/font_list.h"
13 #include "ui/views/background.h" 13 #include "ui/views/background.h"
14 #include "ui/views/border.h" 14 #include "ui/views/border.h"
15 #include "ui/views/controls/label.h" 15 #include "ui/views/controls/label.h"
16 #include "ui/views/layout/box_layout.h" 16 #include "ui/views/layout/box_layout.h"
17 #include "ui/views/widget/widget.h" 17 #include "ui/views/widget/widget.h"
18 #include "ui/views/window/dialog_delegate.h"
19 18
20 namespace athena { 19 namespace athena {
21 namespace { 20 namespace {
22 21
23 // The amount of time that the power button must be held to shut down the 22 // The amount of time that the power button must be held to shut down the
24 // device after shutdown dialog is shown. 23 // device after shutdown dialog is shown.
25 const int kShutdownTimeoutMs = 4000; 24 const int kShutdownTimeoutMs = 4000;
26 25
27 class ModalWidgetDelegate : public views::WidgetDelegate {
28 public:
29 explicit ModalWidgetDelegate(views::View* contents_view)
30 : contents_view_(contents_view) {}
31 virtual ~ModalWidgetDelegate() {}
32
33 // Overridden from WidgetDelegate:
34 virtual views::Widget* GetWidget() override {
35 return contents_view_->GetWidget();
36 }
37 virtual const views::Widget* GetWidget() const override {
38 return contents_view_->GetWidget();
39 }
40 virtual views::View* GetContentsView() override { return contents_view_; }
41 virtual ui::ModalType GetModalType() const override {
42 return ui::MODAL_TYPE_SYSTEM;
43 }
44
45 private:
46 views::View* contents_view_;
47
48 DISALLOW_COPY_AND_ASSIGN(ModalWidgetDelegate);
49 };
50
51 } // namespace 26 } // namespace
52 27
53 ShutdownDialog::ShutdownDialog() : state_(STATE_OTHER) { 28 ShutdownDialog::ShutdownDialog(aura::Window* dialog_container)
29 : warning_message_container_(dialog_container), state_(STATE_OTHER) {
54 InputManager::Get()->AddPowerButtonObserver(this); 30 InputManager::Get()->AddPowerButtonObserver(this);
55 } 31 }
56 32
57 ShutdownDialog::~ShutdownDialog() { 33 ShutdownDialog::~ShutdownDialog() {
58 InputManager::Get()->RemovePowerButtonObserver(this); 34 InputManager::Get()->RemovePowerButtonObserver(this);
59 } 35 }
60 36
61 void ShutdownDialog::ShowShutdownWarningDialog() { 37 void ShutdownDialog::ShowShutdownWarningDialog() {
62 state_ = STATE_SHUTDOWN_WARNING_VISIBLE; 38 state_ = STATE_SHUTDOWN_WARNING_VISIBLE;
63 39
40 shutdown_warning_message_.reset(new views::Widget);
41
42 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP);
43 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
44 params.parent = warning_message_container_;
45 shutdown_warning_message_->Init(params);
46
64 views::Label* label = 47 views::Label* label =
65 new views::Label(l10n_util::GetStringUTF16(IDS_ATHENA_SHUTDOWN_WARNING)); 48 new views::Label(l10n_util::GetStringUTF16(IDS_ATHENA_SHUTDOWN_WARNING));
66 label->SetBackgroundColor(SK_ColorWHITE); 49 label->SetBackgroundColor(SK_ColorWHITE);
67 label->SetFontList(gfx::FontList().DeriveWithStyle(gfx::Font::BOLD)); 50 label->SetFontList(gfx::FontList().DeriveWithStyle(gfx::Font::BOLD));
68 51
69 views::View* container = new views::View; 52 views::View* container = new views::View;
70 container->AddChildView(label); 53 container->AddChildView(label);
71 54
72 const int kBorderSpacing = 50; 55 const int kBorderSpacing = 50;
73 container->SetLayoutManager(new views::BoxLayout( 56 container->SetLayoutManager(new views::BoxLayout(
74 views::BoxLayout::kHorizontal, kBorderSpacing, kBorderSpacing, 0)); 57 views::BoxLayout::kHorizontal, kBorderSpacing, kBorderSpacing, 0));
75 container->set_background( 58 container->set_background(
76 views::Background::CreateSolidBackground(SK_ColorWHITE)); 59 views::Background::CreateSolidBackground(SK_ColorWHITE));
77 container->SetBorder(views::Border::CreateSolidBorder(1, SK_ColorBLACK)); 60 container->SetBorder(views::Border::CreateSolidBorder(1, SK_ColorBLACK));
78 61
79 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); 62 shutdown_warning_message_->SetContentsView(container);
80 params.delegate = new ModalWidgetDelegate(container); 63 shutdown_warning_message_->CenterWindow(container->GetPreferredSize());
81 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
82 params.context = ScreenManager::Get()->GetContext();
83 // Use top most modal container.
84 params.keep_on_top = true;
85
86 shutdown_warning_message_.reset(new views::Widget);
87 shutdown_warning_message_->Init(params);
88 shutdown_warning_message_->Show(); 64 shutdown_warning_message_->Show();
89 shutdown_warning_message_->CenterWindow(container->GetPreferredSize());
90
91 timer_.Start(FROM_HERE, 65 timer_.Start(FROM_HERE,
92 base::TimeDelta::FromMilliseconds(kShutdownTimeoutMs), 66 base::TimeDelta::FromMilliseconds(kShutdownTimeoutMs),
93 this, 67 this,
94 &ShutdownDialog::Shutdown); 68 &ShutdownDialog::Shutdown);
95 } 69 }
96 70
97 void ShutdownDialog::Shutdown() { 71 void ShutdownDialog::Shutdown() {
98 state_ = STATE_SHUTDOWN_REQUESTED; 72 state_ = STATE_SHUTDOWN_REQUESTED;
99 chromeos::DBusThreadManager::Get() 73 chromeos::DBusThreadManager::Get()
100 ->GetPowerManagerClient() 74 ->GetPowerManagerClient()
(...skipping 19 matching lines...) Expand all
120 ->RequestSuspend(); 94 ->RequestSuspend();
121 } 95 }
122 state_ = STATE_OTHER; 96 state_ = STATE_OTHER;
123 timer_.Stop(); 97 timer_.Stop();
124 shutdown_warning_message_.reset(); 98 shutdown_warning_message_.reset();
125 break; 99 break;
126 } 100 }
127 } 101 }
128 102
129 } // namespace athena 103 } // namespace athena
OLDNEW
« no previous file with comments | « athena/system/shutdown_dialog.h ('k') | athena/system/status_icon_container_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698