Update broken references to image assets
[chromium-blink-merge.git] / chrome / browser / chromeos / power / idle_action_warning_dialog_view.cc
blobc09036bbbfa4ac0fafe69adfb000d176a5803430
1 // Copyright 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.
5 #include "chrome/browser/chromeos/power/idle_action_warning_dialog_view.h"
7 #include <algorithm>
9 #include "ash/shell.h"
10 #include "base/location.h"
11 #include "chrome/grit/generated_resources.h"
12 #include "ui/aura/window_event_dispatcher.h"
13 #include "ui/base/l10n/l10n_util.h"
14 #include "ui/base/l10n/time_format.h"
15 #include "ui/base/ui_base_types.h"
16 #include "ui/gfx/geometry/size.h"
17 #include "ui/gfx/text_constants.h"
18 #include "ui/views/border.h"
19 #include "ui/views/controls/label.h"
20 #include "ui/views/layout/fill_layout.h"
21 #include "ui/views/layout/layout_constants.h"
22 #include "ui/views/widget/widget.h"
23 #include "ui/views/window/dialog_client_view.h"
25 namespace chromeos {
27 namespace {
29 const int kIdleActionWarningContentWidth = 300;
31 const int kCountdownUpdateIntervalMs = 1000; // 1 second.
33 class FixedWidthLabel : public views::Label {
34 public:
35 explicit FixedWidthLabel(int width);
36 ~FixedWidthLabel() override;
38 gfx::Size GetPreferredSize() const override;
40 private:
41 int width_;
43 DISALLOW_COPY_AND_ASSIGN(FixedWidthLabel);
46 FixedWidthLabel::FixedWidthLabel(int width) : width_(width) {
47 SetHorizontalAlignment(gfx::ALIGN_LEFT);
48 SetMultiLine(true);
51 FixedWidthLabel::~FixedWidthLabel() {
54 gfx::Size FixedWidthLabel::GetPreferredSize() const {
55 return gfx::Size(width_, GetHeightForWidth(width_));
58 } // namespace
60 IdleActionWarningDialogView::IdleActionWarningDialogView(
61 base::TimeTicks idle_action_time)
62 : idle_action_time_(idle_action_time),
63 label_(NULL) {
64 label_ = new FixedWidthLabel(kIdleActionWarningContentWidth);
65 label_->SetBorder(
66 views::Border::CreateEmptyBorder(views::kPanelVertMargin,
67 views::kButtonHEdgeMarginNew,
68 views::kPanelVertMargin,
69 views::kButtonHEdgeMarginNew));
70 AddChildView(label_);
71 SetLayoutManager(new views::FillLayout());
73 UpdateLabel();
75 views::DialogDelegate::CreateDialogWidget(
76 this, ash::Shell::GetPrimaryRootWindow(), NULL)->Show();
78 update_timer_.Start(
79 FROM_HERE,
80 base::TimeDelta::FromMilliseconds(kCountdownUpdateIntervalMs),
81 this,
82 &IdleActionWarningDialogView::UpdateLabel);
85 void IdleActionWarningDialogView::CloseDialog() {
86 update_timer_.Stop();
87 GetDialogClientView()->CancelWindow();
90 void IdleActionWarningDialogView::Update(base::TimeTicks idle_action_time) {
91 idle_action_time_ = idle_action_time;
92 UpdateLabel();
95 ui::ModalType IdleActionWarningDialogView::GetModalType() const {
96 return ui::MODAL_TYPE_SYSTEM;
99 base::string16 IdleActionWarningDialogView::GetWindowTitle() const {
100 return l10n_util::GetStringUTF16(IDS_IDLE_WARNING_TITLE);
103 int IdleActionWarningDialogView::GetDialogButtons() const {
104 return ui::DIALOG_BUTTON_NONE;
107 bool IdleActionWarningDialogView::Cancel() {
108 return !update_timer_.IsRunning();
111 IdleActionWarningDialogView::~IdleActionWarningDialogView() {
114 void IdleActionWarningDialogView::UpdateLabel() {
115 const base::TimeDelta time_until_idle_action =
116 std::max(idle_action_time_ - base::TimeTicks::Now(),
117 base::TimeDelta());
118 label_->SetText(l10n_util::GetStringFUTF16(
119 IDS_IDLE_WARNING_LOGOUT_WARNING,
120 ui::TimeFormat::Detailed(ui::TimeFormat::FORMAT_DURATION,
121 ui::TimeFormat::LENGTH_LONG,
123 time_until_idle_action)));
126 } // namespace chromeos