diff --git a/atom/browser/native_window.cc b/atom/browser/native_window.cc index d3c40f92827..c9d68df640a 100644 --- a/atom/browser/native_window.cc +++ b/atom/browser/native_window.cc @@ -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& regions) { + SkRegion* sk_region = new SkRegion; + for (std::vector::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& 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; diff --git a/atom/browser/native_window.h b/atom/browser/native_window.h index b9c2486b791..611ff82011c 100644 --- a/atom/browser/native_window.h +++ b/atom/browser/native_window.h @@ -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& regions) = 0; - // brightray::InspectableWebContentsViewDelegate: void DevToolsFocused() override; void DevToolsOpened() override; @@ -257,6 +256,10 @@ class NativeWindow : public content::WebContentsObserver, ObserverList observers_; private: + // Called when the window needs to update its draggable region. + void UpdateDraggableRegions( + const std::vector& 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 draggable_region_; // used in custom drag. + base::WeakPtrFactory weak_factory_; DISALLOW_COPY_AND_ASSIGN(NativeWindow); diff --git a/atom/browser/native_window_mac.h b/atom/browser/native_window_mac.h index 67f4389ff70..e54dc6ad87f 100644 --- a/atom/browser/native_window_mac.h +++ b/atom/browser/native_window_mac.h @@ -11,13 +11,11 @@ #include #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& 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 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_; diff --git a/atom/browser/native_window_mac.mm b/atom/browser/native_window_mac.mm index 295c0ac5400..8a0955b2903 100644 --- a/atom/browser/native_window_mac.mm +++ b/atom/browser/native_window_mac.mm @@ -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& regions) { - SkRegion* sk_region = new SkRegion; - for (std::vector::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& 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) { diff --git a/atom/browser/native_window_views.cc b/atom/browser/native_window_views.cc index 62cf51f4d84..35aea41eb54 100644 --- a/atom/browser/native_window_views.cc +++ b/atom/browser/native_window_views.cc @@ -753,29 +753,6 @@ gfx::AcceleratedWidget NativeWindowViews::GetAcceleratedWidget() { return GetNativeWindow()->GetHost()->GetAcceleratedWidget(); } -void NativeWindowViews::UpdateDraggableRegions( - const std::vector& 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::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. diff --git a/atom/browser/native_window_views.h b/atom/browser/native_window_views.h index fa7e13c1c33..dcf1f603a4f 100644 --- a/atom/browser/native_window_views.h +++ b/atom/browser/native_window_views.h @@ -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& 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 draggable_region_; - DISALLOW_COPY_AND_ASSIGN(NativeWindowViews); };