Commit 884e1a19 authored by Aldo Culquicondor's avatar Aldo Culquicondor Committed by Commit Bot

[Android] Making the touch handles aware of DIP changes

Instead of caching the DIP scale at creation, query the scale from the
view.

Bug: 851634
Change-Id: Iaacec8f649fcb0da6aa01ec0859b29f8cf1281b3
Reviewed-on: https://chromium-review.googlesource.com/1099045Reviewed-by: default avatarPedro Amaral <amaralp@chromium.org>
Commit-Queue: Aldo Culquicondor <acondor@chromium.org>
Cr-Commit-Position: refs/heads/master@{#566978}
parent 4a80148f
......@@ -10,6 +10,7 @@
#include "cc/layers/ui_resource_layer.h"
#include "content/public/browser/android/compositor.h"
#include "ui/android/handle_view_resources.h"
#include "ui/android/view_android.h"
using base::android::JavaRef;
......@@ -22,17 +23,16 @@ base::LazyInstance<ui::HandleViewResources>::Leaky g_selection_resources;
} // namespace
CompositedTouchHandleDrawable::CompositedTouchHandleDrawable(
cc::Layer* root_layer,
float dpi_scale,
gfx::NativeView view,
const JavaRef<jobject>& context)
: dpi_scale_(dpi_scale),
: view_(view),
orientation_(ui::TouchHandleOrientation::UNDEFINED),
layer_(cc::UIResourceLayer::Create()) {
g_selection_resources.Get().LoadIfNecessary(context);
drawable_horizontal_padding_ratio_ =
g_selection_resources.Get().GetDrawableHorizontalPaddingRatio();
DCHECK(root_layer);
root_layer->AddChild(layer_.get());
DCHECK(view->GetLayer());
view->GetLayer()->AddChild(layer_.get());
}
CompositedTouchHandleDrawable::~CompositedTouchHandleDrawable() {
......@@ -78,7 +78,7 @@ void CompositedTouchHandleDrawable::SetOrientation(
}
void CompositedTouchHandleDrawable::SetOrigin(const gfx::PointF& origin) {
origin_position_ = gfx::ScalePoint(origin, dpi_scale_);
origin_position_ = origin;
UpdateLayerPosition();
}
......@@ -91,11 +91,10 @@ void CompositedTouchHandleDrawable::SetAlpha(float alpha) {
}
gfx::RectF CompositedTouchHandleDrawable::GetVisibleBounds() const {
return gfx::ScaleRect(gfx::RectF(layer_->position().x(),
layer_->position().y(),
layer_->bounds().width(),
layer_->bounds().height()),
1.f / dpi_scale_);
return gfx::ScaleRect(
gfx::RectF(layer_->position().x(), layer_->position().y(),
layer_->bounds().width(), layer_->bounds().height()),
1.f / view_->GetDipScale());
}
float CompositedTouchHandleDrawable::GetDrawableHorizontalPaddingRatio() const {
......@@ -107,7 +106,7 @@ void CompositedTouchHandleDrawable::DetachLayer() {
}
void CompositedTouchHandleDrawable::UpdateLayerPosition() {
layer_->SetPosition(origin_position_);
layer_->SetPosition(gfx::ScalePoint(origin_position_, view_->GetDipScale()));
}
} // namespace content
......@@ -8,10 +8,10 @@
#include "base/android/scoped_java_ref.h"
#include "base/macros.h"
#include "base/memory/scoped_refptr.h"
#include "ui/gfx/native_widget_types.h"
#include "ui/touch_selection/touch_handle.h"
namespace cc {
class Layer;
class UIResourceLayer;
} // namespace cc
......@@ -20,8 +20,7 @@ namespace content {
// Touch handle drawable implementation backed by a cc layer.
class CompositedTouchHandleDrawable : public ui::TouchHandleDrawable {
public:
CompositedTouchHandleDrawable(cc::Layer* root_layer,
float dpi_scale,
CompositedTouchHandleDrawable(gfx::NativeView view,
const base::android::JavaRef<jobject>& context);
~CompositedTouchHandleDrawable() override;
......@@ -39,7 +38,7 @@ class CompositedTouchHandleDrawable : public ui::TouchHandleDrawable {
void DetachLayer();
void UpdateLayerPosition();
const float dpi_scale_;
gfx::NativeView view_;
float drawable_horizontal_padding_ratio_;
ui::TouchHandleOrientation orientation_;
gfx::PointF origin_position_;
......
......@@ -74,8 +74,7 @@ SelectionPopupController::CreateTouchHandleDrawable() {
// the java side in CompositedTouchHandleDrawable.
auto* view = web_contents()->GetNativeView();
return std::unique_ptr<ui::TouchHandleDrawable>(
new CompositedTouchHandleDrawable(view->GetLayer(), view->GetDipScale(),
activityContext));
new CompositedTouchHandleDrawable(view, activityContext));
}
void SelectionPopupController::MoveRangeSelectionExtent(
......
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