Add support for draggable regions (issue #1645).

Regions are defined using the '-webkit-app-region: drag/no-drag'
CSS property and passed to the CefDragHandler::
OnDraggableRegionsChanged callback.
This commit is contained in:
Felix Bruns
2015-04-24 15:48:32 +02:00
committed by Marshall Greenblatt
parent ead921a3f6
commit c5b8b8b9c8
27 changed files with 581 additions and 3 deletions

View File

@@ -2659,6 +2659,8 @@ bool CefBrowserHostImpl::OnMessageReceived(const IPC::Message& message) {
IPC_BEGIN_MESSAGE_MAP(CefBrowserHostImpl, message)
IPC_MESSAGE_HANDLER(CefHostMsg_FrameIdentified, OnFrameIdentified)
IPC_MESSAGE_HANDLER(CefHostMsg_DidFinishLoad, OnDidFinishLoad)
IPC_MESSAGE_HANDLER(CefHostMsg_UpdateDraggableRegions,
OnUpdateDraggableRegions)
IPC_MESSAGE_HANDLER(CefHostMsg_Request, OnRequest)
IPC_MESSAGE_HANDLER(CefHostMsg_Response, OnResponse)
IPC_MESSAGE_HANDLER(CefHostMsg_ResponseAck, OnResponseAck)
@@ -2716,6 +2718,26 @@ void CefBrowserHostImpl::OnDidFinishLoad(int64 frame_id,
OnLoadEnd(frame, validated_url, http_status_code);
}
void CefBrowserHostImpl::OnUpdateDraggableRegions(
const std::vector<Cef_DraggableRegion_Params>& regions) {
std::vector<CefDraggableRegion> draggable_regions;
draggable_regions.reserve(regions.size());
std::vector<Cef_DraggableRegion_Params>::const_iterator it = regions.begin();
for (; it != regions.end(); ++it) {
const gfx::Rect& rect(it->bounds);
const CefRect bounds(rect.x(), rect.y(), rect.width(), rect.height());
draggable_regions.push_back(CefDraggableRegion(bounds, it->draggable));
}
if (client_.get()) {
CefRefPtr<CefDragHandler> handler = client_->GetDragHandler();
if (handler.get()) {
handler->OnDraggableRegionsChanged(this, draggable_regions);
}
}
}
void CefBrowserHostImpl::OnRequest(const Cef_Request_Params& params) {
bool success = false;
std::string response;

View File

@@ -64,6 +64,7 @@ class Widget;
class CefWindowX11;
#endif
struct Cef_DraggableRegion_Params;
struct Cef_Request_Params;
struct Cef_Response_Params;
class CefBrowserInfo;
@@ -477,6 +478,8 @@ class CefBrowserHostImpl : public CefBrowserHost,
const GURL& validated_url,
bool is_main_frame,
int http_status_code);
void OnUpdateDraggableRegions(
const std::vector<Cef_DraggableRegion_Params>& regions);
void OnRequest(const Cef_Request_Params& params);
void OnResponse(const Cef_Response_Params& params);
void OnResponseAck(int request_id);

View File

@@ -68,6 +68,12 @@ IPC_STRUCT_BEGIN(Cef_CrossOriginWhiteListEntry_Params)
IPC_STRUCT_MEMBER(bool, allow_target_subdomains)
IPC_STRUCT_END()
// Parameters structure for a draggable region.
IPC_STRUCT_BEGIN(Cef_DraggableRegion_Params)
IPC_STRUCT_MEMBER(gfx::Rect, bounds)
IPC_STRUCT_MEMBER(bool, draggable)
IPC_STRUCT_END()
// Messages sent from the browser to the renderer.
@@ -189,6 +195,10 @@ IPC_MESSAGE_ROUTED1(CefHostMsg_Response,
IPC_MESSAGE_ROUTED1(CefHostMsg_ResponseAck,
int /* request_id */)
// Sent by the renderer when the draggable regions are updated.
IPC_MESSAGE_ROUTED1(CefHostMsg_UpdateDraggableRegions,
std::vector<Cef_DraggableRegion_Params> /* regions */)
// Singly-included section for struct and custom IPC traits.
#ifndef CEF_LIBCEF_COMMON_CEF_MESSAGES_H_

View File

@@ -571,6 +571,19 @@ void CefBrowserImpl::FocusedNodeChanged(const blink::WebNode& node) {
}
}
void CefBrowserImpl::DraggableRegionsChanged(blink::WebFrame* frame) {
blink::WebVector<blink::WebDraggableRegion> webregions =
frame->document().draggableRegions();
std::vector<Cef_DraggableRegion_Params> regions;
for (size_t i = 0; i < webregions.size(); ++i) {
Cef_DraggableRegion_Params region;
region.bounds = webregions[i].bounds;
region.draggable = webregions[i].draggable;
regions.push_back(region);
}
Send(new CefHostMsg_UpdateDraggableRegions(routing_id(), regions));
}
bool CefBrowserImpl::OnMessageReceived(const IPC::Message& message) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(CefBrowserImpl, message)

View File

@@ -119,6 +119,7 @@ class CefBrowserImpl : public CefBrowser,
bool is_new_navigation) override;
void FrameDetached(blink::WebFrame* frame) override;
void FocusedNodeChanged(const blink::WebNode& node) override;
void DraggableRegionsChanged(blink::WebFrame* frame) override;
bool OnMessageReceived(const IPC::Message& message) override;
// RenderViewObserver::OnMessageReceived message handlers.