Skip to content

Commit

Permalink
desks: Highlighted desk items can be selected or deleted.
Browse files Browse the repository at this point in the history
Pressing ctrl+W will delete a desk if a mini view is highlighted. It will
have no effect if the new desk button is highlighted. Pressing enter
will activate a desk if a mini view is highlighted. It will create a new
desk if possible if the new desk button is highlighted.

Test: manual, added tests
Bug: 988141
Change-Id: Ibd5996052cd882ec8d5a768e9c452eed1524cfb9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1724279
Commit-Queue: Sammie Quon <sammiequon@chromium.org>
Reviewed-by: Ahmed Fakhry <afakhry@chromium.org>
Cr-Commit-Position: refs/heads/master@{#683814}
  • Loading branch information
sammiequon71 authored and Commit Bot committed Aug 3, 2019
1 parent 07996fe commit 9c7cfb9
Show file tree
Hide file tree
Showing 16 changed files with 254 additions and 90 deletions.
33 changes: 24 additions & 9 deletions ash/wm/desks/desk_mini_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -183,15 +183,7 @@ void DeskMiniView::ButtonPressed(views::Button* sender,
if (sender != close_desk_button_)
return;

// Hide the close button so it can no longer be pressed.
close_desk_button_->SetVisible(false);

// This mini_view can no longer be pressed.
listener_ = nullptr;

auto* controller = DesksController::Get();
DCHECK(controller->CanRemoveDesks());
controller->RemoveDesk(desk_, DesksCreationRemovalSource::kButton);
OnCloseButtonPressed();
}

void DeskMiniView::OnContentChanged() {
Expand Down Expand Up @@ -228,10 +220,33 @@ gfx::Rect DeskMiniView::GetHighlightBoundsInScreen() {
return bounds_in_screen;
}

void DeskMiniView::MaybeActivateHighlightedView() {
DesksController::Get()->ActivateDesk(desk(),
DesksSwitchSource::kMiniViewButton);
}

void DeskMiniView::MaybeCloseHighlightedView() {
OnCloseButtonPressed();
}

bool DeskMiniView::IsPointOnMiniView(const gfx::Point& screen_location) const {
gfx::Point point_in_view = screen_location;
ConvertPointFromScreen(this, &point_in_view);
return HitTestPoint(point_in_view);
}

void DeskMiniView::OnCloseButtonPressed() {
auto* controller = DesksController::Get();
if (!controller->CanRemoveDesks())
return;

// Hide the close button so it can no longer be pressed.
close_desk_button_->SetVisible(false);

// This mini_view can no longer be pressed.
listener_ = nullptr;

controller->RemoveDesk(desk_, DesksCreationRemovalSource::kButton);
}

} // namespace ash
4 changes: 4 additions & 0 deletions ash/wm/desks/desk_mini_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,14 @@ class ASH_EXPORT DeskMiniView
// OverviewHighlightController::OverviewHighlightableView:
views::View* GetView() override;
gfx::Rect GetHighlightBoundsInScreen() override;
void MaybeActivateHighlightedView() override;
void MaybeCloseHighlightedView() override;

bool IsPointOnMiniView(const gfx::Point& screen_location) const;

private:
void OnCloseButtonPressed();

DesksBarView* const owner_bar_;

// The root window on which this mini_view is created.
Expand Down
14 changes: 4 additions & 10 deletions ash/wm/desks/desks_bar_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ DesksBarView::DesksBarView()

AddChildView(background_view_);
AddChildView(new_desk_button_);

DesksController::Get()->AddObserver(this);
}

Expand Down Expand Up @@ -244,10 +245,7 @@ void DesksBarView::ButtonPressed(views::Button* sender,
const ui::Event& event) {
auto* controller = DesksController::Get();
if (sender == new_desk_button_) {
if (controller->CanCreateDesks()) {
controller->NewDesk(DesksCreationRemovalSource::kButton);
UpdateNewDeskButtonState();
}
new_desk_button_->OnButtonPressed();
return;
}

Expand Down Expand Up @@ -277,15 +275,15 @@ void DesksBarView::OnDeskRemoved(const Desk* desk) {
// removed from the collection because it needs to know the index of the mini
// view relative to other traversable views.
auto* highlight_controller = GetHighlightController();
highlight_controller->OnViewDestroying(iter->get());
highlight_controller->OnViewDestroyingOrDisabling(iter->get());

const int begin_x = GetFirstMiniViewXOffset();
std::unique_ptr<DeskMiniView> removed_mini_view = std::move(*iter);
auto partition_iter = mini_views_.erase(iter);

Layout();
UpdateMiniViewsLabels();
UpdateNewDeskButtonState();
new_desk_button_->UpdateButtonState();

// Once the remaining mini views have their bounds updated, notify the
// overview highlight controller so that it can update the focus highlight, if
Expand Down Expand Up @@ -320,10 +318,6 @@ void DesksBarView::OnDeskActivationChanged(const Desk* activated,

void DesksBarView::OnDeskSwitchAnimationFinished() {}

void DesksBarView::UpdateNewDeskButtonState() {
new_desk_button_->UpdateButtonState();
}

void DesksBarView::UpdateNewMiniViews(bool animate) {
const auto& desks = DesksController::Get()->desks();
if (desks.size() < 2) {
Expand Down
4 changes: 0 additions & 4 deletions ash/wm/desks/desks_bar_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,6 @@ class ASH_EXPORT DesksBarView : public views::View,
// animated to their final positions.
void UpdateNewMiniViews(bool animate);

// Updates the enabled state of the new desk button when the ability to create
// new desk may have changed.
void UpdateNewDeskButtonState();

// Returns the mini_view associated with |desk| or nullptr if no mini_view
// has been created for it yet.
DeskMiniView* FindMiniViewForDesk(const Desk* desk) const;
Expand Down
33 changes: 33 additions & 0 deletions ash/wm/desks/new_desk_button.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,14 @@
#include <utility>

#include "ash/resources/vector_icons/vector_icons.h"
#include "ash/shell.h"
#include "ash/strings/grit/ash_strings.h"
#include "ash/wm/desks/desks_bar_view.h"
#include "ash/wm/desks/desks_controller.h"
#include "ash/wm/desks/desks_util.h"
#include "ash/wm/overview/overview_controller.h"
#include "ash/wm/overview/overview_highlight_controller.h"
#include "ash/wm/overview/overview_session.h"
#include "base/strings/utf_string_conversions.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/color_palette.h"
Expand Down Expand Up @@ -69,11 +75,29 @@ NewDeskButton::NewDeskButton(views::ButtonListener* listener)

void NewDeskButton::UpdateButtonState() {
const bool enabled = DesksController::Get()->CanCreateDesks();
if (GetEnabled() == enabled)
return;

// Notify the overview highlight if we are about to be disabled.
if (!enabled) {
OverviewSession* overview_session =
Shell::Get()->overview_controller()->overview_session();
DCHECK(overview_session);
overview_session->highlight_controller()->OnViewDestroyingOrDisabling(this);
}
SetEnabled(enabled);
SetBackground(views::CreateRoundedRectBackground(
enabled ? kBackgroundColor : kDisabledBackgroundColor, kCornerRadius));
}

void NewDeskButton::OnButtonPressed() {
auto* controller = DesksController::Get();
if (controller->CanCreateDesks()) {
controller->NewDesk(DesksCreationRemovalSource::kButton);
UpdateButtonState();
}
}

const char* NewDeskButton::GetClassName() const {
return "NewDeskButton";
}
Expand Down Expand Up @@ -120,4 +144,13 @@ gfx::RoundedCornersF NewDeskButton::GetRoundedCornersRadii() const {
return gfx::RoundedCornersF(kCornerRadius);
}

void NewDeskButton::MaybeActivateHighlightedView() {
if (!GetEnabled())
return;

OnButtonPressed();
}

void NewDeskButton::MaybeCloseHighlightedView() {}

} // namespace ash
6 changes: 5 additions & 1 deletion ash/wm/desks/new_desk_button.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ class ASH_EXPORT NewDeskButton
: public views::LabelButton,
public OverviewHighlightController::OverviewHighlightableView {
public:
NewDeskButton(views::ButtonListener* listener);
explicit NewDeskButton(views::ButtonListener* listener);
~NewDeskButton() override = default;

// Update the button's enable/disable state based on current desks state.
void UpdateButtonState();

void OnButtonPressed();

// LabelButton:
const char* GetClassName() const override;
std::unique_ptr<views::InkDrop> CreateInkDrop() override;
Expand All @@ -40,6 +42,8 @@ class ASH_EXPORT NewDeskButton
views::View* GetView() override;
gfx::Rect GetHighlightBoundsInScreen() override;
gfx::RoundedCornersF GetRoundedCornersRadii() const override;
void MaybeActivateHighlightedView() override;
void MaybeCloseHighlightedView() override;

private:
DISALLOW_COPY_AND_ASSIGN(NewDeskButton);
Expand Down
10 changes: 10 additions & 0 deletions ash/wm/overview/caption_container_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,16 @@ gfx::Rect CaptionContainerView::GetHighlightBoundsInScreen() {
return target_bounds;
}

void CaptionContainerView::MaybeActivateHighlightedView() {
if (event_delegate_)
event_delegate_->OnHighlightedViewActivated();
}

void CaptionContainerView::MaybeCloseHighlightedView() {
if (event_delegate_)
event_delegate_->OnHighlightedViewClosed();
}

void CaptionContainerView::Layout() {
gfx::Rect bounds(GetLocalBounds());
bounds.Inset(kMarginDp, kMarginDp);
Expand Down
4 changes: 4 additions & 0 deletions ash/wm/overview/caption_container_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ class ASH_EXPORT CaptionContainerView
virtual void HandleTapEvent() = 0;
virtual void HandleGestureEndEvent() = 0;
virtual bool ShouldIgnoreGestureEvents() = 0;
virtual void OnHighlightedViewActivated() = 0;
virtual void OnHighlightedViewClosed() = 0;

protected:
virtual ~EventDelegate() {}
Expand Down Expand Up @@ -101,6 +103,8 @@ class ASH_EXPORT CaptionContainerView
// OverviewHighlightController::OverviewHighlightableView:
views::View* GetView() override;
gfx::Rect GetHighlightBoundsInScreen() override;
void MaybeActivateHighlightedView() override;
void MaybeCloseHighlightedView() override;

// TODO(sammiequon): Move these to a test api.
views::View* header_view() { return header_view_; }
Expand Down
4 changes: 2 additions & 2 deletions ash/wm/overview/overview_grid.cc
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ void OverviewGrid::RemoveItem(OverviewItem* overview_item) {
window_state_observer_.Remove(WindowState::Get(window));

if (overview_session_) {
overview_session_->highlight_controller()->OnViewDestroying(
overview_session_->highlight_controller()->OnViewDestroyingOrDisabling(
(*iter)->caption_container_view());
}

Expand Down Expand Up @@ -765,7 +765,7 @@ void OverviewGrid::OnWindowDestroying(aura::Window* window) {
auto iter = GetOverviewItemIterContainingWindow(window);
DCHECK(iter != window_list_.end());
if (overview_session_) {
overview_session_->highlight_controller()->OnViewDestroying(
overview_session_->highlight_controller()->OnViewDestroyingOrDisabling(
(*iter)->caption_container_view());
}

Expand Down
18 changes: 17 additions & 1 deletion ash/wm/overview/overview_highlight_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ void OverviewHighlightController::MoveHighlight(bool reverse) {
UpdateFocusWidget(traversable_views[index], reverse);
}

void OverviewHighlightController::OnViewDestroying(
void OverviewHighlightController::OnViewDestroyingOrDisabling(
OverviewHighlightableView* view) {
DCHECK(view);
if (view != highlighted_view_)
Expand Down Expand Up @@ -232,6 +232,22 @@ bool OverviewHighlightController::IsFocusHighlightVisible() const {
return highlight_widget_ && highlight_widget_->IsVisible();
}

bool OverviewHighlightController::MaybeActivateHighlightedView() {
if (!highlighted_view_)
return false;

highlighted_view_->MaybeActivateHighlightedView();
return true;
}

bool OverviewHighlightController::MaybeCloseHighlightedView() {
if (!highlighted_view_)
return false;

highlighted_view_->MaybeCloseHighlightedView();
return true;
}

OverviewItem* OverviewHighlightController::GetHighlightedItem() const {
if (!highlighted_view_)
return nullptr;
Expand Down
14 changes: 10 additions & 4 deletions ash/wm/overview/overview_highlight_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ class OverviewSession;
// Manages highlighting items while in overview. Creates a semi transparent
// highlight when users try to traverse through overview items using arrow keys
// or tab keys, or when users are tab dragging.
// TODO(sammiequon): Add a new test class which tests highlighting desk items,
// and move the existing OverviewSession highlight related tests to the new
// class.
class ASH_EXPORT OverviewHighlightController {
public:
// An interface that must be implemented by classes that want to be
Expand All @@ -47,6 +44,10 @@ class ASH_EXPORT OverviewHighlightController {
// |this|.
virtual gfx::RoundedCornersF GetRoundedCornersRadii() const;

// Attempts to activate or close this view. Overriders may do nothing.
virtual void MaybeActivateHighlightedView() = 0;
virtual void MaybeCloseHighlightedView() = 0;

protected:
virtual ~OverviewHighlightableView() {}
};
Expand All @@ -59,12 +60,17 @@ class ASH_EXPORT OverviewHighlightController {

// Called when a |view| that might be in the focus traversal rotation is about
// to be deleted.
void OnViewDestroying(OverviewHighlightableView* view);
void OnViewDestroyingOrDisabling(OverviewHighlightableView* view);

// Sets and gets the visibility of |highlight_widget_|.
void SetFocusHighlightVisibility(bool visible);
bool IsFocusHighlightVisible() const;

// Activates or closes the currently highlighted view (if any) if it supports
// the activation or closing operations respectively.
bool MaybeActivateHighlightedView();
bool MaybeCloseHighlightedView();

// Tries to get the item that is currently highlighted. Returns null if there
// is no highlight, or if the highlight is on a desk view.
OverviewItem* GetHighlightedItem() const;
Expand Down
Loading

0 comments on commit 9c7cfb9

Please sign in to comment.