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