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