| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ash/system/web_notification/web_notification_tray.h" | 5 #include "ash/system/web_notification/web_notification_tray.h" |
| 6 | 6 |
| 7 #include "ash/ash_switches.h" | 7 #include "ash/ash_switches.h" |
| 8 #include "ash/root_window_controller.h" | 8 #include "ash/root_window_controller.h" |
| 9 #include "ash/shelf/shelf_layout_manager.h" | 9 #include "ash/shelf/shelf_layout_manager.h" |
| 10 #include "ash/shelf/shelf_layout_manager_observer.h" | 10 #include "ash/shelf/shelf_layout_manager_observer.h" |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 StopObserving(); | 116 StopObserving(); |
| 117 } | 117 } |
| 118 | 118 |
| 119 void WorkAreaObserver::SetSystemTrayHeight(int height) { | 119 void WorkAreaObserver::SetSystemTrayHeight(int height) { |
| 120 system_tray_height_ = height; | 120 system_tray_height_ = height; |
| 121 | 121 |
| 122 // If the shelf is shown during auto-hide state, the distance from the edge | 122 // If the shelf is shown during auto-hide state, the distance from the edge |
| 123 // should be reduced by the height of shelf's shown height. | 123 // should be reduced by the height of shelf's shown height. |
| 124 if (shelf_ && shelf_->visibility_state() == SHELF_AUTO_HIDE && | 124 if (shelf_ && shelf_->visibility_state() == SHELF_AUTO_HIDE && |
| 125 shelf_->auto_hide_state() == SHELF_AUTO_HIDE_SHOWN) { | 125 shelf_->auto_hide_state() == SHELF_AUTO_HIDE_SHOWN) { |
| 126 system_tray_height_ -= ShelfLayoutManager::GetPreferredShelfSize() - | 126 system_tray_height_ -= kShelfSize - ShelfLayoutManager::kAutoHideSize; |
| 127 ShelfLayoutManager::kAutoHideSize; | |
| 128 } | 127 } |
| 129 | 128 |
| 130 if (system_tray_height_ > 0 && ash::switches::UseAlternateShelfLayout()) | 129 if (system_tray_height_ > 0) |
| 131 system_tray_height_ += message_center::kMarginBetweenItems; | 130 system_tray_height_ += message_center::kMarginBetweenItems; |
| 132 | 131 |
| 133 if (!shelf_) | 132 if (!shelf_) |
| 134 return; | 133 return; |
| 135 | 134 |
| 136 OnAutoHideStateChanged(shelf_->auto_hide_state()); | 135 OnAutoHideStateChanged(shelf_->auto_hide_state()); |
| 137 } | 136 } |
| 138 | 137 |
| 139 void WorkAreaObserver::StartObserving( | 138 void WorkAreaObserver::StartObserving( |
| 140 message_center::MessagePopupCollection* collection, | 139 message_center::MessagePopupCollection* collection, |
| (...skipping 25 matching lines...) Expand all Loading... |
| 166 | 165 |
| 167 void WorkAreaObserver::OnAutoHideStateChanged(ShelfAutoHideState new_state) { | 166 void WorkAreaObserver::OnAutoHideStateChanged(ShelfAutoHideState new_state) { |
| 168 gfx::Display display = Shell::GetScreen()->GetDisplayNearestWindow( | 167 gfx::Display display = Shell::GetScreen()->GetDisplayNearestWindow( |
| 169 shelf_->shelf_widget()->GetNativeView()); | 168 shelf_->shelf_widget()->GetNativeView()); |
| 170 gfx::Rect work_area = display.work_area(); | 169 gfx::Rect work_area = display.work_area(); |
| 171 int width = 0; | 170 int width = 0; |
| 172 if ((shelf_->visibility_state() == SHELF_AUTO_HIDE) && | 171 if ((shelf_->visibility_state() == SHELF_AUTO_HIDE) && |
| 173 new_state == SHELF_AUTO_HIDE_SHOWN) { | 172 new_state == SHELF_AUTO_HIDE_SHOWN) { |
| 174 // Since the work_area is already reduced by kAutoHideSize, the inset width | 173 // Since the work_area is already reduced by kAutoHideSize, the inset width |
| 175 // should be just the difference. | 174 // should be just the difference. |
| 176 width = ShelfLayoutManager::GetPreferredShelfSize() - | 175 width = kShelfSize - ShelfLayoutManager::kAutoHideSize; |
| 177 ShelfLayoutManager::kAutoHideSize; | |
| 178 } | 176 } |
| 179 work_area.Inset(shelf_->SelectValueForShelfAlignment( | 177 work_area.Inset(shelf_->SelectValueForShelfAlignment( |
| 180 gfx::Insets(0, 0, width, 0), | 178 gfx::Insets(0, 0, width, 0), |
| 181 gfx::Insets(0, width, 0, 0), | 179 gfx::Insets(0, width, 0, 0), |
| 182 gfx::Insets(0, 0, 0, width), | 180 gfx::Insets(0, 0, 0, width), |
| 183 gfx::Insets(width, 0, 0, 0))); | 181 gfx::Insets(width, 0, 0, 0))); |
| 184 if (system_tray_height_ > 0) { | 182 if (system_tray_height_ > 0) { |
| 185 work_area.set_height( | 183 work_area.set_height( |
| 186 std::max(0, work_area.height() - system_tray_height_)); | 184 std::max(0, work_area.height() - system_tray_height_)); |
| 187 if (shelf_->GetAlignment() == SHELF_ALIGNMENT_TOP) | 185 if (shelf_->GetAlignment() == SHELF_ALIGNMENT_TOP) |
| (...skipping 24 matching lines...) Expand all Loading... |
| 212 views::TrayBubbleView::InitParams init_params = | 210 views::TrayBubbleView::InitParams init_params = |
| 213 bubble->GetInitParams(anchor_alignment); | 211 bubble->GetInitParams(anchor_alignment); |
| 214 views::View* anchor = tray->tray_container(); | 212 views::View* anchor = tray->tray_container(); |
| 215 if (anchor_alignment == views::TrayBubbleView::ANCHOR_ALIGNMENT_BOTTOM) { | 213 if (anchor_alignment == views::TrayBubbleView::ANCHOR_ALIGNMENT_BOTTOM) { |
| 216 gfx::Point bounds(anchor->width() / 2, 0); | 214 gfx::Point bounds(anchor->width() / 2, 0); |
| 217 views::View::ConvertPointToWidget(anchor, &bounds); | 215 views::View::ConvertPointToWidget(anchor, &bounds); |
| 218 init_params.arrow_offset = bounds.x(); | 216 init_params.arrow_offset = bounds.x(); |
| 219 } | 217 } |
| 220 views::TrayBubbleView* bubble_view = views::TrayBubbleView::Create( | 218 views::TrayBubbleView* bubble_view = views::TrayBubbleView::Create( |
| 221 tray->GetBubbleWindowContainer(), anchor, tray, &init_params); | 219 tray->GetBubbleWindowContainer(), anchor, tray, &init_params); |
| 222 if (ash::switches::UseAlternateShelfLayout()) | 220 bubble_view->SetArrowPaintType(views::BubbleBorder::PAINT_NONE); |
| 223 bubble_view->SetArrowPaintType(views::BubbleBorder::PAINT_NONE); | |
| 224 bubble_wrapper_.reset(new TrayBubbleWrapper(tray, bubble_view)); | 221 bubble_wrapper_.reset(new TrayBubbleWrapper(tray, bubble_view)); |
| 225 bubble->InitializeContents(bubble_view); | 222 bubble->InitializeContents(bubble_view); |
| 226 } | 223 } |
| 227 | 224 |
| 228 message_center::MessageBubbleBase* bubble() const { return bubble_.get(); } | 225 message_center::MessageBubbleBase* bubble() const { return bubble_.get(); } |
| 229 | 226 |
| 230 // Convenience accessors. | 227 // Convenience accessors. |
| 231 views::TrayBubbleView* bubble_view() const { return bubble_->bubble_view(); } | 228 views::TrayBubbleView* bubble_view() const { return bubble_->bubble_view(); } |
| 232 | 229 |
| 233 private: | 230 private: |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 // in ash_strings. | 262 // in ash_strings. |
| 266 unread_label_->SetText((unread_count > 9) ? | 263 unread_label_->SetText((unread_count > 9) ? |
| 267 l10n_util::GetStringUTF16(IDS_ASH_NOTIFICATION_UNREAD_COUNT_NINE_PLUS) : | 264 l10n_util::GetStringUTF16(IDS_ASH_NOTIFICATION_UNREAD_COUNT_NINE_PLUS) : |
| 268 base::FormatNumber(unread_count)); | 265 base::FormatNumber(unread_count)); |
| 269 UpdateIconVisibility(); | 266 UpdateIconVisibility(); |
| 270 } | 267 } |
| 271 | 268 |
| 272 protected: | 269 protected: |
| 273 // Overridden from views::ImageButton: | 270 // Overridden from views::ImageButton: |
| 274 virtual gfx::Size GetPreferredSize() OVERRIDE { | 271 virtual gfx::Size GetPreferredSize() OVERRIDE { |
| 275 const int notification_item_size = GetShelfItemHeight(); | 272 return gfx::Size(kShelfItemHeight, kShelfItemHeight); |
| 276 return gfx::Size(notification_item_size, notification_item_size); | |
| 277 } | 273 } |
| 278 | 274 |
| 279 virtual int GetHeightForWidth(int width) OVERRIDE { | 275 virtual int GetHeightForWidth(int width) OVERRIDE { |
| 280 return GetPreferredSize().height(); | 276 return GetPreferredSize().height(); |
| 281 } | 277 } |
| 282 | 278 |
| 283 private: | 279 private: |
| 284 void UpdateIconVisibility() { | 280 void UpdateIconVisibility() { |
| 285 unread_label_->SetEnabledColor( | 281 unread_label_->SetEnabledColor( |
| 286 (!is_bubble_visible_ && unread_count_ > 0) ? | 282 (!is_bubble_visible_ && unread_count_ > 0) ? |
| (...skipping 24 matching lines...) Expand all Loading... |
| 311 SetVisible(false); | 307 SetVisible(false); |
| 312 message_center_tray_.reset(new message_center::MessageCenterTray( | 308 message_center_tray_.reset(new message_center::MessageCenterTray( |
| 313 this, | 309 this, |
| 314 message_center::MessageCenter::Get())); | 310 message_center::MessageCenter::Get())); |
| 315 popup_collection_.reset(new message_center::MessagePopupCollection( | 311 popup_collection_.reset(new message_center::MessagePopupCollection( |
| 316 ash::Shell::GetContainer( | 312 ash::Shell::GetContainer( |
| 317 status_area_widget->GetNativeView()->GetRootWindow(), | 313 status_area_widget->GetNativeView()->GetRootWindow(), |
| 318 kShellWindowId_StatusContainer), | 314 kShellWindowId_StatusContainer), |
| 319 message_center(), | 315 message_center(), |
| 320 message_center_tray_.get(), | 316 message_center_tray_.get(), |
| 321 ash::switches::UseAlternateShelfLayout())); | 317 true)); |
| 322 work_area_observer_.reset(new WorkAreaObserver()); | 318 work_area_observer_.reset(new WorkAreaObserver()); |
| 323 work_area_observer_->StartObserving( | 319 work_area_observer_->StartObserving( |
| 324 popup_collection_.get(), | 320 popup_collection_.get(), |
| 325 status_area_widget->GetNativeView()->GetRootWindow()); | 321 status_area_widget->GetNativeView()->GetRootWindow()); |
| 326 OnMessageCenterTrayChanged(); | 322 OnMessageCenterTrayChanged(); |
| 327 } | 323 } |
| 328 | 324 |
| 329 WebNotificationTray::~WebNotificationTray() { | 325 WebNotificationTray::~WebNotificationTray() { |
| 330 // Release any child views that might have back pointers before ~View(). | 326 // Release any child views that might have back pointers before ~View(). |
| 331 message_center_bubble_.reset(); | 327 message_center_bubble_.reset(); |
| 332 popup_collection_.reset(); | 328 popup_collection_.reset(); |
| 333 work_area_observer_.reset(); | 329 work_area_observer_.reset(); |
| 334 } | 330 } |
| 335 | 331 |
| 336 // Public methods. | 332 // Public methods. |
| 337 | 333 |
| 338 bool WebNotificationTray::ShowMessageCenterInternal(bool show_settings) { | 334 bool WebNotificationTray::ShowMessageCenterInternal(bool show_settings) { |
| 339 if (!ShouldShowMessageCenter()) | 335 if (!ShouldShowMessageCenter()) |
| 340 return false; | 336 return false; |
| 341 | 337 |
| 342 should_block_shelf_auto_hide_ = true; | 338 should_block_shelf_auto_hide_ = true; |
| 343 message_center::MessageCenterBubble* message_center_bubble = | 339 message_center::MessageCenterBubble* message_center_bubble = |
| 344 new message_center::MessageCenterBubble( | 340 new message_center::MessageCenterBubble( |
| 345 message_center(), | 341 message_center(), |
| 346 message_center_tray_.get(), | 342 message_center_tray_.get(), |
| 347 ash::switches::UseAlternateShelfLayout()); | 343 true); |
| 348 | 344 |
| 349 int max_height = 0; | 345 int max_height = 0; |
| 350 aura::Window* status_area_window = status_area_widget()->GetNativeView(); | 346 aura::Window* status_area_window = status_area_widget()->GetNativeView(); |
| 351 switch (GetShelfLayoutManager()->GetAlignment()) { | 347 switch (GetShelfLayoutManager()->GetAlignment()) { |
| 352 case SHELF_ALIGNMENT_BOTTOM: { | 348 case SHELF_ALIGNMENT_BOTTOM: { |
| 353 gfx::Rect shelf_bounds = GetShelfLayoutManager()->GetIdealBounds(); | 349 gfx::Rect shelf_bounds = GetShelfLayoutManager()->GetIdealBounds(); |
| 354 max_height = shelf_bounds.y(); | 350 max_height = shelf_bounds.y(); |
| 355 break; | 351 break; |
| 356 } | 352 } |
| 357 case SHELF_ALIGNMENT_TOP: { | 353 case SHELF_ALIGNMENT_TOP: { |
| 358 aura::Window* root = status_area_window->GetRootWindow(); | 354 aura::Window* root = status_area_window->GetRootWindow(); |
| 359 max_height = | 355 max_height = |
| 360 root->bounds().height() - status_area_window->bounds().height(); | 356 root->bounds().height() - status_area_window->bounds().height(); |
| 361 break; | 357 break; |
| 362 } | 358 } |
| 363 case SHELF_ALIGNMENT_LEFT: | 359 case SHELF_ALIGNMENT_LEFT: |
| 364 case SHELF_ALIGNMENT_RIGHT: { | 360 case SHELF_ALIGNMENT_RIGHT: { |
| 365 // Assume that the bottom line of the status area widget and the bubble | 361 // Assume that the bottom line of the status area widget and the bubble |
| 366 // are aligned. | 362 // are aligned. |
| 367 max_height = status_area_window->GetBoundsInRootWindow().bottom(); | 363 max_height = status_area_window->GetBoundsInRootWindow().bottom(); |
| 368 break; | 364 break; |
| 369 } | 365 } |
| 370 default: | 366 default: |
| 371 NOTREACHED(); | 367 NOTREACHED(); |
| 372 } | 368 } |
| 373 | 369 |
| 374 message_center_bubble->SetMaxHeight(std::max(0, | 370 message_center_bubble->SetMaxHeight(std::max(0, |
| 375 max_height - GetTraySpacing())); | 371 max_height - kTraySpacing)); |
| 376 if (show_settings) | 372 if (show_settings) |
| 377 message_center_bubble->SetSettingsVisible(); | 373 message_center_bubble->SetSettingsVisible(); |
| 378 message_center_bubble_.reset( | 374 message_center_bubble_.reset( |
| 379 new WebNotificationBubbleWrapper(this, message_center_bubble)); | 375 new WebNotificationBubbleWrapper(this, message_center_bubble)); |
| 380 | 376 |
| 381 status_area_widget()->SetHideSystemNotifications(true); | 377 status_area_widget()->SetHideSystemNotifications(true); |
| 382 GetShelfLayoutManager()->UpdateAutoHideState(); | 378 GetShelfLayoutManager()->UpdateAutoHideState(); |
| 383 button_->SetBubbleVisible(true); | 379 button_->SetBubbleVisible(true); |
| 384 SetDrawBackgroundAsActive(true); | 380 SetDrawBackgroundAsActive(true); |
| 385 return true; | 381 return true; |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 616 | 612 |
| 617 message_center::MessageCenterBubble* | 613 message_center::MessageCenterBubble* |
| 618 WebNotificationTray::GetMessageCenterBubbleForTest() { | 614 WebNotificationTray::GetMessageCenterBubbleForTest() { |
| 619 if (!message_center_bubble()) | 615 if (!message_center_bubble()) |
| 620 return NULL; | 616 return NULL; |
| 621 return static_cast<message_center::MessageCenterBubble*>( | 617 return static_cast<message_center::MessageCenterBubble*>( |
| 622 message_center_bubble()->bubble()); | 618 message_center_bubble()->bubble()); |
| 623 } | 619 } |
| 624 | 620 |
| 625 } // namespace ash | 621 } // namespace ash |
| OLD | NEW |