electron/shell/browser/native_window_mac.h

230 lines
8.1 KiB
C
Raw Normal View History

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