Commit 2a91c564 authored by jhorwich@chromium.org's avatar jhorwich@chromium.org

Revert 151752 - Move non SystemTray specific code to TrayBackgroundView

This fixes the behavior of the web notification tray with launcher auto-hide.
It also fixes visibility of the web notification tray in the lock screen.

BUG=142506

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

TBR=stevenjb@google.com
Review URL: https://chromiumcodereview.appspot.com/10854175

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@151763 0039d316-1c4b-4281-b951-d872f2087c98
parent b61e731e
......@@ -324,12 +324,9 @@ StatusAreaWidget::~StatusAreaWidget() {
void StatusAreaWidget::CreateTrayViews(ShellDelegate* shell_delegate) {
AddWebNotificationTray();
AddSystemTray(shell_delegate);
// Initialize() must be called after all trays have been created.
if (system_tray_)
system_tray_->Initialize();
if (web_notification_tray_)
web_notification_tray_->Initialize();
UpdateAfterLoginStatusChange(system_tray_delegate_->GetUserLoginStatus());
// SetBorder() must be called after all trays have been created.
web_notification_tray_->SetBorder();
system_tray_->SetBorder();
}
void StatusAreaWidget::Shutdown() {
......@@ -346,6 +343,7 @@ void StatusAreaWidget::Shutdown() {
void StatusAreaWidget::AddSystemTray(ShellDelegate* shell_delegate) {
system_tray_ = new SystemTray(this);
status_area_widget_delegate_->AddTray(system_tray_);
system_tray_->Initialize(); // Called after added to widget.
if (shell_delegate) {
system_tray_delegate_.reset(
......@@ -353,6 +351,9 @@ void StatusAreaWidget::AddSystemTray(ShellDelegate* shell_delegate) {
}
if (!system_tray_delegate_.get())
system_tray_delegate_.reset(new DummySystemTrayDelegate());
system_tray_->CreateItems(); // Called after delegate is created.
UpdateAfterLoginStatusChange(system_tray_delegate_->GetUserLoginStatus());
}
void StatusAreaWidget::AddWebNotificationTray() {
......
......@@ -51,9 +51,39 @@
namespace ash {
namespace internal {
// Observe the tray layer animation and update the anchor when it changes.
// TODO(stevenjb): Observe or mirror the actual animation, not just the start
// and end points.
class SystemTrayLayerAnimationObserver : public ui::LayerAnimationObserver {
public:
explicit SystemTrayLayerAnimationObserver(SystemTray* host) : host_(host) {}
virtual void OnLayerAnimationEnded(ui::LayerAnimationSequence* sequence) {
host_->UpdateNotificationAnchor();
}
virtual void OnLayerAnimationAborted(ui::LayerAnimationSequence* sequence) {
host_->UpdateNotificationAnchor();
}
virtual void OnLayerAnimationScheduled(ui::LayerAnimationSequence* sequence) {
host_->UpdateNotificationAnchor();
}
private:
SystemTray* host_;
DISALLOW_COPY_AND_ASSIGN(SystemTrayLayerAnimationObserver);
};
} // namespace internal
// SystemTray
using internal::SystemTrayBubble;
using internal::SystemTrayLayerAnimationObserver;
using internal::TrayBubbleView;
SystemTray::SystemTray(internal::StatusAreaWidget* status_area_widget)
......@@ -83,6 +113,14 @@ SystemTray::~SystemTray() {
++it) {
(*it)->DestroyTrayView();
}
GetWidget()->GetNativeView()->layer()->GetAnimator()->RemoveObserver(
layer_animation_observer_.get());
}
void SystemTray::Initialize() {
layer_animation_observer_.reset(new SystemTrayLayerAnimationObserver(this));
GetWidget()->GetNativeView()->layer()->GetAnimator()->AddObserver(
layer_animation_observer_.get());
}
void SystemTray::CreateItems() {
......@@ -143,7 +181,8 @@ void SystemTray::AddTrayItem(SystemTrayItem* item) {
SystemTrayDelegate* delegate = Shell::GetInstance()->tray_delegate();
views::View* tray_item = item->CreateTrayView(delegate->GetUserLoginStatus());
item->UpdateAfterShelfAlignmentChange(shelf_alignment());
item->UpdateAfterShelfAlignmentChange(
ash::Shell::GetInstance()->system_tray()->shelf_alignment());
if (tray_item) {
tray_container()->AddChildViewAt(tray_item, 0);
......@@ -396,9 +435,12 @@ void SystemTray::UpdateNotificationBubble() {
status_area_widget()->HideNonSystemNotifications();
}
void SystemTray::Initialize() {
internal::TrayBackgroundView::Initialize();
CreateItems();
void SystemTray::UpdateNotificationAnchor() {
if (!notification_bubble_.get())
return;
notification_bubble_->bubble_view()->UpdateBubble();
// Ensure that the notification buble is above the launcher/status area.
notification_bubble_->bubble_view()->GetWidget()->StackAtTop();
}
void SystemTray::SetShelfAlignment(ShelfAlignment alignment) {
......@@ -415,16 +457,6 @@ void SystemTray::SetShelfAlignment(ShelfAlignment alignment) {
}
}
void SystemTray::AnchorUpdated() {
if (notification_bubble_.get()) {
notification_bubble_->bubble_view()->UpdateBubble();
// Ensure that the notification buble is above the launcher/status area.
notification_bubble_->bubble_view()->GetWidget()->StackAtTop();
}
if (bubble_.get())
bubble_->bubble_view()->UpdateBubble();
}
bool SystemTray::PerformAction(const ui::Event& event) {
// If we're already showing the default view, hide it; otherwise, show it
// (and hide any popup that's currently shown).
......@@ -459,10 +491,24 @@ void SystemTray::OnMouseExited(const ui::MouseEvent& event) {
should_show_launcher_ = false;
}
void SystemTray::AboutToRequestFocusFromTabTraversal(bool reverse) {
views::View* v = GetNextFocusableView();
if (v)
v->AboutToRequestFocusFromTabTraversal(reverse);
}
void SystemTray::GetAccessibleState(ui::AccessibleViewState* state) {
state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON;
state->name = l10n_util::GetStringUTF16(
IDS_ASH_STATUS_TRAY_ACCESSIBLE_NAME);
}
void SystemTray::OnPaintFocusBorder(gfx::Canvas* canvas) {
// The tray itself expands to the right and bottom edge of the screen to make
// sure clicking on the edges brings up the popup. However, the focus border
// should be only around the container.
if (GetWidget() && GetWidget()->IsActive())
DrawBorder(canvas, GetContentsBounds());
}
} // namespace ash
......@@ -41,6 +41,7 @@ class SystemTrayItem;
namespace internal {
class SystemTrayBubble;
class SystemTrayContainer;
class SystemTrayLayerAnimationObserver;
}
// There are different methods for creating bubble views.
......@@ -54,6 +55,9 @@ class ASH_EXPORT SystemTray : public internal::TrayBackgroundView {
explicit SystemTray(internal::StatusAreaWidget* status_area_widget);
virtual ~SystemTray();
// Called after the tray has been added to the widget containing it.
void Initialize();
// Creates the default set of items for the sytem tray.
void CreateItems();
......@@ -152,11 +156,10 @@ class ASH_EXPORT SystemTray : public internal::TrayBackgroundView {
bool CloseBubbleForTest() const;
// Overridden from TrayBackgroundView.
virtual void Initialize() OVERRIDE;
virtual void SetShelfAlignment(ShelfAlignment alignment) OVERRIDE;
virtual void AnchorUpdated() OVERRIDE;
private:
friend class internal::SystemTrayLayerAnimationObserver;
friend class internal::SystemTrayBubble;
// Resets |bubble_| and clears any related state.
......@@ -188,13 +191,18 @@ class ASH_EXPORT SystemTray : public internal::TrayBackgroundView {
// |notification_items_|, or destroys it if there are no notification items.
void UpdateNotificationBubble();
// Called when the anchor (tray or bubble) may have moved or changed.
void UpdateNotificationAnchor();
// Overridden from internal::ActionableView.
virtual bool PerformAction(const ui::Event& event) OVERRIDE;
// Overridden from views::View.
virtual void OnMouseEntered(const ui::MouseEvent& event) OVERRIDE;
virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE;
virtual void AboutToRequestFocusFromTabTraversal(bool reverse) OVERRIDE;
virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE;
virtual void OnPaintFocusBorder(gfx::Canvas* canvas) OVERRIDE;
// Owned items.
ScopedVector<SystemTrayItem> items_;
......@@ -231,6 +239,9 @@ class ASH_EXPORT SystemTray : public internal::TrayBackgroundView {
// See description agove getter.
bool should_show_launcher_;
scoped_ptr<internal::SystemTrayLayerAnimationObserver>
layer_animation_observer_;
// 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.
int default_bubble_height_;
......
......@@ -11,7 +11,6 @@
#include "ash/system/status_area_widget_delegate.h"
#include "ash/system/tray/tray_constants.h"
#include "ui/aura/window.h"
#include "ui/compositor/layer_animation_observer.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/skia_util.h"
#include "ui/views/background.h"
......@@ -33,33 +32,6 @@ const int kTrayContainerHorizontalPaddingVerticalAlignment = 1;
namespace ash {
namespace internal {
// Observe the tray layer animation and update the anchor when it changes.
// TODO(stevenjb): Observe or mirror the actual animation, not just the start
// and end points.
class TrayLayerAnimationObserver : public ui::LayerAnimationObserver {
public:
explicit TrayLayerAnimationObserver(TrayBackgroundView* host)
: host_(host) {
}
virtual void OnLayerAnimationEnded(ui::LayerAnimationSequence* sequence) {
host_->AnchorUpdated();
}
virtual void OnLayerAnimationAborted(ui::LayerAnimationSequence* sequence) {
host_->AnchorUpdated();
}
virtual void OnLayerAnimationScheduled(ui::LayerAnimationSequence* sequence) {
host_->AnchorUpdated();
}
private:
TrayBackgroundView* host_;
DISALLOW_COPY_AND_ASSIGN(TrayLayerAnimationObserver);
};
class TrayBackground : public views::Background {
public:
TrayBackground() : alpha_(kTrayBackgroundAlpha) {}
......@@ -159,9 +131,7 @@ TrayBackgroundView::TrayBackgroundView(
ALLOW_THIS_IN_INITIALIZER_LIST(hide_background_animator_(
this, 0, kTrayBackgroundAlpha)),
ALLOW_THIS_IN_INITIALIZER_LIST(hover_background_animator_(
this, 0, kTrayBackgroundHoverAlpha - kTrayBackgroundAlpha)),
ALLOW_THIS_IN_INITIALIZER_LIST(layer_animation_observer_(
new TrayLayerAnimationObserver(this))) {
this, 0, kTrayBackgroundHoverAlpha - kTrayBackgroundAlpha)) {
set_notify_enter_exit_on_child(true);
// Initially we want to paint the background, but without the hover effect.
......@@ -174,14 +144,6 @@ TrayBackgroundView::TrayBackgroundView(
}
TrayBackgroundView::~TrayBackgroundView() {
GetWidget()->GetNativeView()->layer()->GetAnimator()->RemoveObserver(
layer_animation_observer_.get());
}
void TrayBackgroundView::Initialize() {
GetWidget()->GetNativeView()->layer()->GetAnimator()->AddObserver(
layer_animation_observer_.get());
SetBorder();
}
void TrayBackgroundView::OnMouseEntered(const ui::MouseEvent& event) {
......@@ -198,21 +160,6 @@ void TrayBackgroundView::ChildPreferredSizeChanged(views::View* child) {
PreferredSizeChanged();
}
void TrayBackgroundView::OnPaintFocusBorder(gfx::Canvas* canvas) {
// The tray itself expands to the right and bottom edge of the screen to make
// sure clicking on the edges brings up the popup. However, the focus border
// should be only around the container.
if (GetWidget() && GetWidget()->IsActive())
DrawBorder(canvas, GetContentsBounds());
}
void TrayBackgroundView::AboutToRequestFocusFromTabTraversal(bool reverse) {
// Return focus to the login view. See crbug.com/120500.
views::View* v = GetNextFocusableView();
if (v)
v->AboutToRequestFocusFromTabTraversal(reverse);
}
bool TrayBackgroundView::PerformAction(const ui::Event& event) {
return false;
}
......
......@@ -15,7 +15,6 @@ namespace internal {
class StatusAreaWidget;
class TrayBackground;
class TrayLayerAnimationObserver;
// Base class for children of StatusAreaWidget: SystemTray, WebNotificationTray.
// This class handles setting and animating the background when the Launcher
......@@ -59,15 +58,10 @@ class ASH_EXPORT TrayBackgroundView : public internal::ActionableView,
explicit TrayBackgroundView(internal::StatusAreaWidget* status_area_widget);
virtual ~TrayBackgroundView();
// Called after the tray has been added to the widget containing it.
virtual void Initialize();
// Overridden from views::View.
virtual void OnMouseEntered(const ui::MouseEvent& event) OVERRIDE;
virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE;
virtual void ChildPreferredSizeChanged(views::View* child) OVERRIDE;
virtual void OnPaintFocusBorder(gfx::Canvas* canvas) OVERRIDE;
virtual void AboutToRequestFocusFromTabTraversal(bool reverse) OVERRIDE;
// Overridden from internal::ActionableView.
virtual bool PerformAction(const ui::Event& event) OVERRIDE;
......@@ -78,9 +72,6 @@ class ASH_EXPORT TrayBackgroundView : public internal::ActionableView,
// Called whenever the shelf alignment changes.
virtual void SetShelfAlignment(ShelfAlignment alignment);
// Called when the anchor (tray or bubble) may have moved or changed.
virtual void AnchorUpdated() {}
// Sets |contents| as a child and sets its background to |background_|.
void SetContents(views::View* contents);
......@@ -90,6 +81,10 @@ class ASH_EXPORT TrayBackgroundView : public internal::ActionableView,
bool value,
internal::BackgroundAnimator::ChangeType change_type);
// Called after all status area trays have been created. Sets the border
// based on the position of the view.
void SetBorder();
StatusAreaWidget* status_area_widget() {
return status_area_widget_;
}
......@@ -97,12 +92,6 @@ class ASH_EXPORT TrayBackgroundView : public internal::ActionableView,
ShelfAlignment shelf_alignment() const { return shelf_alignment_; }
private:
friend class TrayLayerAnimationObserver;
// Called from Initialize after all status area trays have been created.
// Sets the border based on the position of the view.
void SetBorder();
// Unowned pointer to parent widget.
StatusAreaWidget* status_area_widget_;
......@@ -117,8 +106,6 @@ class ASH_EXPORT TrayBackgroundView : public internal::ActionableView,
internal::BackgroundAnimator hide_background_animator_;
internal::BackgroundAnimator hover_background_animator_;
scoped_ptr<internal::TrayLayerAnimationObserver>
layer_animation_observer_;
DISALLOW_COPY_AND_ASSIGN(TrayBackgroundView);
};
......
......@@ -762,7 +762,6 @@ class WebNotificationTray::Bubble : public TrayBubbleView::Host,
}
views::Widget* bubble_widget() const { return bubble_widget_; }
TrayBubbleView* bubble_view() const { return bubble_view_; }
// Overridden from TrayBubbleView::Host.
virtual void BubbleViewDestroyed() OVERRIDE {
......@@ -967,16 +966,6 @@ void WebNotificationTray::SetShelfAlignment(ShelfAlignment alignment) {
HideNotificationBubble();
}
void WebNotificationTray::AnchorUpdated() {
if (notification_bubble_.get()) {
notification_bubble_->bubble_view()->UpdateBubble();
// Ensure that the notification buble is above the launcher/status area.
notification_bubble_->bubble_view()->GetWidget()->StackAtTop();
}
if (message_center_bubble_.get())
message_center_bubble_->bubble_view()->UpdateBubble();
}
// Protected methods (invoked only from Bubble and its child classes)
void WebNotificationTray::SendRemoveNotification(const std::string& id) {
......@@ -1052,10 +1041,7 @@ void WebNotificationTray::UpdateTray() {
count_label_->SetEnabledColor(
(notification_list()->notifications().size() == 0) ?
kMessageCountDimmedColor : kMessageCountColor);
bool is_visible =
(status_area_widget()->login_status() != user::LOGGED_IN_NONE) &&
(status_area_widget()->login_status() != user::LOGGED_IN_LOCKED);
SetVisible(is_visible);
SetVisible((status_area_widget()->login_status() != user::LOGGED_IN_NONE));
Layout();
SchedulePaint();
}
......
......@@ -118,7 +118,6 @@ class ASH_EXPORT WebNotificationTray : public internal::TrayBackgroundView {
// Overridden from TrayBackgroundView.
virtual void SetShelfAlignment(ShelfAlignment alignment) OVERRIDE;
virtual void AnchorUpdated() OVERRIDE;
// Overridden from internal::ActionableView.
virtual bool PerformAction(const ui::Event& event) 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