2014-10-31 11:17:05 -07:00
|
|
|
// Copyright (c) 2013 GitHub, Inc.
|
2014-04-25 17:49:37 +08:00
|
|
|
// Use of this source code is governed by the MIT license that can be
|
2013-04-12 15:04:46 +08:00
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2019-06-19 13:56:58 -07:00
|
|
|
#ifndef SHELL_BROWSER_NATIVE_WINDOW_MAC_H_
|
|
|
|
#define SHELL_BROWSER_NATIVE_WINDOW_MAC_H_
|
2013-04-12 15:04:46 +08:00
|
|
|
|
|
|
|
#import <Cocoa/Cocoa.h>
|
|
|
|
|
2018-09-12 19:25:56 -05:00
|
|
|
#include <memory>
|
2014-12-18 15:40:35 -08:00
|
|
|
#include <string>
|
2018-11-09 04:03:19 +11:00
|
|
|
#include <tuple>
|
2014-12-18 15:40:35 -08:00
|
|
|
#include <vector>
|
|
|
|
|
2016-08-08 16:33:16 +09:00
|
|
|
#include "base/mac/scoped_nsobject.h"
|
2019-06-19 13:46:59 -07:00
|
|
|
#include "shell/browser/native_window.h"
|
2018-05-02 15:39:43 +09:00
|
|
|
#include "ui/views/controls/native/native_view_host.h"
|
2013-04-12 15:04:46 +08:00
|
|
|
|
2015-03-25 18:51:29 +08:00
|
|
|
@class AtomNSWindow;
|
|
|
|
@class AtomNSWindowDelegate;
|
2018-04-19 16:41:36 +09:00
|
|
|
@class AtomPreviewItem;
|
2018-04-19 16:12:11 +09:00
|
|
|
@class AtomTouchBar;
|
2018-05-02 15:39:43 +09:00
|
|
|
@class CustomWindowButtonView;
|
2014-12-11 14:25:51 -08:00
|
|
|
@class FullSizeContentView;
|
2013-09-05 23:52:29 +08:00
|
|
|
|
2019-06-19 14:23:04 -07:00
|
|
|
namespace electron {
|
2013-04-12 15:04:46 +08:00
|
|
|
|
2018-05-02 15:39:43 +09:00
|
|
|
class RootViewMac;
|
|
|
|
|
2018-04-25 15:51:54 +09:00
|
|
|
class NativeWindowMac : public NativeWindow {
|
2013-04-12 15:04:46 +08:00
|
|
|
public:
|
2018-04-17 21:44:10 -04:00
|
|
|
NativeWindowMac(const mate::Dictionary& options, NativeWindow* parent);
|
2015-06-25 09:47:57 +08:00
|
|
|
~NativeWindowMac() override;
|
2013-04-12 15:04:46 +08:00
|
|
|
|
2015-06-25 11:07:23 +08:00
|
|
|
// NativeWindow:
|
2018-05-08 12:51:27 +09:00
|
|
|
void SetContentView(views::View* view) override;
|
2014-12-23 15:31:39 -08:00
|
|
|
void Close() override;
|
|
|
|
void CloseImmediately() override;
|
|
|
|
void Focus(bool focus) override;
|
|
|
|
bool IsFocused() override;
|
|
|
|
void Show() override;
|
|
|
|
void ShowInactive() override;
|
|
|
|
void Hide() override;
|
|
|
|
bool IsVisible() override;
|
2016-06-17 17:38:44 +09:00
|
|
|
bool IsEnabled() override;
|
2018-02-06 09:16:22 -05:00
|
|
|
void SetEnabled(bool enable) override;
|
2014-12-23 15:31:39 -08:00
|
|
|
void Maximize() override;
|
|
|
|
void Unmaximize() override;
|
|
|
|
bool IsMaximized() override;
|
|
|
|
void Minimize() override;
|
|
|
|
void Restore() override;
|
|
|
|
bool IsMinimized() override;
|
|
|
|
void SetFullScreen(bool fullscreen) override;
|
2015-04-21 19:05:36 +05:30
|
|
|
bool IsFullscreen() const override;
|
2016-01-15 17:31:31 +01:00
|
|
|
void SetBounds(const gfx::Rect& bounds, bool animate = false) override;
|
2015-05-01 20:10:46 +05:30
|
|
|
gfx::Rect GetBounds() override;
|
2018-08-24 23:33:27 +02:00
|
|
|
bool IsNormal() override;
|
|
|
|
gfx::Rect GetNormalBounds() override;
|
2015-10-05 16:19:01 +08:00
|
|
|
void SetContentSizeConstraints(
|
|
|
|
const extensions::SizeConstraints& size_constraints) override;
|
2014-12-23 15:31:39 -08:00
|
|
|
void SetResizable(bool resizable) override;
|
2018-04-03 22:04:32 +09:00
|
|
|
void MoveTop() override;
|
2014-12-23 15:31:39 -08:00
|
|
|
bool IsResizable() override;
|
2016-01-18 23:46:35 +01:00
|
|
|
void SetMovable(bool movable) override;
|
2018-04-17 21:44:10 -04:00
|
|
|
void SetAspectRatio(double aspect_ratio,
|
|
|
|
const gfx::Size& extra_size) override;
|
|
|
|
void PreviewFile(const std::string& path,
|
|
|
|
const std::string& display_name) override;
|
2016-11-21 13:30:13 -05:00
|
|
|
void CloseFilePreview() override;
|
2016-01-18 23:46:35 +01:00
|
|
|
bool IsMovable() override;
|
|
|
|
void SetMinimizable(bool minimizable) override;
|
|
|
|
bool IsMinimizable() override;
|
2016-01-22 22:24:33 +01:00
|
|
|
void SetMaximizable(bool maximizable) override;
|
|
|
|
bool IsMaximizable() override;
|
2016-01-22 23:47:37 -08:00
|
|
|
void SetFullScreenable(bool fullscreenable) override;
|
|
|
|
bool IsFullScreenable() override;
|
2016-01-18 23:46:35 +01:00
|
|
|
void SetClosable(bool closable) override;
|
|
|
|
bool IsClosable() override;
|
2019-07-24 15:58:51 -07:00
|
|
|
void SetAlwaysOnTop(ui::ZOrderLevel z_order,
|
2018-04-17 21:44:10 -04:00
|
|
|
const std::string& level,
|
|
|
|
int relativeLevel,
|
|
|
|
std::string* error) override;
|
2019-07-24 15:58:51 -07:00
|
|
|
ui::ZOrderLevel GetZOrderLevel() override;
|
2014-12-23 15:31:39 -08:00
|
|
|
void Center() override;
|
2017-02-13 19:41:24 -08:00
|
|
|
void Invalidate() override;
|
2014-12-23 15:31:39 -08:00
|
|
|
void SetTitle(const std::string& title) override;
|
|
|
|
std::string GetTitle() override;
|
|
|
|
void FlashFrame(bool flash) override;
|
|
|
|
void SetSkipTaskbar(bool skip) override;
|
2019-03-27 08:10:23 -04:00
|
|
|
void SetExcludedFromShownWindowsMenu(bool excluded) override;
|
|
|
|
bool IsExcludedFromShownWindowsMenu() override;
|
2017-08-13 00:28:33 -06:00
|
|
|
void SetSimpleFullScreen(bool simple_fullscreen) override;
|
|
|
|
bool IsSimpleFullScreen() override;
|
2014-12-23 15:31:39 -08:00
|
|
|
void SetKiosk(bool kiosk) override;
|
|
|
|
bool IsKiosk() override;
|
2018-03-06 13:21:47 +09:00
|
|
|
void SetBackgroundColor(SkColor color) override;
|
2016-01-23 01:15:49 +01:00
|
|
|
void SetHasShadow(bool has_shadow) override;
|
|
|
|
bool HasShadow() override;
|
2017-09-29 11:26:02 +09:00
|
|
|
void SetOpacity(const double opacity) override;
|
2017-10-03 00:08:10 +09:00
|
|
|
double GetOpacity() override;
|
2014-12-23 15:31:39 -08:00
|
|
|
void SetRepresentedFilename(const std::string& filename) override;
|
|
|
|
std::string GetRepresentedFilename() override;
|
|
|
|
void SetDocumentEdited(bool edited) override;
|
|
|
|
bool IsDocumentEdited() override;
|
2018-04-09 12:35:05 +02:00
|
|
|
void SetIgnoreMouseEvents(bool ignore, bool forward) override;
|
2016-06-22 10:40:01 +02:00
|
|
|
void SetContentProtection(bool enable) override;
|
2019-07-07 19:34:18 -07:00
|
|
|
void SetFocusable(bool focusable) override;
|
2018-12-22 04:49:26 +03:00
|
|
|
void AddBrowserView(NativeBrowserView* browser_view) override;
|
|
|
|
void RemoveBrowserView(NativeBrowserView* browser_view) override;
|
2016-06-17 15:28:43 +09:00
|
|
|
void SetParentWindow(NativeWindow* parent) override;
|
2017-05-23 11:41:59 +02:00
|
|
|
gfx::NativeView GetNativeView() const override;
|
|
|
|
gfx::NativeWindow GetNativeWindow() const override;
|
|
|
|
gfx::AcceleratedWidget GetAcceleratedWidget() const override;
|
2018-12-12 02:45:55 +09:00
|
|
|
NativeWindowHandle GetNativeWindowHandle() const override;
|
2016-08-09 16:05:44 -07:00
|
|
|
void SetProgressBar(double progress, const ProgressState state) override;
|
2015-02-07 11:56:03 -08:00
|
|
|
void SetOverlayIcon(const gfx::Image& overlay,
|
2015-02-10 17:14:26 -08:00
|
|
|
const std::string& description) override;
|
2016-11-28 11:38:40 -08:00
|
|
|
|
2018-08-31 17:06:02 -05:00
|
|
|
void SetVisibleOnAllWorkspaces(bool visible,
|
|
|
|
bool visibleOnFullScreen) override;
|
2015-03-26 14:18:37 +08:00
|
|
|
bool IsVisibleOnAllWorkspaces() override;
|
2016-11-28 11:38:40 -08:00
|
|
|
|
2016-11-29 13:36:08 -08:00
|
|
|
void SetAutoHideCursor(bool auto_hide) override;
|
2016-11-28 11:38:40 -08:00
|
|
|
|
2017-08-21 00:46:10 -04:00
|
|
|
void SelectPreviousTab() override;
|
|
|
|
void SelectNextTab() override;
|
|
|
|
void MergeAllWindows() override;
|
|
|
|
void MoveTabToNewWindow() override;
|
|
|
|
void ToggleTabBar() override;
|
2018-02-27 13:00:42 -08:00
|
|
|
bool AddTabbedWindow(NativeWindow* window) override;
|
2017-08-21 00:46:10 -04:00
|
|
|
|
2018-07-03 10:20:56 +02:00
|
|
|
bool SetWindowButtonVisibility(bool visible) override;
|
|
|
|
|
2016-11-07 21:22:41 +01:00
|
|
|
void SetVibrancy(const std::string& type) override;
|
2017-02-28 16:14:02 -08:00
|
|
|
void SetTouchBar(
|
|
|
|
const std::vector<mate::PersistentDictionary>& items) override;
|
2017-02-28 16:08:12 -08:00
|
|
|
void RefreshTouchBarItem(const std::string& item_id) override;
|
2017-03-29 15:11:39 +11:00
|
|
|
void SetEscapeTouchBarItem(const mate::PersistentDictionary& item) override;
|
2015-03-26 14:18:37 +08:00
|
|
|
|
2018-04-17 16:03:51 -07:00
|
|
|
gfx::Rect ContentBoundsToWindowBounds(const gfx::Rect& bounds) const override;
|
|
|
|
gfx::Rect WindowBoundsToContentBounds(const gfx::Rect& bounds) const override;
|
2018-02-22 15:09:38 +09:00
|
|
|
|
2018-07-10 10:43:42 +09:00
|
|
|
// Use a custom content view instead of Chromium's BridgedContentView.
|
|
|
|
void OverrideNSWindowContentView();
|
|
|
|
|
2016-05-17 16:19:28 +09:00
|
|
|
// Set the attribute of NSWindow while work around a bug of zoom button.
|
|
|
|
void SetStyleMask(bool on, NSUInteger flag);
|
|
|
|
void SetCollectionBehavior(bool on, NSUInteger flag);
|
|
|
|
|
2019-05-03 20:11:41 +02:00
|
|
|
enum class TitleBarStyle {
|
2016-06-17 10:54:50 +09:00
|
|
|
NORMAL,
|
|
|
|
HIDDEN,
|
|
|
|
HIDDEN_INSET,
|
2017-06-05 13:30:08 -07:00
|
|
|
CUSTOM_BUTTONS_ON_HOVER,
|
2016-06-17 10:54:50 +09:00
|
|
|
};
|
|
|
|
TitleBarStyle title_bar_style() const { return title_bar_style_; }
|
2015-12-21 20:55:23 +02:00
|
|
|
|
2018-04-19 16:41:36 +09:00
|
|
|
AtomPreviewItem* preview_item() const { return preview_item_.get(); }
|
|
|
|
AtomTouchBar* touch_bar() const { return touch_bar_.get(); }
|
2016-10-27 11:29:51 -07:00
|
|
|
bool zoom_to_page_width() const { return zoom_to_page_width_; }
|
2017-07-14 11:48:10 -07:00
|
|
|
bool fullscreen_window_title() const { return fullscreen_window_title_; }
|
2017-09-13 12:16:37 -06:00
|
|
|
bool simple_fullscreen() const { return always_simple_fullscreen_; }
|
2015-10-21 07:33:43 +08:00
|
|
|
|
2018-04-24 17:23:08 +09:00
|
|
|
protected:
|
|
|
|
// views::WidgetDelegate:
|
2018-04-24 19:00:44 +09:00
|
|
|
bool CanResize() const override;
|
2018-05-02 15:39:43 +09:00
|
|
|
views::View* GetContentsView() override;
|
2018-04-24 17:23:08 +09:00
|
|
|
|
2013-04-12 15:04:46 +08:00
|
|
|
private:
|
2018-07-10 10:43:42 +09:00
|
|
|
// Add custom layers to the content view.
|
2019-05-28 10:23:16 -07:00
|
|
|
void AddContentViewLayers(bool minimizable, bool closable);
|
2018-07-10 10:43:42 +09:00
|
|
|
|
2017-05-01 22:08:27 +02:00
|
|
|
void InternalSetParentWindow(NativeWindow* parent, bool attach);
|
2018-04-09 12:35:05 +02:00
|
|
|
void SetForwardMouseMessages(bool forward);
|
|
|
|
|
2018-04-24 17:23:08 +09:00
|
|
|
AtomNSWindow* window_; // Weak ref, managed by widget_.
|
|
|
|
|
2015-03-25 18:51:29 +08:00
|
|
|
base::scoped_nsobject<AtomNSWindowDelegate> window_delegate_;
|
2018-04-19 16:41:36 +09:00
|
|
|
base::scoped_nsobject<AtomPreviewItem> preview_item_;
|
|
|
|
base::scoped_nsobject<AtomTouchBar> touch_bar_;
|
2018-05-02 15:39:43 +09:00
|
|
|
base::scoped_nsobject<CustomWindowButtonView> buttons_view_;
|
2016-01-25 15:02:43 +08:00
|
|
|
|
|
|
|
// Event monitor for scroll wheel event.
|
|
|
|
id wheel_event_monitor_;
|
2013-04-12 15:04:46 +08:00
|
|
|
|
2014-12-11 14:25:51 -08:00
|
|
|
// The view that will fill the whole frameless window.
|
2018-04-10 17:30:46 +09:00
|
|
|
base::scoped_nsobject<FullSizeContentView> container_view_;
|
|
|
|
|
2018-05-02 15:39:43 +09:00
|
|
|
// The view that fills the client area.
|
|
|
|
std::unique_ptr<RootViewMac> root_view_;
|
|
|
|
|
2018-05-22 00:18:38 +02:00
|
|
|
bool is_kiosk_ = false;
|
|
|
|
bool was_fullscreen_ = false;
|
|
|
|
bool zoom_to_page_width_ = false;
|
|
|
|
bool fullscreen_window_title_ = false;
|
|
|
|
bool resizable_ = true;
|
2017-06-17 20:45:29 -04:00
|
|
|
|
2018-05-22 00:18:38 +02:00
|
|
|
NSInteger attention_request_id_ = 0; // identifier from requestUserAttention
|
2013-04-12 15:04:46 +08:00
|
|
|
|
2014-06-09 13:04:59 +08:00
|
|
|
// The presentation options before entering kiosk mode.
|
|
|
|
NSApplicationPresentationOptions kiosk_options_;
|
|
|
|
|
2016-06-17 10:54:50 +09:00
|
|
|
// The "titleBarStyle" option.
|
2019-05-03 20:11:41 +02:00
|
|
|
TitleBarStyle title_bar_style_ = TitleBarStyle::NORMAL;
|
2016-05-17 15:48:14 +09:00
|
|
|
|
2018-07-03 10:20:56 +02:00
|
|
|
// The visibility mode of window button controls when explicitly set through
|
|
|
|
// setWindowButtonVisibility().
|
|
|
|
base::Optional<bool> window_button_visibility_;
|
|
|
|
|
2017-08-13 00:28:33 -06:00
|
|
|
// Simple (pre-Lion) Fullscreen Settings
|
2018-05-22 00:18:38 +02:00
|
|
|
bool always_simple_fullscreen_ = false;
|
|
|
|
bool is_simple_fullscreen_ = false;
|
|
|
|
bool was_maximizable_ = false;
|
|
|
|
bool was_movable_ = false;
|
2017-08-13 00:28:33 -06:00
|
|
|
NSRect original_frame_;
|
2018-10-10 07:38:52 +02:00
|
|
|
NSInteger original_level_;
|
2017-09-12 12:27:30 -06:00
|
|
|
NSUInteger simple_fullscreen_mask_;
|
2017-08-13 00:28:33 -06:00
|
|
|
|
2018-02-13 05:38:37 +11:00
|
|
|
base::scoped_nsobject<NSColor> background_color_before_vibrancy_;
|
2018-05-22 00:18:38 +02:00
|
|
|
bool transparency_before_vibrancy_ = false;
|
2018-02-13 05:38:37 +11:00
|
|
|
|
2017-08-13 00:28:33 -06:00
|
|
|
// The presentation options before entering simple fullscreen mode.
|
|
|
|
NSApplicationPresentationOptions simple_fullscreen_options_;
|
|
|
|
|
2013-04-12 15:04:46 +08:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(NativeWindowMac);
|
|
|
|
};
|
|
|
|
|
2019-06-19 14:23:04 -07:00
|
|
|
} // namespace electron
|
2013-04-12 15:04:46 +08:00
|
|
|
|
2019-06-19 13:56:58 -07:00
|
|
|
#endif // SHELL_BROWSER_NATIVE_WINDOW_MAC_H_
|