Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion java/org/cef/CefSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,14 @@ public class ColorType {
private ColorType() {}

public ColorType(int alpha, int red, int green, int blue) {
color_value = (alpha << 24) | (red << 16) | (green << 8) | (blue << 0);
// Pack in long-typed arithmetic and mask to 32 bits -- packing in
// int arithmetic first (as this used to) sign-extends into the
// long's upper 32 bits whenever alpha >= 0x80 (the sign bit of
// the intermediate 32-bit result), instead of the plain unsigned
// 32-bit ARGB value this field's own Javadoc describes. See
// Thrameos/java-cef#8.
color_value = ((long) alpha << 24 | (long) red << 16 | (long) green << 8 | blue)
& 0xFFFFFFFFL;
}

public long getColor() {
Expand Down
27 changes: 27 additions & 0 deletions java/tests/junittests/CefSettingsTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (c) 2026 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.

package tests.junittests;

import static org.junit.jupiter.api.Assertions.assertEquals;

import org.cef.CefSettings;
import org.junit.jupiter.api.Test;

// Plain Java value object -- no CEF native lifecycle involved.
class CefSettingsTest {
@Test
void colorTypeHighAlphaDoesNotSignExtend() {
CefSettings settings = new CefSettings();
CefSettings.ColorType color = settings.new ColorType(0xFF, 0x11, 0x22, 0x33);
assertEquals(0xFF112233L, color.getColor());
}

@Test
void colorTypeLowAlpha() {
CefSettings settings = new CefSettings();
CefSettings.ColorType color = settings.new ColorType(0x7F, 0x11, 0x22, 0x33);
assertEquals(0x7F112233L, color.getColor());
}
}
Loading