Skip to content

Commit

Permalink
fix: draggable regions with devtools open (#29696)
Browse files Browse the repository at this point in the history
  • Loading branch information
codebytere committed Jun 16, 2021
1 parent 6fd9e42 commit d59e2d7
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 9 deletions.
4 changes: 4 additions & 0 deletions shell/browser/api/electron_api_browser_window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,10 @@ void BrowserWindow::ResetBrowserViews() {
#endif
}

void BrowserWindow::OnDevToolsResized() {
UpdateDraggableRegions(draggable_regions_);
}

void BrowserWindow::SetVibrancy(v8::Isolate* isolate,
v8::Local<v8::Value> value) {
std::string type = gin::V8ToString(isolate, value);
Expand Down
4 changes: 0 additions & 4 deletions shell/browser/api/electron_api_browser_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ class BrowserWindow : public BaseWindow,
void OnActivateContents() override;
void OnPageTitleUpdated(const std::u16string& title,
bool explicit_set) override;
#if defined(OS_MAC)
void OnDevToolsResized() override;
#endif

// NativeWindowObserver:
void RequestPreferredWidth(int* width) override;
Expand Down Expand Up @@ -118,9 +116,7 @@ class BrowserWindow : public BaseWindow,
// it should be cancelled when we can prove that the window is responsive.
base::CancelableRepeatingClosure window_unresponsive_closure_;

#if defined(OS_MAC)
std::vector<mojom::DraggableRegionPtr> draggable_regions_;
#endif

v8::Global<v8::Value> web_contents_;
base::WeakPtr<api::WebContents> api_web_contents_;
Expand Down
4 changes: 0 additions & 4 deletions shell/browser/api/electron_api_browser_window_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@
[contentView viewDidMoveToWindow];
}

void BrowserWindow::OnDevToolsResized() {
UpdateDraggableRegions(draggable_regions_);
}

void BrowserWindow::UpdateDraggableRegions(
const std::vector<mojom::DraggableRegionPtr>& regions) {
if (window_->has_frame())
Expand Down
15 changes: 14 additions & 1 deletion shell/browser/api/electron_api_browser_window_views.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "shell/browser/api/electron_api_browser_window.h"

#include "shell/browser/native_window_views.h"
#include "ui/aura/window.h"

namespace electron {

Expand All @@ -14,8 +15,20 @@ void BrowserWindow::UpdateDraggableRegions(
const std::vector<mojom::DraggableRegionPtr>& regions) {
if (window_->has_frame())
return;

if (&draggable_regions_ != &regions) {
auto const offset =
web_contents()->GetNativeView()->GetBoundsInRootWindow();
auto snapped_regions = mojo::Clone(regions);
for (auto& snapped_region : snapped_regions) {
snapped_region->bounds.Offset(offset.x(), offset.y());
}

draggable_regions_ = mojo::Clone(snapped_regions);
}

static_cast<NativeWindowViews*>(window_.get())
->UpdateDraggableRegions(regions);
->UpdateDraggableRegions(draggable_regions_);
}

} // namespace api
Expand Down
7 changes: 7 additions & 0 deletions shell/browser/ui/views/inspectable_web_contents_view_views.cc
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ void InspectableWebContentsViewViews::ShowDevTools(bool activate) {
} else {
devtools_window_->ShowInactive();
}

// Update draggable regions to account for the new dock position.
if (GetDelegate())
GetDelegate()->DevToolsResized();
} else {
devtools_web_view_->SetVisible(true);
devtools_web_view_->SetWebContents(
Expand Down Expand Up @@ -227,6 +231,9 @@ void InspectableWebContentsViewViews::Layout() {

devtools_web_view_->SetBoundsRect(new_devtools_bounds);
contents_web_view_->SetBoundsRect(new_contents_bounds);

if (GetDelegate())
GetDelegate()->DevToolsResized();
}

} // namespace electron

0 comments on commit d59e2d7

Please sign in to comment.