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.
|
|
|
|
|
2021-11-22 07:34:31 +00:00
|
|
|
#ifndef ELECTRON_SHELL_BROWSER_NATIVE_WINDOW_H_
|
|
|
|
#define ELECTRON_SHELL_BROWSER_NATIVE_WINDOW_H_
|
2013-04-12 07:04:46 +00:00
|
|
|
|
2018-12-22 01:49:26 +00:00
|
|
|
#include <list>
|
2016-07-04 06:08:55 +00:00
|
|
|
#include <memory>
|
2024-01-10 22:23:35 +00:00
|
|
|
#include <optional>
|
2022-06-07 16:59:50 +00:00
|
|
|
#include <queue>
|
2014-03-16 01:13:06 +00:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2023-05-11 20:07:39 +00:00
|
|
|
#include "base/memory/raw_ptr.h"
|
2013-11-29 06:52:12 +00:00
|
|
|
#include "base/memory/weak_ptr.h"
|
2013-04-18 12:50:58 +00:00
|
|
|
#include "base/observer_list.h"
|
2015-10-01 05:45:59 +00:00
|
|
|
#include "base/supports_user_data.h"
|
2019-08-15 06:51:15 +00:00
|
|
|
#include "content/public/browser/desktop_media_id.h"
|
2015-06-24 14:14:46 +00:00
|
|
|
#include "content/public/browser/web_contents_user_data.h"
|
2023-07-16 14:14:43 +00:00
|
|
|
#include "electron/shell/common/api/api.mojom.h"
|
2015-10-05 08:19:01 +00:00
|
|
|
#include "extensions/browser/app_window/size_constraints.h"
|
2022-11-07 18:15:57 +00:00
|
|
|
#include "shell/browser/draggable_region_provider.h"
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/browser/native_window_observer.h"
|
2022-10-17 15:10:07 +00:00
|
|
|
#include "shell/browser/ui/inspectable_web_contents_view.h"
|
2018-04-25 06:51:54 +00:00
|
|
|
#include "ui/views/widget/widget_delegate.h"
|
2013-04-12 07:04:46 +00:00
|
|
|
|
2022-10-12 16:05:45 +00:00
|
|
|
class SkRegion;
|
|
|
|
|
2024-06-07 21:18:35 +00:00
|
|
|
namespace input {
|
2015-06-25 03:07:23 +00:00
|
|
|
struct NativeWebKeyboardEvent;
|
2013-04-12 07:04:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace gfx {
|
2018-03-06 06:24:54 +00:00
|
|
|
class Image;
|
2013-04-12 07:04:46 +00:00
|
|
|
class Point;
|
|
|
|
class Rect;
|
2021-06-02 02:37:10 +00:00
|
|
|
enum class ResizeEdge;
|
2013-04-12 07:04:46 +00:00
|
|
|
class Size;
|
2018-04-18 01:44:10 +00:00
|
|
|
} // namespace gfx
|
2013-04-12 07:04:46 +00:00
|
|
|
|
2019-10-25 13:03:28 +00:00
|
|
|
namespace gin_helper {
|
2014-06-23 13:51:42 +00:00
|
|
|
class Dictionary;
|
2018-04-10 06:23:16 +00:00
|
|
|
class PersistentDictionary;
|
2019-10-31 07:56:00 +00:00
|
|
|
} // namespace gin_helper
|
2014-06-23 13:51:42 +00:00
|
|
|
|
2013-04-12 07:04:46 +00:00
|
|
|
namespace electron {
|
|
|
|
|
2023-12-13 21:01:03 +00:00
|
|
|
extern const char kElectronNativeWindowKey[];
|
|
|
|
|
2018-04-10 06:23:16 +00:00
|
|
|
class ElectronMenuModel;
|
2023-09-26 20:00:46 +00:00
|
|
|
class BackgroundThrottlingSource;
|
Implement initial, experimental BrowserView API
Right now, `<webview>` is the only way to embed additional content in a
`BrowserWindow`. Unfortunately `<webview>` suffers from a [number of
problems](https://github.com/electron/electron/issues?utf8=%E2%9C%93&q=is%3Aissue%20is%3Aopen%20label%3Awebview%20).
To make matters worse, many of these are upstream Chromium bugs instead
of Electron-specific bugs.
For us at [Figma](https://www.figma.com), the main issue is very slow
performance.
Despite the upstream improvements to `<webview>` through the OOPIF work, it is
probable that there will continue to be `<webview>`-specific bugs in the
future.
Therefore, this introduces a `<webview>` alternative to called `BrowserView`,
which...
- is a thin wrapper around `api::WebContents` (so bugs in `BrowserView` will
likely also be bugs in `BrowserWindow` web contents)
- is instantiated in the main process like `BrowserWindow` (and unlike
`<webview>`, which lives in the DOM of a `BrowserWindow` web contents)
- needs to be added to a `BrowserWindow` to display something on the screen
This implements the most basic API. The API is expected to evolve and change in
the near future and has consequently been marked as experimental. Please do not
use this API in production unless you are prepared to deal with breaking
changes.
In the future, we will want to change the API to support multiple
`BrowserView`s per window. We will also want to consider z-ordering
auto-resizing, and possibly even nested views.
2017-04-11 17:47:30 +00:00
|
|
|
|
2022-10-17 15:10:07 +00:00
|
|
|
namespace api {
|
|
|
|
class BrowserView;
|
|
|
|
}
|
|
|
|
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_MAC)
|
2018-12-11 17:45:55 +00:00
|
|
|
typedef NSView* NativeWindowHandle;
|
|
|
|
#else
|
|
|
|
typedef gfx::AcceleratedWidget NativeWindowHandle;
|
|
|
|
#endif
|
|
|
|
|
2018-04-25 06:51:54 +00:00
|
|
|
class NativeWindow : public base::SupportsUserData,
|
|
|
|
public views::WidgetDelegate {
|
2013-04-12 07:04:46 +00:00
|
|
|
public:
|
2016-07-11 06:29:03 +00:00
|
|
|
~NativeWindow() override;
|
2013-04-12 07:04:46 +00:00
|
|
|
|
2021-11-03 11:41:45 +00:00
|
|
|
// disable copy
|
|
|
|
NativeWindow(const NativeWindow&) = delete;
|
|
|
|
NativeWindow& operator=(const NativeWindow&) = delete;
|
|
|
|
|
2014-03-04 06:35:35 +00:00
|
|
|
// Create window with existing WebContents, the caller is responsible for
|
|
|
|
// managing the window's live.
|
2019-10-25 13:03:28 +00:00
|
|
|
static NativeWindow* Create(const gin_helper::Dictionary& options,
|
2018-04-08 11:20:43 +00:00
|
|
|
NativeWindow* parent = nullptr);
|
2013-04-20 05:42:39 +00:00
|
|
|
|
2019-10-25 13:03:28 +00:00
|
|
|
void InitFromOptions(const gin_helper::Dictionary& options);
|
2013-04-12 07:04:46 +00:00
|
|
|
|
2018-05-08 03:51:27 +00:00
|
|
|
virtual void SetContentView(views::View* view) = 0;
|
2018-04-08 11:20:43 +00:00
|
|
|
|
2013-04-12 07:04:46 +00:00
|
|
|
virtual void Close() = 0;
|
2013-05-01 08:12:00 +00:00
|
|
|
virtual void CloseImmediately() = 0;
|
2018-04-17 23:47:47 +00:00
|
|
|
virtual bool IsClosed() const;
|
2013-04-12 07:04:46 +00:00
|
|
|
virtual void Focus(bool focus) = 0;
|
2024-01-04 15:51:59 +00:00
|
|
|
virtual bool IsFocused() const = 0;
|
2013-04-12 07:04:46 +00:00
|
|
|
virtual void Show() = 0;
|
2014-10-17 14:51:20 +00:00
|
|
|
virtual void ShowInactive() = 0;
|
2013-04-12 07:04:46 +00:00
|
|
|
virtual void Hide() = 0;
|
2024-01-04 15:51:59 +00:00
|
|
|
virtual bool IsVisible() const = 0;
|
|
|
|
virtual bool IsEnabled() const = 0;
|
2018-02-06 13:21:53 +00:00
|
|
|
virtual void SetEnabled(bool enable) = 0;
|
2013-04-12 07:04:46 +00:00
|
|
|
virtual void Maximize() = 0;
|
|
|
|
virtual void Unmaximize() = 0;
|
2024-01-04 15:51:59 +00:00
|
|
|
virtual bool IsMaximized() const = 0;
|
2013-04-12 07:04:46 +00:00
|
|
|
virtual void Minimize() = 0;
|
|
|
|
virtual void Restore() = 0;
|
2024-01-04 15:51:59 +00:00
|
|
|
virtual bool IsMinimized() const = 0;
|
2014-11-25 06:34:14 +00:00
|
|
|
virtual void SetFullScreen(bool fullscreen) = 0;
|
2015-04-21 13:35:36 +00:00
|
|
|
virtual bool IsFullscreen() const = 0;
|
2016-01-15 16:31:31 +00:00
|
|
|
virtual void SetBounds(const gfx::Rect& bounds, bool animate = false) = 0;
|
2024-01-04 15:51:59 +00:00
|
|
|
virtual gfx::Rect GetBounds() const = 0;
|
2016-01-15 16:31:31 +00:00
|
|
|
virtual void SetSize(const gfx::Size& size, bool animate = false);
|
2024-01-04 15:51:59 +00:00
|
|
|
virtual gfx::Size GetSize() const;
|
2016-01-15 16:31:31 +00:00
|
|
|
virtual void SetPosition(const gfx::Point& position, bool animate = false);
|
2024-01-04 15:51:59 +00:00
|
|
|
virtual gfx::Point GetPosition() const;
|
2016-01-15 16:31:31 +00:00
|
|
|
virtual void SetContentSize(const gfx::Size& size, bool animate = false);
|
2024-01-04 15:51:59 +00:00
|
|
|
virtual gfx::Size GetContentSize() const;
|
2016-08-04 19:02:24 +00:00
|
|
|
virtual void SetContentBounds(const gfx::Rect& bounds, bool animate = false);
|
2024-01-04 15:51:59 +00:00
|
|
|
virtual gfx::Rect GetContentBounds() const;
|
|
|
|
virtual bool IsNormal() const;
|
|
|
|
virtual gfx::Rect GetNormalBounds() const = 0;
|
2015-10-05 08:19:01 +00:00
|
|
|
virtual void SetSizeConstraints(
|
2021-06-01 01:46:25 +00:00
|
|
|
const extensions::SizeConstraints& window_constraints);
|
2017-05-21 18:57:19 +00:00
|
|
|
virtual extensions::SizeConstraints GetSizeConstraints() const;
|
2015-10-05 08:19:01 +00:00
|
|
|
virtual void SetContentSizeConstraints(
|
|
|
|
const extensions::SizeConstraints& size_constraints);
|
2017-05-21 18:57:19 +00:00
|
|
|
virtual extensions::SizeConstraints GetContentSizeConstraints() const;
|
2015-10-05 08:19:01 +00:00
|
|
|
virtual void SetMinimumSize(const gfx::Size& size);
|
2017-05-21 18:57:19 +00:00
|
|
|
virtual gfx::Size GetMinimumSize() const;
|
2015-10-05 08:19:01 +00:00
|
|
|
virtual void SetMaximumSize(const gfx::Size& size);
|
2017-05-21 18:57:19 +00:00
|
|
|
virtual gfx::Size GetMaximumSize() const;
|
2018-05-12 15:37:31 +00:00
|
|
|
virtual gfx::Size GetContentMinimumSize() const;
|
|
|
|
virtual gfx::Size GetContentMaximumSize() const;
|
2016-05-20 03:19:08 +00:00
|
|
|
virtual void SetSheetOffset(const double offsetX, const double offsetY);
|
2024-01-04 15:51:59 +00:00
|
|
|
virtual double GetSheetOffsetX() const;
|
|
|
|
virtual double GetSheetOffsetY() const;
|
2013-04-12 07:04:46 +00:00
|
|
|
virtual void SetResizable(bool resizable) = 0;
|
2019-08-15 06:51:15 +00:00
|
|
|
virtual bool MoveAbove(const std::string& sourceId) = 0;
|
2018-04-03 13:04:32 +00:00
|
|
|
virtual void MoveTop() = 0;
|
2024-01-04 15:51:59 +00:00
|
|
|
virtual bool IsResizable() const = 0;
|
2016-01-18 22:46:35 +00:00
|
|
|
virtual void SetMovable(bool movable) = 0;
|
2024-01-04 15:51:59 +00:00
|
|
|
virtual bool IsMovable() const = 0;
|
2016-01-18 22:46:35 +00:00
|
|
|
virtual void SetMinimizable(bool minimizable) = 0;
|
2024-01-04 15:51:59 +00:00
|
|
|
virtual bool IsMinimizable() const = 0;
|
2016-01-22 21:24:33 +00:00
|
|
|
virtual void SetMaximizable(bool maximizable) = 0;
|
2024-01-04 15:51:59 +00:00
|
|
|
virtual bool IsMaximizable() const = 0;
|
2016-01-23 07:47:37 +00:00
|
|
|
virtual void SetFullScreenable(bool fullscreenable) = 0;
|
2024-01-04 15:51:59 +00:00
|
|
|
virtual bool IsFullScreenable() const = 0;
|
2016-01-18 22:46:35 +00:00
|
|
|
virtual void SetClosable(bool closable) = 0;
|
2024-01-04 15:51:59 +00:00
|
|
|
virtual bool IsClosable() const = 0;
|
2019-07-24 22:58:51 +00:00
|
|
|
virtual void SetAlwaysOnTop(ui::ZOrderLevel z_order,
|
2017-01-24 04:36:09 +00:00
|
|
|
const std::string& level = "floating",
|
2019-10-18 19:57:34 +00:00
|
|
|
int relativeLevel = 0) = 0;
|
2024-01-04 15:51:59 +00:00
|
|
|
virtual ui::ZOrderLevel GetZOrderLevel() const = 0;
|
2013-05-10 12:34:05 +00:00
|
|
|
virtual void Center() = 0;
|
2017-02-14 03:41:24 +00:00
|
|
|
virtual void Invalidate() = 0;
|
2013-04-12 07:04:46 +00:00
|
|
|
virtual void SetTitle(const std::string& title) = 0;
|
2024-01-04 15:51:59 +00:00
|
|
|
virtual std::string GetTitle() const = 0;
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_MAC)
|
2024-01-04 15:51:59 +00:00
|
|
|
virtual std::string GetAlwaysOnTopLevel() const = 0;
|
2021-05-19 09:27:35 +00:00
|
|
|
virtual void SetActive(bool is_key) = 0;
|
|
|
|
virtual bool IsActive() const = 0;
|
2023-07-26 14:47:32 +00:00
|
|
|
virtual void RemoveChildFromParentWindow() = 0;
|
2023-05-31 09:57:44 +00:00
|
|
|
virtual void RemoveChildWindow(NativeWindow* child) = 0;
|
|
|
|
virtual void AttachChildren() = 0;
|
|
|
|
virtual void DetachChildren() = 0;
|
2021-05-19 09:27:35 +00:00
|
|
|
#endif
|
2019-08-27 22:35:34 +00:00
|
|
|
|
|
|
|
// Ability to augment the window title for the screen readers.
|
|
|
|
void SetAccessibleTitle(const std::string& title);
|
|
|
|
std::string GetAccessibleTitle();
|
|
|
|
|
2013-04-12 07:04:46 +00:00
|
|
|
virtual void FlashFrame(bool flash) = 0;
|
2014-06-16 02:29:51 +00:00
|
|
|
virtual void SetSkipTaskbar(bool skip) = 0;
|
2019-03-27 12:10:23 +00:00
|
|
|
virtual void SetExcludedFromShownWindowsMenu(bool excluded) = 0;
|
2024-01-04 15:51:59 +00:00
|
|
|
virtual bool IsExcludedFromShownWindowsMenu() const = 0;
|
2017-08-13 06:28:33 +00:00
|
|
|
virtual void SetSimpleFullScreen(bool simple_fullscreen) = 0;
|
2024-01-04 15:51:59 +00:00
|
|
|
virtual bool IsSimpleFullScreen() const = 0;
|
2013-04-12 07:04:46 +00:00
|
|
|
virtual void SetKiosk(bool kiosk) = 0;
|
2024-01-04 15:51:59 +00:00
|
|
|
virtual bool IsKiosk() const = 0;
|
2020-09-22 05:40:42 +00:00
|
|
|
virtual bool IsTabletMode() const;
|
2018-03-06 04:21:47 +00:00
|
|
|
virtual void SetBackgroundColor(SkColor color) = 0;
|
2024-01-04 15:51:59 +00:00
|
|
|
virtual SkColor GetBackgroundColor() const = 0;
|
2022-12-01 18:24:44 +00:00
|
|
|
virtual void InvalidateShadow();
|
2016-01-23 10:55:12 +00:00
|
|
|
virtual void SetHasShadow(bool has_shadow) = 0;
|
2024-01-04 15:51:59 +00:00
|
|
|
virtual bool HasShadow() const = 0;
|
2017-09-29 02:26:02 +00:00
|
|
|
virtual void SetOpacity(const double opacity) = 0;
|
2024-01-04 15:51:59 +00:00
|
|
|
virtual double GetOpacity() const = 0;
|
2014-05-27 06:15:34 +00:00
|
|
|
virtual void SetRepresentedFilename(const std::string& filename);
|
2024-01-04 15:51:59 +00:00
|
|
|
virtual std::string GetRepresentedFilename() const;
|
2014-05-27 06:15:34 +00:00
|
|
|
virtual void SetDocumentEdited(bool edited);
|
2024-01-04 15:51:59 +00:00
|
|
|
virtual bool IsDocumentEdited() const;
|
2017-08-14 18:21:00 +00:00
|
|
|
virtual void SetIgnoreMouseEvents(bool ignore, bool forward) = 0;
|
2016-06-22 08:40:01 +00:00
|
|
|
virtual void SetContentProtection(bool enable) = 0;
|
2016-06-13 08:10:28 +00:00
|
|
|
virtual void SetFocusable(bool focusable);
|
2024-01-04 15:51:59 +00:00
|
|
|
virtual bool IsFocusable() const;
|
2016-07-06 23:04:18 +00:00
|
|
|
virtual void SetMenu(ElectronMenuModel* menu);
|
2016-06-20 05:49:24 +00:00
|
|
|
virtual void SetParentWindow(NativeWindow* parent);
|
2019-08-15 06:51:15 +00:00
|
|
|
virtual content::DesktopMediaID GetDesktopMediaID() const = 0;
|
2017-05-21 18:57:19 +00:00
|
|
|
virtual gfx::NativeView GetNativeView() const = 0;
|
|
|
|
virtual gfx::NativeWindow GetNativeWindow() const = 0;
|
|
|
|
virtual gfx::AcceleratedWidget GetAcceleratedWidget() const = 0;
|
2018-12-11 17:45:55 +00:00
|
|
|
virtual NativeWindowHandle GetNativeWindowHandle() const = 0;
|
2015-08-06 03:10:34 +00:00
|
|
|
|
|
|
|
// Taskbar/Dock APIs.
|
2019-05-03 18:11:41 +00:00
|
|
|
enum class ProgressState {
|
|
|
|
kNone, // no progress, no marking
|
|
|
|
kIndeterminate, // progress, indeterminate
|
|
|
|
kError, // progress, errored (red)
|
|
|
|
kPaused, // progress, paused (yellow)
|
|
|
|
kNormal, // progress, not marked (green)
|
2016-08-09 23:05:44 +00:00
|
|
|
};
|
|
|
|
|
2018-04-18 01:44:10 +00:00
|
|
|
virtual void SetProgressBar(double progress, const ProgressState state) = 0;
|
2015-02-07 01:00:26 +00:00
|
|
|
virtual void SetOverlayIcon(const gfx::Image& overlay,
|
2015-02-07 00:31:41 +00:00
|
|
|
const std::string& description) = 0;
|
2015-08-06 03:10:34 +00:00
|
|
|
|
|
|
|
// Workspace APIs.
|
2021-02-02 12:24:04 +00:00
|
|
|
virtual void SetVisibleOnAllWorkspaces(
|
|
|
|
bool visible,
|
|
|
|
bool visibleOnFullScreen = false,
|
|
|
|
bool skipTransformProcessType = false) = 0;
|
2018-08-31 22:06:02 +00:00
|
|
|
|
2024-01-04 15:51:59 +00:00
|
|
|
virtual bool IsVisibleOnAllWorkspaces() const = 0;
|
2014-02-24 04:08:33 +00:00
|
|
|
|
2016-11-28 19:38:40 +00:00
|
|
|
virtual void SetAutoHideCursor(bool auto_hide);
|
|
|
|
|
2016-11-07 20:22:41 +00:00
|
|
|
// Vibrancy API
|
2023-09-11 12:51:54 +00:00
|
|
|
const std::string& vibrancy() const { return vibrancy_; }
|
2016-11-10 10:59:25 +00:00
|
|
|
virtual void SetVibrancy(const std::string& type);
|
2016-11-07 20:22:41 +00:00
|
|
|
|
2023-09-11 12:51:54 +00:00
|
|
|
const std::string& background_material() const {
|
|
|
|
return background_material_;
|
|
|
|
}
|
2023-05-15 20:31:57 +00:00
|
|
|
virtual void SetBackgroundMaterial(const std::string& type);
|
|
|
|
|
2020-03-05 22:22:12 +00:00
|
|
|
// Traffic Light API
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_MAC)
|
2021-01-19 10:12:09 +00:00
|
|
|
virtual void SetWindowButtonVisibility(bool visible) = 0;
|
|
|
|
virtual bool GetWindowButtonVisibility() const = 0;
|
2024-01-10 22:23:35 +00:00
|
|
|
virtual void SetWindowButtonPosition(std::optional<gfx::Point> position) = 0;
|
|
|
|
virtual std::optional<gfx::Point> GetWindowButtonPosition() const = 0;
|
2020-03-30 22:39:50 +00:00
|
|
|
virtual void RedrawTrafficLights() = 0;
|
2021-03-16 09:41:59 +00:00
|
|
|
virtual void UpdateFrame() = 0;
|
2020-03-05 22:22:12 +00:00
|
|
|
#endif
|
|
|
|
|
2022-11-01 20:43:42 +00:00
|
|
|
// whether windows should be ignored by mission control
|
|
|
|
#if BUILDFLAG(IS_MAC)
|
2024-01-04 15:51:59 +00:00
|
|
|
virtual bool IsHiddenInMissionControl() const = 0;
|
2022-11-01 20:43:42 +00:00
|
|
|
virtual void SetHiddenInMissionControl(bool hidden) = 0;
|
|
|
|
#endif
|
|
|
|
|
2016-11-27 05:57:01 +00:00
|
|
|
// Touchbar API
|
2019-10-31 07:56:00 +00:00
|
|
|
virtual void SetTouchBar(std::vector<gin_helper::PersistentDictionary> items);
|
2017-03-01 00:08:12 +00:00
|
|
|
virtual void RefreshTouchBarItem(const std::string& item_id);
|
2019-10-31 07:56:00 +00:00
|
|
|
virtual void SetEscapeTouchBarItem(gin_helper::PersistentDictionary item);
|
2016-11-27 05:57:01 +00:00
|
|
|
|
2017-08-21 04:46:10 +00:00
|
|
|
// Native Tab API
|
|
|
|
virtual void SelectPreviousTab();
|
|
|
|
virtual void SelectNextTab();
|
2023-07-10 08:43:37 +00:00
|
|
|
virtual void ShowAllTabs();
|
2017-08-21 04:46:10 +00:00
|
|
|
virtual void MergeAllWindows();
|
|
|
|
virtual void MoveTabToNewWindow();
|
|
|
|
virtual void ToggleTabBar();
|
2018-02-27 21:00:42 +00:00
|
|
|
virtual bool AddTabbedWindow(NativeWindow* window);
|
2024-01-10 22:23:35 +00:00
|
|
|
virtual std::optional<std::string> GetTabbingIdentifier() const;
|
2017-08-21 04:46:10 +00:00
|
|
|
|
2014-11-12 09:36:20 +00:00
|
|
|
// Toggle the menu bar.
|
|
|
|
virtual void SetAutoHideMenuBar(bool auto_hide);
|
2024-01-04 15:51:59 +00:00
|
|
|
virtual bool IsMenuBarAutoHide() const;
|
2014-11-12 09:36:20 +00:00
|
|
|
virtual void SetMenuBarVisibility(bool visible);
|
2024-01-04 15:51:59 +00:00
|
|
|
virtual bool IsMenuBarVisible() const;
|
2014-11-12 09:36:20 +00:00
|
|
|
|
2015-07-23 02:07:58 +00:00
|
|
|
// Set the aspect ratio when resizing window.
|
2024-02-09 09:29:14 +00:00
|
|
|
[[nodiscard]] double aspect_ratio() const { return aspect_ratio_; }
|
|
|
|
[[nodiscard]] gfx::Size aspect_ratio_extra_size() const {
|
|
|
|
return aspect_ratio_extraSize_;
|
|
|
|
}
|
2016-05-22 23:50:50 +00:00
|
|
|
virtual void SetAspectRatio(double aspect_ratio, const gfx::Size& extra_size);
|
2016-11-21 18:30:13 +00:00
|
|
|
|
|
|
|
// File preview APIs.
|
2016-10-14 16:42:50 +00:00
|
|
|
virtual void PreviewFile(const std::string& path,
|
2016-10-26 00:47:22 +00:00
|
|
|
const std::string& display_name);
|
2016-11-21 18:30:13 +00:00
|
|
|
virtual void CloseFilePreview();
|
2015-07-23 02:07:58 +00:00
|
|
|
|
2020-12-18 00:50:51 +00:00
|
|
|
virtual void SetGTKDarkThemeEnabled(bool use_dark_theme) {}
|
2020-08-20 20:53:06 +00:00
|
|
|
|
2018-02-22 06:16:24 +00:00
|
|
|
// Converts between content bounds and window bounds.
|
|
|
|
virtual gfx::Rect ContentBoundsToWindowBounds(
|
|
|
|
const gfx::Rect& bounds) const = 0;
|
|
|
|
virtual gfx::Rect WindowBoundsToContentBounds(
|
|
|
|
const gfx::Rect& bounds) const = 0;
|
|
|
|
|
2014-03-04 10:42:37 +00:00
|
|
|
base::WeakPtr<NativeWindow> GetWeakPtr() {
|
|
|
|
return weak_factory_.GetWeakPtr();
|
|
|
|
}
|
|
|
|
|
2024-01-10 22:23:35 +00:00
|
|
|
virtual std::optional<gfx::Rect> GetWindowControlsOverlayRect();
|
2021-07-01 19:25:40 +00:00
|
|
|
virtual void SetWindowControlsOverlayRect(const gfx::Rect& overlay_rect);
|
|
|
|
|
2015-06-25 03:07:23 +00:00
|
|
|
// Methods called by the WebContents.
|
2024-06-07 21:18:35 +00:00
|
|
|
virtual void HandleKeyboardEvent(content::WebContents*,
|
|
|
|
const input::NativeWebKeyboardEvent& event) {
|
|
|
|
}
|
2015-06-25 03:07:23 +00:00
|
|
|
|
2014-04-23 02:24:46 +00:00
|
|
|
// Public API used by platform-dependent delegates and observers to send UI
|
|
|
|
// related notifications.
|
2022-04-05 16:25:07 +00:00
|
|
|
void NotifyWindowRequestPreferredWidth(int* width);
|
2018-02-22 07:15:21 +00:00
|
|
|
void NotifyWindowCloseButtonClicked();
|
2014-04-23 02:24:46 +00:00
|
|
|
void NotifyWindowClosed();
|
2017-04-24 18:49:21 +00:00
|
|
|
void NotifyWindowEndSession();
|
2014-04-23 02:24:46 +00:00
|
|
|
void NotifyWindowBlur();
|
2014-05-21 17:46:13 +00:00
|
|
|
void NotifyWindowFocus();
|
2016-03-08 17:36:41 +00:00
|
|
|
void NotifyWindowShow();
|
2020-06-29 20:15:28 +00:00
|
|
|
void NotifyWindowIsKeyChanged(bool is_key);
|
2016-03-08 17:36:41 +00:00
|
|
|
void NotifyWindowHide();
|
2014-11-25 04:43:25 +00:00
|
|
|
void NotifyWindowMaximize();
|
|
|
|
void NotifyWindowUnmaximize();
|
|
|
|
void NotifyWindowMinimize();
|
|
|
|
void NotifyWindowRestore();
|
2015-05-09 15:55:10 +00:00
|
|
|
void NotifyWindowMove();
|
2018-07-27 09:53:01 +00:00
|
|
|
void 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);
|
2015-05-09 15:55:10 +00:00
|
|
|
void NotifyWindowResize();
|
2020-11-12 00:27:24 +00:00
|
|
|
void NotifyWindowResized();
|
2018-08-28 13:44:10 +00:00
|
|
|
void NotifyWindowWillMove(const gfx::Rect& new_bounds, bool* prevent_default);
|
2015-05-20 08:37:13 +00:00
|
|
|
void NotifyWindowMoved();
|
2016-03-23 15:20:11 +00:00
|
|
|
void NotifyWindowSwipe(const std::string& direction);
|
2019-07-23 19:42:26 +00:00
|
|
|
void NotifyWindowRotateGesture(float rotation);
|
2017-04-20 17:31:25 +00:00
|
|
|
void NotifyWindowSheetBegin();
|
|
|
|
void NotifyWindowSheetEnd();
|
2021-01-30 23:15:10 +00:00
|
|
|
virtual void NotifyWindowEnterFullScreen();
|
|
|
|
virtual void NotifyWindowLeaveFullScreen();
|
2015-05-21 05:09:31 +00:00
|
|
|
void NotifyWindowEnterHtmlFullScreen();
|
|
|
|
void NotifyWindowLeaveHtmlFullScreen();
|
2018-10-04 18:02:16 +00:00
|
|
|
void NotifyWindowAlwaysOnTopChanged();
|
2018-12-05 17:35:59 +00:00
|
|
|
void NotifyWindowExecuteAppCommand(const std::string& command);
|
2017-02-28 23:37:15 +00:00
|
|
|
void NotifyTouchBarItemInteraction(const std::string& item_id,
|
2022-07-05 15:25:18 +00:00
|
|
|
base::Value::Dict details);
|
2017-06-11 08:19:01 +00:00
|
|
|
void NotifyNewWindowForTab();
|
2020-10-08 22:45:05 +00:00
|
|
|
void NotifyWindowSystemContextMenu(int x, int y, bool* prevent_default);
|
2021-07-01 19:25:40 +00:00
|
|
|
void NotifyLayoutWindowControlsOverlay();
|
2014-04-23 02:24:46 +00:00
|
|
|
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2015-10-27 01:12:01 +00:00
|
|
|
void NotifyWindowMessage(UINT message, WPARAM w_param, LPARAM l_param);
|
2018-04-18 01:44:10 +00:00
|
|
|
#endif
|
2015-10-27 01:12:01 +00:00
|
|
|
|
2018-04-18 01:44:10 +00:00
|
|
|
void AddObserver(NativeWindowObserver* obs) { observers_.AddObserver(obs); }
|
2013-04-18 12:50:58 +00:00
|
|
|
void RemoveObserver(NativeWindowObserver* obs) {
|
|
|
|
observers_.RemoveObserver(obs);
|
|
|
|
}
|
|
|
|
|
2022-06-07 16:59:50 +00:00
|
|
|
// Handle fullscreen transitions.
|
|
|
|
void HandlePendingFullscreenTransitions();
|
2022-08-01 20:52:58 +00:00
|
|
|
|
2023-05-12 13:24:01 +00:00
|
|
|
enum class FullScreenTransitionState { kEntering, kExiting, kNone };
|
2022-08-01 20:52:58 +00:00
|
|
|
|
2022-06-07 16:59:50 +00:00
|
|
|
void set_fullscreen_transition_state(FullScreenTransitionState state) {
|
|
|
|
fullscreen_transition_state_ = state;
|
|
|
|
}
|
|
|
|
FullScreenTransitionState fullscreen_transition_state() const {
|
|
|
|
return fullscreen_transition_state_;
|
|
|
|
}
|
|
|
|
|
2023-05-12 13:24:01 +00:00
|
|
|
enum class FullScreenTransitionType { kHTML, kNative, kNone };
|
2022-08-01 20:52:58 +00:00
|
|
|
|
|
|
|
void set_fullscreen_transition_type(FullScreenTransitionType type) {
|
|
|
|
fullscreen_transition_type_ = type;
|
|
|
|
}
|
|
|
|
FullScreenTransitionType fullscreen_transition_type() const {
|
|
|
|
return fullscreen_transition_type_;
|
|
|
|
}
|
|
|
|
|
2018-04-25 07:05:43 +00:00
|
|
|
views::Widget* widget() const { return widget_.get(); }
|
2018-05-08 03:51:27 +00:00
|
|
|
views::View* content_view() const { return content_view_; }
|
2018-04-25 07:05:43 +00:00
|
|
|
|
2021-08-11 18:07:36 +00:00
|
|
|
enum class TitleBarStyle {
|
|
|
|
kNormal,
|
|
|
|
kHidden,
|
|
|
|
kHiddenInset,
|
|
|
|
kCustomButtonsOnHover,
|
|
|
|
};
|
|
|
|
TitleBarStyle title_bar_style() const { return title_bar_style_; }
|
2022-01-24 22:09:21 +00:00
|
|
|
int titlebar_overlay_height() const { return titlebar_overlay_height_; }
|
2022-03-25 00:02:45 +00:00
|
|
|
void set_titlebar_overlay_height(int height) {
|
|
|
|
titlebar_overlay_height_ = height;
|
|
|
|
}
|
|
|
|
bool titlebar_overlay_enabled() const { return titlebar_overlay_; }
|
2021-08-11 18:07:36 +00:00
|
|
|
|
2013-09-11 05:05:08 +00:00
|
|
|
bool has_frame() const { return has_frame_; }
|
2016-05-17 06:48:14 +00:00
|
|
|
void set_has_frame(bool has_frame) { has_frame_ = has_frame; }
|
|
|
|
|
2022-01-26 21:59:09 +00:00
|
|
|
bool has_client_frame() const { return has_client_frame_; }
|
2015-08-05 04:46:32 +00:00
|
|
|
bool transparent() const { return transparent_; }
|
|
|
|
bool enable_larger_than_screen() const { return enable_larger_than_screen_; }
|
2013-09-11 05:05:08 +00:00
|
|
|
|
2016-06-20 05:49:24 +00:00
|
|
|
NativeWindow* parent() const { return parent_; }
|
|
|
|
bool is_modal() const { return is_modal_; }
|
|
|
|
|
2020-07-16 17:14:54 +00:00
|
|
|
int32_t window_id() const { return next_id_; }
|
|
|
|
|
2023-05-31 09:57:44 +00:00
|
|
|
void add_child_window(NativeWindow* child) {
|
|
|
|
child_windows_.push_back(child);
|
|
|
|
}
|
|
|
|
|
2022-11-07 18:15:57 +00:00
|
|
|
int NonClientHitTest(const gfx::Point& point);
|
|
|
|
void AddDraggableRegionProvider(DraggableRegionProvider* provider);
|
|
|
|
void RemoveDraggableRegionProvider(DraggableRegionProvider* provider);
|
|
|
|
|
2023-09-11 12:51:54 +00:00
|
|
|
bool IsTranslucent() const;
|
|
|
|
|
2023-09-26 20:00:46 +00:00
|
|
|
// Adds |source| to |background_throttling_sources_|, triggers update of
|
|
|
|
// background throttling state.
|
|
|
|
void AddBackgroundThrottlingSource(BackgroundThrottlingSource* source);
|
|
|
|
// Removes |source| to |background_throttling_sources_|, triggers update of
|
|
|
|
// background throttling state.
|
|
|
|
void RemoveBackgroundThrottlingSource(BackgroundThrottlingSource* source);
|
|
|
|
// Updates `ui::Compositor` background throttling state based on
|
|
|
|
// |background_throttling_sources_|. If at least one of the sources disables
|
|
|
|
// throttling, then throttling in the `ui::Compositor` will be disabled.
|
|
|
|
void UpdateBackgroundThrottlingState();
|
|
|
|
|
2013-04-12 07:04:46 +00:00
|
|
|
protected:
|
2022-10-17 15:10:07 +00:00
|
|
|
friend class api::BrowserView;
|
|
|
|
|
2019-10-25 13:03:28 +00:00
|
|
|
NativeWindow(const gin_helper::Dictionary& options, NativeWindow* parent);
|
2013-04-12 07:04:46 +00:00
|
|
|
|
2018-04-25 07:05:43 +00:00
|
|
|
// views::WidgetDelegate:
|
2020-03-03 21:35:05 +00:00
|
|
|
views::Widget* GetWidget() override;
|
|
|
|
const views::Widget* GetWidget() const override;
|
2021-03-16 16:18:45 +00:00
|
|
|
std::u16string GetAccessibleWindowTitle() const override;
|
2018-04-25 07:05:43 +00:00
|
|
|
|
2018-05-08 03:51:27 +00:00
|
|
|
void set_content_view(views::View* view) { content_view_ = view; }
|
2018-12-22 01:49:26 +00:00
|
|
|
|
2021-08-11 18:07:36 +00:00
|
|
|
// The boolean parsing of the "titleBarOverlay" option
|
2021-07-01 19:25:40 +00:00
|
|
|
bool titlebar_overlay_ = false;
|
|
|
|
|
2022-01-24 22:09:21 +00:00
|
|
|
// The custom height parsed from the "height" option in a Object
|
|
|
|
// "titleBarOverlay"
|
|
|
|
int titlebar_overlay_height_ = 0;
|
|
|
|
|
2021-08-11 18:07:36 +00:00
|
|
|
// The "titleBarStyle" option.
|
|
|
|
TitleBarStyle title_bar_style_ = TitleBarStyle::kNormal;
|
|
|
|
|
2023-07-05 15:02:05 +00:00
|
|
|
// Minimum and maximum size.
|
2024-01-10 22:23:35 +00:00
|
|
|
std::optional<extensions::SizeConstraints> size_constraints_;
|
2023-07-05 15:02:05 +00:00
|
|
|
// Same as above but stored as content size, we are storing 2 types of size
|
|
|
|
// constraints beacause converting between them will cause rounding errors
|
|
|
|
// on HiDPI displays on some environments.
|
2024-01-10 22:23:35 +00:00
|
|
|
std::optional<extensions::SizeConstraints> content_size_constraints_;
|
2023-07-05 15:02:05 +00:00
|
|
|
|
2022-06-07 16:59:50 +00:00
|
|
|
std::queue<bool> pending_transitions_;
|
|
|
|
FullScreenTransitionState fullscreen_transition_state_ =
|
2023-05-12 13:24:01 +00:00
|
|
|
FullScreenTransitionState::kNone;
|
2022-08-01 20:52:58 +00:00
|
|
|
FullScreenTransitionType fullscreen_transition_type_ =
|
2023-05-12 13:24:01 +00:00
|
|
|
FullScreenTransitionType::kNone;
|
2022-06-07 16:59:50 +00:00
|
|
|
|
2023-05-31 09:57:44 +00:00
|
|
|
std::list<NativeWindow*> child_windows_;
|
|
|
|
|
2013-04-12 07:04:46 +00:00
|
|
|
private:
|
2018-04-25 07:05:43 +00:00
|
|
|
std::unique_ptr<views::Widget> widget_;
|
|
|
|
|
2020-07-16 17:14:54 +00:00
|
|
|
static int32_t next_id_;
|
|
|
|
|
2018-05-08 03:51:27 +00:00
|
|
|
// The content view, weak ref.
|
2023-05-11 20:07:39 +00:00
|
|
|
raw_ptr<views::View> content_view_ = nullptr;
|
2018-05-08 03:51:27 +00:00
|
|
|
|
2015-08-05 04:46:32 +00:00
|
|
|
// Whether window has standard frame.
|
2018-05-21 22:18:38 +00:00
|
|
|
bool has_frame_ = true;
|
2015-08-05 04:46:32 +00:00
|
|
|
|
2022-01-26 21:59:09 +00:00
|
|
|
// Whether window has standard frame, but it's drawn by Electron (the client
|
|
|
|
// application) instead of the OS. Currently only has meaning on Linux for
|
|
|
|
// Wayland hosts.
|
|
|
|
bool has_client_frame_ = false;
|
|
|
|
|
2015-08-05 04:46:32 +00:00
|
|
|
// Whether window is transparent.
|
2018-05-21 22:18:38 +00:00
|
|
|
bool transparent_ = false;
|
2015-08-05 04:46:32 +00:00
|
|
|
|
|
|
|
// Whether window can be resized larger than screen.
|
2018-05-21 22:18:38 +00:00
|
|
|
bool enable_larger_than_screen_ = false;
|
2015-08-05 04:46:32 +00:00
|
|
|
|
2013-07-23 07:29:56 +00:00
|
|
|
// The windows has been closed.
|
2018-05-21 22:18:38 +00:00
|
|
|
bool is_closed_ = false;
|
2013-04-30 15:56:50 +00:00
|
|
|
|
2016-05-19 06:39:16 +00:00
|
|
|
// Used to display sheets at the appropriate horizontal and vertical offsets
|
2016-06-18 13:26:26 +00:00
|
|
|
// on macOS.
|
2018-05-21 22:18:38 +00:00
|
|
|
double sheet_offset_x_ = 0.0;
|
|
|
|
double sheet_offset_y_ = 0.0;
|
2016-03-27 01:12:25 +00:00
|
|
|
|
2015-07-16 18:26:48 +00:00
|
|
|
// Used to maintain the aspect ratio of a view which is inside of the
|
|
|
|
// content view.
|
2018-05-21 22:18:38 +00:00
|
|
|
double aspect_ratio_ = 0.0;
|
2015-07-23 02:07:58 +00:00
|
|
|
gfx::Size aspect_ratio_extraSize_;
|
2015-07-16 17:54:51 +00:00
|
|
|
|
2016-06-20 05:49:24 +00:00
|
|
|
// The parent window, it is guaranteed to be valid during this window's life.
|
2023-05-11 20:07:39 +00:00
|
|
|
raw_ptr<NativeWindow> parent_ = nullptr;
|
2016-06-20 05:49:24 +00:00
|
|
|
|
|
|
|
// Is this a modal window.
|
2018-05-21 22:18:38 +00:00
|
|
|
bool is_modal_ = false;
|
2016-06-20 05:49:24 +00:00
|
|
|
|
2022-11-07 18:15:57 +00:00
|
|
|
std::list<DraggableRegionProvider*> draggable_region_providers_;
|
2022-10-17 15:10:07 +00:00
|
|
|
|
2015-08-05 04:46:32 +00:00
|
|
|
// Observers of this window.
|
2015-09-02 07:16:49 +00:00
|
|
|
base::ObserverList<NativeWindowObserver> observers_;
|
2015-08-05 04:32:22 +00:00
|
|
|
|
2023-09-26 20:00:46 +00:00
|
|
|
std::set<BackgroundThrottlingSource*> background_throttling_sources_;
|
|
|
|
|
2019-08-27 22:35:34 +00:00
|
|
|
// Accessible title.
|
2021-03-16 16:18:45 +00:00
|
|
|
std::u16string accessible_title_;
|
2019-08-27 22:35:34 +00:00
|
|
|
|
2023-09-11 12:51:54 +00:00
|
|
|
std::string vibrancy_;
|
|
|
|
std::string background_material_;
|
|
|
|
|
2021-07-01 19:25:40 +00:00
|
|
|
gfx::Rect overlay_rect_;
|
|
|
|
|
2021-01-26 18:16:21 +00:00
|
|
|
base::WeakPtrFactory<NativeWindow> weak_factory_{this};
|
2013-04-12 07:04:46 +00:00
|
|
|
};
|
|
|
|
|
2015-06-24 14:14:46 +00:00
|
|
|
// This class provides a hook to get a NativeWindow from a WebContents.
|
2018-04-18 01:44:10 +00:00
|
|
|
class NativeWindowRelay
|
|
|
|
: public content::WebContentsUserData<NativeWindowRelay> {
|
2015-06-24 14:14:46 +00:00
|
|
|
public:
|
2018-10-02 22:14:43 +00:00
|
|
|
static void CreateForWebContents(content::WebContents*,
|
|
|
|
base::WeakPtr<NativeWindow>);
|
2017-11-30 07:37:26 +00:00
|
|
|
|
2018-10-02 22:14:43 +00:00
|
|
|
~NativeWindowRelay() override;
|
|
|
|
|
|
|
|
NativeWindow* GetNativeWindow() const { return native_window_.get(); }
|
2015-06-24 14:14:46 +00:00
|
|
|
|
2019-01-21 16:56:54 +00:00
|
|
|
WEB_CONTENTS_USER_DATA_KEY_DECL();
|
|
|
|
|
2015-06-24 14:14:46 +00:00
|
|
|
private:
|
|
|
|
friend class content::WebContentsUserData<NativeWindow>;
|
2022-01-10 22:31:39 +00:00
|
|
|
explicit NativeWindowRelay(content::WebContents* web_contents,
|
|
|
|
base::WeakPtr<NativeWindow> window);
|
2018-10-02 22:14:43 +00:00
|
|
|
|
|
|
|
base::WeakPtr<NativeWindow> native_window_;
|
2015-06-24 14:14:46 +00:00
|
|
|
};
|
|
|
|
|
2013-04-12 07:04:46 +00:00
|
|
|
} // namespace electron
|
|
|
|
|
2021-11-22 07:34:31 +00:00
|
|
|
#endif // ELECTRON_SHELL_BROWSER_NATIVE_WINDOW_H_
|