Commit b0a5f940 authored by Gyuyoung Kim's avatar Gyuyoung Kim Committed by Commit Bot

Introduce ChooserResourceLoader in Blink's core/html/forms

This CL introduces ChooserResourceLoader class to replace
Platform::Current()->GetDataResource(name) with UncompressResourceAsString.

ChooserResourceLoader class supports static functions which return
a string of the given style sheet or javascript.

But, Android doesn't support IDR_FOO used by the choosers in
blink_resource.grd. So, this CL just returns String() because Android
port doesn't use the resources.

Bug: 983396
Change-Id: I2a836cc3868e2bccfd4da1449aee217396073438
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1714624Reviewed-by: default avatarKent Tamura <tkent@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Commit-Queue: Gyuyoung Kim <gyuyoung@igalia.com>
Cr-Commit-Position: refs/heads/master@{#684281}
parent 9b56db73
......@@ -482,30 +482,6 @@ const DataResource kDataResources[] = {
ui::SCALE_FACTOR_NONE, true},
{"DocumentXMLTreeViewer.js", IDR_DOCUMENTXMLTREEVIEWER_JS,
ui::SCALE_FACTOR_NONE, true},
#ifdef IDR_PICKER_COMMON_JS
{"pickerCommon.js", IDR_PICKER_COMMON_JS, ui::SCALE_FACTOR_NONE, true},
{"pickerCommon.css", IDR_PICKER_COMMON_CSS, ui::SCALE_FACTOR_NONE, true},
{"calendarPicker.js", IDR_CALENDAR_PICKER_JS, ui::SCALE_FACTOR_NONE, true},
{"calendarPicker.css", IDR_CALENDAR_PICKER_CSS, ui::SCALE_FACTOR_NONE,
true},
{"calendar_picker_refresh.css", IDR_CALENDAR_PICKER_REFRESH_CSS,
ui::SCALE_FACTOR_NONE, true},
{"listPicker.js", IDR_LIST_PICKER_JS, ui::SCALE_FACTOR_NONE, true},
{"listPicker.css", IDR_LIST_PICKER_CSS, ui::SCALE_FACTOR_NONE, true},
{"pickerButton.css", IDR_PICKER_BUTTON_CSS, ui::SCALE_FACTOR_NONE, true},
{"suggestionPicker.js", IDR_SUGGESTION_PICKER_JS, ui::SCALE_FACTOR_NONE,
true},
{"suggestionPicker.css", IDR_SUGGESTION_PICKER_CSS, ui::SCALE_FACTOR_NONE,
true},
{"color_picker_common.js", IDR_COLOR_PICKER_COMMON_JS,
ui::SCALE_FACTOR_NONE, true},
{"colorSuggestionPicker.js", IDR_COLOR_SUGGESTION_PICKER_JS,
ui::SCALE_FACTOR_NONE, true},
{"colorSuggestionPicker.css", IDR_COLOR_SUGGESTION_PICKER_CSS,
ui::SCALE_FACTOR_NONE, true},
{"color_picker.js", IDR_COLOR_PICKER_JS, ui::SCALE_FACTOR_NONE, true},
{"color_picker.css", IDR_COLOR_PICKER_CSS, ui::SCALE_FACTOR_NONE, true},
#endif
{"input_alert.svg", IDR_VALIDATION_BUBBLE_ICON, ui::SCALE_FACTOR_NONE,
true},
{"validation_bubble.css", IDR_VALIDATION_BUBBLE_CSS, ui::SCALE_FACTOR_NONE,
......
......@@ -121,6 +121,8 @@ blink_core_sources("html") {
"forms/checkbox_input_type.h",
"forms/chooser_only_temporal_input_type_view.cc",
"forms/chooser_only_temporal_input_type_view.h",
"forms/chooser_resource_loader.cc",
"forms/chooser_resource_loader.h",
"forms/clear_button_element.cc",
"forms/clear_button_element.h",
"forms/color_chooser.cc",
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "third_party/blink/renderer/core/html/forms/chooser_resource_loader.h"
#include "build/build_config.h"
#include "third_party/blink/public/resources/grit/blink_resources.h"
#include "third_party/blink/renderer/platform/data_resource_helper.h"
namespace blink {
String ChooserResourceLoader::GetSuggestionPickerStyleSheet() {
#if !defined(OS_ANDROID)
return UncompressResourceAsString(IDR_SUGGESTION_PICKER_CSS);
#else
NOTREACHED();
return String();
#endif
}
String ChooserResourceLoader::GetSuggestionPickerJS() {
#if !defined(OS_ANDROID)
return UncompressResourceAsString(IDR_SUGGESTION_PICKER_JS);
#else
NOTREACHED();
return String();
#endif
}
String ChooserResourceLoader::GetPickerButtonStyleSheet() {
#if !defined(OS_ANDROID)
return UncompressResourceAsString(IDR_PICKER_BUTTON_CSS);
#else
NOTREACHED();
return String();
#endif
}
String ChooserResourceLoader::GetPickerCommonStyleSheet() {
#if !defined(OS_ANDROID)
return UncompressResourceAsString(IDR_PICKER_COMMON_CSS);
#else
NOTREACHED();
return String();
#endif
}
String ChooserResourceLoader::GetPickerCommonJS() {
#if !defined(OS_ANDROID)
return UncompressResourceAsString(IDR_PICKER_COMMON_JS);
#else
NOTREACHED();
return String();
#endif
}
String ChooserResourceLoader::GetCalendarPickerStyleSheet() {
#if !defined(OS_ANDROID)
return UncompressResourceAsString(IDR_CALENDAR_PICKER_CSS);
#else
NOTREACHED();
return String();
#endif
}
String ChooserResourceLoader::GetCalendarPickerJS() {
#if !defined(OS_ANDROID)
return UncompressResourceAsString(IDR_CALENDAR_PICKER_JS);
#else
NOTREACHED();
return String();
#endif
}
String ChooserResourceLoader::GetColorSuggestionPickerStyleSheet() {
#if !defined(OS_ANDROID)
return UncompressResourceAsString(IDR_COLOR_SUGGESTION_PICKER_CSS);
#else
NOTREACHED();
return String();
#endif
}
String ChooserResourceLoader::GetColorSuggestionPickerJS() {
#if !defined(OS_ANDROID)
return UncompressResourceAsString(IDR_COLOR_SUGGESTION_PICKER_JS);
#else
NOTREACHED();
return String();
#endif
}
String ChooserResourceLoader::GetColorPickerStyleSheet() {
#if !defined(OS_ANDROID)
return UncompressResourceAsString(IDR_COLOR_PICKER_CSS);
#else
NOTREACHED();
return String();
#endif
}
String ChooserResourceLoader::GetCalendarPickerRefreshStyleSheet() {
#if !defined(OS_ANDROID)
return UncompressResourceAsString(IDR_CALENDAR_PICKER_REFRESH_CSS);
#else
NOTREACHED();
return String();
#endif
}
String ChooserResourceLoader::GetColorPickerJS() {
#if !defined(OS_ANDROID)
return UncompressResourceAsString(IDR_COLOR_PICKER_JS);
#else
NOTREACHED();
return String();
#endif
}
String ChooserResourceLoader::GetColorPickerCommonJS() {
#if !defined(OS_ANDROID)
return UncompressResourceAsString(IDR_COLOR_PICKER_COMMON_JS);
#else
NOTREACHED();
return String();
#endif
}
String ChooserResourceLoader::GetListPickerStyleSheet() {
#if !defined(OS_ANDROID)
return UncompressResourceAsString(IDR_LIST_PICKER_CSS);
#else
NOTREACHED();
return String();
#endif
}
String ChooserResourceLoader::GetListPickerJS() {
#if !defined(OS_ANDROID)
return UncompressResourceAsString(IDR_LIST_PICKER_JS);
#else
NOTREACHED();
return String();
#endif
}
} // namespace blink
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_HTML_FORMS_CHOOSER_RESOURCE_LOADER_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_HTML_FORMS_CHOOSER_RESOURCE_LOADER_H_
#include "third_party/blink/renderer/platform/wtf/allocator/allocator.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
namespace blink {
class ChooserResourceLoader {
STATIC_ONLY(ChooserResourceLoader);
public:
// Returns the picker common stylesheet as a string.
static String GetPickerCommonStyleSheet();
// Returns the picker common javascript as a string.
static String GetPickerCommonJS();
// Returns the picker button stylesheet as a string.
static String GetPickerButtonStyleSheet();
// Returns the suggestion picker stylesheet as a string.
static String GetSuggestionPickerStyleSheet();
// Returns the suggestion picker javascript as a string.
static String GetSuggestionPickerJS();
// Returns the suggestion picker stylesheet as a string.
static String GetCalendarPickerStyleSheet();
// Returns the calendar picker refresh stylesheet as a string.
static String GetCalendarPickerRefreshStyleSheet();
// Returns the suggestion picker javascript as a string.
static String GetCalendarPickerJS();
// Returns the color suggestion picker stylesheet as a string.
static String GetColorSuggestionPickerStyleSheet();
// Returns the color suggestion picker javascript as a string.
static String GetColorSuggestionPickerJS();
// Returns the color picker stylesheet as a string.
static String GetColorPickerStyleSheet();
// Returns the color picker javascript as a string.
static String GetColorPickerJS();
// Returns the color picker common javascript as a string.
static String GetColorPickerCommonJS();
// Returns the list picker stylesheet as a string.
static String GetListPickerStyleSheet();
// Returns the list picker javascript as a string.
static String GetListPickerJS();
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_CORE_HTML_FORMS_CHOOSER_RESOURCE_LOADER_H_
......@@ -28,6 +28,7 @@
#include "third_party/blink/public/platform/platform.h"
#include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/frame/local_frame_view.h"
#include "third_party/blink/renderer/core/html/forms/chooser_resource_loader.h"
#include "third_party/blink/renderer/core/html/forms/color_chooser_client.h"
#include "third_party/blink/renderer/core/page/chrome_client.h"
#include "third_party/blink/renderer/core/page/page_popup.h"
......@@ -98,8 +99,9 @@ void ColorChooserPopupUIController::WriteColorPickerDocument(
PagePopupClient::AddString(
"<!DOCTYPE html><head><meta charset='UTF-8'><style>\n", data);
data->Append(Platform::Current()->GetDataResource("pickerCommon.css"));
data->Append(Platform::Current()->GetDataResource("color_picker.css"));
AddString(ChooserResourceLoader::GetPickerCommonStyleSheet(), data);
AddString(ChooserResourceLoader::GetColorPickerStyleSheet(), data);
PagePopupClient::AddString(
"</style></head><body>\n"
"<div id='main'>Loading...</div><script>\n"
......@@ -111,9 +113,9 @@ void ColorChooserPopupUIController::WriteColorPickerDocument(
AddProperty("zoomFactor", ZoomFactor(), data);
AddProperty("shouldShowColorSuggestionPicker", false, data);
PagePopupClient::AddString("};\n", data);
data->Append(Platform::Current()->GetDataResource("pickerCommon.js"));
data->Append(Platform::Current()->GetDataResource("color_picker.js"));
data->Append(Platform::Current()->GetDataResource("color_picker_common.js"));
AddString(ChooserResourceLoader::GetPickerCommonJS(), data);
AddString(ChooserResourceLoader::GetColorPickerJS(), data);
AddString(ChooserResourceLoader::GetColorPickerCommonJS(), data);
PagePopupClient::AddString("</script></body>\n", data);
}
......@@ -129,12 +131,11 @@ void ColorChooserPopupUIController::WriteColorSuggestionPickerDocument(
PagePopupClient::AddString(
"<!DOCTYPE html><head><meta charset='UTF-8'><style>\n", data);
data->Append(Platform::Current()->GetDataResource("pickerCommon.css"));
data->Append(
Platform::Current()->GetDataResource("colorSuggestionPicker.css"));
if (RuntimeEnabledFeatures::FormControlsRefreshEnabled()) {
data->Append(Platform::Current()->GetDataResource("color_picker.css"));
}
AddString(ChooserResourceLoader::GetPickerCommonStyleSheet(), data);
AddString(ChooserResourceLoader::GetColorSuggestionPickerStyleSheet(), data);
if (RuntimeEnabledFeatures::FormControlsRefreshEnabled())
AddString(ChooserResourceLoader::GetColorPickerStyleSheet(), data);
PagePopupClient::AddString(
"</style></head><body>\n"
"<div id='main'>Loading...</div><script>\n"
......@@ -154,13 +155,11 @@ void ColorChooserPopupUIController::WriteColorSuggestionPickerDocument(
AddProperty("isFormControlsRefreshEnabled",
RuntimeEnabledFeatures::FormControlsRefreshEnabled(), data);
PagePopupClient::AddString("};\n", data);
data->Append(Platform::Current()->GetDataResource("pickerCommon.js"));
data->Append(
Platform::Current()->GetDataResource("colorSuggestionPicker.js"));
if (RuntimeEnabledFeatures::FormControlsRefreshEnabled()) {
data->Append(Platform::Current()->GetDataResource("color_picker.js"));
}
data->Append(Platform::Current()->GetDataResource("color_picker_common.js"));
AddString(ChooserResourceLoader::GetPickerCommonJS(), data);
AddString(ChooserResourceLoader::GetColorSuggestionPickerJS(), data);
if (RuntimeEnabledFeatures::FormControlsRefreshEnabled())
AddString(ChooserResourceLoader::GetColorPickerJS(), data);
AddString(ChooserResourceLoader::GetColorPickerCommonJS(), data);
PagePopupClient::AddString("</script></body>\n", data);
}
......
......@@ -33,6 +33,7 @@
#include "third_party/blink/public/mojom/choosers/date_time_chooser.mojom-blink.h"
#include "third_party/blink/public/platform/platform.h"
#include "third_party/blink/renderer/core/frame/local_frame_view.h"
#include "third_party/blink/renderer/core/html/forms/chooser_resource_loader.h"
#include "third_party/blink/renderer/core/html/forms/date_time_chooser_client.h"
#include "third_party/blink/renderer/core/input_type_names.h"
#include "third_party/blink/renderer/core/layout/layout_theme.h"
......@@ -120,15 +121,15 @@ void DateTimeChooserImpl::WriteDocument(SharedBuffer* data) {
}
AddString("<!DOCTYPE html><head><meta charset='UTF-8'><style>\n", data);
data->Append(Platform::Current()->GetDataResource("pickerCommon.css"));
if (!RuntimeEnabledFeatures::FormControlsRefreshEnabled()) {
data->Append(Platform::Current()->GetDataResource("pickerButton.css"));
}
data->Append(Platform::Current()->GetDataResource("suggestionPicker.css"));
data->Append(Platform::Current()->GetDataResource("calendarPicker.css"));
AddString(ChooserResourceLoader::GetPickerCommonStyleSheet(), data);
if (!RuntimeEnabledFeatures::FormControlsRefreshEnabled())
AddString(ChooserResourceLoader::GetPickerButtonStyleSheet(), data);
AddString(ChooserResourceLoader::GetSuggestionPickerStyleSheet(), data);
AddString(ChooserResourceLoader::GetCalendarPickerStyleSheet(), data);
if (RuntimeEnabledFeatures::FormControlsRefreshEnabled()) {
data->Append(
Platform::Current()->GetDataResource("calendar_picker_refresh.css"));
AddString(ChooserResourceLoader::GetCalendarPickerRefreshStyleSheet(),
data);
}
AddString(
"</style></head><body><div id=main>Loading...</div><script>\n"
......@@ -214,9 +215,9 @@ void DateTimeChooserImpl::WriteDocument(SharedBuffer* data) {
}
AddString("}\n", data);
data->Append(Platform::Current()->GetDataResource("pickerCommon.js"));
data->Append(Platform::Current()->GetDataResource("suggestionPicker.js"));
data->Append(Platform::Current()->GetDataResource("calendarPicker.js"));
AddString(ChooserResourceLoader::GetPickerCommonJS(), data);
AddString(ChooserResourceLoader::GetSuggestionPickerJS(), data);
AddString(ChooserResourceLoader::GetCalendarPickerJS(), data);
AddString("</script></body>\n", data);
}
......
......@@ -16,6 +16,7 @@
#include "third_party/blink/renderer/core/exported/web_view_impl.h"
#include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/frame/local_frame_view.h"
#include "third_party/blink/renderer/core/html/forms/chooser_resource_loader.h"
#include "third_party/blink/renderer/core/html/forms/html_opt_group_element.h"
#include "third_party/blink/renderer/core/html/forms/html_option_element.h"
#include "third_party/blink/renderer/core/html/forms/html_select_element.h"
......@@ -232,8 +233,8 @@ void InternalPopupMenu::WriteDocument(SharedBuffer* data) {
float scale_factor = chrome_client_->WindowToViewportScalar(1.f);
PagePopupClient::AddString(
"<!DOCTYPE html><head><meta charset='UTF-8'><style>\n", data);
data->Append(Platform::Current()->GetDataResource("pickerCommon.css"));
data->Append(Platform::Current()->GetDataResource("listPicker.css"));
AddString(ChooserResourceLoader::GetPickerCommonStyleSheet(), data);
AddString(ChooserResourceLoader::GetListPickerStyleSheet(), data);
if (!RuntimeEnabledFeatures::ForceTallerSelectPopupEnabled())
PagePopupClient::AddString("@media (any-pointer:coarse) {", data);
int padding = static_cast<int>(roundf(4 * scale_factor));
......@@ -288,8 +289,9 @@ void InternalPopupMenu::WriteDocument(SharedBuffer* data) {
: owner_element.ClientPaddingLeft().ToDouble(),
data);
PagePopupClient::AddString("};\n", data);
data->Append(Platform::Current()->GetDataResource("pickerCommon.js"));
data->Append(Platform::Current()->GetDataResource("listPicker.js"));
AddString(ChooserResourceLoader::GetPickerCommonJS(), data);
AddString(ChooserResourceLoader::GetListPickerJS(), data);
PagePopupClient::AddString("</script></body>\n", data);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment