Chromium Code Reviews| 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" | |
|
sadrul
2016/05/17 00:18:48
Is this needed?
Mark Dittmer
2016/05/17 14:18:11
Yes. It provides mus::mojom::EventResult.
| |
| 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 // TODO: figure out what this should be. | 59 // TODO: figure out what this should be. |
| 54 class FocusRulesImpl : public wm::BaseFocusRules { | 60 class FocusRulesImpl : public wm::BaseFocusRules { |
| 55 public: | 61 public: |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 288 // TODO(jamescook): Support other scale factors. | 294 // TODO(jamescook): Support other scale factors. |
| 289 SkBitmap AppIconFromDelegate(WidgetDelegate* delegate) { | 295 SkBitmap AppIconFromDelegate(WidgetDelegate* delegate) { |
| 290 if (!delegate) | 296 if (!delegate) |
| 291 return SkBitmap(); | 297 return SkBitmap(); |
| 292 gfx::ImageSkia app_icon = delegate->GetWindowAppIcon(); | 298 gfx::ImageSkia app_icon = delegate->GetWindowAppIcon(); |
| 293 if (app_icon.isNull()) | 299 if (app_icon.isNull()) |
| 294 return SkBitmap(); | 300 return SkBitmap(); |
| 295 return app_icon.GetRepresentation(1.f).sk_bitmap(); | 301 return app_icon.GetRepresentation(1.f).sk_bitmap(); |
| 296 } | 302 } |
| 297 | 303 |
| 304 // Handles acknowledgement of an input event, either immediately when a nested | |
| 305 // message loop starts, or upon destruction. | |
| 306 class EventAckHandler : public base::MessageLoop::NestingObserver { | |
| 307 public: | |
| 308 explicit EventAckHandler( | |
| 309 std::unique_ptr<base::Callback<void(EventResult)>> ack_callback) | |
| 310 : ack_callback_(std::move(ack_callback)) { | |
| 311 DCHECK(ack_callback_); | |
| 312 base::MessageLoop::current()->AddNestingObserver(this); | |
| 313 } | |
| 314 | |
| 315 ~EventAckHandler() override { | |
| 316 base::MessageLoop::current()->RemoveNestingObserver(this); | |
| 317 if (ack_callback_) { | |
| 318 ack_callback_->Run(handled_ ? EventResult::HANDLED | |
| 319 : EventResult::UNHANDLED); | |
| 320 } | |
| 321 } | |
| 322 | |
| 323 void set_handled(bool handled) { handled_ = handled; } | |
| 324 | |
| 325 // base::MessageLoop::NestingObserver: | |
| 326 void OnBeginNestedMessageLoop() override { | |
| 327 // Acknowledge the event immediately if a nested message loop starts. | |
| 328 // Otherwise we appear unresponsive for the life of the nested message loop. | |
| 329 if (ack_callback_) { | |
| 330 ack_callback_->Run(EventResult::HANDLED); | |
| 331 ack_callback_.reset(); | |
| 332 } | |
| 333 } | |
| 334 | |
| 335 private: | |
| 336 std::unique_ptr<base::Callback<void(EventResult)>> ack_callback_; | |
| 337 bool handled_ = false; | |
| 338 | |
| 339 DISALLOW_COPY_AND_ASSIGN(EventAckHandler); | |
| 340 }; | |
| 341 | |
| 298 } // namespace | 342 } // namespace |
| 299 | 343 |
| 300 class NativeWidgetMus::MusWindowObserver : public mus::WindowObserver { | 344 class NativeWidgetMus::MusWindowObserver : public mus::WindowObserver { |
| 301 public: | 345 public: |
| 302 explicit MusWindowObserver(NativeWidgetMus* native_widget_mus) | 346 explicit MusWindowObserver(NativeWidgetMus* native_widget_mus) |
| 303 : native_widget_mus_(native_widget_mus), | 347 : native_widget_mus_(native_widget_mus), |
| 304 show_state_(mus::mojom::ShowState::DEFAULT) { | 348 show_state_(mus::mojom::ShowState::DEFAULT) { |
| 305 mus_window()->AddObserver(this); | 349 mus_window()->AddObserver(this); |
| 306 } | 350 } |
| 307 | 351 |
| (...skipping 897 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1205 } | 1249 } |
| 1206 | 1250 |
| 1207 void NativeWidgetMus::OnGestureEvent(ui::GestureEvent* event) { | 1251 void NativeWidgetMus::OnGestureEvent(ui::GestureEvent* event) { |
| 1208 native_widget_delegate_->OnGestureEvent(event); | 1252 native_widget_delegate_->OnGestureEvent(event); |
| 1209 } | 1253 } |
| 1210 | 1254 |
| 1211 void NativeWidgetMus::OnHostCloseRequested(const aura::WindowTreeHost* host) { | 1255 void NativeWidgetMus::OnHostCloseRequested(const aura::WindowTreeHost* host) { |
| 1212 GetWidget()->Close(); | 1256 GetWidget()->Close(); |
| 1213 } | 1257 } |
| 1214 | 1258 |
| 1259 void NativeWidgetMus::OnWindowInputEvent( | |
| 1260 mus::Window* view, | |
| 1261 const ui::Event& event_in, | |
| 1262 std::unique_ptr<base::Callback<void(EventResult)>>* ack_callback) { | |
| 1263 // Take ownership of the callback, indicating that we will handle it. | |
| 1264 EventAckHandler ack_handler(std::move(*ack_callback)); | |
| 1265 | |
| 1266 std::unique_ptr<ui::Event> event = ui::Event::Clone(event_in); | |
| 1267 platform_window_delegate()->DispatchEvent(event.get()); | |
| 1268 // NOTE: |this| may be deleted. | |
| 1269 | |
| 1270 ack_handler.set_handled(event->handled()); | |
| 1271 // |ack_handler| acks the event on destruction if necessary. | |
| 1272 } | |
| 1273 | |
| 1215 void NativeWidgetMus::OnMusWindowVisibilityChanging(mus::Window* window) { | 1274 void NativeWidgetMus::OnMusWindowVisibilityChanging(mus::Window* window) { |
| 1216 native_widget_delegate_->OnNativeWidgetVisibilityChanging(!window->visible()); | 1275 native_widget_delegate_->OnNativeWidgetVisibilityChanging(!window->visible()); |
| 1217 } | 1276 } |
| 1218 | 1277 |
| 1219 void NativeWidgetMus::OnMusWindowVisibilityChanged(mus::Window* window) { | 1278 void NativeWidgetMus::OnMusWindowVisibilityChanged(mus::Window* window) { |
| 1220 if (window->visible()) { | 1279 if (window->visible()) { |
| 1221 window_tree_host_->Show(); | 1280 window_tree_host_->Show(); |
| 1222 window_->SetVisible(true); | 1281 window_->SetVisible(true); |
| 1223 GetNativeWindow()->Show(); | 1282 GetNativeWindow()->Show(); |
| 1224 } else { | 1283 } else { |
| 1225 window_tree_host_->Hide(); | 1284 window_tree_host_->Hide(); |
| 1226 window_->SetVisible(false); | 1285 window_->SetVisible(false); |
| 1227 GetNativeWindow()->Hide(); | 1286 GetNativeWindow()->Hide(); |
| 1228 } | 1287 } |
| 1229 native_widget_delegate_->OnNativeWidgetVisibilityChanged(window->visible()); | 1288 native_widget_delegate_->OnNativeWidgetVisibilityChanged(window->visible()); |
| 1230 } | 1289 } |
| 1231 | 1290 |
| 1232 } // namespace views | 1291 } // namespace views |
| OLD | NEW |