Skip to content

Commit

Permalink
chore: cleanup drag_util (#36806)
Browse files Browse the repository at this point in the history
chore: cleanup drag_util
  • Loading branch information
codebytere committed Jan 9, 2023
1 parent 0d05273 commit 1a9c338
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
19 changes: 9 additions & 10 deletions shell/browser/ui/drag_util_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.

#include "shell/browser/ui/drag_util.h"

#import <Cocoa/Cocoa.h>

#include <vector>

#include "base/files/file_path.h"
#include "base/strings/sys_string_conversions.h"
#include "shell/browser/ui/drag_util.h"
#include "base/mac/foundation_util.h"

// Contents largely copied from
// chrome/browser/download/drag_download_item_mac.mm.
Expand Down Expand Up @@ -40,9 +41,10 @@ - (NSDragOperation)draggingSession:(NSDraggingSession*)session
void DragFileItems(const std::vector<base::FilePath>& files,
const gfx::Image& icon,
gfx::NativeView view) {
DCHECK(view);
auto* native_view = view.GetNativeNSView();
NSPoint current_position =
[[native_view window] mouseLocationOutsideOfEventStream];
native_view.window.mouseLocationOutsideOfEventStream;
current_position =
[native_view backingAlignedRect:NSMakeRect(current_position.x,
current_position.y, 0, 0)
Expand All @@ -51,8 +53,7 @@ void DragFileItems(const std::vector<base::FilePath>& files,

NSMutableArray* file_items = [NSMutableArray array];
for (auto const& file : files) {
NSURL* file_url =
[NSURL fileURLWithPath:base::SysUTF8ToNSString(file.value())];
NSURL* file_url = base::mac::FilePathToNSURL(file);
NSDraggingItem* file_item = [[[NSDraggingItem alloc]
initWithPasteboardWriter:file_url] autorelease];
NSImage* file_image = icon.ToNSImage();
Expand All @@ -66,14 +67,12 @@ void DragFileItems(const std::vector<base::FilePath>& files,

// Synthesize a drag event, since we don't have access to the actual event
// that initiated a drag (possibly consumed by the Web UI, for example).
NSPoint position = [[native_view window] mouseLocationOutsideOfEventStream];
NSTimeInterval eventTime = [[NSApp currentEvent] timestamp];
NSEvent* dragEvent =
[NSEvent mouseEventWithType:NSEventTypeLeftMouseDragged
location:position
location:current_position
modifierFlags:0
timestamp:eventTime
windowNumber:[[native_view window] windowNumber]
timestamp:NSApp.currentEvent.timestamp
windowNumber:native_view.window.windowNumber
context:nil
eventNumber:0
clickCount:1
Expand Down
10 changes: 5 additions & 5 deletions shell/browser/ui/drag_util_views.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ namespace electron {
void DragFileItems(const std::vector<base::FilePath>& files,
const gfx::Image& icon,
gfx::NativeView view) {
// Set up our OLE machinery
aura::Window* root_window = view->GetRootWindow();
if (!root_window || !aura::client::GetDragDropClient(root_window))
return;

// Set up our OLE machinery.
auto data = std::make_unique<ui::OSExchangeData>();

button_drag_utils::SetDragImage(GURL(), files[0].LossyDisplayName(),
Expand All @@ -34,10 +38,6 @@ void DragFileItems(const std::vector<base::FilePath>& files,
}
data->SetFilenames(file_infos);

aura::Window* root_window = view->GetRootWindow();
if (!root_window || !aura::client::GetDragDropClient(root_window))
return;

gfx::Point location = display::Screen::GetScreen()->GetCursorScreenPoint();
// TODO(varunjain): Properly determine and send DragEventSource below.
aura::client::GetDragDropClient(root_window)
Expand Down

0 comments on commit 1a9c338

Please sign in to comment.