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 "mash/touch/touch_hud_application.h" | |
6 | |
7 #include "ash/public/interfaces/container.mojom.h" | |
8 #include "base/macros.h" | |
9 #include "base/strings/utf_string_conversions.h" | |
10 #include "components/mus/public/cpp/property_type_converters.h" | |
11 #include "mojo/public/cpp/bindings/binding.h" | |
12 #include "services/catalog/public/interfaces/catalog.mojom.h" | |
13 #include "services/shell/public/cpp/application_runner.h" | |
14 #include "services/shell/public/cpp/connector.h" | |
15 #include "ui/views/background.h" | |
16 #include "ui/views/controls/touch/touch_hud_drawer.h" | |
17 #include "ui/views/mus/aura_init.h" | |
18 #include "ui/views/mus/native_widget_mus.h" | |
19 #include "ui/views/mus/window_manager_connection.h" | |
20 #include "ui/views/pointer_watcher.h" | |
21 #include "ui/views/widget/widget_delegate.h" | |
22 | |
23 namespace mash { | |
24 namespace touch { | |
25 | |
26 class TouchHudUI : public views::WidgetDelegateView, | |
27 public views::PointerWatcher { | |
28 public: | |
29 TouchHudUI(TouchHudApplication* touch_hud, | |
30 views::WindowManagerConnection& window_manager_connection, | |
31 catalog::mojom::CatalogPtr catalog) | |
32 : touch_hud_(touch_hud), | |
33 window_manager_connection_(window_manager_connection), | |
34 touch_hud_drawer_(new views::TouchHudDrawer), | |
35 catalog_(std::move(catalog)) { | |
36 window_manager_connection_.AddPointerWatcher(this); | |
37 } | |
38 ~TouchHudUI() override { | |
39 window_manager_connection_.RemovePointerWatcher(this); | |
40 touch_hud_->RemoveWindow(GetWidget()); | |
41 } | |
42 | |
43 private: | |
44 // Overridden from views::WidgetDelegate: | |
45 views::View* GetContentsView() override { return this; } | |
46 base::string16 GetWindowTitle() const override { | |
47 // TODO(beng): use resources. | |
48 return base::ASCIIToUTF16("TouchHud"); | |
49 } | |
50 | |
51 // Overridden from views::PointerWatcher: | |
52 void OnMousePressObserved(const ui::MouseEvent& event, | |
53 const gfx::Point& location_in_screen, | |
54 views::Widget* target) override {} | |
55 void OnTouchPressObserved(const ui::TouchEvent& event, | |
56 const gfx::Point& location_in_screen, | |
57 views::Widget* target) override { | |
58 touch_hud_drawer_->HandleTouchEvent(&event, target); | |
59 } | |
60 void OnTouchReleaseObserved(const ui::TouchEvent& event, | |
61 const gfx::Point& location_in_screen, | |
62 views::Widget* target) override { | |
63 touch_hud_drawer_->HandleTouchEvent(&event, target); | |
64 } | |
65 void OnTouchMoveObserved(const ui::TouchEvent& event, | |
66 const gfx::Point& location_in_screen, | |
67 views::Widget* target) override { | |
68 touch_hud_drawer_->HandleTouchEvent(&event, target); | |
69 } | |
70 void OnTouchCancellObserved(const ui::TouchEvent& event, | |
71 const gfx::Point& location_in_screen, | |
72 views::Widget* target) override { | |
73 touch_hud_drawer_->HandleTouchEvent(&event, target); | |
74 } | |
75 | |
76 TouchHudApplication* touch_hud_; | |
77 views::WindowManagerConnection& window_manager_connection_; | |
78 views::TouchHudDrawer* touch_hud_drawer_; | |
79 catalog::mojom::CatalogPtr catalog_; | |
80 | |
81 DISALLOW_COPY_AND_ASSIGN(TouchHudUI); | |
82 }; | |
83 | |
84 TouchHudApplication::TouchHudApplication() {} | |
85 TouchHudApplication::~TouchHudApplication() {} | |
86 | |
87 void TouchHudApplication::RemoveWindow(views::Widget* window) { | |
88 auto it = std::find(windows_.begin(), windows_.end(), window); | |
89 DCHECK(it != windows_.end()); | |
90 windows_.erase(it); | |
91 if (windows_.empty()) | |
92 base::MessageLoop::current()->QuitWhenIdle(); | |
93 } | |
94 | |
95 void TouchHudApplication::Initialize(shell::Connector* connector, | |
96 const shell::Identity& identity, | |
97 uint32_t id) { | |
98 connector_ = connector; | |
99 tracing_.Initialize(connector, identity.name()); | |
100 | |
101 aura_init_.reset(new views::AuraInit(connector, "views_mus_resources.pak")); | |
102 | |
103 window_manager_connection_ = | |
104 views::WindowManagerConnection::Create(connector, identity); | |
105 } | |
106 | |
107 bool TouchHudApplication::AcceptConnection(shell::Connection* connection) { | |
108 connection->AddInterface<mojom::Launchable>(this); | |
109 return true; | |
110 } | |
111 | |
112 void TouchHudApplication::Launch(uint32_t what, mojom::LaunchMode how) { | |
113 bool reuse = how == mojom::LaunchMode::REUSE || | |
114 how == mojom::LaunchMode::DEFAULT; | |
115 if (reuse && !windows_.empty()) { | |
116 windows_.back()->Activate(); | |
117 return; | |
118 } | |
119 | |
120 shell::mojom::ShellPtr shell; | |
121 connector_->ConnectToInterface("mojo:shell", &shell); | |
122 | |
123 catalog::mojom::CatalogPtr catalog; | |
124 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.
| |
125 | |
126 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.
| |
127 views::Widget* widget = new views::Widget; | |
128 views::Widget::InitParams params( | |
129 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | |
130 params.opacity = views::Widget::InitParams::OPAQUE_WINDOW; | |
131 // params.activatable = views::Widget::InitParams::ACTIVATABLE_NO; | |
132 // params.accept_events = false; | |
133 params.delegate = new TouchHudUI(this, *window_manager_connection_, | |
134 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.
| |
135 | |
136 std::map<std::string, std::vector<uint8_t>> properties; | |
137 properties[ash::mojom::kWindowContainer_Property] = | |
138 mojo::ConvertTo<std::vector<uint8_t>>( | |
139 static_cast<int32_t>(ash::mojom::Container::OVERLAY)); | |
140 mus::Window* window = | |
141 views::WindowManagerConnection::Get()->NewWindow(properties); | |
142 params.native_widget = new views::NativeWidgetMus( | |
143 widget, connector_, window, mus::mojom::SurfaceType::DEFAULT); | |
144 widget->Init(params); | |
145 widget->Show(); | |
146 windows_.push_back(widget); | |
147 touch_hud_enabled = true; | |
148 } else { | |
149 touch_hud_enabled = false; | |
150 } | |
151 } | |
152 | |
153 void TouchHudApplication::Create(shell::Connection* connection, | |
154 mojom::LaunchableRequest request) { | |
155 bindings_.AddBinding(this, std::move(request)); | |
156 } | |
157 | |
158 } // namespace touch | |
159 } // namespace mash | |
OLD | NEW |