Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(771)

Unified Diff: ash/system/web_notification/web_notification_tray.cc

Issue 19291004: Observes work area change and auto-hide for notifications. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ash/system/web_notification/web_notification_tray.cc
diff --git a/ash/system/web_notification/web_notification_tray.cc b/ash/system/web_notification/web_notification_tray.cc
index b4a1e573879f12d2efb0e85d7b48f65afd09922e..e52ff00563c2648cc4f3178a79c78e826de48191 100644
--- a/ash/system/web_notification/web_notification_tray.cc
+++ b/ash/system/web_notification/web_notification_tray.cc
@@ -7,6 +7,8 @@
#include "ash/ash_switches.h"
#include "ash/root_window_controller.h"
#include "ash/shelf/shelf_layout_manager.h"
+#include "ash/shelf/shelf_layout_manager_observer.h"
+#include "ash/shelf/shelf_widget.h"
#include "ash/shell.h"
#include "ash/shell_window_ids.h"
#include "ash/system/status_area_widget.h"
@@ -63,9 +65,74 @@ 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(message_center::MessagePopupCollection* collection,
+ ShelfLayoutManager* shelf);
+ virtual ~WorkAreaObserver();
+
+ // Overridden from ShellObserver:
+ virtual void OnDisplayWorkAreaInsetsChanged() OVERRIDE;
+
+ // Overridden from ShelfLayoutManagerObserver:
+ virtual void OnAutoHideStateChanged(ShelfAutoHideState new_state) OVERRIDE;
+
+ private:
+ message_center::MessagePopupCollection* collection_;
+ ShelfLayoutManager* shelf_;
+
+ DISALLOW_COPY_AND_ASSIGN(WorkAreaObserver);
+};
+
+WorkAreaObserver::WorkAreaObserver(
+ message_center::MessagePopupCollection* collection,
+ ShelfLayoutManager* shelf)
+ : collection_(collection),
+ shelf_(shelf) {
+ DCHECK(collection_);
+ shelf_->AddObserver(this);
+ Shell::GetInstance()->AddShellObserver(this);
+}
+
+WorkAreaObserver::~WorkAreaObserver() {
+ Shell::GetInstance()->RemoveShellObserver(this);
+ shelf_->RemoveObserver(this);
+}
+
+void WorkAreaObserver::OnDisplayWorkAreaInsetsChanged() {
+ collection_->OnDisplayBoundsChanged(
+ Shell::GetScreen()->GetDisplayNearestWindow(
+ shelf_->shelf_widget()->GetNativeView()));
+}
+
+void WorkAreaObserver::OnAutoHideStateChanged(ShelfAutoHideState new_state) {
+ gfx::Rect work_area = Shell::GetScreen()->GetDisplayNearestWindow(
+ shelf_->shelf_widget()->GetNativeView()).work_area();
+ int width = (new_state == SHELF_AUTO_HIDE_HIDDEN) ?
+ ShelfLayoutManager::kAutoHideSize :
+ ShelfLayoutManager::GetPreferredShelfSize();
+ switch (shelf_->GetAlignment()) {
+ case SHELF_ALIGNMENT_BOTTOM:
+ work_area.Inset(0, 0, 0, width);
+ break;
+ case SHELF_ALIGNMENT_LEFT:
+ work_area.Inset(width, 0, 0, 0);
+ break;
+ case SHELF_ALIGNMENT_RIGHT:
+ work_area.Inset(0, 0, width, 0);
+ break;
+ case SHELF_ALIGNMENT_TOP:
+ work_area.Inset(0, width, 0, 0);
+ break;
+ }
+ collection_->SetWorkArea(work_area);
+}
+
// Class to initialize and manage the WebNotificationBubble and
// TrayBubbleWrapper instances for a bubble.
-
class WebNotificationBubbleWrapper {
public:
// Takes ownership of |bubble| and creates |bubble_wrapper_|.
@@ -185,6 +252,7 @@ WebNotificationTray::~WebNotificationTray() {
// Release any child views that might have back pointers before ~View().
message_center_bubble_.reset();
popup_collection_.reset();
+ work_area_observer_.reset();
}
// Public methods.
@@ -270,12 +338,14 @@ bool WebNotificationTray::ShowPopups() {
internal::kShellWindowId_StatusContainer),
message_center(),
message_center_tray_.get()));
-
+ work_area_observer_.reset(new internal::WorkAreaObserver(
+ popup_collection_.get(), GetShelfLayoutManager()));
return true;
}
void WebNotificationTray::HidePopups() {
popup_collection_.reset();
+ work_area_observer_.reset();
}
// Private methods.
« no previous file with comments | « ash/system/web_notification/web_notification_tray.h ('k') | ui/message_center/views/message_popup_collection.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698