summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgsennton <gsennton@chromium.org>2015-07-13 10:19:28 -0700
committerCommit bot <commit-bot@chromium.org>2015-07-13 17:20:12 +0000
commite2c899d8fbf171716aa23b526dee6f296a471ff0 (patch)
treea0759a5e9870bd04b7879b26ae07391230fc8120
parentbab9c3168bfb1ae4089f3a1cc79a6ba5c39e9809 (diff)
downloadchromium_src-e2c899d8fbf171716aa23b526dee6f296a471ff0.zip
chromium_src-e2c899d8fbf171716aa23b526dee6f296a471ff0.tar.gz
chromium_src-e2c899d8fbf171716aa23b526dee6f296a471ff0.tar.bz2
Use display information from the current activity instead of application
This CL changes calls to the functions of screen.h to make sure that we obtain display metrics from the current display instead of always fetching information for the primary display. The main CL for this change is https://codereview.chromium.org/1144333004/ BUG=310763 Review URL: https://codereview.chromium.org/1180073004 Cr-Commit-Position: refs/heads/master@{#338519}
-rw-r--r--content/browser/android/content_view_core_impl.cc9
-rw-r--r--content/browser/android/content_view_core_impl.h6
-rw-r--r--content/browser/renderer_host/input/synthetic_gesture_target_android.cc5
-rw-r--r--content/browser/renderer_host/input/touch_emulator.cc7
-rw-r--r--content/browser/renderer_host/input/touch_emulator.h2
-rw-r--r--content/browser/renderer_host/input/touch_emulator_unittest.cc26
-rw-r--r--content/browser/renderer_host/render_widget_host_impl.cc6
7 files changed, 21 insertions, 40 deletions
diff --git a/content/browser/android/content_view_core_impl.cc b/content/browser/android/content_view_core_impl.cc
index 6495133..1d2783c 100644
--- a/content/browser/android/content_view_core_impl.cc
+++ b/content/browser/android/content_view_core_impl.cc
@@ -57,7 +57,6 @@
#include "ui/gfx/geometry/point_conversions.h"
#include "ui/gfx/geometry/size_conversions.h"
#include "ui/gfx/geometry/size_f.h"
-#include "ui/gfx/screen.h"
using base::android::AttachCurrentThread;
using base::android::ConvertJavaStringToUTF16;
@@ -155,12 +154,6 @@ int ToGestureEventType(WebInputEvent::Type type) {
};
}
-float GetPrimaryDisplayDeviceScaleFactor() {
- const gfx::Display& display =
- gfx::Screen::GetNativeScreen()->GetPrimaryDisplay();
- return display.device_scale_factor();
-}
-
} // namespace
// Enables a callback when the underlying WebContents is destroyed, to enable
@@ -222,9 +215,9 @@ ContentViewCoreImpl::ContentViewCoreImpl(
java_ref_(env, obj),
web_contents_(static_cast<WebContentsImpl*>(web_contents)),
root_layer_(cc::SolidColorLayer::Create(Compositor::LayerSettings())),
- dpi_scale_(GetPrimaryDisplayDeviceScaleFactor()),
page_scale_(1),
view_android_(new ui::ViewAndroid(view_android_delegate, window_android)),
+ dpi_scale_(ui::GetScaleFactorForNativeView(view_android_.get())),
window_android_(window_android),
device_orientation_(0),
accessibility_enabled_(false) {
diff --git a/content/browser/android/content_view_core_impl.h b/content/browser/android/content_view_core_impl.h
index 4fd76fc..1aca5a0 100644
--- a/content/browser/android/content_view_core_impl.h
+++ b/content/browser/android/content_view_core_impl.h
@@ -366,9 +366,6 @@ class ContentViewCoreImpl : public ContentViewCore,
// A compositor layer containing any layer that should be shown.
scoped_refptr<cc::Layer> root_layer_;
- // Device scale factor.
- float dpi_scale_;
-
// Page scale factor.
float page_scale_;
@@ -376,6 +373,9 @@ class ContentViewCoreImpl : public ContentViewCore,
// like AutofillPopup.
scoped_ptr<ui::ViewAndroid> view_android_;
+ // Device scale factor.
+ const float dpi_scale_;
+
// The owning window that has a hold of main application activity.
ui::WindowAndroid* window_android_;
diff --git a/content/browser/renderer_host/input/synthetic_gesture_target_android.cc b/content/browser/renderer_host/input/synthetic_gesture_target_android.cc
index 501da40..aca0ab6 100644
--- a/content/browser/renderer_host/input/synthetic_gesture_target_android.cc
+++ b/content/browser/renderer_host/input/synthetic_gesture_target_android.cc
@@ -9,7 +9,6 @@
#include "jni/MotionEventSynthesizer_jni.h"
#include "third_party/WebKit/public/web/WebInputEvent.h"
#include "ui/gfx/android/view_configuration.h"
-#include "ui/gfx/screen.h"
using blink::WebTouchEvent;
@@ -107,10 +106,14 @@ SyntheticGestureTargetAndroid::GetDefaultSyntheticGestureSourceType() const {
}
float SyntheticGestureTargetAndroid::GetTouchSlopInDips() const {
+ // TODO(jdduke): Have all targets use the same ui::GestureConfiguration
+ // codepath.
return gfx::ViewConfiguration::GetTouchSlopInDips();
}
float SyntheticGestureTargetAndroid::GetMinScalingSpanInDips() const {
+ // TODO(jdduke): Have all targets use the same ui::GestureConfiguration
+ // codepath.
return gfx::ViewConfiguration::GetMinScalingSpanInDips();
}
diff --git a/content/browser/renderer_host/input/touch_emulator.cc b/content/browser/renderer_host/input/touch_emulator.cc
index d22065e..90a6bf7 100644
--- a/content/browser/renderer_host/input/touch_emulator.cc
+++ b/content/browser/renderer_host/input/touch_emulator.cc
@@ -15,7 +15,6 @@
#include "ui/events/blink/blink_event_util.h"
#include "ui/events/gesture_detection/gesture_provider_config_helper.h"
#include "ui/gfx/image/image.h"
-#include "ui/gfx/screen.h"
using blink::WebGestureEvent;
using blink::WebInputEvent;
@@ -45,7 +44,8 @@ const double kMouseMoveDropIntervalSeconds = 5.f / 1000;
} // namespace
-TouchEmulator::TouchEmulator(TouchEmulatorClient* client)
+TouchEmulator::TouchEmulator(TouchEmulatorClient* client,
+ float device_scale_factor)
: client_(client),
gesture_provider_config_type_(
ui::GestureProviderConfigType::CURRENT_PLATFORM),
@@ -55,8 +55,7 @@ TouchEmulator::TouchEmulator(TouchEmulatorClient* client)
DCHECK(client_);
ResetState();
- bool use_2x = gfx::Screen::GetNativeScreen()->
- GetPrimaryDisplay().device_scale_factor() > 1.5f;
+ bool use_2x = device_scale_factor > 1.5f;
float cursor_scale_factor = use_2x ? 2.f : 1.f;
cursor_size_ = InitCursorFromResource(&touch_cursor_,
cursor_scale_factor,
diff --git a/content/browser/renderer_host/input/touch_emulator.h b/content/browser/renderer_host/input/touch_emulator.h
index 87c985d..e21287f 100644
--- a/content/browser/renderer_host/input/touch_emulator.h
+++ b/content/browser/renderer_host/input/touch_emulator.h
@@ -18,7 +18,7 @@ namespace content {
// Emulates touch input with mouse and keyboard.
class CONTENT_EXPORT TouchEmulator : public ui::GestureProviderClient {
public:
- explicit TouchEmulator(TouchEmulatorClient* client);
+ TouchEmulator(TouchEmulatorClient* client, float device_scale_factor);
~TouchEmulator() override;
void Enable(ui::GestureProviderConfigType config_type);
diff --git a/content/browser/renderer_host/input/touch_emulator_unittest.cc b/content/browser/renderer_host/input/touch_emulator_unittest.cc
index 4b8bd1d..f46703c 100644
--- a/content/browser/renderer_host/input/touch_emulator_unittest.cc
+++ b/content/browser/renderer_host/input/touch_emulator_unittest.cc
@@ -13,11 +13,6 @@
#include "content/common/input/web_input_event_traits.h"
#include "testing/gtest/include/gtest/gtest.h"
-#if defined(USE_AURA)
-#include "ui/aura/env.h"
-#include "ui/aura/test/test_screen.h"
-#endif
-
using blink::WebGestureEvent;
using blink::WebInputEvent;
using blink::WebKeyboardEvent;
@@ -46,13 +41,7 @@ class TouchEmulatorTest : public testing::Test,
// testing::Test
void SetUp() override {
-#if defined(USE_AURA)
- aura::Env::CreateInstance(true);
- screen_.reset(aura::TestScreen::Create(gfx::Size()));
- gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, screen_.get());
-#endif
-
- emulator_.reset(new TouchEmulator(this));
+ emulator_.reset(new TouchEmulator(this, 1.0f));
emulator_->SetDoubleTapSupportForPageEnabled(false);
emulator_->Enable(ui::GestureProviderConfigType::GENERIC_MOBILE);
}
@@ -60,12 +49,6 @@ class TouchEmulatorTest : public testing::Test,
void TearDown() override {
emulator_->Disable();
EXPECT_EQ("", ExpectedEvents());
-
-#if defined(USE_AURA)
- aura::Env::DeleteInstance();
- gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, nullptr);
- screen_.reset();
-#endif
}
void ForwardGestureEvent(const blink::WebGestureEvent& event) override {
@@ -251,9 +234,6 @@ class TouchEmulatorTest : public testing::Test,
private:
scoped_ptr<TouchEmulator> emulator_;
std::vector<WebInputEvent::Type> forwarded_events_;
-#if defined(USE_AURA)
- scoped_ptr<gfx::Screen> screen_;
-#endif
double last_event_time_seconds_;
double event_time_delta_seconds_;
bool shift_pressed_;
@@ -575,4 +555,8 @@ TEST_F(TouchEmulatorTest, CancelAfterDisableDoesNotCrash) {
emulator()->CancelTouch();
}
+TEST_F(TouchEmulatorTest, ConstructorWithHighDeviceScaleDoesNotCrash) {
+ TouchEmulator(this, 4.0f);
+}
+
} // namespace content
diff --git a/content/browser/renderer_host/render_widget_host_impl.cc b/content/browser/renderer_host/render_widget_host_impl.cc
index 314f785..6080ecc 100644
--- a/content/browser/renderer_host/render_widget_host_impl.cc
+++ b/content/browser/renderer_host/render_widget_host_impl.cc
@@ -1599,8 +1599,10 @@ void RenderWidgetHostImpl::OnSetCursor(const WebCursor& cursor) {
void RenderWidgetHostImpl::SetTouchEventEmulationEnabled(
bool enabled, ui::GestureProviderConfigType config_type) {
if (enabled) {
- if (!touch_emulator_)
- touch_emulator_.reset(new TouchEmulator(this));
+ if (!touch_emulator_) {
+ touch_emulator_.reset(new TouchEmulator(
+ this, view_ ? content::GetScaleFactorForView(view_) : 1.0f));
+ }
touch_emulator_->Enable(config_type);
} else {
if (touch_emulator_)