Skip to content

Commit

Permalink
fix: update draggable regions when resizing
Browse files Browse the repository at this point in the history
  • Loading branch information
zcbenz authored and electron-bot committed Nov 9, 2020
1 parent 015333e commit 52175a0
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 0 deletions.
3 changes: 3 additions & 0 deletions shell/browser/api/electron_api_browser_window.h
Expand Up @@ -63,6 +63,9 @@ class BrowserWindow : public TopLevelWindow,
void OnActivateContents() override;
void OnPageTitleUpdated(const base::string16& title,
bool explicit_set) override;
#if defined(OS_MAC)
void OnDevToolsResized() override;
#endif

// NativeWindowObserver:
void RequestPreferredWidth(int* width) override;
Expand Down
4 changes: 4 additions & 0 deletions shell/browser/api/electron_api_browser_window_mac.mm
Expand Up @@ -36,6 +36,10 @@
[contentView viewDidMoveToWindow];
}

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

void BrowserWindow::UpdateDraggableRegions(
const std::vector<mojom::DraggableRegionPtr>& regions) {
if (window_->has_frame())
Expand Down
5 changes: 5 additions & 0 deletions shell/browser/api/electron_api_web_contents.cc
Expand Up @@ -1462,6 +1462,11 @@ void WebContents::DevToolsClosed() {
Emit("devtools-closed");
}

void WebContents::DevToolsResized() {
for (ExtendedWebContentsObserver& observer : observers_)
observer.OnDevToolsResized();
}

bool WebContents::OnMessageReceived(const IPC::Message& message) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(WebContents, message)
Expand Down
1 change: 1 addition & 0 deletions shell/browser/api/electron_api_web_contents.h
Expand Up @@ -554,6 +554,7 @@ class WebContents : public gin_helper::TrackableObject<WebContents>,
void DevToolsFocused() override;
void DevToolsOpened() override;
void DevToolsClosed() override;
void DevToolsResized() override;

private:
ElectronBrowserContext* GetBrowserContext() const;
Expand Down
1 change: 1 addition & 0 deletions shell/browser/extended_web_contents_observer.h
Expand Up @@ -25,6 +25,7 @@ class ExtendedWebContentsObserver : public base::CheckedObserver {
virtual void OnActivateContents() {}
virtual void OnPageTitleUpdated(const base::string16& title,
bool explicit_set) {}
virtual void OnDevToolsResized() {}

protected:
~ExtendedWebContentsObserver() override {}
Expand Down
11 changes: 11 additions & 0 deletions shell/browser/ui/cocoa/electron_inspectable_web_contents_view.mm
Expand Up @@ -86,6 +86,14 @@ - (void)notifyDevToolsFocused {
inspectableWebContentsView_->GetDelegate()->DevToolsFocused();
}

- (void)notifyDevToolsResized {
// When devtools is opened, resizing devtools would not trigger
// UpdateDraggableRegions for WebContents, so we have to notify the window
// to do an update of draggable regions.
if (inspectableWebContentsView_->GetDelegate())
inspectableWebContentsView_->GetDelegate()->DevToolsResized();
}

- (void)setDevToolsVisible:(BOOL)visible activate:(BOOL)activate {
if (visible == devtools_visible_)
return;
Expand Down Expand Up @@ -117,6 +125,7 @@ - (void)setDevToolsVisible:(BOOL)visible activate:(BOOL)activate {
[devToolsView removeFromSuperview];
[devtools_mask_ removeFromSuperview];
[self adjustSubviews];
[self notifyDevToolsResized];
}
} else {
if (visible) {
Expand Down Expand Up @@ -233,6 +242,8 @@ - (void)adjustSubviews {
devtools_frame.size.height = sb.size.height;
}
[devtools_mask_ setFrame:devtools_frame];

[self notifyDevToolsResized];
}

- (void)setTitle:(NSString*)title {
Expand Down
1 change: 1 addition & 0 deletions shell/browser/ui/inspectable_web_contents_view_delegate.h
Expand Up @@ -19,6 +19,7 @@ class InspectableWebContentsViewDelegate {
virtual void DevToolsFocused() {}
virtual void DevToolsOpened() {}
virtual void DevToolsClosed() {}
virtual void DevToolsResized() {}

// Returns the icon of devtools window.
virtual gfx::ImageSkia GetDevToolsWindowIcon();
Expand Down

0 comments on commit 52175a0

Please sign in to comment.