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

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

Issue 2266603002: mus: Implement interwindow drag and drop (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Uploaded for a few comments. Created 4 years, 3 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 "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/run_loop.h"
(...skipping 14 matching lines...) Expand all
25 #include "ui/aura/window.h" 25 #include "ui/aura/window.h"
26 #include "ui/aura/window_property.h" 26 #include "ui/aura/window_property.h"
27 #include "ui/base/hit_test.h" 27 #include "ui/base/hit_test.h"
28 #include "ui/display/display.h" 28 #include "ui/display/display.h"
29 #include "ui/display/screen.h" 29 #include "ui/display/screen.h"
30 #include "ui/events/event.h" 30 #include "ui/events/event.h"
31 #include "ui/gfx/canvas.h" 31 #include "ui/gfx/canvas.h"
32 #include "ui/gfx/path.h" 32 #include "ui/gfx/path.h"
33 #include "ui/native_theme/native_theme_aura.h" 33 #include "ui/native_theme/native_theme_aura.h"
34 #include "ui/platform_window/platform_window_delegate.h" 34 #include "ui/platform_window/platform_window_delegate.h"
35 #include "ui/views/mus/drop_target_mus.h"
36 #include "ui/views/mus/os_exchange_data_provider_mus.h"
35 #include "ui/views/mus/window_manager_constants_converters.h" 37 #include "ui/views/mus/window_manager_constants_converters.h"
36 #include "ui/views/mus/window_manager_frame_values.h" 38 #include "ui/views/mus/window_manager_frame_values.h"
37 #include "ui/views/mus/window_tree_host_mus.h" 39 #include "ui/views/mus/window_tree_host_mus.h"
40 #include "ui/views/widget/drop_helper.h"
38 #include "ui/views/widget/native_widget_aura.h" 41 #include "ui/views/widget/native_widget_aura.h"
39 #include "ui/views/widget/widget_delegate.h" 42 #include "ui/views/widget/widget_delegate.h"
40 #include "ui/views/window/custom_frame_view.h" 43 #include "ui/views/window/custom_frame_view.h"
41 #include "ui/wm/core/base_focus_rules.h" 44 #include "ui/wm/core/base_focus_rules.h"
42 #include "ui/wm/core/capture_controller.h" 45 #include "ui/wm/core/capture_controller.h"
43 #include "ui/wm/core/cursor_manager.h" 46 #include "ui/wm/core/cursor_manager.h"
44 #include "ui/wm/core/default_screen_position_client.h" 47 #include "ui/wm/core/default_screen_position_client.h"
45 #include "ui/wm/core/focus_controller.h" 48 #include "ui/wm/core/focus_controller.h"
46 #include "ui/wm/core/native_cursor_manager.h" 49 #include "ui/wm/core/native_cursor_manager.h"
47 50
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 NativeWidgetMus::NativeWidgetMus(internal::NativeWidgetDelegate* delegate, 518 NativeWidgetMus::NativeWidgetMus(internal::NativeWidgetDelegate* delegate,
516 ui::Window* window, 519 ui::Window* window,
517 ui::mojom::SurfaceType surface_type) 520 ui::mojom::SurfaceType surface_type)
518 : window_(window), 521 : window_(window),
519 last_cursor_(ui::mojom::Cursor::CURSOR_NULL), 522 last_cursor_(ui::mojom::Cursor::CURSOR_NULL),
520 native_widget_delegate_(delegate), 523 native_widget_delegate_(delegate),
521 surface_type_(surface_type), 524 surface_type_(surface_type),
522 show_state_before_fullscreen_(ui::mojom::ShowState::DEFAULT), 525 show_state_before_fullscreen_(ui::mojom::ShowState::DEFAULT),
523 ownership_(Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET), 526 ownership_(Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET),
524 content_(new aura::Window(this)), 527 content_(new aura::Window(this)),
528 last_drop_operation_(ui::DragDropTypes::DRAG_NONE),
525 close_widget_factory_(this) { 529 close_widget_factory_(this) {
526 window_->set_input_event_handler(this); 530 window_->set_input_event_handler(this);
527 mus_window_observer_.reset(new MusWindowObserver(this)); 531 mus_window_observer_.reset(new MusWindowObserver(this));
528 532
529 // TODO(fsamuel): Figure out lifetime of |window_|. 533 // TODO(fsamuel): Figure out lifetime of |window_|.
530 aura::SetMusWindow(content_, window_); 534 aura::SetMusWindow(content_, window_);
531 window->SetLocalProperty(kNativeWidgetMusKey, this); 535 window->SetLocalProperty(kNativeWidgetMusKey, this);
532 window_tree_host_.reset(new WindowTreeHostMus(this, window_)); 536 window_tree_host_.reset(new WindowTreeHostMus(this, window_));
533 } 537 }
534 538
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
689 693
690 focus_client_.reset( 694 focus_client_.reset(
691 new FocusControllerMus(new FocusRulesImpl(hosted_window))); 695 new FocusControllerMus(new FocusRulesImpl(hosted_window)));
692 696
693 aura::client::SetFocusClient(hosted_window, focus_client_.get()); 697 aura::client::SetFocusClient(hosted_window, focus_client_.get());
694 aura::client::SetActivationClient(hosted_window, focus_client_.get()); 698 aura::client::SetActivationClient(hosted_window, focus_client_.get());
695 screen_position_client_.reset(new ScreenPositionClientMus(window_)); 699 screen_position_client_.reset(new ScreenPositionClientMus(window_));
696 aura::client::SetScreenPositionClient(hosted_window, 700 aura::client::SetScreenPositionClient(hosted_window,
697 screen_position_client_.get()); 701 screen_position_client_.get());
698 702
703 // TODO(erg): Create and call CreateDragDropClient() here for maximum aura.
704
705 drop_target_.reset(new DropTargetMus(content_));
706 window_->SetCanAcceptDrags(drop_target_.get());
707 drop_helper_.reset(new DropHelper(GetWidget()->GetRootView()));
708 aura::client::SetDragDropDelegate(content_, this);
709
699 // TODO(erg): Remove this check when ash/mus/move_event_handler.cc's 710 // TODO(erg): Remove this check when ash/mus/move_event_handler.cc's
700 // direct usage of ui::Window::SetPredefinedCursor() is switched to a 711 // direct usage of ui::Window::SetPredefinedCursor() is switched to a
701 // private method on WindowManagerClient. 712 // private method on WindowManagerClient.
702 if (!is_parallel_widget_in_window_manager()) { 713 if (!is_parallel_widget_in_window_manager()) {
703 cursor_manager_.reset(new wm::CursorManager( 714 cursor_manager_.reset(new wm::CursorManager(
704 base::MakeUnique<NativeCursorManagerMus>(window_))); 715 base::MakeUnique<NativeCursorManagerMus>(window_)));
705 aura::client::SetCursorClient(hosted_window, cursor_manager_.get()); 716 aura::client::SetCursorClient(hosted_window, cursor_manager_.get());
706 } 717 }
707 718
708 window_tree_client_.reset(new NativeWidgetMusWindowTreeClient(hosted_window)); 719 window_tree_client_.reset(new NativeWidgetMusWindowTreeClient(hosted_window));
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
1110 1121
1111 void NativeWidgetMus::SetOpacity(float opacity) { 1122 void NativeWidgetMus::SetOpacity(float opacity) {
1112 if (window_) 1123 if (window_)
1113 window_->SetOpacity(opacity); 1124 window_->SetOpacity(opacity);
1114 } 1125 }
1115 1126
1116 void NativeWidgetMus::FlashFrame(bool flash_frame) { 1127 void NativeWidgetMus::FlashFrame(bool flash_frame) {
1117 // NOTIMPLEMENTED(); 1128 // NOTIMPLEMENTED();
1118 } 1129 }
1119 1130
1120 void NativeWidgetMus::RunShellDrag( 1131 void NativeWidgetMus::RunShellDrag(View* view,
1121 View* view, 1132 const ui::OSExchangeData& data,
1122 const ui::OSExchangeData& data, 1133 const gfx::Point& location,
1123 const gfx::Point& location, 1134 int drag_operations,
1124 int operation, 1135 ui::DragDropTypes::DragEventSource source) {
1125 ui::DragDropTypes::DragEventSource source) { 1136 ReleaseCapture();
1126 // NOTIMPLEMENTED(); 1137
1138 base::MessageLoopForUI* loop = base::MessageLoopForUI::current();
1139 base::MessageLoop::ScopedNestableTaskAllower allow_nested(loop);
1140 base::RunLoop run_loop;
1141
1142 std::map<std::string, std::vector<uint8_t>> drag_data =
1143 static_cast<const OSExchangeDataProviderMus&>(data.provider()).GetData();
1144
1145 // TODO(erg): Right now, I'm passing the cursor_location, but maybe I want to
1146 // pass OSExchangeData::GetDragImageOffset() instead?
1147
1148 bool success = false;
1149 gfx::Point cursor_location = location;
1150 window_->PerformDragDrop(
1151 drag_data, drag_operations, cursor_location,
1152 *data.provider().GetDragImage().bitmap(),
1153 base::Bind(OnMoveLoopEnd, &success, run_loop.QuitClosure()));
1154
1155 run_loop.Run();
1156
1157 // In the aura version, we just throw the return code away.
1127 } 1158 }
1128 1159
1129 void NativeWidgetMus::SchedulePaintInRect(const gfx::Rect& rect) { 1160 void NativeWidgetMus::SchedulePaintInRect(const gfx::Rect& rect) {
1130 if (content_) 1161 if (content_)
1131 content_->SchedulePaintInRect(rect); 1162 content_->SchedulePaintInRect(rect);
1132 } 1163 }
1133 1164
1134 void NativeWidgetMus::SetCursor(gfx::NativeCursor cursor) { 1165 void NativeWidgetMus::SetCursor(gfx::NativeCursor cursor) {
1135 if (!window_) 1166 if (!window_)
1136 return; 1167 return;
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
1370 1401
1371 void NativeWidgetMus::OnHostMoved(const aura::WindowTreeHost* host, 1402 void NativeWidgetMus::OnHostMoved(const aura::WindowTreeHost* host,
1372 const gfx::Point& new_origin) { 1403 const gfx::Point& new_origin) {
1373 native_widget_delegate_->OnNativeWidgetMove(); 1404 native_widget_delegate_->OnNativeWidgetMove();
1374 } 1405 }
1375 1406
1376 void NativeWidgetMus::OnHostCloseRequested(const aura::WindowTreeHost* host) { 1407 void NativeWidgetMus::OnHostCloseRequested(const aura::WindowTreeHost* host) {
1377 GetWidget()->Close(); 1408 GetWidget()->Close();
1378 } 1409 }
1379 1410
1411 ////////////////////////////////////////////////////////////////////////////////
1412 // NativeWidgetMus, aura::WindowDragDropDelegate implementation:
1413
1414 void NativeWidgetMus::OnDragEntered(const ui::DropTargetEvent& event) {
1415 DCHECK(drop_helper_);
1416 last_drop_operation_ = drop_helper_->OnDragOver(
1417 event.data(), event.location(), event.source_operations());
1418 }
1419
1420 int NativeWidgetMus::OnDragUpdated(const ui::DropTargetEvent& event) {
1421 DCHECK(drop_helper_);
1422 last_drop_operation_ = drop_helper_->OnDragOver(
1423 event.data(), event.location(), event.source_operations());
1424 return last_drop_operation_;
1425 }
1426
1427 void NativeWidgetMus::OnDragExited() {
1428 DCHECK(drop_helper_);
1429 drop_helper_->OnDragExit();
1430 }
1431
1432 int NativeWidgetMus::OnPerformDrop(const ui::DropTargetEvent& event) {
1433 DCHECK(drop_helper_);
1434 // if (ShouldActivate())
1435 // Activate();
1436 return drop_helper_->OnDrop(event.data(), event.location(),
1437 last_drop_operation_);
1438 }
1439
1440 ////////////////////////////////////////////////////////////////////////////////
1441 // NativeWidgetMus, ui::InputEventHandler implementation:
1442
1380 void NativeWidgetMus::OnWindowInputEvent( 1443 void NativeWidgetMus::OnWindowInputEvent(
1381 ui::Window* view, 1444 ui::Window* view,
1382 const ui::Event& event_in, 1445 const ui::Event& event_in,
1383 std::unique_ptr<base::Callback<void(EventResult)>>* ack_callback) { 1446 std::unique_ptr<base::Callback<void(EventResult)>>* ack_callback) {
1384 // Take ownership of the callback, indicating that we will handle it. 1447 // Take ownership of the callback, indicating that we will handle it.
1385 EventAckHandler ack_handler(std::move(*ack_callback)); 1448 EventAckHandler ack_handler(std::move(*ack_callback));
1386 1449
1387 std::unique_ptr<ui::Event> event = ui::Event::Clone(event_in); 1450 std::unique_ptr<ui::Event> event = ui::Event::Clone(event_in);
1388 // TODO(markdittmer): This should be this->OnEvent(event.get()), but that 1451 // TODO(markdittmer): This should be this->OnEvent(event.get()), but that
1389 // can't happen until IME is refactored out of in WindowTreeHostMus. 1452 // can't happen until IME is refactored out of in WindowTreeHostMus.
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1428 1491
1429 gfx::Path mask_path; 1492 gfx::Path mask_path;
1430 native_widget_delegate_->GetHitTestMask(&mask_path); 1493 native_widget_delegate_->GetHitTestMask(&mask_path);
1431 // TODO(jamescook): Use the full path for the mask. 1494 // TODO(jamescook): Use the full path for the mask.
1432 gfx::Rect mask_rect = 1495 gfx::Rect mask_rect =
1433 gfx::ToEnclosingRect(gfx::SkRectToRectF(mask_path.getBounds())); 1496 gfx::ToEnclosingRect(gfx::SkRectToRectF(mask_path.getBounds()));
1434 window_->SetHitTestMask(mask_rect); 1497 window_->SetHitTestMask(mask_rect);
1435 } 1498 }
1436 1499
1437 } // namespace views 1500 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698