0

[ios] Expose text_zoom API as free function

Add two free functions exposing the `text_zoom` API with the goal
to replace `TextZoomProvider` class. Do not convert the code to use
the function as they have no internal implementation yet.

Bug: 1201182
Change-Id: Ib9a667dfb922e3fe86aa5c9c36b94da39dd9eefe
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3024085
Reviewed-by: Olivier Robin <olivierrobin@chromium.org>
Commit-Queue: Sylvain Defresne <sdefresne@chromium.org>
Cr-Commit-Position: refs/heads/master@{#901028}
This commit is contained in:
Sylvain Defresne
2021-07-13 15:48:49 +00:00
committed by Chromium LUCI CQ
parent 3ddae3a587
commit f087c0a01a
8 changed files with 113 additions and 1 deletions
ios
chrome
browser
public
web
public
js_messaging

@ -53,6 +53,7 @@ group("chromium_providers") {
# The individual API implementations.
"//ios/chrome/browser/providers/modals:chromium_modals",
"//ios/chrome/browser/providers/text_zoom:chromium_text_zoom",
# The provider API needs to provide MaterialDesignComponent API (as the
# internal provider provides an alternate implementation).

@ -0,0 +1,14 @@
# Copyright 2021 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.
source_set("chromium_text_zoom") {
configs += [ "//build/config/compiler:enable_arc" ]
sources = [ "chromium_text_zoom.mm" ]
deps = [
"//ios/chrome/browser/web:feature_flags",
"//ios/public/provider/chrome/browser:font_size_java_script_feature",
"//ios/public/provider/chrome/browser/text_zoom:text_zoom_api",
"//ui/base",
]
}

@ -0,0 +1,27 @@
// Copyright 2021 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 "ios/chrome/browser/web/features.h"
#import "ios/public/provider/chrome/browser/font_size_java_script_feature.h"
#import "ios/public/provider/chrome/browser/text_zoom/text_zoom_api.h"
#include "ui/base/device_form_factor.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace ios {
namespace provider {
void SetTextZoomForWebState(web::WebState* web_state, int size) {
FontSizeJavaScriptFeature::GetInstance()->AdjustFontSize(web_state, size);
}
bool IsTextZoomEnabled() {
return ui::GetDeviceFormFactor() != ui::DEVICE_FORM_FACTOR_TABLET &&
base::FeatureList::IsEnabled(web::kWebPageTextAccessibility);
}
} // namespace provider
} // namespace ios

@ -38,14 +38,15 @@ source_set("font_size_java_script_feature") {
deps = [
"//base",
"//ios/web/public",
"//ios/web/public/js_messaging",
]
public_deps = [ "//ios/web/public/js_messaging" ]
}
group("provider_api") {
deps = [
# The individual APIs.
"//ios/public/provider/chrome/browser/modals:modals_api",
"//ios/public/provider/chrome/browser/text_zoom:text_zoom_api",
]
}
@ -95,6 +96,7 @@ group("test_providers") {
# The individual API implementations.
"//ios/public/provider/chrome/browser/modals:test_modals",
"//ios/public/provider/chrome/browser/text_zoom:test_text_zoom",
# The provider API needs to provide MaterialDesignComponent API (as the
# internal provider provides an alternate implementation).

@ -0,0 +1,18 @@
# Copyright 2021 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.
source_set("text_zoom_api") {
configs += [ "//build/config/compiler:enable_arc" ]
sources = [ "text_zoom_api.h" ]
}
source_set("test_text_zoom") {
testonly = true
configs += [ "//build/config/compiler:enable_arc" ]
sources = [ "test_text_zoom.mm" ]
deps = [
":text_zoom_api",
"//ios/public/provider/chrome/browser:font_size_java_script_feature",
]
}

@ -0,0 +1,24 @@
// Copyright 2021 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.
#import "ios/public/provider/chrome/browser/font_size_java_script_feature.h"
#import "ios/public/provider/chrome/browser/text_zoom/text_zoom_api.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace ios {
namespace provider {
void SetTextZoomForWebState(web::WebState* web_state, int size) {
FontSizeJavaScriptFeature::GetInstance()->AdjustFontSize(web_state, size);
}
bool IsTextZoomEnabled() {
return true;
}
} // namespace provider
} // namespace ios

@ -0,0 +1,25 @@
// Copyright 2021 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 IOS_PUBLIC_PROVIDER_CHROME_BROWSER_TEXT_ZOOM_TEXT_ZOOM_API_H_
#define IOS_PUBLIC_PROVIDER_CHROME_BROWSER_TEXT_ZOOM_TEXT_ZOOM_API_H_
namespace web {
class WebState;
} // namespace web
namespace ios {
namespace provider {
// Zooms the given web_state to the provided size as a percentage. I.e. a size
// of 100 corresponds to a zoom of 100%.
void SetTextZoomForWebState(web::WebState* web_state, int size);
// Returns whether text zoom is enabled currently.
bool IsTextZoomEnabled();
} // namespace provider
} // namespace ios
#endif // IOS_PUBLIC_PROVIDER_CHROME_BROWSER_TEXT_ZOOM_TEXT_ZOOM_API_H_

@ -8,6 +8,7 @@ source_set("js_messaging") {
"//ios/web/public/",
"//url",
]
public_deps = [ "//third_party/abseil-cpp:absl" ]
sources = [
"java_script_feature.h",