| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ash/autoclick/mus/autoclick_application.h" | 5 #include "ash/autoclick/mus/autoclick_application.h" |
| 6 | 6 |
| 7 #include "ash/public/cpp/shell_window_ids.h" | 7 #include "ash/public/cpp/shell_window_ids.h" |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 11 #include "services/service_manager/public/cpp/connector.h" | 11 #include "services/service_manager/public/cpp/connector.h" |
| 12 #include "services/service_manager/public/cpp/service_context.h" | 12 #include "services/service_manager/public/cpp/service_context.h" |
| 13 #include "services/ui/public/cpp/property_type_converters.h" | 13 #include "services/ui/public/cpp/property_type_converters.h" |
| 14 #include "services/ui/public/interfaces/window_manager_constants.mojom.h" | 14 #include "services/ui/public/interfaces/window_manager_constants.mojom.h" |
| 15 #include "ui/aura/mus/property_converter.h" | 15 #include "ui/aura/mus/property_converter.h" |
| 16 #include "ui/base/ui_base_types.h" |
| 16 #include "ui/views/mus/aura_init.h" | 17 #include "ui/views/mus/aura_init.h" |
| 17 #include "ui/views/mus/native_widget_mus.h" | 18 #include "ui/views/mus/mus_client.h" |
| 18 #include "ui/views/mus/pointer_watcher_event_router.h" | 19 #include "ui/views/mus/pointer_watcher_event_router2.h" |
| 19 #include "ui/views/mus/window_manager_connection.h" | |
| 20 #include "ui/views/pointer_watcher.h" | 20 #include "ui/views/pointer_watcher.h" |
| 21 #include "ui/views/widget/widget.h" | 21 #include "ui/views/widget/widget.h" |
| 22 #include "ui/views/widget/widget_delegate.h" | 22 #include "ui/views/widget/widget_delegate.h" |
| 23 | 23 |
| 24 namespace ash { | 24 namespace ash { |
| 25 namespace autoclick { | 25 namespace autoclick { |
| 26 | 26 |
| 27 // The default wait time between last mouse movement and sending | 27 // The default wait time between last mouse movement and sending |
| 28 // the autoclick. | 28 // the autoclick. |
| 29 const int kDefaultAutoclickDelayMs = 1000; | 29 const int kDefaultAutoclickDelayMs = 1000; |
| 30 | 30 |
| 31 // AutoclickUI handles events to the autoclick app. | 31 // AutoclickUI handles events to the autoclick app. |
| 32 class AutoclickUI : public views::WidgetDelegateView, | 32 class AutoclickUI : public views::WidgetDelegateView, |
| 33 public views::PointerWatcher { | 33 public views::PointerWatcher { |
| 34 public: | 34 public: |
| 35 AutoclickUI(views::WindowManagerConnection* window_manager_connection, | 35 explicit AutoclickUI(AutoclickControllerCommon* autoclick_controller_common) |
| 36 AutoclickControllerCommon* autoclick_controller_common) | 36 : autoclick_controller_common_(autoclick_controller_common) { |
| 37 : window_manager_connection_(window_manager_connection), | 37 views::MusClient::Get()->pointer_watcher_event_router()->AddPointerWatcher( |
| 38 autoclick_controller_common_(autoclick_controller_common) { | 38 this, true /* want_moves */); |
| 39 window_manager_connection_->pointer_watcher_event_router() | |
| 40 ->AddPointerWatcher(this, true /* want_moves */); | |
| 41 } | 39 } |
| 42 ~AutoclickUI() override { | 40 ~AutoclickUI() override { |
| 43 window_manager_connection_->pointer_watcher_event_router() | 41 views::MusClient::Get() |
| 42 ->pointer_watcher_event_router() |
| 44 ->RemovePointerWatcher(this); | 43 ->RemovePointerWatcher(this); |
| 45 } | 44 } |
| 46 | 45 |
| 47 private: | 46 private: |
| 48 // Overridden from views::WidgetDelegate: | 47 // Overridden from views::WidgetDelegate: |
| 49 base::string16 GetWindowTitle() const override { | 48 base::string16 GetWindowTitle() const override { |
| 50 // TODO(beng): use resources. | 49 // TODO(beng): use resources. |
| 51 return base::ASCIIToUTF16("Autoclick"); | 50 return base::ASCIIToUTF16("Autoclick"); |
| 52 } | 51 } |
| 53 | 52 |
| 54 // Overridden from views::PointerWatcher: | 53 // Overridden from views::PointerWatcher: |
| 55 void OnPointerEventObserved(const ui::PointerEvent& event, | 54 void OnPointerEventObserved(const ui::PointerEvent& event, |
| 56 const gfx::Point& location_in_screen, | 55 const gfx::Point& location_in_screen, |
| 57 views::Widget* target) override { | 56 views::Widget* target) override { |
| 57 // AutoclickControllerCommon won't work correctly with a target. |
| 58 DCHECK(!event.target()); |
| 58 if (event.IsTouchPointerEvent()) { | 59 if (event.IsTouchPointerEvent()) { |
| 59 autoclick_controller_common_->CancelAutoclick(); | 60 autoclick_controller_common_->CancelAutoclick(); |
| 60 } else if (event.IsMousePointerEvent()) { | 61 } else if (event.IsMousePointerEvent()) { |
| 61 if (event.type() == ui::ET_POINTER_WHEEL_CHANGED) { | 62 if (event.type() == ui::ET_POINTER_WHEEL_CHANGED) { |
| 62 autoclick_controller_common_->HandleMouseEvent( | 63 autoclick_controller_common_->HandleMouseEvent( |
| 63 ui::MouseWheelEvent(event)); | 64 ui::MouseWheelEvent(event)); |
| 64 } else { | 65 } else { |
| 65 autoclick_controller_common_->HandleMouseEvent(ui::MouseEvent(event)); | 66 ui::MouseEvent mouse_event(event); |
| 67 // AutoclickControllerCommon wants screen coordinates when there isn't a |
| 68 // target. |
| 69 mouse_event.set_location(location_in_screen); |
| 70 autoclick_controller_common_->HandleMouseEvent(mouse_event); |
| 66 } | 71 } |
| 67 } | 72 } |
| 68 } | 73 } |
| 69 | 74 |
| 70 views::WindowManagerConnection* window_manager_connection_; | |
| 71 AutoclickControllerCommon* autoclick_controller_common_; | 75 AutoclickControllerCommon* autoclick_controller_common_; |
| 72 | 76 |
| 73 DISALLOW_COPY_AND_ASSIGN(AutoclickUI); | 77 DISALLOW_COPY_AND_ASSIGN(AutoclickUI); |
| 74 }; | 78 }; |
| 75 | 79 |
| 76 AutoclickApplication::AutoclickApplication() | 80 AutoclickApplication::AutoclickApplication() |
| 77 : launchable_binding_(this), autoclick_binding_(this) {} | 81 : launchable_binding_(this), autoclick_binding_(this) {} |
| 78 | 82 |
| 79 AutoclickApplication::~AutoclickApplication() {} | 83 AutoclickApplication::~AutoclickApplication() {} |
| 80 | 84 |
| 81 void AutoclickApplication::OnStart() { | 85 void AutoclickApplication::OnStart() { |
| 82 aura_init_ = base::MakeUnique<views::AuraInit>( | 86 aura_init_ = base::MakeUnique<views::AuraInit>( |
| 83 context()->connector(), context()->identity(), "views_mus_resources.pak"); | 87 context()->connector(), context()->identity(), "views_mus_resources.pak", |
| 84 window_manager_connection_ = views::WindowManagerConnection::Create( | 88 std::string(), nullptr, views::AuraInit::Mode::AURA_MUS); |
| 85 context()->connector(), context()->identity()); | |
| 86 autoclick_controller_common_.reset(new AutoclickControllerCommon( | 89 autoclick_controller_common_.reset(new AutoclickControllerCommon( |
| 87 base::TimeDelta::FromMilliseconds(kDefaultAutoclickDelayMs), this)); | 90 base::TimeDelta::FromMilliseconds(kDefaultAutoclickDelayMs), this)); |
| 88 } | 91 } |
| 89 | 92 |
| 90 bool AutoclickApplication::OnConnect( | 93 bool AutoclickApplication::OnConnect( |
| 91 const service_manager::ServiceInfo& remote_info, | 94 const service_manager::ServiceInfo& remote_info, |
| 92 service_manager::InterfaceRegistry* registry) { | 95 service_manager::InterfaceRegistry* registry) { |
| 93 registry->AddInterface<mash::mojom::Launchable>(this); | 96 registry->AddInterface<mash::mojom::Launchable>(this); |
| 94 registry->AddInterface<mojom::AutoclickController>(this); | 97 registry->AddInterface<mojom::AutoclickController>(this); |
| 95 return true; | 98 return true; |
| 96 } | 99 } |
| 97 | 100 |
| 98 void AutoclickApplication::Launch(uint32_t what, mash::mojom::LaunchMode how) { | 101 void AutoclickApplication::Launch(uint32_t what, mash::mojom::LaunchMode how) { |
| 99 if (!widget_) { | 102 if (!widget_) { |
| 100 widget_.reset(new views::Widget); | 103 widget_.reset(new views::Widget); |
| 101 views::Widget::InitParams params( | 104 views::Widget::InitParams params( |
| 102 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 105 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
| 103 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; | 106 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; |
| 104 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 107 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 105 params.activatable = views::Widget::InitParams::ACTIVATABLE_NO; | 108 params.activatable = views::Widget::InitParams::ACTIVATABLE_NO; |
| 106 params.accept_events = false; | 109 params.accept_events = false; |
| 107 params.delegate = new AutoclickUI(window_manager_connection_.get(), | 110 params.delegate = new AutoclickUI(autoclick_controller_common_.get()); |
| 108 autoclick_controller_common_.get()); | |
| 109 | 111 |
| 110 std::map<std::string, std::vector<uint8_t>> properties; | 112 params.mus_properties[ui::mojom::WindowManager::kContainerId_InitProperty] = |
| 111 properties[ui::mojom::WindowManager::kContainerId_InitProperty] = | |
| 112 mojo::ConvertTo<std::vector<uint8_t>>( | 113 mojo::ConvertTo<std::vector<uint8_t>>( |
| 113 ash::kShellWindowId_OverlayContainer); | 114 ash::kShellWindowId_OverlayContainer); |
| 114 properties[ui::mojom::WindowManager::kShowState_Property] = | 115 params.show_state = ui::SHOW_STATE_FULLSCREEN; |
| 115 mojo::ConvertTo<std::vector<uint8_t>>( | |
| 116 static_cast<aura::PropertyConverter::PrimitiveType>( | |
| 117 ui::mojom::ShowState::FULLSCREEN)); | |
| 118 ui::Window* window = | |
| 119 window_manager_connection_.get()->NewTopLevelWindow(properties); | |
| 120 params.native_widget = new views::NativeWidgetMus( | |
| 121 widget_.get(), window, ui::mojom::CompositorFrameSinkType::DEFAULT); | |
| 122 widget_->Init(params); | 116 widget_->Init(params); |
| 123 } else { | 117 } else { |
| 124 widget_->Close(); | 118 widget_->Close(); |
| 125 base::MessageLoop::current()->QuitWhenIdle(); | 119 base::MessageLoop::current()->QuitWhenIdle(); |
| 126 } | 120 } |
| 127 } | 121 } |
| 128 | 122 |
| 129 void AutoclickApplication::SetAutoclickDelay(uint32_t delay_in_milliseconds) { | 123 void AutoclickApplication::SetAutoclickDelay(uint32_t delay_in_milliseconds) { |
| 130 autoclick_controller_common_->SetAutoclickDelay( | 124 autoclick_controller_common_->SetAutoclickDelay( |
| 131 base::TimeDelta::FromMilliseconds(delay_in_milliseconds)); | 125 base::TimeDelta::FromMilliseconds(delay_in_milliseconds)); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 161 // TODO(riajiang): Currently not working. Need to know how to generate events | 155 // TODO(riajiang): Currently not working. Need to know how to generate events |
| 162 // in mus world (crbug.com/628665). | 156 // in mus world (crbug.com/628665). |
| 163 } | 157 } |
| 164 | 158 |
| 165 void AutoclickApplication::OnAutoclickCanceled() { | 159 void AutoclickApplication::OnAutoclickCanceled() { |
| 166 // Not used in mus. | 160 // Not used in mus. |
| 167 } | 161 } |
| 168 | 162 |
| 169 } // namespace autoclick | 163 } // namespace autoclick |
| 170 } // namespace ash | 164 } // namespace ash |
| OLD | NEW |