Emit scroll-touch-edge event instead of changing the behavior of scroll-touch-begin/end

fix #6873
This commit is contained in:
Anthony Tseng 2016-09-17 22:29:32 +08:00
parent d4b204799d
commit 269a87b26f
8 changed files with 19 additions and 9 deletions

View file

@ -230,6 +230,10 @@ void Window::OnWindowScrollTouchEnd() {
Emit("scroll-touch-end"); Emit("scroll-touch-end");
} }
void Window::OnWindowScrollTouchEdge() {
Emit("scroll-touch-edge");
}
void Window::OnWindowSwipe(const std::string& direction) { void Window::OnWindowSwipe(const std::string& direction) {
Emit("swipe", direction); Emit("swipe", direction);
} }

View file

@ -74,6 +74,7 @@ class Window : public mate::TrackableObject<Window>,
void OnWindowMoved() override; void OnWindowMoved() override;
void OnWindowScrollTouchBegin() override; void OnWindowScrollTouchBegin() override;
void OnWindowScrollTouchEnd() override; void OnWindowScrollTouchEnd() override;
void OnWindowScrollTouchEdge() override;
void OnWindowSwipe(const std::string& direction) override; void OnWindowSwipe(const std::string& direction) override;
void OnWindowEnterFullScreen() override; void OnWindowEnterFullScreen() override;
void OnWindowLeaveFullScreen() override; void OnWindowLeaveFullScreen() override;

View file

@ -504,6 +504,11 @@ void NativeWindow::NotifyWindowScrollTouchEnd() {
OnWindowScrollTouchEnd()); OnWindowScrollTouchEnd());
} }
void NativeWindow::NotifyWindowScrollTouchEdge() {
FOR_EACH_OBSERVER(NativeWindowObserver, observers_,
OnWindowScrollTouchEdge());
}
void NativeWindow::NotifyWindowSwipe(const std::string& direction) { void NativeWindow::NotifyWindowSwipe(const std::string& direction) {
FOR_EACH_OBSERVER(NativeWindowObserver, observers_, FOR_EACH_OBSERVER(NativeWindowObserver, observers_,
OnWindowSwipe(direction)); OnWindowSwipe(direction));

View file

@ -207,6 +207,7 @@ class NativeWindow : public base::SupportsUserData,
void NotifyWindowMoved(); void NotifyWindowMoved();
void NotifyWindowScrollTouchBegin(); void NotifyWindowScrollTouchBegin();
void NotifyWindowScrollTouchEnd(); void NotifyWindowScrollTouchEnd();
void NotifyWindowScrollTouchEdge();
void NotifyWindowSwipe(const std::string& direction); void NotifyWindowSwipe(const std::string& direction);
void NotifyWindowEnterFullScreen(); void NotifyWindowEnterFullScreen();
void NotifyWindowLeaveFullScreen(); void NotifyWindowLeaveFullScreen();

View file

@ -160,9 +160,6 @@ class NativeWindowMac : public NativeWindow,
// The "titleBarStyle" option. // The "titleBarStyle" option.
TitleBarStyle title_bar_style_; TitleBarStyle title_bar_style_;
// Whether user has scrolled the page to edge.
bool is_edge_;
DISALLOW_COPY_AND_ASSIGN(NativeWindowMac); DISALLOW_COPY_AND_ASSIGN(NativeWindowMac);
}; };

View file

@ -530,8 +530,7 @@ NativeWindowMac::NativeWindowMac(
: NativeWindow(web_contents, options, parent), : NativeWindow(web_contents, options, parent),
is_kiosk_(false), is_kiosk_(false),
attention_request_id_(0), attention_request_id_(0),
title_bar_style_(NORMAL), title_bar_style_(NORMAL) {
is_edge_(false) {
int width = 800, height = 600; int width = 800, height = 600;
options.Get(options::kWidth, &width); options.Get(options::kWidth, &width);
options.Get(options::kHeight, &height); options.Get(options::kHeight, &height);
@ -676,16 +675,14 @@ NativeWindowMac::NativeWindowMac(
if (!web_contents) if (!web_contents)
return event; return event;
if (!began && is_edge_ && (([event phase] == NSEventPhaseMayBegin) || if (!began && (([event phase] == NSEventPhaseMayBegin) ||
([event phase] == NSEventPhaseBegan))) { ([event phase] == NSEventPhaseBegan))) {
this->NotifyWindowScrollTouchBegin(); this->NotifyWindowScrollTouchBegin();
began = YES; began = YES;
is_edge_ = false;
} else if (began && (([event phase] == NSEventPhaseEnded) || } else if (began && (([event phase] == NSEventPhaseEnded) ||
([event phase] == NSEventPhaseCancelled))) { ([event phase] == NSEventPhaseCancelled))) {
this->NotifyWindowScrollTouchEnd(); this->NotifyWindowScrollTouchEnd();
began = NO; began = NO;
is_edge_ = false;
} }
return event; return event;
}]; }];
@ -1131,7 +1128,7 @@ void NativeWindowMac::OnInputEvent(const blink::WebInputEvent& event) {
case blink::WebInputEvent::GestureScrollBegin: case blink::WebInputEvent::GestureScrollBegin:
case blink::WebInputEvent::GestureScrollUpdate: case blink::WebInputEvent::GestureScrollUpdate:
case blink::WebInputEvent::GestureScrollEnd: case blink::WebInputEvent::GestureScrollEnd:
is_edge_ = true; this->NotifyWindowScrollTouchEdge();
break; break;
default: default:
break; break;

View file

@ -64,6 +64,7 @@ class NativeWindowObserver {
virtual void OnWindowMoved() {} virtual void OnWindowMoved() {}
virtual void OnWindowScrollTouchBegin() {} virtual void OnWindowScrollTouchBegin() {}
virtual void OnWindowScrollTouchEnd() {} virtual void OnWindowScrollTouchEnd() {}
virtual void OnWindowScrollTouchEdge() {}
virtual void OnWindowSwipe(const std::string& direction) {} virtual void OnWindowSwipe(const std::string& direction) {}
virtual void OnWindowEnterFullScreen() {} virtual void OnWindowEnterFullScreen() {}
virtual void OnWindowLeaveFullScreen() {} virtual void OnWindowLeaveFullScreen() {}

View file

@ -448,6 +448,10 @@ Emitted when scroll wheel event phase has begun.
Emitted when scroll wheel event phase has ended. Emitted when scroll wheel event phase has ended.
#### Event: 'scroll-touch-edge' _macOS_
Emitted when scroll wheel event phase filed upon reaching the edge of element.
#### Event: 'swipe' _macOS_ #### Event: 'swipe' _macOS_
Returns: Returns: