Commit 0bb65e96 authored by stevenjb@chromium.org's avatar stevenjb@chromium.org

Re-factor system tray code controlling launcher visibility

This CL prevents the launcher from being hidden when either the web notification tray or the system tray is visible.

BUG=142506
For minor change to ash/wm/shelf_layout_manager.cc:
TBR=sky@chromium.org


Review URL: https://chromiumcodereview.appspot.com/10823350

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@152028 0039d316-1c4b-4281-b951-d872f2087c98
parent 50cc61fe
...@@ -15,9 +15,11 @@ ...@@ -15,9 +15,11 @@
#include "ash/system/tray/system_tray_delegate.h" #include "ash/system/tray/system_tray_delegate.h"
#include "ash/system/web_notification/web_notification_tray.h" #include "ash/system/web_notification/web_notification_tray.h"
#include "ash/volume_control_delegate.h" #include "ash/volume_control_delegate.h"
#include "ash/wm/shelf_layout_manager.h"
#include "base/i18n/time_formatting.h" #include "base/i18n/time_formatting.h"
#include "base/utf_string_conversions.h" #include "base/utf_string_conversions.h"
#include "ui/aura/window.h" #include "ui/aura/window.h"
#include "ui/gfx/screen.h"
namespace ash { namespace ash {
...@@ -306,7 +308,8 @@ StatusAreaWidget::StatusAreaWidget() ...@@ -306,7 +308,8 @@ StatusAreaWidget::StatusAreaWidget()
: status_area_widget_delegate_(new internal::StatusAreaWidgetDelegate), : status_area_widget_delegate_(new internal::StatusAreaWidgetDelegate),
system_tray_(NULL), system_tray_(NULL),
web_notification_tray_(NULL), web_notification_tray_(NULL),
login_status_(user::LOGGED_IN_NONE) { login_status_(user::LOGGED_IN_NONE),
should_show_launcher_(false) {
views::Widget::InitParams params( views::Widget::InitParams params(
views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
params.delegate = status_area_widget_delegate_; params.delegate = status_area_widget_delegate_;
...@@ -405,5 +408,27 @@ void StatusAreaWidget::UpdateAfterLoginStatusChange( ...@@ -405,5 +408,27 @@ void StatusAreaWidget::UpdateAfterLoginStatusChange(
web_notification_tray_->UpdateAfterLoginStatusChange(login_status); web_notification_tray_->UpdateAfterLoginStatusChange(login_status);
} }
void StatusAreaWidget::UpdateShouldShowLauncher() {
// If any bubble is visible, we should show the launcher.
bool should_show_launcher =
(system_tray_ && system_tray_->IsSystemBubbleVisible()) ||
(web_notification_tray_ &&
web_notification_tray_->IsMessageCenterBubbleVisible());
if (!should_show_launcher && Shell::GetInstance()->shelf()->IsVisible()) {
// If the launcher is currently visible, don't hide the launcher if
// the mouse is in this widget or in any notification bubbles.
should_show_launcher =
(GetWindowBoundsInScreen().Contains(
gfx::Screen::GetCursorScreenPoint())) ||
(system_tray_ && system_tray_->IsMouseInNotificationBubble()) ||
(web_notification_tray_ &&
web_notification_tray_->IsMouseInNotificationBubble());
}
if (should_show_launcher != should_show_launcher_) {
should_show_launcher_ = should_show_launcher;
Shell::GetInstance()->shelf()->UpdateAutoHideState();
}
}
} // namespace internal } // namespace internal
} // namespace ash } // namespace ash
...@@ -56,6 +56,11 @@ class ASH_EXPORT StatusAreaWidget : public views::Widget { ...@@ -56,6 +56,11 @@ class ASH_EXPORT StatusAreaWidget : public views::Widget {
// notification tray. // notification tray.
void UpdateAfterLoginStatusChange(user::LoginStatus login_status); void UpdateAfterLoginStatusChange(user::LoginStatus login_status);
// Called whenever the launcher auto-hide behavior may need updating.
// This sets should_show_launcher_ and calls
// ShelfLayoutManager::UpdateAutoHideState() if the state has changed.
void UpdateShouldShowLauncher();
internal::StatusAreaWidgetDelegate* status_area_widget_delegate() { internal::StatusAreaWidgetDelegate* status_area_widget_delegate() {
return status_area_widget_delegate_; return status_area_widget_delegate_;
} }
...@@ -69,6 +74,8 @@ class ASH_EXPORT StatusAreaWidget : public views::Widget { ...@@ -69,6 +74,8 @@ class ASH_EXPORT StatusAreaWidget : public views::Widget {
user::LoginStatus login_status() const { return login_status_; } user::LoginStatus login_status() const { return login_status_; }
bool should_show_launcher() const { return should_show_launcher_; }
private: private:
void AddSystemTray(ShellDelegate* shell_delegate); void AddSystemTray(ShellDelegate* shell_delegate);
void AddWebNotificationTray(); void AddWebNotificationTray();
...@@ -79,6 +86,7 @@ class ASH_EXPORT StatusAreaWidget : public views::Widget { ...@@ -79,6 +86,7 @@ class ASH_EXPORT StatusAreaWidget : public views::Widget {
SystemTray* system_tray_; SystemTray* system_tray_;
WebNotificationTray* web_notification_tray_; WebNotificationTray* web_notification_tray_;
user::LoginStatus login_status_; user::LoginStatus login_status_;
bool should_show_launcher_;
DISALLOW_COPY_AND_ASSIGN(StatusAreaWidget); DISALLOW_COPY_AND_ASSIGN(StatusAreaWidget);
}; };
......
...@@ -30,7 +30,6 @@ ...@@ -30,7 +30,6 @@
#include "ash/system/tray_update.h" #include "ash/system/tray_update.h"
#include "ash/system/user/login_status.h" #include "ash/system/user/login_status.h"
#include "ash/system/user/tray_user.h" #include "ash/system/user/tray_user.h"
#include "ash/wm/shelf_layout_manager.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/timer.h" #include "base/timer.h"
#include "base/utf_string_conversions.h" #include "base/utf_string_conversions.h"
...@@ -71,7 +70,6 @@ SystemTray::SystemTray(internal::StatusAreaWidget* status_area_widget) ...@@ -71,7 +70,6 @@ SystemTray::SystemTray(internal::StatusAreaWidget* status_area_widget)
network_observer_(NULL), network_observer_(NULL),
update_observer_(NULL), update_observer_(NULL),
user_observer_(NULL), user_observer_(NULL),
should_show_launcher_(false),
default_bubble_height_(0), default_bubble_height_(0),
hide_notifications_(false) { hide_notifications_(false) {
} }
...@@ -230,6 +228,10 @@ void SystemTray::SetHideNotifications(bool hide_notifications) { ...@@ -230,6 +228,10 @@ void SystemTray::SetHideNotifications(bool hide_notifications) {
hide_notifications_ = hide_notifications; hide_notifications_ = hide_notifications;
} }
bool SystemTray::IsSystemBubbleVisible() const {
return (bubble_.get() && bubble_->IsVisible());
}
bool SystemTray::IsAnyBubbleVisible() const { bool SystemTray::IsAnyBubbleVisible() const {
if (bubble_.get() && bubble_->IsVisible()) if (bubble_.get() && bubble_->IsVisible())
return true; return true;
...@@ -238,6 +240,13 @@ bool SystemTray::IsAnyBubbleVisible() const { ...@@ -238,6 +240,13 @@ bool SystemTray::IsAnyBubbleVisible() const {
return false; return false;
} }
bool SystemTray::IsMouseInNotificationBubble() const {
if (!notification_bubble_.get())
return false;
return notification_bubble_->bubble_view()->GetBoundsInScreen().Contains(
gfx::Screen::GetCursorScreenPoint());
}
bool SystemTray::CloseBubbleForTest() const { bool SystemTray::CloseBubbleForTest() const {
if (!bubble_.get()) if (!bubble_.get())
return false; return false;
...@@ -256,14 +265,7 @@ void SystemTray::RemoveBubble(SystemTrayBubble* bubble) { ...@@ -256,14 +265,7 @@ void SystemTray::RemoveBubble(SystemTrayBubble* bubble) {
if (bubble == bubble_.get()) { if (bubble == bubble_.get()) {
DestroyBubble(); DestroyBubble();
UpdateNotificationBubble(); // State changed, re-create notifications. UpdateNotificationBubble(); // State changed, re-create notifications.
if (should_show_launcher_) { UpdateShouldShowLauncher();
// No need to show the launcher if the mouse isn't over the status area
// anymore.
should_show_launcher_ = GetWidget()->GetWindowBoundsInScreen().Contains(
gfx::Screen::GetCursorScreenPoint());
if (!should_show_launcher_)
Shell::GetInstance()->shelf()->UpdateAutoHideState();
}
} else if (bubble == notification_bubble_) { } else if (bubble == notification_bubble_) {
notification_bubble_.reset(); notification_bubble_.reset();
} else { } else {
...@@ -340,13 +342,9 @@ void SystemTray::ShowItems(const std::vector<SystemTrayItem*>& items, ...@@ -340,13 +342,9 @@ void SystemTray::ShowItems(const std::vector<SystemTrayItem*>& items,
else else
detailed_item_ = NULL; detailed_item_ = NULL;
// If we have focus the shelf should be visible and we need to continue
// showing the shelf when the popup is shown.
if (GetWidget()->IsActive())
should_show_launcher_ = true;
UpdateNotificationBubble(); // State changed, re-create notifications. UpdateNotificationBubble(); // State changed, re-create notifications.
status_area_widget()->HideNonSystemNotifications(); status_area_widget()->HideNonSystemNotifications();
UpdateShouldShowLauncher();
} }
void SystemTray::UpdateNotificationBubble() { void SystemTray::UpdateNotificationBubble() {
...@@ -447,18 +445,6 @@ bool SystemTray::PerformAction(const ui::Event& event) { ...@@ -447,18 +445,6 @@ bool SystemTray::PerformAction(const ui::Event& event) {
return true; return true;
} }
void SystemTray::OnMouseEntered(const ui::MouseEvent& event) {
TrayBackgroundView::OnMouseEntered(event);
should_show_launcher_ = true;
}
void SystemTray::OnMouseExited(const ui::MouseEvent& event) {
TrayBackgroundView::OnMouseExited(event);
// When the popup closes we'll update |should_show_launcher_|.
if (!bubble_.get())
should_show_launcher_ = false;
}
void SystemTray::GetAccessibleState(ui::AccessibleViewState* state) { void SystemTray::GetAccessibleState(ui::AccessibleViewState* state) {
state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON; state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON;
state->name = l10n_util::GetStringUTF16( state->name = l10n_util::GetStringUTF16(
......
...@@ -95,13 +95,14 @@ class ASH_EXPORT SystemTray : public internal::TrayBackgroundView { ...@@ -95,13 +95,14 @@ class ASH_EXPORT SystemTray : public internal::TrayBackgroundView {
// Temporarily hides/unhides the notification bubble. // Temporarily hides/unhides the notification bubble.
void SetHideNotifications(bool hidden); void SetHideNotifications(bool hidden);
// Returns true if the system bubble is visible.
bool IsSystemBubbleVisible() const;
// Returns true if any bubble is visible. // Returns true if any bubble is visible.
bool IsAnyBubbleVisible() const; bool IsAnyBubbleVisible() const;
// Returns true if the launcher should show. // Returns true if the mouse is inside the notification bubble.
bool should_show_launcher() const { bool IsMouseInNotificationBubble() const;
return bubble_.get() && should_show_launcher_;
}
AccessibilityObserver* accessibility_observer() const { AccessibilityObserver* accessibility_observer() const {
return accessibility_observer_; return accessibility_observer_;
...@@ -192,8 +193,6 @@ class ASH_EXPORT SystemTray : public internal::TrayBackgroundView { ...@@ -192,8 +193,6 @@ class ASH_EXPORT SystemTray : public internal::TrayBackgroundView {
virtual bool PerformAction(const ui::Event& event) OVERRIDE; virtual bool PerformAction(const ui::Event& event) OVERRIDE;
// Overridden from views::View. // Overridden from views::View.
virtual void OnMouseEntered(const ui::MouseEvent& event) OVERRIDE;
virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE;
virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE;
// Owned items. // Owned items.
...@@ -228,9 +227,6 @@ class ASH_EXPORT SystemTray : public internal::TrayBackgroundView { ...@@ -228,9 +227,6 @@ class ASH_EXPORT SystemTray : public internal::TrayBackgroundView {
// Bubble for notifications. // Bubble for notifications.
scoped_ptr<internal::SystemTrayBubble> notification_bubble_; scoped_ptr<internal::SystemTrayBubble> notification_bubble_;
// See description agove getter.
bool should_show_launcher_;
// Keep track of the default view height so that when we create detailed // Keep track of the default view height so that when we create detailed
// views directly (e.g. from a notification) we know what height to use. // views directly (e.g. from a notification) we know what height to use.
int default_bubble_height_; int default_bubble_height_;
......
...@@ -320,10 +320,12 @@ void SystemTrayBubble::BubbleViewDestroyed() { ...@@ -320,10 +320,12 @@ void SystemTrayBubble::BubbleViewDestroyed() {
void SystemTrayBubble::OnMouseEnteredView() { void SystemTrayBubble::OnMouseEnteredView() {
StopAutoCloseTimer(); StopAutoCloseTimer();
tray_->UpdateShouldShowLauncher();
} }
void SystemTrayBubble::OnMouseExitedView() { void SystemTrayBubble::OnMouseExitedView() {
RestartAutoCloseTimer(); RestartAutoCloseTimer();
tray_->UpdateShouldShowLauncher();
} }
void SystemTrayBubble::OnClickedOutsideView() { void SystemTrayBubble::OnClickedOutsideView() {
......
...@@ -189,11 +189,13 @@ void TrayBackgroundView::Initialize() { ...@@ -189,11 +189,13 @@ void TrayBackgroundView::Initialize() {
void TrayBackgroundView::OnMouseEntered(const ui::MouseEvent& event) { void TrayBackgroundView::OnMouseEntered(const ui::MouseEvent& event) {
hover_background_animator_.SetPaintsBackground(true, hover_background_animator_.SetPaintsBackground(true,
internal::BackgroundAnimator::CHANGE_ANIMATE); internal::BackgroundAnimator::CHANGE_ANIMATE);
UpdateShouldShowLauncher();
} }
void TrayBackgroundView::OnMouseExited(const ui::MouseEvent& event) { void TrayBackgroundView::OnMouseExited(const ui::MouseEvent& event) {
hover_background_animator_.SetPaintsBackground(false, hover_background_animator_.SetPaintsBackground(false,
internal::BackgroundAnimator::CHANGE_ANIMATE); internal::BackgroundAnimator::CHANGE_ANIMATE);
UpdateShouldShowLauncher();
} }
void TrayBackgroundView::ChildPreferredSizeChanged(views::View* child) { void TrayBackgroundView::ChildPreferredSizeChanged(views::View* child) {
...@@ -270,5 +272,9 @@ void TrayBackgroundView::SetBorder() { ...@@ -270,5 +272,9 @@ void TrayBackgroundView::SetBorder() {
} }
} }
void TrayBackgroundView::UpdateShouldShowLauncher() {
status_area_widget()->UpdateShouldShowLauncher();
}
} // namespace internal } // namespace internal
} // namespace ash } // namespace ash
...@@ -90,6 +90,9 @@ class ASH_EXPORT TrayBackgroundView : public internal::ActionableView, ...@@ -90,6 +90,9 @@ class ASH_EXPORT TrayBackgroundView : public internal::ActionableView,
bool value, bool value,
internal::BackgroundAnimator::ChangeType change_type); internal::BackgroundAnimator::ChangeType change_type);
// Convenience function to call same function in status_area_widget_.
void UpdateShouldShowLauncher();
StatusAreaWidget* status_area_widget() { StatusAreaWidget* status_area_widget() {
return status_area_widget_; return status_area_widget_;
} }
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "ui/base/models/simple_menu_model.h" #include "ui/base/models/simple_menu_model.h"
#include "ui/base/resource/resource_bundle.h" #include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/image/image_skia_operations.h" #include "ui/gfx/image/image_skia_operations.h"
#include "ui/gfx/screen.h"
#include "ui/views/controls/button/button.h" #include "ui/views/controls/button/button.h"
#include "ui/views/controls/button/menu_button.h" #include "ui/views/controls/button/menu_button.h"
#include "ui/views/controls/button/menu_button_listener.h" #include "ui/views/controls/button/menu_button_listener.h"
...@@ -761,6 +762,10 @@ class WebNotificationTray::Bubble : public TrayBubbleView::Host, ...@@ -761,6 +762,10 @@ class WebNotificationTray::Bubble : public TrayBubbleView::Host,
base::TimeDelta::FromMilliseconds(kUpdateDelayMs)); base::TimeDelta::FromMilliseconds(kUpdateDelayMs));
} }
bool IsVisible() const {
return bubble_widget_ && bubble_widget_->IsVisible();
}
views::Widget* bubble_widget() const { return bubble_widget_; } views::Widget* bubble_widget() const { return bubble_widget_; }
TrayBubbleView* bubble_view() const { return bubble_view_; } TrayBubbleView* bubble_view() const { return bubble_view_; }
...@@ -772,10 +777,12 @@ class WebNotificationTray::Bubble : public TrayBubbleView::Host, ...@@ -772,10 +777,12 @@ class WebNotificationTray::Bubble : public TrayBubbleView::Host,
virtual void OnMouseEnteredView() OVERRIDE { virtual void OnMouseEnteredView() OVERRIDE {
StopAutoCloseTimer(); StopAutoCloseTimer();
tray_->UpdateShouldShowLauncher();
} }
virtual void OnMouseExitedView() OVERRIDE { virtual void OnMouseExitedView() OVERRIDE {
StartAutoCloseTimer(); StartAutoCloseTimer();
tray_->UpdateShouldShowLauncher();
} }
virtual void OnClickedOutsideView() OVERRIDE { virtual void OnClickedOutsideView() OVERRIDE {
...@@ -907,6 +914,7 @@ void WebNotificationTray::ShowMessageCenterBubble() { ...@@ -907,6 +914,7 @@ void WebNotificationTray::ShowMessageCenterBubble() {
message_center_bubble_.reset( message_center_bubble_.reset(
new Bubble(this, Bubble::BUBBLE_TYPE_MESAGE_CENTER)); new Bubble(this, Bubble::BUBBLE_TYPE_MESAGE_CENTER));
status_area_widget()->SetHideSystemNotifications(true); status_area_widget()->SetHideSystemNotifications(true);
UpdateShouldShowLauncher();
} }
void WebNotificationTray::HideMessageCenterBubble() { void WebNotificationTray::HideMessageCenterBubble() {
...@@ -916,6 +924,7 @@ void WebNotificationTray::HideMessageCenterBubble() { ...@@ -916,6 +924,7 @@ void WebNotificationTray::HideMessageCenterBubble() {
show_message_center_on_unlock_ = false; show_message_center_on_unlock_ = false;
notification_list_->SetIsVisible(false); notification_list_->SetIsVisible(false);
status_area_widget()->SetHideSystemNotifications(false); status_area_widget()->SetHideSystemNotifications(false);
UpdateShouldShowLauncher();
} }
void WebNotificationTray::ShowNotificationBubble() { void WebNotificationTray::ShowNotificationBubble() {
...@@ -954,6 +963,17 @@ void WebNotificationTray::UpdateAfterLoginStatusChange( ...@@ -954,6 +963,17 @@ void WebNotificationTray::UpdateAfterLoginStatusChange(
UpdateTray(); UpdateTray();
} }
bool WebNotificationTray::IsMessageCenterBubbleVisible() const {
return (message_center_bubble() && message_center_bubble_->IsVisible());
}
bool WebNotificationTray::IsMouseInNotificationBubble() const {
if (!notification_bubble())
return false;
return notification_bubble_->bubble_view()->GetBoundsInScreen().Contains(
gfx::Screen::GetCursorScreenPoint());
}
void WebNotificationTray::SetShelfAlignment(ShelfAlignment alignment) { void WebNotificationTray::SetShelfAlignment(ShelfAlignment alignment) {
if (alignment == shelf_alignment()) if (alignment == shelf_alignment())
return; return;
......
...@@ -116,6 +116,12 @@ class ASH_EXPORT WebNotificationTray : public internal::TrayBackgroundView { ...@@ -116,6 +116,12 @@ class ASH_EXPORT WebNotificationTray : public internal::TrayBackgroundView {
// Updates tray visibility login status of the system changes. // Updates tray visibility login status of the system changes.
void UpdateAfterLoginStatusChange(user::LoginStatus login_status); void UpdateAfterLoginStatusChange(user::LoginStatus login_status);
// Returns true if the message center bubble is visible.
bool IsMessageCenterBubbleVisible() const;
// Returns true if the mouse is inside the notification bubble.
bool IsMouseInNotificationBubble() const;
// Overridden from TrayBackgroundView. // Overridden from TrayBackgroundView.
virtual void SetShelfAlignment(ShelfAlignment alignment) OVERRIDE; virtual void SetShelfAlignment(ShelfAlignment alignment) OVERRIDE;
virtual void AnchorUpdated() OVERRIDE; virtual void AnchorUpdated() OVERRIDE;
......
...@@ -544,7 +544,8 @@ ShelfLayoutManager::AutoHideState ShelfLayoutManager::CalculateAutoHideState( ...@@ -544,7 +544,8 @@ ShelfLayoutManager::AutoHideState ShelfLayoutManager::CalculateAutoHideState(
if (shell->GetAppListTargetVisibility()) if (shell->GetAppListTargetVisibility())
return AUTO_HIDE_SHOWN; return AUTO_HIDE_SHOWN;
if (shell->system_tray() && shell->system_tray()->should_show_launcher()) if (shell->status_area_widget() &&
shell->status_area_widget()->should_show_launcher())
return AUTO_HIDE_SHOWN; return AUTO_HIDE_SHOWN;
if (launcher_ && launcher_->IsShowingMenu()) if (launcher_ && launcher_->IsShowingMenu())
......
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