Skip to content
This repository has been archived by the owner on Jan 4, 2019. It is now read-only.

Commit

Permalink
Emit scroll-touch-edge event instead of changing the behavior of scro…
Browse files Browse the repository at this point in the history
…ll-touch-begin/end

Auditor: @bbondy
  • Loading branch information
darkdh committed Sep 19, 2016
1 parent e6fed34 commit a5042be
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 9 deletions.
4 changes: 4 additions & 0 deletions atom/browser/api/atom_api_window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,10 @@ void Window::OnWindowScrollTouchEnd() {
Emit("scroll-touch-end");
}

void Window::OnWindowScrollTouchEdge() {
Emit("scroll-touch-edge");
}

void Window::OnWindowSwipe(const std::string& direction) {
Emit("swipe", direction);
}
Expand Down
1 change: 1 addition & 0 deletions atom/browser/api/atom_api_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class Window : public mate::TrackableObject<Window>,
void OnWindowMoved() override;
void OnWindowScrollTouchBegin() override;
void OnWindowScrollTouchEnd() override;
void OnWindowScrollTouchEdge() override;
void OnWindowSwipe(const std::string& direction) override;
void OnWindowEnterFullScreen() override;
void OnWindowLeaveFullScreen() override;
Expand Down
5 changes: 5 additions & 0 deletions atom/browser/native_window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,11 @@ void NativeWindow::NotifyWindowScrollTouchEnd() {
OnWindowScrollTouchEnd());
}

void NativeWindow::NotifyWindowScrollTouchEdge() {
FOR_EACH_OBSERVER(NativeWindowObserver, observers_,
OnWindowScrollTouchEdge());
}

void NativeWindow::NotifyWindowSwipe(const std::string& direction) {
FOR_EACH_OBSERVER(NativeWindowObserver, observers_,
OnWindowSwipe(direction));
Expand Down
1 change: 1 addition & 0 deletions atom/browser/native_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ class NativeWindow : public base::SupportsUserData,
void NotifyWindowMoved();
void NotifyWindowScrollTouchBegin();
void NotifyWindowScrollTouchEnd();
void NotifyWindowScrollTouchEdge();
void NotifyWindowSwipe(const std::string& direction);
void NotifyWindowEnterFullScreen();
void NotifyWindowLeaveFullScreen();
Expand Down
3 changes: 0 additions & 3 deletions atom/browser/native_window_mac.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,6 @@ class NativeWindowMac : public NativeWindow,
// The "titleBarStyle" option.
TitleBarStyle title_bar_style_;

// Whether user has scrolled the page to edge.
bool is_edge_;

DISALLOW_COPY_AND_ASSIGN(NativeWindowMac);
};

Expand Down
9 changes: 3 additions & 6 deletions atom/browser/native_window_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -530,8 +530,7 @@ static bool FromV8(v8::Isolate* isolate, v8::Handle<v8::Value> val,
: NativeWindow(web_contents, options, parent),
is_kiosk_(false),
attention_request_id_(0),
title_bar_style_(NORMAL),
is_edge_(false) {
title_bar_style_(NORMAL) {
int width = 800, height = 600;
options.Get(options::kWidth, &width);
options.Get(options::kHeight, &height);
Expand Down Expand Up @@ -676,16 +675,14 @@ static bool FromV8(v8::Isolate* isolate, v8::Handle<v8::Value> val,
if (!web_contents)
return event;

if (!began && is_edge_ && (([event phase] == NSEventPhaseMayBegin) ||
if (!began && (([event phase] == NSEventPhaseMayBegin) ||
([event phase] == NSEventPhaseBegan))) {
this->NotifyWindowScrollTouchBegin();
began = YES;
is_edge_ = false;
} else if (began && (([event phase] == NSEventPhaseEnded) ||
([event phase] == NSEventPhaseCancelled))) {
this->NotifyWindowScrollTouchEnd();
began = NO;
is_edge_ = false;
}
return event;
}];
Expand Down Expand Up @@ -1132,7 +1129,7 @@ static bool FromV8(v8::Isolate* isolate, v8::Handle<v8::Value> val,
case blink::WebInputEvent::GestureScrollBegin:
case blink::WebInputEvent::GestureScrollUpdate:
case blink::WebInputEvent::GestureScrollEnd:
is_edge_ = true;
this->NotifyWindowScrollTouchEdge();
break;
default:
break;
Expand Down
1 change: 1 addition & 0 deletions atom/browser/native_window_observer.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class NativeWindowObserver {
virtual void OnWindowMoved() {}
virtual void OnWindowScrollTouchBegin() {}
virtual void OnWindowScrollTouchEnd() {}
virtual void OnWindowScrollTouchEdge() {}
virtual void OnWindowSwipe(const std::string& direction) {}
virtual void OnWindowEnterFullScreen() {}
virtual void OnWindowLeaveFullScreen() {}
Expand Down
4 changes: 4 additions & 0 deletions docs/api/browser-window.md
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,10 @@ Emitted when scroll wheel event phase has begun.

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_

Returns:
Expand Down

0 comments on commit a5042be

Please sign in to comment.