Index: ash/touch_hud/mus/touch_hud_application.cc |
diff --git a/ash/touch_hud/mus/touch_hud_application.cc b/ash/touch_hud/mus/touch_hud_application.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..09240755b9a82b5c8f2b9e87b00889616e0e55d1 |
--- /dev/null |
+++ b/ash/touch_hud/mus/touch_hud_application.cc |
@@ -0,0 +1,121 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "ash/touch_hud/mus/touch_hud_application.h" |
+ |
+#include "ash/public/interfaces/container.mojom.h" |
+#include "ash/touch_hud/touch_hud_renderer.h" |
+#include "base/macros.h" |
+#include "base/strings/utf_string_conversions.h" |
+#include "mojo/public/cpp/bindings/binding.h" |
+#include "services/shell/public/cpp/connector.h" |
+#include "services/ui/public/cpp/property_type_converters.h" |
+#include "services/ui/public/interfaces/window_manager_constants.mojom.h" |
+#include "ui/views/mus/aura_init.h" |
+#include "ui/views/mus/native_widget_mus.h" |
+#include "ui/views/mus/window_manager_connection.h" |
+#include "ui/views/touch_event_watcher.h" |
+#include "ui/views/widget/widget.h" |
+#include "ui/views/widget/widget_delegate.h" |
+ |
+namespace ash { |
+namespace touch_hud { |
+ |
+// TouchHudUI handles events on the widget of the touch-hud app. After |
+// receiving touch events from ui::WindowManagerConnection, it calls |
+// ash::TouchHudRenderer to draw out touch points. |
+class TouchHudUI : public views::WidgetDelegateView, |
+ public views::TouchEventWatcher { |
+ public: |
+ TouchHudUI(views::WindowManagerConnection* window_manager_connection, |
+ views::Widget* widget) |
+ : window_manager_connection_(window_manager_connection), |
+ widget_(widget), |
+ touch_hud_renderer_(new TouchHudRenderer(widget_)) { |
+ window_manager_connection_->AddTouchEventWatcher(this); |
+ } |
+ ~TouchHudUI() override { |
+ window_manager_connection_->RemoveTouchEventWatcher(this); |
+ } |
+ |
+ private: |
+ // Overridden from views::WidgetDelegate: |
+ views::View* GetContentsView() override { return this; } |
+ base::string16 GetWindowTitle() const override { |
+ // TODO(beng): use resources. |
+ return base::ASCIIToUTF16("TouchHud"); |
+ } |
+ |
+ // Overridden from views::TouchEventWatcher: |
+ void OnTouchEventObserved(const ui::LocatedEvent& event, |
+ views::Widget* target) override { |
+ touch_hud_renderer_->HandleTouchEvent(event); |
+ } |
+ |
+ views::WindowManagerConnection* window_manager_connection_; |
+ views::Widget* widget_; |
+ TouchHudRenderer* touch_hud_renderer_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(TouchHudUI); |
+}; |
+ |
+TouchHudApplication::TouchHudApplication() {} |
+TouchHudApplication::~TouchHudApplication() {} |
+ |
+void TouchHudApplication::OnStart(shell::Connector* connector, |
+ const shell::Identity& identity, |
+ uint32_t id) { |
+ connector_ = connector; |
+ tracing_.Initialize(connector, identity.name()); |
+ |
+ aura_init_.reset(new views::AuraInit(connector, "views_mus_resources.pak")); |
+ |
+ window_manager_connection_ = |
+ views::WindowManagerConnection::Create(connector, identity); |
+} |
+ |
+bool TouchHudApplication::OnConnect(shell::Connection* connection) { |
+ connection->AddInterface<mash::mojom::Launchable>(this); |
+ return true; |
+} |
+ |
+void TouchHudApplication::Launch(uint32_t what, mash::mojom::LaunchMode how) { |
+ if (!widget_) { |
+ // 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.
|
+ widget_ = new views::Widget; |
+ views::Widget::InitParams params( |
+ views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
+ params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; |
+ params.activatable = views::Widget::InitParams::ACTIVATABLE_NO; |
+ params.accept_events = false; |
+ params.delegate = |
+ 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.
|
+ |
+ std::map<std::string, std::vector<uint8_t>> properties; |
+ properties[ash::mojom::kWindowContainer_Property] = |
+ mojo::ConvertTo<std::vector<uint8_t>>( |
+ static_cast<int32_t>(ash::mojom::Container::OVERLAY)); |
+ properties[ui::mojom::WindowManager::kShowState_Property] = |
+ mojo::ConvertTo<std::vector<uint8_t>>( |
+ static_cast<int32_t>(ui::mojom::ShowState::FULLSCREEN)); |
+ ui::Window* window = |
+ views::WindowManagerConnection::Get()->NewWindow(properties); |
+ params.native_widget = new views::NativeWidgetMus( |
+ widget_, connector_, window, ui::mojom::SurfaceType::DEFAULT); |
+ widget_->Init(params); |
+ widget_->Show(); |
+ } else { |
+ // If the keyboard shortcut for disabling touch-hud app is used. |
+ widget_->Close(); |
+ 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.
|
+ } |
+} |
+ |
+void TouchHudApplication::Create(shell::Connection* connection, |
+ mash::mojom::LaunchableRequest request) { |
+ bindings_.AddBinding(this, std::move(request)); |
+} |
+ |
+} // namespace touch_hud |
+} // namespace ash |