]> khamidou — GitHub mirrors - electron.git/commitdiff
Remove duplicate UpdateDraggableRegions
authorCheng Zhao <zcbenz@gmail.com>
Wed, 5 Aug 2015 04:32:22 +0000 (12:32 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Wed, 5 Aug 2015 04:32:22 +0000 (12:32 +0800)
atom/browser/native_window.cc
atom/browser/native_window.h
atom/browser/native_window_mac.h
atom/browser/native_window_mac.mm
atom/browser/native_window_views.cc
atom/browser/native_window_views.h

index d3c40f92827263c1e08e4cbc4c198053714d56d2..c9d68df640a5349e1685dbc1b346820d94dbdf5a 100644 (file)
@@ -68,6 +68,25 @@ const char* kWebRuntimeFeatures[] = {
   switches::kPageVisibility,
 };
 
+// Convert draggable regions in raw format to SkRegion format. Caller is
+// responsible for deleting the returned SkRegion instance.
+SkRegion* DraggableRegionsToSkRegion(
+    const std::vector<DraggableRegion>& regions) {
+  SkRegion* sk_region = new SkRegion;
+  for (std::vector<DraggableRegion>::const_iterator iter = regions.begin();
+       iter != regions.end();
+       ++iter) {
+    const DraggableRegion& region = *iter;
+    sk_region->op(
+        region.bounds.x(),
+        region.bounds.y(),
+        region.bounds.right(),
+        region.bounds.bottom(),
+        region.draggable ? SkRegion::kUnion_Op : SkRegion::kDifference_Op);
+  }
+  return sk_region;
+}
+
 }  // namespace
 
 NativeWindow::NativeWindow(
@@ -559,6 +578,15 @@ bool NativeWindow::OnMessageReceived(const IPC::Message& message) {
   return handled;
 }
 
+void NativeWindow::UpdateDraggableRegions(
+    const std::vector<DraggableRegion>& regions) {
+  // Draggable region is not supported for non-frameless window.
+  if (has_frame_)
+    return;
+
+  draggable_region_.reset(DraggableRegionsToSkRegion(regions));
+}
+
 void NativeWindow::ScheduleUnresponsiveEvent(int ms) {
   if (!window_unresposive_closure_.IsCancelled())
     return;
index b9c2486b791bfc81d03173cc4c42a760f2217d64..611ff82011c59c511548bbaf6d7d0ff5d389e44d 100644 (file)
@@ -23,6 +23,8 @@
 #include "ui/gfx/image/image.h"
 #include "ui/gfx/image/image_skia.h"
 
+class SkRegion;
+
 namespace base {
 class CommandLine;
 }
@@ -217,6 +219,7 @@ class NativeWindow : public content::WebContentsObserver,
   }
 
   bool has_frame() const { return has_frame_; }
+  SkRegion* draggable_region() const { return draggable_region_.get(); }
 
   void set_has_dialog_attached(bool has_dialog_attached) {
     has_dialog_attached_ = has_dialog_attached;
@@ -226,10 +229,6 @@ class NativeWindow : public content::WebContentsObserver,
   NativeWindow(brightray::InspectableWebContents* inspectable_web_contents,
                const mate::Dictionary& options);
 
-  // Called when the window needs to update its draggable region.
-  virtual void UpdateDraggableRegions(
-      const std::vector<DraggableRegion>& regions) = 0;
-
   // brightray::InspectableWebContentsViewDelegate:
   void DevToolsFocused() override;
   void DevToolsOpened() override;
@@ -257,6 +256,10 @@ class NativeWindow : public content::WebContentsObserver,
   ObserverList<NativeWindowObserver> observers_;
 
  private:
+  // Called when the window needs to update its draggable region.
+  void UpdateDraggableRegions(
+      const std::vector<DraggableRegion>& regions);
+
   // Schedule a notification unresponsive event.
   void ScheduleUnresponsiveEvent(int ms);
 
@@ -298,6 +301,10 @@ class NativeWindow : public content::WebContentsObserver,
   // The page this window is viewing.
   brightray::InspectableWebContents* inspectable_web_contents_;
 
+  // For custom drag, the whole window is non-draggable and the draggable region
+  // has to been explicitly provided.
+  scoped_ptr<SkRegion> draggable_region_;  // used in custom drag.
+
   base::WeakPtrFactory<NativeWindow> weak_factory_;
 
   DISALLOW_COPY_AND_ASSIGN(NativeWindow);
index 67f4389ff7036e4cd98c29127f1bb0abafd38578..e54dc6ad87f62351340fd04421cfa521b1162fca 100644 (file)
 #include <vector>
 
 #include "base/mac/scoped_nsobject.h"
-#include "base/memory/scoped_ptr.h"
 #include "atom/browser/native_window.h"
 
 @class AtomNSWindow;
 @class AtomNSWindowDelegate;
 @class FullSizeContentView;
-class SkRegion;
 
 namespace atom {
 
@@ -88,9 +86,6 @@ class NativeWindowMac : public NativeWindow {
   void ClipWebView();
 
  protected:
-  void UpdateDraggableRegions(
-      const std::vector<DraggableRegion>& regions) override;
-
   // NativeWindow:
   void HandleKeyboardEvent(
       content::WebContents*,
@@ -117,10 +112,6 @@ class NativeWindowMac : public NativeWindow {
   // The presentation options before entering kiosk mode.
   NSApplicationPresentationOptions kiosk_options_;
 
-  // For custom drag, the whole window is non-draggable and the draggable region
-  // has to been explicitly provided.
-  scoped_ptr<SkRegion> draggable_region_;  // used in custom drag.
-
   // Mouse location since the last mouse event, in screen coordinates. This is
   // used in custom drag to compute the window movement.
   NSPoint last_mouse_offset_;
index 295c0ac5400ac4d6b0ed4258dde6c9074bb7ec25..8a0955b2903c6dfc5b0f0494b4281e9ee156b281 100644 (file)
@@ -318,29 +318,6 @@ static const CGFloat kAtomWindowCornerRadius = 4.0;
 
 namespace atom {
 
-namespace {
-
-// Convert draggable regions in raw format to SkRegion format. Caller is
-// responsible for deleting the returned SkRegion instance.
-SkRegion* DraggableRegionsToSkRegion(
-    const std::vector<DraggableRegion>& regions) {
-  SkRegion* sk_region = new SkRegion;
-  for (std::vector<DraggableRegion>::const_iterator iter = regions.begin();
-       iter != regions.end();
-       ++iter) {
-    const DraggableRegion& region = *iter;
-    sk_region->op(
-        region.bounds.x(),
-        region.bounds.y(),
-        region.bounds.right(),
-        region.bounds.bottom(),
-        region.draggable ? SkRegion::kUnion_Op : SkRegion::kDifference_Op);
-  }
-  return sk_region;
-}
-
-}  // namespace
-
 NativeWindowMac::NativeWindowMac(
     brightray::InspectableWebContents* web_contents,
     const mate::Dictionary& options)
@@ -747,7 +724,7 @@ bool NativeWindowMac::IsVisibleOnAllWorkspaces() {
 }
 
 bool NativeWindowMac::IsWithinDraggableRegion(NSPoint point) const {
-  if (!draggable_region_)
+  if (!draggable_region())
     return false;
   if (!web_contents())
     return false;
@@ -756,7 +733,7 @@ bool NativeWindowMac::IsWithinDraggableRegion(NSPoint point) const {
   // |draggable_region_| is stored in local platform-indepdent coordiate system
   // while |point| is in local Cocoa coordinate system. Do the conversion
   // to match these two.
-  return draggable_region_->contains(point.x, webViewHeight - point.y);
+  return draggable_region()->contains(point.x, webViewHeight - point.y);
 }
 
 void NativeWindowMac::HandleMouseEvent(NSEvent* event) {
@@ -776,15 +753,6 @@ void NativeWindowMac::HandleMouseEvent(NSEvent* event) {
   }
 }
 
-void NativeWindowMac::UpdateDraggableRegions(
-    const std::vector<DraggableRegion>& regions) {
-  // Draggable region is not supported for non-frameless window.
-  if (has_frame_)
-    return;
-
-  draggable_region_.reset(DraggableRegionsToSkRegion(regions));
-}
-
 void NativeWindowMac::HandleKeyboardEvent(
     content::WebContents*,
     const content::NativeWebKeyboardEvent& event) {
index 62cf51f4d84e275743127e5f4538ed7e9a920177..35aea41eb549496cbb9fcd52b3f802ef418307cc 100644 (file)
@@ -753,29 +753,6 @@ gfx::AcceleratedWidget NativeWindowViews::GetAcceleratedWidget() {
   return GetNativeWindow()->GetHost()->GetAcceleratedWidget();
 }
 
-void NativeWindowViews::UpdateDraggableRegions(
-    const std::vector<DraggableRegion>& regions) {
-  if (has_frame_)
-    return;
-
-  SkRegion* draggable_region = new SkRegion;
-
-  // By default, the whole window is non-draggable. We need to explicitly
-  // include those draggable regions.
-  for (std::vector<DraggableRegion>::const_iterator iter = regions.begin();
-       iter != regions.end(); ++iter) {
-    const DraggableRegion& region = *iter;
-    draggable_region->op(
-        region.bounds.x(),
-        region.bounds.y(),
-        region.bounds.right(),
-        region.bounds.bottom(),
-        region.draggable ? SkRegion::kUnion_Op : SkRegion::kDifference_Op);
-  }
-
-  draggable_region_.reset(draggable_region);
-}
-
 void NativeWindowViews::OnWidgetActivationChanged(
     views::Widget* widget, bool active) {
   if (widget != window_.get())
@@ -858,8 +835,8 @@ bool NativeWindowViews::ShouldDescendIntoChildForEventHandling(
     gfx::NativeView child,
     const gfx::Point& location) {
   // App window should claim mouse events that fall within the draggable region.
-  if (draggable_region_ &&
-      draggable_region_->contains(location.x(), location.y()))
+  if (draggable_region() &&
+      draggable_region()->contains(location.x(), location.y()))
     return false;
 
   // And the events on border for dragging resizable frameless window.
index fa7e13c1c335e5f0a76dc88e9ba18ff0c31690eb..dcf1f603a4f47d137d7ccd541503d05f37ecef96 100644 (file)
@@ -82,14 +82,9 @@ class NativeWindowViews : public NativeWindow,
 
   gfx::AcceleratedWidget GetAcceleratedWidget();
 
-  SkRegion* draggable_region() const { return draggable_region_.get(); }
   views::Widget* widget() const { return window_.get(); }
 
  private:
-  // NativeWindow:
-  void UpdateDraggableRegions(
-      const std::vector<DraggableRegion>& regions) override;
-
   // views::WidgetObserver:
   void OnWidgetActivationChanged(
       views::Widget* widget, bool active) override;
@@ -177,8 +172,6 @@ class NativeWindowViews : public NativeWindow,
   gfx::Size maximum_size_;
   gfx::Size widget_size_;
 
-  scoped_ptr<SkRegion> draggable_region_;
-
   DISALLOW_COPY_AND_ASSIGN(NativeWindowViews);
 };