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

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: comments 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
« no previous file with comments | « ui/views/mus/native_widget_mus.h ('k') | ui/views/mus/os_exchange_data_provider_mus.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_ = base::MakeUnique<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_ = base::MakeUnique<WindowTreeHostMus>(this, window_);
534 } 542 }
535 543
536 NativeWidgetMus::~NativeWidgetMus() { 544 NativeWidgetMus::~NativeWidgetMus() {
537 if (ownership_ == Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET) { 545 if (ownership_ == Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET) {
538 DCHECK(!window_); 546 DCHECK(!window_);
539 delete native_widget_delegate_; 547 delete native_widget_delegate_;
540 } else { 548 } else {
541 if (window_) 549 if (window_)
542 window_->set_input_event_handler(nullptr); 550 window_->set_input_event_handler(nullptr);
543 CloseNow(); 551 CloseNow();
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
688 window_tree_host_->InitHost(); 696 window_tree_host_->InitHost();
689 hosted_window->SetProperty(kMusWindow, window_); 697 hosted_window->SetProperty(kMusWindow, window_);
690 698
691 // TODO(moshayedi): crbug.com/641039. Investigate whether there are any cases 699 // TODO(moshayedi): crbug.com/641039. Investigate whether there are any cases
692 // where we need input method but don't have the WindowManagerConnection here. 700 // where we need input method but don't have the WindowManagerConnection here.
693 if (WindowManagerConnection::Exists()) { 701 if (WindowManagerConnection::Exists()) {
694 window_tree_host_->InitInputMethod( 702 window_tree_host_->InitInputMethod(
695 WindowManagerConnection::Get()->connector()); 703 WindowManagerConnection::Get()->connector());
696 } 704 }
697 705
698 focus_client_.reset( 706 focus_client_ =
699 new FocusControllerMus(new FocusRulesImpl(hosted_window))); 707 base::MakeUnique<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_ = base::MakeUnique<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 drag_drop_client_ = base::MakeUnique<DragDropClientMus>(window_);
716 aura::client::SetDragDropClient(hosted_window, drag_drop_client_.get());
717 drop_target_ = base::MakeUnique<DropTargetMus>(content_);
718 window_->SetCanAcceptDrops(drop_target_.get());
719 drop_helper_ = base::MakeUnique<DropHelper>(GetWidget()->GetRootView());
720 aura::client::SetDragDropDelegate(content_, this);
721
707 // TODO(erg): Remove this check when ash/mus/move_event_handler.cc's 722 // TODO(erg): Remove this check when ash/mus/move_event_handler.cc's
708 // direct usage of ui::Window::SetPredefinedCursor() is switched to a 723 // direct usage of ui::Window::SetPredefinedCursor() is switched to a
709 // private method on WindowManagerClient. 724 // private method on WindowManagerClient.
710 if (!is_parallel_widget_in_window_manager()) { 725 if (!is_parallel_widget_in_window_manager()) {
711 cursor_manager_.reset(new wm::CursorManager( 726 cursor_manager_ = base::MakeUnique<wm::CursorManager>(
712 base::MakeUnique<NativeCursorManagerMus>(window_))); 727 base::MakeUnique<NativeCursorManagerMus>(window_));
713 aura::client::SetCursorClient(hosted_window, cursor_manager_.get()); 728 aura::client::SetCursorClient(hosted_window, cursor_manager_.get());
714 } 729 }
715 730
716 window_tree_client_.reset(new NativeWidgetMusWindowTreeClient(hosted_window)); 731 window_tree_client_ =
732 base::MakeUnique<NativeWidgetMusWindowTreeClient>(hosted_window);
717 hosted_window->AddPreTargetHandler(focus_client_.get()); 733 hosted_window->AddPreTargetHandler(focus_client_.get());
718 hosted_window->SetLayoutManager( 734 hosted_window->SetLayoutManager(
719 new ContentWindowLayoutManager(hosted_window, content_)); 735 new ContentWindowLayoutManager(hosted_window, content_));
720 capture_client_.reset(new MusCaptureClient(hosted_window, content_, window_)); 736 capture_client_ =
737 base::MakeUnique<MusCaptureClient>(hosted_window, content_, window_);
721 738
722 content_->SetType(ui::wm::WINDOW_TYPE_NORMAL); 739 content_->SetType(ui::wm::WINDOW_TYPE_NORMAL);
723 content_->Init(params.layer_type); 740 content_->Init(params.layer_type);
724 if (window_->visible()) 741 if (window_->visible())
725 content_->Show(); 742 content_->Show();
726 content_->SetTransparent(true); 743 content_->SetTransparent(true);
727 content_->SetFillsBoundsCompletely(false); 744 content_->SetFillsBoundsCompletely(false);
728 content_->set_ignore_events(!params.accept_events); 745 content_->set_ignore_events(!params.accept_events);
729 hosted_window->AddChild(content_); 746 hosted_window->AddChild(content_);
730 747
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after
1143 1160
1144 void NativeWidgetMus::SetOpacity(float opacity) { 1161 void NativeWidgetMus::SetOpacity(float opacity) {
1145 if (window_) 1162 if (window_)
1146 window_->SetOpacity(opacity); 1163 window_->SetOpacity(opacity);
1147 } 1164 }
1148 1165
1149 void NativeWidgetMus::FlashFrame(bool flash_frame) { 1166 void NativeWidgetMus::FlashFrame(bool flash_frame) {
1150 // NOTIMPLEMENTED(); 1167 // NOTIMPLEMENTED();
1151 } 1168 }
1152 1169
1153 void NativeWidgetMus::RunShellDrag( 1170 void NativeWidgetMus::RunShellDrag(View* view,
1154 View* view, 1171 const ui::OSExchangeData& data,
1155 const ui::OSExchangeData& data, 1172 const gfx::Point& location,
1156 const gfx::Point& location, 1173 int drag_operations,
1157 int operation, 1174 ui::DragDropTypes::DragEventSource source) {
1158 ui::DragDropTypes::DragEventSource source) { 1175 if (window_)
1159 // NOTIMPLEMENTED(); 1176 views::RunShellDrag(content_, data, location, drag_operations, source);
1160 } 1177 }
1161 1178
1162 void NativeWidgetMus::SchedulePaintInRect(const gfx::Rect& rect) { 1179 void NativeWidgetMus::SchedulePaintInRect(const gfx::Rect& rect) {
1163 if (content_) 1180 if (content_)
1164 content_->SchedulePaintInRect(rect); 1181 content_->SchedulePaintInRect(rect);
1165 } 1182 }
1166 1183
1167 void NativeWidgetMus::SetCursor(gfx::NativeCursor cursor) { 1184 void NativeWidgetMus::SetCursor(gfx::NativeCursor cursor) {
1168 if (!window_) 1185 if (!window_)
1169 return; 1186 return;
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
1403 1420
1404 void NativeWidgetMus::OnHostMoved(const aura::WindowTreeHost* host, 1421 void NativeWidgetMus::OnHostMoved(const aura::WindowTreeHost* host,
1405 const gfx::Point& new_origin) { 1422 const gfx::Point& new_origin) {
1406 native_widget_delegate_->OnNativeWidgetMove(); 1423 native_widget_delegate_->OnNativeWidgetMove();
1407 } 1424 }
1408 1425
1409 void NativeWidgetMus::OnHostCloseRequested(const aura::WindowTreeHost* host) { 1426 void NativeWidgetMus::OnHostCloseRequested(const aura::WindowTreeHost* host) {
1410 GetWidget()->Close(); 1427 GetWidget()->Close();
1411 } 1428 }
1412 1429
1430 ////////////////////////////////////////////////////////////////////////////////
1431 // NativeWidgetMus, aura::WindowDragDropDelegate implementation:
1432
1433 void NativeWidgetMus::OnDragEntered(const ui::DropTargetEvent& event) {
1434 DCHECK(drop_helper_);
1435 last_drop_operation_ = drop_helper_->OnDragOver(
1436 event.data(), event.location(), event.source_operations());
1437 }
1438
1439 int NativeWidgetMus::OnDragUpdated(const ui::DropTargetEvent& event) {
1440 DCHECK(drop_helper_);
1441 last_drop_operation_ = drop_helper_->OnDragOver(
1442 event.data(), event.location(), event.source_operations());
1443 return last_drop_operation_;
1444 }
1445
1446 void NativeWidgetMus::OnDragExited() {
1447 DCHECK(drop_helper_);
1448 drop_helper_->OnDragExit();
1449 }
1450
1451 int NativeWidgetMus::OnPerformDrop(const ui::DropTargetEvent& event) {
1452 DCHECK(drop_helper_);
1453 return drop_helper_->OnDrop(event.data(), event.location(),
1454 last_drop_operation_);
1455 }
1456
1457 ////////////////////////////////////////////////////////////////////////////////
1458 // NativeWidgetMus, ui::InputEventHandler implementation:
1459
1413 void NativeWidgetMus::OnWindowInputEvent( 1460 void NativeWidgetMus::OnWindowInputEvent(
1414 ui::Window* view, 1461 ui::Window* view,
1415 const ui::Event& event_in, 1462 const ui::Event& event_in,
1416 std::unique_ptr<base::Callback<void(EventResult)>>* ack_callback) { 1463 std::unique_ptr<base::Callback<void(EventResult)>>* ack_callback) {
1417 // Take ownership of the callback, indicating that we will handle it. 1464 // Take ownership of the callback, indicating that we will handle it.
1418 EventAckHandler ack_handler(std::move(*ack_callback)); 1465 EventAckHandler ack_handler(std::move(*ack_callback));
1419 1466
1420 std::unique_ptr<ui::Event> event = ui::Event::Clone(event_in); 1467 std::unique_ptr<ui::Event> event = ui::Event::Clone(event_in);
1421 // TODO(markdittmer): This should be this->OnEvent(event.get()), but that 1468 // TODO(markdittmer): This should be this->OnEvent(event.get()), but that
1422 // can't happen until IME is refactored out of in WindowTreeHostMus. 1469 // can't happen until IME is refactored out of in WindowTreeHostMus.
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1461 1508
1462 gfx::Path mask_path; 1509 gfx::Path mask_path;
1463 native_widget_delegate_->GetHitTestMask(&mask_path); 1510 native_widget_delegate_->GetHitTestMask(&mask_path);
1464 // TODO(jamescook): Use the full path for the mask. 1511 // TODO(jamescook): Use the full path for the mask.
1465 gfx::Rect mask_rect = 1512 gfx::Rect mask_rect =
1466 gfx::ToEnclosingRect(gfx::SkRectToRectF(mask_path.getBounds())); 1513 gfx::ToEnclosingRect(gfx::SkRectToRectF(mask_path.getBounds()));
1467 window_->SetHitTestMask(mask_rect); 1514 window_->SetHitTestMask(mask_rect);
1468 } 1515 }
1469 1516
1470 } // namespace views 1517 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/mus/native_widget_mus.h ('k') | ui/views/mus/os_exchange_data_provider_mus.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698