| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "ui/views/mus/native_widget_mus.h" | 5 #include "ui/views/mus/native_widget_mus.h" |
| 6 | 6 |
| 7 #include "base/callback.h" |
| 7 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/message_loop/message_loop.h" |
| 8 #include "base/threading/thread_task_runner_handle.h" | 10 #include "base/threading/thread_task_runner_handle.h" |
| 9 #include "components/mus/public/cpp/property_type_converters.h" | 11 #include "components/mus/public/cpp/property_type_converters.h" |
| 10 #include "components/mus/public/cpp/window.h" | 12 #include "components/mus/public/cpp/window.h" |
| 11 #include "components/mus/public/cpp/window_observer.h" | 13 #include "components/mus/public/cpp/window_observer.h" |
| 12 #include "components/mus/public/cpp/window_property.h" | 14 #include "components/mus/public/cpp/window_property.h" |
| 13 #include "components/mus/public/cpp/window_tree_connection.h" | 15 #include "components/mus/public/cpp/window_tree_connection.h" |
| 14 #include "components/mus/public/interfaces/cursor.mojom.h" | 16 #include "components/mus/public/interfaces/cursor.mojom.h" |
| 15 #include "components/mus/public/interfaces/window_manager.mojom.h" | 17 #include "components/mus/public/interfaces/window_manager.mojom.h" |
| 16 #include "components/mus/public/interfaces/window_manager_constants.mojom.h" | 18 #include "components/mus/public/interfaces/window_manager_constants.mojom.h" |
| 19 #include "components/mus/public/interfaces/window_tree.mojom.h" |
| 17 #include "mojo/converters/geometry/geometry_type_converters.h" | 20 #include "mojo/converters/geometry/geometry_type_converters.h" |
| 18 #include "ui/aura/client/default_capture_client.h" | 21 #include "ui/aura/client/default_capture_client.h" |
| 19 #include "ui/aura/client/window_tree_client.h" | 22 #include "ui/aura/client/window_tree_client.h" |
| 20 #include "ui/aura/env.h" | 23 #include "ui/aura/env.h" |
| 21 #include "ui/aura/layout_manager.h" | 24 #include "ui/aura/layout_manager.h" |
| 22 #include "ui/aura/mus/mus_util.h" | 25 #include "ui/aura/mus/mus_util.h" |
| 23 #include "ui/aura/window.h" | 26 #include "ui/aura/window.h" |
| 24 #include "ui/aura/window_property.h" | 27 #include "ui/aura/window_property.h" |
| 25 #include "ui/base/hit_test.h" | 28 #include "ui/base/hit_test.h" |
| 29 #include "ui/events/event.h" |
| 26 #include "ui/gfx/canvas.h" | 30 #include "ui/gfx/canvas.h" |
| 27 #include "ui/native_theme/native_theme_aura.h" | 31 #include "ui/native_theme/native_theme_aura.h" |
| 28 #include "ui/platform_window/platform_window_delegate.h" | 32 #include "ui/platform_window/platform_window_delegate.h" |
| 29 #include "ui/views/mus/platform_window_mus.h" | 33 #include "ui/views/mus/platform_window_mus.h" |
| 30 #include "ui/views/mus/surface_context_factory.h" | 34 #include "ui/views/mus/surface_context_factory.h" |
| 31 #include "ui/views/mus/window_manager_constants_converters.h" | 35 #include "ui/views/mus/window_manager_constants_converters.h" |
| 32 #include "ui/views/mus/window_manager_frame_values.h" | 36 #include "ui/views/mus/window_manager_frame_values.h" |
| 33 #include "ui/views/mus/window_tree_host_mus.h" | 37 #include "ui/views/mus/window_tree_host_mus.h" |
| 34 #include "ui/views/widget/native_widget_aura.h" | 38 #include "ui/views/widget/native_widget_aura.h" |
| 35 #include "ui/views/widget/widget_delegate.h" | 39 #include "ui/views/widget/widget_delegate.h" |
| 36 #include "ui/views/window/custom_frame_view.h" | 40 #include "ui/views/window/custom_frame_view.h" |
| 37 #include "ui/wm/core/base_focus_rules.h" | 41 #include "ui/wm/core/base_focus_rules.h" |
| 38 #include "ui/wm/core/capture_controller.h" | 42 #include "ui/wm/core/capture_controller.h" |
| 39 #include "ui/wm/core/cursor_manager.h" | 43 #include "ui/wm/core/cursor_manager.h" |
| 40 #include "ui/wm/core/default_screen_position_client.h" | 44 #include "ui/wm/core/default_screen_position_client.h" |
| 41 #include "ui/wm/core/focus_controller.h" | 45 #include "ui/wm/core/focus_controller.h" |
| 42 #include "ui/wm/core/native_cursor_manager.h" | 46 #include "ui/wm/core/native_cursor_manager.h" |
| 43 | 47 |
| 44 DECLARE_WINDOW_PROPERTY_TYPE(mus::Window*); | 48 DECLARE_WINDOW_PROPERTY_TYPE(mus::Window*); |
| 45 | 49 |
| 50 using mus::mojom::EventResult; |
| 51 |
| 46 namespace views { | 52 namespace views { |
| 47 namespace { | 53 namespace { |
| 48 | 54 |
| 49 DEFINE_WINDOW_PROPERTY_KEY(mus::Window*, kMusWindow, nullptr); | 55 DEFINE_WINDOW_PROPERTY_KEY(mus::Window*, kMusWindow, nullptr); |
| 50 | 56 |
| 51 MUS_DEFINE_WINDOW_PROPERTY_KEY(NativeWidgetMus*, kNativeWidgetMusKey, nullptr); | 57 MUS_DEFINE_WINDOW_PROPERTY_KEY(NativeWidgetMus*, kNativeWidgetMusKey, nullptr); |
| 52 | 58 |
| 53 // This ensures that only the top-level aura Window can be activated. | 59 // This ensures that only the top-level aura Window can be activated. |
| 54 class FocusRulesImpl : public wm::BaseFocusRules { | 60 class FocusRulesImpl : public wm::BaseFocusRules { |
| 55 public: | 61 public: |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 // TODO(jamescook): Support other scale factors. | 296 // TODO(jamescook): Support other scale factors. |
| 291 SkBitmap AppIconFromDelegate(WidgetDelegate* delegate) { | 297 SkBitmap AppIconFromDelegate(WidgetDelegate* delegate) { |
| 292 if (!delegate) | 298 if (!delegate) |
| 293 return SkBitmap(); | 299 return SkBitmap(); |
| 294 gfx::ImageSkia app_icon = delegate->GetWindowAppIcon(); | 300 gfx::ImageSkia app_icon = delegate->GetWindowAppIcon(); |
| 295 if (app_icon.isNull()) | 301 if (app_icon.isNull()) |
| 296 return SkBitmap(); | 302 return SkBitmap(); |
| 297 return app_icon.GetRepresentation(1.f).sk_bitmap(); | 303 return app_icon.GetRepresentation(1.f).sk_bitmap(); |
| 298 } | 304 } |
| 299 | 305 |
| 306 // Handles acknowledgement of an input event, either immediately when a nested |
| 307 // message loop starts, or upon destruction. |
| 308 class EventAckHandler : public base::MessageLoop::NestingObserver { |
| 309 public: |
| 310 explicit EventAckHandler( |
| 311 std::unique_ptr<base::Callback<void(EventResult)>> ack_callback) |
| 312 : ack_callback_(std::move(ack_callback)) { |
| 313 DCHECK(ack_callback_); |
| 314 base::MessageLoop::current()->AddNestingObserver(this); |
| 315 } |
| 316 |
| 317 ~EventAckHandler() override { |
| 318 base::MessageLoop::current()->RemoveNestingObserver(this); |
| 319 if (ack_callback_) { |
| 320 ack_callback_->Run(handled_ ? EventResult::HANDLED |
| 321 : EventResult::UNHANDLED); |
| 322 } |
| 323 } |
| 324 |
| 325 void set_handled(bool handled) { handled_ = handled; } |
| 326 |
| 327 // base::MessageLoop::NestingObserver: |
| 328 void OnBeginNestedMessageLoop() override { |
| 329 // Acknowledge the event immediately if a nested message loop starts. |
| 330 // Otherwise we appear unresponsive for the life of the nested message loop. |
| 331 if (ack_callback_) { |
| 332 ack_callback_->Run(EventResult::HANDLED); |
| 333 ack_callback_.reset(); |
| 334 } |
| 335 } |
| 336 |
| 337 private: |
| 338 std::unique_ptr<base::Callback<void(EventResult)>> ack_callback_; |
| 339 bool handled_ = false; |
| 340 |
| 341 DISALLOW_COPY_AND_ASSIGN(EventAckHandler); |
| 342 }; |
| 343 |
| 300 } // namespace | 344 } // namespace |
| 301 | 345 |
| 302 class NativeWidgetMus::MusWindowObserver : public mus::WindowObserver { | 346 class NativeWidgetMus::MusWindowObserver : public mus::WindowObserver { |
| 303 public: | 347 public: |
| 304 explicit MusWindowObserver(NativeWidgetMus* native_widget_mus) | 348 explicit MusWindowObserver(NativeWidgetMus* native_widget_mus) |
| 305 : native_widget_mus_(native_widget_mus), | 349 : native_widget_mus_(native_widget_mus), |
| 306 show_state_(mus::mojom::ShowState::DEFAULT) { | 350 show_state_(mus::mojom::ShowState::DEFAULT) { |
| 307 mus_window()->AddObserver(this); | 351 mus_window()->AddObserver(this); |
| 308 } | 352 } |
| 309 | 353 |
| (...skipping 902 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1212 } | 1256 } |
| 1213 | 1257 |
| 1214 void NativeWidgetMus::OnGestureEvent(ui::GestureEvent* event) { | 1258 void NativeWidgetMus::OnGestureEvent(ui::GestureEvent* event) { |
| 1215 native_widget_delegate_->OnGestureEvent(event); | 1259 native_widget_delegate_->OnGestureEvent(event); |
| 1216 } | 1260 } |
| 1217 | 1261 |
| 1218 void NativeWidgetMus::OnHostCloseRequested(const aura::WindowTreeHost* host) { | 1262 void NativeWidgetMus::OnHostCloseRequested(const aura::WindowTreeHost* host) { |
| 1219 GetWidget()->Close(); | 1263 GetWidget()->Close(); |
| 1220 } | 1264 } |
| 1221 | 1265 |
| 1266 void NativeWidgetMus::OnWindowInputEvent( |
| 1267 mus::Window* view, |
| 1268 const ui::Event& event_in, |
| 1269 std::unique_ptr<base::Callback<void(EventResult)>>* ack_callback) { |
| 1270 // Take ownership of the callback, indicating that we will handle it. |
| 1271 EventAckHandler ack_handler(std::move(*ack_callback)); |
| 1272 |
| 1273 std::unique_ptr<ui::Event> event = ui::Event::Clone(event_in); |
| 1274 // TODO(markdittmer): This should be this->OnEvent(event.get()), but that |
| 1275 // can't happen until IME is refactored out of in WindowTreeHostMus. |
| 1276 platform_window_delegate()->DispatchEvent(event.get()); |
| 1277 // NOTE: |this| may be deleted. |
| 1278 |
| 1279 ack_handler.set_handled(event->handled()); |
| 1280 // |ack_handler| acks the event on destruction if necessary. |
| 1281 } |
| 1282 |
| 1222 void NativeWidgetMus::OnMusWindowVisibilityChanging(mus::Window* window) { | 1283 void NativeWidgetMus::OnMusWindowVisibilityChanging(mus::Window* window) { |
| 1223 native_widget_delegate_->OnNativeWidgetVisibilityChanging(!window->visible()); | 1284 native_widget_delegate_->OnNativeWidgetVisibilityChanging(!window->visible()); |
| 1224 } | 1285 } |
| 1225 | 1286 |
| 1226 void NativeWidgetMus::OnMusWindowVisibilityChanged(mus::Window* window) { | 1287 void NativeWidgetMus::OnMusWindowVisibilityChanged(mus::Window* window) { |
| 1227 if (window->visible()) { | 1288 if (window->visible()) { |
| 1228 window_tree_host_->Show(); | 1289 window_tree_host_->Show(); |
| 1229 window_->SetVisible(true); | 1290 window_->SetVisible(true); |
| 1230 GetNativeWindow()->Show(); | 1291 GetNativeWindow()->Show(); |
| 1231 } else { | 1292 } else { |
| 1232 window_tree_host_->Hide(); | 1293 window_tree_host_->Hide(); |
| 1233 window_->SetVisible(false); | 1294 window_->SetVisible(false); |
| 1234 GetNativeWindow()->Hide(); | 1295 GetNativeWindow()->Hide(); |
| 1235 } | 1296 } |
| 1236 native_widget_delegate_->OnNativeWidgetVisibilityChanged(window->visible()); | 1297 native_widget_delegate_->OnNativeWidgetVisibilityChanged(window->visible()); |
| 1237 } | 1298 } |
| 1238 | 1299 |
| 1239 } // namespace views | 1300 } // namespace views |
| OLD | NEW |