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/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 const int AutoclickApplication::kDefaultAutoclickDelayMs = 1000; | |
| 25 | |
| 26 // AutoclickUI handles events to the autoclick app. | |
| 27 class AutoclickUI : public views::WidgetDelegateView, | |
| 28 public views::PointerWatcher { | |
| 29 public: | |
| 30 AutoclickUI(views::WindowManagerConnection* window_manager_connection, | |
| 31 AutoclickControllerCommon* autoclick_controller_common) | |
| 32 : window_manager_connection_(window_manager_connection), | |
| 33 autoclick_controller_common_(autoclick_controller_common) { | |
| 34 window_manager_connection_->pointer_watcher_event_router() | |
| 35 ->AddPointerWatcher(this, true /* want_moves */); | |
| 36 } | |
| 37 ~AutoclickUI() override { | |
| 38 window_manager_connection_->pointer_watcher_event_router() | |
| 39 ->RemovePointerWatcher(this); | |
| 40 } | |
| 41 | |
| 42 private: | |
| 43 // Overridden from views::WidgetDelegate: | |
| 44 views::View* GetContentsView() override { return this; } | |
| 45 base::string16 GetWindowTitle() const override { | |
| 46 // TODO(beng): use resources. | |
| 47 return base::ASCIIToUTF16("Autoclick"); | |
| 48 } | |
| 49 | |
| 50 // Overridden from views::PointerWatcher: | |
| 51 void OnPointerEventObserved(const ui::PointerEvent& event, | |
| 52 const gfx::Point& location_in_screen, | |
| 53 views::Widget* target) override { | |
| 54 if (event.IsTouchPointerEvent()) { | |
| 55 autoclick_controller_common_->CancelAutoclick(); | |
| 56 } else if (event.IsMousePointerEvent()) { | |
| 57 autoclick_controller_common_->HandleMouseEvent(event); | |
| 58 } | |
| 59 } | |
| 60 | |
| 61 views::WindowManagerConnection* window_manager_connection_; | |
| 62 AutoclickControllerCommon* autoclick_controller_common_; | |
| 63 | |
| 64 DISALLOW_COPY_AND_ASSIGN(AutoclickUI); | |
| 65 }; | |
| 66 | |
| 67 AutoclickApplication::AutoclickApplication() | |
| 68 : launchable_binding_(this), autoclick_binding_(this) {} | |
| 69 | |
| 70 AutoclickApplication::~AutoclickApplication() {} | |
| 71 | |
| 72 void AutoclickApplication::OnStart(const shell::Identity& identity) { | |
| 73 aura_init_.reset(new views::AuraInit(connector(), "views_mus_resources.pak")); | |
| 74 window_manager_connection_ = | |
| 75 views::WindowManagerConnection::Create(connector(), identity); | |
| 76 autoclick_controller_common_.reset(new AutoclickControllerCommon( | |
| 77 base::TimeDelta::FromMilliseconds( | |
| 78 static_cast<int64_t>(kDefaultAutoclickDelayMs)), | |
|
sky
2016/09/09 21:42:29
Are you sure you need the cast?
riajiang
2016/09/12 16:15:46
Removed.
| |
| 79 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 widget_->SetOpacity(1.f); | |
|
sky
2016/09/09 21:42:29
This is the default.
riajiang
2016/09/12 16:15:46
Removed.
| |
| 114 } else { | |
| 115 widget_->Close(); | |
| 116 base::MessageLoop::current()->QuitWhenIdle(); | |
| 117 } | |
| 118 } | |
| 119 | |
| 120 void AutoclickApplication::SetAutoclickDelay(int64_t delay_in_milliseconds) { | |
| 121 autoclick_controller_common_->SetAutoclickDelay( | |
| 122 base::TimeDelta::FromMilliseconds(delay_in_milliseconds)); | |
| 123 } | |
| 124 | |
| 125 void AutoclickApplication::Create(const shell::Identity& remote_identity, | |
| 126 mash::mojom::LaunchableRequest request) { | |
| 127 launchable_binding_.Close(); | |
| 128 launchable_binding_.Bind(std::move(request)); | |
| 129 } | |
| 130 | |
| 131 void AutoclickApplication::Create(const shell::Identity& remote_identity, | |
| 132 mojom::AutoclickControllerRequest request) { | |
| 133 autoclick_binding_.Close(); | |
| 134 autoclick_binding_.Bind(std::move(request)); | |
| 135 } | |
| 136 | |
| 137 views::Widget* AutoclickApplication::CreateAutoclickRingWidget( | |
| 138 const gfx::Point& event_location) { | |
| 139 return widget_.get(); | |
| 140 } | |
| 141 | |
| 142 void AutoclickApplication::UpdateAutoclickRingWidget( | |
| 143 views::Widget* widget, | |
| 144 const gfx::Point& event_location) { | |
| 145 // Not used in mus. | |
| 146 } | |
| 147 | |
| 148 void AutoclickApplication::DoAutoclick(const gfx::Point& event_location, | |
| 149 const int mouse_event_flags) { | |
| 150 // TODO(riajiang): Currently not working. Need to know how to generate events | |
| 151 // in mus world (crbug.com/628665). | |
| 152 } | |
| 153 | |
| 154 void AutoclickApplication::OnAutoclickCanceled() { | |
| 155 // Not used in mus. | |
| 156 } | |
| 157 | |
| 158 } // namespace autoclick | |
| 159 } // namespace ash | |
| OLD | NEW |