Skip to content

Commit

Permalink
ARC: Take ARC windowing into account for IME coordinates.
Browse files Browse the repository at this point in the history
The previous implementation assumed that the coordinate system
is the same inside and outside ARC. Now, it's not the case.

BUG=b/27368003

Review URL: https://codereview.chromium.org/1835263002

Cr-Commit-Position: refs/heads/master@{#386275}
  • Loading branch information
kinaba authored and Commit bot committed Apr 9, 2016
1 parent 09e881c commit e966a6c
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion components/arc/ime/arc_ime_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "components/arc/ime/arc_ime_bridge_impl.h"
#include "components/exo/shell_surface.h"
#include "components/exo/surface.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/client/focus_client.h"
#include "ui/aura/env.h"
#include "ui/aura/window.h"
Expand All @@ -20,6 +21,15 @@ namespace arc {

namespace {

// The height in DIP of the window titlebar, rendered in client-side (i.e.,
// inside ARC), but outside where ARC apps and IME recognize. Rather than
// to complicate things by wiring the value progaramatically via yet another
// IPC, we just embed the constant here for simplicity.
//
// TODO(kinaba, skuhne): Future version of ARC window management should make
// this host-side offsetting unnecessary. Get rid of this when it's ready.
constexpr int kWindowTitleHeight = 32;

bool IsArcWindow(const aura::Window* window) {
return exo::Surface::AsSurface(window);
}
Expand Down Expand Up @@ -206,7 +216,29 @@ ui::TextInputType ArcImeService::GetTextInputType() const {
}

gfx::Rect ArcImeService::GetCaretBounds() const {
return cursor_rect_;
if (!focused_arc_window_.has_windows())
return gfx::Rect();
aura::Window* window = focused_arc_window_.windows().front();

// |cursor_rect_| holds the rectangle reported from ARC apps, in the "screen
// coordinates" in ARC, counted by physical pixels.
// Chrome OS input methods expect the coordinates in Chrome OS screen, within
// device independent pixels. Three factors are involved for the conversion.

// Divide by the scale factor. To convert from physical pixels to DIP.
gfx::Rect converted = gfx::ScaleToEnclosingRect(
cursor_rect_, 1 / window->layer()->device_scale_factor());

// Add the offset of the window showing the ARC app.
converted.Offset(window->GetBoundsInScreen().OffsetFromOrigin());

// Add the titlebar height (drawn inside ARC.)
// TODO(kinaba, skuhne): This should be absorbed inside ARC in the future.
if (window->GetProperty(aura::client::kShowStateKey) !=
ui::SHOW_STATE_FULLSCREEN) {
converted.Offset(0, kWindowTitleHeight);
}
return converted;
}

ui::TextInputMode ArcImeService::GetTextInputMode() const {
Expand Down

0 comments on commit e966a6c

Please sign in to comment.