Index: mash/touch/touch_hud_application.cc |
diff --git a/mash/touch/touch_hud_application.cc b/mash/touch/touch_hud_application.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..61b3be32dfffd53bf5e16a849ec795b325119f9d |
--- /dev/null |
+++ b/mash/touch/touch_hud_application.cc |
@@ -0,0 +1,159 @@ |
+// 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 "mash/touch/touch_hud_application.h" |
+ |
+#include "ash/public/interfaces/container.mojom.h" |
+#include "base/macros.h" |
+#include "base/strings/utf_string_conversions.h" |
+#include "components/mus/public/cpp/property_type_converters.h" |
+#include "mojo/public/cpp/bindings/binding.h" |
+#include "services/catalog/public/interfaces/catalog.mojom.h" |
+#include "services/shell/public/cpp/application_runner.h" |
+#include "services/shell/public/cpp/connector.h" |
+#include "ui/views/background.h" |
+#include "ui/views/controls/touch/touch_hud_drawer.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/pointer_watcher.h" |
+#include "ui/views/widget/widget_delegate.h" |
+ |
+namespace mash { |
+namespace touch { |
+ |
+class TouchHudUI : public views::WidgetDelegateView, |
+ public views::PointerWatcher { |
+ public: |
+ TouchHudUI(TouchHudApplication* touch_hud, |
+ views::WindowManagerConnection& window_manager_connection, |
+ catalog::mojom::CatalogPtr catalog) |
+ : touch_hud_(touch_hud), |
+ window_manager_connection_(window_manager_connection), |
+ touch_hud_drawer_(new views::TouchHudDrawer), |
+ catalog_(std::move(catalog)) { |
+ window_manager_connection_.AddPointerWatcher(this); |
+ } |
+ ~TouchHudUI() override { |
+ window_manager_connection_.RemovePointerWatcher(this); |
+ touch_hud_->RemoveWindow(GetWidget()); |
+ } |
+ |
+ 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::PointerWatcher: |
+ void OnMousePressObserved(const ui::MouseEvent& event, |
+ const gfx::Point& location_in_screen, |
+ views::Widget* target) override {} |
+ void OnTouchPressObserved(const ui::TouchEvent& event, |
+ const gfx::Point& location_in_screen, |
+ views::Widget* target) override { |
+ touch_hud_drawer_->HandleTouchEvent(&event, target); |
+ } |
+ void OnTouchReleaseObserved(const ui::TouchEvent& event, |
+ const gfx::Point& location_in_screen, |
+ views::Widget* target) override { |
+ touch_hud_drawer_->HandleTouchEvent(&event, target); |
+ } |
+ void OnTouchMoveObserved(const ui::TouchEvent& event, |
+ const gfx::Point& location_in_screen, |
+ views::Widget* target) override { |
+ touch_hud_drawer_->HandleTouchEvent(&event, target); |
+ } |
+ void OnTouchCancellObserved(const ui::TouchEvent& event, |
+ const gfx::Point& location_in_screen, |
+ views::Widget* target) override { |
+ touch_hud_drawer_->HandleTouchEvent(&event, target); |
+ } |
+ |
+ TouchHudApplication* touch_hud_; |
+ views::WindowManagerConnection& window_manager_connection_; |
+ views::TouchHudDrawer* touch_hud_drawer_; |
+ catalog::mojom::CatalogPtr catalog_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(TouchHudUI); |
+}; |
+ |
+TouchHudApplication::TouchHudApplication() {} |
+TouchHudApplication::~TouchHudApplication() {} |
+ |
+void TouchHudApplication::RemoveWindow(views::Widget* window) { |
+ auto it = std::find(windows_.begin(), windows_.end(), window); |
+ DCHECK(it != windows_.end()); |
+ windows_.erase(it); |
+ if (windows_.empty()) |
+ base::MessageLoop::current()->QuitWhenIdle(); |
+} |
+ |
+void TouchHudApplication::Initialize(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::AcceptConnection(shell::Connection* connection) { |
+ connection->AddInterface<mojom::Launchable>(this); |
+ return true; |
+} |
+ |
+void TouchHudApplication::Launch(uint32_t what, mojom::LaunchMode how) { |
+ bool reuse = how == mojom::LaunchMode::REUSE || |
+ how == mojom::LaunchMode::DEFAULT; |
+ if (reuse && !windows_.empty()) { |
+ windows_.back()->Activate(); |
+ return; |
+ } |
+ |
+ shell::mojom::ShellPtr shell; |
+ connector_->ConnectToInterface("mojo:shell", &shell); |
+ |
+ catalog::mojom::CatalogPtr catalog; |
+ connector_->ConnectToInterface("mojo:catalog", &catalog); |
sadrul
2016/06/27 14:44:54
You don't need this.
riajiang
2016/06/28 21:52:51
Done.
|
+ |
+ if (!touch_hud_enabled) { |
sadrul
2016/06/27 14:44:54
You don't need |touch_hud_enabled_|. You can just
riajiang
2016/06/28 21:52:51
Done and done.
|
+ views::Widget* widget = new views::Widget; |
+ views::Widget::InitParams params( |
+ views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
+ params.opacity = views::Widget::InitParams::OPAQUE_WINDOW; |
+ // params.activatable = views::Widget::InitParams::ACTIVATABLE_NO; |
+ // params.accept_events = false; |
+ params.delegate = new TouchHudUI(this, *window_manager_connection_, |
+ std::move(catalog)); |
sadrul
2016/06/27 14:44:54
Try setting params.bounds to something (e.g. gfx::
riajiang
2016/06/28 21:52:51
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)); |
+ mus::Window* window = |
+ views::WindowManagerConnection::Get()->NewWindow(properties); |
+ params.native_widget = new views::NativeWidgetMus( |
+ widget, connector_, window, mus::mojom::SurfaceType::DEFAULT); |
+ widget->Init(params); |
+ widget->Show(); |
+ windows_.push_back(widget); |
+ touch_hud_enabled = true; |
+ } else { |
+ touch_hud_enabled = false; |
+ } |
+} |
+ |
+void TouchHudApplication::Create(shell::Connection* connection, |
+ mojom::LaunchableRequest request) { |
+ bindings_.AddBinding(this, std::move(request)); |
+} |
+ |
+} // namespace touch |
+} // namespace mash |