Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(283)

Side by Side Diff: ash/autoclick/mus/autoclick_application.cc

Issue 2316553003: mash: Add autoclick app. (Closed)
Patch Set: int, deps etc. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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/autoclick/mus/autoclick_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 "services/shell/public/cpp/connector.h"
11 #include "services/ui/public/cpp/property_type_converters.h"
12 #include "services/ui/public/interfaces/window_manager_constants.mojom.h"
13 #include "ui/views/mus/aura_init.h"
14 #include "ui/views/mus/native_widget_mus.h"
15 #include "ui/views/mus/pointer_watcher_event_router.h"
16 #include "ui/views/mus/window_manager_connection.h"
17 #include "ui/views/pointer_watcher.h"
18 #include "ui/views/widget/widget.h"
19 #include "ui/views/widget/widget_delegate.h"
20
21 namespace ash {
22 namespace autoclick {
23
24 // The default wait time between last mouse movement and sending
25 // the autoclick.
26 const int kDefaultAutoclickDelayMs = 1000;
27
28 // AutoclickUI handles events to the autoclick app.
29 class AutoclickUI : public views::WidgetDelegateView,
30 public views::PointerWatcher {
31 public:
32 AutoclickUI(views::WindowManagerConnection* window_manager_connection,
33 AutoclickControllerCommon* autoclick_controller_common)
34 : window_manager_connection_(window_manager_connection),
35 autoclick_controller_common_(autoclick_controller_common) {
36 window_manager_connection_->pointer_watcher_event_router()
37 ->AddPointerWatcher(this, true /* want_moves */);
38 }
39 ~AutoclickUI() override {
40 window_manager_connection_->pointer_watcher_event_router()
41 ->RemovePointerWatcher(this);
42 }
43
44 private:
45 // Overridden from views::WidgetDelegate:
46 views::View* GetContentsView() override { return this; }
47 base::string16 GetWindowTitle() const override {
48 // TODO(beng): use resources.
49 return base::ASCIIToUTF16("Autoclick");
50 }
51
52 // Overridden from views::PointerWatcher:
53 void OnPointerEventObserved(const ui::PointerEvent& event,
54 const gfx::Point& location_in_screen,
55 views::Widget* target) override {
56 if (event.IsTouchPointerEvent()) {
57 autoclick_controller_common_->CancelAutoclick();
58 } else if (event.IsMousePointerEvent()) {
59 autoclick_controller_common_->HandleMouseEvent(event);
60 }
61 }
62
63 views::WindowManagerConnection* window_manager_connection_;
64 AutoclickControllerCommon* autoclick_controller_common_;
65
66 DISALLOW_COPY_AND_ASSIGN(AutoclickUI);
67 };
68
69 AutoclickApplication::AutoclickApplication()
70 : launchable_binding_(this), autoclick_binding_(this) {}
71
72 AutoclickApplication::~AutoclickApplication() {}
73
74 void AutoclickApplication::OnStart(const shell::Identity& identity) {
75 aura_init_.reset(new views::AuraInit(connector(), "views_mus_resources.pak"));
76 window_manager_connection_ =
77 views::WindowManagerConnection::Create(connector(), identity);
78 autoclick_controller_common_.reset(new AutoclickControllerCommon(
79 base::TimeDelta::FromMilliseconds(kDefaultAutoclickDelayMs), this));
80 }
81
82 bool AutoclickApplication::OnConnect(const shell::Identity& remote_identity,
83 shell::InterfaceRegistry* registry) {
84 registry->AddInterface<mash::mojom::Launchable>(this);
85 registry->AddInterface<mojom::AutoclickController>(this);
86 return true;
87 }
88
89 void AutoclickApplication::Launch(uint32_t what, mash::mojom::LaunchMode how) {
90 if (!widget_) {
91 widget_.reset(new views::Widget);
92 views::Widget::InitParams params(
93 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
94 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
95 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
96 params.activatable = views::Widget::InitParams::ACTIVATABLE_NO;
97 params.accept_events = false;
98 params.delegate = new AutoclickUI(window_manager_connection_.get(),
99 autoclick_controller_common_.get());
100
101 std::map<std::string, std::vector<uint8_t>> properties;
102 properties[ash::mojom::kWindowContainer_Property] =
103 mojo::ConvertTo<std::vector<uint8_t>>(
104 static_cast<int32_t>(ash::mojom::Container::OVERLAY));
105 properties[ui::mojom::WindowManager::kShowState_Property] =
106 mojo::ConvertTo<std::vector<uint8_t>>(
107 static_cast<int32_t>(ui::mojom::ShowState::FULLSCREEN));
108 ui::Window* window =
109 window_manager_connection_.get()->NewWindow(properties);
110 params.native_widget = new views::NativeWidgetMus(
111 widget_.get(), window, ui::mojom::SurfaceType::DEFAULT);
112 widget_->Init(params);
113 } else {
114 widget_->Close();
115 base::MessageLoop::current()->QuitWhenIdle();
116 }
117 }
118
119 void AutoclickApplication::SetAutoclickDelay(int32_t delay_in_milliseconds) {
120 autoclick_controller_common_->SetAutoclickDelay(
121 base::TimeDelta::FromMilliseconds(delay_in_milliseconds));
122 }
123
124 void AutoclickApplication::Create(const shell::Identity& remote_identity,
125 mash::mojom::LaunchableRequest request) {
126 launchable_binding_.Close();
127 launchable_binding_.Bind(std::move(request));
128 }
129
130 void AutoclickApplication::Create(const shell::Identity& remote_identity,
131 mojom::AutoclickControllerRequest request) {
132 autoclick_binding_.Close();
133 autoclick_binding_.Bind(std::move(request));
134 }
135
136 views::Widget* AutoclickApplication::CreateAutoclickRingWidget(
137 const gfx::Point& event_location) {
138 return widget_.get();
139 }
140
141 void AutoclickApplication::UpdateAutoclickRingWidget(
142 views::Widget* widget,
143 const gfx::Point& event_location) {
144 // Not used in mus.
145 }
146
147 void AutoclickApplication::DoAutoclick(const gfx::Point& event_location,
148 const int mouse_event_flags) {
149 // TODO(riajiang): Currently not working. Need to know how to generate events
150 // in mus world (crbug.com/628665).
151 }
152
153 void AutoclickApplication::OnAutoclickCanceled() {
154 // Not used in mus.
155 }
156
157 } // namespace autoclick
158 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698