Commit 1a8346a5 authored by Weidong Guo's avatar Weidong Guo Committed by Commit Bot

Reland "Disable blur for suggestion chip and folder icon in clamshell mode"

This is a reland of ae60a134

Original change's description:
> Disable blur for suggestion chip and folder icon in clamshell mode
>
> Changes:
> 1. Destroy layer for suggestion chip in clamshell mode.
> 2. Set blur to 0 for folder icon in clammshell mode.
> 3. Avoid recreation of suggestion chip views after update.
>
> Bug: 896525
> Change-Id: I4cb84c06f5e0ed5a0cc70c0c2338028573bd7017
> Reviewed-on: https://chromium-review.googlesource.com/c/1287709
> Reviewed-by: Xiyuan Xia <xiyuan@chromium.org>
> Commit-Queue: Weidong Guo <weidongg@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#600819}

TBR=xiyuan@chromium.org

Bug: 896525
Change-Id: Idd17312d89e759f65a7f4fb5db125f89b96bd9af
Reviewed-on: https://chromium-review.googlesource.com/c/1290133
Commit-Queue: Weidong Guo <weidongg@chromium.org>
Reviewed-by: default avatarWeidong Guo <weidongg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#601213}
parent 31a76c6d
......@@ -138,7 +138,8 @@ class AppListItemView::IconImageView : public views::ImageView {
std::unique_ptr<ui::Layer> old_layer = views::View::RecreateLayer();
// ui::Layer::Clone() does not copy mask layer, so set it explicitly here.
SetRoundedRectMaskLayer(mask_corner_radius_, mask_insets_);
if (mask_corner_radius_ != 0 || !mask_insets_.IsEmpty())
SetRoundedRectMaskLayer(mask_corner_radius_, mask_insets_);
return old_layer;
}
......@@ -162,7 +163,7 @@ class AppListItemView::IconImageView : public views::ImageView {
std::unique_ptr<ui::LayerOwner> icon_mask_;
// The corner radius of mask layer.
int mask_corner_radius_;
int mask_corner_radius_ = 0;
// The insets of the mask layer.
gfx::Insets mask_insets_;
......@@ -198,8 +199,10 @@ AppListItemView::AppListItemView(AppsGridView* apps_grid_view,
if (is_new_style_launcher_enabled_ && is_folder_) {
// Set background blur for folder icon and use mask layer to clip it into
// circle.
icon_->layer()->SetBackgroundBlur(AppListConfig::instance().blur_radius());
// circle. Note that blur is only enabled in tablet mode to improve dragging
// smoothness.
if (apps_grid_view_->IsTabletMode())
SetBackgroundBlurEnabled(true);
icon_->SetRoundedRectMaskLayer(
AppListConfig::instance().folder_icon_radius(),
gfx::Insets(AppListConfig::instance().folder_icon_insets()));
......@@ -745,6 +748,12 @@ void AppListItemView::OnDraggedViewExit() {
dragged_view_hover_animation_->Hide();
}
void AppListItemView::SetBackgroundBlurEnabled(bool enabled) {
DCHECK(is_folder_);
icon_->layer()->SetBackgroundBlur(
enabled ? AppListConfig::instance().blur_radius() : 0);
}
void AppListItemView::AnimationProgressed(const gfx::Animation* animation) {
if (is_folder_) {
// Animate the folder icon via changing mask layer's corner radius and
......
......@@ -131,6 +131,9 @@ class APP_LIST_EXPORT AppListItemView
void OnDraggedViewEnter();
void OnDraggedViewExit();
// Enables background blur for folder icon if |enabled| is true.
void SetBackgroundBlurEnabled(bool enabled);
private:
class IconImageView;
......
......@@ -1162,6 +1162,7 @@ void AppListView::OnTabletModeChanged(bool started) {
is_tablet_mode_ = started;
search_box_view_->OnTabletModeChanged(started);
search_model_->SetTabletMode(started);
GetAppsContainerView()->OnTabletModeChanged(started);
if (is_home_launcher_enabled_) {
if (!started) {
......
......@@ -549,9 +549,11 @@ class AppListViewFocusTest : public views::ViewsTestBase,
std::vector<views::View*> suggestions;
if (is_new_style_launcher_enabled_) {
for (int i = 0; i < suggestions_container()->child_count(); ++i) {
suggestions.emplace_back(static_cast<SearchResultSuggestionChipView*>(
suggestions_container()->child_at(i))
->suggestion_chip_view());
SearchResultSuggestionChipView* view =
static_cast<SearchResultSuggestionChipView*>(
suggestions_container()->child_at(i));
if (view->visible())
suggestions.emplace_back(view->suggestion_chip_view());
}
return suggestions;
}
......
......@@ -209,6 +209,12 @@ void AppsContainerView::UpdateYPositionAndOpacity() {
}
}
void AppsContainerView::OnTabletModeChanged(bool started) {
if (suggestion_chip_container_view_)
suggestion_chip_container_view_->OnTabletModeChanged(started);
apps_grid_view_->OnTabletModeChanged(started);
}
gfx::Size AppsContainerView::CalculatePreferredSize() const {
if (is_new_style_launcher_enabled_)
return contents_view_->GetPreferredSize();
......
......@@ -69,6 +69,9 @@ class APP_LIST_EXPORT AppsContainerView : public HorizontalPage {
// Updates y position and opacity of the items in this view during dragging.
void UpdateYPositionAndOpacity();
// Called when tablet mode starts and ends.
void OnTabletModeChanged(bool started);
// views::View overrides:
gfx::Size CalculatePreferredSize() const override;
void Layout() override;
......
......@@ -471,6 +471,15 @@ void AppsGridView::DisableFocusForShowingActiveFolder(bool disabled) {
}
}
void AppsGridView::OnTabletModeChanged(bool started) {
// Enable/Disable folder icons's background blur based on tablet mode.
for (int i = 0; i < view_model_.view_size(); ++i) {
auto* item_view = view_model_.view_at(i);
if (item_view->item()->is_folder())
item_view->SetBackgroundBlurEnabled(started);
}
}
void AppsGridView::SetModel(AppListModel* model) {
if (model_)
model_->RemoveObserver(this);
......@@ -2023,6 +2032,10 @@ AppListItemView* AppsGridView::GetCurrentPageLastItemViewInFolder() {
return view_model_.view_at(last_index);
}
bool AppsGridView::IsTabletMode() const {
return contents_view_->app_list_view()->is_tablet_mode();
}
void AppsGridView::StartDragAndDropHostDrag(const gfx::Point& grid_location) {
// When a drag and drop host is given, the item can be dragged out of the app
// list window. In that case a proxy widget needs to be used.
......@@ -2047,7 +2060,8 @@ void AppsGridView::StartDragAndDropHostDrag(const gfx::Point& grid_location) {
drag_and_drop_host_->CreateDragIconProxyByLocationWithNoAnimation(
drag_view_->GetIconBoundsInScreen().origin(), drag_view_->GetIconImage(),
drag_view_, kDragAndDropProxyScale * GetTransform().Scale2d().x(),
is_new_style_launcher_enabled_ && drag_view_->item()->is_folder()
is_new_style_launcher_enabled_ && drag_view_->item()->is_folder() &&
IsTabletMode()
? AppListConfig::instance().blur_radius()
: 0);
......
......@@ -119,6 +119,9 @@ class APP_LIST_EXPORT AppsGridView : public views::View,
// used to trap focus within the folder when it is opened.
void DisableFocusForShowingActiveFolder(bool disabled);
// Called when tablet mode starts and ends.
void OnTabletModeChanged(bool started);
// Sets |model| to use. Note this does not take ownership of |model|.
void SetModel(AppListModel* model);
......@@ -254,6 +257,9 @@ class APP_LIST_EXPORT AppsGridView : public views::View,
// Returns the last app list item view in the selected page in the folder.
AppListItemView* GetCurrentPageLastItemViewInFolder();
// Returns true if tablet mode is active.
bool IsTabletMode() const;
// Return the view model.
views::ViewModelT<AppListItemView>* view_model() { return &view_model_; }
......
......@@ -38,7 +38,11 @@ void LogAppLaunch(int index_in_suggestion_chip_container) {
SearchResultSuggestionChipView::SearchResultSuggestionChipView(
AppListViewDelegate* view_delegate)
: view_delegate_(view_delegate), weak_ptr_factory_(this) {}
: view_delegate_(view_delegate), weak_ptr_factory_(this) {
suggestion_chip_view_ = new SuggestionChipView(
app_list::SuggestionChipView::Params(), /* listener */ this);
AddChildView(suggestion_chip_view_);
}
SearchResultSuggestionChipView::~SearchResultSuggestionChipView() {
SetSearchResult(nullptr);
......@@ -55,6 +59,7 @@ void SearchResultSuggestionChipView::SetSearchResult(SearchResult* item) {
if (item_)
item_->AddObserver(this);
SetVisible(!!item_);
UpdateSuggestionChipView();
}
......@@ -105,20 +110,16 @@ void SearchResultSuggestionChipView::GetAccessibleNodeData(
}
void SearchResultSuggestionChipView::UpdateSuggestionChipView() {
if (!item_)
if (!item_) {
suggestion_chip_view_->SetIcon(gfx::ImageSkia());
suggestion_chip_view_->SetText(base::string16());
suggestion_chip_view_->SetAccessibleName(base::string16());
return;
if (suggestion_chip_view_) {
suggestion_chip_view_->SetIcon(item_->chip_icon());
suggestion_chip_view_->SetText(item_->title());
} else {
app_list::SuggestionChipView::Params params;
params.text = item_->title();
params.icon = item_->chip_icon();
suggestion_chip_view_ = new SuggestionChipView(params, /* listener */ this);
AddChildView(suggestion_chip_view_);
}
suggestion_chip_view_->SetIcon(item_->chip_icon());
suggestion_chip_view_->SetText(item_->title());
base::string16 accessible_name = item_->title();
if (item_->id() == app_list::kInternalAppIdContinueReading) {
accessible_name = l10n_util::GetStringFUTF16(
......
......@@ -42,6 +42,15 @@ SuggestionChipContainerView::SuggestionChipContainerView(
kChipSpacing));
layout_manager->set_main_axis_alignment(
views::BoxLayout::MainAxisAlignment::MAIN_AXIS_ALIGNMENT_CENTER);
for (size_t i = 0; i < static_cast<size_t>(kNumStartPageTiles); ++i) {
SearchResultSuggestionChipView* chip =
new SearchResultSuggestionChipView(view_delegate_);
chip->SetVisible(false);
chip->SetIndexInSuggestionChipContainer(i);
suggestion_chip_views_.emplace_back(chip);
AddChildView(chip);
}
}
SuggestionChipContainerView::~SuggestionChipContainerView() = default;
......@@ -50,29 +59,20 @@ int SuggestionChipContainerView::DoUpdate() {
if (IgnoreUpdateAndLayout())
return num_results();
// Clear all current suggestion chips.
for (size_t i = 0; i < suggestion_chip_views_.size(); ++i)
delete suggestion_chip_views_[i];
suggestion_chip_views_.clear();
std::vector<SearchResult*> display_results =
SearchModel::FilterSearchResultsByDisplayType(
results(), ash::SearchResultDisplayType::kRecommendation,
/*excludes=*/{}, kNumStartPageTiles);
// Create a suggestion chip for each search result, but wait until layout to
// add them as child views when we know this view's bounds.
for (size_t i = 0; i < display_results.size(); ++i) {
auto* result = display_results[i];
SearchResultSuggestionChipView* chip =
new SearchResultSuggestionChipView(view_delegate_);
chip->SetSearchResult(result);
chip->SetIndexInSuggestionChipContainer(i);
suggestion_chip_views_.emplace_back(chip);
// Update search results here, but wait until layout to add them as child
// views when we know this view's bounds.
for (size_t i = 0; i < static_cast<size_t>(kNumStartPageTiles); ++i) {
suggestion_chip_views_[i]->SetSearchResult(
i < display_results.size() ? display_results[i] : nullptr);
}
Layout();
return suggestion_chip_views_.size();
return std::min(kNumStartPageTiles, static_cast<int>(display_results.size()));
}
const char* SuggestionChipContainerView::GetClassName() const {
......@@ -84,15 +84,19 @@ void SuggestionChipContainerView::Layout() {
return;
// Only show the chips that fit in this view's contents bounds.
RemoveAllChildViews(false /* delete_children */);
int total_width = 0;
const int max_width = GetContentsBounds().width();
for (auto* chip : suggestion_chip_views_) {
const int chip_width = chip->GetPreferredSize().width();
if (chip_width + total_width > max_width)
if (!chip->result())
break;
AddChildView(chip);
total_width += (total_width == 0 ? 0 : kChipSpacing) + chip_width;
const gfx::Size size = chip->CalculatePreferredSize();
if (size.width() + total_width > max_width) {
chip->SetVisible(false);
} else {
chip->SetVisible(true);
chip->SetSize(size);
}
total_width += (total_width == 0 ? 0 : kChipSpacing) + size.width();
}
views::View::Layout();
......@@ -126,6 +130,12 @@ void SuggestionChipContainerView::DisableFocusForShowingActiveFolder(
chip->suggestion_chip_view()->SetEnabled(!disabled);
}
void SuggestionChipContainerView::OnTabletModeChanged(bool started) {
// Enable/Disable chips' background blur based on tablet mode.
for (auto* chip : suggestion_chip_views_)
chip->suggestion_chip_view()->SetBackgroundBlurEnabled(started);
}
bool SuggestionChipContainerView::IgnoreUpdateAndLayout() const {
// Ignore update and layout when this view is not shown.
const ash::AppListState state = contents_view_->GetActiveState();
......
......@@ -34,6 +34,9 @@ class SuggestionChipContainerView : public SearchResultContainerView {
// trap focus within the folder when it is opened.
void DisableFocusForShowingActiveFolder(bool disabled);
// Called when tablet mode starts and ends.
void OnTabletModeChanged(bool started);
private:
// Returns true if update and layout should be ignored.
bool IgnoreUpdateAndLayout() const;
......
......@@ -67,27 +67,37 @@ SuggestionChipView::SuggestionChipView(const Params& params,
SetFocusBehavior(FocusBehavior::ALWAYS);
SetInkDropMode(InkDropHostView::InkDropMode::ON);
if (!assistant_style_) {
// Set background blur for the chip and use mask layer to clip it into
// rounded rect.
SetPaintToLayer();
layer()->SetFillsBoundsOpaquely(false);
layer()->SetBackgroundBlur(kBlurRadius);
SetRoundedRectMaskLayer(kPreferredHeightDip / 2);
}
// Set background blur for the chip and use mask layer to clip it into
// rounded rect.
if (!assistant_style_)
SetBackgroundBlurEnabled(false);
InitLayout(params);
}
SuggestionChipView::~SuggestionChipView() = default;
gfx::Size SuggestionChipView::CalculatePreferredSize() const {
const int preferred_width = views::View::CalculatePreferredSize().width();
return gfx::Size(preferred_width, GetHeightForWidth(preferred_width));
void SuggestionChipView::SetBackgroundBlurEnabled(bool enabled) {
DCHECK(!assistant_style_);
// Background blur is enabled if and only if layer exists.
if (!!layer() == enabled)
return;
if (!enabled) {
DestroyLayer();
return;
}
SetPaintToLayer();
layer()->SetFillsBoundsOpaquely(false);
layer()->SetBackgroundBlur(kBlurRadius);
SetRoundedRectMaskLayer(kPreferredHeightDip / 2);
}
int SuggestionChipView::GetHeightForWidth(int width) const {
return kPreferredHeightDip;
gfx::Size SuggestionChipView::CalculatePreferredSize() const {
const int preferred_width = views::View::CalculatePreferredSize().width();
return gfx::Size(preferred_width, kPreferredHeightDip);
}
void SuggestionChipView::ChildVisibilityChanged(views::View* child) {
......@@ -223,7 +233,7 @@ void SuggestionChipView::SetIcon(const gfx::ImageSkia& icon) {
void SuggestionChipView::SetText(const base::string16& text) {
text_view_->SetText(text);
if (!assistant_style_) {
gfx::Size size = text_view_->GetPreferredSize();
gfx::Size size = text_view_->CalculatePreferredSize();
size.set_width(std::min(kAppListMaxTextWidth, size.width()));
text_view_->SetPreferredSize(size);
}
......
......@@ -42,10 +42,12 @@ class APP_LIST_EXPORT SuggestionChipView : public views::Button {
SuggestionChipView(const Params& params, views::ButtonListener* listener);
~SuggestionChipView() override;
// Enables background blur for folder icon if |enabled| is true.
void SetBackgroundBlurEnabled(bool enabled);
// views::View:
gfx::Size CalculatePreferredSize() const override;
void ChildVisibilityChanged(views::View* child) override;
int GetHeightForWidth(int width) const override;
void OnPaintBackground(gfx::Canvas* canvas) override;
void OnFocus() override;
void OnBlur() override;
......
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