electron/atom/browser/native_window_mac.h

194 lines
6.6 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.
#ifndef ATOM_BROWSER_NATIVE_WINDOW_MAC_H_
#define ATOM_BROWSER_NATIVE_WINDOW_MAC_H_
#import <Cocoa/Cocoa.h>
#include <string>
#include <vector>
2014-03-16 00:30:26 +00:00
#include "atom/browser/native_window.h"
#include "base/mac/scoped_nsobject.h"
2016-08-01 10:01:21 +00:00
#include "content/public/browser/render_widget_host.h"
2013-04-12 07:04:46 +00:00
@class AtomNSWindow;
@class AtomNSWindowDelegate;
@class FullSizeContentView;
2013-04-12 07:04:46 +00:00
namespace atom {
2016-08-01 10:01:21 +00:00
class NativeWindowMac : public NativeWindow,
public content::RenderWidgetHost::InputEventObserver {
2013-04-12 07:04:46 +00:00
public:
NativeWindowMac(brightray::InspectableWebContents* inspectable_web_contents,
2016-06-19 03:06:08 +00:00
const mate::Dictionary& options,
NativeWindow* parent);
~NativeWindowMac() override;
2013-04-12 07:04:46 +00:00
// NativeWindow:
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;
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;
void SetContentSizeConstraints(
const extensions::SizeConstraints& size_constraints) override;
void SetResizable(bool resizable) override;
bool IsResizable() override;
void SetMovable(bool movable) override;
void SetAspectRatio(double aspect_ratio, const gfx::Size& extra_size)
override;
2016-10-26 00:47:22 +00:00
void PreviewFile(const std::string& path, const std::string& display_name)
2016-10-13 00:25:31 +00:00
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;
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 SetKiosk(bool kiosk) override;
bool IsKiosk() override;
2015-10-23 03:35:33 +00:00
void SetBackgroundColor(const std::string& color_name) override;
void SetHasShadow(bool has_shadow) override;
bool HasShadow() override;
void SetRepresentedFilename(const std::string& filename) override;
std::string GetRepresentedFilename() override;
void SetDocumentEdited(bool edited) override;
bool IsDocumentEdited() override;
void SetIgnoreMouseEvents(bool ignore) override;
void SetContentProtection(bool enable) override;
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
void SetBrowserView(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;
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) override;
bool IsVisibleOnAllWorkspaces() override;
void SetAutoHideCursor(bool auto_hide) 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;
// content::RenderWidgetHost::InputEventObserver:
2016-08-01 10:01:21 +00:00
void OnInputEvent(const blink::WebInputEvent& event) override;
// content::WebContentsObserver:
void RenderViewHostChanged(content::RenderViewHost* old_host,
content::RenderViewHost* new_host) override;
// Refresh the DraggableRegion views.
void UpdateDraggableRegionViews() {
UpdateDraggableRegionViews(draggable_regions_);
}
// 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 TitleBarStyle {
NORMAL,
HIDDEN,
HIDDEN_INSET,
CUSTOM_BUTTONS_ON_HOVER,
};
TitleBarStyle title_bar_style() const { return title_bar_style_; }
2016-10-27 18:29:51 +00:00
bool zoom_to_page_width() const { return zoom_to_page_width_; }
2013-04-12 07:04:46 +00:00
protected:
// Return a vector of non-draggable regions that fill a window of size
// |width| by |height|, but leave gaps where the window should be draggable.
std::vector<gfx::Rect> CalculateNonDraggableRegions(
const std::vector<DraggableRegion>& regions, int width, int height);
2013-04-12 07:04:46 +00:00
private:
// NativeWindow:
2017-05-23 09:41:59 +00:00
gfx::Rect ContentBoundsToWindowBounds(const gfx::Rect& bounds) const;
gfx::Rect WindowBoundsToContentBounds(const gfx::Rect& bounds) const;
void UpdateDraggableRegions(
const std::vector<DraggableRegion>& regions) override;
void ShowWindowButton(NSWindowButton button);
2013-04-12 07:04:46 +00:00
void InstallView();
void UninstallView();
// Install the drag view, which will cover the whole window and decides
// whehter we can drag.
void UpdateDraggableRegionViews(const std::vector<DraggableRegion>& regions);
2013-04-12 07:04:46 +00:00
2016-08-01 10:01:21 +00:00
void RegisterInputEventObserver(content::RenderViewHost* host);
void UnregisterInputEventObserver(content::RenderViewHost* host);
base::scoped_nsobject<AtomNSWindow> window_;
base::scoped_nsobject<AtomNSWindowDelegate> window_delegate_;
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.
base::scoped_nsobject<FullSizeContentView> content_view_;
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
NativeBrowserView* browser_view_;
std::vector<DraggableRegion> draggable_regions_;
2013-04-12 07:04:46 +00:00
bool is_kiosk_;
2017-01-13 23:04:51 +00:00
bool was_fullscreen_;
2016-10-27 18:29:51 +00:00
bool zoom_to_page_width_;
2013-04-12 07:04:46 +00:00
NSInteger attention_request_id_; // identifier from requestUserAttention
// The presentation options before entering kiosk mode.
NSApplicationPresentationOptions kiosk_options_;
// The "titleBarStyle" option.
TitleBarStyle title_bar_style_;
2013-04-12 07:04:46 +00:00
DISALLOW_COPY_AND_ASSIGN(NativeWindowMac);
};
} // namespace atom
#endif // ATOM_BROWSER_NATIVE_WINDOW_MAC_H_