diff --git a/shell/browser/native_browser_view_views.cc b/shell/browser/native_browser_view_views.cc index 7a2e73f8bd791..1b938126ed775 100644 --- a/shell/browser/native_browser_view_views.cc +++ b/shell/browser/native_browser_view_views.cc @@ -4,6 +4,7 @@ #include "shell/browser/native_browser_view_views.h" +#include "shell/browser/ui/drag_util.h" #include "shell/browser/ui/inspectable_web_contents_view.h" #include "ui/gfx/geometry/rect.h" #include "ui/views/background.h" @@ -22,6 +23,29 @@ void NativeBrowserViewViews::SetAutoResizeFlags(uint8_t flags) { ResetAutoResizeProportions(); } +void NativeBrowserViewViews::UpdateDraggableRegions( + const std::vector& regions) { + // We need to snap the regions to the bounds of the current BrowserView. + // For example, if an attached BrowserView is draggable but its bounds are + // { x: 200, y: 100, width: 300, height: 300 } + // then we need to add 200 to the x-value and 100 to the + // y-value of each of the passed regions or it will be incorrectly + // assumed that the regions begin in the top left corner as they + // would for the main client window. + std::vector snapped_regions; + auto bounds = GetBounds(); + for (const auto& r : regions) { + auto region = mojom::DraggableRegion::New(); + region->bounds = + gfx::Rect(r->bounds.x() + bounds.x(), r->bounds.y() + bounds.y(), + r->bounds.width(), r->bounds.height()); + region->draggable = true; + snapped_regions.push_back(std::move(region)); + } + + draggable_region_ = DraggableRegionsToSkRegion(snapped_regions); +} + void NativeBrowserViewViews::SetAutoResizeProportions( const gfx::Size& window_size) { if ((auto_resize_flags_ & AutoResizeFlags::kAutoResizeHorizontal) && diff --git a/shell/browser/native_browser_view_views.h b/shell/browser/native_browser_view_views.h index 35fdbcbbcafa0..91a88ac2be522 100644 --- a/shell/browser/native_browser_view_views.h +++ b/shell/browser/native_browser_view_views.h @@ -6,6 +6,7 @@ #define SHELL_BROWSER_NATIVE_BROWSER_VIEW_VIEWS_H_ #include "shell/browser/native_browser_view.h" +#include "third_party/skia/include/core/SkRegion.h" namespace electron { @@ -26,6 +27,10 @@ class NativeBrowserViewViews : public NativeBrowserView { void SetBounds(const gfx::Rect& bounds) override; gfx::Rect GetBounds() override; void SetBackgroundColor(SkColor color) override; + void UpdateDraggableRegions( + const std::vector& regions) override; + + SkRegion* draggable_region() const { return draggable_region_.get(); } private: void ResetAutoResizeProportions(); @@ -40,6 +45,8 @@ class NativeBrowserViewViews : public NativeBrowserView { float auto_vertical_proportion_height_ = 0.; float auto_vertical_proportion_top_ = 0.; + std::unique_ptr draggable_region_; + DISALLOW_COPY_AND_ASSIGN(NativeBrowserViewViews); }; diff --git a/shell/browser/native_window_views.cc b/shell/browser/native_window_views.cc index cb53ac2fd1040..1c711e534189e 100644 --- a/shell/browser/native_window_views.cc +++ b/shell/browser/native_window_views.cc @@ -1446,6 +1446,16 @@ views::View* NativeWindowViews::GetContentsView() { bool NativeWindowViews::ShouldDescendIntoChildForEventHandling( gfx::NativeView child, const gfx::Point& location) { + // App window should claim mouse events that fall within any BrowserViews' + // draggable region. + for (auto* view : browser_views()) { + auto* native_view = static_cast(view); + auto* view_draggable_region = native_view->draggable_region(); + if (view_draggable_region && + view_draggable_region->contains(location.x(), location.y())) + return false; + } + // App window should claim mouse events that fall within the draggable region. if (draggable_region() && draggable_region()->contains(location.x(), location.y())) diff --git a/shell/browser/ui/views/frameless_view.cc b/shell/browser/ui/views/frameless_view.cc index 605c90233d07a..685a875b78596 100644 --- a/shell/browser/ui/views/frameless_view.cc +++ b/shell/browser/ui/views/frameless_view.cc @@ -4,6 +4,7 @@ #include "shell/browser/ui/views/frameless_view.h" +#include "shell/browser/native_browser_view_views.h" #include "shell/browser/native_window_views.h" #include "ui/aura/window.h" #include "ui/base/hit_test.h" @@ -68,6 +69,15 @@ int FramelessView::NonClientHitTest(const gfx::Point& cursor) { if (frame_->IsFullscreen()) return HTCLIENT; + // Check attached BrowserViews for potential draggable areas. + for (auto* view : window_->browser_views()) { + auto* native_view = static_cast(view); + auto* view_draggable_region = native_view->draggable_region(); + if (view_draggable_region && + view_draggable_region->contains(cursor.x(), cursor.y())) + return HTCAPTION; + } + // Check for possible draggable region in the client area for the frameless // window. SkRegion* draggable_region = window_->draggable_region();