Commit aad8b28a authored by Shawn Gallea's avatar Shawn Gallea Committed by Commit Bot

EXO: Refactored text input interface into its own file

Moved text_input_manager_v1 interface into another file,
to be followed by refactoring of more protocols.

Refactor wayland_text_input_delegate.* from server.cc
with no new code.

Modify server_util to add more utilities

Bug: 896710
Test: Compiled on ChromeOS.
Change-Id: I2739c538a16640fdaebed1cd7493d300dd42a5a9
Reviewed-on: https://chromium-review.googlesource.com/c/1306406Reviewed-by: default avatarDaniele Castagna <dcastagna@chromium.org>
Reviewed-by: default avatarDaniel Nicoara <dnicoara@chromium.org>
Commit-Queue: Shawn Gallea <sagallea@google.com>
Cr-Commit-Position: refs/heads/master@{#607738}
parent f347ba6a
......@@ -33,9 +33,12 @@ source_set("wayland") {
"scoped_wl.h",
"server.cc",
"server.h",
"server_util.cc",
"server_util.h",
"zcr_notification_shell.cc",
"zcr_notification_shell.h",
"zwp_text_input_manager.cc",
"zwp_text_input_manager.h",
]
defines = [ "EXO_IMPLEMENTATION" ]
......
This diff is collapsed.
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/exo/wayland/server_util.h"
#include "base/time/time.h"
#include "components/exo/data_offer.h"
#include "ui/display/display.h"
#include "ui/gfx/geometry/insets.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/size.h"
namespace exo {
namespace wayland {
namespace {
// A property key containing the surface resource that is associated with
// window. If unset, no surface resource is associated with surface object.
DEFINE_UI_CLASS_PROPERTY_KEY(wl_resource*, kSurfaceResourceKey, nullptr);
// A property key containing the data offer resource that is associated with
// data offer object.
DEFINE_UI_CLASS_PROPERTY_KEY(wl_resource*, kDataOfferResourceKey, nullptr);
} // namespace
uint32_t TimeTicksToMilliseconds(base::TimeTicks ticks) {
return (ticks - base::TimeTicks()).InMilliseconds();
}
uint32_t NowInMilliseconds() {
return TimeTicksToMilliseconds(base::TimeTicks::Now());
}
wl_resource* GetSurfaceResource(Surface* surface) {
return surface->GetProperty(kSurfaceResourceKey);
}
void SetSurfaceResource(Surface* surface, wl_resource* resource) {
surface->SetProperty(kSurfaceResourceKey, resource);
}
wl_resource* GetDataOfferResource(const DataOffer* data_offer) {
return data_offer->GetProperty(kDataOfferResourceKey);
}
void SetDataOfferResource(DataOffer* data_offer,
wl_resource* data_offer_resource) {
data_offer->SetProperty(kDataOfferResourceKey, data_offer_resource);
}
// Scale the |child_bounds| in such a way that if it should fill the
// |parent_size|'s width/height, it returns the |parent_size_in_pixel|'s
// width/height.
gfx::Rect ScaleBoundsToPixelSnappedToParent(
const gfx::Size& parent_size_in_pixel,
const gfx::Size& parent_size,
float device_scale_factor,
const gfx::Rect& child_bounds) {
int right = child_bounds.right();
int bottom = child_bounds.bottom();
int new_x = std::round(child_bounds.x() * device_scale_factor);
int new_y = std::round(child_bounds.y() * device_scale_factor);
int new_right = right == parent_size.width()
? parent_size_in_pixel.width()
: std::round(right * device_scale_factor);
int new_bottom = bottom == parent_size.height()
? parent_size_in_pixel.height()
: std::round(bottom * device_scale_factor);
return gfx::Rect(new_x, new_y, new_right - new_x, new_bottom - new_y);
}
// Create the insets make sure that work area will be within the chrome's
// work area when converted to the pixel on client side.
// TODO(oshima): We should send these information in pixel so that
// client do not have to convert it back.
gfx::Insets GetAdjustedInsets(const display::Display& display) {
float scale = display.device_scale_factor();
gfx::Size size_in_pixel = display.GetSizeInPixel();
gfx::Rect work_area_in_display = display.work_area();
work_area_in_display.Offset(-display.bounds().x(), -display.bounds().y());
gfx::Rect work_area_in_pixel = ScaleBoundsToPixelSnappedToParent(
size_in_pixel, display.bounds().size(), scale, work_area_in_display);
gfx::Insets insets_in_pixel =
gfx::Rect(size_in_pixel).InsetsFrom(work_area_in_pixel);
return gfx::Insets(std::ceil(insets_in_pixel.top() / scale),
std::ceil(insets_in_pixel.left() / scale),
std::ceil(insets_in_pixel.bottom() / scale),
std::ceil(insets_in_pixel.right() / scale));
}
} // namespace wayland
} // namespace exo
......@@ -10,8 +10,26 @@
#include <memory>
#include "base/memory/ptr_util.h"
#include "base/time/time.h"
#include "components/exo/surface.h"
#include "ui/base/class_property.h"
struct wl_resource;
namespace display {
class Display;
}
namespace gfx {
class Insets;
class Rect;
class Size;
} // namespace gfx
namespace exo {
class DataOffer;
namespace wayland {
template <class T>
......@@ -39,6 +57,34 @@ void SetImplementation(wl_resource* resource,
DestroyUserData<T>);
}
// Convert a timestamp to a time value that can be used when interfacing
// with wayland. Note that we cast a int64_t value to uint32_t which can
// potentially overflow.
uint32_t TimeTicksToMilliseconds(base::TimeTicks ticks);
uint32_t NowInMilliseconds();
wl_resource* GetSurfaceResource(Surface* surface);
void SetSurfaceResource(Surface* surface, wl_resource* resource);
wl_resource* GetDataOfferResource(const DataOffer* data_offer);
void SetDataOfferResource(DataOffer* data_offer,
wl_resource* data_offer_resource);
// Scale the |child_bounds| in such a way that if it should fill the
// |parent_size|'s width/height, it returns the |parent_size_in_pixel|'s
// width/height.
gfx::Rect ScaleBoundsToPixelSnappedToParent(
const gfx::Size& parent_size_in_pixel,
const gfx::Size& parent_size,
float device_scale_factor,
const gfx::Rect& child_bounds);
// Create the insets make sure that work area will be within the chrome's
// work area when converted to the pixel on client side.
// TODO(oshima): We should send these information in pixel so that
// client do not have to convert it back.
gfx::Insets GetAdjustedInsets(const display::Display& display);
} // namespace wayland
} // namespace exo
......
This diff is collapsed.
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_EXO_WAYLAND_ZWP_TEXT_INPUT_MANAGER_H_
#define COMPONENTS_EXO_WAYLAND_ZWP_TEXT_INPUT_MANAGER_H_
#include <stdint.h>
struct wl_client;
namespace exo {
namespace wayland {
void bind_text_input_manager(wl_client* client,
void* data,
uint32_t version,
uint32_t id);
} // namespace wayland
} // namespace exo
#endif // COMPONENTS_EXO_WAYLAND_ZWP_TEXT_INPUT_MANAGER_H_
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