Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: draggable region edge calculation on resize #26321

Merged
merged 1 commit into from
Nov 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 9 additions & 1 deletion shell/browser/api/electron_api_browser_window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "content/public/browser/render_view_host.h"
#include "shell/browser/api/electron_api_web_contents_view.h"
#include "shell/browser/browser.h"
#include "shell/browser/native_browser_view.h"
#include "shell/browser/unresponsive_suppressor.h"
#include "shell/browser/web_contents_preferences.h"
#include "shell/browser/window_list.h"
Expand Down Expand Up @@ -300,8 +301,15 @@ void BrowserWindow::OnWindowIsKeyChanged(bool is_key) {

void BrowserWindow::OnWindowResize() {
#if defined(OS_MACOSX)
if (!draggable_regions_.empty())
if (!draggable_regions_.empty()) {
UpdateDraggableRegions(draggable_regions_);
} else {
// Ensure draggable bounds are recalculated for BrowserViews if any exist.
auto browser_views = window_->browser_views();
for (NativeBrowserView* view : browser_views) {
view->UpdateDraggableRegions(draggable_regions_);
}
}
#endif
TopLevelWindow::OnWindowResize();
}
Expand Down
4 changes: 2 additions & 2 deletions shell/browser/api/electron_api_browser_window_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ - (NSView*)hitTest:(NSPoint)aPoint {
if ([subview isKindOfClass:[ControlRegionView class]])
[subview removeFromSuperview];

// Draggable regions is implemented by having the whole web view draggable
// (mouseDownCanMoveWindow) and overlaying regions that are not draggable.
// Draggable regions are implemented by having the whole web view draggable
// and overlaying regions that are not draggable.
if (&draggable_regions_ != &regions) {
draggable_regions_.clear();
for (const auto& r : regions)
Expand Down
2 changes: 2 additions & 0 deletions shell/browser/native_browser_view_mac.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class NativeBrowserViewMac : public NativeBrowserView {
const std::vector<mojom::DraggableRegionPtr>& regions) override;

private:
std::vector<mojom::DraggableRegionPtr> draggable_regions_;

DISALLOW_COPY_AND_ASSIGN(NativeBrowserViewMac);
};

Expand Down
21 changes: 19 additions & 2 deletions shell/browser/native_browser_view_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,9 @@ - (BOOL)mouseDownCanMoveWindow {
view.frame =
NSMakeRect(bounds.x(), superview_height - bounds.y() - bounds.height(),
bounds.width(), bounds.height());

// Ensure draggable regions are properly updated to reflect new bounds.
UpdateDraggableRegions(draggable_regions_);
}

gfx::Rect NativeBrowserViewMac::GetBounds() {
Expand Down Expand Up @@ -245,8 +248,22 @@ - (BOOL)mouseDownCanMoveWindow {

NSInteger webViewWidth = NSWidth([web_view bounds]);
NSInteger webViewHeight = NSHeight([web_view bounds]);
auto drag_exclude_rects = CalculateNonDraggableRegions(
DraggableRegionsToSkRegion(regions), webViewWidth, webViewHeight);

std::vector<gfx::Rect> drag_exclude_rects;
if (regions.empty()) {
drag_exclude_rects.push_back(gfx::Rect(0, 0, webViewWidth, webViewHeight));
} else {
drag_exclude_rects = CalculateNonDraggableRegions(
DraggableRegionsToSkRegion(regions), webViewWidth, webViewHeight);
}

// Draggable regions are implemented by having the whole web view draggable
// and overlaying regions that are not draggable.
if (&draggable_regions_ != &regions) {
draggable_regions_.clear();
for (const auto& r : regions)
draggable_regions_.push_back(r.Clone());
}

// Remove all DragRegionViews that were added last time. Note that we need
// to copy the `subviews` array to avoid mutation during iteration.
Expand Down