Commit 35ebae92 authored by Ahmed Fakhry's avatar Ahmed Fakhry Committed by Commit Bot

Virtual Desks 2.3: Extract DesksBarView into its own widget

In preparation for removing the overview's shield widget,
this CL extracts the DesksBarView into its own widget.

BUG=866622, 942759
TEST=Manual, DesksTests still pass.

Change-Id: Ic378e113dae4b7abdc1ce856655b74cfcd3337d0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1542664
Commit-Queue: Ahmed Fakhry <afakhry@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Reviewed-by: default avatarSammie Quon <sammiequon@chromium.org>
Cr-Commit-Position: refs/heads/master@{#645351}
parent 59391a10
......@@ -8,14 +8,18 @@
#include <iterator>
#include <utility>
#include "ash/public/cpp/shell_window_ids.h"
#include "ash/strings/grit/ash_strings.h"
#include "ash/wm/desks/desk_mini_view.h"
#include "ash/wm/desks/desk_mini_view_animations.h"
#include "ash/wm/desks/new_desk_button.h"
#include "base/stl_util.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/aura/window.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/geometry/insets.h"
#include "ui/views/widget/widget.h"
#include "ui/wm/core/window_animations.h"
namespace ash {
......@@ -61,6 +65,32 @@ int DesksBarView::GetBarHeight() {
return kBarHeight;
}
// static
std::unique_ptr<views::Widget> DesksBarView::CreateDesksWidget(
aura::Window* root,
const gfx::Rect& bounds) {
DCHECK(root);
DCHECK(root->IsRootWindow());
auto widget = std::make_unique<views::Widget>();
views::Widget::InitParams params(
views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
params.activatable = views::Widget::InitParams::ACTIVATABLE_NO;
params.accept_events = true;
params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
// Use the wallpaper container similar to all background widgets created in
// overview mode.
params.parent = root->GetChildById(kShellWindowId_WallpaperContainer);
params.bounds = bounds;
params.name = "VirtualDesksWidget";
widget->Init(params);
::wm::SetWindowVisibilityAnimationTransition(widget->GetNativeWindow(),
::wm::ANIMATE_NONE);
return widget;
}
void DesksBarView::Init() {
UpdateNewMiniViews(/*animate=*/false);
}
......
......@@ -30,6 +30,13 @@ class ASH_EXPORT DesksBarView : public views::View,
// The height of the desk bar view.
static int GetBarHeight();
// Creates and returns the widget that contains the DeskBarView in overview
// mode. The returned widget has no content view yet, and hasn't been shown
// yet.
static std::unique_ptr<views::Widget> CreateDesksWidget(
aura::Window* root,
const gfx::Rect& bounds);
views::View* backgroud_view() const { return backgroud_view_; }
NewDeskButton* new_desk_button() const { return new_desk_button_; }
......
......@@ -263,6 +263,11 @@ gfx::Rect GetGridBoundsInScreenDuringDragging(aura::Window* dragged_window,
}
}
gfx::Rect GetDesksWidgetBounds(aura::Window* root, int overview_grid_width) {
return screen_util::SnapBoundsToDisplayEdge(
gfx::Rect(overview_grid_width, DesksBarView::GetBarHeight()), root);
}
} // namespace
// ShieldView contains the background for overview mode. It also contains text
......@@ -299,20 +304,6 @@ class OverviewGrid::ShieldView : public views::View {
~ShieldView() override = default;
const DesksBarView* desks_bar_view() const { return desks_bar_view_; }
// Call this only after this view has been added to a widget. This is needed
// because the desks mini views need to access the widget to get the
// root window in order to know how to layout themselves.
void MaybeInitVirtualDesksBar() {
if (!features::IsVirtualDesksEnabled())
return;
desks_bar_view_ = new DesksBarView;
AddChildView(desks_bar_view_);
desks_bar_view_->Init();
}
void SetLabelVisibility(bool visible) {
label_container_->SetVisible(visible);
}
......@@ -331,18 +322,10 @@ class OverviewGrid::ShieldView : public views::View {
label_container_bounds.ClampToCenteredSize(
gfx::Size(label_width, kNoItemsIndicatorHeightDp));
label_container_->SetBoundsRect(label_container_bounds);
UpdateDesksBarBounds();
}
bool IsLabelVisible() const { return label_container_->visible(); }
protected:
// views::View:
void Layout() override {
UpdateDesksBarBounds();
}
private:
// ui::EventHandler:
void OnMouseEvent(ui::MouseEvent* event) override {
......@@ -378,21 +361,9 @@ class OverviewGrid::ShieldView : public views::View {
event->StopPropagation();
}
void UpdateDesksBarBounds() {
if (!desks_bar_view_)
return;
// TODO: Make the ShieldView's bounds match the overview grid bounds rather
// than the entire screen?
const auto bar_bounds =
gfx::Rect{bounds().width(), DesksBarView::GetBarHeight()};
desks_bar_view_->SetBoundsRect(bar_bounds);
}
// Owned by views heirarchy.
RoundedRectView* label_container_ = nullptr;
views::Label* label_ = nullptr;
DesksBarView* desks_bar_view_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(ShieldView);
};
......@@ -547,8 +518,10 @@ void OverviewGrid::Shutdown() {
}
void OverviewGrid::PrepareForOverview() {
if (!ShouldAnimateWallpaper())
if (!ShouldAnimateWallpaper()) {
InitShieldWidget(/*animate=*/false);
MaybeInitDesksWidget();
}
for (const auto& window : window_list_)
window->PrepareForOverview();
......@@ -774,6 +747,10 @@ void OverviewGrid::SetBoundsAndUpdatePositionsIgnoringWindow(
bounds_ = bounds;
if (shield_view_)
shield_view_->SetGridBounds(bounds_);
if (desks_widget_) {
desks_widget_->SetBounds(
GetDesksWidgetBounds(root_window_, bounds_.width()));
}
PositionWindows(/*animate=*/true, ignored_item);
}
......@@ -1108,6 +1085,8 @@ void OverviewGrid::OnStartingAnimationComplete(bool canceled) {
ShowNoRecentsWindowMessage(window_list_.empty());
}
MaybeInitDesksWidget();
for (auto& window : window_list())
window->OnStartingAnimationComplete();
}
......@@ -1408,10 +1387,6 @@ aura::Window* OverviewGrid::GetTargetWindowOnLocation(
return (iter != window_list_.end()) ? (*iter)->GetWindow() : nullptr;
}
const DesksBarView* OverviewGrid::GetDesksBarViewForTesting() const {
return shield_view_->desks_bar_view();
}
bool OverviewGrid::IsDesksBarViewActive() const {
DCHECK(features::IsVirtualDesksEnabled());
......@@ -1419,8 +1394,7 @@ bool OverviewGrid::IsDesksBarViewActive() const {
// overview is started. Once there are more than one desk, it should stay
// active even if the 2nd to last desk is deleted.
return DesksController::Get()->desks().size() > 1 ||
(shield_view_ &&
!shield_view_->desks_bar_view()->mini_views().empty());
(desks_bar_view_ && !desks_bar_view_->mini_views().empty());
}
void OverviewGrid::InitShieldWidget(bool animate) {
......@@ -1446,7 +1420,6 @@ void OverviewGrid::InitShieldWidget(bool animate) {
// Create |shield_view_| and animate its background and label if needed.
shield_view_ = new ShieldView();
shield_widget_->SetContentsView(shield_view_);
shield_view_->MaybeInitVirtualDesksBar();
shield_view_->SetGridBounds(bounds_);
// TODO(sammiequon): The shield widget is not anymore in most cases. Remove
......@@ -1462,6 +1435,24 @@ void OverviewGrid::InitShieldWidget(bool animate) {
}
}
void OverviewGrid::MaybeInitDesksWidget() {
if (!features::IsVirtualDesksEnabled() || desks_widget_)
return;
desks_widget_ = DesksBarView::CreateDesksWidget(
root_window_, GetDesksWidgetBounds(root_window_, bounds_.width()));
desks_bar_view_ = new DesksBarView;
// The following order of function calls is significant: SetContentsView()
// must be called before DesksBarView:: Init(). This is needed because the
// desks mini views need to access the widget to get the root window in order
// to know how to layout themselves.
desks_widget_->SetContentsView(desks_bar_view_);
desks_bar_view_->Init();
desks_widget_->Show();
}
void OverviewGrid::InitSelectionWidget(OverviewSession::Direction direction) {
selection_widget_ = CreateBackgroundWidget(
root_window_, ui::LAYER_TEXTURED, kWindowSelectionColor, 0,
......
......@@ -252,7 +252,9 @@ class ASH_EXPORT OverviewGrid : public aura::WindowObserver,
void set_suspend_reposition(bool value) { suspend_reposition_ = value; }
const DesksBarView* GetDesksBarViewForTesting() const;
const DesksBarView* GetDesksBarViewForTesting() const {
return desks_bar_view_;
}
private:
class ShieldView;
......@@ -269,6 +271,10 @@ class ASH_EXPORT OverviewGrid : public aura::WindowObserver,
// Initializes the screen shield widget.
void InitShieldWidget(bool animate);
// If the Virtual Desks feature is enabled, it initializes the widget that
// contains the DeskBarView contents.
void MaybeInitDesksWidget();
// Internal function to initialize the selection widget.
void InitSelectionWidget(OverviewSession::Direction direction);
......@@ -346,6 +352,12 @@ class ASH_EXPORT OverviewGrid : public aura::WindowObserver,
// A pointer to |shield_widget_|'s content view.
ShieldView* shield_view_ = nullptr;
// Widget that contains the DeskBarView contents when the Virtual Desks
// feature is enabled.
std::unique_ptr<views::Widget> desks_widget_;
// The contents view of the above |desks_widget_| if created.
DesksBarView* desks_bar_view_ = nullptr;
// Widget that indicates to the user which is the selected window.
std::unique_ptr<views::Widget> selection_widget_;
......
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