OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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/touch_hud/mus/touch_hud_application.h" |
| 6 |
| 7 #include "ash/public/interfaces/container.mojom.h" |
| 8 #include "ash/touch_hud/touch_hud_renderer.h" |
| 9 #include "base/macros.h" |
| 10 #include "base/strings/utf_string_conversions.h" |
| 11 #include "services/shell/public/cpp/connector.h" |
| 12 #include "services/ui/public/cpp/property_type_converters.h" |
| 13 #include "services/ui/public/interfaces/window_manager_constants.mojom.h" |
| 14 #include "ui/views/mus/aura_init.h" |
| 15 #include "ui/views/mus/native_widget_mus.h" |
| 16 #include "ui/views/mus/window_manager_connection.h" |
| 17 #include "ui/views/touch_event_watcher.h" |
| 18 #include "ui/views/widget/widget.h" |
| 19 #include "ui/views/widget/widget_delegate.h" |
| 20 |
| 21 namespace ash { |
| 22 namespace touch_hud { |
| 23 |
| 24 // TouchHudUI handles events on the widget of the touch-hud app. After |
| 25 // receiving touch events from ui::WindowManagerConnection, it calls |
| 26 // ash::TouchHudRenderer to draw out touch points. |
| 27 class TouchHudUI : public views::WidgetDelegateView, |
| 28 public views::TouchEventWatcher { |
| 29 public: |
| 30 TouchHudUI(views::WindowManagerConnection* window_manager_connection, |
| 31 views::Widget* widget) |
| 32 : window_manager_connection_(window_manager_connection), |
| 33 touch_hud_renderer_(new TouchHudRenderer(widget)) { |
| 34 window_manager_connection_->AddTouchEventWatcher(this); |
| 35 } |
| 36 ~TouchHudUI() override { |
| 37 window_manager_connection_->RemoveTouchEventWatcher(this); |
| 38 } |
| 39 |
| 40 private: |
| 41 // Overridden from views::WidgetDelegate: |
| 42 views::View* GetContentsView() override { return this; } |
| 43 base::string16 GetWindowTitle() const override { |
| 44 // TODO(beng): use resources. |
| 45 return base::ASCIIToUTF16("TouchHud"); |
| 46 } |
| 47 |
| 48 // Overridden from views::TouchEventWatcher: |
| 49 void OnTouchEventObserved(const ui::LocatedEvent& event, |
| 50 views::Widget* target) override { |
| 51 touch_hud_renderer_->HandleTouchEvent(event); |
| 52 } |
| 53 |
| 54 views::WindowManagerConnection* window_manager_connection_; |
| 55 TouchHudRenderer* touch_hud_renderer_; |
| 56 |
| 57 DISALLOW_COPY_AND_ASSIGN(TouchHudUI); |
| 58 }; |
| 59 |
| 60 TouchHudApplication::TouchHudApplication() : binding_(this) {} |
| 61 TouchHudApplication::~TouchHudApplication() {} |
| 62 |
| 63 void TouchHudApplication::OnStart(shell::Connector* connector, |
| 64 const shell::Identity& identity, |
| 65 uint32_t id) { |
| 66 connector_ = connector; |
| 67 aura_init_.reset(new views::AuraInit(connector, "views_mus_resources.pak")); |
| 68 window_manager_connection_ = |
| 69 views::WindowManagerConnection::Create(connector, identity); |
| 70 } |
| 71 |
| 72 bool TouchHudApplication::OnConnect(shell::Connection* connection) { |
| 73 connection->AddInterface<mash::mojom::Launchable>(this); |
| 74 return true; |
| 75 } |
| 76 |
| 77 void TouchHudApplication::Launch(uint32_t what, mash::mojom::LaunchMode how) { |
| 78 if (!widget_) { |
| 79 widget_ = new views::Widget; |
| 80 views::Widget::InitParams params( |
| 81 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
| 82 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; |
| 83 params.activatable = views::Widget::InitParams::ACTIVATABLE_NO; |
| 84 params.accept_events = false; |
| 85 params.delegate = new TouchHudUI(window_manager_connection_.get(), widget_); |
| 86 |
| 87 std::map<std::string, std::vector<uint8_t>> properties; |
| 88 properties[ash::mojom::kWindowContainer_Property] = |
| 89 mojo::ConvertTo<std::vector<uint8_t>>( |
| 90 static_cast<int32_t>(ash::mojom::Container::OVERLAY)); |
| 91 properties[ui::mojom::WindowManager::kShowState_Property] = |
| 92 mojo::ConvertTo<std::vector<uint8_t>>( |
| 93 static_cast<int32_t>(ui::mojom::ShowState::FULLSCREEN)); |
| 94 ui::Window* window = |
| 95 window_manager_connection_.get()->NewWindow(properties); |
| 96 params.native_widget = new views::NativeWidgetMus( |
| 97 widget_, connector_, window, ui::mojom::SurfaceType::DEFAULT); |
| 98 widget_->Init(params); |
| 99 widget_->Show(); |
| 100 } else { |
| 101 widget_->Close(); |
| 102 base::MessageLoop::current()->QuitWhenIdle(); |
| 103 } |
| 104 } |
| 105 |
| 106 void TouchHudApplication::Create(shell::Connection* connection, |
| 107 mash::mojom::LaunchableRequest request) { |
| 108 binding_.Bind(std::move(request)); |
| 109 } |
| 110 |
| 111 } // namespace touch_hud |
| 112 } // namespace ash |
OLD | NEW |