Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for activating various UI items via right click #2859

Merged
merged 56 commits into from
Jul 31, 2019
Merged

Fix for activating various UI items via right click #2859

merged 56 commits into from
Jul 31, 2019

Conversation

Comandeer
Copy link
Member

@Comandeer Comandeer commented Feb 24, 2019

What is the purpose of this pull request?

Bug fix

Does your PR contain necessary tests?

All patches which change the editor code must include tests. You can always read more
on PR testing,
how to set the testing environment and
how to create tests
in the official CKEditor documentation.

This PR contains

  • Unit tests
  • Manual tests

What is the proposed changelog entry for this pull request?

Fixed Issues:

* [IE, Edge] Fixed: Various editor's UI elements react to right mouse button click:
	* [#2845](https://github.com/ckeditor/ckeditor-dev/issues/2845): [Rich Combo](https://ckeditor.com/cke4/addon/richcombo).
	* [#2857](https://github.com/ckeditor/ckeditor-dev/issues/2857): [List Block](https://ckeditor.com/cke4/addon/listblock).
	* [#2858](https://github.com/ckeditor/ckeditor-dev/issues/2858): [Menu](https://ckeditor.com/cke4/addon/menu).

API Changes:

* [#2845](https://github.com/ckeditor/ckeditor-dev/issues/2845): The [`CKEDITOR.tools.normalizeMouseButton`](https://ckeditor.com/docs/ckeditor4/latest/api/CKEDITOR_tools.html#method-normalizeMouseButton) was added.
* [#2975](https://github.com/ckeditor/ckeditor-dev/issues/2975): The [`CKEDITOR.dom.element#fireEventHandler`](https://ckeditor.com/docs/ckeditor4/latest/api/CKEDITOR_dom_element.html#method-fireEventHandler) was added.

What changes did you make?

I've fixed ability to use rich combos, listblocks and menus with right mouse button.

To do so I had to add CKEDITOR.tools.fireElementEventHandler to be able to emulate mouseup events with correct mouse button info in keystrokes handler in panel.

Closes #2845.
Closes #2857.
Closes #2858.
Closes #2975.

@Comandeer Comandeer closed this Feb 26, 2019
@Comandeer Comandeer changed the base branch from next to master February 26, 2019 13:16
@Comandeer Comandeer reopened this Feb 26, 2019
@mlewand mlewand added the review:easy Pull requests that can be reviewed by a Junior Developer before being reviewed by the Reviewer. label Mar 3, 2019
@jacekbogdanski jacekbogdanski self-assigned this Mar 6, 2019
Copy link
Member

@jacekbogdanski jacekbogdanski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like magic numbers for IE8 passed as a mouse button keystroke. I see that IE8 returns different mouse button code than other browsers, however, the mapping should be done explicitly to avoid guessing what's going on. I'm wondering if we could just make reversed getMouseButton mapping public?

## Procedure

1. Open console.
2. Open editor's context menu.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe Open editor's context menu by right-clicking its content. to make it more brainless?

tests/plugins/menu/manual/rightclick.md Show resolved Hide resolved

### Expected result:

Focus is moved to the clicked item.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not valid for a single context menu item which is already preselected.

tests/plugins/menu/manual/rightclick.html Show resolved Hide resolved

// (#2858)
'test right-clicking menu items': function() {
if ( !CKEDITOR.env.ie ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also enable this test for other browsers for regression protection.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Comandeer can you refer to this comment? Is this similar situation as with other tests that you find the regressions very unlikely to happen?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's de facto impossible. We use click event in every other browser, so right click will never occur in the first place. In IE it occurred as we use mouseup event there due to some nasty bug in IE's native image controls.

'<a href="#" onmouseup="this.setAttribute(\'data-button\',event.button);return false;">Link</a>' );

CKEDITOR.tools.fireElementEventHandler( link, 'onmouseup', {
button: 2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, use enum values for readability (CKEDITOR.MOUSE_BUTTON_RIGHT). Update the rest of the proposed tests with enum values.


block._.markFirstDisplayed();

block.onKeyDown( 13 );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add info about pressed keystroke e.g. block.onKeyDown( 13 ); // ENTER.


// (#2565)
'test right-clicking combo': function() {
if ( !CKEDITOR.env.ie ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, I think it makes sense to enable test for all browsers.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I stated there, I do not think such regression is even possible.

// We must pass info about clicked button (#2857).
CKEDITOR.tools.fireElementEventHandler( focusable, 'on' + keyAction, {
button: ( CKEDITOR.env.ie && ( CKEDITOR.env.version < 9 || CKEDITOR.env.ie6Compat ) ) ?
1 : CKEDITOR.MOUSE_BUTTON_LEFT
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This IE8 magic number which additionally can be mistaken with a middle button click (thus 1 == CKEDITOR.MOUSE_BUTTON_MIDDLE should be replaced with correct mapping.

@Comandeer
Copy link
Member Author

I've replaced most of magic numbers with bilateral mouse button normalization via newly added CKEDITOR.tools.normalizeMouseButton method. Additionally I've added CKEDITOR.dom.element#fireEventHandler method and fixed unit tests (as mouse event were dispatched from wrong document object, causing tests to always pass).

I didn't enable tests in any other browsers, as I don't see any reason to do it. The whole issue originates from the fact that we use mouseup event in IE, which is fired for every mouse click, not only ones made with primary button. In contrary, all other browsers use click event, which is restricted only to primary button clicks (bold's mine):

The click event type MUST be dispatched on the topmost event target indicated by the pointer, when the user presses down and releases the primary pointer button, or otherwise activates the pointer in a manner that simulates such an action.

There is no point of switching click to mouseup in any other browser, so IMO it's safe to ignore these tests in other browsers – as regression is very unlike to ever occur there.

@Comandeer
Copy link
Member Author

I see that introduced changes caused CI to fail due to keyboard handling in emoji. I'll fix it.

@Comandeer
Copy link
Member Author

Comandeer commented Mar 25, 2019

I've fixed incorrect handling of keyboard in emoji plugin, using the same technique that was already used in our old approach: if there isn't element[ 'on' + eventName ] property, use element[ eventName ] one. Thanks to that clicks can be fired using element.click.

Copy link
Member

@jacekbogdanski jacekbogdanski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests checking if right click focuses item fails e.g.:
tests/plugins/listblock/manual/rightclick
tests/plugins/menu/manual/rightclick
Right click doesn't focus clicked item, you can verify it by right-clicking item and pressing enter. In that case, the default option will be applied instead of the selected one. Also, there is no visible focus for context menu.

rightclick

core/tools.js Outdated
@@ -1466,26 +1466,72 @@
* @since 4.7.3
* @param {CKEDITOR.dom.event/Event} evt DOM event. Since 4.11.3 a native `MouseEvent` instance can be passed.
* @returns {Number|Boolean} Returns a number indicating the mouse button or `false`
* if the mouse button cannot be determined.
* if the mouse button cannot be determined. The mouse button is normalized using {@link CKEDITOR.tools#normalizeMouseButton}.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this info revealing implementation details?

core/tools.js Outdated
*
* ```
* +--------------+------+----------------+
* | Mouse button | IE | Other browsers |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe IE -> IE8 / IE9 QM / IE9 CM so you need quick glimpse to find out different mappings for these browsers?

@Comandeer
Copy link
Member Author

Tests checking if right click focuses item fails e.g.:
tests/plugins/listblock/manual/rightclick
tests/plugins/menu/manual/rightclick
Right click doesn't focus clicked item, you can verify it by right-clicking item and pressing enter. In that case, the default option will be applied instead of the selected one. Also, there is no visible focus for context menu.

This is the mistake in test description, caused by the fact that visible focus indicator (outline) is in fact moved to the clicked item. I fixed tests descriptions.

I've also rebased the whole PR onto latest major.

@Comandeer Comandeer changed the base branch from master to major May 18, 2019 16:40
@jacekbogdanski jacekbogdanski self-assigned this May 23, 2019
Copy link
Member

@jacekbogdanski jacekbogdanski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When right-clicking any toolbar button on Edge using manual tests, a selection from editor disappears:
rightclick

The issue also sometimes occurs when the right-clicking button of language button (IE10) or right-clicking dropdown item (IE10 and below).

Seems to work fine on Chrome, Firefox.

* } );
* ```
*
* @since 4.11.4
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, update version tags across all changes.

core/tools.js Outdated Show resolved Hide resolved
core/tools.js Outdated

if ( mapping[ 0 ] === button && reverse ) {
return mapping[ 1 ];
} else if ( !reverse && mapping[ 1 ] === button ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

else if could be replaced with simpler if condition thus return statement.

},

/*
* Fires specified mouse event on given element
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing dot, block comment should start with two *. Also grammar:
Fires specified mouse event on the given element.

*/
fireEventHandler: function( eventName, evt ) {
var handlerName = 'on' + eventName,
element = this.$;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about renaming native element with $ prefix? I.e. $element. I know it's not something we are doing in our code base but makes code much more readable for me.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a big fan of it. IMO the name of the variable is readable enough on its own. TBH I'm more eager to change to something like nativeElement than add $ to the beginning – as it would be readable also for users that do not know the convention.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nativeElement also works for me 👍

tests/plugins/menu/manual/rightclick.md Show resolved Hide resolved
CHANGES.md Outdated
@@ -12,6 +12,9 @@ Fixed Issues:

* [#2672](https://github.com/ckeditor/ckeditor-dev/issues/2672): Fixed: When resizing [Enhanced Image](https://ckeditor.com/cke4/addon/image2) to minimum size with a resizer the image dialog doesn't show actual values.
* [#1478](https://github.com/ckeditor/ckeditor-dev/issues/1478): Fixed: Custom colors added to [Color Button](https://ckeditor.com/cke4/addon/colorbutton) via [`config.colorButton_colors`](https://ckeditor.com/docs/ckeditor4/latest/api/CKEDITOR_config.html#cfg-colorButton_colors) in form label/code don't work correctly.
* [#2845](https://github.com/ckeditor/ckeditor-dev/issues/2845): [Rich Combo](https://ckeditor.com/cke4/addon/richcombo) reacts to right mouse button click.
* [#2857](https://github.com/ckeditor/ckeditor-dev/issues/2857): [List Block](https://ckeditor.com/cke4/addon/listblock) items react to right mouse button click.
* [#2858](https://github.com/ckeditor/ckeditor-dev/issues/2858): [Menu](https://ckeditor.com/cke4/addon/menu) items react to right mouse button click.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering about some entry change log merge here as they have mostly the same message. WDYT?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was also thinking about it, but I looked through the whole changelog and didn't spot anything like that. Because of that I decided to create separate entries.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I got an idea, how to do it. bed3e35 shows the proposed solution.

@f1ames
Copy link
Contributor

f1ames commented Jul 31, 2019

Rebased onto latest major.

Copy link
Contributor

@f1ames f1ames left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍 Well done @Comandeer @jacekbogdanski 🎉

@f1ames f1ames merged commit 00c4c02 into major Jul 31, 2019
@CKEditorBot CKEditorBot deleted the t/2845 branch July 31, 2019 14:53
@f1ames f1ames removed this from the 4.13.0 milestone Jul 31, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
review:easy Pull requests that can be reviewed by a Junior Developer before being reviewed by the Reviewer.
Projects
None yet
4 participants