Skip to content

Commit 159192f

Browse files
committed
Several changes:
- Expose touchStarted and touchEnded events on WAbstractItemView - Touch: use long long for identifier and add accessor Some browsers use negative values, some browsers use values larger than 2**31 - 1, let's just use long long, so whatever the value is, it will be preserved.
1 parent 2d20243 commit 159192f

File tree

12 files changed

+136
-47
lines changed

12 files changed

+136
-47
lines changed

src/Wt/WAbstractItemView.C

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1394,8 +1394,8 @@ void WAbstractItemView::handleMouseUp(const WModelIndex& index,
13941394
mouseWentUp_.emit(index, event);
13951395
}
13961396

1397-
void WAbstractItemView::handleTouchStart(const std::vector<WModelIndex>& indices,
1398-
const WTouchEvent& event)
1397+
void WAbstractItemView::handleTouchSelect(const std::vector<WModelIndex>& indices,
1398+
const WTouchEvent& event)
13991399
{
14001400
const WModelIndex& index = indices[0];
14011401
touchRegistered_ = true;
@@ -1415,6 +1415,18 @@ void WAbstractItemView::handleTouchStart(const std::vector<WModelIndex>& indices
14151415
touchStart_.emit(index, event);
14161416
}
14171417

1418+
void WAbstractItemView::handleTouchStart(const std::vector<WModelIndex>& indices,
1419+
const WTouchEvent& event)
1420+
{
1421+
touchStarted_.emit(indices, event);
1422+
}
1423+
1424+
void WAbstractItemView::handleTouchEnd(const std::vector<WModelIndex>& indices,
1425+
const WTouchEvent& event)
1426+
{
1427+
touchEnded_.emit(indices, event);
1428+
}
1429+
14181430
void WAbstractItemView::setEditTriggers(WFlags<EditTrigger> editTriggers)
14191431
{
14201432
editTriggers_ = editTriggers;

src/Wt/WAbstractItemView.h

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -714,9 +714,29 @@ class WT_API WAbstractItemView : public WCompositeWidget
714714
*
715715
* When the event happened over an item, the first argument
716716
* indicates the item that was touched.
717+
*
718+
* \deprecated Use touchStarted() instead.
717719
*/
718720
Signal<WModelIndex, WTouchEvent>& touchStart() { return touchStart_; }
719721

722+
/*! \brief %Signal emitted when one or more fingers are placed on the screen.
723+
*
724+
* When the event happened over an item, the first argument
725+
* indicates the items that were touched. The indices in the model index
726+
* vector match the indices in the \link WTouchEvent::changedTouches() changedTouches() of the WTouchEvent\endlink.
727+
*/
728+
Signal<std::vector<WModelIndex>, WTouchEvent>& touchStarted() { return touchStarted_; }
729+
730+
/*! \brief %Signal emitted when one or more fingers are removed from the screen.
731+
*
732+
* When the event happened over an item, the first argument
733+
* indicates the items where the touch ended. The indices in the model index
734+
* vector match the indices in the \link WTouchEvent::changedTouches() changedTouches() of the WTouchEvent\endlink.
735+
*
736+
* \note When JavaScript is disabled, the signal will never fire.
737+
*/
738+
Signal<std::vector<WModelIndex>, WTouchEvent>& touchEnded() { return touchEnded_; }
739+
720740
/*! \brief %Signal emitted when the selection is changed.
721741
*
722742
* \sa select(), setSelectionMode(), setSelectionBehavior()
@@ -1008,10 +1028,20 @@ class WT_API WAbstractItemView : public WCompositeWidget
10081028
virtual void handleMouseUp(const WModelIndex& index,
10091029
const WMouseEvent& event);
10101030

1031+
/*! \brief Handles a touch select event.
1032+
*/
1033+
virtual void handleTouchSelect(const std::vector<WModelIndex>& indices,
1034+
const WTouchEvent& event);
1035+
10111036
/*! \brief Handles a touch started event.
10121037
*/
10131038
virtual void handleTouchStart(const std::vector<WModelIndex>& indices,
1014-
const WTouchEvent& event);
1039+
const WTouchEvent& event);
1040+
1041+
/*! \brief Handles a touch ended event.
1042+
*/
1043+
virtual void handleTouchEnd(const std::vector<WModelIndex>& indices,
1044+
const WTouchEvent& event);
10151045

10161046
virtual bool internalSelect(const WModelIndex& index, SelectionFlag option);
10171047

@@ -1083,6 +1113,8 @@ class WT_API WAbstractItemView : public WCompositeWidget
10831113
Signal<WModelIndex, WMouseEvent> mouseWentDown_;
10841114
Signal<WModelIndex, WMouseEvent> mouseWentUp_;
10851115
Signal<WModelIndex, WTouchEvent> touchStart_;
1116+
Signal<std::vector<WModelIndex>, WTouchEvent> touchStarted_;
1117+
Signal<std::vector<WModelIndex>, WTouchEvent> touchEnded_;
10861118
Signal<> selectionChanged_;
10871119
Signal<> pageChanged_;
10881120

src/Wt/WEvent.C

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,8 @@ namespace {
4040
return Utils::stoi(v);
4141
}
4242

43-
unsigned asUInt(const std::string& v) {
44-
long long res = Utils::stoll(v);
45-
return static_cast<unsigned>(res);
43+
long long asLongLong(const std::string& v) {
44+
return Utils::stoll(v);
4645
}
4746

4847
int parseIntParameter(const WebRequest& request, const std::string& name,
@@ -85,7 +84,7 @@ namespace {
8584

8685
try {
8786
for (unsigned i = 0; i < s.size(); i += 9) {
88-
result.push_back(Touch(asUInt(s[i + 0]),
87+
result.push_back(Touch(asLongLong(s[i + 0]),
8988
asInt(s[i + 1]), asInt(s[i + 2]),
9089
asInt(s[i + 3]), asInt(s[i + 4]),
9190
asInt(s[i + 5]), asInt(s[i + 6]),
@@ -108,7 +107,7 @@ EventType WEvent::eventType() const
108107
return impl_.handler->session()->getEventType(*this);
109108
}
110109

111-
Touch::Touch(unsigned identifier,
110+
Touch::Touch(long long identifier,
112111
int clientX, int clientY,
113112
int documentX, int documentY,
114113
int screenX, int screenY,

src/Wt/WEvent.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ namespace Wt {
3434
public:
3535
/*! \brief Constructor.
3636
*/
37-
Touch(unsigned identifier,
37+
Touch(long long identifier,
3838
int clientX, int clientY,
3939
int documentX, int documentY,
4040
int screenX, int screenY,
@@ -59,12 +59,16 @@ namespace Wt {
5959
*/
6060
Coordinates widget() const { return Coordinates(widgetX_, widgetY_); }
6161

62+
/*! \brief Returns the identifier for this touch.
63+
*/
64+
long long identifier() const { return identifier_; }
65+
6266
private:
6367
int clientX_, clientY_;
6468
int documentX_, documentY_;
6569
int screenX_, screenY_;
6670
int widgetX_, widgetY_;
67-
unsigned identifier_;
71+
long long identifier_;
6872
};
6973

7074
class WebRequest;

src/Wt/WTableView.C

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ WTableView::WTableView()
5555
plainTable_(nullptr),
5656
dropEvent_(impl_, "dropEvent"),
5757
scrolled_(impl_, "scrolled"),
58-
itemTouchEvent_(impl_, "itemTouchEvent"),
58+
itemTouchSelectEvent_(impl_, "itemTouchSelectEvent"),
5959
firstColumn_(-1),
6060
lastColumn_(-1),
6161
viewportLeft_(0),
@@ -790,8 +790,8 @@ void WTableView::defineJavaScript()
790790
if (!scrolled_.isConnected())
791791
scrolled_.connect(this, &WTableView::onViewportChange);
792792

793-
if (!itemTouchEvent_.isConnected())
794-
itemTouchEvent_.connect(this, &WTableView::handleTouchStarted);
793+
if (!itemTouchSelectEvent_.isConnected())
794+
itemTouchSelectEvent_.connect(this, &WTableView::handleTouchSelected);
795795

796796
if (!columnResizeConnected_) {
797797
columnResized().connect(this, &WTableView::onColumnResize);
@@ -869,6 +869,18 @@ void WTableView::render(WFlags<RenderFlag> flags)
869869
(this, std::bind(&WTableView::handleRootDoubleClick, this, 0,
870870
std::placeholders::_1));
871871
}
872+
873+
if (!touchStartConnection_.isConnected()
874+
&& touchStarted().isConnected()) {
875+
touchStartConnection_ = canvas_->touchStarted()
876+
.connect(std::bind(&WTableView::handleTouchStarted, this, std::placeholders::_1));
877+
}
878+
879+
if (!touchEndConnection_.isConnected()
880+
&& touchEnded().isConnected()) {
881+
touchEndConnection_ = canvas_->touchEnded()
882+
.connect(std::bind(&WTableView::handleTouchEnded, this, std::placeholders::_1));
883+
}
872884
}
873885

874886
if (model())
@@ -1737,15 +1749,35 @@ void WTableView::handleMouseWentUp(bool headerColumns, const WMouseEvent& event)
17371749
handleMouseUp(index, event);
17381750
}
17391751

1740-
void WTableView::handleTouchStarted(const WTouchEvent& event)
1752+
void WTableView::handleTouchSelected(const WTouchEvent& event)
17411753
{
17421754
std::vector<WModelIndex> indices;
17431755
for(std::size_t i = 0; i < event.touches().size(); i++){
17441756
indices.push_back(translateModelIndex(event.touches()[i]));
17451757
}
1758+
handleTouchSelect(indices, event);
1759+
}
1760+
1761+
void WTableView::handleTouchStarted(const WTouchEvent& event)
1762+
{
1763+
std::vector<WModelIndex> indices;
1764+
const std::vector<Touch> &touches = event.changedTouches();
1765+
for(std::size_t i = 0; i < touches.size(); i++){
1766+
indices.push_back(translateModelIndex(touches[i]));
1767+
}
17461768
handleTouchStart(indices, event);
17471769
}
17481770

1771+
void WTableView::handleTouchEnded(const WTouchEvent& event)
1772+
{
1773+
std::vector<WModelIndex> indices;
1774+
const std::vector<Touch> &touches = event.changedTouches();
1775+
for (std::size_t i = 0; i < touches.size(); i++) {
1776+
indices.push_back(translateModelIndex(touches[i]));
1777+
}
1778+
handleTouchEnd(indices, event);
1779+
}
1780+
17491781
void WTableView::handleRootSingleClick(int u, const WMouseEvent& event)
17501782
{
17511783
handleClick(WModelIndex(), event);

src/Wt/WTableView.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,10 @@ class WT_API WTableView : public WAbstractItemView
170170

171171
JSignal<int, int, std::string, std::string, WMouseEvent> dropEvent_;
172172
JSignal<int, int, int, int> scrolled_;
173-
JSignal<WTouchEvent> itemTouchEvent_;
173+
JSignal<WTouchEvent> itemTouchSelectEvent_;
174+
175+
Signals::connection touchStartConnection_;
176+
Signals::connection touchEndConnection_;
174177

175178
/* Ajax only: First and last columns rendered (this somewhat
176179
* redundant with the state contained in the widgets, but because
@@ -241,7 +244,9 @@ class WT_API WTableView : public WAbstractItemView
241244
void handleDblClick(bool headerColumns, const WMouseEvent& event);
242245
void handleMouseWentDown(bool headerColumns, const WMouseEvent& event);
243246
void handleMouseWentUp(bool headerColumns, const WMouseEvent& event);
247+
void handleTouchSelected(const WTouchEvent& event);
244248
void handleTouchStarted(const WTouchEvent& event);
249+
void handleTouchEnded(const WTouchEvent& event);
245250
WModelIndex translateModelIndex(bool headerColumns, const WMouseEvent& event);
246251
WModelIndex translateModelIndex(const Touch& touch);
247252

src/Wt/WTreeView.C

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1364,7 +1364,7 @@ void WTreeView::render(WFlags<RenderFlag> flags)
13641364
if (flags.test(RenderFlag::Full)) {
13651365
defineJavaScript();
13661366

1367-
if (!itemTouchEvent_.isConnected())
1367+
if (!itemTouchEvent_.isConnected())
13681368
itemTouchEvent_.connect(this, &WTreeView::onItemTouchEvent);
13691369

13701370
if (!itemEvent_.isConnected()) {
@@ -1609,16 +1609,19 @@ void WTreeView::onItemEvent(std::string nodeAndColumnId, std::string type,
16091609
}
16101610
}
16111611

1612-
void WTreeView::onItemTouchEvent(std::string nodeAndColumnId, std::string type,
1613-
std::string extra1, std::string extra2, WTouchEvent event)
1612+
void WTreeView::onItemTouchEvent(std::string nodeAndColumnId, std::string type, WTouchEvent event)
16141613
{
16151614
// nodeId and columnId are combined because WSignal needed to be changed
16161615
// since MSVS 2012 does not support >5 arguments in std::bind()
16171616
std::vector<WModelIndex> index;
16181617
index.push_back(calculateModelIndex(nodeAndColumnId));
16191618

1620-
if (type == "touchstart")
1619+
if (type == "touchselect")
1620+
handleTouchSelect(index, event);
1621+
else if (type == "touchstart")
16211622
handleTouchStart(index, event);
1623+
else if (type == "touchend")
1624+
handleTouchEnd(index, event);
16221625
}
16231626

16241627
WModelIndex WTreeView::calculateModelIndex(std::string nodeAndColumnId)

src/Wt/WTreeView.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,7 @@ class WT_API WTreeView : public WAbstractItemView
268268

269269
JSignal<std::string, std::string, std::string,
270270
std::string, WMouseEvent> itemEvent_;
271-
JSignal<std::string, std::string, std::string,
272-
std::string, WTouchEvent> itemTouchEvent_;
271+
JSignal<std::string, std::string, WTouchEvent> itemTouchEvent_;
273272

274273
std::unique_ptr<ToggleButtonConfig> expandConfig_;
275274

@@ -300,8 +299,7 @@ class WT_API WTreeView : public WAbstractItemView
300299
void contentsSizeChanged(int width, int height);
301300
void onItemEvent(std::string nodeAndColumnId, std::string type,
302301
std::string extra1, std::string extra2, WMouseEvent event);
303-
void onItemTouchEvent(std::string nodeAndColumnId, std::string type,
304-
std::string extra1, std::string extra2, WTouchEvent event);
302+
void onItemTouchEvent(std::string nodeAndColumnId, std::string type, WTouchEvent event);
305303
WModelIndex calculateModelIndex(std::string nodeAndColumnId);
306304
void setRootNodeStyle();
307305
void setCollapsed(const WModelIndex& index);

src/js/WTableView.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,18 +269,18 @@ WT_DECLARE_WT_MEMBER
269269
}
270270
if (event.touches.length > 1) {
271271
clearTimeout(touchStartTimer);
272-
touchStartTimer = setTimeout(function(){emitTouchStart(obj, event);}, 1000);
272+
touchStartTimer = setTimeout(function(){emitTouchSelect(obj, event);}, 1000);
273273
touches = event.touches.length;
274274
}
275275
else{
276276
clearTimeout(touchStartTimer);
277-
touchStartTimer = setTimeout(function(){emitTouchStart(obj, event);}, 50);
277+
touchStartTimer = setTimeout(function(){emitTouchSelect(obj, event);}, 50);
278278
touches = 1;
279279
}
280280
};
281281

282-
function emitTouchStart(obj, event) {
283-
APP.emit(el, { name: 'itemTouchEvent', eventObject: obj, event: event});
282+
function emitTouchSelect(obj, event) {
283+
APP.emit(el, { name: 'itemTouchSelectEvent', eventObject: obj, event: event});
284284
};
285285

286286
this.touchMove = function(obj, event) {

src/js/WTableView.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)