OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 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 "ui/aura/desktop.h" |
| 6 #include "ui/aura/window.h" |
| 7 #include "ui/aura_shell/examples/example_factory.h" |
| 8 #include "ui/aura_shell/shell_window_ids.h" |
| 9 #include "ui/gfx/canvas.h" |
| 10 #include "ui/gfx/font.h" |
| 11 #include "views/widget/widget.h" |
| 12 #include "views/widget/widget_delegate.h" |
| 13 |
| 14 namespace aura_shell { |
| 15 namespace examples { |
| 16 |
| 17 class LockView : public views::WidgetDelegateView { |
| 18 public: |
| 19 LockView() { |
| 20 } |
| 21 virtual ~LockView() {} |
| 22 |
| 23 // Overridden from View: |
| 24 virtual gfx::Size GetPreferredSize() OVERRIDE { |
| 25 return gfx::Size(500, 400); |
| 26 } |
| 27 |
| 28 private: |
| 29 // Overridden from View: |
| 30 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { |
| 31 canvas->FillRectInt(SK_ColorYELLOW, 0, 0, width(), height()); |
| 32 string16 text = L"LOCKED!"; |
| 33 int string_width = font_.GetStringWidth(text); |
| 34 canvas->DrawStringInt(text, font_, SK_ColorRED, (width() - string_width)/ 2, |
| 35 (height() - font_.GetHeight()) / 2, |
| 36 string_width, font_.GetHeight()); |
| 37 } |
| 38 virtual bool OnMousePressed(const views::MouseEvent& event) OVERRIDE { |
| 39 return true; |
| 40 } |
| 41 virtual void OnMouseReleased(const views::MouseEvent& event) OVERRIDE { |
| 42 GetWidget()->Close(); |
| 43 } |
| 44 |
| 45 gfx::Font font_; |
| 46 |
| 47 DISALLOW_COPY_AND_ASSIGN(LockView); |
| 48 }; |
| 49 |
| 50 void CreateLock() { |
| 51 LockView* lock_view = new LockView; |
| 52 views::Widget* widget = new views::Widget; |
| 53 views::Widget::InitParams params(views::Widget::InitParams::TYPE_CONTROL); |
| 54 gfx::Size ps = lock_view->GetPreferredSize(); |
| 55 |
| 56 gfx::Rect desktop_bounds = aura::Desktop::GetInstance()->window()->bounds(); |
| 57 params.bounds = gfx::Rect((desktop_bounds.width() - ps.width()) / 2, |
| 58 (desktop_bounds.height() - ps.height()) / 2, |
| 59 ps.width(), ps.height()); |
| 60 params.delegate = lock_view; |
| 61 params.parent = aura::Desktop::GetInstance()->window()->GetChildById( |
| 62 aura_shell::internal::kShellWindowId_LockScreenContainer); |
| 63 widget->Init(params); |
| 64 widget->SetContentsView(lock_view); |
| 65 widget->Show(); |
| 66 widget->GetNativeView()->set_name("LockView"); |
| 67 } |
| 68 |
| 69 } // namespace examples |
| 70 } // namespace aura_shell |
OLD | NEW |