| 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..6339b46386e45ebcddb2fb202407cdbba6e9fd30
|
| --- /dev/null
|
| +++ b/ash/touch_hud/mus/touch_hud_application.cc
|
| @@ -0,0 +1,112 @@
|
| +// 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 "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),
|
| + 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_;
|
| + TouchHudRenderer* touch_hud_renderer_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(TouchHudUI);
|
| +};
|
| +
|
| +TouchHudApplication::TouchHudApplication() : binding_(this) {}
|
| +TouchHudApplication::~TouchHudApplication() {}
|
| +
|
| +void TouchHudApplication::OnStart(shell::Connector* connector,
|
| + const shell::Identity& identity,
|
| + uint32_t id) {
|
| + connector_ = connector;
|
| + 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_) {
|
| + 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(window_manager_connection_.get(), widget_);
|
| +
|
| + 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 =
|
| + window_manager_connection_.get()->NewWindow(properties);
|
| + params.native_widget = new views::NativeWidgetMus(
|
| + widget_, connector_, window, ui::mojom::SurfaceType::DEFAULT);
|
| + widget_->Init(params);
|
| + widget_->Show();
|
| + } else {
|
| + widget_->Close();
|
| + base::MessageLoop::current()->QuitWhenIdle();
|
| + }
|
| +}
|
| +
|
| +void TouchHudApplication::Create(shell::Connection* connection,
|
| + mash::mojom::LaunchableRequest request) {
|
| + binding_.Bind(std::move(request));
|
| +}
|
| +
|
| +} // namespace touch_hud
|
| +} // namespace ash
|
|
|