Commit 297ece61 authored by Mikolaj Walczak's avatar Mikolaj Walczak Committed by Commit Bot

Add accelerators for ARC++ specific key events

Create boilerplate for changing density in ARC++
applications on user input (CTRL +/CTRL -/CTRL 0)
to simulate the behaviour of the chrome native apps.
BUG=b:142100473
TEST=Manual

Change-Id: I1e58e1b03b2cc07dfeaff22b0e49436936cbc228
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1847032
Commit-Queue: Mikolaj Walczak <walczakm@google.com>
Reviewed-by: default avatarMitsuru Oshima <oshima@chromium.org>
Cr-Commit-Position: refs/heads/master@{#704961}
parent a510d14c
......@@ -102,6 +102,8 @@ source_set("exo") {
"//chromeos/constants",
]
sources += [
"client_controlled_accelerators.cc",
"client_controlled_accelerators.h",
"client_controlled_shell_surface.cc",
"client_controlled_shell_surface.h",
"gaming_seat.cc",
......
// Copyright 2019 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/client_controlled_accelerators.h"
namespace exo {
ClientControlledAcceleratorTarget::ClientControlledAcceleratorTarget(
ClientControlledShellSurface* surface)
: surface_(surface) {}
ClientControlledAcceleratorTarget::~ClientControlledAcceleratorTarget() =
default;
void ClientControlledAcceleratorTarget::RegisterAccelerator(
const ui::Accelerator& accelerator,
ClientControlledAcceleratorAction action) {
accelerators_.insert(std::make_pair(ui::Accelerator{accelerator}, action));
}
void ClientControlledAcceleratorTarget::RegisterAccelerator(
ui::Accelerator&& accelerator,
ClientControlledAcceleratorAction action) {
accelerators_.insert(std::make_pair(std::move(accelerator), action));
}
bool ClientControlledAcceleratorTarget::AcceleratorPressed(
const ui::Accelerator& accelerator) {
auto it = accelerators_.find(accelerator);
DCHECK(it != accelerators_.end());
ClientControlledAcceleratorAction action = it->second;
switch (action) {
case ClientControlledAcceleratorAction::ZOOM_IN:
surface_->ChangeZoomLevel(ZoomChange::IN);
break;
case ClientControlledAcceleratorAction::ZOOM_OUT:
surface_->ChangeZoomLevel(ZoomChange::OUT);
break;
case ClientControlledAcceleratorAction::ZOOM_RESET:
surface_->ChangeZoomLevel(ZoomChange::RESET);
break;
}
return true;
}
bool ClientControlledAcceleratorTarget::CanHandleAccelerators() const {
return true;
}
} // namespace exo
// Copyright 2019 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_CLIENT_CONTROLLED_ACCELERATORS_H_
#define COMPONENTS_EXO_CLIENT_CONTROLLED_ACCELERATORS_H_
#include "components/exo/client_controlled_shell_surface.h"
#include "ui/aura/window.h"
#include "ui/base/accelerators/accelerator.h"
#include "ui/views/focus/focus_manager.h"
namespace exo {
enum class ClientControlledAcceleratorAction {
ZOOM_IN,
ZOOM_OUT,
ZOOM_RESET,
};
class ClientControlledShellSurface;
class ClientControlledAcceleratorTarget : public ui::AcceleratorTarget {
public:
explicit ClientControlledAcceleratorTarget(
ClientControlledShellSurface* surface);
~ClientControlledAcceleratorTarget() override;
void RegisterAccelerator(const ui::Accelerator& accelerator,
ClientControlledAcceleratorAction action);
void RegisterAccelerator(ui::Accelerator&& accelerator,
ClientControlledAcceleratorAction action);
// ui::AcceleratorTarget interface implementation.
bool AcceleratorPressed(const ui::Accelerator& accelerator) override;
bool CanHandleAccelerators() const override;
private:
ClientControlledShellSurface* surface_;
std::map<ui::Accelerator, ClientControlledAcceleratorAction> accelerators_;
DISALLOW_COPY_AND_ASSIGN(ClientControlledAcceleratorTarget);
};
} // namespace exo
#endif // COMPONENTS_EXO_CLIENT_CONTROLLED_ACCELERATORS_H_
......@@ -55,6 +55,20 @@ namespace exo {
namespace {
// Client controlled specific accelerators.
const struct {
ui::KeyboardCode keycode;
int modifiers;
ClientControlledAcceleratorAction action;
} kAccelerators[] = {
{ui::VKEY_OEM_MINUS, ui::EF_CONTROL_DOWN,
ClientControlledAcceleratorAction::ZOOM_OUT},
{ui::VKEY_OEM_PLUS, ui::EF_CONTROL_DOWN,
ClientControlledAcceleratorAction::ZOOM_IN},
{ui::VKEY_0, ui::EF_CONTROL_DOWN,
ClientControlledAcceleratorAction::ZOOM_RESET},
};
ClientControlledShellSurface::DelegateFactoryCallback& GetFactoryForTesting() {
using CallbackType = ClientControlledShellSurface::DelegateFactoryCallback;
static base::NoDestructor<CallbackType> factory;
......@@ -611,6 +625,10 @@ void ClientControlledShellSurface::OnBoundsChangeEvent(
}
}
void ClientControlledShellSurface::ChangeZoomLevel(ZoomChange change) {
// TODO(walczakm): Send wayland event.
}
void ClientControlledShellSurface::OnDragStarted(int component) {
in_drag_ = true;
if (drag_started_callback_)
......@@ -904,6 +922,19 @@ void ClientControlledShellSurface::InitializeWindowState(
UpdateFrameWidth();
if (initial_orientation_lock_ != ash::OrientationLockType::kAny)
SetOrientationLock(initial_orientation_lock_);
// Register Client controlled accelerators.
views::FocusManager* focus_manager = widget_->GetFocusManager();
accelerator_target_ =
std::make_unique<ClientControlledAcceleratorTarget>(this);
for (const auto& entry : kAccelerators) {
focus_manager->RegisterAccelerator(
ui::Accelerator(entry.keycode, entry.modifiers),
ui::AcceleratorManager::kNormalPriority, accelerator_target_.get());
accelerator_target_->RegisterAccelerator(
ui::Accelerator(entry.keycode, entry.modifiers), entry.action);
}
}
float ClientControlledShellSurface::GetScale() const {
......
......@@ -12,6 +12,7 @@
#include "ash/wm/client_controlled_state.h"
#include "base/callback.h"
#include "base/macros.h"
#include "components/exo/client_controlled_accelerators.h"
#include "components/exo/shell_surface_base.h"
#include "ui/base/hit_test.h"
#include "ui/compositor/compositor_lock.h"
......@@ -30,8 +31,10 @@ enum class WindowPinType;
namespace exo {
class Surface;
class ClientControlledAcceleratorTarget;
enum class Orientation { PORTRAIT, LANDSCAPE };
enum class ZoomChange { IN, OUT, RESET };
// This class implements a ShellSurface whose window state and bounds are
// controlled by a remote shell client rather than the window manager. The
......@@ -154,6 +157,9 @@ class ClientControlledShellSurface : public ShellSurfaceBase,
// Set resize outset for surface.
void SetResizeOutset(int outset);
// Sends the request to change the zoom level to the client.
void ChangeZoomLevel(ZoomChange change);
// Sends the window state change event to client.
void OnWindowStateChangeEvent(ash::WindowStateType old_state,
ash::WindowStateType next_state);
......@@ -340,6 +346,9 @@ class ClientControlledShellSurface : public ShellSurfaceBase,
// True if the window state has changed during the commit.
bool state_changed_ = false;
// Client controlled specific accelerator target.
std::unique_ptr<ClientControlledAcceleratorTarget> accelerator_target_;
DISALLOW_COPY_AND_ASSIGN(ClientControlledShellSurface);
};
......
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