Commit ea157e49 authored by jinsukkim's avatar jinsukkim Committed by Commit bot

Let IME frame update bypass ContentViewCore

Decouples IME frame update (cursor/anchor coordinates) from
ContentViewCore, hence redueces the dependency on CVC. Now
RenderWidgetHostViewAndroid uses native ImeAdapter to route
the frame update info directly to Java layer.

BUG=662908

Review-Url: https://codereview.chromium.org/2834343005
Cr-Commit-Position: refs/heads/master@{#467257}
parent 61b8dd80
......@@ -409,8 +409,7 @@ void ContentViewCoreImpl::UpdateFrameInfo(
const gfx::SizeF& viewport_size,
const float top_controls_height,
const float top_controls_shown_ratio,
bool is_mobile_optimized_hint,
const gfx::SelectionBound& selection_start) {
bool is_mobile_optimized_hint) {
JNIEnv* env = AttachCurrentThread();
ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
if (obj.is_null() || !GetWindowAndroid())
......@@ -421,26 +420,12 @@ void ContentViewCoreImpl::UpdateFrameInfo(
page_scale_ = page_scale_factor;
// The CursorAnchorInfo API in Android only supports zero width selection
// bounds.
const jboolean has_insertion_marker =
selection_start.type() == gfx::SelectionBound::CENTER;
const jboolean is_insertion_marker_visible = selection_start.visible();
const jfloat insertion_marker_horizontal =
has_insertion_marker ? selection_start.edge_top().x() : 0.0f;
const jfloat insertion_marker_top =
has_insertion_marker ? selection_start.edge_top().y() : 0.0f;
const jfloat insertion_marker_bottom =
has_insertion_marker ? selection_start.edge_bottom().y() : 0.0f;
Java_ContentViewCore_updateFrameInfo(
env, obj, scroll_offset.x(), scroll_offset.y(), page_scale_factor,
page_scale_factor_limits.x(), page_scale_factor_limits.y(),
content_size.width(), content_size.height(), viewport_size.width(),
viewport_size.height(), top_controls_height, top_controls_shown_ratio,
is_mobile_optimized_hint, has_insertion_marker,
is_insertion_marker_visible, insertion_marker_horizontal,
insertion_marker_top, insertion_marker_bottom);
is_mobile_optimized_hint);
}
void ContentViewCoreImpl::ShowSelectPopupMenu(
......
......@@ -260,8 +260,7 @@ class ContentViewCoreImpl : public ContentViewCore,
const gfx::SizeF& viewport_size,
const float top_controls_height,
const float top_controls_shown_ratio,
bool is_mobile_optimized_hint,
const gfx::SelectionBound& selection_start);
bool is_mobile_optimized_hint);
bool HasFocus();
void RequestDisallowInterceptTouchEvent();
......
......@@ -157,6 +157,33 @@ void ImeAdapterAndroid::UpdateState(const TextInputState& state) {
state.composition_end, state.reply_to_request);
}
void ImeAdapterAndroid::UpdateFrameInfo(
const gfx::SelectionBound& selection_start,
float dip_scale,
float content_offset_ypix) {
JNIEnv* env = AttachCurrentThread();
ScopedJavaLocalRef<jobject> obj = java_ime_adapter_.get(env);
if (obj.is_null())
return;
// The CursorAnchorInfo API in Android only supports zero width selection
// bounds.
const jboolean has_insertion_marker =
selection_start.type() == gfx::SelectionBound::CENTER;
const jboolean is_insertion_marker_visible = selection_start.visible();
const jfloat insertion_marker_horizontal =
has_insertion_marker ? selection_start.edge_top().x() : 0.0f;
const jfloat insertion_marker_top =
has_insertion_marker ? selection_start.edge_top().y() : 0.0f;
const jfloat insertion_marker_bottom =
has_insertion_marker ? selection_start.edge_bottom().y() : 0.0f;
Java_ImeAdapter_updateFrameInfo(
env, obj, dip_scale, content_offset_ypix, has_insertion_marker,
is_insertion_marker_visible, insertion_marker_horizontal,
insertion_marker_top, insertion_marker_bottom);
}
bool ImeAdapterAndroid::SendKeyEvent(
JNIEnv* env,
const JavaParamRef<jobject>&,
......
......@@ -90,6 +90,10 @@ class CONTENT_EXPORT ImeAdapterAndroid : public RenderWidgetHostConnector {
RenderWidgetHostViewAndroid* old_rwhva,
RenderWidgetHostViewAndroid* new_rhwva) override;
void UpdateFrameInfo(const gfx::SelectionBound& selection_start,
float dip_scale,
float content_offset_ypix);
// Called from native -> java
void CancelComposition();
void FocusedNodeChanged(bool is_editable_node);
......
......@@ -1370,6 +1370,15 @@ void RenderWidgetHostViewAndroid::OnFrameMetadataUpdated(
bool is_mobile_optimized = IsMobileOptimizedFrame(frame_metadata);
gesture_provider_.SetDoubleTapSupportForPageEnabled(!is_mobile_optimized);
float dip_scale = view_.GetDipScale();
float top_controls_pix = frame_metadata.top_controls_height * dip_scale;
float top_shown_pix =
top_controls_pix * frame_metadata.top_controls_shown_ratio;
if (ime_adapter_android_)
ime_adapter_android_->UpdateFrameInfo(frame_metadata.selection.start,
dip_scale, top_shown_pix);
if (!content_view_core_)
return;
......@@ -1396,22 +1405,17 @@ void RenderWidgetHostViewAndroid::OnFrameMetadataUpdated(
frame_metadata.top_controls_height *
frame_metadata.top_controls_shown_ratio));
float dip_scale = view_.GetDipScale();
float top_controls_pix = frame_metadata.top_controls_height * dip_scale;
float top_shown_pix =
top_controls_pix * frame_metadata.top_controls_shown_ratio;
bool top_changed = !FloatEquals(top_shown_pix, prev_top_shown_pix_);
float bottom_controls_pix = frame_metadata.bottom_controls_height * dip_scale;
float bottom_shown_pix =
bottom_controls_pix * frame_metadata.bottom_controls_shown_ratio;
bool bottom_changed = !FloatEquals(bottom_shown_pix, prev_bottom_shown_pix_);
if (top_changed) {
float translate = top_shown_pix - top_controls_pix;
view_.OnTopControlsChanged(translate, top_shown_pix);
prev_top_shown_pix_ = top_shown_pix;
}
float bottom_controls_pix = frame_metadata.bottom_controls_height * dip_scale;
float bottom_shown_pix =
bottom_controls_pix * frame_metadata.bottom_controls_shown_ratio;
bool bottom_changed = !FloatEquals(bottom_shown_pix, prev_bottom_shown_pix_);
if (bottom_changed) {
float translate = bottom_controls_pix - bottom_shown_pix;
view_.OnBottomControlsChanged(translate, bottom_shown_pix);
......@@ -1420,16 +1424,12 @@ void RenderWidgetHostViewAndroid::OnFrameMetadataUpdated(
// All offsets and sizes are in CSS pixels.
content_view_core_->UpdateFrameInfo(
frame_metadata.root_scroll_offset,
frame_metadata.page_scale_factor,
frame_metadata.root_scroll_offset, frame_metadata.page_scale_factor,
gfx::Vector2dF(frame_metadata.min_page_scale_factor,
frame_metadata.max_page_scale_factor),
frame_metadata.root_layer_size,
frame_metadata.scrollable_viewport_size,
frame_metadata.root_layer_size, frame_metadata.scrollable_viewport_size,
frame_metadata.top_controls_height,
frame_metadata.top_controls_shown_ratio,
is_mobile_optimized,
frame_metadata.selection.start);
frame_metadata.top_controls_shown_ratio, is_mobile_optimized);
}
void RenderWidgetHostViewAndroid::ShowInternal() {
......
......@@ -1578,9 +1578,7 @@ public class ContentViewCore
float minPageScaleFactor, float maxPageScaleFactor, float contentWidth,
float contentHeight, float viewportWidth, float viewportHeight,
float browserControlsHeightDp, float browserControlsShownRatio,
boolean isMobileOptimizedHint, boolean hasInsertionMarker,
boolean isInsertionMarkerVisible, float insertionMarkerHorizontal,
float insertionMarkerTop, float insertionMarkerBottom) {
boolean isMobileOptimizedHint) {
TraceEvent.begin("ContentViewCore:updateFrameInfo");
mIsMobileOptimizedHint = isMobileOptimizedHint;
// Adjust contentWidth/Height to be always at least as big as
......@@ -1645,10 +1643,6 @@ public class ContentViewCore
mBrowserAccessibilityManager.notifyFrameInfoInitialized();
}
mImeAdapter.onUpdateFrameInfo(mRenderCoordinates, hasInsertionMarker,
isInsertionMarkerVisible, insertionMarkerHorizontal, insertionMarkerTop,
insertionMarkerBottom);
TraceEvent.end("ContentViewCore:updateFrameInfo");
}
......
......@@ -12,7 +12,6 @@ import android.view.inputmethod.CursorAnchorInfo;
import org.chromium.base.VisibleForTesting;
import org.chromium.base.annotations.SuppressFBWarnings;
import org.chromium.content.browser.RenderCoordinates;
import java.util.Arrays;
......@@ -144,6 +143,8 @@ final class CursorAnchorInfoController {
/**
* Sets coordinates system parameters and selection marker information.
* @param scale device scale factor.
* @param contentOffsetYPix Y offset below the browser controls.
* @param hasInsertionMarker {@code true} if the insertion marker exists.
* @param isInsertionMarkerVisible {@code true} if the insertion insertion marker is visible.
* @param insertionMarkerHorizontal X coordinate of the top of the first selection marker.
......@@ -152,10 +153,9 @@ final class CursorAnchorInfoController {
* @param view The attached view.
*/
@SuppressFBWarnings("FE_FLOATING_POINT_EQUALITY")
public void onUpdateFrameInfo(@Nonnull RenderCoordinates renderCoordinates,
boolean hasInsertionMarker, boolean isInsertionMarkerVisible,
float insertionMarkerHorizontal, float insertionMarkerTop,
float insertionMarkerBottom, @Nonnull View view) {
public void onUpdateFrameInfo(float scale, float contentOffsetYPix, boolean hasInsertionMarker,
boolean isInsertionMarkerVisible, float insertionMarkerHorizontal,
float insertionMarkerTop, float insertionMarkerBottom, @Nonnull View view) {
if (!mIsEditable) return;
// Reuse {@param #mViewOrigin} to avoid object creation, as this method is supposed to be
......@@ -168,10 +168,8 @@ final class CursorAnchorInfoController {
//
// We need to prepare parameters that convert such values to physical pixels, in the
// screen coordinate. Hence the following values are derived.
float scale = renderCoordinates.getDeviceScaleFactor();
float translationX = mViewOrigin[0];
float translationY = mViewOrigin[1] + renderCoordinates.getContentOffsetYPix();
float translationY = mViewOrigin[1] + contentOffsetYPix;
if (!mHasCoordinateInfo
|| scale != mScale
|| translationX != mTranslationX
......
......@@ -33,7 +33,6 @@ import org.chromium.base.annotations.JNINamespace;
import org.chromium.blink_public.web.WebInputEventModifier;
import org.chromium.blink_public.web.WebInputEventType;
import org.chromium.blink_public.web.WebTextInputMode;
import org.chromium.content.browser.RenderCoordinates;
import org.chromium.content.browser.ViewUtils;
import org.chromium.content.browser.picker.InputDialogContainer;
import org.chromium.content_public.browser.ImeEventObserver;
......@@ -823,8 +822,8 @@ public class ImeAdapter {
/**
* Notified when a frame has been produced by the renderer and all the associated metadata.
* @param renderCoordinates coordinate information to convert CSS (document) coordinates to
* View-local Physical (screen) coordinates
* @param scaleFactor device scale factor.
* @param contentOffsetYPix Y offset below the browser controls.
* @param hasInsertionMarker Whether the insertion marker is visible or not.
* @param insertionMarkerHorizontal X coordinates (in view-local DIP pixels) of the insertion
* marker if it exists. Will be ignored otherwise.
......@@ -833,13 +832,15 @@ public class ImeAdapter {
* @param insertionMarkerBottom Y coordinates (in view-local DIP pixels) of the bottom of
* the insertion marker if it exists. Will be ignored otherwise.
*/
public void onUpdateFrameInfo(RenderCoordinates renderCoordinates, boolean hasInsertionMarker,
boolean isInsertionMarkerVisible, float insertionMarkerHorizontal,
float insertionMarkerTop, float insertionMarkerBottom) {
@CalledByNative
private void updateFrameInfo(float scaleFactor, float contentOffsetYPix,
boolean hasInsertionMarker, boolean isInsertionMarkerVisible,
float insertionMarkerHorizontal, float insertionMarkerTop,
float insertionMarkerBottom) {
if (mCursorAnchorInfoController == null) return;
mCursorAnchorInfoController.onUpdateFrameInfo(renderCoordinates, hasInsertionMarker,
isInsertionMarkerVisible, insertionMarkerHorizontal, insertionMarkerTop,
insertionMarkerBottom, mContainerView);
mCursorAnchorInfoController.onUpdateFrameInfo(scaleFactor, contentOffsetYPix,
hasInsertionMarker, isInsertionMarkerVisible, insertionMarkerHorizontal,
insertionMarkerTop, insertionMarkerBottom, mContainerView);
}
@CalledByNative
......
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