Move InputEventObserver to api::BrowserWindow
This commit is contained in:
parent
aa3eafcea1
commit
c611eb061d
7 changed files with 32 additions and 59 deletions
|
@ -172,6 +172,10 @@ void BrowserWindow::Init(v8::Isolate* isolate,
|
|||
// window's JS wrapper gets initialized.
|
||||
if (!parent.IsEmpty())
|
||||
parent->child_windows_.Set(isolate, ID(), wrapper);
|
||||
|
||||
auto* host = web_contents->web_contents()->GetRenderViewHost();
|
||||
if (host)
|
||||
host->GetWidget()->AddInputEventObserver(this);
|
||||
}
|
||||
|
||||
BrowserWindow::~BrowserWindow() {
|
||||
|
@ -185,6 +189,26 @@ BrowserWindow::~BrowserWindow() {
|
|||
base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, window_.release());
|
||||
}
|
||||
|
||||
void BrowserWindow::OnInputEvent(const blink::WebInputEvent& event) {
|
||||
switch (event.GetType()) {
|
||||
case blink::WebInputEvent::kGestureScrollBegin:
|
||||
case blink::WebInputEvent::kGestureScrollUpdate:
|
||||
case blink::WebInputEvent::kGestureScrollEnd:
|
||||
Emit("scroll-touch-edge");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void BrowserWindow::RenderViewHostChanged(content::RenderViewHost* old_host,
|
||||
content::RenderViewHost* new_host) {
|
||||
if (old_host)
|
||||
old_host->GetWidget()->RemoveInputEventObserver(this);
|
||||
if (new_host)
|
||||
new_host->GetWidget()->AddInputEventObserver(this);
|
||||
}
|
||||
|
||||
void BrowserWindow::RenderViewCreated(
|
||||
content::RenderViewHost* render_view_host) {
|
||||
if (!window_->transparent())
|
||||
|
@ -386,10 +410,6 @@ void BrowserWindow::OnWindowScrollTouchEnd() {
|
|||
Emit("scroll-touch-end");
|
||||
}
|
||||
|
||||
void BrowserWindow::OnWindowScrollTouchEdge() {
|
||||
Emit("scroll-touch-edge");
|
||||
}
|
||||
|
||||
void BrowserWindow::OnWindowSwipe(const std::string& direction) {
|
||||
Emit("swipe", direction);
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#include "atom/common/key_weak_map.h"
|
||||
#include "base/cancelable_callback.h"
|
||||
#include "base/memory/weak_ptr.h"
|
||||
#include "content/public/browser/render_widget_host.h"
|
||||
#include "native_mate/persistent_dictionary.h"
|
||||
|
||||
class GURL;
|
||||
|
@ -37,6 +38,7 @@ class NativeWindow;
|
|||
namespace api {
|
||||
|
||||
class BrowserWindow : public mate::TrackableObject<BrowserWindow>,
|
||||
public content::RenderWidgetHost::InputEventObserver,
|
||||
public content::WebContentsObserver,
|
||||
public ExtendedWebContentsObserver,
|
||||
public NativeWindowObserver {
|
||||
|
@ -60,7 +62,12 @@ class BrowserWindow : public mate::TrackableObject<BrowserWindow>,
|
|||
const mate::Dictionary& options);
|
||||
~BrowserWindow() override;
|
||||
|
||||
// content::RenderWidgetHost::InputEventObserver:
|
||||
void OnInputEvent(const blink::WebInputEvent& event) override;
|
||||
|
||||
// content::WebContentsObserver:
|
||||
void RenderViewHostChanged(content::RenderViewHost* old_host,
|
||||
content::RenderViewHost* new_host) override;
|
||||
void RenderViewCreated(content::RenderViewHost* render_view_host) override;
|
||||
void DidFirstVisuallyNonEmptyPaint() override;
|
||||
void BeforeUnloadDialogCancelled() override;
|
||||
|
@ -90,7 +97,6 @@ class BrowserWindow : public mate::TrackableObject<BrowserWindow>,
|
|||
void OnWindowMoved() override;
|
||||
void OnWindowScrollTouchBegin() override;
|
||||
void OnWindowScrollTouchEnd() override;
|
||||
void OnWindowScrollTouchEdge() override;
|
||||
void OnWindowSwipe(const std::string& direction) override;
|
||||
void OnWindowSheetBegin() override;
|
||||
void OnWindowSheetEnd() override;
|
||||
|
|
|
@ -530,11 +530,6 @@ void NativeWindow::NotifyWindowScrollTouchEnd() {
|
|||
observer.OnWindowScrollTouchEnd();
|
||||
}
|
||||
|
||||
void NativeWindow::NotifyWindowScrollTouchEdge() {
|
||||
for (NativeWindowObserver& observer : observers_)
|
||||
observer.OnWindowScrollTouchEdge();
|
||||
}
|
||||
|
||||
void NativeWindow::NotifyWindowSwipe(const std::string& direction) {
|
||||
for (NativeWindowObserver& observer : observers_)
|
||||
observer.OnWindowSwipe(direction);
|
||||
|
|
|
@ -259,7 +259,6 @@ class NativeWindow : public base::SupportsUserData,
|
|||
void NotifyWindowMoved();
|
||||
void NotifyWindowScrollTouchBegin();
|
||||
void NotifyWindowScrollTouchEnd();
|
||||
void NotifyWindowScrollTouchEdge();
|
||||
void NotifyWindowSwipe(const std::string& direction);
|
||||
void NotifyWindowSheetBegin();
|
||||
void NotifyWindowSheetEnd();
|
||||
|
|
|
@ -12,7 +12,6 @@
|
|||
|
||||
#include "atom/browser/native_window.h"
|
||||
#include "base/mac/scoped_nsobject.h"
|
||||
#include "content/public/browser/render_widget_host.h"
|
||||
|
||||
@class AtomNSWindow;
|
||||
@class AtomNSWindowDelegate;
|
||||
|
@ -20,8 +19,7 @@
|
|||
|
||||
namespace atom {
|
||||
|
||||
class NativeWindowMac : public NativeWindow,
|
||||
public content::RenderWidgetHost::InputEventObserver {
|
||||
class NativeWindowMac : public NativeWindow {
|
||||
public:
|
||||
NativeWindowMac(brightray::InspectableWebContents* inspectable_web_contents,
|
||||
const mate::Dictionary& options,
|
||||
|
@ -124,13 +122,6 @@ class NativeWindowMac : public NativeWindow,
|
|||
void UpdateDraggableRegions(
|
||||
const std::vector<DraggableRegion>& regions) override;
|
||||
|
||||
// content::RenderWidgetHost::InputEventObserver:
|
||||
void OnInputEvent(const blink::WebInputEvent& event) override;
|
||||
|
||||
// content::WebContentsObserver:
|
||||
void RenderViewHostChanged(content::RenderViewHost* old_host,
|
||||
content::RenderViewHost* new_host) override;
|
||||
|
||||
// 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);
|
||||
|
@ -163,9 +154,6 @@ class NativeWindowMac : public NativeWindow,
|
|||
void InstallView();
|
||||
void UninstallView();
|
||||
|
||||
void RegisterInputEventObserver(content::RenderViewHost* host);
|
||||
void UnregisterInputEventObserver(content::RenderViewHost* host);
|
||||
|
||||
void SetRenderWidgetHostOpaque(bool opaque);
|
||||
|
||||
base::scoped_nsobject<AtomNSWindow> window_;
|
||||
|
|
|
@ -1038,9 +1038,6 @@ NativeWindowMac::NativeWindowMac(
|
|||
// Set maximizable state last to ensure zoom button does not get reset
|
||||
// by calls to other APIs.
|
||||
SetMaximizable(maximizable);
|
||||
|
||||
RegisterInputEventObserver(
|
||||
web_contents->GetWebContents()->GetRenderViewHost());
|
||||
}
|
||||
|
||||
NativeWindowMac::~NativeWindowMac() {
|
||||
|
@ -1869,25 +1866,6 @@ void NativeWindowMac::UpdateDraggableRegions(
|
|||
[window_ setMovableByWindowBackground:YES];
|
||||
}
|
||||
|
||||
void NativeWindowMac::OnInputEvent(const blink::WebInputEvent& event) {
|
||||
switch (event.GetType()) {
|
||||
case blink::WebInputEvent::kGestureScrollBegin:
|
||||
case blink::WebInputEvent::kGestureScrollUpdate:
|
||||
case blink::WebInputEvent::kGestureScrollEnd:
|
||||
this->NotifyWindowScrollTouchEdge();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void NativeWindowMac::RenderViewHostChanged(
|
||||
content::RenderViewHost* old_host,
|
||||
content::RenderViewHost* new_host) {
|
||||
UnregisterInputEventObserver(old_host);
|
||||
RegisterInputEventObserver(new_host);
|
||||
}
|
||||
|
||||
std::vector<gfx::Rect> NativeWindowMac::CalculateNonDraggableRegions(
|
||||
const std::vector<DraggableRegion>& regions, int width, int height) {
|
||||
std::vector<gfx::Rect> result;
|
||||
|
@ -2016,18 +1994,6 @@ void NativeWindowMac::SetCollectionBehavior(bool on, NSUInteger flag) {
|
|||
SetMaximizable(was_maximizable);
|
||||
}
|
||||
|
||||
void NativeWindowMac::RegisterInputEventObserver(
|
||||
content::RenderViewHost* host) {
|
||||
if (host)
|
||||
host->GetWidget()->AddInputEventObserver(this);
|
||||
}
|
||||
|
||||
void NativeWindowMac::UnregisterInputEventObserver(
|
||||
content::RenderViewHost* host) {
|
||||
if (host)
|
||||
host->GetWidget()->RemoveInputEventObserver(this);
|
||||
}
|
||||
|
||||
// static
|
||||
NativeWindow* NativeWindow::Create(
|
||||
brightray::InspectableWebContents* inspectable_web_contents,
|
||||
|
|
|
@ -65,7 +65,6 @@ class NativeWindowObserver {
|
|||
virtual void OnWindowMoved() {}
|
||||
virtual void OnWindowScrollTouchBegin() {}
|
||||
virtual void OnWindowScrollTouchEnd() {}
|
||||
virtual void OnWindowScrollTouchEdge() {}
|
||||
virtual void OnWindowSwipe(const std::string& direction) {}
|
||||
virtual void OnWindowSheetBegin() {}
|
||||
virtual void OnWindowSheetEnd() {}
|
||||
|
|
Loading…
Reference in a new issue