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

8320359: ImageView: add styleable fitWidth, fitHeight, preserveRatio, smooth properties #1293

Conversation

andy-goryachev-oracle
Copy link
Contributor

@andy-goryachev-oracle andy-goryachev-oracle commented Nov 21, 2023

Adding missing styleable properties to ImageView:

-fx-preserve-ratio
-fx-smooth
-fx-fit-width
-fx-fit-height

Updated CSS Reference.


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change requires CSR request JDK-8321126 to be approved

Issues

  • JDK-8320359: ImageView: add styleable fitWidth, fitHeight, preserveRatio, smooth properties (Enhancement - P4)
  • JDK-8321126: ImageView: add styleable fitWidth, fitHeight, preserveRatio, smooth properties (CSR)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jfx.git pull/1293/head:pull/1293
$ git checkout pull/1293

Update a local copy of the PR:
$ git checkout pull/1293
$ git pull https://git.openjdk.org/jfx.git pull/1293/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 1293

View PR using the GUI difftool:
$ git pr show -t 1293

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jfx/pull/1293.diff

Webrev

Link to Webrev Comment

@andy-goryachev-oracle
Copy link
Contributor Author

/csr

@bridgekeeper
Copy link

bridgekeeper bot commented Nov 21, 2023

👋 Welcome back angorya! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk openjdk bot added the csr Need approved CSR to integrate pull request label Nov 21, 2023
@openjdk
Copy link

openjdk bot commented Nov 21, 2023

@andy-goryachev-oracle has indicated that a compatibility and specification (CSR) request is needed for this pull request.

@andy-goryachev-oracle please create a CSR request for issue JDK-8320359 with the correct fix version. This pull request cannot be integrated until the CSR request is approved.

*
* @since 22
*/
public static List<CssMetaData<? extends Styleable, ?>> initStyleables(
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this enhancement shouldn't be a part of this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

created JDK-8320796

@andy-goryachev-oracle andy-goryachev-oracle marked this pull request as ready for review November 30, 2023 16:18
@openjdk openjdk bot added the rfr Ready for review label Nov 30, 2023
@mlbridge
Copy link

mlbridge bot commented Nov 30, 2023

Webrevs

/**
* Utility methods for dealing with CSS.
*/
public class CssUtil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it's best for utility classes to make it final and the constructor private.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this class is not accessible to the outside world, but sure, will do.

Copy link
Collaborator

@hjohn hjohn left a comment

Choose a reason for hiding this comment

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

LGTM

}

/** immutable list with random access backed by an array */
private static class ImmutableArrayList<T> extends AbstractList<T> implements RandomAccess {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd like to point that a skeletal implementation of AbstractList will perform worse than ArrayList for any method that needs to walk the list, as the AbstractList will use iterators for methods like indexOf, hashCode and equals. Now that will probably be irrelevant, but as this seems to be a micro optimization, you should be aware of all the trade offs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, thanks!
This also applies to UnmodifiableArrayList.

For completeness sake, I wanted to mention a few issues (not in scope for this PR) that came out of the code review:

  • could use UnmodifiableArrayList but it stores extra int size. perhaps a factory method can be added to it for when size != elements.length.
  • could improve UnmodifiableArrayList with fast(er) indexOf, hashCode, equals per @hjohn 's comment earlier
  • Control.getCssMetaData() can be improved to skip merging of two lists if skinBase is null
  • the same immutable list should be used in Control.getCssMetaData() instead of ArrayList()

Copy link
Collaborator

Choose a reason for hiding this comment

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

I wouldn't do any of the above unless there is a very good reason (and I'm not seeing one). Just use standard List.of as the last step (or use the Collections.unmodifableList wrapper); you'll get the most optimized, automatically maintained, bugfree, immutable List implementation Java has to offer. It means another copy will be made; that's fine, this only happens once -- it's not in a hot path.

If you feel like optimizing something, don't bother with Control.getCssMetaData either; instead, deduplicate the property lists so there is only one list per unique Skin + Control combo. That saves a complete list per control instance.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, though I would still not use List.of() because of the unnecessary copy.
I agree on Skin + Control copy. Just not sure how... a static hash table perhaps?

Copy link
Member

Choose a reason for hiding this comment

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

I will approve this as is, but I agree with John that it would be better to use one of the existing implementations of List: new UnmodifiableArrayList, List.of, or Collections.unmodifiableList. The cost of the extra copy for List.of is in the noise compared to the benefit of not having to maintain yet another special case List class. Similarly, the extra word of data storage in UnmodifiableArrayList is in the noise. This is a one-per-class not one-per instance list.

Copy link
Member

@kevinrushforth kevinrushforth left a comment

Choose a reason for hiding this comment

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

Looks good. I left one HTML formatting comment on the newly added cssref.html docs (I also left an editorial comment that you should feel free to ignore).

I'll reapprove if and when you make the suggested doc formatting change.

<th class="propertyname" scope="row">-fx-image</th>
<th class="propertyname" scope="row">-fx-fit-height</th>
<td class="value"><a href="#typenumber" class="typelink">&lt;number&gt;</a></td>
<td>0</td>
Copy link
Member

Choose a reason for hiding this comment

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

Since you don't specify a style class for the newly added properties, they will all be left justified. The existing null value for -fx-image specifies class="default" which centers it. I recommend either adding the class="default" to all of the newly added properties, or removing it from the default value of the existing fx-image property.

I'll reapprove if you want to make the change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thank you! I am going to add class="default" as it allows for styling of the default column.

Two notes:

  • There are a few other places where class="default" is omitted (HBox for instance). We may want to fix it in a separate PR.
  • I don't think the center alignment is the right choice here, I would rather see this column left aligned. Perhaps we should fix the .default class as part of the enhancement.

}

/** immutable list with random access backed by an array */
private static class ImmutableArrayList<T> extends AbstractList<T> implements RandomAccess {
Copy link
Member

Choose a reason for hiding this comment

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

I will approve this as is, but I agree with John that it would be better to use one of the existing implementations of List: new UnmodifiableArrayList, List.of, or Collections.unmodifiableList. The cost of the extra copy for List.of is in the noise compared to the benefit of not having to maintain yet another special case List class. Similarly, the extra word of data storage in UnmodifiableArrayList is in the noise. This is a one-per-class not one-per instance list.

Copy link
Member

@kevinrushforth kevinrushforth left a comment

Choose a reason for hiding this comment

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

Looks good.

Once you update the CSR to match the HTML changes, I'll Review that and you can Finalize it.

@andy-goryachev-oracle
Copy link
Contributor Author

Once you update the CSR

updated already

@openjdk
Copy link

openjdk bot commented Dec 4, 2023

@andy-goryachev-oracle This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8320359: ImageView: add styleable fitWidth, fitHeight, preserveRatio, smooth properties

Reviewed-by: mstrauss, jhendrikx, kcr

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 3 new commits pushed to the master branch:

  • 092d5d2: 8314597: Deprecate for removal protected access methods in converters
  • 036d81b: 8269921: TextFlow: listeners on bounds can throw NPE while computing text bounds
  • 0d33417: 8320267: WebView crashes on macOS 11 with WebKit 616.1

Please see this link for an up-to-date comparison between the source branch of this pull request and the master branch.
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk bot added ready Ready to be integrated and removed csr Need approved CSR to integrate pull request labels Dec 4, 2023
@andy-goryachev-oracle
Copy link
Contributor Author

/integrate

@openjdk
Copy link

openjdk bot commented Dec 4, 2023

Going to push as commit aedc887.
Since your change was applied there have been 3 commits pushed to the master branch:

  • 092d5d2: 8314597: Deprecate for removal protected access methods in converters
  • 036d81b: 8269921: TextFlow: listeners on bounds can throw NPE while computing text bounds
  • 0d33417: 8320267: WebView crashes on macOS 11 with WebKit 616.1

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Dec 4, 2023
@openjdk openjdk bot closed this Dec 4, 2023
@openjdk openjdk bot removed ready Ready to be integrated rfr Ready for review labels Dec 4, 2023
@openjdk
Copy link

openjdk bot commented Dec 4, 2023

@andy-goryachev-oracle Pushed as commit aedc887.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

@andy-goryachev-oracle andy-goryachev-oracle deleted the 8320359.image.view.css branch December 4, 2023 21:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integrated Pull request has been integrated
4 participants