Commit 4ce22a24 authored by Steven Bennetts's avatar Steven Bennetts Committed by Commit Bot

ash.mojom.KeyboardController: Pass bounds as screen coordinates.

Bounds passed over mojo should be in Screen coordinates since
Chrome and Ash do not share a common window tree in Mash.

For comment-only change to keyboard_controller.mojom:
TBR=tsepez@chromium.org

Bug: 843332
Change-Id: I40cee828ee5872cf69c4589141a9bb79c7c08cee
Reviewed-on: https://chromium-review.googlesource.com/c/1351801
Commit-Queue: Steven Bennetts <stevenjb@chromium.org>
Reviewed-by: default avatarSteven Bennetts <stevenjb@chromium.org>
Reviewed-by: default avatarDarren Shen <shend@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#611324}
parent d4af9eee
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/rect.h"
#include "ui/keyboard/keyboard_controller.h" #include "ui/keyboard/keyboard_controller.h"
#include "ui/keyboard/keyboard_ui.h" #include "ui/keyboard/keyboard_ui.h"
#include "ui/wm/core/coordinate_conversion.h"
using keyboard::mojom::KeyboardConfig; using keyboard::mojom::KeyboardConfig;
using keyboard::mojom::KeyboardConfigPtr; using keyboard::mojom::KeyboardConfigPtr;
...@@ -264,15 +265,21 @@ void AshKeyboardController::OnKeyboardVisibilityStateChanged(bool is_visible) { ...@@ -264,15 +265,21 @@ void AshKeyboardController::OnKeyboardVisibilityStateChanged(bool is_visible) {
void AshKeyboardController::OnKeyboardVisibleBoundsChanged( void AshKeyboardController::OnKeyboardVisibleBoundsChanged(
const gfx::Rect& bounds) { const gfx::Rect& bounds) {
observers_.ForAllPtrs([&bounds](mojom::KeyboardControllerObserver* observer) { // Pass the bounds in screen coordinates over mojo.
observer->OnKeyboardVisibleBoundsChanged(bounds); gfx::Rect screen_bounds = BoundsToScreen(bounds);
observers_.ForAllPtrs(
[&screen_bounds](mojom::KeyboardControllerObserver* observer) {
observer->OnKeyboardVisibleBoundsChanged(screen_bounds);
}); });
} }
void AshKeyboardController::OnKeyboardWorkspaceOccludedBoundsChanged( void AshKeyboardController::OnKeyboardWorkspaceOccludedBoundsChanged(
const gfx::Rect& bounds) { const gfx::Rect& bounds) {
observers_.ForAllPtrs([&bounds](mojom::KeyboardControllerObserver* observer) { // Pass the bounds in screen coordinates over mojo.
observer->OnKeyboardOccludedBoundsChanged(bounds); gfx::Rect screen_bounds = BoundsToScreen(bounds);
observers_.ForAllPtrs(
[&screen_bounds](mojom::KeyboardControllerObserver* observer) {
observer->OnKeyboardOccludedBoundsChanged(screen_bounds);
}); });
} }
...@@ -292,4 +299,12 @@ void AshKeyboardController::OnKeyboardEnabledChanged(bool is_enabled) { ...@@ -292,4 +299,12 @@ void AshKeyboardController::OnKeyboardEnabledChanged(bool is_enabled) {
}); });
} }
gfx::Rect AshKeyboardController::BoundsToScreen(const gfx::Rect& bounds) {
DCHECK(keyboard_controller_->GetKeyboardWindow());
gfx::Rect screen_bounds(bounds);
::wm::ConvertRectToScreen(keyboard_controller_->GetKeyboardWindow(),
&screen_bounds);
return screen_bounds;
}
} // namespace ash } // namespace ash
...@@ -116,6 +116,8 @@ class ASH_EXPORT AshKeyboardController ...@@ -116,6 +116,8 @@ class ASH_EXPORT AshKeyboardController
override; override;
void OnKeyboardEnabledChanged(bool is_enabled) override; void OnKeyboardEnabledChanged(bool is_enabled) override;
gfx::Rect BoundsToScreen(const gfx::Rect& bounds);
SessionController* session_controller_; // unowned SessionController* session_controller_; // unowned
std::unique_ptr<keyboard::KeyboardController> keyboard_controller_; std::unique_ptr<keyboard::KeyboardController> keyboard_controller_;
std::unique_ptr<VirtualKeyboardController> virtual_keyboard_controller_; std::unique_ptr<VirtualKeyboardController> virtual_keyboard_controller_;
......
...@@ -34,11 +34,13 @@ interface KeyboardControllerObserver { ...@@ -34,11 +34,13 @@ interface KeyboardControllerObserver {
// field is focused or blurred, or the user hides the keyboard. // field is focused or blurred, or the user hides the keyboard.
OnKeyboardVisibilityChanged(bool visible); OnKeyboardVisibilityChanged(bool visible);
// Called when the keyboard bounds change. // Called when the keyboard bounds change. |screen_bounds| is in screen
OnKeyboardVisibleBoundsChanged(gfx.mojom.Rect new_bounds); // coordinates.
OnKeyboardVisibleBoundsChanged(gfx.mojom.Rect screen_bounds);
// Called when the keyboard occluded bounds change. // Called when the keyboard occluded bounds change. |screen_bounds| is in
OnKeyboardOccludedBoundsChanged(gfx.mojom.Rect new_bounds); // screen coordinates.
OnKeyboardOccludedBoundsChanged(gfx.mojom.Rect screen_bounds);
}; };
interface KeyboardController { interface KeyboardController {
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "ui/base/ui_base_features.h" #include "ui/base/ui_base_features.h"
#include "ui/gfx/geometry/insets.h" #include "ui/gfx/geometry/insets.h"
#include "ui/views/view.h" #include "ui/views/view.h"
#include "ui/wm/core/coordinate_conversion.h"
ChromeKeyboardBoundsObserver::ChromeKeyboardBoundsObserver( ChromeKeyboardBoundsObserver::ChromeKeyboardBoundsObserver(
aura::Window* keyboard_window) aura::Window* keyboard_window)
...@@ -32,7 +33,9 @@ ChromeKeyboardBoundsObserver::~ChromeKeyboardBoundsObserver() { ...@@ -32,7 +33,9 @@ ChromeKeyboardBoundsObserver::~ChromeKeyboardBoundsObserver() {
} }
void ChromeKeyboardBoundsObserver::OnKeyboardOccludedBoundsChanged( void ChromeKeyboardBoundsObserver::OnKeyboardOccludedBoundsChanged(
const gfx::Rect& new_bounds) { const gfx::Rect& screen_bounds) {
gfx::Rect new_bounds(screen_bounds);
wm::ConvertRectFromScreen(keyboard_window_, &new_bounds);
UpdateOccludedBounds( UpdateOccludedBounds(
ChromeKeyboardControllerClient::Get()->IsKeyboardOverscrollEnabled() ChromeKeyboardControllerClient::Get()->IsKeyboardOverscrollEnabled()
? new_bounds ? new_bounds
......
...@@ -31,7 +31,7 @@ class ChromeKeyboardBoundsObserver ...@@ -31,7 +31,7 @@ class ChromeKeyboardBoundsObserver
// keyboard::ChromeKeyboardControllerClient::Observer: // keyboard::ChromeKeyboardControllerClient::Observer:
void OnKeyboardVisibilityChanged(bool visible) override {} void OnKeyboardVisibilityChanged(bool visible) override {}
void OnKeyboardOccludedBoundsChanged(const gfx::Rect& new_bounds) override; void OnKeyboardOccludedBoundsChanged(const gfx::Rect& screen_bounds) override;
private: private:
void AddObservedWindow(aura::Window* window); void AddObservedWindow(aura::Window* window);
......
...@@ -281,7 +281,7 @@ void ChromeKeyboardControllerClient::OnKeyboardVisibilityChanged(bool visible) { ...@@ -281,7 +281,7 @@ void ChromeKeyboardControllerClient::OnKeyboardVisibilityChanged(bool visible) {
} }
void ChromeKeyboardControllerClient::OnKeyboardVisibleBoundsChanged( void ChromeKeyboardControllerClient::OnKeyboardVisibleBoundsChanged(
const gfx::Rect& bounds) { const gfx::Rect& screen_bounds) {
Profile* profile = GetProfile(); Profile* profile = GetProfile();
extensions::EventRouter* router = extensions::EventRouter::Get(profile); extensions::EventRouter* router = extensions::EventRouter::Get(profile);
// |router| may be null in tests. // |router| may be null in tests.
...@@ -290,12 +290,14 @@ void ChromeKeyboardControllerClient::OnKeyboardVisibleBoundsChanged( ...@@ -290,12 +290,14 @@ void ChromeKeyboardControllerClient::OnKeyboardVisibleBoundsChanged(
return; return;
} }
// Note: |bounds| is in screen coordinates, which is what we want to pass to
// the extension.
auto event_args = std::make_unique<base::ListValue>(); auto event_args = std::make_unique<base::ListValue>();
auto new_bounds = std::make_unique<base::DictionaryValue>(); auto new_bounds = std::make_unique<base::DictionaryValue>();
new_bounds->SetInteger("left", bounds.x()); new_bounds->SetInteger("left", screen_bounds.x());
new_bounds->SetInteger("top", bounds.y()); new_bounds->SetInteger("top", screen_bounds.y());
new_bounds->SetInteger("width", bounds.width()); new_bounds->SetInteger("width", screen_bounds.width());
new_bounds->SetInteger("height", bounds.height()); new_bounds->SetInteger("height", screen_bounds.height());
event_args->Append(std::move(new_bounds)); event_args->Append(std::move(new_bounds));
auto event = std::make_unique<extensions::Event>( auto event = std::make_unique<extensions::Event>(
...@@ -306,9 +308,9 @@ void ChromeKeyboardControllerClient::OnKeyboardVisibleBoundsChanged( ...@@ -306,9 +308,9 @@ void ChromeKeyboardControllerClient::OnKeyboardVisibleBoundsChanged(
} }
void ChromeKeyboardControllerClient::OnKeyboardOccludedBoundsChanged( void ChromeKeyboardControllerClient::OnKeyboardOccludedBoundsChanged(
const gfx::Rect& bounds) { const gfx::Rect& screen_bounds) {
for (auto& observer : observers_) for (auto& observer : observers_)
observer.OnKeyboardOccludedBoundsChanged(bounds); observer.OnKeyboardOccludedBoundsChanged(screen_bounds);
} }
Profile* ChromeKeyboardControllerClient::GetProfile() { Profile* ChromeKeyboardControllerClient::GetProfile() {
......
...@@ -41,7 +41,8 @@ class ChromeKeyboardControllerClient ...@@ -41,7 +41,8 @@ class ChromeKeyboardControllerClient
// Forwards the 'OnKeyboardOccludedBoundsChanged' mojo observer method. // Forwards the 'OnKeyboardOccludedBoundsChanged' mojo observer method.
// This is used by overscrolling. // This is used by overscrolling.
virtual void OnKeyboardOccludedBoundsChanged(const gfx::Rect& new_bounds) {} virtual void OnKeyboardOccludedBoundsChanged(
const gfx::Rect& screen_bounds) {}
// Notifies observers when the keyboard content (i.e. the extension) has // Notifies observers when the keyboard content (i.e. the extension) has
// loaded. Note: if the content is already loaded when the observer is // loaded. Note: if the content is already loaded when the observer is
...@@ -125,8 +126,8 @@ class ChromeKeyboardControllerClient ...@@ -125,8 +126,8 @@ class ChromeKeyboardControllerClient
void OnKeyboardConfigChanged( void OnKeyboardConfigChanged(
keyboard::mojom::KeyboardConfigPtr config) override; keyboard::mojom::KeyboardConfigPtr config) override;
void OnKeyboardVisibilityChanged(bool visible) override; void OnKeyboardVisibilityChanged(bool visible) override;
void OnKeyboardVisibleBoundsChanged(const gfx::Rect& bounds) override; void OnKeyboardVisibleBoundsChanged(const gfx::Rect& screen_bounds) override;
void OnKeyboardOccludedBoundsChanged(const gfx::Rect& bounds) override; void OnKeyboardOccludedBoundsChanged(const gfx::Rect& screen_bounds) override;
// Returns either the test profile or the active user profile. // Returns either the test profile or the active user profile.
Profile* GetProfile(); Profile* GetProfile();
......
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