Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
arc/gio: Wrap EditLabel into EditLabels
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
Showing
11 changed files
with
176 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.