I want to implement borderless window with drag logic on some HTML element. I found some working examples (like frameless window for Chrome) and this is what I've tried:
.title-area
{
-webkit-app-region: drag;
}
<div class='title-area'>
A draggable area
</div>
Then, in C# code I've implemented IDragHandler class:
internal class PromtDragHandler : IDragHandler
{
bool IDragHandler.OnDragEnter(IWebBrowser browserControl, IBrowser browser, IDragData dragData, DragOperationsMask mask)
{
return false;
}
void IDragHandler.OnDraggableRegionsChanged(IWebBrowser browserControl, IBrowser browser, IList<DraggableRegion> regions)
{
}
}
Method OnDraggableRegionsChanged fires once at start, OnDragEnter fires when I'm dragging some text of the element "title-area". But I'm not sure what to do next to make my window move?
UPDATE. As mentioned in comments, CefTestApp support this drag feature. In the source code we have method OnSetDraggableRegions which is called from DragHandler:
void RootWindowWin::OnSetDraggableRegions(
const std::vector<CefDraggableRegion>& regions) {
REQUIRE_MAIN_THREAD();
// Reset draggable region.
::SetRectRgn(draggable_region_, 0, 0, 0, 0);
// Determine new draggable region.
std::vector<CefDraggableRegion>::const_iterator it = regions.begin();
for (;it != regions.end(); ++it) {
HRGN region = ::CreateRectRgn(
it->bounds.x, it->bounds.y,
it->bounds.x + it->bounds.width,
it->bounds.y + it->bounds.height);
::CombineRgn(
draggable_region_, draggable_region_, region,
it->draggable ? RGN_OR : RGN_DIFF);
::DeleteObject(region);
}
// Subclass child window procedures in order to do hit-testing.
// This will be a no-op, if it is already subclassed.
if (hwnd_) {
WNDENUMPROC proc = !regions.empty() ?
SubclassWindowsProc : UnSubclassWindowsProc;
::EnumChildWindows(
hwnd_, proc, reinterpret_cast<LPARAM>(draggable_region_));
}
}
I'm still not quite understanding, how exactly information about dragable regions (which fires only once at start) helps to move window? Can someone explain me this logic or provide C# equivalent of this code?