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

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

Issue 662763002: Support modal windows (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git/+/master
Patch Set: fix leaks 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"
18 19
19 namespace athena { 20 namespace athena {
20 namespace { 21 namespace {
21 22
22 // The amount of time that the power button must be held to shut down the 23 // The amount of time that the power button must be held to shut down the
23 // device after shutdown dialog is shown. 24 // device after shutdown dialog is shown.
24 const int kShutdownTimeoutMs = 4000; 25 const int kShutdownTimeoutMs = 4000;
25 26
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
26 } // namespace 51 } // namespace
27 52
28 ShutdownDialog::ShutdownDialog(aura::Window* dialog_container) 53 ShutdownDialog::ShutdownDialog() : state_(STATE_OTHER) {
29 : warning_message_container_(dialog_container), state_(STATE_OTHER) {
30 InputManager::Get()->AddPowerButtonObserver(this); 54 InputManager::Get()->AddPowerButtonObserver(this);
31 } 55 }
32 56
33 ShutdownDialog::~ShutdownDialog() { 57 ShutdownDialog::~ShutdownDialog() {
34 InputManager::Get()->RemovePowerButtonObserver(this); 58 InputManager::Get()->RemovePowerButtonObserver(this);
35 } 59 }
36 60
37 void ShutdownDialog::ShowShutdownWarningDialog() { 61 void ShutdownDialog::ShowShutdownWarningDialog() {
38 state_ = STATE_SHUTDOWN_WARNING_VISIBLE; 62 state_ = STATE_SHUTDOWN_WARNING_VISIBLE;
39 63
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
47 views::Label* label = 64 views::Label* label =
48 new views::Label(l10n_util::GetStringUTF16(IDS_ATHENA_SHUTDOWN_WARNING)); 65 new views::Label(l10n_util::GetStringUTF16(IDS_ATHENA_SHUTDOWN_WARNING));
49 label->SetBackgroundColor(SK_ColorWHITE); 66 label->SetBackgroundColor(SK_ColorWHITE);
50 label->SetFontList(gfx::FontList().DeriveWithStyle(gfx::Font::BOLD)); 67 label->SetFontList(gfx::FontList().DeriveWithStyle(gfx::Font::BOLD));
51 68
52 views::View* container = new views::View; 69 views::View* container = new views::View;
53 container->AddChildView(label); 70 container->AddChildView(label);
54 71
55 const int kBorderSpacing = 50; 72 const int kBorderSpacing = 50;
56 container->SetLayoutManager(new views::BoxLayout( 73 container->SetLayoutManager(new views::BoxLayout(
57 views::BoxLayout::kHorizontal, kBorderSpacing, kBorderSpacing, 0)); 74 views::BoxLayout::kHorizontal, kBorderSpacing, kBorderSpacing, 0));
58 container->set_background( 75 container->set_background(
59 views::Background::CreateSolidBackground(SK_ColorWHITE)); 76 views::Background::CreateSolidBackground(SK_ColorWHITE));
60 container->SetBorder(views::Border::CreateSolidBorder(1, SK_ColorBLACK)); 77 container->SetBorder(views::Border::CreateSolidBorder(1, SK_ColorBLACK));
61 78
62 shutdown_warning_message_->SetContentsView(container); 79 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP);
80 params.delegate = new ModalWidgetDelegate(container);
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();
63 shutdown_warning_message_->CenterWindow(container->GetPreferredSize()); 89 shutdown_warning_message_->CenterWindow(container->GetPreferredSize());
64 shutdown_warning_message_->Show(); 90
65 timer_.Start(FROM_HERE, 91 timer_.Start(FROM_HERE,
66 base::TimeDelta::FromMilliseconds(kShutdownTimeoutMs), 92 base::TimeDelta::FromMilliseconds(kShutdownTimeoutMs),
67 this, 93 this,
68 &ShutdownDialog::Shutdown); 94 &ShutdownDialog::Shutdown);
69 } 95 }
70 96
71 void ShutdownDialog::Shutdown() { 97 void ShutdownDialog::Shutdown() {
72 state_ = STATE_SHUTDOWN_REQUESTED; 98 state_ = STATE_SHUTDOWN_REQUESTED;
73 chromeos::DBusThreadManager::Get() 99 chromeos::DBusThreadManager::Get()
74 ->GetPowerManagerClient() 100 ->GetPowerManagerClient()
(...skipping 19 matching lines...) Expand all
94 ->RequestSuspend(); 120 ->RequestSuspend();
95 } 121 }
96 state_ = STATE_OTHER; 122 state_ = STATE_OTHER;
97 timer_.Stop(); 123 timer_.Stop();
98 shutdown_warning_message_.reset(); 124 shutdown_warning_message_.reset();
99 break; 125 break;
100 } 126 }
101 } 127 }
102 128
103 } // namespace athena 129 } // 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