#include "ash/system/tray/tray_bubble_wrapper.h"
#include "ash/system/tray/tray_constants.h"
#include "ash/system/tray/tray_utils.h"
+#include "ash/system/web_notification/ash_popup_alignment_delegate.h"
#include "base/auto_reset.h"
#include "base/i18n/number_formatting.h"
#include "base/i18n/rtl.h"
#include "base/strings/utf_string_conversions.h"
#include "grit/ash_strings.h"
-#include "grit/ui_strings.h"
-#include "ui/aura/root_window.h"
#include "ui/aura/window.h"
+#include "ui/aura/window_event_dispatcher.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/screen.h"
#include "ui/message_center/message_center_style.h"
#include "ui/message_center/message_center_tray_delegate.h"
-#include "ui/message_center/message_center_util.h"
#include "ui/message_center/views/message_bubble_base.h"
#include "ui/message_center/views/message_center_bubble.h"
#include "ui/message_center/views/message_popup_collection.h"
+#include "ui/strings/grit/ui_strings.h"
#include "ui/views/bubble/tray_bubble_view.h"
#include "ui/views/controls/button/custom_button.h"
#include "ui/views/controls/image_view.h"
}
-namespace internal {
namespace {
-const SkColor kWebNotificationColorNoUnread = SkColorSetA(SK_ColorWHITE, 128);
+const SkColor kWebNotificationColorNoUnread =
+ SkColorSetARGB(128, 255, 255, 255);
const SkColor kWebNotificationColorWithUnread = SK_ColorWHITE;
}
-// Observes the change of work area (including temporary change by auto-hide)
-// and notifies MessagePopupCollection.
-class WorkAreaObserver : public ShelfLayoutManagerObserver,
- public ShellObserver {
- public:
- WorkAreaObserver();
- virtual ~WorkAreaObserver();
-
- void SetSystemTrayHeight(int height);
-
- // Starts observing |shelf| and shell and sends the change to |collection|.
- void StartObserving(message_center::MessagePopupCollection* collection,
- aura::Window* root_window);
-
- // Stops the observing session.
- void StopObserving();
-
- // Overridden from ShellObserver:
- virtual void OnDisplayWorkAreaInsetsChanged() OVERRIDE;
-
- // Overridden from ShelfLayoutManagerObserver:
- virtual void OnAutoHideStateChanged(ShelfAutoHideState new_state) OVERRIDE;
-
- private:
- // Updates |shelf_| from |root_window_|.
- void UpdateShelf();
-
- message_center::MessagePopupCollection* collection_;
- aura::Window* root_window_;
- ShelfLayoutManager* shelf_;
- int system_tray_height_;
-
- DISALLOW_COPY_AND_ASSIGN(WorkAreaObserver);
-};
-
-WorkAreaObserver::WorkAreaObserver()
- : collection_(NULL),
- root_window_(NULL),
- shelf_(NULL),
- system_tray_height_(0) {
-}
-
-WorkAreaObserver::~WorkAreaObserver() {
- StopObserving();
-}
-
-void WorkAreaObserver::SetSystemTrayHeight(int height) {
- system_tray_height_ = height;
-
- // If the shelf is shown during auto-hide state, the distance from the edge
- // should be reduced by the height of shelf's shown height.
- if (shelf_ && shelf_->visibility_state() == SHELF_AUTO_HIDE &&
- shelf_->auto_hide_state() == SHELF_AUTO_HIDE_SHOWN) {
- system_tray_height_ -= ShelfLayoutManager::GetPreferredShelfSize() -
- ShelfLayoutManager::kAutoHideSize;
- }
-
- if (system_tray_height_ > 0 && ash::switches::UseAlternateShelfLayout())
- system_tray_height_ += message_center::kMarginBetweenItems;
-
- if (!shelf_)
- return;
-
- OnAutoHideStateChanged(shelf_->auto_hide_state());
-}
-
-void WorkAreaObserver::StartObserving(
- message_center::MessagePopupCollection* collection,
- aura::Window* root_window) {
- DCHECK(collection);
- collection_ = collection;
- root_window_ = root_window;
- UpdateShelf();
- Shell::GetInstance()->AddShellObserver(this);
- if (system_tray_height_ > 0)
- OnAutoHideStateChanged(shelf_->auto_hide_state());
-}
-
-void WorkAreaObserver::StopObserving() {
- Shell::GetInstance()->RemoveShellObserver(this);
- if (shelf_)
- shelf_->RemoveObserver(this);
- collection_ = NULL;
- shelf_ = NULL;
-}
-
-void WorkAreaObserver::OnDisplayWorkAreaInsetsChanged() {
- UpdateShelf();
-
- collection_->OnDisplayBoundsChanged(
- Shell::GetScreen()->GetDisplayNearestWindow(
- shelf_->shelf_widget()->GetNativeView()));
-}
-
-void WorkAreaObserver::OnAutoHideStateChanged(ShelfAutoHideState new_state) {
- gfx::Display display = Shell::GetScreen()->GetDisplayNearestWindow(
- shelf_->shelf_widget()->GetNativeView());
- gfx::Rect work_area = display.work_area();
- int width = 0;
- if ((shelf_->visibility_state() == SHELF_AUTO_HIDE) &&
- new_state == SHELF_AUTO_HIDE_SHOWN) {
- // Since the work_area is already reduced by kAutoHideSize, the inset width
- // should be just the difference.
- width = ShelfLayoutManager::GetPreferredShelfSize() -
- ShelfLayoutManager::kAutoHideSize;
- }
- work_area.Inset(shelf_->SelectValueForShelfAlignment(
- gfx::Insets(0, 0, width, 0),
- gfx::Insets(0, width, 0, 0),
- gfx::Insets(0, 0, 0, width),
- gfx::Insets(width, 0, 0, 0)));
- if (system_tray_height_ > 0) {
- work_area.set_height(
- std::max(0, work_area.height() - system_tray_height_));
- if (shelf_->GetAlignment() == SHELF_ALIGNMENT_TOP)
- work_area.set_y(work_area.y() + system_tray_height_);
- }
- collection_->SetDisplayInfo(work_area, display.bounds());
-}
-
-void WorkAreaObserver::UpdateShelf() {
- if (shelf_)
- return;
-
- shelf_ = ShelfLayoutManager::ForShelf(root_window_);
- if (shelf_)
- shelf_->AddObserver(this);
-}
-
// Class to initialize and manage the WebNotificationBubble and
// TrayBubbleWrapper instances for a bubble.
class WebNotificationBubbleWrapper {
}
views::TrayBubbleView* bubble_view = views::TrayBubbleView::Create(
tray->GetBubbleWindowContainer(), anchor, tray, &init_params);
- if (ash::switches::UseAlternateShelfLayout())
- bubble_view->SetArrowPaintType(views::BubbleBorder::PAINT_NONE);
bubble_wrapper_.reset(new TrayBubbleWrapper(tray, bubble_view));
+ bubble_view->SetArrowPaintType(views::BubbleBorder::PAINT_NONE);
bubble->InitializeContents(bubble_view);
}
private:
scoped_ptr<message_center::MessageBubbleBase> bubble_;
- scoped_ptr<internal::TrayBubbleWrapper> bubble_wrapper_;
+ scoped_ptr<TrayBubbleWrapper> bubble_wrapper_;
DISALLOW_COPY_AND_ASSIGN(WebNotificationBubbleWrapper);
};
protected:
// Overridden from views::ImageButton:
- virtual gfx::Size GetPreferredSize() OVERRIDE {
- const int notification_item_size = GetShelfItemHeight();
- return gfx::Size(notification_item_size, notification_item_size);
+ virtual gfx::Size GetPreferredSize() const OVERRIDE {
+ return gfx::Size(kShelfItemHeight, kShelfItemHeight);
}
- virtual int GetHeightForWidth(int width) OVERRIDE {
+ virtual int GetHeightForWidth(int width) const OVERRIDE {
return GetPreferredSize().height();
}
DISALLOW_COPY_AND_ASSIGN(WebNotificationButton);
};
-} // namespace internal
-
-WebNotificationTray::WebNotificationTray(
- internal::StatusAreaWidget* status_area_widget)
+WebNotificationTray::WebNotificationTray(StatusAreaWidget* status_area_widget)
: TrayBackgroundView(status_area_widget),
button_(NULL),
show_message_center_on_unlock_(false),
should_update_tray_content_(false),
should_block_shelf_auto_hide_(false) {
- button_ = new internal::WebNotificationButton(this);
+ button_ = new WebNotificationButton(this);
button_->set_triggerable_event_flags(
ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON);
tray_container()->AddChildView(button_);
SetContentsBackground();
tray_container()->SetBorder(views::Border::NullBorder());
- SetVisible(false);
message_center_tray_.reset(new message_center::MessageCenterTray(
this,
message_center::MessageCenter::Get()));
- work_area_observer_.reset(new internal::WorkAreaObserver());
+ popup_alignment_delegate_.reset(new AshPopupAlignmentDelegate());
+ popup_collection_.reset(new message_center::MessagePopupCollection(
+ ash::Shell::GetContainer(
+ status_area_widget->GetNativeView()->GetRootWindow(),
+ kShellWindowId_StatusContainer),
+ message_center(),
+ message_center_tray_.get(),
+ popup_alignment_delegate_.get()));
+ const gfx::Display& display = Shell::GetScreen()->GetDisplayNearestWindow(
+ status_area_widget->GetNativeView());
+ popup_alignment_delegate_->StartObserving(Shell::GetScreen(), display);
OnMessageCenterTrayChanged();
}
WebNotificationTray::~WebNotificationTray() {
// Release any child views that might have back pointers before ~View().
message_center_bubble_.reset();
+ popup_alignment_delegate_.reset();
popup_collection_.reset();
- work_area_observer_.reset();
}
// Public methods.
new message_center::MessageCenterBubble(
message_center(),
message_center_tray_.get(),
- ash::switches::UseAlternateShelfLayout());
+ true);
int max_height = 0;
aura::Window* status_area_window = status_area_widget()->GetNativeView();
}
message_center_bubble->SetMaxHeight(std::max(0,
- max_height - GetTraySpacing()));
+ max_height - kTraySpacing));
if (show_settings)
message_center_bubble->SetSettingsVisible();
message_center_bubble_.reset(
- new internal::WebNotificationBubbleWrapper(this, message_center_bubble));
+ new WebNotificationBubbleWrapper(this, message_center_bubble));
status_area_widget()->SetHideSystemNotifications(true);
GetShelfLayoutManager()->UpdateAutoHideState();
}
void WebNotificationTray::SetSystemTrayHeight(int height) {
- work_area_observer_->SetSystemTrayHeight(height);
+ popup_alignment_delegate_->SetSystemTrayHeight(height);
}
bool WebNotificationTray::ShowPopups() {
if (message_center_bubble())
return false;
- popup_collection_.reset(new message_center::MessagePopupCollection(
- ash::Shell::GetContainer(
- GetWidget()->GetNativeView()->GetRootWindow(),
- internal::kShellWindowId_StatusContainer),
- message_center(),
- message_center_tray_.get(),
- ash::switches::UseAlternateShelfLayout()));
- work_area_observer_->StartObserving(
- popup_collection_.get(), GetWidget()->GetNativeView()->GetRootWindow());
+ popup_collection_->DoUpdateIfPossible();
return true;
}
void WebNotificationTray::HidePopups() {
DCHECK(popup_collection_.get());
-
popup_collection_->MarkAllPopupsShown();
- popup_collection_.reset();
- work_area_observer_->StopObserving();
}
// Private methods.
void WebNotificationTray::SetShelfAlignment(ShelfAlignment alignment) {
if (alignment == shelf_alignment())
return;
- internal::TrayBackgroundView::SetShelfAlignment(alignment);
+ TrayBackgroundView::SetShelfAlignment(alignment);
tray_container()->SetBorder(views::Border::NullBorder());
// Destroy any existing bubble so that it will be rebuilt correctly.
message_center_tray_->HideMessageCenterBubble();
gfx::Rect WebNotificationTray::GetAnchorRect(
views::Widget* anchor_widget,
views::TrayBubbleView::AnchorType anchor_type,
- views::TrayBubbleView::AnchorAlignment anchor_alignment) {
+ views::TrayBubbleView::AnchorAlignment anchor_alignment) const {
return GetBubbleAnchorRect(anchor_widget, anchor_type, anchor_alignment);
}
bool WebNotificationTray::IsContextMenuEnabled() const {
user::LoginStatus login_status = status_area_widget()->login_status();
+ bool userAddingRunning = ash::Shell::GetInstance()
+ ->session_state_delegate()
+ ->IsInSecondaryLoginScreen();
+
return login_status != user::LOGGED_IN_NONE
- && login_status != user::LOGGED_IN_LOCKED;
+ && login_status != user::LOGGED_IN_LOCKED && !userAddingRunning;
}
message_center::MessageCenterTray* WebNotificationTray::GetMessageCenterTray() {
button_->SetState(views::CustomButton::STATE_PRESSED);
else
button_->SetState(views::CustomButton::STATE_NORMAL);
+ bool userAddingRunning = ash::Shell::GetInstance()
+ ->session_state_delegate()
+ ->IsInSecondaryLoginScreen();
+
SetVisible((status_area_widget()->login_status() != user::LOGGED_IN_NONE) &&
(status_area_widget()->login_status() != user::LOGGED_IN_LOCKED) &&
- (message_center->NotificationCount() > 0));
+ !userAddingRunning && (message_center->NotificationCount() > 0));
Layout();
SchedulePaint();
}