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 regions with devtools open #29696

Merged
merged 1 commit into from
Jun 16, 2021
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
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