2014-10-31 18:17:05 +00:00
|
|
|
// Copyright (c) 2013 GitHub, Inc.
|
2014-04-25 09:49:37 +00:00
|
|
|
// Use of this source code is governed by the MIT license that can be
|
2013-04-12 07:04:46 +00:00
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/browser/native_window.h"
|
2013-04-12 07:04:46 +00:00
|
|
|
|
2018-05-12 15:37:31 +00:00
|
|
|
#include <algorithm>
|
2013-04-12 07:04:46 +00:00
|
|
|
#include <string>
|
2014-03-16 01:13:06 +00:00
|
|
|
#include <vector>
|
2013-04-12 07:04:46 +00:00
|
|
|
|
2023-05-30 08:28:43 +00:00
|
|
|
#include "base/containers/contains.h"
|
2019-08-29 06:57:11 +00:00
|
|
|
#include "base/memory/ptr_util.h"
|
|
|
|
#include "base/strings/utf_string_conversions.h"
|
2021-07-02 00:51:37 +00:00
|
|
|
#include "base/values.h"
|
2022-01-10 22:31:39 +00:00
|
|
|
#include "content/public/browser/web_contents_user_data.h"
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/browser/browser.h"
|
2022-01-26 21:59:09 +00:00
|
|
|
#include "shell/browser/native_window_features.h"
|
2022-10-12 16:05:45 +00:00
|
|
|
#include "shell/browser/ui/drag_util.h"
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/browser/window_list.h"
|
|
|
|
#include "shell/common/color_util.h"
|
2019-10-25 13:03:28 +00:00
|
|
|
#include "shell/common/gin_helper/dictionary.h"
|
2019-10-31 07:56:00 +00:00
|
|
|
#include "shell/common/gin_helper/persistent_dictionary.h"
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/common/options_switches.h"
|
2022-10-12 16:05:45 +00:00
|
|
|
#include "third_party/skia/include/core/SkRegion.h"
|
2022-11-07 18:15:57 +00:00
|
|
|
#include "ui/base/hit_test.h"
|
2018-05-12 19:33:47 +00:00
|
|
|
#include "ui/views/widget/widget.h"
|
|
|
|
|
2023-01-26 13:04:19 +00:00
|
|
|
#if !BUILDFLAG(IS_MAC)
|
|
|
|
#include "shell/browser/ui/views/frameless_view.h"
|
|
|
|
#endif
|
|
|
|
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2018-05-12 15:37:31 +00:00
|
|
|
#include "ui/base/win/shell.h"
|
|
|
|
#include "ui/display/win/screen_win.h"
|
2018-05-12 19:33:47 +00:00
|
|
|
#endif
|
2013-04-12 07:04:46 +00:00
|
|
|
|
2022-03-28 16:48:50 +00:00
|
|
|
#if defined(USE_OZONE)
|
2022-01-26 21:59:09 +00:00
|
|
|
#include "ui/base/ui_base_features.h"
|
|
|
|
#include "ui/ozone/public/ozone_platform.h"
|
|
|
|
#endif
|
|
|
|
|
2021-08-11 18:07:36 +00:00
|
|
|
namespace gin {
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct Converter<electron::NativeWindow::TitleBarStyle> {
|
|
|
|
static bool FromV8(v8::Isolate* isolate,
|
|
|
|
v8::Handle<v8::Value> val,
|
|
|
|
electron::NativeWindow::TitleBarStyle* out) {
|
|
|
|
using TitleBarStyle = electron::NativeWindow::TitleBarStyle;
|
|
|
|
std::string title_bar_style;
|
|
|
|
if (!ConvertFromV8(isolate, val, &title_bar_style))
|
|
|
|
return false;
|
|
|
|
if (title_bar_style == "hidden") {
|
|
|
|
*out = TitleBarStyle::kHidden;
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_MAC)
|
2021-08-11 18:07:36 +00:00
|
|
|
} else if (title_bar_style == "hiddenInset") {
|
|
|
|
*out = TitleBarStyle::kHiddenInset;
|
|
|
|
} else if (title_bar_style == "customButtonsOnHover") {
|
|
|
|
*out = TitleBarStyle::kCustomButtonsOnHover;
|
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace gin
|
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
namespace electron {
|
2013-04-12 07:04:46 +00:00
|
|
|
|
2018-05-12 15:37:31 +00:00
|
|
|
namespace {
|
|
|
|
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2018-05-12 17:51:19 +00:00
|
|
|
gfx::Size GetExpandedWindowSize(const NativeWindow* window, gfx::Size size) {
|
2023-02-03 11:43:42 +00:00
|
|
|
if (!window->transparent())
|
2018-05-12 17:51:19 +00:00
|
|
|
return size;
|
2018-05-12 15:37:31 +00:00
|
|
|
|
2018-05-12 17:51:19 +00:00
|
|
|
gfx::Size min_size = display::win::ScreenWin::ScreenToDIPSize(
|
2018-05-12 15:37:31 +00:00
|
|
|
window->GetAcceleratedWidget(), gfx::Size(64, 64));
|
|
|
|
|
2018-05-12 17:51:19 +00:00
|
|
|
// Some AMD drivers can't display windows that are less than 64x64 pixels,
|
|
|
|
// so expand them to be at least that size. http://crbug.com/286609
|
|
|
|
gfx::Size expanded(std::max(size.width(), min_size.width()),
|
|
|
|
std::max(size.height(), min_size.height()));
|
|
|
|
return expanded;
|
|
|
|
}
|
2018-05-12 15:37:31 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2019-10-25 13:03:28 +00:00
|
|
|
NativeWindow::NativeWindow(const gin_helper::Dictionary& options,
|
2018-04-10 06:23:16 +00:00
|
|
|
NativeWindow* parent)
|
2021-06-08 02:00:05 +00:00
|
|
|
: widget_(std::make_unique<views::Widget>()), parent_(parent) {
|
2020-07-16 17:14:54 +00:00
|
|
|
++next_id_;
|
|
|
|
|
2015-11-13 05:58:31 +00:00
|
|
|
options.Get(options::kFrame, &has_frame_);
|
|
|
|
options.Get(options::kTransparent, &transparent_);
|
|
|
|
options.Get(options::kEnableLargerThanScreen, &enable_larger_than_screen_);
|
2021-08-11 18:07:36 +00:00
|
|
|
options.Get(options::kTitleBarStyle, &title_bar_style_);
|
|
|
|
|
|
|
|
v8::Local<v8::Value> titlebar_overlay;
|
|
|
|
if (options.Get(options::ktitleBarOverlay, &titlebar_overlay)) {
|
|
|
|
if (titlebar_overlay->IsBoolean()) {
|
|
|
|
options.Get(options::ktitleBarOverlay, &titlebar_overlay_);
|
|
|
|
} else if (titlebar_overlay->IsObject()) {
|
|
|
|
titlebar_overlay_ = true;
|
2022-01-24 22:09:21 +00:00
|
|
|
|
2022-09-07 07:46:37 +00:00
|
|
|
gin_helper::Dictionary titlebar_overlay_dict =
|
2022-01-24 22:09:21 +00:00
|
|
|
gin::Dictionary::CreateEmpty(options.isolate());
|
2022-09-07 07:46:37 +00:00
|
|
|
options.Get(options::ktitleBarOverlay, &titlebar_overlay_dict);
|
2022-01-24 22:09:21 +00:00
|
|
|
int height;
|
2022-09-07 07:46:37 +00:00
|
|
|
if (titlebar_overlay_dict.Get(options::kOverlayHeight, &height))
|
2022-01-24 22:09:21 +00:00
|
|
|
titlebar_overlay_height_ = height;
|
|
|
|
|
2022-02-10 02:58:52 +00:00
|
|
|
#if !(BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC))
|
2021-08-11 18:07:36 +00:00
|
|
|
DCHECK(false);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
2013-09-05 13:43:47 +00:00
|
|
|
|
2016-06-20 05:49:24 +00:00
|
|
|
if (parent)
|
|
|
|
options.Get("modal", &is_modal_);
|
|
|
|
|
2022-01-26 21:59:09 +00:00
|
|
|
#if defined(USE_OZONE)
|
|
|
|
// Ozone X11 likes to prefer custom frames, but we don't need them unless
|
|
|
|
// on Wayland.
|
|
|
|
if (base::FeatureList::IsEnabled(features::kWaylandWindowDecorations) &&
|
|
|
|
!ui::OzonePlatform::GetInstance()
|
|
|
|
->GetPlatformRuntimeProperties()
|
|
|
|
.supports_server_side_window_decorations) {
|
|
|
|
has_client_frame_ = true;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-05-02 14:54:09 +00:00
|
|
|
WindowList::AddWindow(this);
|
2013-04-12 07:04:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NativeWindow::~NativeWindow() {
|
2013-05-02 12:08:23 +00:00
|
|
|
// It's possible that the windows gets destroyed before it's closed, in that
|
2018-07-22 17:42:57 +00:00
|
|
|
// case we need to ensure the Widget delegate gets destroyed and
|
|
|
|
// OnWindowClosed message is still notified.
|
|
|
|
if (widget_->widget_delegate())
|
|
|
|
widget_->OnNativeWidgetDestroyed();
|
2013-05-02 12:08:23 +00:00
|
|
|
NotifyWindowClosed();
|
2013-04-12 07:04:46 +00:00
|
|
|
}
|
|
|
|
|
2019-10-25 13:03:28 +00:00
|
|
|
void NativeWindow::InitFromOptions(const gin_helper::Dictionary& options) {
|
2013-04-12 07:04:46 +00:00
|
|
|
// Setup window from options.
|
2013-07-01 14:01:17 +00:00
|
|
|
int x = -1, y = -1;
|
2013-05-10 12:34:05 +00:00
|
|
|
bool center;
|
2015-11-13 05:58:31 +00:00
|
|
|
if (options.Get(options::kX, &x) && options.Get(options::kY, &y)) {
|
2016-01-15 16:31:31 +00:00
|
|
|
SetPosition(gfx::Point(x, y));
|
2017-10-30 18:19:50 +00:00
|
|
|
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2017-11-01 18:30:32 +00:00
|
|
|
// FIXME(felixrieseberg): Dirty, dirty workaround for
|
2017-10-30 18:19:50 +00:00
|
|
|
// https://github.com/electron/electron/issues/10862
|
|
|
|
// Somehow, we need to call `SetBounds` twice to get
|
|
|
|
// usable results. The root cause is still unknown.
|
|
|
|
SetPosition(gfx::Point(x, y));
|
|
|
|
#endif
|
2015-11-13 05:58:31 +00:00
|
|
|
} else if (options.Get(options::kCenter, ¢er) && center) {
|
2013-05-10 12:34:05 +00:00
|
|
|
Center();
|
2013-04-12 07:04:46 +00:00
|
|
|
}
|
2019-01-31 02:19:47 +00:00
|
|
|
|
|
|
|
bool use_content_size = false;
|
|
|
|
options.Get(options::kUseContentSize, &use_content_size);
|
|
|
|
|
2015-10-15 08:35:50 +00:00
|
|
|
// On Linux and Window we may already have maximum size defined.
|
2019-01-31 02:19:47 +00:00
|
|
|
extensions::SizeConstraints size_constraints(
|
|
|
|
use_content_size ? GetContentSizeConstraints() : GetSizeConstraints());
|
2022-03-01 22:20:07 +00:00
|
|
|
|
2022-01-26 22:00:17 +00:00
|
|
|
int min_width = size_constraints.GetMinimumSize().width();
|
|
|
|
int min_height = size_constraints.GetMinimumSize().height();
|
|
|
|
options.Get(options::kMinWidth, &min_width);
|
|
|
|
options.Get(options::kMinHeight, &min_height);
|
|
|
|
size_constraints.set_minimum_size(gfx::Size(min_width, min_height));
|
2022-03-01 22:20:07 +00:00
|
|
|
|
|
|
|
gfx::Size max_size = size_constraints.GetMaximumSize();
|
|
|
|
int max_width = max_size.width() > 0 ? max_size.width() : INT_MAX;
|
|
|
|
int max_height = max_size.height() > 0 ? max_size.height() : INT_MAX;
|
|
|
|
bool have_max_width = options.Get(options::kMaxWidth, &max_width);
|
2022-12-01 01:02:22 +00:00
|
|
|
if (have_max_width && max_width <= 0)
|
|
|
|
max_width = INT_MAX;
|
2022-03-01 22:20:07 +00:00
|
|
|
bool have_max_height = options.Get(options::kMaxHeight, &max_height);
|
2022-12-01 01:02:22 +00:00
|
|
|
if (have_max_height && max_height <= 0)
|
|
|
|
max_height = INT_MAX;
|
2022-03-01 22:20:07 +00:00
|
|
|
|
|
|
|
// By default the window has a default maximum size that prevents it
|
|
|
|
// from being resized larger than the screen, so we should only set this
|
2022-07-05 15:49:56 +00:00
|
|
|
// if the user has passed in values.
|
2022-03-01 22:20:07 +00:00
|
|
|
if (have_max_height || have_max_width || !max_size.IsEmpty())
|
|
|
|
size_constraints.set_maximum_size(gfx::Size(max_width, max_height));
|
|
|
|
|
2015-10-05 12:36:28 +00:00
|
|
|
if (use_content_size) {
|
|
|
|
SetContentSizeConstraints(size_constraints);
|
|
|
|
} else {
|
|
|
|
SetSizeConstraints(size_constraints);
|
2013-04-12 07:04:46 +00:00
|
|
|
}
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_LINUX)
|
2016-03-07 21:48:33 +00:00
|
|
|
bool resizable;
|
|
|
|
if (options.Get(options::kResizable, &resizable)) {
|
|
|
|
SetResizable(resizable);
|
|
|
|
}
|
2016-01-18 22:46:35 +00:00
|
|
|
bool closable;
|
|
|
|
if (options.Get(options::kClosable, &closable)) {
|
|
|
|
SetClosable(closable);
|
|
|
|
}
|
2015-10-06 07:23:23 +00:00
|
|
|
#endif
|
2016-01-23 10:23:18 +00:00
|
|
|
bool movable;
|
2016-01-23 11:35:30 +00:00
|
|
|
if (options.Get(options::kMovable, &movable)) {
|
2016-01-23 10:23:18 +00:00
|
|
|
SetMovable(movable);
|
|
|
|
}
|
2016-01-23 10:55:12 +00:00
|
|
|
bool has_shadow;
|
|
|
|
if (options.Get(options::kHasShadow, &has_shadow)) {
|
|
|
|
SetHasShadow(has_shadow);
|
|
|
|
}
|
2017-09-29 02:26:02 +00:00
|
|
|
double opacity;
|
|
|
|
if (options.Get(options::kOpacity, &opacity)) {
|
|
|
|
SetOpacity(opacity);
|
|
|
|
}
|
2013-04-12 07:04:46 +00:00
|
|
|
bool top;
|
2015-11-13 05:58:31 +00:00
|
|
|
if (options.Get(options::kAlwaysOnTop, &top) && top) {
|
2019-07-24 22:58:51 +00:00
|
|
|
SetAlwaysOnTop(ui::ZOrderLevel::kFloatingWindow);
|
2013-04-12 07:04:46 +00:00
|
|
|
}
|
2016-02-22 09:23:56 +00:00
|
|
|
bool fullscreenable = true;
|
|
|
|
bool fullscreen = false;
|
2016-05-30 00:12:16 +00:00
|
|
|
if (options.Get(options::kFullscreen, &fullscreen) && !fullscreen) {
|
|
|
|
// Disable fullscreen button if 'fullscreen' is specified to false.
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_MAC)
|
2016-02-22 09:23:56 +00:00
|
|
|
fullscreenable = false;
|
2018-04-18 01:55:30 +00:00
|
|
|
#endif
|
2016-05-30 00:12:16 +00:00
|
|
|
}
|
2021-04-21 14:56:25 +00:00
|
|
|
// Overridden by 'fullscreenable'.
|
2016-03-05 12:54:41 +00:00
|
|
|
options.Get(options::kFullScreenable, &fullscreenable);
|
2016-02-22 09:23:56 +00:00
|
|
|
SetFullScreenable(fullscreenable);
|
2016-03-05 12:54:41 +00:00
|
|
|
if (fullscreen) {
|
2014-11-25 06:34:14 +00:00
|
|
|
SetFullScreen(true);
|
2016-03-05 12:54:41 +00:00
|
|
|
}
|
2014-06-16 02:29:51 +00:00
|
|
|
bool skip;
|
2016-06-13 08:24:45 +00:00
|
|
|
if (options.Get(options::kSkipTaskbar, &skip)) {
|
2014-06-16 02:29:51 +00:00
|
|
|
SetSkipTaskbar(skip);
|
|
|
|
}
|
2013-04-12 07:04:46 +00:00
|
|
|
bool kiosk;
|
2015-11-13 05:58:31 +00:00
|
|
|
if (options.Get(options::kKiosk, &kiosk) && kiosk) {
|
2013-04-12 07:04:46 +00:00
|
|
|
SetKiosk(kiosk);
|
|
|
|
}
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_MAC)
|
2018-04-10 07:54:07 +00:00
|
|
|
std::string type;
|
|
|
|
if (options.Get(options::kVibrancyType, &type)) {
|
|
|
|
SetVibrancy(type);
|
|
|
|
}
|
2023-05-15 20:31:57 +00:00
|
|
|
#elif BUILDFLAG(IS_WIN)
|
|
|
|
std::string material;
|
|
|
|
if (options.Get(options::kBackgroundMaterial, &material)) {
|
|
|
|
SetBackgroundMaterial(material);
|
|
|
|
}
|
2018-04-10 07:54:07 +00:00
|
|
|
#endif
|
2015-10-23 03:35:33 +00:00
|
|
|
std::string color;
|
2015-11-13 05:58:31 +00:00
|
|
|
if (options.Get(options::kBackgroundColor, &color)) {
|
2022-03-21 17:35:54 +00:00
|
|
|
SetBackgroundColor(ParseCSSColor(color));
|
2016-04-14 10:35:31 +00:00
|
|
|
} else if (!transparent()) {
|
|
|
|
// For normal window, use white as default background.
|
2018-03-06 04:21:47 +00:00
|
|
|
SetBackgroundColor(SK_ColorWHITE);
|
2015-10-23 03:35:33 +00:00
|
|
|
}
|
2016-06-08 21:17:33 +00:00
|
|
|
std::string title(Browser::Get()->GetName());
|
2015-11-13 05:58:31 +00:00
|
|
|
options.Get(options::kTitle, &title);
|
2013-04-12 07:04:46 +00:00
|
|
|
SetTitle(title);
|
|
|
|
|
|
|
|
// Then show it.
|
|
|
|
bool show = true;
|
2015-11-13 05:58:31 +00:00
|
|
|
options.Get(options::kShow, &show);
|
2015-10-01 09:46:11 +00:00
|
|
|
if (show)
|
2013-04-12 07:04:46 +00:00
|
|
|
Show();
|
|
|
|
}
|
|
|
|
|
2018-04-17 23:47:47 +00:00
|
|
|
bool NativeWindow::IsClosed() const {
|
|
|
|
return is_closed_;
|
|
|
|
}
|
|
|
|
|
2016-01-15 04:54:12 +00:00
|
|
|
void NativeWindow::SetSize(const gfx::Size& size, bool animate) {
|
|
|
|
SetBounds(gfx::Rect(GetPosition(), size), animate);
|
2015-05-04 04:43:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gfx::Size NativeWindow::GetSize() {
|
|
|
|
return GetBounds().size();
|
|
|
|
}
|
|
|
|
|
2016-01-15 04:54:12 +00:00
|
|
|
void NativeWindow::SetPosition(const gfx::Point& position, bool animate) {
|
|
|
|
SetBounds(gfx::Rect(position, GetSize()), animate);
|
2015-05-04 04:43:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gfx::Point NativeWindow::GetPosition() {
|
|
|
|
return GetBounds().origin();
|
|
|
|
}
|
|
|
|
|
2016-01-15 04:54:12 +00:00
|
|
|
void NativeWindow::SetContentSize(const gfx::Size& size, bool animate) {
|
2016-08-04 19:10:01 +00:00
|
|
|
SetSize(ContentBoundsToWindowBounds(gfx::Rect(size)).size(), animate);
|
2015-10-05 08:19:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gfx::Size NativeWindow::GetContentSize() {
|
2016-08-04 17:58:59 +00:00
|
|
|
return GetContentBounds().size();
|
2016-08-04 19:02:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void NativeWindow::SetContentBounds(const gfx::Rect& bounds, bool animate) {
|
|
|
|
SetBounds(ContentBoundsToWindowBounds(bounds), animate);
|
2016-08-04 17:58:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gfx::Rect NativeWindow::GetContentBounds() {
|
|
|
|
return WindowBoundsToContentBounds(GetBounds());
|
2015-10-05 08:19:01 +00:00
|
|
|
}
|
|
|
|
|
2018-08-24 21:33:27 +00:00
|
|
|
bool NativeWindow::IsNormal() {
|
|
|
|
return !IsMinimized() && !IsMaximized() && !IsFullscreen();
|
|
|
|
}
|
|
|
|
|
2015-10-05 08:19:01 +00:00
|
|
|
void NativeWindow::SetSizeConstraints(
|
|
|
|
const extensions::SizeConstraints& window_constraints) {
|
2016-07-12 17:05:32 +00:00
|
|
|
extensions::SizeConstraints content_constraints(GetContentSizeConstraints());
|
2016-08-04 17:58:59 +00:00
|
|
|
if (window_constraints.HasMaximumSize()) {
|
|
|
|
gfx::Rect max_bounds = WindowBoundsToContentBounds(
|
|
|
|
gfx::Rect(window_constraints.GetMaximumSize()));
|
|
|
|
content_constraints.set_maximum_size(max_bounds.size());
|
|
|
|
}
|
|
|
|
if (window_constraints.HasMinimumSize()) {
|
|
|
|
gfx::Rect min_bounds = WindowBoundsToContentBounds(
|
|
|
|
gfx::Rect(window_constraints.GetMinimumSize()));
|
|
|
|
content_constraints.set_minimum_size(min_bounds.size());
|
|
|
|
}
|
2015-10-05 08:19:01 +00:00
|
|
|
SetContentSizeConstraints(content_constraints);
|
|
|
|
}
|
|
|
|
|
2017-05-21 18:57:19 +00:00
|
|
|
extensions::SizeConstraints NativeWindow::GetSizeConstraints() const {
|
2015-10-05 08:19:01 +00:00
|
|
|
extensions::SizeConstraints content_constraints = GetContentSizeConstraints();
|
|
|
|
extensions::SizeConstraints window_constraints;
|
2016-08-04 17:58:59 +00:00
|
|
|
if (content_constraints.HasMaximumSize()) {
|
|
|
|
gfx::Rect max_bounds = ContentBoundsToWindowBounds(
|
|
|
|
gfx::Rect(content_constraints.GetMaximumSize()));
|
2016-08-04 19:14:23 +00:00
|
|
|
window_constraints.set_maximum_size(max_bounds.size());
|
2016-08-04 17:58:59 +00:00
|
|
|
}
|
|
|
|
if (content_constraints.HasMinimumSize()) {
|
|
|
|
gfx::Rect min_bounds = ContentBoundsToWindowBounds(
|
|
|
|
gfx::Rect(content_constraints.GetMinimumSize()));
|
|
|
|
window_constraints.set_minimum_size(min_bounds.size());
|
|
|
|
}
|
2015-10-05 08:19:01 +00:00
|
|
|
return window_constraints;
|
|
|
|
}
|
|
|
|
|
|
|
|
void NativeWindow::SetContentSizeConstraints(
|
|
|
|
const extensions::SizeConstraints& size_constraints) {
|
|
|
|
size_constraints_ = size_constraints;
|
|
|
|
}
|
|
|
|
|
2017-05-21 18:57:19 +00:00
|
|
|
extensions::SizeConstraints NativeWindow::GetContentSizeConstraints() const {
|
2015-10-05 08:19:01 +00:00
|
|
|
return size_constraints_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void NativeWindow::SetMinimumSize(const gfx::Size& size) {
|
|
|
|
extensions::SizeConstraints size_constraints;
|
|
|
|
size_constraints.set_minimum_size(size);
|
|
|
|
SetSizeConstraints(size_constraints);
|
|
|
|
}
|
|
|
|
|
2017-05-21 18:57:19 +00:00
|
|
|
gfx::Size NativeWindow::GetMinimumSize() const {
|
2015-10-05 08:19:01 +00:00
|
|
|
return GetSizeConstraints().GetMinimumSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
void NativeWindow::SetMaximumSize(const gfx::Size& size) {
|
|
|
|
extensions::SizeConstraints size_constraints;
|
|
|
|
size_constraints.set_maximum_size(size);
|
|
|
|
SetSizeConstraints(size_constraints);
|
|
|
|
}
|
|
|
|
|
2017-05-21 18:57:19 +00:00
|
|
|
gfx::Size NativeWindow::GetMaximumSize() const {
|
2015-10-05 08:19:01 +00:00
|
|
|
return GetSizeConstraints().GetMaximumSize();
|
|
|
|
}
|
|
|
|
|
2018-05-12 15:37:31 +00:00
|
|
|
gfx::Size NativeWindow::GetContentMinimumSize() const {
|
|
|
|
return GetContentSizeConstraints().GetMinimumSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
gfx::Size NativeWindow::GetContentMaximumSize() const {
|
|
|
|
gfx::Size maximum_size = GetContentSizeConstraints().GetMaximumSize();
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2018-05-21 00:56:45 +00:00
|
|
|
return GetContentSizeConstraints().HasMaximumSize()
|
|
|
|
? GetExpandedWindowSize(this, maximum_size)
|
|
|
|
: maximum_size;
|
2018-05-12 20:05:25 +00:00
|
|
|
#else
|
2018-05-12 15:37:31 +00:00
|
|
|
return maximum_size;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2016-05-20 03:19:08 +00:00
|
|
|
void NativeWindow::SetSheetOffset(const double offsetX, const double offsetY) {
|
2016-05-19 06:39:16 +00:00
|
|
|
sheet_offset_x_ = offsetX;
|
|
|
|
sheet_offset_y_ = offsetY;
|
2016-04-19 05:39:12 +00:00
|
|
|
}
|
|
|
|
|
2016-05-19 06:39:16 +00:00
|
|
|
double NativeWindow::GetSheetOffsetX() {
|
|
|
|
return sheet_offset_x_;
|
|
|
|
}
|
|
|
|
|
|
|
|
double NativeWindow::GetSheetOffsetY() {
|
|
|
|
return sheet_offset_y_;
|
2016-04-19 05:39:12 +00:00
|
|
|
}
|
|
|
|
|
2020-09-22 05:40:42 +00:00
|
|
|
bool NativeWindow::IsTabletMode() const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-04-18 01:55:30 +00:00
|
|
|
void NativeWindow::SetRepresentedFilename(const std::string& filename) {}
|
2014-05-27 06:15:34 +00:00
|
|
|
|
2014-07-18 13:42:26 +00:00
|
|
|
std::string NativeWindow::GetRepresentedFilename() {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2018-04-18 01:55:30 +00:00
|
|
|
void NativeWindow::SetDocumentEdited(bool edited) {}
|
2014-05-27 06:15:34 +00:00
|
|
|
|
2014-08-21 13:00:49 +00:00
|
|
|
bool NativeWindow::IsDocumentEdited() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-04-18 01:55:30 +00:00
|
|
|
void NativeWindow::SetFocusable(bool focusable) {}
|
2016-06-13 08:10:28 +00:00
|
|
|
|
2021-04-21 10:32:19 +00:00
|
|
|
bool NativeWindow::IsFocusable() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
void NativeWindow::SetMenu(ElectronMenuModel* menu) {}
|
2014-02-10 12:07:38 +00:00
|
|
|
|
2016-06-20 05:49:24 +00:00
|
|
|
void NativeWindow::SetParentWindow(NativeWindow* parent) {
|
|
|
|
parent_ = parent;
|
2016-06-18 13:53:41 +00:00
|
|
|
}
|
|
|
|
|
2022-12-01 18:24:44 +00:00
|
|
|
void NativeWindow::InvalidateShadow() {}
|
|
|
|
|
2018-04-18 01:55:30 +00:00
|
|
|
void NativeWindow::SetAutoHideCursor(bool auto_hide) {}
|
2016-11-28 19:38:40 +00:00
|
|
|
|
2018-04-18 01:55:30 +00:00
|
|
|
void NativeWindow::SelectPreviousTab() {}
|
2017-08-21 04:46:10 +00:00
|
|
|
|
2018-04-18 01:55:30 +00:00
|
|
|
void NativeWindow::SelectNextTab() {}
|
2017-08-21 04:46:10 +00:00
|
|
|
|
2018-04-18 01:55:30 +00:00
|
|
|
void NativeWindow::MergeAllWindows() {}
|
2017-08-21 04:46:10 +00:00
|
|
|
|
2018-04-18 01:55:30 +00:00
|
|
|
void NativeWindow::MoveTabToNewWindow() {}
|
2017-08-21 04:46:10 +00:00
|
|
|
|
2018-04-18 01:55:30 +00:00
|
|
|
void NativeWindow::ToggleTabBar() {}
|
2017-08-21 04:46:10 +00:00
|
|
|
|
2018-02-27 21:00:42 +00:00
|
|
|
bool NativeWindow::AddTabbedWindow(NativeWindow* window) {
|
|
|
|
return true; // for non-Mac platforms
|
2017-09-13 19:15:14 +00:00
|
|
|
}
|
|
|
|
|
2020-10-27 15:18:36 +00:00
|
|
|
void NativeWindow::SetVibrancy(const std::string& type) {}
|
2016-11-10 10:59:25 +00:00
|
|
|
|
2023-05-15 20:31:57 +00:00
|
|
|
void NativeWindow::SetBackgroundMaterial(const std::string& type) {}
|
|
|
|
|
2017-03-01 00:14:02 +00:00
|
|
|
void NativeWindow::SetTouchBar(
|
2019-10-31 07:56:00 +00:00
|
|
|
std::vector<gin_helper::PersistentDictionary> items) {}
|
2016-11-27 05:57:01 +00:00
|
|
|
|
2018-04-18 01:55:30 +00:00
|
|
|
void NativeWindow::RefreshTouchBarItem(const std::string& item_id) {}
|
2016-12-16 06:24:51 +00:00
|
|
|
|
2017-03-29 19:41:49 +00:00
|
|
|
void NativeWindow::SetEscapeTouchBarItem(
|
2019-10-31 07:56:00 +00:00
|
|
|
gin_helper::PersistentDictionary item) {}
|
2017-03-27 00:22:52 +00:00
|
|
|
|
2018-04-18 01:55:30 +00:00
|
|
|
void NativeWindow::SetAutoHideMenuBar(bool auto_hide) {}
|
2015-09-18 05:49:33 +00:00
|
|
|
|
|
|
|
bool NativeWindow::IsMenuBarAutoHide() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-04-18 01:55:30 +00:00
|
|
|
void NativeWindow::SetMenuBarVisibility(bool visible) {}
|
2015-09-18 05:49:33 +00:00
|
|
|
|
|
|
|
bool NativeWindow::IsMenuBarVisible() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
double NativeWindow::GetAspectRatio() {
|
|
|
|
return aspect_ratio_;
|
|
|
|
}
|
|
|
|
|
|
|
|
gfx::Size NativeWindow::GetAspectRatioExtraSize() {
|
|
|
|
return aspect_ratio_extraSize_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void NativeWindow::SetAspectRatio(double aspect_ratio,
|
|
|
|
const gfx::Size& extra_size) {
|
|
|
|
aspect_ratio_ = aspect_ratio;
|
|
|
|
aspect_ratio_extraSize_ = extra_size;
|
|
|
|
}
|
|
|
|
|
2016-10-14 16:42:50 +00:00
|
|
|
void NativeWindow::PreviewFile(const std::string& path,
|
2018-04-18 01:55:30 +00:00
|
|
|
const std::string& display_name) {}
|
2016-10-12 01:08:01 +00:00
|
|
|
|
2018-04-18 01:55:30 +00:00
|
|
|
void NativeWindow::CloseFilePreview() {}
|
2016-11-21 18:30:13 +00:00
|
|
|
|
2021-07-01 19:25:40 +00:00
|
|
|
gfx::Rect NativeWindow::GetWindowControlsOverlayRect() {
|
|
|
|
return overlay_rect_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void NativeWindow::SetWindowControlsOverlayRect(const gfx::Rect& overlay_rect) {
|
|
|
|
overlay_rect_ = overlay_rect;
|
|
|
|
}
|
|
|
|
|
2022-04-05 16:25:07 +00:00
|
|
|
void NativeWindow::NotifyWindowRequestPreferredWidth(int* width) {
|
2018-03-06 03:03:12 +00:00
|
|
|
for (NativeWindowObserver& observer : observers_)
|
|
|
|
observer.RequestPreferredWidth(width);
|
|
|
|
}
|
|
|
|
|
2018-02-22 07:15:21 +00:00
|
|
|
void NativeWindow::NotifyWindowCloseButtonClicked() {
|
|
|
|
// First ask the observers whether we want to close.
|
|
|
|
bool prevent_default = false;
|
|
|
|
for (NativeWindowObserver& observer : observers_)
|
|
|
|
observer.WillCloseWindow(&prevent_default);
|
|
|
|
if (prevent_default) {
|
|
|
|
WindowList::WindowCloseCancelled(this);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Then ask the observers how should we close the window.
|
|
|
|
for (NativeWindowObserver& observer : observers_)
|
|
|
|
observer.OnCloseButtonClicked(&prevent_default);
|
|
|
|
if (prevent_default)
|
|
|
|
return;
|
|
|
|
|
|
|
|
CloseImmediately();
|
|
|
|
}
|
|
|
|
|
2013-05-02 12:08:23 +00:00
|
|
|
void NativeWindow::NotifyWindowClosed() {
|
|
|
|
if (is_closed_)
|
|
|
|
return;
|
|
|
|
|
|
|
|
is_closed_ = true;
|
2017-01-24 03:34:39 +00:00
|
|
|
for (NativeWindowObserver& observer : observers_)
|
|
|
|
observer.OnWindowClosed();
|
2021-04-28 17:55:08 +00:00
|
|
|
|
|
|
|
WindowList::RemoveWindow(this);
|
2013-05-02 12:08:23 +00:00
|
|
|
}
|
|
|
|
|
2017-04-21 20:45:30 +00:00
|
|
|
void NativeWindow::NotifyWindowEndSession() {
|
|
|
|
for (NativeWindowObserver& observer : observers_)
|
|
|
|
observer.OnWindowEndSession();
|
|
|
|
}
|
|
|
|
|
2013-05-24 09:51:15 +00:00
|
|
|
void NativeWindow::NotifyWindowBlur() {
|
2017-01-24 03:34:39 +00:00
|
|
|
for (NativeWindowObserver& observer : observers_)
|
|
|
|
observer.OnWindowBlur();
|
2013-05-24 09:51:15 +00:00
|
|
|
}
|
|
|
|
|
2014-05-21 17:46:13 +00:00
|
|
|
void NativeWindow::NotifyWindowFocus() {
|
2017-01-24 03:34:39 +00:00
|
|
|
for (NativeWindowObserver& observer : observers_)
|
|
|
|
observer.OnWindowFocus();
|
2014-05-21 17:46:13 +00:00
|
|
|
}
|
|
|
|
|
2020-06-29 20:15:28 +00:00
|
|
|
void NativeWindow::NotifyWindowIsKeyChanged(bool is_key) {
|
|
|
|
for (NativeWindowObserver& observer : observers_)
|
|
|
|
observer.OnWindowIsKeyChanged(is_key);
|
|
|
|
}
|
|
|
|
|
2016-03-08 19:11:17 +00:00
|
|
|
void NativeWindow::NotifyWindowShow() {
|
2017-01-24 03:34:39 +00:00
|
|
|
for (NativeWindowObserver& observer : observers_)
|
|
|
|
observer.OnWindowShow();
|
2016-03-08 19:11:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void NativeWindow::NotifyWindowHide() {
|
2017-01-24 03:34:39 +00:00
|
|
|
for (NativeWindowObserver& observer : observers_)
|
|
|
|
observer.OnWindowHide();
|
2016-03-08 19:11:17 +00:00
|
|
|
}
|
|
|
|
|
2014-11-25 04:43:25 +00:00
|
|
|
void NativeWindow::NotifyWindowMaximize() {
|
2017-01-24 03:34:39 +00:00
|
|
|
for (NativeWindowObserver& observer : observers_)
|
|
|
|
observer.OnWindowMaximize();
|
2014-11-25 04:43:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void NativeWindow::NotifyWindowUnmaximize() {
|
2017-01-24 03:34:39 +00:00
|
|
|
for (NativeWindowObserver& observer : observers_)
|
|
|
|
observer.OnWindowUnmaximize();
|
2014-11-25 04:43:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void NativeWindow::NotifyWindowMinimize() {
|
2017-01-24 03:34:39 +00:00
|
|
|
for (NativeWindowObserver& observer : observers_)
|
|
|
|
observer.OnWindowMinimize();
|
2014-11-25 04:43:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void NativeWindow::NotifyWindowRestore() {
|
2017-01-24 03:34:39 +00:00
|
|
|
for (NativeWindowObserver& observer : observers_)
|
|
|
|
observer.OnWindowRestore();
|
2014-11-25 04:43:25 +00:00
|
|
|
}
|
|
|
|
|
2018-07-27 09:53:01 +00:00
|
|
|
void NativeWindow::NotifyWindowWillResize(const gfx::Rect& new_bounds,
|
2021-06-02 02:37:10 +00:00
|
|
|
const gfx::ResizeEdge& edge,
|
2018-07-27 09:53:01 +00:00
|
|
|
bool* prevent_default) {
|
|
|
|
for (NativeWindowObserver& observer : observers_)
|
2021-06-02 02:37:10 +00:00
|
|
|
observer.OnWindowWillResize(new_bounds, edge, prevent_default);
|
2018-07-27 09:53:01 +00:00
|
|
|
}
|
|
|
|
|
2018-08-28 13:44:10 +00:00
|
|
|
void NativeWindow::NotifyWindowWillMove(const gfx::Rect& new_bounds,
|
|
|
|
bool* prevent_default) {
|
|
|
|
for (NativeWindowObserver& observer : observers_)
|
|
|
|
observer.OnWindowWillMove(new_bounds, prevent_default);
|
|
|
|
}
|
|
|
|
|
2015-05-09 15:55:10 +00:00
|
|
|
void NativeWindow::NotifyWindowResize() {
|
2021-07-01 19:25:40 +00:00
|
|
|
NotifyLayoutWindowControlsOverlay();
|
2017-01-24 03:34:39 +00:00
|
|
|
for (NativeWindowObserver& observer : observers_)
|
|
|
|
observer.OnWindowResize();
|
2015-05-09 15:55:10 +00:00
|
|
|
}
|
|
|
|
|
2020-11-12 00:27:24 +00:00
|
|
|
void NativeWindow::NotifyWindowResized() {
|
|
|
|
for (NativeWindowObserver& observer : observers_)
|
|
|
|
observer.OnWindowResized();
|
|
|
|
}
|
|
|
|
|
2015-05-09 15:55:10 +00:00
|
|
|
void NativeWindow::NotifyWindowMove() {
|
2017-01-24 03:34:39 +00:00
|
|
|
for (NativeWindowObserver& observer : observers_)
|
|
|
|
observer.OnWindowMove();
|
2015-05-09 15:55:10 +00:00
|
|
|
}
|
|
|
|
|
2015-05-20 08:37:13 +00:00
|
|
|
void NativeWindow::NotifyWindowMoved() {
|
2017-01-24 03:34:39 +00:00
|
|
|
for (NativeWindowObserver& observer : observers_)
|
|
|
|
observer.OnWindowMoved();
|
2015-05-20 08:37:13 +00:00
|
|
|
}
|
|
|
|
|
2014-11-25 04:43:25 +00:00
|
|
|
void NativeWindow::NotifyWindowEnterFullScreen() {
|
2017-01-24 03:34:39 +00:00
|
|
|
for (NativeWindowObserver& observer : observers_)
|
|
|
|
observer.OnWindowEnterFullScreen();
|
2014-11-25 04:43:25 +00:00
|
|
|
}
|
|
|
|
|
2016-03-23 15:20:11 +00:00
|
|
|
void NativeWindow::NotifyWindowSwipe(const std::string& direction) {
|
2017-01-24 03:34:39 +00:00
|
|
|
for (NativeWindowObserver& observer : observers_)
|
|
|
|
observer.OnWindowSwipe(direction);
|
2016-03-18 15:20:04 +00:00
|
|
|
}
|
|
|
|
|
2019-07-23 19:42:26 +00:00
|
|
|
void NativeWindow::NotifyWindowRotateGesture(float rotation) {
|
|
|
|
for (NativeWindowObserver& observer : observers_)
|
|
|
|
observer.OnWindowRotateGesture(rotation);
|
|
|
|
}
|
|
|
|
|
2017-04-20 17:31:25 +00:00
|
|
|
void NativeWindow::NotifyWindowSheetBegin() {
|
|
|
|
for (NativeWindowObserver& observer : observers_)
|
|
|
|
observer.OnWindowSheetBegin();
|
|
|
|
}
|
|
|
|
|
|
|
|
void NativeWindow::NotifyWindowSheetEnd() {
|
|
|
|
for (NativeWindowObserver& observer : observers_)
|
|
|
|
observer.OnWindowSheetEnd();
|
|
|
|
}
|
|
|
|
|
2014-11-25 04:43:25 +00:00
|
|
|
void NativeWindow::NotifyWindowLeaveFullScreen() {
|
2017-01-24 03:34:39 +00:00
|
|
|
for (NativeWindowObserver& observer : observers_)
|
|
|
|
observer.OnWindowLeaveFullScreen();
|
2014-11-25 04:43:25 +00:00
|
|
|
}
|
|
|
|
|
2015-05-21 05:09:31 +00:00
|
|
|
void NativeWindow::NotifyWindowEnterHtmlFullScreen() {
|
2017-01-24 03:34:39 +00:00
|
|
|
for (NativeWindowObserver& observer : observers_)
|
|
|
|
observer.OnWindowEnterHtmlFullScreen();
|
2015-05-21 05:09:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void NativeWindow::NotifyWindowLeaveHtmlFullScreen() {
|
2017-01-24 03:34:39 +00:00
|
|
|
for (NativeWindowObserver& observer : observers_)
|
|
|
|
observer.OnWindowLeaveHtmlFullScreen();
|
2015-05-21 05:09:31 +00:00
|
|
|
}
|
|
|
|
|
2018-10-04 18:02:16 +00:00
|
|
|
void NativeWindow::NotifyWindowAlwaysOnTopChanged() {
|
|
|
|
for (NativeWindowObserver& observer : observers_)
|
|
|
|
observer.OnWindowAlwaysOnTopChanged();
|
|
|
|
}
|
|
|
|
|
2018-12-05 17:35:59 +00:00
|
|
|
void NativeWindow::NotifyWindowExecuteAppCommand(const std::string& command) {
|
2017-01-24 03:34:39 +00:00
|
|
|
for (NativeWindowObserver& observer : observers_)
|
2018-12-05 17:35:59 +00:00
|
|
|
observer.OnExecuteAppCommand(command);
|
2015-08-05 04:46:32 +00:00
|
|
|
}
|
|
|
|
|
2022-07-05 15:25:18 +00:00
|
|
|
void NativeWindow::NotifyTouchBarItemInteraction(const std::string& item_id,
|
|
|
|
base::Value::Dict details) {
|
2017-02-27 17:20:25 +00:00
|
|
|
for (NativeWindowObserver& observer : observers_)
|
2017-02-28 23:37:15 +00:00
|
|
|
observer.OnTouchBarItemResult(item_id, details);
|
2017-02-27 17:20:25 +00:00
|
|
|
}
|
2016-11-27 05:57:01 +00:00
|
|
|
|
2017-06-11 08:19:01 +00:00
|
|
|
void NativeWindow::NotifyNewWindowForTab() {
|
2018-04-18 01:55:30 +00:00
|
|
|
for (NativeWindowObserver& observer : observers_)
|
2017-06-11 08:19:01 +00:00
|
|
|
observer.OnNewWindowForTab();
|
|
|
|
}
|
|
|
|
|
2020-10-08 22:45:05 +00:00
|
|
|
void NativeWindow::NotifyWindowSystemContextMenu(int x,
|
|
|
|
int y,
|
|
|
|
bool* prevent_default) {
|
|
|
|
for (NativeWindowObserver& observer : observers_)
|
|
|
|
observer.OnSystemContextMenu(x, y, prevent_default);
|
|
|
|
}
|
|
|
|
|
2021-07-01 19:25:40 +00:00
|
|
|
void NativeWindow::NotifyLayoutWindowControlsOverlay() {
|
|
|
|
gfx::Rect bounding_rect = GetWindowControlsOverlayRect();
|
|
|
|
if (!bounding_rect.IsEmpty()) {
|
|
|
|
for (NativeWindowObserver& observer : observers_)
|
|
|
|
observer.UpdateWindowControlsOverlay(bounding_rect);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2018-04-18 01:55:30 +00:00
|
|
|
void NativeWindow::NotifyWindowMessage(UINT message,
|
|
|
|
WPARAM w_param,
|
|
|
|
LPARAM l_param) {
|
2017-01-24 03:34:39 +00:00
|
|
|
for (NativeWindowObserver& observer : observers_)
|
|
|
|
observer.OnWindowMessage(message, w_param, l_param);
|
2015-10-27 01:12:01 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2022-11-07 18:15:57 +00:00
|
|
|
int NativeWindow::NonClientHitTest(const gfx::Point& point) {
|
2023-01-26 13:04:19 +00:00
|
|
|
#if !BUILDFLAG(IS_MAC)
|
|
|
|
// We need to ensure we account for resizing borders on Windows and Linux.
|
|
|
|
if ((!has_frame() || has_client_frame()) && IsResizable()) {
|
|
|
|
auto* frame =
|
|
|
|
static_cast<FramelessView*>(widget()->non_client_view()->frame_view());
|
|
|
|
int border_hit = frame->ResizingBorderHitTest(point);
|
|
|
|
if (border_hit != HTNOWHERE)
|
|
|
|
return border_hit;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2022-11-07 18:15:57 +00:00
|
|
|
for (auto* provider : draggable_region_providers_) {
|
|
|
|
int hit = provider->NonClientHitTest(point);
|
|
|
|
if (hit != HTNOWHERE)
|
|
|
|
return hit;
|
|
|
|
}
|
|
|
|
return HTNOWHERE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void NativeWindow::AddDraggableRegionProvider(
|
|
|
|
DraggableRegionProvider* provider) {
|
2023-05-30 08:28:43 +00:00
|
|
|
if (!base::Contains(draggable_region_providers_, provider)) {
|
2022-11-07 18:15:57 +00:00
|
|
|
draggable_region_providers_.push_back(provider);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void NativeWindow::RemoveDraggableRegionProvider(
|
|
|
|
DraggableRegionProvider* provider) {
|
|
|
|
draggable_region_providers_.remove_if(
|
|
|
|
[&provider](DraggableRegionProvider* p) { return p == provider; });
|
2022-10-12 16:05:45 +00:00
|
|
|
}
|
|
|
|
|
2020-03-03 21:35:05 +00:00
|
|
|
views::Widget* NativeWindow::GetWidget() {
|
|
|
|
return widget();
|
|
|
|
}
|
|
|
|
|
|
|
|
const views::Widget* NativeWindow::GetWidget() const {
|
2018-04-25 07:05:43 +00:00
|
|
|
return widget();
|
|
|
|
}
|
|
|
|
|
2021-03-16 16:18:45 +00:00
|
|
|
std::u16string NativeWindow::GetAccessibleWindowTitle() const {
|
2019-08-27 22:35:34 +00:00
|
|
|
if (accessible_title_.empty()) {
|
|
|
|
return views::WidgetDelegate::GetAccessibleWindowTitle();
|
|
|
|
}
|
|
|
|
|
|
|
|
return accessible_title_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void NativeWindow::SetAccessibleTitle(const std::string& title) {
|
|
|
|
accessible_title_ = base::UTF8ToUTF16(title);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string NativeWindow::GetAccessibleTitle() {
|
|
|
|
return base::UTF16ToUTF8(accessible_title_);
|
|
|
|
}
|
|
|
|
|
2022-06-07 16:59:50 +00:00
|
|
|
void NativeWindow::HandlePendingFullscreenTransitions() {
|
2022-08-01 20:52:58 +00:00
|
|
|
if (pending_transitions_.empty()) {
|
2023-05-12 13:24:01 +00:00
|
|
|
set_fullscreen_transition_type(FullScreenTransitionType::kNone);
|
2022-06-07 16:59:50 +00:00
|
|
|
return;
|
2022-08-01 20:52:58 +00:00
|
|
|
}
|
2022-06-07 16:59:50 +00:00
|
|
|
|
|
|
|
bool next_transition = pending_transitions_.front();
|
|
|
|
pending_transitions_.pop();
|
|
|
|
SetFullScreen(next_transition);
|
|
|
|
}
|
|
|
|
|
2020-07-16 17:14:54 +00:00
|
|
|
// static
|
|
|
|
int32_t NativeWindow::next_id_ = 0;
|
|
|
|
|
2018-10-02 22:14:43 +00:00
|
|
|
// static
|
|
|
|
void NativeWindowRelay::CreateForWebContents(
|
|
|
|
content::WebContents* web_contents,
|
|
|
|
base::WeakPtr<NativeWindow> window) {
|
|
|
|
DCHECK(web_contents);
|
2019-01-21 16:56:54 +00:00
|
|
|
if (!web_contents->GetUserData(UserDataKey())) {
|
2022-01-10 22:31:39 +00:00
|
|
|
web_contents->SetUserData(
|
|
|
|
UserDataKey(),
|
|
|
|
base::WrapUnique(new NativeWindowRelay(web_contents, window)));
|
2019-01-21 16:56:54 +00:00
|
|
|
}
|
2018-10-02 22:14:43 +00:00
|
|
|
}
|
|
|
|
|
2022-01-10 22:31:39 +00:00
|
|
|
NativeWindowRelay::NativeWindowRelay(content::WebContents* web_contents,
|
|
|
|
base::WeakPtr<NativeWindow> window)
|
|
|
|
: content::WebContentsUserData<NativeWindowRelay>(*web_contents),
|
|
|
|
native_window_(window) {}
|
2018-04-17 23:37:22 +00:00
|
|
|
|
|
|
|
NativeWindowRelay::~NativeWindowRelay() = default;
|
|
|
|
|
2021-10-21 18:51:36 +00:00
|
|
|
WEB_CONTENTS_USER_DATA_KEY_IMPL(NativeWindowRelay);
|
2019-01-21 16:56:54 +00:00
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
} // namespace electron
|