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

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

Issue 863033002: Delete athena/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "athena/system/shutdown_dialog.h"
6
7 #include "athena/screen/public/screen_manager.h"
8 #include "athena/strings/grit/athena_strings.h"
9 #include "chromeos/dbus/dbus_thread_manager.h"
10 #include "chromeos/dbus/power_manager_client.h"
11 #include "ui/base/l10n/l10n_util.h"
12 #include "ui/gfx/font_list.h"
13 #include "ui/views/background.h"
14 #include "ui/views/border.h"
15 #include "ui/views/controls/label.h"
16 #include "ui/views/layout/box_layout.h"
17 #include "ui/views/widget/widget.h"
18 #include "ui/views/window/dialog_delegate.h"
19
20 namespace athena {
21 namespace {
22
23 // The amount of time that the power button must be held to shut down the
24 // device after shutdown dialog is shown.
25 const int kShutdownTimeoutMs = 4000;
26
27 class ModalWidgetDelegate : public views::WidgetDelegate {
28 public:
29 explicit ModalWidgetDelegate(views::View* contents_view)
30 : contents_view_(contents_view) {}
31 ~ModalWidgetDelegate() override {}
32
33 // Overridden from WidgetDelegate:
34 void DeleteDelegate() override { delete this; }
35 views::Widget* GetWidget() override { return contents_view_->GetWidget(); }
36 const views::Widget* GetWidget() const override {
37 return contents_view_->GetWidget();
38 }
39 views::View* GetContentsView() override { return contents_view_; }
40 ui::ModalType GetModalType() const override { return ui::MODAL_TYPE_SYSTEM; }
41
42 private:
43 views::View* contents_view_;
44
45 DISALLOW_COPY_AND_ASSIGN(ModalWidgetDelegate);
46 };
47
48 } // namespace
49
50 ShutdownDialog::ShutdownDialog() : state_(STATE_OTHER) {
51 InputManager::Get()->AddPowerButtonObserver(this);
52 }
53
54 ShutdownDialog::~ShutdownDialog() {
55 InputManager::Get()->RemovePowerButtonObserver(this);
56 }
57
58 void ShutdownDialog::ShowShutdownWarningDialog() {
59 state_ = STATE_SHUTDOWN_WARNING_VISIBLE;
60
61 views::Label* label =
62 new views::Label(l10n_util::GetStringUTF16(IDS_ATHENA_SHUTDOWN_WARNING));
63 label->SetBackgroundColor(SK_ColorWHITE);
64 label->SetFontList(gfx::FontList().DeriveWithStyle(gfx::Font::BOLD));
65
66 views::View* container = new views::View;
67 container->AddChildView(label);
68
69 const int kBorderSpacing = 50;
70 container->SetLayoutManager(new views::BoxLayout(
71 views::BoxLayout::kHorizontal, kBorderSpacing, kBorderSpacing, 0));
72 container->set_background(
73 views::Background::CreateSolidBackground(SK_ColorWHITE));
74 container->SetBorder(views::Border::CreateSolidBorder(1, SK_ColorBLACK));
75
76 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP);
77 params.delegate = new ModalWidgetDelegate(container);
78 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
79 params.context = ScreenManager::Get()->GetContext();
80 // Use top most modal container.
81 params.keep_on_top = true;
82
83 shutdown_warning_message_.reset(new views::Widget);
84 shutdown_warning_message_->Init(params);
85 shutdown_warning_message_->Show();
86 shutdown_warning_message_->CenterWindow(container->GetPreferredSize());
87
88 timer_.Start(FROM_HERE,
89 base::TimeDelta::FromMilliseconds(kShutdownTimeoutMs),
90 this,
91 &ShutdownDialog::Shutdown);
92 }
93
94 void ShutdownDialog::Shutdown() {
95 state_ = STATE_SHUTDOWN_REQUESTED;
96 chromeos::DBusThreadManager::Get()
97 ->GetPowerManagerClient()
98 ->RequestShutdown();
99 }
100
101 void ShutdownDialog::OnPowerButtonStateChanged(
102 PowerButtonObserver::State state) {
103 if (state_ == STATE_SHUTDOWN_REQUESTED)
104 return;
105
106 switch (state) {
107 case PRESSED:
108 state_ = STATE_SUSPEND_ON_RELEASE;
109 break;
110 case LONG_PRESSED:
111 ShowShutdownWarningDialog();
112 break;
113 case RELEASED:
114 if (state_ == STATE_SUSPEND_ON_RELEASE) {
115 chromeos::DBusThreadManager::Get()
116 ->GetPowerManagerClient()
117 ->RequestSuspend();
118 }
119 state_ = STATE_OTHER;
120 timer_.Stop();
121 shutdown_warning_message_.reset();
122 break;
123 }
124 }
125
126 } // 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