src/java.desktop/macosx/classes/apple/laf/JRSUIUtils.java
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 31432 jdk/src/java.desktop/macosx/classes/apple/laf/JRSUIUtils.java@15d0fd22179a
child 59169 7dae4286f1cc
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     1
/*
31432
15d0fd22179a 8008803: [macosx] JVM crash in apple.laf.JRSUIUtils.HitDetection.getHitForPoint
serb
parents: 25859
diff changeset
     2
 * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     4
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    10
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    15
 * accompanied this code).
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    16
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    20
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    23
 * questions.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    24
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    25
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    26
package apple.laf;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    27
31432
15d0fd22179a 8008803: [macosx] JVM crash in apple.laf.JRSUIUtils.HitDetection.getHitForPoint
serb
parents: 25859
diff changeset
    28
import java.security.AccessController;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    29
31432
15d0fd22179a 8008803: [macosx] JVM crash in apple.laf.JRSUIUtils.HitDetection.getHitForPoint
serb
parents: 25859
diff changeset
    30
import apple.laf.JRSUIConstants.Hit;
15d0fd22179a 8008803: [macosx] JVM crash in apple.laf.JRSUIUtils.HitDetection.getHitForPoint
serb
parents: 25859
diff changeset
    31
import apple.laf.JRSUIConstants.ScrollBarPart;
15d0fd22179a 8008803: [macosx] JVM crash in apple.laf.JRSUIUtils.HitDetection.getHitForPoint
serb
parents: 25859
diff changeset
    32
import com.apple.laf.AquaImageFactory.NineSliceMetrics;
23267
381cfe2f7c85 7155984: Security problems in regression test java/awt/PrintJob/Security/SecurityDialogTest.java
pchelko
parents: 12047
diff changeset
    33
import sun.security.action.GetPropertyAction;
381cfe2f7c85 7155984: Security problems in regression test java/awt/PrintJob/Security/SecurityDialogTest.java
pchelko
parents: 12047
diff changeset
    34
31432
15d0fd22179a 8008803: [macosx] JVM crash in apple.laf.JRSUIUtils.HitDetection.getHitForPoint
serb
parents: 25859
diff changeset
    35
public final class JRSUIUtils {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    36
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    37
    static boolean isLeopard = isMacOSXLeopard();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    38
    static boolean isSnowLeopardOrBelow = isMacOSXSnowLeopardOrBelow();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    39
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    40
    static boolean isMacOSXLeopard() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    41
        return isCurrentMacOSXVersion(5);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    42
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    43
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    44
    static boolean isMacOSXSnowLeopardOrBelow() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    45
        return currentMacOSXVersionMatchesGivenVersionRange(6, true, true, false);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    46
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    47
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    48
    static boolean isCurrentMacOSXVersion(final int version) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    49
        return currentMacOSXVersionMatchesGivenVersionRange(version, true, false, false);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    50
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    51
31432
15d0fd22179a 8008803: [macosx] JVM crash in apple.laf.JRSUIUtils.HitDetection.getHitForPoint
serb
parents: 25859
diff changeset
    52
    static boolean currentMacOSXVersionMatchesGivenVersionRange(
15d0fd22179a 8008803: [macosx] JVM crash in apple.laf.JRSUIUtils.HitDetection.getHitForPoint
serb
parents: 25859
diff changeset
    53
            final int version, final boolean inclusive,
15d0fd22179a 8008803: [macosx] JVM crash in apple.laf.JRSUIUtils.HitDetection.getHitForPoint
serb
parents: 25859
diff changeset
    54
            final boolean matchBelow, final boolean matchAbove) {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    55
        // split the "10.x.y" version number
23267
381cfe2f7c85 7155984: Security problems in regression test java/awt/PrintJob/Security/SecurityDialogTest.java
pchelko
parents: 12047
diff changeset
    56
        String osVersion = AccessController.doPrivileged(new GetPropertyAction("os.version"));
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    57
        String[] fragments = osVersion.split("\\.");
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    58
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    59
        // sanity check the "10." part of the version
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    60
        if (!fragments[0].equals("10")) return false;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    61
        if (fragments.length < 2) return false;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    62
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    63
        // check if os.version matches the given version using the given match method
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    64
        try {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    65
            int minorVers = Integer.parseInt(fragments[1]);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    66
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    67
            if (inclusive && minorVers == version) return true;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    68
            if (matchBelow && minorVers < version) return true;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    69
            if (matchAbove && minorVers > version) return true;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    70
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    71
        } catch (NumberFormatException e) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    72
            // was not an integer
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    73
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    74
        return false;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    75
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    76
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    77
    public static class TabbedPane {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    78
        public static boolean useLegacyTabs() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    79
            return isLeopard;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    80
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    81
        public static boolean shouldUseTabbedPaneContrastUI() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    82
            return !isSnowLeopardOrBelow;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    83
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    84
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    85
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    86
    public static class InternalFrame {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    87
        public static boolean shouldUseLegacyBorderMetrics() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    88
            return isSnowLeopardOrBelow;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    89
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    90
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    91
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    92
    public static class Tree {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    93
        public static boolean useLegacyTreeKnobs() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    94
            return isLeopard;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    95
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    96
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    97
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    98
    public static class ScrollBar {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    99
        private static native boolean shouldUseScrollToClick();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   100
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   101
        public static boolean useScrollToClick() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   102
            return shouldUseScrollToClick();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   103
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   104
31432
15d0fd22179a 8008803: [macosx] JVM crash in apple.laf.JRSUIUtils.HitDetection.getHitForPoint
serb
parents: 25859
diff changeset
   105
        public static void getPartBounds(final double[] rect,
15d0fd22179a 8008803: [macosx] JVM crash in apple.laf.JRSUIUtils.HitDetection.getHitForPoint
serb
parents: 25859
diff changeset
   106
                                         final JRSUIControl control,
15d0fd22179a 8008803: [macosx] JVM crash in apple.laf.JRSUIUtils.HitDetection.getHitForPoint
serb
parents: 25859
diff changeset
   107
                                         final int x, final int y, final int w,
15d0fd22179a 8008803: [macosx] JVM crash in apple.laf.JRSUIUtils.HitDetection.getHitForPoint
serb
parents: 25859
diff changeset
   108
                                         final int h,
15d0fd22179a 8008803: [macosx] JVM crash in apple.laf.JRSUIUtils.HitDetection.getHitForPoint
serb
parents: 25859
diff changeset
   109
                                         final ScrollBarPart part) {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   110
            control.getPartBounds(rect, x, y, w, h, part.ordinal);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   111
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   112
31432
15d0fd22179a 8008803: [macosx] JVM crash in apple.laf.JRSUIUtils.HitDetection.getHitForPoint
serb
parents: 25859
diff changeset
   113
        public static double getNativeOffsetChange(final JRSUIControl control,
15d0fd22179a 8008803: [macosx] JVM crash in apple.laf.JRSUIUtils.HitDetection.getHitForPoint
serb
parents: 25859
diff changeset
   114
                                                   final int x, final int y,
15d0fd22179a 8008803: [macosx] JVM crash in apple.laf.JRSUIUtils.HitDetection.getHitForPoint
serb
parents: 25859
diff changeset
   115
                                                   final int w, final int h,
15d0fd22179a 8008803: [macosx] JVM crash in apple.laf.JRSUIUtils.HitDetection.getHitForPoint
serb
parents: 25859
diff changeset
   116
                                                   final int offset,
15d0fd22179a 8008803: [macosx] JVM crash in apple.laf.JRSUIUtils.HitDetection.getHitForPoint
serb
parents: 25859
diff changeset
   117
                                                   final int visibleAmount,
15d0fd22179a 8008803: [macosx] JVM crash in apple.laf.JRSUIUtils.HitDetection.getHitForPoint
serb
parents: 25859
diff changeset
   118
                                                   final int extent) {
15d0fd22179a 8008803: [macosx] JVM crash in apple.laf.JRSUIUtils.HitDetection.getHitForPoint
serb
parents: 25859
diff changeset
   119
            return control.getScrollBarOffsetChange(x, y, w, h, offset,
15d0fd22179a 8008803: [macosx] JVM crash in apple.laf.JRSUIUtils.HitDetection.getHitForPoint
serb
parents: 25859
diff changeset
   120
                                                    visibleAmount, extent);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   121
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   122
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   123
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   124
    public static class Images {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   125
        public static boolean shouldUseLegacySecurityUIPath() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   126
            return isSnowLeopardOrBelow;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   127
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   128
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   129
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   130
    public static class HitDetection {
31432
15d0fd22179a 8008803: [macosx] JVM crash in apple.laf.JRSUIUtils.HitDetection.getHitForPoint
serb
parents: 25859
diff changeset
   131
        public static Hit getHitForPoint(final JRSUIControl control,
15d0fd22179a 8008803: [macosx] JVM crash in apple.laf.JRSUIUtils.HitDetection.getHitForPoint
serb
parents: 25859
diff changeset
   132
                                         final int x, final int y, final int w,
15d0fd22179a 8008803: [macosx] JVM crash in apple.laf.JRSUIUtils.HitDetection.getHitForPoint
serb
parents: 25859
diff changeset
   133
                                         final int h, final int hitX,
15d0fd22179a 8008803: [macosx] JVM crash in apple.laf.JRSUIUtils.HitDetection.getHitForPoint
serb
parents: 25859
diff changeset
   134
                                         final int hitY) {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   135
            return control.getHitForPoint(x, y, w, h, hitX, hitY);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   136
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   137
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   138
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   139
    public interface NineSliceMetricsProvider {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   140
        public NineSliceMetrics getNineSliceMetricsForState(JRSUIState state);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   141
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   142
}