Send and receive the AtomViewHostMsg_UpdateDraggableRegions message.
authorCheng Zhao <zcbenz@gmail.com>
Thu, 5 Sep 2013 12:06:54 +0000 (20:06 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Thu, 5 Sep 2013 12:06:54 +0000 (20:06 +0800)
browser/native_window.cc
browser/native_window.h
browser/native_window_mac.h
browser/native_window_mac.mm
browser/native_window_win.cc
browser/native_window_win.h
renderer/atom_render_view_observer.cc
renderer/atom_render_view_observer.h

index 1895473..34bdefd 100644 (file)
@@ -298,6 +298,8 @@ bool NativeWindow::OnMessageReceived(const IPC::Message& message) {
   IPC_BEGIN_MESSAGE_MAP(NativeWindow, message)
     IPC_MESSAGE_HANDLER(AtomViewHostMsg_Message, OnRendererMessage)
     IPC_MESSAGE_HANDLER(AtomViewHostMsg_Message_Sync, OnRendererMessageSync)
+    IPC_MESSAGE_HANDLER(AtomViewHostMsg_UpdateDraggableRegions,
+                        UpdateDraggableRegions)
     IPC_MESSAGE_UNHANDLED(handled = false)
   IPC_END_MESSAGE_MAP()
 
index b41fd4b..cde0ce1 100644 (file)
@@ -38,6 +38,7 @@ class Size;
 namespace atom {
 
 class AtomJavaScriptDialogManager;
+struct DraggableRegion;
 
 class NativeWindow : public brightray::DefaultWebContentsDelegate,
                      public content::WebContentsObserver,
@@ -125,6 +126,10 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
   void NotifyWindowClosed();
   void NotifyWindowBlur();
 
+  // Called when the window needs to update its draggable region.
+  virtual void UpdateDraggableRegions(
+      const std::vector<DraggableRegion>& regions) = 0;
+
   // Implementations of content::WebContentsDelegate.
   virtual void WebContentsCreated(content::WebContents* source_contents,
                                   int64 source_frame_id,
index d268473..a35e53d 100644 (file)
@@ -57,6 +57,9 @@ class NativeWindowMac : public NativeWindow {
   void NotifyWindowBlur() { NativeWindow::NotifyWindowBlur(); }
 
  protected:
+  virtual void UpdateDraggableRegions(
+      const std::vector<DraggableRegion>& regions) OVERRIDE;
+
   // Implementations of content::WebContentsDelegate.
   virtual void HandleKeyboardEvent(
       content::WebContents*,
index 194b38b..acddd0c 100644 (file)
@@ -324,6 +324,10 @@ gfx::NativeWindow NativeWindowMac::GetNativeWindow() {
   return window();
 }
 
+void NativeWindowMac::UpdateDraggableRegions(
+    const std::vector<DraggableRegion>& regions) {
+}
+
 void NativeWindowMac::HandleKeyboardEvent(
     content::WebContents*,
     const content::NativeWebKeyboardEvent& event) {
index 0a84afd..a358915 100644 (file)
@@ -221,6 +221,10 @@ gfx::NativeWindow NativeWindowWin::GetNativeWindow() {
   return window_->GetNativeView();
 }
 
+void NativeWindowWin::UpdateDraggableRegions(
+    const std::vector<DraggableRegion>& regions) {
+}
+
 void NativeWindowWin::HandleKeyboardEvent(
     content::WebContents*,
     const content::NativeWebKeyboardEvent& event) {
index 3d09615..19d9a55 100644 (file)
@@ -61,6 +61,9 @@ class NativeWindowWin : public NativeWindow,
   virtual gfx::NativeWindow GetNativeWindow() OVERRIDE;
 
  protected:
+  virtual void UpdateDraggableRegions(
+      const std::vector<DraggableRegion>& regions) OVERRIDE;
+
   // Overridden from content::WebContentsDelegate:
   virtual void HandleKeyboardEvent(
       content::WebContents*,
index 0c2c611..6a394e4 100644 (file)
@@ -12,6 +12,8 @@
 #include "ipc/ipc_message_macros.h"
 #include "renderer/api/atom_renderer_bindings.h"
 #include "renderer/atom_renderer_client.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebDraggableRegion.h"
 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
 #include "v8/include/v8.h"
 
@@ -76,6 +78,19 @@ void AtomRenderViewObserver::FrameWillClose(WebFrame* frame) {
   vec.erase(std::remove(vec.begin(), vec.end(), frame), vec.end());
 }
 
+void AtomRenderViewObserver::DraggableRegionsChanged(WebKit::WebFrame* frame) {
+  WebKit::WebVector<WebKit::WebDraggableRegion> webregions =
+      frame->document().draggableRegions();
+  std::vector<DraggableRegion> regions;
+  for (size_t i = 0; i < webregions.size(); ++i) {
+    DraggableRegion region;
+    region.bounds = webregions[i].bounds;
+    region.draggable = webregions[i].draggable;
+    regions.push_back(region);
+  }
+  Send(new AtomViewHostMsg_UpdateDraggableRegions(routing_id(), regions));
+}
+
 bool AtomRenderViewObserver::OnMessageReceived(const IPC::Message& message) {
   bool handled = true;
   IPC_BEGIN_MESSAGE_MAP(AtomRenderViewObserver, message)
index 55f1cdf..fd984d0 100644 (file)
@@ -32,6 +32,7 @@ class AtomRenderViewObserver : content::RenderViewObserver {
 
  private:
   // content::RenderViewObserver implementation.
+  virtual void DraggableRegionsChanged(WebKit::WebFrame* frame) OVERRIDE;
   virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
 
   void OnBrowserMessage(const std::string& channel,