OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2013 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 "ash/system/logout_button/logout_confirmation_dialog_view.h" | |
6 | |
7 #include "ash/shell.h" | |
8 #include "ash/system/logout_button/logout_button_tray.h" | |
9 #include "ash/system/tray/system_tray_delegate.h" | |
10 #include "base/strings/string_number_conversions.h" | |
bartfab (slow)
2013/10/24 13:11:02
This is not used anywhere.
binjin
2013/10/25 13:03:10
Done.
| |
11 #include "grit/ash_strings.h" | |
12 #include "grit/ui_strings.h" | |
13 #include "ui/aura/root_window.h" | |
14 #include "ui/base/l10n/l10n_util.h" | |
15 #include "ui/base/l10n/time_format.h" | |
16 #include "ui/base/resource/resource_bundle.h" | |
17 #include "ui/views/controls/label.h" | |
18 #include "ui/views/layout/grid_layout.h" | |
19 #include "ui/views/layout/layout_constants.h" | |
20 #include "ui/views/widget/widget.h" | |
21 | |
22 namespace { | |
23 | |
24 | |
bartfab (slow)
2013/10/24 13:11:02
Remove duplicated blank line.
binjin
2013/10/25 13:03:10
Done.
| |
25 const int kLogoutConfirmationDialogMaxWidth = 300; | |
bartfab (slow)
2013/10/24 13:11:02
Could you use one of the existing ash/aura/views c
| |
26 const int kCountdownUpdateIntervalMs = 1000; | |
bartfab (slow)
2013/10/24 13:11:02
Add a comment (prefixed by two spaces):
// 1 se
binjin
2013/10/25 13:03:10
Done.
| |
27 const int kAutoLogoutDurationMs = 5 * 1000; | |
bartfab (slow)
2013/10/24 13:11:02
- This will need to be adjustable by pref.
- Add a
binjin
2013/10/25 13:03:10
Done.
| |
28 | |
29 } | |
bartfab (slow)
2013/10/24 13:11:02
Replace with:
} // namespace
binjin
2013/10/25 13:03:10
Done.
| |
30 | |
31 namespace ash { | |
32 | |
33 namespace internal { | |
34 | |
35 | |
bartfab (slow)
2013/10/24 13:11:02
Remove duplicated blank line.
binjin
2013/10/25 13:03:10
Done.
| |
36 bool LogoutConfirmationDialogView::Accept() { | |
37 Shell::GetInstance()->system_tray_delegate()->SignOut(); | |
38 return true; | |
39 } | |
40 | |
41 int LogoutConfirmationDialogView::GetDialogButtons() const { | |
42 return ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL; | |
bartfab (slow)
2013/10/24 13:11:02
This is the default. No need to override the metho
binjin
2013/10/25 13:03:10
Done.
| |
43 } | |
44 | |
45 ui::ModalType LogoutConfirmationDialogView::GetModalType() const { | |
46 return ui::MODAL_TYPE_WINDOW; | |
bartfab (slow)
2013/10/24 13:11:02
- It would seem that ui::MODAL_TYPE_SYSTEM is the
binjin
2013/10/25 13:03:10
Done.
| |
47 } | |
48 | |
49 string16 LogoutConfirmationDialogView::GetWindowTitle() const { | |
50 return l10n_util::GetStringUTF16(IDS_ASH_LOGOUT_CONFIRMATION_TITLE); | |
51 } | |
52 | |
53 string16 LogoutConfirmationDialogView::GetDialogButtonLabel( | |
54 ui::DialogButton button) const { | |
55 if (button == ui::DIALOG_BUTTON_OK) { | |
bartfab (slow)
2013/10/24 13:11:02
No curly braces for single-line conditionals.
binjin
2013/10/25 13:03:10
Done.
| |
56 return l10n_util::GetStringUTF16(IDS_ASH_LOGOUT_CONFIRMATION_BUTTON); | |
57 } | |
58 if (button == ui::DIALOG_BUTTON_CANCEL) { | |
bartfab (slow)
2013/10/24 13:11:02
No curly braces for single-line conditionals.
binjin
2013/10/25 13:03:10
Done.
| |
59 return l10n_util::GetStringUTF16(IDS_APP_CANCEL); | |
bartfab (slow)
2013/10/24 13:11:02
You can defer to the inherited method instead here
binjin
2013/10/25 13:03:10
Done.
| |
60 } | |
61 return base::string16(); | |
bartfab (slow)
2013/10/24 13:11:02
In this implementation, there should be a NOTREACH
binjin
2013/10/25 13:03:10
Done.
| |
62 } | |
63 | |
64 LogoutConfirmationDialogView::LogoutConfirmationDialogView( | |
65 LogoutButtonTray *owner) : display_label_(NULL), owner_(owner) { | |
bartfab (slow)
2013/10/24 13:11:02
Break at the : and the ,
binjin
2013/10/25 13:03:10
Done.
| |
66 } | |
67 | |
68 LogoutConfirmationDialogView::~LogoutConfirmationDialogView() { | |
69 if (owner_) { | |
bartfab (slow)
2013/10/24 13:11:02
No curly braces for single-line conditionals.
binjin
2013/10/25 13:03:10
Done.
| |
70 owner_->RemoveConfirmDialogInstance(this); | |
bartfab (slow)
2013/10/24 13:11:02
- The "Instance" in this method name is unnecessar
binjin
2013/10/25 13:03:10
Done.
| |
71 } | |
72 } | |
73 | |
74 void LogoutConfirmationDialogView::InitAndShow() { | |
bartfab (slow)
2013/10/24 13:11:02
Why is this initialization not done in the constru
binjin
2013/10/25 13:03:10
Done.
| |
75 ui::ResourceBundle &rb = ui::ResourceBundle::GetSharedInstance(); | |
bartfab (slow)
2013/10/24 13:11:02
Abbreviations are strongly frowned upon. Please ex
binjin
2013/10/25 13:03:10
Done.
| |
76 | |
77 display_label_ = new views::Label(); | |
bartfab (slow)
2013/10/24 13:11:02
No () needed for new.
binjin
2013/10/25 13:03:10
Done.
| |
78 display_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
bartfab (slow)
2013/10/24 13:11:02
#include "ui/gfx/text_constants.h"
binjin
2013/10/25 13:03:10
Done.
| |
79 display_label_->SetMultiLine(true); | |
80 display_label_->SetFont(rb.GetFont(ui::ResourceBundle::BaseFont)); | |
bartfab (slow)
2013/10/24 13:11:02
- In this implementation, #include "ui/gfx/font.h"
binjin
2013/10/25 13:03:10
Done.
| |
81 | |
82 views::GridLayout *layout = views::GridLayout::CreatePanel(this); | |
bartfab (slow)
2013/10/24 13:11:02
- Put the * on the data type, not the variable nam
binjin
2013/10/25 13:03:10
Done.
| |
83 SetLayoutManager(layout); | |
84 | |
85 views::ColumnSet *column_set = layout->AddColumnSet(0); | |
bartfab (slow)
2013/10/24 13:11:02
Put the * on the data type, not the variable name.
binjin
2013/10/25 13:03:10
Done.
| |
86 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER, 1, | |
87 views::GridLayout::FIXED, | |
88 kLogoutConfirmationDialogMaxWidth, 0); | |
89 layout->StartRow(0, 0); | |
90 layout->AddPaddingRow(0, views::kRelatedControlHorizontalSpacing); | |
bartfab (slow)
2013/10/24 13:11:02
You are not adding spacing between related control
| |
91 layout->StartRow(0, 0); | |
92 layout->AddView(display_label_); | |
93 layout->AddPaddingRow(0, views::kRelatedControlHorizontalSpacing); | |
bartfab (slow)
2013/10/24 13:11:02
You are not adding spacing between related control
| |
94 | |
95 Show(); | |
96 } | |
97 | |
98 void LogoutConfirmationDialogView::Show() { | |
99 countdown_end_time_ = base::Time::Now() + | |
100 base::TimeDelta::FromMilliseconds(kAutoLogoutDurationMs); | |
bartfab (slow)
2013/10/24 13:11:02
Indent 4 spaces relative to the line above, not 2.
binjin
2013/10/25 13:03:10
Done.
| |
101 | |
102 UpdateCountdown(); | |
103 | |
104 views::DialogDelegate::CreateDialogWidget( | |
105 this, ash::Shell::GetPrimaryRootWindow(), NULL); | |
106 GetWidget()->SetAlwaysOnTop(true); | |
bartfab (slow)
2013/10/24 13:11:02
Is this really necessary when the dialog is marked
binjin
2013/10/25 13:03:10
Done.
| |
107 GetWidget()->Show(); | |
108 | |
109 timer_.Start(FROM_HERE, | |
bartfab (slow)
2013/10/24 13:11:02
#include "base/location.h"
binjin
2013/10/25 13:03:10
Done.
| |
110 base::TimeDelta::FromMilliseconds(kCountdownUpdateIntervalMs), | |
111 this, | |
112 &LogoutConfirmationDialogView::UpdateCountdown); | |
113 } | |
114 | |
115 void LogoutConfirmationDialogView::UpdateCountdown() { | |
116 // 500ms is a workaround to handle inaccurate time measuring. The time | |
bartfab (slow)
2013/10/24 13:11:02
What are you trying to work around here?
| |
117 // duration is now accurate as long as duration is multiple of | |
118 // kCountdownUpdateIntervalMs | |
bartfab (slow)
2013/10/24 13:11:02
Add full stop at the end of the sentence.
binjin
2013/10/25 13:03:10
Done.
| |
119 base::TimeDelta logout_warning_time = countdown_end_time_ - | |
bartfab (slow)
2013/10/24 13:11:02
Mark as const.
binjin
2013/10/25 13:03:10
Done.
| |
120 base::Time::Now() + | |
121 base::TimeDelta::FromMilliseconds(500); | |
122 if (logout_warning_time.InSeconds() > 0) { | |
123 display_label_->SetText(l10n_util::GetStringFUTF16( | |
124 IDS_ASH_LOGOUT_CONFIRMATION_WARNING, | |
bartfab (slow)
2013/10/24 13:11:02
Indent 4 spaces, not 6.
binjin
2013/10/25 13:03:10
Done.
| |
125 ui::TimeFormat::TimeDurationLong(logout_warning_time))); | |
126 } else { | |
127 display_label_->SetText(l10n_util::GetStringUTF16( | |
128 IDS_ASH_LOGOUT_CONFIRMATION_WARNING_NOW)); | |
bartfab (slow)
2013/10/24 13:11:02
Indent 4 spaces, not 6.
binjin
2013/10/25 13:03:10
Done.
| |
129 Shell::GetInstance()->system_tray_delegate()->SignOut(); | |
130 } | |
131 } | |
132 | |
133 } // namespace internal | |
134 | |
135 } // namespace ash | |
bartfab (slow)
2013/10/24 13:11:02
Add blank line at end of file.
binjin
2013/10/25 13:03:10
Done.
| |
OLD | NEW |