Skip to content

Commit

Permalink
Move DragHandler to separated file
Browse files Browse the repository at this point in the history
  • Loading branch information
tishion committed Sep 27, 2023
1 parent f0b2d7f commit 37f6ae5
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 37 deletions.
2 changes: 1 addition & 1 deletion CefViewCore
11 changes: 6 additions & 5 deletions src/details/CCefClientDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,6 @@ class CCefClientDelegate
CefRefPtr<CefFileDialogCallback> callback) override;

// DisplayHandler
virtual bool onDragEnter(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefDragData> dragData,
CefDragHandler::DragOperationsMask mask) override;
virtual void draggableRegionChanged(CefRefPtr<CefBrowser>& browser,
const std::vector<CefDraggableRegion>& regions) override;
virtual void addressChanged(CefRefPtr<CefBrowser>& browser, int64_t frameId, const std::string& url) override;
virtual void titleChanged(CefRefPtr<CefBrowser>& browser, const std::string& title) override;
virtual void faviconURLChanged(CefRefPtr<CefBrowser> browser, const std::vector<CefString>& icon_urls) override;
Expand All @@ -119,6 +114,12 @@ class CCefClientDelegate
virtual void onDownloadUpdated(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefDownloadItem> download_item,
CefRefPtr<CefDownloadItemCallback> callback) override;
// DragHandler
virtual bool onDragEnter(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefDragData> dragData,
CefDragHandler::DragOperationsMask mask) override;
virtual void draggableRegionChanged(CefRefPtr<CefBrowser>& browser,
const std::vector<CefDraggableRegion>& regions) override;

// FocusHandler
virtual void takeFocus(CefRefPtr<CefBrowser>& browser, bool next) override;
Expand Down
31 changes: 0 additions & 31 deletions src/details/CCefClientDelegate_DisplayHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,37 +65,6 @@ mapCursorShape(cef_cursor_type_t& type)
return sCursorTable[type];
}

bool
CCefClientDelegate::onDragEnter(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefDragData> dragData,
CefDragHandler::DragOperationsMask mask)
{
// Return false for default drag handling behavior or true to cancel the drag event.
return !pCefViewPrivate_->q_ptr->isDragAndDropEnabled();
}

void
CCefClientDelegate::draggableRegionChanged(CefRefPtr<CefBrowser>& browser,
const std::vector<CefDraggableRegion>& regions)
{
if (!IsValidBrowser(browser))
return;

// Determine new draggable region.
QRegion draggableRegion;
QRegion nonDraggableRegion;
std::vector<CefDraggableRegion>::const_iterator it = regions.begin();
for (; it != regions.end(); ++it) {
if (it->draggable) {
draggableRegion += QRegion(it->bounds.x, it->bounds.y, it->bounds.width, it->bounds.height);
} else {
nonDraggableRegion += QRegion(it->bounds.x, it->bounds.y, it->bounds.width, it->bounds.height);
}
}

pCefViewPrivate_->q_ptr->draggableRegionChanged(draggableRegion, nonDraggableRegion);
}

void
CCefClientDelegate::addressChanged(CefRefPtr<CefBrowser>& browser, int64_t frameId, const std::string& url)
{
Expand Down
38 changes: 38 additions & 0 deletions src/details/CCefClientDelegate_DragHandler.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include "CCefClientDelegate.h"

#include <QDebug>
#include <QSharedPointer>
#include <QThread>

#include "QCefViewPrivate.h"

bool
CCefClientDelegate::onDragEnter(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefDragData> dragData,
CefDragHandler::DragOperationsMask mask)
{
// Return false for default drag handling behavior or true to cancel the drag event.
return !pCefViewPrivate_->q_ptr->isDragAndDropEnabled();
}

void
CCefClientDelegate::draggableRegionChanged(CefRefPtr<CefBrowser>& browser,
const std::vector<CefDraggableRegion>& regions)
{
if (!IsValidBrowser(browser))
return;

// Determine new draggable region.
QRegion draggableRegion;
QRegion nonDraggableRegion;
std::vector<CefDraggableRegion>::const_iterator it = regions.begin();
for (; it != regions.end(); ++it) {
if (it->draggable) {
draggableRegion += QRegion(it->bounds.x, it->bounds.y, it->bounds.width, it->bounds.height);
} else {
nonDraggableRegion += QRegion(it->bounds.x, it->bounds.y, it->bounds.width, it->bounds.height);
}
}

pCefViewPrivate_->q_ptr->draggableRegionChanged(draggableRegion, nonDraggableRegion);
}

0 comments on commit 37f6ae5

Please sign in to comment.