Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Merge pull request #27844 from cctuan/1127207
Browse files Browse the repository at this point in the history
Bug 1127207 - [Text Selection] migrate touchcarettap handler to selectionstatechange
  • Loading branch information
cctuan committed Feb 9, 2015
2 parents f0bb678 + 7732398 commit 8273899
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 77 deletions.
85 changes: 46 additions & 39 deletions apps/system/js/text_selection_dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@
window.addEventListener('mozChromeEvent', this);
window.addEventListener('value-selector-shown', this);
window.addEventListener('value-selector-hidden', this);
window.addEventListener('system-resize', this);
};

TextSelectionDialog.prototype.stop = function tsd_stop() {
Expand All @@ -87,7 +86,6 @@
window.removeEventListener('mozChromeEvent', this);
window.removeEventListener('value-selector-shown', this);
window.removeEventListener('value-selector-hidden', this);
window.removeEventListener('system-resize', this);
};

TextSelectionDialog.prototype.debug = function tsd_debug(msg) {
Expand All @@ -99,14 +97,6 @@

TextSelectionDialog.prototype.handleEvent = function tsd_handleEvent(evt) {
switch (evt.type) {
case 'system-resize':
// When shortcut mode, gaia gets no selectionchanged when lost focus,
// so we listen to system-resize event to hide the bubble.
if (this._shortcutTimeout) {
this._resetShortcutTimeout();
this.hide();
}
break;
case 'home':
case 'activeappchanged':
case 'hierachychanged':
Expand All @@ -121,7 +111,27 @@
case 'mozChromeEvent':
switch (evt.detail.type) {
case 'selectionstatechanged':
this._onSelectionStateChanged(evt);
if (this._ignoreSelectionChange) {
return;
}
evt.preventDefault();
evt.stopPropagation();

var detail = evt.detail.detail;
if (!detail) {
return;
}
this.debug('on receive selection change event');
this.debug(JSON.stringify(detail));

this._isSelectionVisible = detail.visible;
// Separate collapse mode and selection mode for easier handling.
if (detail.isCollapsed) {
this._onCollapsedMode(detail);
} else {
this._onSelectionMode(detail);

}
break;
case 'scrollviewchange':
this.debug('scrollviewchange');
Expand All @@ -139,6 +149,7 @@
}
break;
case 'touchcarettap':
// We'll remove this event handler after bug 1120750 is merged.
this.debug('touchcarettap');
this.show(this.textualmenuDetail);
this._triggerShortcutTimeout();
Expand All @@ -147,37 +158,36 @@
}
};

TextSelectionDialog.prototype._onSelectionStateChanged =
function tsd__onSelectionStateChanged(evt) {
if (this._ignoreSelectionChange) {
return;
TextSelectionDialog.prototype._onCollapsedMode =
function tsd__onCollapsedMode(detail) {
var states = detail.states;
var commands = detail.commands;
this.textualmenuDetail = detail;
// User can tap on empty column within shortcut timeout or simply tap on
// caret to launch bubble.
if (states.indexOf('taponcaret') !== -1 ||
(states.indexOf('mouseup') !== -1 && this._hasCutOrCopied) ||
(this._transitionState === 'opened' &&
states.indexOf('updateposition') !== -1 )) {
// In collapsed mode, only paste option will be displaed if we have
// copied or cut before.
commands.canSelectAll = false;
this.show(detail);
this._triggerShortcutTimeout();
} else {
this.hide();
}
evt.preventDefault();
evt.stopPropagation();
};

var detail = evt.detail.detail;
if (!detail) {
return;
}
this.debug('on receive selection change event');
this.debug(JSON.stringify(detail));
TextSelectionDialog.prototype._onSelectionMode =
function tsd__onSelectionMode(detail) {
var rect = detail.rect;
var states = detail.states;
var commands = detail.commands;
var isCollapsed = detail.isCollapsed;
var isTempShortcut = this._hasCutOrCopied && isCollapsed;
var rectHeight = rect.top - rect.bottom;
var rectWidth = rect.right - rect.left;

this._isSelectionVisible = detail.visible;
// In collapsed mode, only paste option will be displaed if we have copied
// or cut before.
if (isCollapsed && states.indexOf('mouseup') !== -1) {
this.textualmenuDetail = detail;
commands.canSelectAll = false;
}

if (!isTempShortcut && (isCollapsed || !this._isSelectionVisible)) {
if (!this._isSelectionVisible) {
this.close();
return;
}
Expand All @@ -195,14 +205,14 @@
}

if (states.indexOf('mouseup') !== -1 && rectHeight === 0 &&
rectWidth === 0 && !isTempShortcut) {
rectWidth === 0) {
this.hide();
return;
}

// We should not do anything if below cases happen.
if (states.length === 0 || (
rectHeight === 0 && rectWidth === 0 && !isTempShortcut) ||
rectHeight === 0 && rectWidth === 0) ||
!(commands.canPaste || commands.canCut || commands.canSelectAll ||
commands.canCopy)
) {
Expand All @@ -218,9 +228,6 @@
states.indexOf('mouseup') !== -1 ||
states.indexOf('updateposition') !== -1) {
this.show(detail);
if (isTempShortcut) {
this._triggerShortcutTimeout();
}
return;
}
this.hide();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
LockScreenNotificationBuilder.prototype.decorate =
function lsnb_decorate(node) {
// If this is the previous node before the activated one,
// it should hide the buttom border.
// it should hide the bottom border.
var next = node.nextElementSibling;
if (null !== next && next.classList.contains('actionable')) {
node.classList.add('previous-actionable');
Expand Down
2 changes: 1 addition & 1 deletion apps/system/lockscreen/js/lockscreen_notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
};

/**
* Get the notification at the buttom boundary.
* Get the notification at the bottom boundary.
*/
LockScreenNotifications.prototype.notificationAtBottomBoundary =
function lsn_notificationAtBottomBoundary() {
Expand Down
4 changes: 2 additions & 2 deletions apps/system/test/marionette/faketextselectionapp/bug.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
width: 6rem;
height: 2rem;
}
#bug-buttom-input {
#bug-bottom-input {
position: absolute;
bottom: 0;
}
Expand All @@ -19,6 +19,6 @@
<h3>BUG 1110963, BUG 1115508, BUG 1119126</h3>
<input id="bug-center-input" value="testcenterinput">
<div id="bug-normal-div">NORMALDIV</div>
<input id="bug-buttom-input">
<input id="bug-bottom-input">
</body>
</html>
2 changes: 1 addition & 1 deletion apps/system/test/marionette/lib/faketextselectionapp.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ FakeTextSelectionApp.Selector = Object.freeze({
NonEditableNonSelectedDiv: '#noneditable-userselectnone',
// bug.html
BugCenterInput: '#bug-center-input',
BugButtomInput: '#bug-buttom-input',
BugBottomInput: '#bug-bottom-input',
BugNormalDiv: '#bug-normal-div',
// bug1120358.html
BugContent: '#bug-content',
Expand Down
21 changes: 18 additions & 3 deletions apps/system/test/marionette/text_selection_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ marionette('Text selection >', function() {
fakeTextselectionApp.setTestFrame('bug');
});

test('bug1110963 : Cut/Copy/Paste menu should dismiss ' +
test.skip('bug1110963 : Cut/Copy/Paste menu should dismiss ' +
'when tapping the keyboard',
function() {
fakeTextselectionApp.longPress('BugCenterInput');
Expand All @@ -241,7 +241,22 @@ marionette('Text selection >', function() {
});
});

test('bug1119126 : Shortcut bubble should hide when system is resized',
// Enable the test til bug 1120750 is merged.
test.skip('bug1120750 : Send out carets position for the short cut mode ',
function() {
fakeTextselectionApp.longPress('BugCenterInput');
var originalLocation = fakeTextselectionApp.textSelection.location;
fakeTextselectionApp.cut('BugCenterInput');

fakeTextselectionApp.tap('BugBottomInput');
var newLocation = fakeTextselectionApp.textSelection.location;
assert.ok(fakeTextselectionApp.bubbleVisiblity);
assert.ok(newLocation.y > originalLocation.y);
});

// Enable the test til bug 1120750 is merged.
test.skip('bug1119126 : Shortcut bubble should hide when system is' +
' resized',
function() {
systemInputMgmt = client.loader.getAppClass('system',
'input_management');
Expand All @@ -255,7 +270,7 @@ marionette('Text selection >', function() {
return systemInputMgmt.keyboardFrameHidden();
});
fakeTextselectionApp.switchToTestApp();
fakeTextselectionApp.BugButtomInput.tap();
fakeTextselectionApp.BugBottomInput.tap();

systemInputMgmt.waitForKeyboardFrameDisplayed();

Expand Down
Loading

0 comments on commit 8273899

Please sign in to comment.