Merge pull request #4181 from bengotow/scroll-touch-events

Extend NativeWindow to track touch-based scroll events on OS X
This commit is contained in:
Cheng Zhao 2016-01-25 14:47:54 +08:00
Родитель 58127e3d52 d186dceb4b
Коммит 059d97e1aa
7 изменённых файлов: 47 добавлений и 0 удалений

Просмотреть файл

@ -227,6 +227,14 @@ void Window::OnWindowLeaveFullScreen() {
Emit("leave-full-screen");
}
void Window::OnWindowScrollTouchBegin() {
Emit("scroll-touch-begin");
}
void Window::OnWindowScrollTouchEnd() {
Emit("scroll-touch-end");
}
void Window::OnWindowEnterHtmlFullScreen() {
Emit("enter-html-full-screen");
}

Просмотреть файл

@ -65,6 +65,8 @@ class Window : public mate::TrackableObject<Window>,
void OnWindowResize() override;
void OnWindowMove() override;
void OnWindowMoved() override;
void OnWindowScrollTouchBegin() override;
void OnWindowScrollTouchEnd() override;
void OnWindowEnterFullScreen() override;
void OnWindowLeaveFullScreen() override;
void OnWindowEnterHtmlFullScreen() override;

Просмотреть файл

@ -450,6 +450,16 @@ void NativeWindow::NotifyWindowEnterFullScreen() {
OnWindowEnterFullScreen());
}
void NativeWindow::NotifyWindowScrollTouchBegin() {
FOR_EACH_OBSERVER(NativeWindowObserver, observers_,
OnWindowScrollTouchBegin());
}
void NativeWindow::NotifyWindowScrollTouchEnd() {
FOR_EACH_OBSERVER(NativeWindowObserver, observers_,
OnWindowScrollTouchEnd());
}
void NativeWindow::NotifyWindowLeaveFullScreen() {
FOR_EACH_OBSERVER(NativeWindowObserver, observers_,
OnWindowLeaveFullScreen());

Просмотреть файл

@ -217,6 +217,8 @@ class NativeWindow : public base::SupportsUserData,
void NotifyWindowMove();
void NotifyWindowResize();
void NotifyWindowMoved();
void NotifyWindowScrollTouchBegin();
void NotifyWindowScrollTouchEnd();
void NotifyWindowEnterFullScreen();
void NotifyWindowLeaveFullScreen();
void NotifyWindowEnterHtmlFullScreen();

Просмотреть файл

@ -126,6 +126,7 @@ class NativeWindowMac : public NativeWindow {
base::scoped_nsobject<AtomNSWindow> window_;
base::scoped_nsobject<AtomNSWindowDelegate> window_delegate_;
base::scoped_nsobject<id> event_monitor_;
// The view that will fill the whole frameless window.
base::scoped_nsobject<FullSizeContentView> content_view_;

Просмотреть файл

@ -499,10 +499,32 @@ NativeWindowMac::NativeWindowMac(
NSView* view = inspectable_web_contents()->GetView()->GetNativeView();
[view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
BOOL __block down = NO;
event_monitor_.reset([[NSEvent
addLocalMonitorForEventsMatchingMask:NSScrollWheelMask
handler:^NSEvent * _Nullable(NSEvent * event) {
if ([[event window] windowNumber] != [window_ windowNumber])
return event;
if (!web_contents)
return event;
if (!down && (([event phase] == NSEventPhaseMayBegin) || ([event phase] == NSEventPhaseBegan))) {
this->NotifyWindowScrollTouchBegin();
down = YES;
}
if (down && (([event phase] == NSEventPhaseEnded) || ([event phase] == NSEventPhaseCancelled))) {
this->NotifyWindowScrollTouchEnd();
down = NO;
}
return event;
}] retain]);
InstallView();
}
NativeWindowMac::~NativeWindowMac() {
[NSEvent removeMonitor: event_monitor_.get()];
Observe(nullptr);
}

Просмотреть файл

@ -50,6 +50,8 @@ class NativeWindowObserver {
virtual void OnWindowResize() {}
virtual void OnWindowMove() {}
virtual void OnWindowMoved() {}
virtual void OnWindowScrollTouchBegin() {}
virtual void OnWindowScrollTouchEnd() {}
virtual void OnWindowEnterFullScreen() {}
virtual void OnWindowLeaveFullScreen() {}
virtual void OnWindowEnterHtmlFullScreen() {}