Commit ba706a33 authored by Tetsui Ohkubo's avatar Tetsui Ohkubo Committed by Commit Bot

arc: ime: Use correct deviceScaleFactor for ARC R

Since ARC R, ARC started to natively support display density. That means
now one Android pixel always matches the display's physical pixel, and
will not be affected by default_dsf which can dynamically change when
the screen scaling is changed by the user.

This CL fixes the issue by adding GetDeviceScaleFactorForWindow to
WMHelper. It returns the same value as GetDefaultDeviceScaleFactor()
when |default_scale_cancellation| is true i.e. ARC not supporting native
density. Otherwise, it returns the display's density.

Additionally, |default_scale_cancellation| is forwarded from
WaylandRemoteShell to WMHelper.

TEST=manual
BUG=b:172031529

Change-Id: I04c2a14712c49760a38c2e21eaf4a2244195397d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2525703Reviewed-by: default avatarYuichiro Hanada <yhanada@chromium.org>
Reviewed-by: default avatarMichael Spang <spang@chromium.org>
Reviewed-by: default avatarMitsuru Oshima <oshima@chromium.org>
Commit-Queue: Tetsui Ohkubo <tetsui@chromium.org>
Cr-Commit-Position: refs/heads/master@{#827167}
parent 3f0b776f
...@@ -195,6 +195,16 @@ double CastWMHelper::GetDefaultDeviceScaleFactor() const { ...@@ -195,6 +195,16 @@ double CastWMHelper::GetDefaultDeviceScaleFactor() const {
return 1.0; return 1.0;
} }
double CastWMHelper::GetDeviceScaleFactorForWindow(aura::Window* window) const {
NOTIMPLEMENTED();
return 1.0;
}
void CastWMHelper::SetDefaultScaleCancellation(
bool default_scale_cancellation) {
NOTIMPLEMENTED();
}
void CastWMHelper::SetImeBlocked(aura::Window* window, bool ime_blocked) { void CastWMHelper::SetImeBlocked(aura::Window* window, bool ime_blocked) {
NOTIMPLEMENTED(); NOTIMPLEMENTED();
} }
......
...@@ -95,6 +95,8 @@ class CastWMHelper : public WMHelper, public VSyncTimingManager::Delegate { ...@@ -95,6 +95,8 @@ class CastWMHelper : public WMHelper, public VSyncTimingManager::Delegate {
void RemovePostTargetHandler(ui::EventHandler* handler) override; void RemovePostTargetHandler(ui::EventHandler* handler) override;
bool InTabletMode() const override; bool InTabletMode() const override;
double GetDefaultDeviceScaleFactor() const override; double GetDefaultDeviceScaleFactor() const override;
double GetDeviceScaleFactorForWindow(aura::Window* window) const override;
void SetDefaultScaleCancellation(bool default_scale_cancellation) override;
void SetImeBlocked(aura::Window* window, bool ime_blocked) override; void SetImeBlocked(aura::Window* window, bool ime_blocked) override;
bool IsImeBlocked(aura::Window* window) const override; bool IsImeBlocked(aura::Window* window) const override;
......
...@@ -41,14 +41,6 @@ namespace { ...@@ -41,14 +41,6 @@ namespace {
base::Optional<double> g_override_default_device_scale_factor; base::Optional<double> g_override_default_device_scale_factor;
double GetDefaultDeviceScaleFactor() {
if (g_override_default_device_scale_factor.has_value())
return g_override_default_device_scale_factor.value();
if (!exo::WMHelper::HasInstance())
return 1.0;
return exo::WMHelper::GetInstance()->GetDefaultDeviceScaleFactor();
}
class ArcWindowDelegateImpl : public ArcImeService::ArcWindowDelegate { class ArcWindowDelegateImpl : public ArcImeService::ArcWindowDelegate {
public: public:
explicit ArcWindowDelegateImpl(ArcImeService* ime_service) explicit ArcWindowDelegateImpl(ArcImeService* ime_service)
...@@ -410,15 +402,9 @@ void ArcImeService::SendKeyEvent(std::unique_ptr<ui::KeyEvent> key_event, ...@@ -410,15 +402,9 @@ void ArcImeService::SendKeyEvent(std::unique_ptr<ui::KeyEvent> key_event,
void ArcImeService::OnKeyboardAppearanceChanged( void ArcImeService::OnKeyboardAppearanceChanged(
const ash::KeyboardStateDescriptor& state) { const ash::KeyboardStateDescriptor& state) {
gfx::Rect new_bounds = state.occluded_bounds_in_screen; gfx::Rect new_bounds = state.occluded_bounds_in_screen;
// Multiply by the scale factor. To convert from DIP to physical pixels. // Multiply by the scale factor. To convert from Chrome DIP to Android pixels.
// The default scale factor is always used in Android side regardless of
// dynamic scale factor in Chrome side because Chrome sends only the default
// scale factor. You can find that in WaylandRemoteShell in
// components/exo/wayland/server.cc. We can't send dynamic scale factor due to
// difference between definition of DIP in Chrome OS and definition of DIP in
// Android.
gfx::Rect bounds_in_px = gfx::Rect bounds_in_px =
gfx::ScaleToEnclosingRect(new_bounds, GetDefaultDeviceScaleFactor()); gfx::ScaleToEnclosingRect(new_bounds, GetDeviceScaleFactorForKeyboard());
ime_bridge_->SendOnKeyboardAppearanceChanging(bounds_in_px, state.is_visible); ime_bridge_->SendOnKeyboardAppearanceChanging(bounds_in_px, state.is_visible);
} }
...@@ -675,12 +661,9 @@ void ArcImeService::InvalidateSurroundingTextAndSelectionRange() { ...@@ -675,12 +661,9 @@ void ArcImeService::InvalidateSurroundingTextAndSelectionRange() {
bool ArcImeService::UpdateCursorRect(const gfx::Rect& rect, bool ArcImeService::UpdateCursorRect(const gfx::Rect& rect,
bool is_screen_coordinates) { bool is_screen_coordinates) {
// Divide by the scale factor. To convert from physical pixels to DIP. // Divide by the scale factor. To convert from Android pixels to Chrome DIP.
// The default scale factor is always used because Android side is always gfx::Rect converted(gfx::ScaleToEnclosingRect(
// using the default scale factor regardless of dynamic scale factor in Chrome rect, 1 / GetDeviceScaleFactorForFocusedWindow()));
// side.
gfx::Rect converted(
gfx::ScaleToEnclosingRect(rect, 1 / GetDefaultDeviceScaleFactor()));
// If the supplied coordinates are relative to the window, add the offset of // If the supplied coordinates are relative to the window, add the offset of
// the window showing the ARC app. // the window showing the ARC app.
...@@ -720,4 +703,29 @@ bool ArcImeService::ShouldSendUpdateToInputMethod() const { ...@@ -720,4 +703,29 @@ bool ArcImeService::ShouldSendUpdateToInputMethod() const {
return focused_arc_window_ != nullptr; return focused_arc_window_ != nullptr;
} }
double ArcImeService::GetDeviceScaleFactorForKeyboard() const {
if (g_override_default_device_scale_factor.has_value())
return g_override_default_device_scale_factor.value();
if (!exo::WMHelper::HasInstance() ||
!keyboard::KeyboardUIController::HasInstance()) {
return 1.0;
}
aura::Window* const keyboard_window =
keyboard::KeyboardUIController::Get()->GetKeyboardWindow();
if (!keyboard_window)
return 1.0;
return exo::WMHelper::GetInstance()->GetDeviceScaleFactorForWindow(
keyboard_window);
}
double ArcImeService::GetDeviceScaleFactorForFocusedWindow() const {
DCHECK(focused_arc_window_);
if (g_override_default_device_scale_factor.has_value())
return g_override_default_device_scale_factor.value();
if (!exo::WMHelper::HasInstance())
return 1.0;
return exo::WMHelper::GetInstance()->GetDeviceScaleFactorForWindow(
focused_arc_window_);
}
} // namespace arc } // namespace arc
...@@ -188,6 +188,9 @@ class ArcImeService : public KeyedService, ...@@ -188,6 +188,9 @@ class ArcImeService : public KeyedService,
// from Android is valid. // from Android is valid.
bool ShouldSendUpdateToInputMethod() const; bool ShouldSendUpdateToInputMethod() const;
double GetDeviceScaleFactorForKeyboard() const;
double GetDeviceScaleFactorForFocusedWindow() const;
std::unique_ptr<ArcImeBridge> ime_bridge_; std::unique_ptr<ArcImeBridge> ime_bridge_;
std::unique_ptr<ArcWindowDelegate> arc_window_delegate_; std::unique_ptr<ArcWindowDelegate> arc_window_delegate_;
ui::TextInputType ime_type_; ui::TextInputType ime_type_;
......
...@@ -69,6 +69,10 @@ class WMHelperTester : public WMHelper, public VSyncTimingManager::Delegate { ...@@ -69,6 +69,10 @@ class WMHelperTester : public WMHelper, public VSyncTimingManager::Delegate {
void RemovePostTargetHandler(ui::EventHandler* handler) override {} void RemovePostTargetHandler(ui::EventHandler* handler) override {}
bool InTabletMode() const override { return false; } bool InTabletMode() const override { return false; }
double GetDefaultDeviceScaleFactor() const override { return 1.0; } double GetDefaultDeviceScaleFactor() const override { return 1.0; }
double GetDeviceScaleFactorForWindow(aura::Window* window) const override {
return 1.0;
}
void SetDefaultScaleCancellation(bool default_scale_cancellation) override {}
void SetImeBlocked(aura::Window* window, bool ime_blocked) override {} void SetImeBlocked(aura::Window* window, bool ime_blocked) override {}
bool IsImeBlocked(aura::Window* window) const override { return false; } bool IsImeBlocked(aura::Window* window) const override { return false; }
......
...@@ -909,6 +909,7 @@ class WaylandRemoteShell : public ash::TabletModeObserver, ...@@ -909,6 +909,7 @@ class WaylandRemoteShell : public ash::TabletModeObserver,
void SetUseDefaultScaleCancellation(bool use_default_scale) { void SetUseDefaultScaleCancellation(bool use_default_scale) {
use_default_scale_cancellation_ = use_default_scale; use_default_scale_cancellation_ = use_default_scale;
WMHelper::GetInstance()->SetDefaultScaleCancellation(use_default_scale);
} }
// TODO(mukai, oshima): rewrite this through delegate-style instead of // TODO(mukai, oshima): rewrite this through delegate-style instead of
......
...@@ -123,6 +123,8 @@ class WMHelper : public aura::client::DragDropDelegate { ...@@ -123,6 +123,8 @@ class WMHelper : public aura::client::DragDropDelegate {
virtual void RemovePostTargetHandler(ui::EventHandler* handler) = 0; virtual void RemovePostTargetHandler(ui::EventHandler* handler) = 0;
virtual bool InTabletMode() const = 0; virtual bool InTabletMode() const = 0;
virtual double GetDefaultDeviceScaleFactor() const = 0; virtual double GetDefaultDeviceScaleFactor() const = 0;
virtual double GetDeviceScaleFactorForWindow(aura::Window* window) const = 0;
virtual void SetDefaultScaleCancellation(bool default_scale_cancellation) = 0;
virtual void SetImeBlocked(aura::Window* window, bool ime_blocked) = 0; virtual void SetImeBlocked(aura::Window* window, bool ime_blocked) = 0;
virtual bool IsImeBlocked(aura::Window* window) const = 0; virtual bool IsImeBlocked(aura::Window* window) const = 0;
......
...@@ -231,6 +231,20 @@ double WMHelperChromeOS::GetDefaultDeviceScaleFactor() const { ...@@ -231,6 +231,20 @@ double WMHelperChromeOS::GetDefaultDeviceScaleFactor() const {
return display_info.display_modes()[0].device_scale_factor(); return display_info.display_modes()[0].device_scale_factor();
} }
double WMHelperChromeOS::GetDeviceScaleFactorForWindow(
aura::Window* window) const {
if (default_scale_cancellation_)
return GetDefaultDeviceScaleFactor();
const display::Screen* screen = display::Screen::GetScreen();
display::Display display = screen->GetDisplayNearestWindow(window);
return display.device_scale_factor();
}
void WMHelperChromeOS::SetDefaultScaleCancellation(
bool default_scale_cancellation) {
default_scale_cancellation_ = default_scale_cancellation;
}
void WMHelperChromeOS::SetImeBlocked(aura::Window* window, bool ime_blocked) { void WMHelperChromeOS::SetImeBlocked(aura::Window* window, bool ime_blocked) {
DCHECK_EQ(window, window->GetToplevelWindow()); DCHECK_EQ(window, window->GetToplevelWindow());
window->SetProperty(kImeBlockedKey, ime_blocked); window->SetProperty(kImeBlockedKey, ime_blocked);
......
...@@ -96,6 +96,9 @@ class WMHelperChromeOS : public WMHelper, public VSyncTimingManager::Delegate { ...@@ -96,6 +96,9 @@ class WMHelperChromeOS : public WMHelper, public VSyncTimingManager::Delegate {
void RemovePostTargetHandler(ui::EventHandler* handler) override; void RemovePostTargetHandler(ui::EventHandler* handler) override;
bool InTabletMode() const override; bool InTabletMode() const override;
double GetDefaultDeviceScaleFactor() const override; double GetDefaultDeviceScaleFactor() const override;
double GetDeviceScaleFactorForWindow(aura::Window* window) const override;
void SetDefaultScaleCancellation(bool default_scale_cancellation) override;
void SetImeBlocked(aura::Window* window, bool ime_blocked) override; void SetImeBlocked(aura::Window* window, bool ime_blocked) override;
bool IsImeBlocked(aura::Window* window) const override; bool IsImeBlocked(aura::Window* window) const override;
...@@ -118,6 +121,7 @@ class WMHelperChromeOS : public WMHelper, public VSyncTimingManager::Delegate { ...@@ -118,6 +121,7 @@ class WMHelperChromeOS : public WMHelper, public VSyncTimingManager::Delegate {
base::ObserverList<DragDropObserver>::Unchecked drag_drop_observers_; base::ObserverList<DragDropObserver>::Unchecked drag_drop_observers_;
LifetimeManager lifetime_manager_; LifetimeManager lifetime_manager_;
VSyncTimingManager vsync_timing_manager_; VSyncTimingManager vsync_timing_manager_;
bool default_scale_cancellation_ = true;
DISALLOW_COPY_AND_ASSIGN(WMHelperChromeOS); DISALLOW_COPY_AND_ASSIGN(WMHelperChromeOS);
}; };
......
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