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

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: 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 205d84e3dcc969a8cbd9c34d4e2c24b8718a20aa..166d444df521a0bb109a3f3276bbef46aa85e31a 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 to 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_|.
@@ -268,12 +335,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();
dewittj 2013/07/16 21:31:33 I don't love how the work_area_observer_ needs to
Jun Mukai 2013/07/16 22:49:42 we can disable work_area_observer_ or something, b
}
// Private methods.

Powered by Google App Engine
This is Rietveld 408576698