mirror of
https://github.com/electron/electron.git
synced 2026-04-10 03:01:51 -04:00
make draggable regions work
This commit is contained in:
@@ -82,7 +82,6 @@ BrowserWindow::BrowserWindow(gin::Arguments* args,
|
||||
gin::Handle<WebContentsView> web_contents_view =
|
||||
WebContentsView::Create(isolate, web_preferences);
|
||||
DCHECK(web_contents_view.get());
|
||||
window_->AddDraggableRegionProvider(web_contents_view.get());
|
||||
|
||||
// Save a reference of the WebContents.
|
||||
gin::Handle<WebContents> web_contents =
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "base/no_destructor.h"
|
||||
#include "shell/browser/api/electron_api_web_contents.h"
|
||||
#include "shell/browser/browser.h"
|
||||
#include "shell/browser/native_window.h"
|
||||
#include "shell/browser/ui/inspectable_web_contents_view.h"
|
||||
#include "shell/browser/web_contents_preferences.h"
|
||||
#include "shell/common/gin_converters/gfx_converter.h"
|
||||
@@ -19,6 +20,7 @@
|
||||
#include "ui/base/hit_test.h"
|
||||
#include "ui/views/layout/flex_layout_types.h"
|
||||
#include "ui/views/view_class_properties.h"
|
||||
#include "ui/views/widget/widget.h"
|
||||
|
||||
#if BUILDFLAG(IS_MAC)
|
||||
#include "shell/browser/ui/cocoa/delayed_native_view_host.h"
|
||||
@@ -90,6 +92,26 @@ void WebContentsView::WebContentsDestroyed() {
|
||||
web_contents_.Reset();
|
||||
}
|
||||
|
||||
void WebContentsView::OnViewAddedToWidget(views::View* observed_view) {
|
||||
DCHECK_EQ(observed_view, view());
|
||||
views::Widget* widget = view()->GetWidget();
|
||||
auto* native_window = static_cast<NativeWindow*>(
|
||||
widget->GetNativeWindowProperty(electron::kElectronNativeWindowKey));
|
||||
if (!native_window)
|
||||
return;
|
||||
native_window->AddDraggableRegionProvider(this);
|
||||
}
|
||||
|
||||
void WebContentsView::OnViewRemovedFromWidget(views::View* observed_view) {
|
||||
DCHECK_EQ(observed_view, view());
|
||||
views::Widget* widget = view()->GetWidget();
|
||||
auto* native_window = static_cast<NativeWindow*>(
|
||||
widget->GetNativeWindowProperty(kElectronNativeWindowKey));
|
||||
if (!native_window)
|
||||
return;
|
||||
native_window->RemoveDraggableRegionProvider(this);
|
||||
}
|
||||
|
||||
// static
|
||||
gin::Handle<WebContentsView> WebContentsView::Create(
|
||||
v8::Isolate* isolate,
|
||||
|
||||
@@ -47,6 +47,10 @@ class WebContentsView : public View,
|
||||
// content::WebContentsObserver:
|
||||
void WebContentsDestroyed() override;
|
||||
|
||||
// views::ViewObserver
|
||||
void OnViewAddedToWidget(views::View* view) override;
|
||||
void OnViewRemovedFromWidget(views::View* view) override;
|
||||
|
||||
private:
|
||||
static gin_helper::WrappableBase* New(gin_helper::Arguments* args);
|
||||
|
||||
|
||||
@@ -84,6 +84,8 @@ gfx::Size GetExpandedWindowSize(const NativeWindow* window, gfx::Size size) {
|
||||
|
||||
} // namespace
|
||||
|
||||
const char kElectronNativeWindowKey[] = "__ELECTRON_NATIVE_WINDOW__";
|
||||
|
||||
NativeWindow::NativeWindow(const gin_helper::Dictionary& options,
|
||||
NativeWindow* parent)
|
||||
: widget_(std::make_unique<views::Widget>()), parent_(parent) {
|
||||
|
||||
@@ -49,6 +49,8 @@ class PersistentDictionary;
|
||||
|
||||
namespace electron {
|
||||
|
||||
extern const char kElectronNativeWindowKey[];
|
||||
|
||||
class ElectronMenuModel;
|
||||
|
||||
namespace api {
|
||||
|
||||
@@ -248,6 +248,7 @@ NativeWindowMac::NativeWindowMac(const gin_helper::Dictionary& options,
|
||||
params.native_widget =
|
||||
new ElectronNativeWidgetMac(this, windowType, styleMask, widget());
|
||||
widget()->Init(std::move(params));
|
||||
widget()->SetNativeWindowProperty(kElectronNativeWindowKey, this);
|
||||
SetCanResize(resizable);
|
||||
window_ = static_cast<ElectronNSWindow*>(
|
||||
widget()->GetNativeWindow().GetNativeNSWindow());
|
||||
|
||||
@@ -280,6 +280,7 @@ NativeWindowViews::NativeWindowViews(const gin_helper::Dictionary& options,
|
||||
#endif
|
||||
|
||||
widget()->Init(std::move(params));
|
||||
widget()->SetNativeWindowProperty(kElectronNativeWindowKey, this);
|
||||
SetCanResize(resizable_);
|
||||
|
||||
bool fullscreen = false;
|
||||
|
||||
Reference in New Issue
Block a user