Commit 389f290c authored by Manu Cornet's avatar Manu Cornet Committed by Commit Bot

CrOS: differentiate between running and active apps

* Add a simple mechanism to keep track of the active shelf item
  in the model
* Use the existing shelf window watcher to update the active shelf
  item
* When rendering shelf items in ShelfView, query the active shelf
  item to show the proper indicator
* Remove the STATUS_ACTIVE value since this is now all managed within
  ash

Bug: 874181
Bug: 805612
Change-Id: I089587646208ee03776f95a4f479c5b6d35d82f8
Reviewed-on: https://chromium-review.googlesource.com/1180274Reviewed-by: default avatarMartin Barbella <mbarbella@chromium.org>
Reviewed-by: default avatarMichael Wasserman <msw@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Commit-Queue: Manu Cornet <manucornet@chromium.org>
Cr-Commit-Position: refs/heads/master@{#585340}
parent f3be2b6e
...@@ -185,6 +185,24 @@ void ShelfModel::Set(int index, const ShelfItem& item) { ...@@ -185,6 +185,24 @@ void ShelfModel::Set(int index, const ShelfItem& item) {
} }
} }
// TODO(manucornet): Add some simple unit tests for this method.
void ShelfModel::SetActiveShelfID(const ShelfID& shelf_id) {
if (active_shelf_id_ == shelf_id)
return;
ShelfID old_active_id = active_shelf_id_;
active_shelf_id_ = shelf_id;
if (!old_active_id.IsNull())
OnItemStatusChanged(old_active_id);
if (!active_shelf_id_.IsNull())
OnItemStatusChanged(active_shelf_id_);
}
void ShelfModel::OnItemStatusChanged(const ShelfID& id) {
for (auto& observer : observers_)
observer.ShelfItemStatusChanged(id);
}
void ShelfModel::RemoveNotificationRecord(const std::string& notification_id) { void ShelfModel::RemoveNotificationRecord(const std::string& notification_id) {
auto notification_id_it = notification_id_to_app_id_.find(notification_id); auto notification_id_it = notification_id_to_app_id_.find(notification_id);
......
...@@ -65,6 +65,17 @@ class ASH_PUBLIC_EXPORT ShelfModel { ...@@ -65,6 +65,17 @@ class ASH_PUBLIC_EXPORT ShelfModel {
// Resets the item at the specified index. The item's id should not change. // Resets the item at the specified index. The item's id should not change.
void Set(int index, const ShelfItem& item); void Set(int index, const ShelfItem& item);
// Returns the ID of the currently active item, or an empty ShelfID if
// nothing is currently active.
const ShelfID& active_shelf_id() const { return active_shelf_id_; }
// Sets |shelf_id| to be the newly active shelf item.
void SetActiveShelfID(const ShelfID& shelf_id);
// Notifies observers that the status of the item corresponding to |id|
// has changed.
void OnItemStatusChanged(const ShelfID& id);
// Adds a record of the notification with this app id and notifies observers. // Adds a record of the notification with this app id and notifies observers.
void AddNotificationRecord(const std::string& app_id, void AddNotificationRecord(const std::string& app_id,
const std::string& notification_id); const std::string& notification_id);
...@@ -123,6 +134,10 @@ class ASH_PUBLIC_EXPORT ShelfModel { ...@@ -123,6 +134,10 @@ class ASH_PUBLIC_EXPORT ShelfModel {
ShelfItems items_; ShelfItems items_;
// The shelf ID of the currently active shelf item, or an empty ID if
// nothing is active.
ShelfID active_shelf_id_;
// Maps one app id to a set of all matching notification ids. // Maps one app id to a set of all matching notification ids.
std::map<std::string, std::set<std::string>> app_id_to_notification_id_; std::map<std::string, std::set<std::string>> app_id_to_notification_id_;
// Maps one notification id to one app id. // Maps one notification id to one app id.
......
...@@ -36,6 +36,11 @@ class ASH_PUBLIC_EXPORT ShelfModelObserver { ...@@ -36,6 +36,11 @@ class ASH_PUBLIC_EXPORT ShelfModelObserver {
ShelfItemDelegate* old_delegate, ShelfItemDelegate* old_delegate,
ShelfItemDelegate* delegate) {} ShelfItemDelegate* delegate) {}
// Invoked when the status of the item corresponding to |id| changes. Only
// observers within ash (typically the shelf views) need to respond to this
// event.
virtual void ShelfItemStatusChanged(const ShelfID& id) {}
protected: protected:
virtual ~ShelfModelObserver() {} virtual ~ShelfModelObserver() {}
}; };
......
...@@ -66,8 +66,6 @@ struct EnumTraits<ash::mojom::ShelfItemStatus, ash::ShelfItemStatus> { ...@@ -66,8 +66,6 @@ struct EnumTraits<ash::mojom::ShelfItemStatus, ash::ShelfItemStatus> {
return ash::mojom::ShelfItemStatus::CLOSED; return ash::mojom::ShelfItemStatus::CLOSED;
case ash::STATUS_RUNNING: case ash::STATUS_RUNNING:
return ash::mojom::ShelfItemStatus::RUNNING; return ash::mojom::ShelfItemStatus::RUNNING;
case ash::STATUS_ACTIVE:
return ash::mojom::ShelfItemStatus::ACTIVE;
case ash::STATUS_ATTENTION: case ash::STATUS_ATTENTION:
return ash::mojom::ShelfItemStatus::ATTENTION; return ash::mojom::ShelfItemStatus::ATTENTION;
} }
...@@ -84,8 +82,6 @@ struct EnumTraits<ash::mojom::ShelfItemStatus, ash::ShelfItemStatus> { ...@@ -84,8 +82,6 @@ struct EnumTraits<ash::mojom::ShelfItemStatus, ash::ShelfItemStatus> {
case ash::mojom::ShelfItemStatus::RUNNING: case ash::mojom::ShelfItemStatus::RUNNING:
*out = ash::STATUS_RUNNING; *out = ash::STATUS_RUNNING;
return true; return true;
case ash::mojom::ShelfItemStatus::ACTIVE:
*out = ash::STATUS_ACTIVE;
return true; return true;
case ash::mojom::ShelfItemStatus::ATTENTION: case ash::mojom::ShelfItemStatus::ATTENTION:
*out = ash::STATUS_ATTENTION; *out = ash::STATUS_ATTENTION;
......
...@@ -142,8 +142,6 @@ enum ShelfItemStatus { ...@@ -142,8 +142,6 @@ enum ShelfItemStatus {
STATUS_CLOSED, STATUS_CLOSED,
// A shelf item that has live instance. // A shelf item that has live instance.
STATUS_RUNNING, STATUS_RUNNING,
// A shelf item one of whose windows is currently active.
STATUS_ACTIVE,
// A shelf item that needs user's attention. // A shelf item that needs user's attention.
STATUS_ATTENTION, STATUS_ATTENTION,
}; };
......
...@@ -24,7 +24,6 @@ enum ShelfAction { ...@@ -24,7 +24,6 @@ enum ShelfAction {
enum ShelfItemStatus { enum ShelfItemStatus {
CLOSED, // A closed shelf item, i.e. has no live instance. CLOSED, // A closed shelf item, i.e. has no live instance.
RUNNING, // A shelf item that has live instance. RUNNING, // A shelf item that has live instance.
ACTIVE, // A shelf item that owns the currently active window.
ATTENTION, // A shelf item that needs user's attention. ATTENTION, // A shelf item that needs user's attention.
}; };
......
...@@ -226,26 +226,29 @@ class FadeInAnimationDelegate : public gfx::AnimationDelegate { ...@@ -226,26 +226,29 @@ class FadeInAnimationDelegate : public gfx::AnimationDelegate {
}; };
void ReflectItemStatus(const ShelfItem& item, ShelfButton* button) { void ReflectItemStatus(const ShelfItem& item, ShelfButton* button) {
ShelfID active_id = Shell::Get()->shelf_model()->active_shelf_id();
if (!active_id.IsNull() && item.id == active_id) {
// The active status trumps all other statuses.
button->AddState(ShelfButton::STATE_ACTIVE);
button->ClearState(ShelfButton::STATE_RUNNING);
button->ClearState(ShelfButton::STATE_ATTENTION);
return;
}
button->ClearState(ShelfButton::STATE_ACTIVE);
switch (item.status) { switch (item.status) {
case STATUS_CLOSED: case STATUS_CLOSED:
button->ClearState(ShelfButton::STATE_RUNNING); button->ClearState(ShelfButton::STATE_RUNNING);
button->ClearState(ShelfButton::STATE_ACTIVE);
button->ClearState(ShelfButton::STATE_ATTENTION);
break;
case STATUS_ACTIVE:
button->AddState(ShelfButton::STATE_ACTIVE);
button->AddState(ShelfButton::STATE_RUNNING);
button->ClearState(ShelfButton::STATE_ATTENTION); button->ClearState(ShelfButton::STATE_ATTENTION);
break; break;
case STATUS_RUNNING: case STATUS_RUNNING:
button->AddState(ShelfButton::STATE_RUNNING); button->AddState(ShelfButton::STATE_RUNNING);
button->ClearState(ShelfButton::STATE_ACTIVE);
button->ClearState(ShelfButton::STATE_ATTENTION); button->ClearState(ShelfButton::STATE_ATTENTION);
break; break;
case STATUS_ATTENTION: case STATUS_ATTENTION:
button->ClearState(ShelfButton::STATE_RUNNING); button->ClearState(ShelfButton::STATE_RUNNING);
button->AddState(ShelfButton::STATE_ATTENTION); button->AddState(ShelfButton::STATE_ATTENTION);
button->ClearState(ShelfButton::STATE_ACTIVE);
break; break;
} }
...@@ -1956,6 +1959,20 @@ void ShelfView::ShelfItemDelegateChanged(const ShelfID& id, ...@@ -1956,6 +1959,20 @@ void ShelfView::ShelfItemDelegateChanged(const ShelfID& id,
ShelfItemDelegate* old_delegate, ShelfItemDelegate* old_delegate,
ShelfItemDelegate* delegate) {} ShelfItemDelegate* delegate) {}
void ShelfView::ShelfItemStatusChanged(const ShelfID& id) {
int index = model_->ItemIndexByID(id);
if (index < 0)
return;
const ShelfItem item = model_->items()[index];
views::View* view = view_model_->view_at(index);
CHECK_EQ(ShelfButton::kViewClassName, view->GetClassName());
// TODO(manucornet): Add a helper to get the button.
ShelfButton* button = static_cast<ShelfButton*>(view);
ReflectItemStatus(item, button);
button->SchedulePaint();
}
void ShelfView::AfterItemSelected( void ShelfView::AfterItemSelected(
const ShelfItem& item, const ShelfItem& item,
views::Button* sender, views::Button* sender,
......
...@@ -401,6 +401,7 @@ class ASH_EXPORT ShelfView : public views::View, ...@@ -401,6 +401,7 @@ class ASH_EXPORT ShelfView : public views::View,
void ShelfItemDelegateChanged(const ShelfID& id, void ShelfItemDelegateChanged(const ShelfID& id,
ShelfItemDelegate* old_delegate, ShelfItemDelegate* old_delegate,
ShelfItemDelegate* delegate) override; ShelfItemDelegate* delegate) override;
void ShelfItemStatusChanged(const ShelfID& id) override;
// Handles the result when querying ShelfItemDelegates for context menu items. // Handles the result when querying ShelfItemDelegates for context menu items.
// Shows a default shelf context menu with optional extra custom |menu_items|. // Shows a default shelf context menu with optional extra custom |menu_items|.
......
...@@ -253,6 +253,9 @@ void ShelfWindowWatcher::OnWindowActivated(ActivationReason reason, ...@@ -253,6 +253,9 @@ void ShelfWindowWatcher::OnWindowActivated(ActivationReason reason,
OnUserWindowPropertyChanged(gained_active); OnUserWindowPropertyChanged(gained_active);
if (lost_active && user_windows_with_items_.count(lost_active) > 0) if (lost_active && user_windows_with_items_.count(lost_active) > 0)
OnUserWindowPropertyChanged(lost_active); OnUserWindowPropertyChanged(lost_active);
model_->SetActiveShelfID(gained_active ? GetShelfID(gained_active)
: ShelfID());
} }
void ShelfWindowWatcher::OnRootWindowAdded(aura::Window* root_window) { void ShelfWindowWatcher::OnRootWindowAdded(aura::Window* root_window) {
......
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