Commit 1599c4d0 authored by Jaebaek Seo's avatar Jaebaek Seo Committed by Commit Bot

Adjust location of Autofill popup for --use-zoom-for-dsf

As shown crbug.com/737777#c51, enabling --use-zoom-for-dsf locates Autofill
popup in a wrong place. It is because
AutofillPopupViewAndroid::OnSuggestionsChanged() and
AwAutofillClient::ShowAutofillPopupImpl() passes element_bounds in the CSS scale
as an argument to ViewAndroid::SetAnchorRect() that must receive the device
scaled bounds argument when --use-zoom-for-dsf is enabled.

This CL lets ViewAndroid::SetAnchorRect() receive the CSS scaled bounds argument
and scales down the bounds argument as the CSS scale that
ContentViewCore::ShowSelectPopupMenu() gives to ViewAndroid::SetAnchorRect().

In addition, this CL sets ViewAndroid::content_offset() as the CSS scale, which
must be in the CSS scale for ViewAndroid::SetAnchorRect(),
RenderWidgetHostImpl::WindowSnapshotReachedScreen(),
ContextMenuHelper::ShowContextMenu(), and
TabAndroid::ShowMediaDownloadInProductHelp().

By refactoring RenderWidgetHostViewAndroid::OnFrameMetadataUpdated(), it also
relocates the position of IME CursorAnchorInfo API to the correct position when
--use-zoom-for-dsf is enabled.

BUG=737777

Change-Id: I8f2268562735b822478455dab7581b6418a397fd
Reviewed-on: https://chromium-review.googlesource.com/771491
Commit-Queue: Jaebaek Seo <jaebaek@chromium.org>
Reviewed-by: default avatarJinsuk Kim <jinsukkim@chromium.org>
Reviewed-by: default avatarBo <boliu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#517028}
parent 761e67a0
......@@ -32,6 +32,7 @@
#include "content/browser/renderer_host/render_widget_host_view_android.h"
#include "content/browser/web_contents/web_contents_android.h"
#include "content/browser/web_contents/web_contents_view_android.h"
#include "content/common/content_switches_internal.h"
#include "content/common/frame_messages.h"
#include "content/common/input_messages.h"
#include "content/common/view_messages.h"
......@@ -434,7 +435,12 @@ void ContentViewCore::ShowSelectPopupMenu(RenderFrameHost* frame,
const ScopedJavaLocalRef<jobject> popup_view = select_popup_.view();
if (popup_view.is_null())
return;
view->SetAnchorRect(popup_view, gfx::RectF(bounds));
// |bounds| is in physical pixels if --use-zoom-for-dsf is enabled. Otherwise,
// it is in DIP pixels.
gfx::RectF bounds_dip = gfx::RectF(bounds);
if (IsUseZoomForDSFEnabled())
bounds_dip.Scale(1 / dpi_scale_);
view->SetAnchorRect(popup_view, bounds_dip);
Java_ContentViewCore_showSelectPopup(
env, j_obj, popup_view, reinterpret_cast<intptr_t>(frame), items_array,
enabled_array, multiple, selected_array, right_aligned);
......
......@@ -153,7 +153,6 @@
#include "content/browser/screen_orientation/screen_orientation_delegate_android.h"
#include "media/base/android/media_drm_bridge_client.h"
#include "ui/android/screen_android.h"
#include "ui/android/view_android.h"
#include "ui/display/screen.h"
#include "ui/gl/gl_surface.h"
#endif
......@@ -686,10 +685,6 @@ void BrowserMainLoop::EarlyInitialization() {
}
}
#if defined(OS_ANDROID)
ui::ViewAndroid::SetIsUseZoomForDSFEnabled(IsUseZoomForDSFEnabled());
#endif
if (parts_)
parts_->PostEarlyInitialization();
}
......
......@@ -1504,11 +1504,16 @@ void RenderWidgetHostViewAndroid::OnFrameMetadataUpdated(
bool is_mobile_optimized = IsMobileOptimizedFrame(frame_metadata);
gesture_provider_.SetDoubleTapSupportForPageEnabled(!is_mobile_optimized);
float dip_scale = IsUseZoomForDSFEnabled() ? 1.f : view_.GetDipScale();
float top_controls_pix = frame_metadata.top_controls_height * dip_scale;
float dip_scale = view_.GetDipScale();
float to_pix = IsUseZoomForDSFEnabled() ? 1.f : dip_scale;
float top_controls_pix = frame_metadata.top_controls_height * to_pix;
// |top_content_offset| is its CSS pixels * DSF if --use-zoom-for-dsf is
// enabled. Otherwise, it is in CSS pixels.
// Note that the height of browser control is not affected by page scale
// factor. Thus, |top_content_offset| in CSS pixels is also in DIP pixels.
float top_content_offset = frame_metadata.top_controls_height *
frame_metadata.top_controls_shown_ratio;
float top_shown_pix = top_content_offset * dip_scale;
float top_shown_pix = top_content_offset * to_pix;
if (ime_adapter_android_)
ime_adapter_android_->UpdateFrameInfo(frame_metadata.selection.start,
......@@ -1544,8 +1549,13 @@ void RenderWidgetHostViewAndroid::OnFrameMetadataUpdated(
UpdateBackgroundColor(is_transparent ? SK_ColorTRANSPARENT
: frame_metadata.root_background_color);
// ViewAndroid::content_offset() must be in CSS scale
float top_content_offset_css = IsUseZoomForDSFEnabled()
? top_content_offset / dip_scale
: top_content_offset;
view_.UpdateFrameInfo({frame_metadata.scrollable_viewport_size,
frame_metadata.page_scale_factor, top_content_offset});
frame_metadata.page_scale_factor,
top_content_offset_css});
bool top_changed = !FloatEquals(top_shown_pix, prev_top_shown_pix_);
if (top_changed) {
......@@ -1554,7 +1564,7 @@ void RenderWidgetHostViewAndroid::OnFrameMetadataUpdated(
prev_top_shown_pix_ = top_shown_pix;
}
float bottom_controls_pix = frame_metadata.bottom_controls_height * dip_scale;
float bottom_controls_pix = frame_metadata.bottom_controls_height * to_pix;
float bottom_shown_pix =
bottom_controls_pix * frame_metadata.bottom_controls_shown_ratio;
bool bottom_changed = !FloatEquals(bottom_shown_pix, prev_bottom_shown_pix_);
......@@ -1564,13 +1574,13 @@ void RenderWidgetHostViewAndroid::OnFrameMetadataUpdated(
prev_bottom_shown_pix_ = bottom_shown_pix;
}
// All offsets and sizes are in CSS pixels.
// All offsets and sizes except |top_shown_pix| are in CSS pixels.
content_view_core_->UpdateFrameInfo(
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,
top_content_offset, top_shown_pix, top_changed, is_mobile_optimized);
top_content_offset_css, top_shown_pix, top_changed, is_mobile_optimized);
EvictFrameIfNecessary();
}
......
......@@ -30,8 +30,6 @@ using base::android::JavaRef;
using base::android::ScopedJavaLocalRef;
using blink::WebCursorInfo;
bool ViewAndroid::is_use_zoom_for_dsf_enabled_ = false;
ViewAndroid::ScopedAnchorView::ScopedAnchorView(
JNIEnv* env,
const JavaRef<jobject>& jview,
......@@ -201,24 +199,24 @@ ViewAndroid::ScopedAnchorView ViewAndroid::AcquireAnchorView() {
env, Java_ViewAndroidDelegate_acquireView(env, delegate), delegate);
}
void ViewAndroid::SetIsUseZoomForDSFEnabled(bool enabled) {
is_use_zoom_for_dsf_enabled_ = enabled;
}
void ViewAndroid::SetAnchorRect(const JavaRef<jobject>& anchor,
const gfx::RectF& bounds) {
const gfx::RectF& bounds_dip) {
ScopedJavaLocalRef<jobject> delegate(GetViewAndroidDelegate());
if (delegate.is_null())
return;
float scale = is_use_zoom_for_dsf_enabled_ ? 1 : GetDipScale();
int left_margin = std::round(bounds.x() * scale);
int top_margin = std::round((content_offset() + bounds.y()) * scale);
const gfx::RectF scaled_bounds = gfx::ScaleRect(bounds, scale);
float dip_scale = GetDipScale();
int left_margin = std::round(bounds_dip.x() * dip_scale);
// Note that content_offset() is in CSS scale and bounds_dip is in DIP scale
// (i.e., CSS pixels * page scale factor), but the height of browser control
// is not affected by page scale factor. Thus, content_offset() in CSS scale
// is also in DIP scale.
int top_margin = std::round((content_offset() + bounds_dip.y()) * dip_scale);
const gfx::RectF bounds_px = gfx::ScaleRect(bounds_dip, dip_scale);
JNIEnv* env = base::android::AttachCurrentThread();
Java_ViewAndroidDelegate_setViewPosition(
env, delegate, anchor, scaled_bounds.x(), scaled_bounds.y(),
scaled_bounds.width(), scaled_bounds.height(), left_margin, top_margin);
env, delegate, anchor, bounds_px.x(), bounds_px.y(), bounds_px.width(),
bounds_px.height(), left_margin, top_margin);
}
ScopedJavaLocalRef<jobject> ViewAndroid::GetContainerView() {
......
......@@ -91,14 +91,13 @@ class UI_ANDROID_EXPORT ViewAndroid {
MATCH_PARENT
};
static void SetIsUseZoomForDSFEnabled(bool enabled);
ViewAndroid(ViewClient* view_client, LayoutType layout_type);
ViewAndroid();
virtual ~ViewAndroid();
void UpdateFrameInfo(const FrameInfo& frame_info);
// content_offset is in CSS scale.
float content_offset() const { return frame_info_.content_offset; }
float page_scale() const { return frame_info_.page_scale; }
gfx::SizeF viewport_size() const { return frame_info_.viewport_size; }
......@@ -169,8 +168,6 @@ class UI_ANDROID_EXPORT ViewAndroid {
ViewAndroid* parent_;
private:
static bool is_use_zoom_for_dsf_enabled_;
FRIEND_TEST_ALL_PREFIXES(ViewAndroidBoundsTest, MatchesViewInFront);
FRIEND_TEST_ALL_PREFIXES(ViewAndroidBoundsTest, MatchesViewArea);
FRIEND_TEST_ALL_PREFIXES(ViewAndroidBoundsTest, MatchesViewAfterMove);
......
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