Skip to content

Commit

Permalink
arc/gio: Wrap EditLabel into EditLabels
Browse files Browse the repository at this point in the history
This CL wraps the EditLabel into EditLabels for different action types
to make it easier to find corresponding EditLabel for updating key
bindings. It also moves functions from util to EditLabels.

Bug: b/270975630
Test: unittest doesn't break.
Test: Manual test. EditLabel still shows as expected.
Change-Id: Iaf880a61f3bd5833507926e1b2d36ced0af0dfe9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4564797
Reviewed-by: David Jacobo <djacobo@chromium.org>
Auto-Submit: Cici Ruan <cuicuiruan@google.com>
Commit-Queue: Cici Ruan <cuicuiruan@google.com>
Cr-Commit-Position: refs/heads/main@{#1152804}
  • Loading branch information
Cici Ruan authored and Chromium LUCI CQ committed Jun 2, 2023
1 parent 889430c commit 9b74d19
Show file tree
Hide file tree
Showing 11 changed files with 176 additions and 112 deletions.
2 changes: 2 additions & 0 deletions chrome/browser/ash/BUILD.gn
Expand Up @@ -407,6 +407,8 @@ source_set("ash") {
"arc/input_overlay/ui/edit_finish_view.h",
"arc/input_overlay/ui/edit_label.cc",
"arc/input_overlay/ui/edit_label.h",
"arc/input_overlay/ui/edit_labels.cc",
"arc/input_overlay/ui/edit_labels.h",
"arc/input_overlay/ui/editing_list.cc",
"arc/input_overlay/ui/editing_list.h",
"arc/input_overlay/ui/educational_view.cc",
Expand Down
36 changes: 5 additions & 31 deletions chrome/browser/ash/arc/input_overlay/ui/action_view_list_item.cc
Expand Up @@ -11,6 +11,7 @@
#include "ash/style/typography.h"
#include "chrome/browser/ash/arc/input_overlay/actions/action.h"
#include "chrome/browser/ash/arc/input_overlay/display_overlay_controller.h"
#include "chrome/browser/ash/arc/input_overlay/ui/edit_labels.h"
#include "chrome/browser/ash/arc/input_overlay/ui/ui_utils.h"
#include "ui/chromeos/styles/cros_tokens_color_mappings.h"
#include "ui/views/background.h"
Expand All @@ -24,6 +25,8 @@ ActionViewListItem::ActionViewListItem(DisplayOverlayController* controller,
Init();
}

ActionViewListItem::~ActionViewListItem() = default;

void ActionViewListItem::Init() {
SetUseDefaultFillLayout(true);
auto* container = AddChildView(std::make_unique<ash::RoundedContainer>());
Expand All @@ -43,39 +46,10 @@ void ActionViewListItem::Init() {
/*fixed_width=*/0, /*min_width=*/0)
.AddRows(1, /*vertical_resize=*/views::TableLayout::kFixedSize);

switch (action_->GetType()) {
case ActionType::TAP:
SetActionTapListItem(container);
break;
case ActionType::MOVE:
SetActionMoveListItem(container);
break;
default:
NOTREACHED();
}
}

ActionViewListItem::~ActionViewListItem() = default;

void ActionViewListItem::SetActionTapListItem(views::View* container) {
// Set list item as:
// --------------------------
// | |Name tag| |a| |
// --------------------------
// TODO(b/270969479): Replace the hardcoded string.
container->AddChildView(CreateNameTag(u"title", u"sub-title"));
container->AddChildView(CreateActionTapEditForKeyboard(action_));
}

void ActionViewListItem::SetActionMoveListItem(views::View* container) {
// Set list item as:
// -----------------------------
// | |Name tag| |w| |
// | |a|s|d||
// -----------------------------
// TODO(b/270969479): Replace the hardcoded string.
container->AddChildView(CreateNameTag(u"title", u"sub-title"));
container->AddChildView(CreateActionMoveEditForKeyboard(action_));
labels_view_ = container->AddChildView(
EditLabels::CreateEditLabels(controller_, action_));
}

} // namespace arc::input_overlay
Expand Up @@ -11,6 +11,7 @@
namespace arc::input_overlay {

class Action;
class EditLabels;
class DisplayOverlayController;

// ActionViewListItem shows in EditingList and is associated with each of
Expand All @@ -29,12 +30,10 @@ class ActionViewListItem : public views::View {
private:
void Init();

// Set list item of different types.
void SetActionTapListItem(views::View* container);
void SetActionMoveListItem(views::View* container);

raw_ptr<DisplayOverlayController> controller_;
raw_ptr<Action> action_;

raw_ptr<EditLabels> labels_view_ = nullptr;
};

} // namespace arc::input_overlay
Expand Down
13 changes: 3 additions & 10 deletions chrome/browser/ash/arc/input_overlay/ui/button_options_menu.cc
Expand Up @@ -17,6 +17,7 @@
#include "chrome/app/vector_icons/vector_icons.h"
#include "chrome/browser/ash/arc/input_overlay/actions/action.h"
#include "chrome/browser/ash/arc/input_overlay/display_overlay_controller.h"
#include "chrome/browser/ash/arc/input_overlay/ui/edit_labels.h"
#include "chrome/browser/ash/arc/input_overlay/ui/ui_utils.h"
#include "components/vector_icons/vector_icons.h"
#include "ui/base/l10n/l10n_util.h"
Expand Down Expand Up @@ -261,16 +262,8 @@ void ButtonOptionsMenu::AddActionEdit() {

// TODO(b/274690042): Replace placeholder text with localized strings.
container->AddChildView(CreateNameTag(u"Selected key", u"Key"));
switch (action_->GetType()) {
case ActionType::TAP:
container->AddChildView(CreateActionTapEditForKeyboard(action_));
break;
case ActionType::MOVE:
container->AddChildView(CreateActionMoveEditForKeyboard(action_));
break;
default:
NOTREACHED();
}
labels_view_ = container->AddChildView(
EditLabels::CreateEditLabels(controller_, action_));
}

void ButtonOptionsMenu::AddActionNameLabel() {
Expand Down
3 changes: 3 additions & 0 deletions chrome/browser/ash/arc/input_overlay/ui/button_options_menu.h
Expand Up @@ -18,6 +18,7 @@ namespace arc::input_overlay {

class Action;
class DisplayOverlayController;
class EditLabels;

// ButtonOptionsMenu displays action's type, input binding(s) and name and it
// can modify these information. It shows up upon clicking an action's touch
Expand Down Expand Up @@ -83,6 +84,8 @@ class ButtonOptionsMenu : public views::View, public TouchInjectorObserver {
// DisplayOverlayController owns this class, no need to deallocate.
const raw_ptr<DisplayOverlayController> controller_ = nullptr;
const raw_ptr<Action> action_ = nullptr;

raw_ptr<EditLabels> labels_view_ = nullptr;
};

} // namespace arc::input_overlay
Expand Down
12 changes: 10 additions & 2 deletions chrome/browser/ash/arc/input_overlay/ui/edit_label.cc
Expand Up @@ -8,7 +8,10 @@
#include "ash/style/typography.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/ash/arc/input_overlay/actions/action.h"
#include "chrome/browser/ash/arc/input_overlay/actions/input_element.h"
#include "chrome/browser/ash/arc/input_overlay/display_overlay_controller.h"
#include "chrome/browser/ash/arc/input_overlay/ui/ui_utils.h"
#include "chrome/browser/ash/arc/input_overlay/util.h"
#include "chromeos/strings/grit/chromeos_strings.h"
#include "ui/accessibility/ax_enums.mojom.h"
#include "ui/base/l10n/l10n_util.h"
Expand All @@ -19,8 +22,13 @@

namespace arc::input_overlay {

EditLabel::EditLabel(Action* action, size_t index)
: views::LabelButton(), action_(action), index_(index) {
EditLabel::EditLabel(DisplayOverlayController* controller,
Action* action,
size_t index)
: views::LabelButton(),
controller_(controller),
action_(action),
index_(index) {
Init();
}

Expand Down
8 changes: 6 additions & 2 deletions chrome/browser/ash/arc/input_overlay/ui/edit_label.h
Expand Up @@ -14,12 +14,15 @@
namespace arc::input_overlay {

class Action;
class DisplayOverlayController;

// EditLabel shows input mappings and can be edited to change mappings.
class EditLabel : public views::LabelButton {
public:
METADATA_HEADER(EditLabel);
explicit EditLabel(Action* action, size_t index = 0);
EditLabel(DisplayOverlayController* controller,
Action* action,
size_t index = 0);

EditLabel(const EditLabel&) = delete;
EditLabel& operator=(const EditLabel&) = delete;
Expand All @@ -38,7 +41,8 @@ class EditLabel : public views::LabelButton {
void OnFocus() override;
void OnBlur() override;

raw_ptr<Action> action_;
raw_ptr<DisplayOverlayController> controller_ = nullptr;
raw_ptr<Action> action_ = nullptr;
size_t index_ = 0;
};

Expand Down
82 changes: 82 additions & 0 deletions chrome/browser/ash/arc/input_overlay/ui/edit_labels.cc
@@ -0,0 +1,82 @@
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/ash/arc/input_overlay/ui/edit_labels.h"

#include "chrome/browser/ash/arc/input_overlay/actions/action.h"
#include "chrome/browser/ash/arc/input_overlay/ui/edit_label.h"
#include "ui/views/layout/table_layout.h"

namespace arc::input_overlay {

std::unique_ptr<EditLabels> EditLabels::CreateEditLabels(
DisplayOverlayController* controller,
Action* action) {
auto labels = std::make_unique<EditLabels>(controller, action);
labels->Init();
return labels;
}

EditLabels::EditLabels(DisplayOverlayController* controller, Action* action)
: controller_(controller), action_(action) {}

EditLabels::~EditLabels() = default;

void EditLabels::Init() {
switch (action_->GetType()) {
case ActionType::TAP:
InitForActionTapKeyboard();
break;
case ActionType::MOVE:
InitForActionMoveKeyboard();
break;
default:
NOTREACHED();
}
}

void EditLabels::InitForActionTapKeyboard() {
SetUseDefaultFillLayout(true);
labels_.emplace_back(
AddChildView(std::make_unique<EditLabel>(controller_, action_)));
}

void EditLabels::InitForActionMoveKeyboard() {
SetLayoutManager(std::make_unique<views::TableLayout>())
->AddColumn(/*h_align=*/views::LayoutAlignment::kCenter,
/*v_align=*/views::LayoutAlignment::kCenter,
/*horizontal_resize=*/1.0f,
/*size_type=*/views::TableLayout::ColumnSize::kUsePreferred,
/*fixed_width=*/0, /*min_width=*/0)
.AddPaddingColumn(/*horizontal_resize=*/views::TableLayout::kFixedSize,
/*width=*/4)
.AddColumn(/*h_align=*/views::LayoutAlignment::kCenter,
/*v_align=*/views::LayoutAlignment::kCenter,
/*horizontal_resize=*/1.0f,
/*size_type=*/views::TableLayout::ColumnSize::kUsePreferred,
/*fixed_width=*/0, /*min_width=*/0)
.AddPaddingColumn(/*horizontal_resize=*/views::TableLayout::kFixedSize,
/*width=*/4)
.AddColumn(/*h_align=*/views::LayoutAlignment::kCenter,
/*v_align=*/views::LayoutAlignment::kCenter,
/*horizontal_resize=*/1.0f,
/*size_type=*/views::TableLayout::ColumnSize::kUsePreferred,
/*fixed_width=*/0, /*min_width=*/0)
.AddRows(1, /*vertical_resize=*/views::TableLayout::kFixedSize)
.AddPaddingRow(/*vertical_resize=*/views::TableLayout::kFixedSize,
/*height=*/4)
.AddRows(1, /*vertical_resize=*/views::TableLayout::kFixedSize);

for (int i = 0; i < 6; i++) {
// Column 1 row 1 and Column 3 row 1 are empty.
if (i == 0 || i == 2) {
AddChildView(std::make_unique<views::View>());
} else {
labels_.emplace_back(AddChildView(
std::make_unique<EditLabel>(controller_, action_, labels_.size())));
}
}
}

} // namespace arc::input_overlay
59 changes: 59 additions & 0 deletions chrome/browser/ash/arc/input_overlay/ui/edit_labels.h
@@ -0,0 +1,59 @@
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_ASH_ARC_INPUT_OVERLAY_UI_EDIT_LABELS_H_
#define CHROME_BROWSER_ASH_ARC_INPUT_OVERLAY_UI_EDIT_LABELS_H_

#include <memory>
#include <vector>

#include "base/memory/raw_ptr.h"
#include "ui/views/view.h"

namespace arc::input_overlay {

class Action;
class DisplayOverlayController;
class EditLabel;

// EditLabels wraps the input labels belonging to one action.
class EditLabels : public views::View {
public:
// Create key layout view depending on action type.
// ActionTap for keyboard binding:
// -----
// ||a||
// -----
//
// ActionMove for keyboard binding:
// -------------
// | | w | |
// |-----------|
// | a | s | d |
// -------------
static std::unique_ptr<EditLabels> CreateEditLabels(
DisplayOverlayController* controller,
Action* action);

EditLabels(DisplayOverlayController* controller, Action* action);

EditLabels(const EditLabels&) = delete;
EditLabels& operator=(const EditLabels&) = delete;
~EditLabels() override;

private:
friend class EditLabelTest;

void Init();
void InitForActionTapKeyboard();
void InitForActionMoveKeyboard();

raw_ptr<DisplayOverlayController> controller_ = nullptr;
raw_ptr<Action> action_ = nullptr;

std::vector<EditLabel*> labels_;
};
} // namespace arc::input_overlay

#endif // CHROME_BROWSER_ASH_ARC_INPUT_OVERLAY_UI_EDIT_LABELS_H_
50 changes: 3 additions & 47 deletions chrome/browser/ash/arc/input_overlay/ui/ui_utils.cc
Expand Up @@ -7,13 +7,13 @@
#include "ash/bubble/bubble_utils.h"
#include "ash/style/typography.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/ash/arc/input_overlay/actions/action.h"
#include "chrome/browser/ash/arc/input_overlay/ui/edit_label.h"
#include "chrome/browser/ash/arc/input_overlay/constants.h"
#include "chromeos/strings/grit/chromeos_strings.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/chromeos/styles/cros_tokens_color_mappings.h"
#include "ui/events/keycodes/dom/keycode_converter.h"
#include "ui/views/controls/label.h"
#include "ui/views/layout/flex_layout.h"
#include "ui/views/layout/table_layout.h"
#include "ui/views/view.h"

namespace arc::input_overlay {
Expand Down Expand Up @@ -64,50 +64,6 @@ std::unique_ptr<views::View> CreateNameTag(const std::u16string& title,
return name_tag;
}

std::unique_ptr<views::View> CreateActionTapEditForKeyboard(Action* action) {
return std::make_unique<EditLabel>(action);
}

std::unique_ptr<views::View> CreateActionMoveEditForKeyboard(Action* action) {
auto keys = std::make_unique<views::View>();
// Create a 2x3 table with column and row padding of 4.
keys->SetLayoutManager(std::make_unique<views::TableLayout>())
->AddColumn(/*h_align=*/views::LayoutAlignment::kCenter,
/*v_align=*/views::LayoutAlignment::kCenter,
/*horizontal_resize=*/1.0f,
/*size_type=*/views::TableLayout::ColumnSize::kUsePreferred,
/*fixed_width=*/0, /*min_width=*/0)
.AddPaddingColumn(/*horizontal_resize=*/views::TableLayout::kFixedSize,
/*width=*/4)
.AddColumn(/*h_align=*/views::LayoutAlignment::kCenter,
/*v_align=*/views::LayoutAlignment::kCenter,
/*horizontal_resize=*/1.0f,
/*size_type=*/views::TableLayout::ColumnSize::kUsePreferred,
/*fixed_width=*/0, /*min_width=*/0)
.AddPaddingColumn(/*horizontal_resize=*/views::TableLayout::kFixedSize,
/*width=*/4)
.AddColumn(/*h_align=*/views::LayoutAlignment::kCenter,
/*v_align=*/views::LayoutAlignment::kCenter,
/*horizontal_resize=*/1.0f,
/*size_type=*/views::TableLayout::ColumnSize::kUsePreferred,
/*fixed_width=*/0, /*min_width=*/0)
.AddRows(1, /*vertical_resize=*/views::TableLayout::kFixedSize)
.AddPaddingRow(/*vertical_resize=*/views::TableLayout::kFixedSize,
/*height=*/4)
.AddRows(1, /*vertical_resize=*/views::TableLayout::kFixedSize);

int index = 0;
for (int i = 0; i < 6; i++) {
// Column 1 row 1 and Column 3 row 1 are empty.
if (i == 0 || i == 2) {
keys->AddChildView(std::make_unique<views::View>());
} else {
keys->AddChildView(std::make_unique<EditLabel>(action, index++));
}
}
return keys;
}

std::u16string GetDisplayText(const ui::DomCode code) {
switch (code) {
case ui::DomCode::NONE:
Expand Down

0 comments on commit 9b74d19

Please sign in to comment.