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/callback.h" |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/run_loop.h" |
10 #include "base/threading/thread_task_runner_handle.h" | 11 #include "base/threading/thread_task_runner_handle.h" |
11 #include "components/bitmap_uploader/bitmap_uploader.h" | 12 #include "components/bitmap_uploader/bitmap_uploader.h" |
12 #include "services/ui/common/gpu_service.h" | 13 #include "services/ui/common/gpu_service.h" |
13 #include "services/ui/public/cpp/property_type_converters.h" | 14 #include "services/ui/public/cpp/property_type_converters.h" |
14 #include "services/ui/public/cpp/window.h" | 15 #include "services/ui/public/cpp/window.h" |
15 #include "services/ui/public/cpp/window_observer.h" | 16 #include "services/ui/public/cpp/window_observer.h" |
16 #include "services/ui/public/cpp/window_property.h" | 17 #include "services/ui/public/cpp/window_property.h" |
17 #include "services/ui/public/cpp/window_tree_client.h" | 18 #include "services/ui/public/cpp/window_tree_client.h" |
18 #include "services/ui/public/interfaces/cursor.mojom.h" | 19 #include "services/ui/public/interfaces/cursor.mojom.h" |
19 #include "services/ui/public/interfaces/window_manager.mojom.h" | 20 #include "services/ui/public/interfaces/window_manager.mojom.h" |
20 #include "services/ui/public/interfaces/window_manager_constants.mojom.h" | 21 #include "services/ui/public/interfaces/window_manager_constants.mojom.h" |
21 #include "services/ui/public/interfaces/window_tree.mojom.h" | 22 #include "services/ui/public/interfaces/window_tree.mojom.h" |
22 #include "ui/aura/client/default_capture_client.h" | 23 #include "ui/aura/client/default_capture_client.h" |
23 #include "ui/aura/client/window_tree_client.h" | 24 #include "ui/aura/client/window_tree_client.h" |
24 #include "ui/aura/env.h" | 25 #include "ui/aura/env.h" |
25 #include "ui/aura/layout_manager.h" | 26 #include "ui/aura/layout_manager.h" |
26 #include "ui/aura/mus/mus_util.h" | 27 #include "ui/aura/mus/mus_util.h" |
27 #include "ui/aura/window.h" | 28 #include "ui/aura/window.h" |
28 #include "ui/aura/window_property.h" | 29 #include "ui/aura/window_property.h" |
29 #include "ui/base/hit_test.h" | 30 #include "ui/base/hit_test.h" |
30 #include "ui/base/view_prop.h" | 31 #include "ui/base/view_prop.h" |
31 #include "ui/display/display.h" | 32 #include "ui/display/display.h" |
32 #include "ui/display/screen.h" | 33 #include "ui/display/screen.h" |
| 34 #include "ui/display/screen.h" |
33 #include "ui/events/event.h" | 35 #include "ui/events/event.h" |
34 #include "ui/gfx/canvas.h" | 36 #include "ui/gfx/canvas.h" |
35 #include "ui/gfx/path.h" | 37 #include "ui/gfx/path.h" |
36 #include "ui/native_theme/native_theme_aura.h" | 38 #include "ui/native_theme/native_theme_aura.h" |
37 #include "ui/platform_window/platform_window_delegate.h" | 39 #include "ui/platform_window/platform_window_delegate.h" |
38 #include "ui/views/mus/surface_context_factory.h" | 40 #include "ui/views/mus/surface_context_factory.h" |
39 #include "ui/views/mus/window_manager_constants_converters.h" | 41 #include "ui/views/mus/window_manager_constants_converters.h" |
40 #include "ui/views/mus/window_manager_frame_values.h" | 42 #include "ui/views/mus/window_manager_frame_values.h" |
41 #include "ui/views/mus/window_tree_host_mus.h" | 43 #include "ui/views/mus/window_tree_host_mus.h" |
42 #include "ui/views/widget/native_widget_aura.h" | 44 #include "ui/views/widget/native_widget_aura.h" |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 // TODO(jamescook): Support other scale factors. | 323 // TODO(jamescook): Support other scale factors. |
322 SkBitmap AppIconFromDelegate(WidgetDelegate* delegate) { | 324 SkBitmap AppIconFromDelegate(WidgetDelegate* delegate) { |
323 if (!delegate) | 325 if (!delegate) |
324 return SkBitmap(); | 326 return SkBitmap(); |
325 gfx::ImageSkia app_icon = delegate->GetWindowAppIcon(); | 327 gfx::ImageSkia app_icon = delegate->GetWindowAppIcon(); |
326 if (app_icon.isNull()) | 328 if (app_icon.isNull()) |
327 return SkBitmap(); | 329 return SkBitmap(); |
328 return app_icon.GetRepresentation(1.f).sk_bitmap(); | 330 return app_icon.GetRepresentation(1.f).sk_bitmap(); |
329 } | 331 } |
330 | 332 |
331 // Handles acknowledgement of an input event, either immediately when a nested | 333 // Handles acknowledgment of an input event, either immediately when a nested |
332 // message loop starts, or upon destruction. | 334 // message loop starts, or upon destruction. |
333 class EventAckHandler : public base::MessageLoop::NestingObserver { | 335 class EventAckHandler : public base::MessageLoop::NestingObserver { |
334 public: | 336 public: |
335 explicit EventAckHandler( | 337 explicit EventAckHandler( |
336 std::unique_ptr<base::Callback<void(EventResult)>> ack_callback) | 338 std::unique_ptr<base::Callback<void(EventResult)>> ack_callback) |
337 : ack_callback_(std::move(ack_callback)) { | 339 : ack_callback_(std::move(ack_callback)) { |
338 DCHECK(ack_callback_); | 340 DCHECK(ack_callback_); |
339 base::MessageLoop::current()->AddNestingObserver(this); | 341 base::MessageLoop::current()->AddNestingObserver(this); |
340 } | 342 } |
341 | 343 |
(...skipping 17 matching lines...) Expand all Loading... |
359 } | 361 } |
360 } | 362 } |
361 | 363 |
362 private: | 364 private: |
363 std::unique_ptr<base::Callback<void(EventResult)>> ack_callback_; | 365 std::unique_ptr<base::Callback<void(EventResult)>> ack_callback_; |
364 bool handled_ = false; | 366 bool handled_ = false; |
365 | 367 |
366 DISALLOW_COPY_AND_ASSIGN(EventAckHandler); | 368 DISALLOW_COPY_AND_ASSIGN(EventAckHandler); |
367 }; | 369 }; |
368 | 370 |
| 371 void OnMoveLoopEnd(bool* out_success, |
| 372 base::Closure quit_closure, |
| 373 bool in_success) { |
| 374 *out_success = in_success; |
| 375 quit_closure.Run(); |
| 376 } |
| 377 |
369 } // namespace | 378 } // namespace |
370 | 379 |
371 class NativeWidgetMus::MusWindowObserver : public ui::WindowObserver { | 380 class NativeWidgetMus::MusWindowObserver : public ui::WindowObserver { |
372 public: | 381 public: |
373 explicit MusWindowObserver(NativeWidgetMus* native_widget_mus) | 382 explicit MusWindowObserver(NativeWidgetMus* native_widget_mus) |
374 : native_widget_mus_(native_widget_mus), | 383 : native_widget_mus_(native_widget_mus), |
375 show_state_(ui::mojom::ShowState::DEFAULT) { | 384 show_state_(ui::mojom::ShowState::DEFAULT) { |
376 mus_window()->AddObserver(this); | 385 mus_window()->AddObserver(this); |
377 } | 386 } |
378 | 387 |
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
800 // NOTIMPLEMENTED(); | 809 // NOTIMPLEMENTED(); |
801 } | 810 } |
802 | 811 |
803 // These methods are wrong in mojo. They're not usually used to associate | 812 // These methods are wrong in mojo. They're not usually used to associate |
804 // data with a window; they are used exclusively in chrome/ to unsafely pass | 813 // data with a window; they are used exclusively in chrome/ to unsafely pass |
805 // raw pointers around. I can only find two places where we do the "safe" | 814 // raw pointers around. I can only find two places where we do the "safe" |
806 // thing (and even that requires casting an integer to a void*). They can't be | 815 // thing (and even that requires casting an integer to a void*). They can't be |
807 // used safely in a world where we separate things with mojo. They should be | 816 // used safely in a world where we separate things with mojo. They should be |
808 // removed; not ported. | 817 // removed; not ported. |
809 void NativeWidgetMus::SetNativeWindowProperty(const char* name, void* value) { | 818 void NativeWidgetMus::SetNativeWindowProperty(const char* name, void* value) { |
810 // TODO(beng): push properties to ui::Window. | 819 native_window_properties_[name] = value; |
811 // NOTIMPLEMENTED(); | |
812 } | 820 } |
813 | 821 |
814 void* NativeWidgetMus::GetNativeWindowProperty(const char* name) const { | 822 void* NativeWidgetMus::GetNativeWindowProperty(const char* name) const { |
815 // TODO(beng): pull properties to ui::Window. | 823 auto it = native_window_properties_.find(name); |
816 // NOTIMPLEMENTED(); | 824 if (it == native_window_properties_.end()) |
817 return nullptr; | 825 return nullptr; |
| 826 return it->second; |
818 } | 827 } |
819 | 828 |
820 TooltipManager* NativeWidgetMus::GetTooltipManager() const { | 829 TooltipManager* NativeWidgetMus::GetTooltipManager() const { |
821 // NOTIMPLEMENTED(); | 830 // NOTIMPLEMENTED(); |
822 return nullptr; | 831 return nullptr; |
823 } | 832 } |
824 | 833 |
825 void NativeWidgetMus::SetCapture() { | 834 void NativeWidgetMus::SetCapture() { |
826 if (content_) | 835 if (content_) |
827 content_->SetCapture(); | 836 content_->SetCapture(); |
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1162 | 1171 |
1163 gfx::Rect NativeWidgetMus::GetWorkAreaBoundsInScreen() const { | 1172 gfx::Rect NativeWidgetMus::GetWorkAreaBoundsInScreen() const { |
1164 // NOTIMPLEMENTED(); | 1173 // NOTIMPLEMENTED(); |
1165 return gfx::Rect(); | 1174 return gfx::Rect(); |
1166 } | 1175 } |
1167 | 1176 |
1168 Widget::MoveLoopResult NativeWidgetMus::RunMoveLoop( | 1177 Widget::MoveLoopResult NativeWidgetMus::RunMoveLoop( |
1169 const gfx::Vector2d& drag_offset, | 1178 const gfx::Vector2d& drag_offset, |
1170 Widget::MoveLoopSource source, | 1179 Widget::MoveLoopSource source, |
1171 Widget::MoveLoopEscapeBehavior escape_behavior) { | 1180 Widget::MoveLoopEscapeBehavior escape_behavior) { |
1172 // NOTIMPLEMENTED(); | 1181 ReleaseCapture(); |
1173 return Widget::MOVE_LOOP_CANCELED; | 1182 |
| 1183 base::MessageLoopForUI* loop = base::MessageLoopForUI::current(); |
| 1184 base::MessageLoop::ScopedNestableTaskAllower allow_nested(loop); |
| 1185 base::RunLoop run_loop; |
| 1186 |
| 1187 ui::mojom::MoveLoopSource mus_source = |
| 1188 source == Widget::MOVE_LOOP_SOURCE_MOUSE |
| 1189 ? ui::mojom::MoveLoopSource::MOUSE |
| 1190 : ui::mojom::MoveLoopSource::TOUCH; |
| 1191 |
| 1192 bool success = false; |
| 1193 gfx::Point cursor_location = |
| 1194 display::Screen::GetScreen()->GetCursorScreenPoint(); |
| 1195 window_->PerformWindowMove( |
| 1196 mus_source, cursor_location, |
| 1197 base::Bind(OnMoveLoopEnd, &success, run_loop.QuitClosure())); |
| 1198 |
| 1199 run_loop.Run(); |
| 1200 |
| 1201 return success ? Widget::MOVE_LOOP_SUCCESSFUL : Widget::MOVE_LOOP_CANCELED; |
1174 } | 1202 } |
1175 | 1203 |
1176 void NativeWidgetMus::EndMoveLoop() { | 1204 void NativeWidgetMus::EndMoveLoop() { |
1177 // NOTIMPLEMENTED(); | 1205 window_->CancelWindowMove(); |
1178 } | 1206 } |
1179 | 1207 |
1180 void NativeWidgetMus::SetVisibilityChangedAnimationsEnabled(bool value) { | 1208 void NativeWidgetMus::SetVisibilityChangedAnimationsEnabled(bool value) { |
1181 // NOTIMPLEMENTED(); | 1209 // NOTIMPLEMENTED(); |
1182 } | 1210 } |
1183 | 1211 |
1184 void NativeWidgetMus::SetVisibilityAnimationDuration( | 1212 void NativeWidgetMus::SetVisibilityAnimationDuration( |
1185 const base::TimeDelta& duration) { | 1213 const base::TimeDelta& duration) { |
1186 // NOTIMPLEMENTED(); | 1214 // NOTIMPLEMENTED(); |
1187 } | 1215 } |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1227 gfx::Size NativeWidgetMus::GetMinimumSize() const { | 1255 gfx::Size NativeWidgetMus::GetMinimumSize() const { |
1228 return native_widget_delegate_->GetMinimumSize(); | 1256 return native_widget_delegate_->GetMinimumSize(); |
1229 } | 1257 } |
1230 | 1258 |
1231 gfx::Size NativeWidgetMus::GetMaximumSize() const { | 1259 gfx::Size NativeWidgetMus::GetMaximumSize() const { |
1232 return native_widget_delegate_->GetMaximumSize(); | 1260 return native_widget_delegate_->GetMaximumSize(); |
1233 } | 1261 } |
1234 | 1262 |
1235 void NativeWidgetMus::OnBoundsChanged(const gfx::Rect& old_bounds, | 1263 void NativeWidgetMus::OnBoundsChanged(const gfx::Rect& old_bounds, |
1236 const gfx::Rect& new_bounds) { | 1264 const gfx::Rect& new_bounds) { |
1237 // Assume that if the old bounds was completely empty a move happened. This | 1265 // This is handled in OnHost{Resized,Moved}() like DesktopNativeWidgetAura |
1238 // handles the case of a maximize animation acquiring the layer (acquiring a | 1266 // instead of here like in NativeWidgetAura. |
1239 // layer results in clearing the bounds). | |
1240 if (old_bounds.origin() != new_bounds.origin() || | |
1241 (old_bounds == gfx::Rect(0, 0, 0, 0) && !new_bounds.IsEmpty())) { | |
1242 native_widget_delegate_->OnNativeWidgetMove(); | |
1243 } | |
1244 if (old_bounds.size() != new_bounds.size()) { | |
1245 native_widget_delegate_->OnNativeWidgetSizeChanged(new_bounds.size()); | |
1246 UpdateClientArea(); | |
1247 UpdateHitTestMask(); | |
1248 } | |
1249 } | 1267 } |
1250 | 1268 |
1251 gfx::NativeCursor NativeWidgetMus::GetCursor(const gfx::Point& point) { | 1269 gfx::NativeCursor NativeWidgetMus::GetCursor(const gfx::Point& point) { |
1252 return gfx::NativeCursor(); | 1270 return gfx::NativeCursor(); |
1253 } | 1271 } |
1254 | 1272 |
1255 int NativeWidgetMus::GetNonClientComponent(const gfx::Point& point) const { | 1273 int NativeWidgetMus::GetNonClientComponent(const gfx::Point& point) const { |
1256 return native_widget_delegate_->GetNonClientComponent(point); | 1274 return native_widget_delegate_->GetNonClientComponent(point); |
1257 } | 1275 } |
1258 | 1276 |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1341 event->SetHandled(); | 1359 event->SetHandled(); |
1342 } else { | 1360 } else { |
1343 native_widget_delegate_->OnScrollEvent(event); | 1361 native_widget_delegate_->OnScrollEvent(event); |
1344 } | 1362 } |
1345 } | 1363 } |
1346 | 1364 |
1347 void NativeWidgetMus::OnGestureEvent(ui::GestureEvent* event) { | 1365 void NativeWidgetMus::OnGestureEvent(ui::GestureEvent* event) { |
1348 native_widget_delegate_->OnGestureEvent(event); | 1366 native_widget_delegate_->OnGestureEvent(event); |
1349 } | 1367 } |
1350 | 1368 |
| 1369 void NativeWidgetMus::OnHostResized(const aura::WindowTreeHost* host) { |
| 1370 native_widget_delegate_->OnNativeWidgetSizeChanged( |
| 1371 host->window()->bounds().size()); |
| 1372 UpdateClientArea(); |
| 1373 UpdateHitTestMask(); |
| 1374 } |
| 1375 |
| 1376 void NativeWidgetMus::OnHostMoved(const aura::WindowTreeHost* host, |
| 1377 const gfx::Point& new_origin) { |
| 1378 native_widget_delegate_->OnNativeWidgetMove(); |
| 1379 } |
| 1380 |
1351 void NativeWidgetMus::OnHostCloseRequested(const aura::WindowTreeHost* host) { | 1381 void NativeWidgetMus::OnHostCloseRequested(const aura::WindowTreeHost* host) { |
1352 GetWidget()->Close(); | 1382 GetWidget()->Close(); |
1353 } | 1383 } |
1354 | 1384 |
1355 void NativeWidgetMus::OnWindowInputEvent( | 1385 void NativeWidgetMus::OnWindowInputEvent( |
1356 ui::Window* view, | 1386 ui::Window* view, |
1357 const ui::Event& event_in, | 1387 const ui::Event& event_in, |
1358 std::unique_ptr<base::Callback<void(EventResult)>>* ack_callback) { | 1388 std::unique_ptr<base::Callback<void(EventResult)>>* ack_callback) { |
1359 // Take ownership of the callback, indicating that we will handle it. | 1389 // Take ownership of the callback, indicating that we will handle it. |
1360 EventAckHandler ack_handler(std::move(*ack_callback)); | 1390 EventAckHandler ack_handler(std::move(*ack_callback)); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1403 | 1433 |
1404 gfx::Path mask_path; | 1434 gfx::Path mask_path; |
1405 native_widget_delegate_->GetHitTestMask(&mask_path); | 1435 native_widget_delegate_->GetHitTestMask(&mask_path); |
1406 // TODO(jamescook): Use the full path for the mask. | 1436 // TODO(jamescook): Use the full path for the mask. |
1407 gfx::Rect mask_rect = | 1437 gfx::Rect mask_rect = |
1408 gfx::ToEnclosingRect(gfx::SkRectToRectF(mask_path.getBounds())); | 1438 gfx::ToEnclosingRect(gfx::SkRectToRectF(mask_path.getBounds())); |
1409 window_->SetHitTestMask(mask_rect); | 1439 window_->SetHitTestMask(mask_rect); |
1410 } | 1440 } |
1411 | 1441 |
1412 } // namespace views | 1442 } // namespace views |
OLD | NEW |