Commit ae60a134 authored by Weidong Guo's avatar Weidong Guo Committed by Commit Bot

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