Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(260)

Side by Side Diff: ui/views/mus/native_widget_mus.cc

Issue 2323553002: mash: Use the new mus drag and drop API to get drag working in mash. (Closed)
Patch Set: Patch cleanup Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <utility>
8 #include <vector>
9
7 #include "base/callback.h" 10 #include "base/callback.h"
8 #include "base/macros.h" 11 #include "base/macros.h"
9 #include "base/message_loop/message_loop.h" 12 #include "base/message_loop/message_loop.h"
10 #include "base/run_loop.h" 13 #include "base/run_loop.h"
11 #include "base/threading/thread_task_runner_handle.h" 14 #include "base/threading/thread_task_runner_handle.h"
12 #include "services/ui/public/cpp/property_type_converters.h" 15 #include "services/ui/public/cpp/property_type_converters.h"
13 #include "services/ui/public/cpp/window.h" 16 #include "services/ui/public/cpp/window.h"
14 #include "services/ui/public/cpp/window_observer.h" 17 #include "services/ui/public/cpp/window_observer.h"
15 #include "services/ui/public/cpp/window_property.h" 18 #include "services/ui/public/cpp/window_property.h"
16 #include "services/ui/public/cpp/window_tree_client.h" 19 #include "services/ui/public/cpp/window_tree_client.h"
17 #include "services/ui/public/interfaces/cursor.mojom.h" 20 #include "services/ui/public/interfaces/cursor.mojom.h"
18 #include "services/ui/public/interfaces/window_manager.mojom.h" 21 #include "services/ui/public/interfaces/window_manager.mojom.h"
19 #include "services/ui/public/interfaces/window_manager_constants.mojom.h" 22 #include "services/ui/public/interfaces/window_manager_constants.mojom.h"
20 #include "services/ui/public/interfaces/window_tree.mojom.h" 23 #include "services/ui/public/interfaces/window_tree.mojom.h"
21 #include "ui/aura/client/default_capture_client.h" 24 #include "ui/aura/client/default_capture_client.h"
22 #include "ui/aura/client/window_tree_client.h" 25 #include "ui/aura/client/window_tree_client.h"
23 #include "ui/aura/layout_manager.h" 26 #include "ui/aura/layout_manager.h"
24 #include "ui/aura/mus/mus_util.h" 27 #include "ui/aura/mus/mus_util.h"
25 #include "ui/aura/window.h" 28 #include "ui/aura/window.h"
26 #include "ui/aura/window_property.h" 29 #include "ui/aura/window_property.h"
27 #include "ui/base/hit_test.h" 30 #include "ui/base/hit_test.h"
28 #include "ui/display/display.h" 31 #include "ui/display/display.h"
29 #include "ui/display/screen.h" 32 #include "ui/display/screen.h"
30 #include "ui/events/event.h" 33 #include "ui/events/event.h"
31 #include "ui/gfx/canvas.h" 34 #include "ui/gfx/canvas.h"
32 #include "ui/gfx/path.h" 35 #include "ui/gfx/path.h"
33 #include "ui/native_theme/native_theme_aura.h" 36 #include "ui/native_theme/native_theme_aura.h"
34 #include "ui/platform_window/platform_window_delegate.h" 37 #include "ui/platform_window/platform_window_delegate.h"
38 #include "ui/views/drag_utils.h"
39 #include "ui/views/mus/drag_drop_client_mus.h"
40 #include "ui/views/mus/drop_target_mus.h"
35 #include "ui/views/mus/window_manager_connection.h" 41 #include "ui/views/mus/window_manager_connection.h"
36 #include "ui/views/mus/window_manager_constants_converters.h" 42 #include "ui/views/mus/window_manager_constants_converters.h"
37 #include "ui/views/mus/window_manager_frame_values.h" 43 #include "ui/views/mus/window_manager_frame_values.h"
38 #include "ui/views/mus/window_tree_host_mus.h" 44 #include "ui/views/mus/window_tree_host_mus.h"
45 #include "ui/views/widget/drop_helper.h"
39 #include "ui/views/widget/native_widget_aura.h" 46 #include "ui/views/widget/native_widget_aura.h"
40 #include "ui/views/widget/widget_delegate.h" 47 #include "ui/views/widget/widget_delegate.h"
41 #include "ui/views/window/custom_frame_view.h" 48 #include "ui/views/window/custom_frame_view.h"
42 #include "ui/wm/core/base_focus_rules.h" 49 #include "ui/wm/core/base_focus_rules.h"
43 #include "ui/wm/core/capture_controller.h" 50 #include "ui/wm/core/capture_controller.h"
44 #include "ui/wm/core/cursor_manager.h" 51 #include "ui/wm/core/cursor_manager.h"
45 #include "ui/wm/core/default_screen_position_client.h" 52 #include "ui/wm/core/default_screen_position_client.h"
46 #include "ui/wm/core/focus_controller.h" 53 #include "ui/wm/core/focus_controller.h"
47 #include "ui/wm/core/native_cursor_manager.h" 54 #include "ui/wm/core/native_cursor_manager.h"
48 55
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 if (mus_window) 96 if (mus_window)
90 mus_window->SetFocus(); 97 mus_window->SetFocus();
91 } 98 }
92 } 99 }
93 100
94 DISALLOW_COPY_AND_ASSIGN(FocusControllerMus); 101 DISALLOW_COPY_AND_ASSIGN(FocusControllerMus);
95 }; 102 };
96 103
97 class ContentWindowLayoutManager : public aura::LayoutManager { 104 class ContentWindowLayoutManager : public aura::LayoutManager {
98 public: 105 public:
99 ContentWindowLayoutManager(aura::Window* outer, aura::Window* inner) 106 ContentWindowLayoutManager(aura::Window* outer, aura::Window* inner)
100 : outer_(outer), inner_(inner) {} 107 : outer_(outer), inner_(inner) {}
101 ~ContentWindowLayoutManager() override {} 108 ~ContentWindowLayoutManager() override {}
102 109
103 private: 110 private:
104 // aura::LayoutManager: 111 // aura::LayoutManager:
105 void OnWindowResized() override { inner_->SetBounds(outer_->bounds()); } 112 void OnWindowResized() override { inner_->SetBounds(outer_->bounds()); }
106 void OnWindowAddedToLayout(aura::Window* child) override { 113 void OnWindowAddedToLayout(aura::Window* child) override {
107 OnWindowResized(); 114 OnWindowResized();
108 } 115 }
109 void OnWillRemoveWindowFromLayout(aura::Window* child) override {} 116 void OnWillRemoveWindowFromLayout(aura::Window* child) override {}
110 void OnWindowRemovedFromLayout(aura::Window* child) override {} 117 void OnWindowRemovedFromLayout(aura::Window* child) override {}
111 void OnChildWindowVisibilityChanged(aura::Window* child, 118 void OnChildWindowVisibilityChanged(aura::Window* child,
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 NativeWidgetMus::NativeWidgetMus(internal::NativeWidgetDelegate* delegate, 523 NativeWidgetMus::NativeWidgetMus(internal::NativeWidgetDelegate* delegate,
517 ui::Window* window, 524 ui::Window* window,
518 ui::mojom::SurfaceType surface_type) 525 ui::mojom::SurfaceType surface_type)
519 : window_(window), 526 : window_(window),
520 last_cursor_(ui::mojom::Cursor::CURSOR_NULL), 527 last_cursor_(ui::mojom::Cursor::CURSOR_NULL),
521 native_widget_delegate_(delegate), 528 native_widget_delegate_(delegate),
522 surface_type_(surface_type), 529 surface_type_(surface_type),
523 show_state_before_fullscreen_(ui::mojom::ShowState::DEFAULT), 530 show_state_before_fullscreen_(ui::mojom::ShowState::DEFAULT),
524 ownership_(Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET), 531 ownership_(Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET),
525 content_(new aura::Window(this)), 532 content_(new aura::Window(this)),
533 last_drop_operation_(ui::DragDropTypes::DRAG_NONE),
526 close_widget_factory_(this) { 534 close_widget_factory_(this) {
527 window_->set_input_event_handler(this); 535 window_->set_input_event_handler(this);
528 mus_window_observer_.reset(new MusWindowObserver(this)); 536 mus_window_observer_.reset(new MusWindowObserver(this));
529 537
530 // TODO(fsamuel): Figure out lifetime of |window_|. 538 // TODO(fsamuel): Figure out lifetime of |window_|.
531 aura::SetMusWindow(content_, window_); 539 aura::SetMusWindow(content_, window_);
532 window->SetLocalProperty(kNativeWidgetMusKey, this); 540 window->SetLocalProperty(kNativeWidgetMusKey, this);
533 window_tree_host_.reset(new WindowTreeHostMus(this, window_)); 541 window_tree_host_.reset(new WindowTreeHostMus(this, window_));
534 } 542 }
535 543
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
697 705
698 focus_client_.reset( 706 focus_client_.reset(
699 new FocusControllerMus(new FocusRulesImpl(hosted_window))); 707 new FocusControllerMus(new FocusRulesImpl(hosted_window)));
700 708
701 aura::client::SetFocusClient(hosted_window, focus_client_.get()); 709 aura::client::SetFocusClient(hosted_window, focus_client_.get());
702 aura::client::SetActivationClient(hosted_window, focus_client_.get()); 710 aura::client::SetActivationClient(hosted_window, focus_client_.get());
703 screen_position_client_.reset(new ScreenPositionClientMus(window_)); 711 screen_position_client_.reset(new ScreenPositionClientMus(window_));
704 aura::client::SetScreenPositionClient(hosted_window, 712 aura::client::SetScreenPositionClient(hosted_window,
705 screen_position_client_.get()); 713 screen_position_client_.get());
706 714
715 drop_target_.reset(new DropTargetMus(content_));
sky 2016/09/23 16:14:09 MakeUnique
Elliot Glaysher 2016/09/23 21:40:48 Changed entire file to use MakeUnique.
716 window_->SetCanAcceptDrops(drop_target_.get());
717 drop_helper_.reset(new DropHelper(GetWidget()->GetRootView()));
sky 2016/09/23 16:14:09 MakeUnique
718 aura::client::SetDragDropDelegate(content_, this);
719
707 // TODO(erg): Remove this check when ash/mus/move_event_handler.cc's 720 // TODO(erg): Remove this check when ash/mus/move_event_handler.cc's
708 // direct usage of ui::Window::SetPredefinedCursor() is switched to a 721 // direct usage of ui::Window::SetPredefinedCursor() is switched to a
709 // private method on WindowManagerClient. 722 // private method on WindowManagerClient.
710 if (!is_parallel_widget_in_window_manager()) { 723 if (!is_parallel_widget_in_window_manager()) {
711 cursor_manager_.reset(new wm::CursorManager( 724 cursor_manager_.reset(new wm::CursorManager(
712 base::MakeUnique<NativeCursorManagerMus>(window_))); 725 base::MakeUnique<NativeCursorManagerMus>(window_)));
713 aura::client::SetCursorClient(hosted_window, cursor_manager_.get()); 726 aura::client::SetCursorClient(hosted_window, cursor_manager_.get());
714 } 727 }
715 728
716 window_tree_client_.reset(new NativeWidgetMusWindowTreeClient(hosted_window)); 729 window_tree_client_.reset(new NativeWidgetMusWindowTreeClient(hosted_window));
(...skipping 19 matching lines...) Expand all
736 parent_mus->AddTransientWindow(window_); 749 parent_mus->AddTransientWindow(window_);
737 } 750 }
738 751
739 if (params.parent_mus) 752 if (params.parent_mus)
740 params.parent_mus->AddChild(window_); 753 params.parent_mus->AddChild(window_);
741 754
742 // TODO(sky): deal with show state. 755 // TODO(sky): deal with show state.
743 if (!params.bounds.size().IsEmpty()) 756 if (!params.bounds.size().IsEmpty())
744 SetBounds(params.bounds); 757 SetBounds(params.bounds);
745 758
759 if (!params.parent) {
sky 2016/09/23 16:14:09 I'm unclear as to why you don't create this for ev
Elliot Glaysher 2016/09/23 21:40:48 I'm not sure I believe that this is true. It appe
sky 2016/09/26 02:12:59 See line 541, which creates the WindowTreeHost whi
Elliot Glaysher 2016/09/26 20:57:29 Disabled the test as discussed in person.
760 // On the desktop, we initialize some aura::clients on only the root
761 // window; DesktopNativeWidgetAura and NativeWidgetAura do different
762 // things. When we make a DesktopNativeWidgetMus (and that should be the
763 // root NativeWidget in programs other than the window manager), these
764 // should go there.
765 drag_drop_client_.reset(new DragDropClientMus(content_, window_));
sky 2016/09/23 16:14:09 MakeUnique
766 aura::client::SetDragDropClient(hosted_window, drag_drop_client_.get());
767 }
768
746 // TODO(beng): much else, see [Desktop]NativeWidgetAura. 769 // TODO(beng): much else, see [Desktop]NativeWidgetAura.
747 770
748 native_widget_delegate_->OnNativeWidgetCreated(false); 771 native_widget_delegate_->OnNativeWidgetCreated(false);
749 } 772 }
750 773
751 void NativeWidgetMus::OnWidgetInitDone() { 774 void NativeWidgetMus::OnWidgetInitDone() {
752 // The client area is calculated from the NonClientView. During 775 // The client area is calculated from the NonClientView. During
753 // InitNativeWidget() the NonClientView has not been created. When this 776 // InitNativeWidget() the NonClientView has not been created. When this
754 // function is called the NonClientView has been created, so that we can 777 // function is called the NonClientView has been created, so that we can
755 // correctly calculate the client area and push it to the ui::Window. 778 // correctly calculate the client area and push it to the ui::Window.
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after
1143 1166
1144 void NativeWidgetMus::SetOpacity(float opacity) { 1167 void NativeWidgetMus::SetOpacity(float opacity) {
1145 if (window_) 1168 if (window_)
1146 window_->SetOpacity(opacity); 1169 window_->SetOpacity(opacity);
1147 } 1170 }
1148 1171
1149 void NativeWidgetMus::FlashFrame(bool flash_frame) { 1172 void NativeWidgetMus::FlashFrame(bool flash_frame) {
1150 // NOTIMPLEMENTED(); 1173 // NOTIMPLEMENTED();
1151 } 1174 }
1152 1175
1153 void NativeWidgetMus::RunShellDrag( 1176 void NativeWidgetMus::RunShellDrag(View* view,
1154 View* view, 1177 const ui::OSExchangeData& data,
1155 const ui::OSExchangeData& data, 1178 const gfx::Point& location,
1156 const gfx::Point& location, 1179 int drag_operations,
1157 int operation, 1180 ui::DragDropTypes::DragEventSource source) {
1158 ui::DragDropTypes::DragEventSource source) { 1181 if (window_)
1159 // NOTIMPLEMENTED(); 1182 views::RunShellDrag(content_, data, location, drag_operations, source);
1160 } 1183 }
1161 1184
1162 void NativeWidgetMus::SchedulePaintInRect(const gfx::Rect& rect) { 1185 void NativeWidgetMus::SchedulePaintInRect(const gfx::Rect& rect) {
1163 if (content_) 1186 if (content_)
1164 content_->SchedulePaintInRect(rect); 1187 content_->SchedulePaintInRect(rect);
1165 } 1188 }
1166 1189
1167 void NativeWidgetMus::SetCursor(gfx::NativeCursor cursor) { 1190 void NativeWidgetMus::SetCursor(gfx::NativeCursor cursor) {
1168 if (!window_) 1191 if (!window_)
1169 return; 1192 return;
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
1403 1426
1404 void NativeWidgetMus::OnHostMoved(const aura::WindowTreeHost* host, 1427 void NativeWidgetMus::OnHostMoved(const aura::WindowTreeHost* host,
1405 const gfx::Point& new_origin) { 1428 const gfx::Point& new_origin) {
1406 native_widget_delegate_->OnNativeWidgetMove(); 1429 native_widget_delegate_->OnNativeWidgetMove();
1407 } 1430 }
1408 1431
1409 void NativeWidgetMus::OnHostCloseRequested(const aura::WindowTreeHost* host) { 1432 void NativeWidgetMus::OnHostCloseRequested(const aura::WindowTreeHost* host) {
1410 GetWidget()->Close(); 1433 GetWidget()->Close();
1411 } 1434 }
1412 1435
1436 ////////////////////////////////////////////////////////////////////////////////
1437 // NativeWidgetMus, aura::WindowDragDropDelegate implementation:
1438
1439 void NativeWidgetMus::OnDragEntered(const ui::DropTargetEvent& event) {
1440 DCHECK(drop_helper_);
1441 last_drop_operation_ = drop_helper_->OnDragOver(
1442 event.data(), event.location(), event.source_operations());
1443 }
1444
1445 int NativeWidgetMus::OnDragUpdated(const ui::DropTargetEvent& event) {
1446 DCHECK(drop_helper_);
1447 last_drop_operation_ = drop_helper_->OnDragOver(
1448 event.data(), event.location(), event.source_operations());
1449 return last_drop_operation_;
1450 }
1451
1452 void NativeWidgetMus::OnDragExited() {
1453 DCHECK(drop_helper_);
1454 drop_helper_->OnDragExit();
1455 }
1456
1457 int NativeWidgetMus::OnPerformDrop(const ui::DropTargetEvent& event) {
1458 DCHECK(drop_helper_);
1459 return drop_helper_->OnDrop(event.data(), event.location(),
1460 last_drop_operation_);
1461 }
1462
1463 ////////////////////////////////////////////////////////////////////////////////
1464 // NativeWidgetMus, ui::InputEventHandler implementation:
1465
1413 void NativeWidgetMus::OnWindowInputEvent( 1466 void NativeWidgetMus::OnWindowInputEvent(
1414 ui::Window* view, 1467 ui::Window* view,
1415 const ui::Event& event_in, 1468 const ui::Event& event_in,
1416 std::unique_ptr<base::Callback<void(EventResult)>>* ack_callback) { 1469 std::unique_ptr<base::Callback<void(EventResult)>>* ack_callback) {
1417 // Take ownership of the callback, indicating that we will handle it. 1470 // Take ownership of the callback, indicating that we will handle it.
1418 EventAckHandler ack_handler(std::move(*ack_callback)); 1471 EventAckHandler ack_handler(std::move(*ack_callback));
1419 1472
1420 std::unique_ptr<ui::Event> event = ui::Event::Clone(event_in); 1473 std::unique_ptr<ui::Event> event = ui::Event::Clone(event_in);
1421 // TODO(markdittmer): This should be this->OnEvent(event.get()), but that 1474 // TODO(markdittmer): This should be this->OnEvent(event.get()), but that
1422 // can't happen until IME is refactored out of in WindowTreeHostMus. 1475 // can't happen until IME is refactored out of in WindowTreeHostMus.
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1461 1514
1462 gfx::Path mask_path; 1515 gfx::Path mask_path;
1463 native_widget_delegate_->GetHitTestMask(&mask_path); 1516 native_widget_delegate_->GetHitTestMask(&mask_path);
1464 // TODO(jamescook): Use the full path for the mask. 1517 // TODO(jamescook): Use the full path for the mask.
1465 gfx::Rect mask_rect = 1518 gfx::Rect mask_rect =
1466 gfx::ToEnclosingRect(gfx::SkRectToRectF(mask_path.getBounds())); 1519 gfx::ToEnclosingRect(gfx::SkRectToRectF(mask_path.getBounds()));
1467 window_->SetHitTestMask(mask_rect); 1520 window_->SetHitTestMask(mask_rect);
1468 } 1521 }
1469 1522
1470 } // namespace views 1523 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698