Commit 45f81520 authored by Allen Bauer's avatar Allen Bauer Committed by Commit Bot

Remove use of raw-pointer version of AddChildView and DCAA macro.

Bug: 648382
Bug: 1010217
Change-Id: I1da966eb685b96832017317853c90fb3d744a491
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2353058
Commit-Queue: Allen Bauer <kylixrd@chromium.org>
Reviewed-by: default avatarToni Baržić <tbarzic@chromium.org>
Cr-Commit-Position: refs/heads/master@{#798270}
parent 9e856463
......@@ -111,41 +111,42 @@ void ContentsView::Init(AppListModel* model) {
AppListViewDelegate* view_delegate = GetAppListMainView()->view_delegate();
apps_container_view_ = new AppsContainerView(this, model);
AddLauncherPage(apps_container_view_, AppListState::kStateApps);
apps_container_view_ =
AddLauncherPage(std::make_unique<AppsContainerView>(this, model),
AppListState::kStateApps);
// Search results UI.
search_results_page_view_ =
new SearchResultPageView(view_delegate, view_delegate->GetSearchModel());
auto search_results_page_view = std::make_unique<SearchResultPageView>(
view_delegate, view_delegate->GetSearchModel());
// Search result containers:
if (app_list_features::IsAnswerCardEnabled()) {
search_result_answer_card_view_ =
new SearchResultAnswerCardView(view_delegate);
search_results_page_view_->AddSearchResultContainerView(
search_result_answer_card_view_);
search_results_page_view->AddSearchResultContainerView(
std::make_unique<SearchResultAnswerCardView>(view_delegate));
}
expand_arrow_view_ =
AddChildView(std::make_unique<ExpandArrowView>(this, app_list_view_));
search_result_tile_item_list_view_ = new SearchResultTileItemListView(
GetSearchBoxView()->search_box(), view_delegate);
search_results_page_view_->AddSearchResultContainerView(
search_result_tile_item_list_view_);
search_result_tile_item_list_view_ =
search_results_page_view->AddSearchResultContainerView(
std::make_unique<SearchResultTileItemListView>(
GetSearchBoxView()->search_box(), view_delegate));
search_result_list_view_ =
new SearchResultListView(GetAppListMainView(), view_delegate);
search_results_page_view_->AddSearchResultContainerView(
search_result_list_view_);
search_results_page_view->AddSearchResultContainerView(
std::make_unique<SearchResultListView>(GetAppListMainView(),
view_delegate));
AddLauncherPage(search_results_page_view_, AppListState::kStateSearchResults);
search_results_page_view_ = AddLauncherPage(
std::move(search_results_page_view), AppListState::kStateSearchResults);
assistant_page_view_ =
new AssistantPageView(view_delegate->GetAssistantViewDelegate());
assistant_page_view_->SetVisible(false);
AddLauncherPage(assistant_page_view_, AppListState::kStateEmbeddedAssistant);
auto assistant_page_view = std::make_unique<AssistantPageView>(
view_delegate->GetAssistantViewDelegate());
assistant_page_view->SetVisible(false);
assistant_page_view_ = AddLauncherPage(std::move(assistant_page_view),
AppListState::kStateEmbeddedAssistant);
int initial_page_index = GetPageIndexForState(AppListState::kStateApps);
DCHECK_GE(initial_page_index, 0);
......@@ -490,15 +491,11 @@ AppListMainView* ContentsView::GetAppListMainView() const {
return app_list_view_->app_list_main_view();
}
int ContentsView::AddLauncherPage(AppListPage* view) {
void ContentsView::AddLauncherPageInternal(std::unique_ptr<AppListPage> view,
AppListState state) {
view->set_contents_view(this);
AddChildView(view);
app_list_pages_.push_back(view);
return app_list_pages_.size() - 1;
}
int ContentsView::AddLauncherPage(AppListPage* view, AppListState state) {
int page_index = AddLauncherPage(view);
app_list_pages_.push_back(AddChildView(std::move(view)));
int page_index = app_list_pages_.size() - 1;
bool success =
state_to_view_.insert(std::make_pair(state, page_index)).second;
success = success &&
......@@ -506,7 +503,6 @@ int ContentsView::AddLauncherPage(AppListPage* view, AppListState state) {
// There shouldn't be duplicates in either map.
DCHECK(success);
return page_index;
}
gfx::Rect ContentsView::GetSearchBoxBounds(AppListState state) const {
......
......@@ -237,15 +237,19 @@ class APP_LIST_EXPORT ContentsView : public views::View,
// Updates search box visibility based on the current state.
void UpdateSearchBoxVisibility(AppListState current_state);
// Adds |view| as a new page to the end of the list of launcher pages. The
// view is inserted as a child of the ContentsView. There is no name
// associated with the page. Returns the index of the new page.
int AddLauncherPage(AppListPage* view);
// Adds |view| as a new page to the end of the list of launcher pages. The
// view is inserted as a child of the ContentsView. The page is associated
// with the name |state|. Returns the index of the new page.
int AddLauncherPage(AppListPage* view, AppListState state);
// with the name |state|. Returns a pointer to the instance of the new page.
template <typename T>
T* AddLauncherPage(std::unique_ptr<T> view, AppListState state) {
auto* result = view.get();
AddLauncherPageInternal(std::move(view), state);
return result;
}
// Internal version of the above that does the actual work.
void AddLauncherPageInternal(std::unique_ptr<AppListPage> view,
AppListState state);
// Gets the PaginationModel owned by the AppsGridView.
// Note: This is different to |pagination_model_|, which manages top-level
......
......@@ -7,7 +7,6 @@
#include <stddef.h>
#include <algorithm>
#include <utility>
#include "ash/app_list/app_list_util.h"
#include "ash/app_list/app_list_view_delegate.h"
......@@ -44,6 +43,8 @@
#include "ui/views/focus/focus_manager.h"
#include "ui/views/layout/box_layout.h"
#include "ui/views/layout/fill_layout.h"
#include "ui/views/metadata/metadata_header_macros.h"
#include "ui/views/metadata/metadata_impl_macros.h"
#include "ui/views/window/dialog_delegate.h"
namespace ash {
......@@ -83,20 +84,27 @@ constexpr base::TimeDelta kNotifyA11yDelay =
// in the correct order.
class SearchCardView : public views::View {
public:
explicit SearchCardView(views::View* content_view) {
METADATA_HEADER(SearchCardView);
explicit SearchCardView(std::unique_ptr<views::View> content_view) {
SetLayoutManager(std::make_unique<views::FillLayout>());
AddChildView(content_view);
AddChildView(std::move(content_view));
}
// views::View overrides:
const char* GetClassName() const override { return "SearchCardView"; }
SearchCardView(const SearchCardView&) = delete;
SearchCardView& operator=(const SearchCardView&) = delete;
~SearchCardView() override {}
};
BEGIN_METADATA(SearchCardView)
METADATA_PARENT_CLASS(views::View)
END_METADATA()
class ZeroWidthVerticalScrollBar : public views::OverlayScrollBar {
public:
ZeroWidthVerticalScrollBar() : OverlayScrollBar(false) {}
ZeroWidthVerticalScrollBar(const ZeroWidthVerticalScrollBar&) = delete;
ZeroWidthVerticalScrollBar& operator=(const ZeroWidthVerticalScrollBar&) =
delete;
~ZeroWidthVerticalScrollBar() override = default;
// OverlayScrollBar overrides:
int GetThickness() const override { return 0; }
......@@ -106,9 +114,6 @@ class ZeroWidthVerticalScrollBar : public views::OverlayScrollBar {
// result is focused, it will be set visible in scroll view.
return false;
}
private:
DISALLOW_COPY_AND_ASSIGN(ZeroWidthVerticalScrollBar);
};
class SearchResultPageBackground : public views::Background {
......@@ -116,6 +121,9 @@ class SearchResultPageBackground : public views::Background {
explicit SearchResultPageBackground(SkColor color) {
SetNativeControlColor(color);
}
SearchResultPageBackground(const SearchResultPageBackground&) = delete;
SearchResultPageBackground& operator=(const SearchResultPageBackground&) =
delete;
~SearchResultPageBackground() override = default;
private:
......@@ -130,8 +138,6 @@ class SearchResultPageBackground : public views::Background {
bounds.set_height(kSeparatorThickness);
canvas->FillRect(bounds, kSeparatorColor);
}
DISALLOW_COPY_AND_ASSIGN(SearchResultPageBackground);
};
} // namespace
......@@ -222,17 +228,18 @@ SearchResultPageView::SearchResultPageView(AppListViewDelegate* view_delegate,
SearchResultPageView::~SearchResultPageView() = default;
void SearchResultPageView::AddSearchResultContainerView(
SearchResultContainerView* result_container) {
void SearchResultPageView::AddSearchResultContainerViewInternal(
std::unique_ptr<SearchResultContainerView> result_container) {
if (!result_container_views_.empty()) {
HorizontalSeparator* separator = new HorizontalSeparator(bounds().width());
contents_view_->AddChildView(separator);
separators_.push_back(separator);
separators_.push_back(contents_view_->AddChildView(
std::make_unique<HorizontalSeparator>(bounds().width())));
}
contents_view_->AddChildView(new SearchCardView(result_container));
result_container_views_.push_back(result_container);
result_container->SetResults(search_model_->results());
result_container->set_delegate(this);
auto* result_container_ptr = result_container.get();
contents_view_->AddChildView(
std::make_unique<SearchCardView>(std::move(result_container)));
result_container_views_.push_back(result_container_ptr);
result_container_ptr->SetResults(search_model_->results());
result_container_ptr->set_delegate(this);
}
bool SearchResultPageView::IsFirstResultTile() const {
......
......@@ -6,6 +6,7 @@
#define ASH_APP_LIST_VIEWS_SEARCH_RESULT_PAGE_VIEW_H_
#include <memory>
#include <utility>
#include <vector>
#include "ash/app_list/app_list_export.h"
......@@ -40,8 +41,12 @@ class APP_LIST_EXPORT SearchResultPageView
SearchModel* search_model);
~SearchResultPageView() override;
void AddSearchResultContainerView(
SearchResultContainerView* result_container);
template <typename T>
T* AddSearchResultContainerView(std::unique_ptr<T> result_container) {
auto* result = result_container.get();
AddSearchResultContainerViewInternal(std::move(result_container));
return result;
}
const std::vector<SearchResultContainerView*>& result_container_views() {
return result_container_views_;
......@@ -155,6 +160,9 @@ class APP_LIST_EXPORT SearchResultPageView
// Called when the widget anchored in the search results page gets closed.
void OnAnchoredDialogClosed();
void AddSearchResultContainerViewInternal(
std::unique_ptr<SearchResultContainerView> result_container);
AppListViewDelegate* view_delegate_;
// The search model for which the results are displayed.
......
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