Add WebContentObserver::SafeAreaConstraintChanged
Add the method to be integrated once crrev.com/c/6107457 lands. Bug: 385221500 Change-Id: I879c765e9835bda414be2fbb3b8e0f6ed0c50e7e Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6115531 Reviewed-by: Charles Hager <clhager@google.com> Reviewed-by: Avi Drissman <avi@chromium.org> Commit-Queue: Wenyu Fu <wenyufu@chromium.org> Code-Coverage: findit-for-me@appspot.gserviceaccount.com <findit-for-me@appspot.gserviceaccount.com> Cr-Commit-Position: refs/heads/main@{#1400528}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
02c2fa2785
commit
29b3bb7aaf
chrome/android/java/src/org/chromium/chrome/browser/tab
content
browser
android
display_cutout
web_contents
public
android
java
src
org
chromium
browser
@ -359,13 +359,19 @@ public class TabWebContentsObserver extends TabWebContentsUserData {
|
||||
@Override
|
||||
public void viewportFitChanged(@WebContentsObserver.ViewportFitType int value) {
|
||||
DisplayCutoutTabHelper.from(mTab).setViewportFit(value);
|
||||
// TODO(wenyufu): Create a setSafeAreaConstraint method.
|
||||
if (ChromeFeatureList.sEdgeToEdgeSafeAreaConstraint.isEnabled()) {
|
||||
DisplayCutoutTabHelper.from(mTab)
|
||||
.setSafeAreaConstraint(value == ViewportFit.CONTAIN);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void safeAreaConstraintChanged(boolean hasConstraint) {
|
||||
if (ChromeFeatureList.sEdgeToEdgeSafeAreaConstraint.isEnabled()) {
|
||||
DisplayCutoutTabHelper.from(mTab).setSafeAreaConstraint(hasConstraint);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void virtualKeyboardModeChanged(@VirtualKeyboardMode.EnumType int mode) {
|
||||
RewindableIterator<TabObserver> observers = mTab.getTabObservers();
|
||||
|
@ -318,6 +318,12 @@ void WebContentsObserverProxy::ViewportFitChanged(
|
||||
env, java_observer_, as_jint(static_cast<int>(value)));
|
||||
}
|
||||
|
||||
void WebContentsObserverProxy::SafeAreaConstraintChanged(bool has_constraint) {
|
||||
JNIEnv* env = AttachCurrentThread();
|
||||
Java_WebContentsObserverProxy_safeAreaConstraintChanged(env, java_observer_,
|
||||
has_constraint);
|
||||
}
|
||||
|
||||
void WebContentsObserverProxy::VirtualKeyboardModeChanged(
|
||||
ui::mojom::VirtualKeyboardMode mode) {
|
||||
JNIEnv* env = AttachCurrentThread();
|
||||
|
@ -77,6 +77,7 @@ class WebContentsObserverProxy : public WebContentsObserver {
|
||||
bool will_cause_resize) override;
|
||||
bool SetToBaseURLForDataURLIfNeeded(GURL* url);
|
||||
void ViewportFitChanged(blink::mojom::ViewportFit value) override;
|
||||
void SafeAreaConstraintChanged(bool has_constriant) override;
|
||||
void VirtualKeyboardModeChanged(ui::mojom::VirtualKeyboardMode mode) override;
|
||||
void OnWebContentsFocused(RenderWidgetHost*) override;
|
||||
void OnWebContentsLostFocus(RenderWidgetHost*) override;
|
||||
|
@ -70,6 +70,10 @@ class CONTENT_EXPORT SafeAreaInsetsHost
|
||||
// Protected and virtual for testing only.
|
||||
virtual void SendSafeAreaToFrame(RenderFrameHost* rfh, gfx::Insets insets);
|
||||
|
||||
// Notified that the complex safe-area-inset constraint state changed.
|
||||
virtual void ComplexSafeAreaConstraintChangedForFrame(RenderFrameHost* rfh,
|
||||
bool has_constraint) {}
|
||||
|
||||
// Weak pointer to the owning `WebContentsImpl` instance.
|
||||
raw_ptr<WebContentsImpl> web_contents_impl_;
|
||||
|
||||
|
@ -103,6 +103,13 @@ void SafeAreaInsetsHostImpl::ViewportFitChangedForFrame(
|
||||
}
|
||||
}
|
||||
|
||||
void SafeAreaInsetsHostImpl::ComplexSafeAreaConstraintChangedForFrame(
|
||||
RenderFrameHost* rfh,
|
||||
bool has_constraint) {
|
||||
DCHECK(rfh);
|
||||
web_contents_impl_->NotifySafeAreaConstraintChanged(has_constraint);
|
||||
}
|
||||
|
||||
void SafeAreaInsetsHostImpl::MaybeActiveRenderFrameHostChanged() {
|
||||
base::WeakPtr<RenderFrameHostImpl> new_active_rfh =
|
||||
fullscreen_rfh_ ? fullscreen_rfh_ : current_rfh_;
|
||||
|
@ -59,6 +59,8 @@ class CONTENT_EXPORT SafeAreaInsetsHostImpl : public SafeAreaInsetsHost {
|
||||
// SafeAreaInsetsHost override.
|
||||
void ViewportFitChangedForFrame(RenderFrameHost* rfh,
|
||||
blink::mojom::ViewportFit value) override;
|
||||
void ComplexSafeAreaConstraintChangedForFrame(RenderFrameHost* rfh,
|
||||
bool has_constraint) override;
|
||||
|
||||
// Get the stored viewport fit value for a frame or kAuto if there is no
|
||||
// stored value.
|
||||
|
@ -2213,6 +2213,14 @@ void WebContentsImpl::NotifyViewportFitChanged(
|
||||
observers_.NotifyObservers(&WebContentsObserver::ViewportFitChanged, value);
|
||||
}
|
||||
|
||||
void WebContentsImpl::NotifySafeAreaConstraintChanged(bool has_constraint) {
|
||||
OPTIONAL_TRACE_EVENT1("content",
|
||||
"WebContentsImpl::NotifySafeAreaConstraintChanged",
|
||||
"has_constraint", has_constraint);
|
||||
observers_.NotifyObservers(&WebContentsObserver::SafeAreaConstraintChanged,
|
||||
has_constraint);
|
||||
}
|
||||
|
||||
FindRequestManager* WebContentsImpl::GetFindRequestManagerForTesting() {
|
||||
return GetOrCreateFindRequestManager();
|
||||
}
|
||||
|
@ -1437,8 +1437,11 @@ class CONTENT_EXPORT WebContentsImpl
|
||||
#endif
|
||||
|
||||
// Notify observers that the viewport fit value changed. This is called by
|
||||
// |DisplayCutoutHostImpl|.
|
||||
// |SafeAreaInsetsHost|.
|
||||
void NotifyViewportFitChanged(blink::mojom::ViewportFit value);
|
||||
// Notify observers that safe area constraint has changed. This is called by
|
||||
// |SafeAreaInsetsHost|.
|
||||
void NotifySafeAreaConstraintChanged(bool has_constraint);
|
||||
|
||||
// Returns the current FindRequestManager associated with the WebContents;
|
||||
// this won't create one if none exists.
|
||||
|
@ -438,6 +438,16 @@ class WebContentsObserverProxy extends WebContentsObserver {
|
||||
finishObserverCall();
|
||||
}
|
||||
|
||||
@Override
|
||||
@CalledByNative
|
||||
public void safeAreaConstraintChanged(boolean hasConstraint) {
|
||||
handleObserverCall();
|
||||
for (WebContentsObserver mObserver : mObservers) {
|
||||
mObserver.safeAreaConstraintChanged(hasConstraint);
|
||||
}
|
||||
finishObserverCall();
|
||||
}
|
||||
|
||||
@Override
|
||||
@CalledByNative
|
||||
public void virtualKeyboardModeChanged(@VirtualKeyboardMode.EnumType int mode) {
|
||||
|
@ -204,12 +204,21 @@ public abstract class WebContentsObserver {
|
||||
|
||||
/**
|
||||
* Called when the viewport fit of the Web Contents changes.
|
||||
*
|
||||
* @param value the new viewport fit value.
|
||||
*/
|
||||
public void viewportFitChanged(@ViewportFitType int value) {}
|
||||
|
||||
/**
|
||||
* Called when the safe area constraint of the Web Contents changes.
|
||||
*
|
||||
* @param hasConstraint Whether there are safe area constraint.
|
||||
*/
|
||||
public void safeAreaConstraintChanged(boolean hasConstraint) {}
|
||||
|
||||
/**
|
||||
* Called when the virtual keyboard mode of the Web Contents changes.
|
||||
*
|
||||
* @param mode the new virtual keyboard mode.
|
||||
*/
|
||||
public void virtualKeyboardModeChanged(@VirtualKeyboardMode.EnumType int mode) {}
|
||||
|
@ -681,6 +681,9 @@ class CONTENT_EXPORT WebContentsObserver : public base::CheckedObserver {
|
||||
// This method is called when the viewport fit of a WebContents changes.
|
||||
virtual void ViewportFitChanged(blink::mojom::ViewportFit value) {}
|
||||
|
||||
// This method is called when the safe area constraint changed.
|
||||
virtual void SafeAreaConstraintChanged(bool has_constraint) {}
|
||||
|
||||
// This method is called when the virtual keyboard mode of a WebContents
|
||||
// changes. This can happen as a result of the
|
||||
// `navigator.virtualKeyboard.overlaysContent` API or the virtual-keyboard key
|
||||
|
Reference in New Issue
Block a user