idle_action_warning_dialog_view.cc revision c2e0dbddbe15c98d52c4786dac06cb8952a8ae6d
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. 4 5#include "chrome/browser/chromeos/power/idle_action_warning_dialog_view.h" 6 7#include "ash/shell.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" 20 21namespace chromeos { 22 23namespace { 24 25const int kIdleActionWarningContentWidth = 300; 26 27class FixedWidthLabel : public views::Label { 28 public: 29 FixedWidthLabel(const string16& text, int width); 30 virtual ~FixedWidthLabel(); 31 32 virtual gfx::Size GetPreferredSize() OVERRIDE; 33 34 private: 35 int width_; 36 37 DISALLOW_COPY_AND_ASSIGN(FixedWidthLabel); 38}; 39 40FixedWidthLabel::FixedWidthLabel(const string16& text, int width) 41 : Label(text), 42 width_(width) { 43 SetHorizontalAlignment(gfx::ALIGN_LEFT); 44 SetMultiLine(true); 45} 46 47FixedWidthLabel::~FixedWidthLabel() { 48} 49 50gfx::Size FixedWidthLabel::GetPreferredSize() { 51 return gfx::Size(width_, GetHeightForWidth(width_)); 52} 53 54} // namespace 55 56IdleActionWarningDialogView::IdleActionWarningDialogView() : closing_(false) { 57 FixedWidthLabel* content = new FixedWidthLabel( 58 l10n_util::GetStringUTF16(IDS_IDLE_WARNING_LOGOUT_WARNING), 59 kIdleActionWarningContentWidth); 60 if (DialogDelegate::UseNewStyle()) { 61 content->set_border(views::Border::CreateEmptyBorder( 62 views::kPanelVertMargin, views::kButtonHEdgeMarginNew, 63 views::kPanelVertMargin, views::kButtonHEdgeMarginNew)); 64 } else { 65 content->set_border(views::Border::CreateEmptyBorder( 66 views::kPanelVertMargin, views::kPanelHorizMargin, 67 views::kPanelVertMargin, views::kPanelHorizMargin)); 68 } 69 AddChildView(content); 70 SetLayoutManager(new views::FillLayout()); 71 72 views::Widget::CreateWindowWithContext(this, 73 ash::Shell::GetPrimaryRootWindow()); 74 GetWidget()->Show(); 75} 76 77void IdleActionWarningDialogView::Close() { 78 closing_ = true; 79 GetDialogClientView()->CancelWindow(); 80} 81 82ui::ModalType IdleActionWarningDialogView::GetModalType() const { 83 return ui::MODAL_TYPE_SYSTEM; 84} 85 86string16 IdleActionWarningDialogView::GetWindowTitle() const { 87 return l10n_util::GetStringUTF16(IDS_IDLE_WARNING_TITLE); 88} 89 90int IdleActionWarningDialogView::GetDialogButtons() const { 91 return ui::DIALOG_BUTTON_NONE; 92} 93 94bool IdleActionWarningDialogView::Cancel() { 95 return closing_; 96} 97 98IdleActionWarningDialogView::~IdleActionWarningDialogView() { 99} 100 101} // namespace chromeos 102