Commit 02517f2c authored by My Nguyen's avatar My Nguyen Committed by Commit Bot

Use std::unique_ptr in suggestion_view and suggestion_window_view

Also add comment in "suggestion_window_controller_impl.cc"to affirm
there is no memory leak.

Bug: 1060965
Change-Id: Iccb3f2935c1cbdec31c4a260d46a6646c3975edb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2134029Reviewed-by: default avatarDarren Shen <shend@chromium.org>
Reviewed-by: default avatarKeith Lee <keithlee@chromium.org>
Commit-Queue: My Nguyen <myy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#756569}
parent 698e4349
......@@ -41,6 +41,7 @@ void SuggestionWindowControllerImpl::Init() {
active_window ? active_window->GetRootWindow()
: ash::Shell::GetRootWindowForNewWindows(),
ash::kShellWindowId_VirtualKeyboardContainer);
// suggestion_window_view_ is deleted by DialogDelegateView::DeleteDelegate.
suggestion_window_view_ = new ui::ime::SuggestionWindowView(
parent, ash::kShellWindowId_VirtualKeyboardContainer);
views::Widget* widget = suggestion_window_view_->InitWidget();
......
......@@ -19,10 +19,9 @@ namespace {
// Creates the suggestion label, and returns it (never returns nullptr).
// The label text is not set in this function.
views::Label* CreateSuggestionLabel() {
// Create the suggestion label. The label will be added to |this| as a
// child view, hence it's deleted when |this| is deleted.
views::Label* suggestion_label = new views::Label;
std::unique_ptr<views::Label> CreateSuggestionLabel() {
std::unique_ptr<views::Label> suggestion_label =
std::make_unique<views::Label>();
suggestion_label->SetFontList(kSuggestionFont);
suggestion_label->SetEnabledColor(kSuggestionLabelColor);
......@@ -34,8 +33,9 @@ views::Label* CreateSuggestionLabel() {
}
// Creates the "tab" annotation label, and return it (never returns nullptr).
views::Label* CreateAnnotationLabel() {
views::Label* annotation_label = new views::Label;
std::unique_ptr<views::Label> CreateAnnotationLabel() {
std::unique_ptr<views::Label> annotation_label =
std::make_unique<views::Label>();
annotation_label->SetFontList(kAnnotationFont);
annotation_label->SetEnabledColor(kSuggestionLabelColor);
annotation_label->SetHorizontalAlignment(gfx::ALIGN_CENTER);
......@@ -54,17 +54,13 @@ views::Label* CreateAnnotationLabel() {
} // namespace
SuggestionView::SuggestionView()
: suggestion_label_(nullptr),
annotation_label_(nullptr),
suggestion_width_(0) {
suggestion_label_ = CreateSuggestionLabel();
annotation_label_ = CreateAnnotationLabel();
AddChildView(suggestion_label_);
AddChildView(annotation_label_);
SuggestionView::SuggestionView() {
suggestion_label_ = AddChildView(CreateSuggestionLabel());
annotation_label_ = AddChildView(CreateAnnotationLabel());
}
SuggestionView::~SuggestionView() = default;
void SuggestionView::SetText(const base::string16& text) {
suggestion_label_->SetText(text);
suggestion_width_ = suggestion_label_->GetPreferredSize().width();
......
......@@ -39,7 +39,7 @@ constexpr SkColor kSuggestionLabelColor =
class UI_CHROMEOS_EXPORT SuggestionView : public views::View {
public:
SuggestionView();
~SuggestionView() override {}
~SuggestionView() override;
void SetText(const base::string16& text);
......@@ -56,11 +56,11 @@ class UI_CHROMEOS_EXPORT SuggestionView : public views::View {
// child views will be deleted when |this| is deleted.
// The suggestion label renders suggestions.
views::Label* suggestion_label_;
views::Label* suggestion_label_ = nullptr;
// The annotation label renders annotations.
views::Label* annotation_label_;
views::Label* annotation_label_ = nullptr;
int suggestion_width_;
int suggestion_width_ = 0;
DISALLOW_COPY_AND_ASSIGN(SuggestionView);
};
......
......@@ -66,12 +66,10 @@ SuggestionWindowView::SuggestionWindowView(gfx::NativeView parent,
SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kVertical));
suggestion_view_ = new SuggestionView();
AddChildView(suggestion_view_);
suggestion_view_ = AddChildView(std::make_unique<SuggestionView>());
}
SuggestionWindowView::~SuggestionWindowView() {}
SuggestionWindowView::~SuggestionWindowView() = default;
views::Widget* SuggestionWindowView::InitWidget() {
views::Widget* widget = BubbleDialogDelegateView::CreateBubble(this);
......
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