Commit adaa3675 authored by Darren Shen's avatar Darren Shen Committed by Commit Bot

ime: Use unique_ptr for memory management + misc fixes.

Passing unique_ptr to AddChildView as recommended.
Moved some default values to the header file too.

Change-Id: I72f4ca718bf2ac55615a51072b97b970d254e8c6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2134175Reviewed-by: default avatarKeith Lee <keithlee@chromium.org>
Commit-Queue: Darren Shen <shend@chromium.org>
Cr-Commit-Position: refs/heads/master@{#756561}
parent 05bc8d81
......@@ -23,11 +23,10 @@ namespace {
// the vertical candidate window.
class VerticalCandidateLabel : public views::Label {
public:
VerticalCandidateLabel() {}
VerticalCandidateLabel() = default;
~VerticalCandidateLabel() override = default;
private:
~VerticalCandidateLabel() override {}
// views::Label:
// Returns the preferred size, but guarantees that the width has at
// least kMinCandidateLabelWidth pixels.
......@@ -43,15 +42,12 @@ class VerticalCandidateLabel : public views::Label {
DISALLOW_COPY_AND_ASSIGN(VerticalCandidateLabel);
};
// Creates the shortcut label, and returns it (never returns NULL).
// Creates the shortcut label, and returns it (never returns nullptr).
// The label text is not set in this function.
views::Label* CreateShortcutLabel(
std::unique_ptr<views::Label> CreateShortcutLabel(
ui::CandidateWindow::Orientation orientation,
const ui::NativeTheme& theme) {
// Create the shortcut label. The label will be owned by
// |wrapped_shortcut_label|, hence it's deleted when
// |wrapped_shortcut_label| is deleted.
views::Label* shortcut_label = new views::Label;
auto shortcut_label = std::make_unique<views::Label>();
// TODO(tapted): Get this FontList from views::style.
if (orientation == ui::CandidateWindow::VERTICAL) {
......@@ -91,16 +87,14 @@ views::Label* CreateShortcutLabel(
// Creates the candidate label, and returns it (never returns NULL).
// The label text is not set in this function.
views::Label* CreateCandidateLabel(
std::unique_ptr<views::Label> CreateCandidateLabel(
ui::CandidateWindow::Orientation orientation) {
views::Label* candidate_label = NULL;
std::unique_ptr<views::Label> candidate_label;
// Create the candidate label. The label will be added to |this| as a
// child view, hence it's deleted when |this| is deleted.
if (orientation == ui::CandidateWindow::VERTICAL) {
candidate_label = new VerticalCandidateLabel;
candidate_label = std::make_unique<VerticalCandidateLabel>();
} else {
candidate_label = new views::Label;
candidate_label = std::make_unique<views::Label>();
}
// Change the font size.
......@@ -114,11 +108,10 @@ views::Label* CreateCandidateLabel(
// Creates the annotation label, and return it (never returns NULL).
// The label text is not set in this function.
views::Label* CreateAnnotationLabel(
std::unique_ptr<views::Label> CreateAnnotationLabel(
ui::CandidateWindow::Orientation orientation,
const ui::NativeTheme& theme) {
// Create the annotation label.
views::Label* annotation_label = new views::Label;
auto annotation_label = std::make_unique<views::Label>();
// Change the font size and color.
annotation_label->SetFontList(
......@@ -135,31 +128,19 @@ views::Label* CreateAnnotationLabel(
CandidateView::CandidateView(views::ButtonListener* listener,
ui::CandidateWindow::Orientation orientation)
: views::Button(listener),
orientation_(orientation),
shortcut_label_(NULL),
candidate_label_(NULL),
annotation_label_(NULL),
infolist_icon_(NULL),
shortcut_width_(0),
candidate_width_(0),
highlighted_(false) {
: views::Button(listener), orientation_(orientation) {
SetBorder(views::CreateEmptyBorder(1, 1, 1, 1));
const ui::NativeTheme& theme = *GetNativeTheme();
shortcut_label_ = CreateShortcutLabel(orientation, theme);
candidate_label_ = CreateCandidateLabel(orientation);
annotation_label_ = CreateAnnotationLabel(orientation, theme);
AddChildView(shortcut_label_);
AddChildView(candidate_label_);
AddChildView(annotation_label_);
shortcut_label_ = AddChildView(CreateShortcutLabel(orientation, theme));
candidate_label_ = AddChildView(CreateCandidateLabel(orientation));
annotation_label_ = AddChildView(CreateAnnotationLabel(orientation, theme));
if (orientation == ui::CandidateWindow::VERTICAL) {
infolist_icon_ = new views::View;
infolist_icon_->SetBackground(views::CreateSolidBackground(
auto infolist_icon = std::make_unique<views::View>();
infolist_icon->SetBackground(views::CreateSolidBackground(
theme.GetSystemColor(ui::NativeTheme::kColorId_FocusedBorderColor)));
AddChildView(infolist_icon_);
infolist_icon_ = AddChildView(std::move(infolist_icon));
}
}
......
......@@ -56,17 +56,17 @@ class UI_CHROMEOS_EXPORT CandidateView : public views::Button {
// child views will be deleted when |this| is deleted.
// The shortcut label renders shortcut numbers like 1, 2, and 3.
views::Label* shortcut_label_;
views::Label* shortcut_label_ = nullptr;
// The candidate label renders candidates.
views::Label* candidate_label_;
views::Label* candidate_label_ = nullptr;
// The annotation label renders annotations.
views::Label* annotation_label_;
views::Label* annotation_label_ = nullptr;
// The infolist icon.
views::View* infolist_icon_;
views::View* infolist_icon_ = nullptr;
int shortcut_width_;
int candidate_width_;
bool highlighted_;
int shortcut_width_ = 0;
int candidate_width_ = 0;
bool highlighted_ = false;
DISALLOW_COPY_AND_ASSIGN(CandidateView);
};
......
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