Commit 7315b5e3 authored by Yuichiro Hanada's avatar Yuichiro Hanada Committed by Commit Bot

Use default scale factor to calculate size of the window of VK.

To use the same value as used in Android side.

Bug: 807545
Test: Manual on a device. Added unit tests.
Change-Id: I04c54e047884a42b019e2d1de69343ce2b89ce60
Reviewed-on: https://chromium-review.googlesource.com/895127
Commit-Queue: Yuichiro Hanada <yhanada@chromium.org>
Reviewed-by: default avatarHidehiko Abe <hidehiko@chromium.org>
Reviewed-by: default avatarKazuhiro Inaba <kinaba@chromium.org>
Cr-Commit-Position: refs/heads/master@{#536972}
parent c32aac7c
...@@ -28,6 +28,16 @@ namespace arc { ...@@ -28,6 +28,16 @@ namespace arc {
namespace { namespace {
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)
...@@ -283,11 +293,16 @@ void ArcImeService::OnKeyboardAppearanceChanged( ...@@ -283,11 +293,16 @@ void ArcImeService::OnKeyboardAppearanceChanged(
const keyboard::KeyboardStateDescriptor& state) { const keyboard::KeyboardStateDescriptor& state) {
if (!focused_arc_window_) if (!focused_arc_window_)
return; return;
aura::Window* window = focused_arc_window_;
gfx::Rect new_bounds = state.occluded_bounds; gfx::Rect new_bounds = state.occluded_bounds;
// Multiply by the scale factor. To convert from DPI to physical pixels. // Multiply by the scale factor. To convert from DIP to physical pixels.
gfx::Rect bounds_in_px = gfx::ScaleToEnclosingRect( // The default scale factor is always used in Android side regardless of
new_bounds, window->layer()->device_scale_factor()); // 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::ScaleToEnclosingRect(new_bounds, GetDefaultDeviceScaleFactor());
ime_bridge_->SendOnKeyboardAppearanceChanging(bounds_in_px, ime_bridge_->SendOnKeyboardAppearanceChanging(bounds_in_px,
state.is_available); state.is_available);
...@@ -379,8 +394,11 @@ gfx::Rect ArcImeService::GetCaretBounds() const { ...@@ -379,8 +394,11 @@ gfx::Rect ArcImeService::GetCaretBounds() const {
// device independent pixels. Two factors are involved for the conversion. // device independent pixels. Two factors are involved for the conversion.
// Divide by the scale factor. To convert from physical pixels to DIP. // Divide by the scale factor. To convert from physical pixels to DIP.
// The default scale factor is always used because Android side is always
// using the default scale factor regardless of dynamic scale factor in Chrome
// side.
gfx::Rect converted = gfx::ScaleToEnclosingRect( gfx::Rect converted = gfx::ScaleToEnclosingRect(
cursor_rect_, 1 / window->layer()->device_scale_factor()); cursor_rect_, 1.0 / GetDefaultDeviceScaleFactor());
// Add the offset of the window showing the ARC app. // Add the offset of the window showing the ARC app.
// TODO(yoshiki): Support for non-arc toplevel window. The following code do // TODO(yoshiki): Support for non-arc toplevel window. The following code do
...@@ -475,6 +493,12 @@ const std::string& ArcImeService::GetClientSourceInfo() const { ...@@ -475,6 +493,12 @@ const std::string& ArcImeService::GetClientSourceInfo() const {
return base::EmptyString(); return base::EmptyString();
} }
// static
void ArcImeService::SetOverrideDefaultDeviceScaleFactorForTesting(
base::Optional<double> scale_factor) {
g_override_default_device_scale_factor = scale_factor;
}
void ArcImeService::InvalidateSurroundingTextAndSelectionRange() { void ArcImeService::InvalidateSurroundingTextAndSelectionRange() {
text_range_ = gfx::Range::InvalidRange(); text_range_ = gfx::Range::InvalidRange();
text_in_range_ = base::string16(); text_in_range_ = base::string16();
......
...@@ -134,6 +134,11 @@ class ArcImeService : public KeyedService, ...@@ -134,6 +134,11 @@ class ArcImeService : public KeyedService,
} }
const std::string& GetClientSourceInfo() const override; const std::string& GetClientSourceInfo() const override;
// Normally, the default device scale factor is used to convert from DPI to
// physical pixels. This method provides a way to override it for testing.
static void SetOverrideDefaultDeviceScaleFactorForTesting(
base::Optional<double> scale_factor);
private: private:
ui::InputMethod* GetInputMethod(); ui::InputMethod* GetInputMethod();
......
...@@ -26,7 +26,8 @@ namespace { ...@@ -26,7 +26,8 @@ namespace {
class FakeArcImeBridge : public ArcImeBridge { class FakeArcImeBridge : public ArcImeBridge {
public: public:
FakeArcImeBridge() : count_send_insert_text_(0) {} FakeArcImeBridge()
: count_send_insert_text_(0), last_keyboard_availability_(false) {}
void SendSetCompositionText(const ui::CompositionText& composition) override { void SendSetCompositionText(const ui::CompositionText& composition) override {
} }
...@@ -39,12 +40,22 @@ class FakeArcImeBridge : public ArcImeBridge { ...@@ -39,12 +40,22 @@ class FakeArcImeBridge : public ArcImeBridge {
} }
void SendOnKeyboardAppearanceChanging(const gfx::Rect& new_bounds, void SendOnKeyboardAppearanceChanging(const gfx::Rect& new_bounds,
bool is_available) override { bool is_available) override {
last_keyboard_bounds_ = new_bounds;
last_keyboard_availability_ = is_available;
} }
int count_send_insert_text() const { return count_send_insert_text_; } int count_send_insert_text() const { return count_send_insert_text_; }
const gfx::Rect& last_keyboard_bounds() const {
return last_keyboard_bounds_;
}
bool last_keyboard_availability() const {
return last_keyboard_availability_;
}
private: private:
int count_send_insert_text_; int count_send_insert_text_;
gfx::Rect last_keyboard_bounds_;
bool last_keyboard_availability_;
}; };
class FakeInputMethod : public ui::DummyInputMethod { class FakeInputMethod : public ui::DummyInputMethod {
...@@ -167,6 +178,7 @@ class ArcImeServiceTest : public testing::Test { ...@@ -167,6 +178,7 @@ class ArcImeServiceTest : public testing::Test {
} }
void TearDown() override { void TearDown() override {
ArcImeService::SetOverrideDefaultDeviceScaleFactorForTesting(base::nullopt);
arc_win_.reset(); arc_win_.reset();
fake_window_delegate_ = nullptr; fake_window_delegate_ = nullptr;
fake_arc_ime_bridge_ = nullptr; fake_arc_ime_bridge_ = nullptr;
...@@ -317,4 +329,45 @@ TEST_F(ArcImeServiceTest, GetTextFromRange) { ...@@ -317,4 +329,45 @@ TEST_F(ArcImeServiceTest, GetTextFromRange) {
EXPECT_EQ(selection_range, temp); EXPECT_EQ(selection_range, temp);
} }
TEST_F(ArcImeServiceTest, OnKeyboardAppearanceChanged) {
instance_->OnWindowFocused(arc_win_.get(), nullptr);
EXPECT_EQ(gfx::Rect(), fake_arc_ime_bridge_->last_keyboard_bounds());
EXPECT_FALSE(fake_arc_ime_bridge_->last_keyboard_availability());
const gfx::Rect keyboard_bounds(0, 480, 1200, 320);
keyboard::KeyboardStateDescriptor desc1{true, false, keyboard_bounds,
keyboard_bounds, keyboard_bounds};
instance_->OnKeyboardAppearanceChanged(desc1);
EXPECT_EQ(keyboard_bounds, fake_arc_ime_bridge_->last_keyboard_bounds());
EXPECT_TRUE(fake_arc_ime_bridge_->last_keyboard_availability());
// Change the default scale factor of the internal display.
const double new_scale_factor = 10.0;
const gfx::Rect new_keyboard_bounds(
0 * new_scale_factor, 480 * new_scale_factor, 1200 * new_scale_factor,
320 * new_scale_factor);
instance_->SetOverrideDefaultDeviceScaleFactorForTesting(new_scale_factor);
// Keyboard bounds passed to Android should be changed.
instance_->OnKeyboardAppearanceChanged(desc1);
EXPECT_EQ(new_keyboard_bounds, fake_arc_ime_bridge_->last_keyboard_bounds());
EXPECT_TRUE(fake_arc_ime_bridge_->last_keyboard_availability());
}
TEST_F(ArcImeServiceTest, GetCaretBounds) {
EXPECT_EQ(gfx::Rect(), instance_->GetCaretBounds());
instance_->OnWindowFocused(arc_win_.get(), nullptr);
const gfx::Rect cursor_rect(10, 12, 2, 8);
instance_->OnCursorRectChanged(cursor_rect);
EXPECT_EQ(cursor_rect, instance_->GetCaretBounds());
const double new_scale_factor = 10.0;
const gfx::Rect new_cursor_rect(10 * new_scale_factor, 12 * new_scale_factor,
2 * new_scale_factor, 8 * new_scale_factor);
instance_->SetOverrideDefaultDeviceScaleFactorForTesting(new_scale_factor);
instance_->OnCursorRectChanged(new_cursor_rect);
EXPECT_EQ(cursor_rect, instance_->GetCaretBounds());
}
} // namespace arc } // namespace arc
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