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"
8 #include "grit/generated_resources.h"
9 #include "ui/aura/root_window.h"
10 #include "ui/base/l10n/l10n_util.h"
11 #include "ui/base/ui_base_types.h"
12 #include "ui/gfx/size.h"
13 #include "ui/gfx/text_constants.h"
14 #include "ui/views/border.h"
15 #include "ui/views/controls/label.h"
16 #include "ui/views/layout/fill_layout.h"
17 #include "ui/views/layout/layout_constants.h"
18 #include "ui/views/widget/widget.h"
19 #include "ui/views/window/dialog_client_view.h"
25 const int kIdleActionWarningContentWidth
= 300;
27 class FixedWidthLabel
: public views::Label
{
29 FixedWidthLabel(const base::string16
& text
, int width
);
30 virtual ~FixedWidthLabel();
32 virtual gfx::Size
GetPreferredSize() OVERRIDE
;
37 DISALLOW_COPY_AND_ASSIGN(FixedWidthLabel
);
40 FixedWidthLabel::FixedWidthLabel(const base::string16
& text
, int width
)
43 SetHorizontalAlignment(gfx::ALIGN_LEFT
);
47 FixedWidthLabel::~FixedWidthLabel() {
50 gfx::Size
FixedWidthLabel::GetPreferredSize() {
51 return gfx::Size(width_
, GetHeightForWidth(width_
));
56 IdleActionWarningDialogView::IdleActionWarningDialogView() : closing_(false) {
57 FixedWidthLabel
* content
= new FixedWidthLabel(
58 l10n_util::GetStringUTF16(IDS_IDLE_WARNING_LOGOUT_WARNING
),
59 kIdleActionWarningContentWidth
);
60 content
->set_border(views::Border::CreateEmptyBorder(
61 views::kPanelVertMargin
, views::kButtonHEdgeMarginNew
,
62 views::kPanelVertMargin
, views::kButtonHEdgeMarginNew
));
63 AddChildView(content
);
64 SetLayoutManager(new views::FillLayout());
66 views::DialogDelegate::CreateDialogWidget(
67 this, ash::Shell::GetPrimaryRootWindow(), NULL
)->Show();
70 void IdleActionWarningDialogView::CloseDialog() {
72 GetDialogClientView()->CancelWindow();
75 ui::ModalType
IdleActionWarningDialogView::GetModalType() const {
76 return ui::MODAL_TYPE_SYSTEM
;
79 base::string16
IdleActionWarningDialogView::GetWindowTitle() const {
80 return l10n_util::GetStringUTF16(IDS_IDLE_WARNING_TITLE
);
83 int IdleActionWarningDialogView::GetDialogButtons() const {
84 return ui::DIALOG_BUTTON_NONE
;
87 bool IdleActionWarningDialogView::Cancel() {
91 IdleActionWarningDialogView::~IdleActionWarningDialogView() {
94 } // namespace chromeos