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

Providing fallback CSS for inlinetoolbar #1136

Merged
merged 11 commits into from
Nov 23, 2017
Merged

Providing fallback CSS for inlinetoolbar #1136

merged 11 commits into from
Nov 23, 2017

Conversation

msamsel
Copy link
Contributor

@msamsel msamsel commented Nov 8, 2017

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 changes did you make?

  • Adding css for inlinetoolbar and balloonpanel (inline toolbar require it to proper work). CSS base on moono-lisa skin.

I thought to force loading moono-lisa as fallback, but it might be confusing if user will remove those css folders thinking that are unnecessary for his configuration. That's why I add -default suffix and separate files.

@f1ames f1ames self-requested a review November 10, 2017 10:38
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.

Manual test is failing, inline toolbar is not working:
screen shot 2017-11-10 at 12 42 56


Also I don't think copying whole skin for test is a good idea, maybe it will be possible to overwrite appendStyleSheet method to just not load skin CSS file for inlinetoolbar?


This task is about inlinetoolbar and from what I recall the default CSS was supposed to be added only for inlinetoolbar plugin. If there are some additional styles from balloonpanel needed they probably should be placed in inlinetoolbar CSS file too.


Would it be possible to add unit test, which checks if specific styling was applied to inline toolbar (so basically two test, one with default CSS and one with skin)?

@@ -0,0 +1,61 @@
/*
Copy link
Contributor

Choose a reason for hiding this comment

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

I would simply name this file default.css as it is already in the inlinetoolbar directory so the prefix seems redundant.

<p>&nbsp;</p>
<p>&nbsp;</p>
</div>

Copy link
Contributor

Choose a reason for hiding this comment

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

You could also add inline editor here.

@mlewand mlewand changed the title Providing fallback css for inlinetoolbar Providing fallback CSS for inlinetoolbar Nov 13, 2017
@msamsel
Copy link
Contributor Author

msamsel commented Nov 14, 2017

@mlewand what do you think about that?

This task is about inlinetoolbar and from what I recall the default CSS was supposed to be added only for inlinetoolbar plugin. If there are some additional styles from balloonpanel needed they probably should be placed in inlinetoolbar CSS file too.

Inline toolbar inheritance styles from balloon panel related to:

  • drawing triangle below/above balloon
  • ballon position (like setting proper display mode, z-index, etc.)

@msamsel
Copy link
Contributor Author

msamsel commented Nov 15, 2017

I haven't notice that after rebase there was change in API so create method became attach.
I've made al changes suggested in your review. I extract from balloonpanel only important styles (from perspective of inlinetoolbar).

I have to prepare 2 separate test suites with css. Unfortunately skins cannot be changed after loading, so I have to made proper thing at the very begging of each test suite.

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.

Unfortunately, there are some failing tests in Edge/IE realm:

Edge/IE11/IE10

One unit test failing:
screen shot 2017-11-16 at 08 24 10

IE9

Unit test failing:
screen shot 2017-11-16 at 08 42 50

And manual one as it seems default CSS is always used:
screen shot 2017-11-16 at 08 42 26

IE8

Both unit tests failing:
screen shot 2017-11-16 at 08 30 17
screen shot 2017-11-16 at 08 30 26

And manual to as the default skin CSS seems to be always used over specific skin CSS:
screen shot 2017-11-16 at 08 31 32

The manual tests on which I checked how default CSS works with specific skin are tests/plugins/inlinetoolbar/manual/[kama|moono|moono-lisa].


( function() {
'use strict';
// Please be aware that entire test suite has to use the same skin. That's why tests are separate between 2 files.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this comment is unnecessary. As it makes sense in the context of the whole PR, when someone will look at the test itself its lacks this context (same for the other test).

}
};

// We need to set up skin at the very beginning befor files start to load.
Copy link
Contributor

Choose a reason for hiding this comment

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

Typo "before".

// Overwrite prototype to simulate missing css file.
var oldFn = CKEDITOR.dom.document.prototype.appendStyleSheet;
CKEDITOR.dom.document.prototype.appendStyleSheet = function( cssFileUrl ) {
// Simualate missing css in skin.
Copy link
Contributor

Choose a reason for hiding this comment

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

Typo in "Simulate".

if ( cssFileUrl.indexOf( 'inlinetoolbar.css' ) > -1 || cssFileUrl.indexOf( 'balloonpanel.css' ) > -1 ) {
cssFileUrl = '';
}
oldFn.call( CKEDITOR.document, cssFileUrl );
Copy link
Contributor

Choose a reason for hiding this comment

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

You could simplify it a little:

if ( !cssFileUrl.match( /(inlinetoolbar|balloonpanel)\.css/ ) ) {
    oldFn.call( CKEDITOR.document, cssFileUrl );
}

no need to call original function with empty file path.

CKEDITOR.skinName = 'moono';

var tests = {
'test check default css usage': function( editor ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should it be test check specific|moono skin css usage?

cssFileUrl = '';
}

if ( this.$.createStyleSheet ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

We didn't you use call to original function here same as in unit test?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've made it earlier with stub and forget about it. I think option with calling origin function is simpler, and can be resistant for possible method changes.
I've update this to looks like in Unit test.

@bender-ckeditor-plugins: wysiwygarea,toolbar,basicstyles,floatingspace,inlinetoolbar,link,image,resize,language,stylescombo

Perform below steps in both editors:
1. Click into image.
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. Click on image or just Click image.

@msamsel
Copy link
Contributor Author

msamsel commented Nov 16, 2017

As I talk with @mlewand we currently should focus on most popular browsers, and older IE left for further improvements. That's why I ignore tests on IE below 11.
Additional info, all those errors which looks like default.css are used in IE8 etc:

And manual one as it seems default CSS is always used:

Those are also happen on t/933 without introducing default.css. So it's not depended from my change. It's cause just by inline toolbar which doesn't have special styleset for IE8 which replace linear-gradients (or other not supported styles).

I have add different assertion for the IE envs to have sure that "transparent" will be matched.

I also a little tune our tools method, which converts rgb to hex to also support rgba. If you consider it as separate issue, give me an info I'll extract it, but this might extend realisation of this issue. As this introduce dependancy here. Another option would be creating specific function just for those test purposes, but I'm not think is a good option, because this will duplicate the code.

@msamsel msamsel requested a review from f1ames November 16, 2017 14:21
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.

As I talk with @mlewand we currently should focus on most popular browsers, and older IE left for further improvements. That's why I ignore tests on IE below 11.

👍

Additional info, all those errors which looks like default.css are used in IE8 (...) are also happen on t/933 without introducing default.css.

Ok, haven't checked that, in this case it ok to leave it as is 👍


I also a little tune our tools method, which converts rgb to hex to also support rgba. If you consider it as separate issue, give me an info I'll extract it, but this might extend realisation of this issue.

It should be extracted, because it affects much wider part of the code. convertRgbToHex method is used together with CSS normalization which is used in many places in CKEditor. Also you can see that one unit test is failing:
screen shot 2017-11-17 at 11 34 45

The other problem is that your solution just ignores the alpha part, always producing hex representation from rgb part. But two colors with different transparency (e.g. rgba(150, 150, 150, 1) and rgba(150, 150, 150, 0.5)) are just different colors and their hex representation is also different.

Another option would be creating specific function just for those test purposes, but I'm not think is a good option, because this will duplicate the code.

Usually it is not the best approach, however I would go this way in this case. As we need this specific functionality only in this test you could create a function which will filter rgba and pass only rgb to convertRgbToHex function (regex or some split/replace).

You could extract it to some helper as it will be used in both unit tests. I would also place appendStyleSheet stub (https://github.com/ckeditor/ckeditor-dev/pull/1136/files#diff-497cd1ab5d84223f82e739984c6dd387R64) in this helper file as it is also used in two test.

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.

Almost there;)

margin-left: -20px;
}

.cke_balloon.cke_inlinetoolbar
Copy link
Contributor

Choose a reason for hiding this comment

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

This is the same selector as in line 6 (https://github.com/ckeditor/ckeditor-dev/pull/1136/files#diff-a222e1835c2e1c3b856fdaf98d45e2faR6), it should be merged into one rule.

}

/* align: [ hcenter ] */
.cke_balloon.cke_inlinetoolbar .cke_balloon_triangle_outer.cke_balloon_triangle_align_hcenter
Copy link
Contributor

Choose a reason for hiding this comment

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

This is the same selector as in line 28 (https://github.com/ckeditor/ckeditor-dev/pull/1136/files#diff-a222e1835c2e1c3b856fdaf98d45e2faR28), it should be merged into one rule.


'use strict';

function replaceAppendStyleSheet() {
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks good, however it doesn't provide a possibility to clean up after running tests (restore original function). You could do two things:

  • This function might return a function which will restore original one when called:
return function() {
    CKEDITOR.dom.document.prototype.appendStyleSheet = oldFn;
}
  • Use sinon stub which has stub.restore() method.

It is good practise to always clean up after test run (especially for unit tests, for manual you may skip it). So after changing it, please add clean up to unit test (you may use tearDown function).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I decided to not use sinon.stub, because I wasn't able to find possibility to fire origin function within stub.
In documentation I found only possibility how to replace the method, with own function.
That's why I wrote some similar wrapper which could execute native method. I'll extend it a little bit to restore native method.

Copy link
Contributor

Choose a reason for hiding this comment

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

It works fine but it's a little over complicated for me. You have to create new instance, it has two methods which you have to call, etc. plus you reinvented a wheel (well, a part of it:D).

In documentation I found only possibility how to replace the method, with own function.

That's exactly where you can call the original function, the stub could look like this:

function stubAppendStyleSheet() {
	var originFn = CKEDITOR.dom.document.prototype.appendStyleSheet;
	return sinon.stub( CKEDITOR.dom.document.prototype, 'appendStyleSheet', function( cssFileUrl ) {
		// Simulate missing css in skin.
		if ( !cssFileUrl.match( /(inlinetoolbar|balloonpanel)\.css/ ) ) {
			originFn.call( CKEDITOR.document, cssFileUrl );
		}
	} );
}

and then you can use it like:

var stub = stubAppendStyleSheet();
CKEDITOR.once( 'instanceReady', stub.restore );

It is shorter and simpler IMHO. Plus for everybody who knows sinon, you just take a look at the usage and it should be clear that these two lines stubs appendStyleSheet method and then restores it. With custom code you always have to dive in to check what's going on.

@msamsel
Copy link
Contributor Author

msamsel commented Nov 21, 2017

I can use neither setUp nor tearDown. Those methods are executed too late. Skins are loaded when global CKEDITOR object is created and are applied to all editors at given page. That's why test cases are separated between 2 files, and that's why I cannot use it in setUp. Because those methods are executed after main lib is fully loaded.
That's why I made cleaning up in a different approach inside an event, when editor should have all css loaded, so modification shouldn't be required any longer.

@msamsel msamsel requested a review from f1ames November 21, 2017 11:23
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.

Check this comment: #1136 (comment).

@msamsel msamsel requested a review from f1ames November 21, 2017 14:07
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 👍

@f1ames f1ames merged commit d626f55 into t/933 Nov 23, 2017
@f1ames f1ames deleted the t/933-3148 branch November 23, 2017 09:31
mlewand pushed a commit that referenced this pull request Nov 29, 2017
Providing fallback CSS for inlinetoolbar
@mlewand mlewand mentioned this pull request Dec 4, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants