Skip to content

Commit

Permalink
Remove dip scale dependency from ui::WindowAndroid
Browse files Browse the repository at this point in the history
Starting from Android N dip scale can be changed dynamically.
In this CL we remove the dip scale impliciltly stored in
WindowAndroid's |content_offset_| and use the scale at the
time of calculations that involve the content offset.

This is a prerequisite for https://codereview.chromium.org/2202123002/

BUG=620929

Review-Url: https://codereview.chromium.org/2249243002
Cr-Commit-Position: refs/heads/master@{#412653}
  • Loading branch information
timav authored and Commit bot committed Aug 17, 2016
1 parent 21576e2 commit 164e1ee
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
3 changes: 1 addition & 2 deletions content/browser/android/content_view_core_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -427,8 +427,7 @@ void ContentViewCoreImpl::UpdateFrameInfo(
if (obj.is_null() || !view_.GetWindowAndroid())
return;

view_.GetWindowAndroid()->set_content_offset(
gfx::ScaleVector2d(content_offset, dpi_scale_));
view_.GetWindowAndroid()->set_content_offset(content_offset);

page_scale_ = page_scale_factor;

Expand Down
4 changes: 2 additions & 2 deletions ui/android/view_android.cc
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ void ViewAndroid::SetAnchorRect(const JavaRef<jobject>& anchor,
int left_margin = std::round(bounds.x() * scale);
// TODO(jinsukkim): Move content_offset() to ViewAndroid, since it's
// specific to a given web contents/render widget.
float content_offset_y_pix = GetWindowAndroid()->content_offset().y();
int top_margin = std::round(content_offset_y_pix + bounds.y() * scale);
int top_margin = std::round(
(GetWindowAndroid()->content_offset().y() + bounds.y()) * scale);
JNIEnv* env = base::android::AttachCurrentThread();
Java_ViewAndroidDelegate_setViewPosition(
env, delegate, anchor, bounds.x(), bounds.y(), bounds.width(),
Expand Down
4 changes: 2 additions & 2 deletions ui/android/window_android.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ class UI_ANDROID_EXPORT WindowAndroid : public ViewAndroid {

static bool RegisterWindowAndroid(JNIEnv* env);

// The content offset is used to translate snapshots to the correct part of
// the window.
// The content offset in CSS pixels. It is used together with device scale
// factor to translate snapshots to the correct part of the window.
void set_content_offset(const gfx::Vector2dF& content_offset) {
content_offset_ = content_offset;
}
Expand Down
10 changes: 6 additions & 4 deletions ui/snapshot/snapshot_android.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,12 @@ static void MakeAsyncCopyRequest(
gfx::ScaleToEnclosingRect(source_rect, device_scale_factor);

// Account for the toolbar offset.
gfx::Vector2dF offset = window->content_offset();
gfx::Rect adjusted_source_rect(gfx::ToRoundedPoint(
gfx::PointF(source_rect_in_pixel.x() + offset.x(),
source_rect_in_pixel.y() + offset.y())),
gfx::Vector2dF offset_in_pixel =
gfx::ScaleVector2d(window->content_offset(), device_scale_factor);
gfx::Rect adjusted_source_rect(
gfx::ToRoundedPoint(
gfx::PointF(source_rect_in_pixel.x() + offset_in_pixel.x(),
source_rect_in_pixel.y() + offset_in_pixel.y())),
source_rect_in_pixel.size());

request->set_area(adjusted_source_rect);
Expand Down

0 comments on commit 164e1ee

Please sign in to comment.