feat: add BrowserWindow.isSnapped()
(#46079)
* feat: add BrowserWindow.isSnapped() on Windows * docs: mark _Readonly_
This commit is contained in:
parent
47cf4e7bfd
commit
9ec14b91e7
8 changed files with 52 additions and 0 deletions
|
@ -1091,6 +1091,10 @@ void BaseWindow::SetAppDetails(const gin_helper::Dictionary& options) {
|
|||
relaunch_command, relaunch_display_name,
|
||||
window_->GetAcceleratedWidget());
|
||||
}
|
||||
|
||||
bool BaseWindow::IsSnapped() const {
|
||||
return window_->IsSnapped();
|
||||
}
|
||||
#endif
|
||||
|
||||
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_LINUX)
|
||||
|
@ -1335,6 +1339,8 @@ void BaseWindow::BuildPrototype(v8::Isolate* isolate,
|
|||
.SetMethod("setIcon", &BaseWindow::SetIcon)
|
||||
#endif
|
||||
#if BUILDFLAG(IS_WIN)
|
||||
.SetMethod("isSnapped", &BaseWindow::IsSnapped)
|
||||
.SetProperty("snapped", &BaseWindow::IsSnapped)
|
||||
.SetMethod("hookWindowMessage", &BaseWindow::HookWindowMessage)
|
||||
.SetMethod("isWindowMessageHooked", &BaseWindow::IsWindowMessageHooked)
|
||||
.SetMethod("unhookWindowMessage", &BaseWindow::UnhookWindowMessage)
|
||||
|
|
|
@ -252,6 +252,7 @@ class BaseWindow : public gin_helper::TrackableObject<BaseWindow>,
|
|||
bool SetThumbnailClip(const gfx::Rect& region);
|
||||
bool SetThumbnailToolTip(const std::string& tooltip);
|
||||
void SetAppDetails(const gin_helper::Dictionary& options);
|
||||
bool IsSnapped() const;
|
||||
#endif
|
||||
|
||||
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_LINUX)
|
||||
|
|
|
@ -489,6 +489,10 @@ void NativeWindow::SetAspectRatio(double aspect_ratio,
|
|||
aspect_ratio_extraSize_ = extra_size;
|
||||
}
|
||||
|
||||
bool NativeWindow::IsSnapped() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::optional<gfx::Rect> NativeWindow::GetWindowControlsOverlayRect() {
|
||||
return overlay_rect_;
|
||||
}
|
||||
|
|
|
@ -267,6 +267,8 @@ class NativeWindow : public base::SupportsUserData,
|
|||
virtual void SetMenuBarVisibility(bool visible) {}
|
||||
virtual bool IsMenuBarVisible() const;
|
||||
|
||||
virtual bool IsSnapped() const;
|
||||
|
||||
// Set the aspect ratio when resizing window.
|
||||
[[nodiscard]] double aspect_ratio() const { return aspect_ratio_; }
|
||||
[[nodiscard]] gfx::Size aspect_ratio_extra_size() const {
|
||||
|
|
|
@ -1488,6 +1488,22 @@ bool NativeWindowViews::IsMenuBarVisible() const {
|
|||
return root_view_.is_menu_bar_visible();
|
||||
}
|
||||
|
||||
bool NativeWindowViews::IsSnapped() const {
|
||||
#if BUILDFLAG(IS_WIN)
|
||||
// IsWindowArranged() is not a part of any header file.
|
||||
// https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-iswindowarranged
|
||||
using IsWindowArrangedFuncType = BOOL(WINAPI*)(HWND);
|
||||
static const auto is_window_arranged_func =
|
||||
reinterpret_cast<IsWindowArrangedFuncType>(
|
||||
base::win::GetUser32FunctionPointer("IsWindowArranged"));
|
||||
return is_window_arranged_func
|
||||
? is_window_arranged_func(GetAcceleratedWidget())
|
||||
: false;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
void NativeWindowViews::SetBackgroundMaterial(const std::string& material) {
|
||||
NativeWindow::SetBackgroundMaterial(material);
|
||||
|
||||
|
|
|
@ -130,6 +130,7 @@ class NativeWindowViews : public NativeWindow,
|
|||
bool IsMenuBarAutoHide() const override;
|
||||
void SetMenuBarVisibility(bool visible) override;
|
||||
bool IsMenuBarVisible() const override;
|
||||
bool IsSnapped() const override;
|
||||
void SetBackgroundMaterial(const std::string& type) override;
|
||||
|
||||
void SetVisibleOnAllWorkspaces(bool visible,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue