OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 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 "ash/surfaces/test_shell_surface_overlay_view.h" |
| 6 |
| 7 #include "ash/shell.h" |
| 8 #include "ash/shell_window_ids.h" |
| 9 #include "ash/surfaces/surface_controller.h" |
| 10 #include "ui/events/event.h" |
| 11 #include "ui/gfx/canvas.h" |
| 12 #include "ui/gfx/transform_util.h" |
| 13 |
| 14 namespace ash { |
| 15 |
| 16 TestShellSurfaceOverlayView::TestShellSurfaceOverlayView() {} |
| 17 |
| 18 TestShellSurfaceOverlayView::~TestShellSurfaceOverlayView() {} |
| 19 |
| 20 void TestShellSurfaceOverlayView::OnPaint(gfx::Canvas* canvas) { |
| 21 canvas->FillRect(GetLocalBounds(), SK_ColorBLACK); |
| 22 } |
| 23 |
| 24 void TestShellSurfaceOverlayView::WindowClosing() { |
| 25 Cancel(); |
| 26 } |
| 27 |
| 28 void TestShellSurfaceOverlayView::Cancel() { |
| 29 Shell::GetInstance()->overlay_filter()->Deactivate(this); |
| 30 views::Widget* widget = GetWidget(); |
| 31 if (widget) |
| 32 widget->Close(); |
| 33 } |
| 34 |
| 35 bool TestShellSurfaceOverlayView::IsCancelingKeyEvent(ui::KeyEvent* event) { |
| 36 if (event->type() != ui::ET_KEY_PRESSED) |
| 37 return false; |
| 38 |
| 39 // Ignore the caps lock and shift state. |
| 40 const int flags = |
| 41 event->flags() & ~(ui::EF_CAPS_LOCK_DOWN | ui::EF_SHIFT_DOWN); |
| 42 |
| 43 // Keys to invoke hide (Ctrl+Alt+A). |
| 44 return event->key_code() == ui::VKEY_A && |
| 45 flags == (ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN); |
| 46 } |
| 47 |
| 48 aura::Window* TestShellSurfaceOverlayView::GetWindow() { |
| 49 return GetWidget()->GetNativeWindow(); |
| 50 } |
| 51 |
| 52 // static |
| 53 void TestShellSurfaceOverlayView::Show() { |
| 54 if (Shell::GetInstance()->overlay_filter()->IsActive()) |
| 55 return; |
| 56 |
| 57 const gfx::Point kOrigin(64, 40); |
| 58 const float kScale = 0.3f; |
| 59 |
| 60 ui::Layer* test_shell_surface_layer = |
| 61 Shell::GetInstance()->surface_controller()->test_shell_surface_layer(); |
| 62 |
| 63 test_shell_surface_layer->SetTransform( |
| 64 gfx::GetScaleTransform(gfx::Point(), kScale)); |
| 65 |
| 66 TestShellSurfaceOverlayView* view = new TestShellSurfaceOverlayView; |
| 67 views::Widget::InitParams params( |
| 68 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
| 69 params.shadow_type = views::Widget::InitParams::SHADOW_TYPE_DROP; |
| 70 params.bounds = gfx::Rect( |
| 71 kOrigin, |
| 72 gfx::ScaleToRoundedSize( |
| 73 Shell::GetScreen()->GetPrimaryDisplay().bounds().size(), kScale)); |
| 74 params.show_state = ui::SHOW_STATE_NORMAL; |
| 75 params.parent = Shell::GetContainer(Shell::GetPrimaryRootWindow(), |
| 76 kShellWindowId_OverlayContainer); |
| 77 views::Widget* widget = new views::Widget; |
| 78 widget->Init(params); |
| 79 widget->SetContentsView(view); |
| 80 widget->GetNativeWindow()->layer()->Add(test_shell_surface_layer); |
| 81 widget->Show(); |
| 82 widget->GetNativeView()->SetName("TestShellSurfaceOverlayView"); |
| 83 widget->GetNativeView()->Focus(); |
| 84 |
| 85 Shell::GetInstance()->overlay_filter()->Activate(view); |
| 86 } |
| 87 |
| 88 // static |
| 89 void TestShellSurfaceOverlayView::ShowFullscreen() { |
| 90 if (Shell::GetInstance()->overlay_filter()->IsActive()) |
| 91 return; |
| 92 |
| 93 ui::Layer* test_shell_surface_layer = |
| 94 Shell::GetInstance()->surface_controller()->test_shell_surface_layer(); |
| 95 |
| 96 test_shell_surface_layer->SetTransform(gfx::Transform()); |
| 97 |
| 98 TestShellSurfaceOverlayView* view = new TestShellSurfaceOverlayView; |
| 99 views::Widget::InitParams params( |
| 100 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
| 101 params.bounds = Shell::GetScreen()->GetPrimaryDisplay().bounds(); |
| 102 params.show_state = ui::SHOW_STATE_FULLSCREEN; |
| 103 params.parent = Shell::GetContainer(Shell::GetPrimaryRootWindow(), |
| 104 kShellWindowId_OverlayContainer); |
| 105 views::Widget* widget = new views::Widget; |
| 106 widget->Init(params); |
| 107 widget->SetContentsView(view); |
| 108 widget->GetNativeWindow()->layer()->Add(test_shell_surface_layer); |
| 109 widget->Show(); |
| 110 widget->GetNativeView()->SetName("TestShellSurfaceOverlayView"); |
| 111 widget->GetNativeView()->Focus(); |
| 112 |
| 113 Shell::GetInstance()->overlay_filter()->Activate(view); |
| 114 } |
| 115 |
| 116 } // namespace ash |
OLD | NEW |