mac: Remove access to webContents in windowWillUseStandardFrame
This commit is contained in:
parent
e73326a324
commit
cad3d694ab
6 changed files with 21 additions and 7 deletions
|
@ -307,6 +307,10 @@ void BrowserWindow::WillCloseWindow(bool* prevent_default) {
|
|||
*prevent_default = Emit("close");
|
||||
}
|
||||
|
||||
void BrowserWindow::RequestPreferredWidth(int* width) {
|
||||
*width = web_contents()->GetPreferredSize().width();
|
||||
}
|
||||
|
||||
void BrowserWindow::OnCloseButtonClicked(bool* prevent_default) {
|
||||
// When user tries to close the window by clicking the close button, we do
|
||||
// not close the window immediately, instead we try to close the web page
|
||||
|
|
|
@ -81,6 +81,7 @@ class BrowserWindow : public mate::TrackableObject<BrowserWindow>,
|
|||
|
||||
// NativeWindowObserver:
|
||||
void WillCloseWindow(bool* prevent_default) override;
|
||||
void RequestPreferredWidth(int* width) override;
|
||||
void OnCloseButtonClicked(bool* prevent_default) override;
|
||||
void OnWindowClosed() override;
|
||||
void OnWindowEndSession() override;
|
||||
|
|
|
@ -402,6 +402,11 @@ void NativeWindow::PreviewFile(const std::string& path,
|
|||
void NativeWindow::CloseFilePreview() {
|
||||
}
|
||||
|
||||
void NativeWindow::NotifyWindowRequestPreferredWith(int* width) {
|
||||
for (NativeWindowObserver& observer : observers_)
|
||||
observer.RequestPreferredWidth(width);
|
||||
}
|
||||
|
||||
void NativeWindow::NotifyWindowCloseButtonClicked() {
|
||||
// First ask the observers whether we want to close.
|
||||
bool prevent_default = false;
|
||||
|
|
|
@ -243,6 +243,7 @@ class NativeWindow : public base::SupportsUserData,
|
|||
|
||||
// Public API used by platform-dependent delegates and observers to send UI
|
||||
// related notifications.
|
||||
void NotifyWindowRequestPreferredWith(int* width);
|
||||
void NotifyWindowCloseButtonClicked();
|
||||
void NotifyWindowClosed();
|
||||
void NotifyWindowEndSession();
|
||||
|
|
|
@ -218,16 +218,16 @@ bool ScopedDisableResize::disable_resize_ = false;
|
|||
if ([[NSApp currentEvent] modifierFlags] & NSShiftKeyMask)
|
||||
return frame;
|
||||
|
||||
content::WebContents* web_contents = shell_->web_contents();
|
||||
if (!web_contents)
|
||||
// Get preferred width from observers. Usually the page width.
|
||||
int preferred_width = 0;
|
||||
shell_->NotifyWindowRequestPreferredWith(&preferred_width);
|
||||
if (preferred_width <= 0)
|
||||
return frame;
|
||||
|
||||
CGFloat page_width = static_cast<CGFloat>(
|
||||
web_contents->GetPreferredSize().width());
|
||||
NSRect window_frame = [window frame];
|
||||
|
||||
// Never shrink from the current size on zoom.
|
||||
CGFloat zoomed_width = std::max(page_width, NSWidth(window_frame));
|
||||
NSRect window_frame = [window frame];
|
||||
CGFloat zoomed_width = std::max(static_cast<CGFloat>(preferred_width),
|
||||
NSWidth(window_frame));
|
||||
|
||||
// |frame| determines our maximum extents. We need to set the origin of the
|
||||
// frame -- and only move it left if necessary.
|
||||
|
|
|
@ -34,6 +34,9 @@ class NativeWindowObserver {
|
|||
// Called when the window is gonna closed.
|
||||
virtual void WillCloseWindow(bool* prevent_default) {}
|
||||
|
||||
// Called when the window wants to know the preferred width.
|
||||
virtual void RequestPreferredWidth(int* width) {}
|
||||
|
||||
// Called when closed button is clicked.
|
||||
virtual void OnCloseButtonClicked(bool* prevent_default) {}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue