OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/chromeos/ui/kiosk_external_update_notification.h" |
| 6 |
| 7 #include "ash/shell.h" |
| 8 #include "ash/shell_window_ids.h" |
| 9 #include "ui/aura/window.h" |
| 10 #include "ui/base/resource/resource_bundle.h" |
| 11 #include "ui/compositor/layer.h" |
| 12 #include "ui/compositor/scoped_layer_animation_settings.h" |
| 13 #include "ui/gfx/canvas.h" |
| 14 #include "ui/views/controls/label.h" |
| 15 #include "ui/views/layout/fill_layout.h" |
| 16 #include "ui/views/view.h" |
| 17 #include "ui/views/widget/widget.h" |
| 18 #include "ui/views/widget/widget_delegate.h" |
| 19 |
| 20 namespace chromeos { |
| 21 |
| 22 namespace { |
| 23 |
| 24 const SkColor kTextColor = SK_ColorBLACK; |
| 25 const SkColor kWindowBackgroundColor = SK_ColorWHITE; |
| 26 const int kWindowCornerRadius = 4; |
| 27 const int kPreferredWidth = 600; |
| 28 const int kPreferredHeight = 250; |
| 29 |
| 30 } // namespace |
| 31 |
| 32 class KioskExternalUpdateNotificationView : public views::WidgetDelegateView { |
| 33 public: |
| 34 KioskExternalUpdateNotificationView() { |
| 35 AddLabel(); |
| 36 SetLayoutManager(new views::FillLayout); |
| 37 } |
| 38 |
| 39 virtual ~KioskExternalUpdateNotificationView() {} |
| 40 |
| 41 // Close the widget immediately. This can be called from the owner or from |
| 42 // this class. |
| 43 void Close() { GetWidget()->Close(); } |
| 44 |
| 45 void SetMessage(const base::string16& message) { label_->SetText(message); } |
| 46 |
| 47 // views::WidgetDelegateView overrides: |
| 48 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { |
| 49 SkPaint paint; |
| 50 paint.setStyle(SkPaint::kFill_Style); |
| 51 paint.setColor(kWindowBackgroundColor); |
| 52 canvas->DrawRoundRect(GetLocalBounds(), kWindowCornerRadius, paint); |
| 53 views::WidgetDelegateView::OnPaint(canvas); |
| 54 } |
| 55 |
| 56 virtual gfx::Size GetPreferredSize() const OVERRIDE { |
| 57 return gfx::Size(kPreferredWidth, kPreferredHeight); |
| 58 } |
| 59 |
| 60 private: |
| 61 void AddLabel() { |
| 62 label_ = new views::Label; |
| 63 label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 64 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 65 label_->SetFontList(rb.GetFontList(ui::ResourceBundle::BoldFont)); |
| 66 label_->SetEnabledColor(kTextColor); |
| 67 label_->SetDisabledColor(kTextColor); |
| 68 label_->SetAutoColorReadabilityEnabled(false); |
| 69 label_->SetMultiLine(true); |
| 70 AddChildView(label_); |
| 71 } |
| 72 |
| 73 views::Label* label_; // owned by views hierarchy. |
| 74 |
| 75 DISALLOW_COPY_AND_ASSIGN(KioskExternalUpdateNotificationView); |
| 76 }; |
| 77 |
| 78 KioskExternalUpdateNotification::KioskExternalUpdateNotification( |
| 79 const base::string16& message) { |
| 80 CreateAndShowNotificationView(message); |
| 81 } |
| 82 |
| 83 KioskExternalUpdateNotification::~KioskExternalUpdateNotification() { |
| 84 view_->Close(); |
| 85 } |
| 86 |
| 87 void KioskExternalUpdateNotification::ShowMessage( |
| 88 const base::string16& message) { |
| 89 DCHECK(view_); |
| 90 view_->SetMessage(message); |
| 91 } |
| 92 |
| 93 void KioskExternalUpdateNotification::CreateAndShowNotificationView( |
| 94 const base::string16& message) { |
| 95 view_ = new KioskExternalUpdateNotificationView(); |
| 96 view_->SetMessage(message); |
| 97 |
| 98 aura::Window* root_window = ash::Shell::GetTargetRootWindow(); |
| 99 gfx::Size rs = root_window->bounds().size(); |
| 100 gfx::Size ps = view_->GetPreferredSize(); |
| 101 gfx::Rect bounds((rs.width() - ps.width()) / 2, |
| 102 (rs.height() - ps.height()) / 10, |
| 103 ps.width(), |
| 104 ps.height()); |
| 105 views::Widget::InitParams params; |
| 106 params.type = views::Widget::InitParams::TYPE_POPUP; |
| 107 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; |
| 108 params.ownership = views::Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET; |
| 109 params.accept_events = false; |
| 110 params.keep_on_top = true; |
| 111 params.remove_standard_frame = true; |
| 112 params.delegate = view_; |
| 113 params.bounds = bounds; |
| 114 params.parent = ash::Shell::GetContainer( |
| 115 root_window, ash::kShellWindowId_SettingBubbleContainer); |
| 116 views::Widget* widget = new views::Widget; |
| 117 widget->Init(params); |
| 118 widget->SetContentsView(view_); |
| 119 gfx::NativeView native_view = widget->GetNativeView(); |
| 120 native_view->SetName("KioskExternalUpdateNotification"); |
| 121 widget->Show(); |
| 122 } |
| 123 |
| 124 } // namespace chromeos |
OLD | NEW |