Skip to content

Commit

Permalink
8313181: Enabling modern media controls on webkit 616.1 does not load…
Browse files Browse the repository at this point in the history
… button images on HTML5 video Element

Reviewed-by: kcr, hmeda
  • Loading branch information
Jay Bhaskar committed Aug 9, 2023
1 parent 9f180e2 commit 5d74176
Show file tree
Hide file tree
Showing 12 changed files with 278 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,6 @@
#endif

/* FIXME: This is used to "turn on a specific feature of WebKit", so should be converted to an ENABLE macro. */
#if (PLATFORM(COCOA) || PLATFORM(GTK) || PLATFORM(WPE)) && ENABLE(ACCESSIBILITY)
#if (PLATFORM(COCOA) || PLATFORM(GTK) || PLATFORM(JAVA) || PLATFORM(WPE)) && ENABLE(ACCESSIBILITY)
#define USE_ACCESSIBILITY_CONTEXT_MENUS 1
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ String MediaControlsHost::layoutTraitsClassName() const
return "IOSLayoutTraits"_s;
#elif PLATFORM(WATCHOS)
return "WatchOSLayoutTraits"_s;
#elif PLATFORM(GTK) || PLATFORM(WPE) || PLATFORM(WIN_CAIRO)
#elif PLATFORM(GTK) || PLATFORM(WPE) || PLATFORM(WIN_CAIRO) || PLATFORM(JAVA)
return "AdwaitaLayoutTraits"_s;
#else
ASSERT_NOT_REACHED();
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ platform/java/PluginInfoStoreJava.cpp
platform/java/PluginViewJava.cpp
platform/java/PluginWidgetJava.cpp
platform/java/RenderThemeJava.cpp
platform/java/ModernMediaControlResource.cpp
platform/java/ScrollbarThemeJava.cpp
platform/java/SharedBufferJava.cpp
platform/java/MainThreadSharedTimerJava.cpp
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

#pragma once

#include <map>
#include <string>
#include <wtf/text/WTFString.h>
#include <wtf/HashMap.h>

class MediaControlResource {
public:
virtual String getValue(const String &key) = 0;
virtual ~MediaControlResource() { }
};

class ModernMediaControlResource : public MediaControlResource {
private:
HashMap<String, String> imageMap;
public:
ModernMediaControlResource();
String getValue(const String &resource_key) override;
};

// Factory for creating MediaControlResource objects
class MediaControlResourceFactory {
public:
static std::unique_ptr<MediaControlResource> createResource() {
return std::make_unique<ModernMediaControlResource>();
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ RenderTheme& RenderTheme::singleton()
return sm_defaultInstance;
}

RenderThemeJava::RenderThemeJava()
RenderThemeJava::RenderThemeJava() : mediaResource(MediaControlResourceFactory::createResource())
{
}

Expand Down Expand Up @@ -494,8 +494,7 @@ Vector<String, 2> RenderThemeJava::mediaControlsScripts()

String RenderThemeJava::extraMediaControlsStyleSheet()
{

return String(ModernMediaControlsUserAgentStyleSheet, sizeof(ModernMediaControlsUserAgentStyleSheet));
return emptyString();

}

Expand Down Expand Up @@ -553,7 +552,15 @@ bool RenderThemeJava::paintMediaControl(jint type, const RenderObject&, const Pa
return true;
}

String RenderThemeJava::mediaControlsStyleSheet()
{
return String(ModernMediaControlsUserAgentStyleSheet, sizeof(ModernMediaControlsUserAgentStyleSheet));
}

String RenderThemeJava::mediaControlsBase64StringForIconNameAndType(const String& iconName, const String& iconType)
{
return mediaResource->getValue(iconName);
}
#undef JNI_EXPAND_MEDIA

#endif // ENABLE(VIDEO)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#pragma once

#include "RenderTheme.h"
#include "ModernMediaControlResource.h"
#include "GraphicsContext.h"
#include "StyleResolver.h"

Expand Down Expand Up @@ -107,7 +108,8 @@ class RenderThemeJava final : public RenderTheme {

void adjustSliderTrackStyle(RenderStyle&, const Element*) const override;
bool paintSliderTrack(const RenderObject&, const PaintInfo&, const IntRect&) override;

String mediaControlsBase64StringForIconNameAndType(const String&, const String&);
String mediaControlsStyleSheet();

private:
int createWidgetState(const RenderObject& o);
Expand All @@ -116,6 +118,7 @@ class RenderThemeJava final : public RenderTheme {
bool paintWidget(int widgetIndex, const RenderObject& o,
const PaintInfo& i, const FloatRect& rect);
Color getSelectionColor(int index) const;
std::unique_ptr<MediaControlResource> mediaResource;
#if ENABLE(VIDEO)
bool paintMediaControl(jint type, const RenderObject&, const PaintInfo&, const IntRect&);
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_PUBLIC_SUFFIX_LIST PRIVATE OFF)
WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_FTL_JIT PUBLIC OFF)
WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_WEBASSEMBLY PRIVATE OFF)
WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_MODERN_MEDIA_CONTROLS PRIVATE ON)
WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_MEDIA_CONTROLS_CONTEXT_MENUS PRIVATE ON)
WEBKIT_OPTION_DEFAULT_PORT_VALUE(USE_AVIF PRIVATE OFF)


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!/usr/bin/env python3

'''
/*
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
'''
'''
Tool to generate base64 code
'''
import os
import base64
import sys

class ImageProcessor:
def __init__(self, directory_path):
self.directory_path = directory_path

def read_images(self):
image_data = {}
for filename in os.listdir(self.directory_path):
if filename.lower().endswith(('.png', '.svg')):
with open(os.path.join(self.directory_path, filename), 'rb') as image_file:
image_data[filename] = image_file.read()
return image_data

def generate_base64(self, image_data):
base64_images = {}
for filename, data in image_data.items():
base64_images[filename] = base64.b64encode(data).decode('utf-8')
return base64_images

if __name__ == "__main__":
if len(sys.argv) != 2:
print("Usage: python script_name.py directory_path")
sys.exit(1)

image_directory = sys.argv[1]

if not os.path.isdir(image_directory):
print("Invalid directory path.")
sys.exit(1)

image_processor = ImageProcessor(image_directory)

images = image_processor.read_images()
base64_images = image_processor.generate_base64(images)
size_of_list = len(images)
print("imageMap = {")
for filename, base64_code in base64_images.items():
file_name_without_extension = os.path.splitext(filename)[0]
print("{"+file_name_without_extension +"_s, " + base64_code + "_s},")
print("};")
73 changes: 73 additions & 0 deletions tests/manual/web/HTML5VideoControlTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.VBox;
import javafx.scene.web.WebView;
import javafx.stage.Stage;

public class HTML5VideoControlTest extends Application {
@Override
public void start(Stage primaryStage) {
WebView webView = new WebView();
webView.getEngine().loadContent(
"<video width=\"320\" height=\"240\" controls>\n" +
" <source src=\"https://download.oracle.com/otndocs/products/javafx/oow2010-2.mp4\">\n" +
" Your browser does not support the video tag.\n" +
"</video>"
);

VBox root = new VBox();
root.setSpacing(20);

root.getChildren().addAll(createInstructionsBox(), webView);

Scene scene = new Scene(root, 800, 400);
primaryStage.setScene(scene);
primaryStage.setTitle("HTML5 Video Player with Instructions");
primaryStage.show();
}

private VBox createInstructionsBox() {
VBox instructionsBox = new VBox();
instructionsBox.setStyle("-fx-background-color: #f0f0f0;");
instructionsBox.setPrefWidth(400);

instructionsBox.getChildren().addAll(
new Label("Instructions:"),
new Label("1. Click 'Play' to start the video."),
new Label("2. The media controls should be visible once the video starts playing."),
new Label("3. Use the media controls to play/pause/seek the video.")
);

return instructionsBox;
}

public static void main(String[] args) {
launch(args);
}
}

3 comments on commit 5d74176

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

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

@kevinrushforth
Copy link
Member

Choose a reason for hiding this comment

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

/tag 22+4

@openjdk
Copy link

@openjdk openjdk bot commented on 5d74176 Aug 10, 2023

Choose a reason for hiding this comment

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

@kevinrushforth The tag 22+4 was successfully created.

Please sign in to comment.