| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ash/touch_hud/mus/touch_hud_application.h" | 5 #include "ash/touch_hud/mus/touch_hud_application.h" |
| 6 | 6 |
| 7 #include "ash/public/cpp/shell_window_ids.h" | 7 #include "ash/public/cpp/shell_window_ids.h" |
| 8 #include "ash/touch_hud/touch_hud_renderer.h" | 8 #include "ash/touch_hud/touch_hud_renderer.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "services/service_manager/public/cpp/connector.h" | 12 #include "services/service_manager/public/cpp/connector.h" |
| 13 #include "services/service_manager/public/cpp/interface_registry.h" | 13 #include "services/service_manager/public/cpp/interface_registry.h" |
| 14 #include "services/service_manager/public/cpp/service_context.h" | 14 #include "services/service_manager/public/cpp/service_context.h" |
| 15 #include "services/ui/public/cpp/property_type_converters.h" | 15 #include "services/ui/public/cpp/property_type_converters.h" |
| 16 #include "services/ui/public/interfaces/window_manager_constants.mojom.h" | 16 #include "services/ui/public/interfaces/window_manager_constants.mojom.h" |
| 17 #include "ui/aura/mus/property_converter.h" | 17 #include "ui/aura/mus/property_converter.h" |
| 18 #include "ui/views/mus/aura_init.h" | 18 #include "ui/views/mus/aura_init.h" |
| 19 #include "ui/views/mus/mus_client.h" |
| 19 #include "ui/views/mus/native_widget_mus.h" | 20 #include "ui/views/mus/native_widget_mus.h" |
| 20 #include "ui/views/mus/pointer_watcher_event_router.h" | 21 #include "ui/views/mus/pointer_watcher_event_router2.h" |
| 21 #include "ui/views/mus/window_manager_connection.h" | |
| 22 #include "ui/views/pointer_watcher.h" | 22 #include "ui/views/pointer_watcher.h" |
| 23 #include "ui/views/widget/widget.h" | 23 #include "ui/views/widget/widget.h" |
| 24 #include "ui/views/widget/widget_delegate.h" | 24 #include "ui/views/widget/widget_delegate.h" |
| 25 | 25 |
| 26 namespace ash { | 26 namespace ash { |
| 27 namespace touch_hud { | 27 namespace touch_hud { |
| 28 | 28 |
| 29 // TouchHudUI handles events on the widget of the touch-hud app. After | 29 // TouchHudUI handles events on the widget of the touch-hud app. After |
| 30 // receiving touch events from ui::WindowManagerConnection, it calls | 30 // receiving touch events from PointerWatcher, it calls ash::TouchHudRenderer to |
| 31 // ash::TouchHudRenderer to draw out touch points. | 31 // draw the touch points. |
| 32 class TouchHudUI : public views::WidgetDelegateView, | 32 class TouchHudUI : public views::WidgetDelegateView, |
| 33 public views::PointerWatcher { | 33 public views::PointerWatcher { |
| 34 public: | 34 public: |
| 35 TouchHudUI(views::WindowManagerConnection* window_manager_connection, | 35 explicit TouchHudUI(views::Widget* widget) |
| 36 views::Widget* widget) | 36 : touch_hud_renderer_(new TouchHudRenderer(widget)) { |
| 37 : window_manager_connection_(window_manager_connection), | 37 views::MusClient::Get()->pointer_watcher_event_router()->AddPointerWatcher( |
| 38 touch_hud_renderer_(new TouchHudRenderer(widget)) { | 38 this, true /* want_moves */); |
| 39 window_manager_connection_->pointer_watcher_event_router() | |
| 40 ->AddPointerWatcher(this, true /* want_moves */); | |
| 41 } | 39 } |
| 42 ~TouchHudUI() override { | 40 ~TouchHudUI() override { |
| 43 window_manager_connection_->pointer_watcher_event_router() | 41 views::MusClient::Get() |
| 42 ->pointer_watcher_event_router() |
| 44 ->RemovePointerWatcher(this); | 43 ->RemovePointerWatcher(this); |
| 45 } | 44 } |
| 46 | 45 |
| 47 private: | 46 private: |
| 48 // Overridden from views::WidgetDelegate: | 47 // Overridden from views::WidgetDelegate: |
| 49 base::string16 GetWindowTitle() const override { | 48 base::string16 GetWindowTitle() const override { |
| 50 // TODO(beng): use resources. | 49 // TODO(beng): use resources. |
| 51 return base::ASCIIToUTF16("TouchHud"); | 50 return base::ASCIIToUTF16("TouchHud"); |
| 52 } | 51 } |
| 53 | 52 |
| 54 // Overridden from views::PointerWatcher: | 53 // Overridden from views::PointerWatcher: |
| 55 void OnPointerEventObserved(const ui::PointerEvent& event, | 54 void OnPointerEventObserved(const ui::PointerEvent& event, |
| 56 const gfx::Point& location_in_screen, | 55 const gfx::Point& location_in_screen, |
| 57 views::Widget* target) override { | 56 views::Widget* target) override { |
| 58 if (event.IsTouchPointerEvent()) | 57 if (event.IsTouchPointerEvent()) |
| 59 touch_hud_renderer_->HandleTouchEvent(event); | 58 touch_hud_renderer_->HandleTouchEvent(event); |
| 60 } | 59 } |
| 61 | 60 |
| 62 views::WindowManagerConnection* window_manager_connection_; | |
| 63 TouchHudRenderer* touch_hud_renderer_; | 61 TouchHudRenderer* touch_hud_renderer_; |
| 64 | 62 |
| 65 DISALLOW_COPY_AND_ASSIGN(TouchHudUI); | 63 DISALLOW_COPY_AND_ASSIGN(TouchHudUI); |
| 66 }; | 64 }; |
| 67 | 65 |
| 68 TouchHudApplication::TouchHudApplication() : binding_(this) {} | 66 TouchHudApplication::TouchHudApplication() : binding_(this) {} |
| 69 TouchHudApplication::~TouchHudApplication() {} | 67 TouchHudApplication::~TouchHudApplication() {} |
| 70 | 68 |
| 71 void TouchHudApplication::OnStart() { | 69 void TouchHudApplication::OnStart() { |
| 72 aura_init_ = base::MakeUnique<views::AuraInit>( | 70 aura_init_ = base::MakeUnique<views::AuraInit>( |
| 73 context()->connector(), context()->identity(), "views_mus_resources.pak"); | 71 context()->connector(), context()->identity(), "views_mus_resources.pak", |
| 74 window_manager_connection_ = views::WindowManagerConnection::Create( | 72 std::string(), nullptr, views::AuraInit::Mode::AURA_MUS); |
| 75 context()->connector(), context()->identity()); | |
| 76 } | 73 } |
| 77 | 74 |
| 78 bool TouchHudApplication::OnConnect( | 75 bool TouchHudApplication::OnConnect( |
| 79 const service_manager::ServiceInfo& remote_info, | 76 const service_manager::ServiceInfo& remote_info, |
| 80 service_manager::InterfaceRegistry* registry) { | 77 service_manager::InterfaceRegistry* registry) { |
| 81 registry->AddInterface<mash::mojom::Launchable>(this); | 78 registry->AddInterface<mash::mojom::Launchable>(this); |
| 82 return true; | 79 return true; |
| 83 } | 80 } |
| 84 | 81 |
| 85 void TouchHudApplication::Launch(uint32_t what, mash::mojom::LaunchMode how) { | 82 void TouchHudApplication::Launch(uint32_t what, mash::mojom::LaunchMode how) { |
| 86 if (!widget_) { | 83 if (!widget_) { |
| 87 widget_ = new views::Widget; | 84 widget_ = new views::Widget; |
| 88 views::Widget::InitParams params( | 85 views::Widget::InitParams params( |
| 89 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 86 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
| 90 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; | 87 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; |
| 91 params.activatable = views::Widget::InitParams::ACTIVATABLE_NO; | 88 params.activatable = views::Widget::InitParams::ACTIVATABLE_NO; |
| 92 params.accept_events = false; | 89 params.accept_events = false; |
| 93 params.delegate = new TouchHudUI(window_manager_connection_.get(), widget_); | 90 params.delegate = new TouchHudUI(widget_); |
| 94 | 91 params.mus_properties[ui::mojom::WindowManager::kContainerId_InitProperty] = |
| 95 std::map<std::string, std::vector<uint8_t>> properties; | |
| 96 properties[ui::mojom::WindowManager::kContainerId_InitProperty] = | |
| 97 mojo::ConvertTo<std::vector<uint8_t>>( | 92 mojo::ConvertTo<std::vector<uint8_t>>( |
| 98 ash::kShellWindowId_OverlayContainer); | 93 ash::kShellWindowId_OverlayContainer); |
| 99 properties[ui::mojom::WindowManager::kShowState_Property] = | 94 params.show_state = ui::SHOW_STATE_FULLSCREEN; |
| 100 mojo::ConvertTo<std::vector<uint8_t>>( | |
| 101 static_cast<aura::PropertyConverter::PrimitiveType>( | |
| 102 ui::mojom::ShowState::FULLSCREEN)); | |
| 103 ui::Window* window = | |
| 104 window_manager_connection_.get()->NewTopLevelWindow(properties); | |
| 105 params.native_widget = new views::NativeWidgetMus( | |
| 106 widget_, window, ui::mojom::CompositorFrameSinkType::DEFAULT); | |
| 107 widget_->Init(params); | 95 widget_->Init(params); |
| 108 widget_->Show(); | 96 widget_->Show(); |
| 109 } else { | 97 } else { |
| 110 widget_->Close(); | 98 widget_->Close(); |
| 111 base::MessageLoop::current()->QuitWhenIdle(); | 99 base::MessageLoop::current()->QuitWhenIdle(); |
| 112 } | 100 } |
| 113 } | 101 } |
| 114 | 102 |
| 115 void TouchHudApplication::Create( | 103 void TouchHudApplication::Create( |
| 116 const service_manager::Identity& remote_identity, | 104 const service_manager::Identity& remote_identity, |
| 117 mash::mojom::LaunchableRequest request) { | 105 mash::mojom::LaunchableRequest request) { |
| 118 binding_.Close(); | 106 binding_.Close(); |
| 119 binding_.Bind(std::move(request)); | 107 binding_.Bind(std::move(request)); |
| 120 } | 108 } |
| 121 | 109 |
| 122 } // namespace touch_hud | 110 } // namespace touch_hud |
| 123 } // namespace ash | 111 } // namespace ash |
| OLD | NEW |