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