| 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/public/cpp/shell_window_ids.h" | 7 #include "ash/public/cpp/shell_window_ids.h" |
| 8 #include "ash/resources/vector_icons/vector_icons.h" | 8 #include "ash/resources/vector_icons/vector_icons.h" |
| 9 #include "ash/root_window_controller.h" | 9 #include "ash/root_window_controller.h" |
| 10 #include "ash/session/session_controller.h" | 10 #include "ash/session/session_controller.h" |
| 11 #include "ash/shelf/shelf_constants.h" | 11 #include "ash/shelf/shelf_constants.h" |
| 12 #include "ash/shelf/wm_shelf.h" | 12 #include "ash/shelf/wm_shelf.h" |
| 13 #include "ash/shelf/wm_shelf_util.h" | 13 #include "ash/shelf/wm_shelf_util.h" |
| 14 #include "ash/shell.h" | 14 #include "ash/shell.h" |
| 15 #include "ash/strings/grit/ash_strings.h" | 15 #include "ash/strings/grit/ash_strings.h" |
| 16 #include "ash/system/status_area_widget.h" | 16 #include "ash/system/status_area_widget.h" |
| 17 #include "ash/system/tray/system_tray.h" | 17 #include "ash/system/tray/system_tray.h" |
| 18 #include "ash/system/tray/system_tray_delegate.h" | 18 #include "ash/system/tray/system_tray_delegate.h" |
| 19 #include "ash/system/tray/tray_bubble_wrapper.h" | 19 #include "ash/system/tray/tray_bubble_wrapper.h" |
| 20 #include "ash/system/tray/tray_constants.h" | 20 #include "ash/system/tray/tray_constants.h" |
| 21 #include "ash/system/tray/tray_container.h" |
| 21 #include "ash/system/tray/tray_utils.h" | 22 #include "ash/system/tray/tray_utils.h" |
| 22 #include "ash/system/web_notification/ash_popup_alignment_delegate.h" | 23 #include "ash/system/web_notification/ash_popup_alignment_delegate.h" |
| 23 #include "ash/wm_window.h" | 24 #include "ash/wm_window.h" |
| 24 #include "base/auto_reset.h" | 25 #include "base/auto_reset.h" |
| 25 #include "base/i18n/number_formatting.h" | 26 #include "base/i18n/number_formatting.h" |
| 26 #include "base/i18n/rtl.h" | 27 #include "base/i18n/rtl.h" |
| 27 #include "base/strings/utf_string_conversions.h" | 28 #include "base/strings/utf_string_conversions.h" |
| 28 #include "base/threading/thread_task_runner_handle.h" | 29 #include "base/threading/thread_task_runner_handle.h" |
| 29 #include "ui/base/l10n/l10n_util.h" | 30 #include "ui/base/l10n/l10n_util.h" |
| 30 #include "ui/display/display.h" | 31 #include "ui/display/display.h" |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 protected: | 158 protected: |
| 158 // Overridden from views::View: | 159 // Overridden from views::View: |
| 159 gfx::Size GetPreferredSize() const override { | 160 gfx::Size GetPreferredSize() const override { |
| 160 if (!animation_.get() || !animation_->is_animating()) | 161 if (!animation_.get() || !animation_->is_animating()) |
| 161 return kTrayItemOuterSize; | 162 return kTrayItemOuterSize; |
| 162 | 163 |
| 163 // Animate the width (or height) when this item shows (or hides) so that | 164 // Animate the width (or height) when this item shows (or hides) so that |
| 164 // the icons on the left are shifted with the animation. | 165 // the icons on the left are shifted with the animation. |
| 165 // Note that TrayItemView does the same thing. | 166 // Note that TrayItemView does the same thing. |
| 166 gfx::Size size = kTrayItemOuterSize; | 167 gfx::Size size = kTrayItemOuterSize; |
| 167 if (IsHorizontalLayout()) { | 168 if (tray_->shelf()->IsHorizontalAlignment()) { |
| 168 size.set_width(std::max( | 169 size.set_width(std::max( |
| 169 1, gfx::ToRoundedInt(size.width() * animation_->GetCurrentValue()))); | 170 1, gfx::ToRoundedInt(size.width() * animation_->GetCurrentValue()))); |
| 170 } else { | 171 } else { |
| 171 size.set_height(std::max( | 172 size.set_height(std::max( |
| 172 1, gfx::ToRoundedInt(size.height() * animation_->GetCurrentValue()))); | 173 1, gfx::ToRoundedInt(size.height() * animation_->GetCurrentValue()))); |
| 173 } | 174 } |
| 174 return size; | 175 return size; |
| 175 } | 176 } |
| 176 | 177 |
| 177 int GetHeightForWidth(int width) const override { | 178 int GetHeightForWidth(int width) const override { |
| 178 return GetPreferredSize().height(); | 179 return GetPreferredSize().height(); |
| 179 } | 180 } |
| 180 | 181 |
| 181 bool IsHorizontalLayout() const { | |
| 182 return IsHorizontalAlignment(tray_->shelf_alignment()); | |
| 183 } | |
| 184 | |
| 185 private: | 182 private: |
| 186 // gfx::AnimationDelegate: | 183 // gfx::AnimationDelegate: |
| 187 void AnimationProgressed(const gfx::Animation* animation) override { | 184 void AnimationProgressed(const gfx::Animation* animation) override { |
| 188 gfx::Transform transform; | 185 gfx::Transform transform; |
| 189 if (IsHorizontalLayout()) { | 186 if (tray_->shelf()->IsHorizontalAlignment()) { |
| 190 transform.Translate(0, animation->CurrentValueBetween( | 187 transform.Translate(0, animation->CurrentValueBetween( |
| 191 static_cast<double>(height()) / 2., 0.)); | 188 static_cast<double>(height()) / 2., 0.)); |
| 192 } else { | 189 } else { |
| 193 transform.Translate( | 190 transform.Translate( |
| 194 animation->CurrentValueBetween(static_cast<double>(width() / 2.), 0.), | 191 animation->CurrentValueBetween(static_cast<double>(width() / 2.), 0.), |
| 195 0); | 192 0); |
| 196 } | 193 } |
| 197 transform.Scale(animation->GetCurrentValue(), animation->GetCurrentValue()); | 194 transform.Scale(animation->GetCurrentValue(), animation->GetCurrentValue()); |
| 198 layer()->SetTransform(transform); | 195 layer()->SetTransform(transform); |
| 199 PreferredSizeChanged(); | 196 PreferredSizeChanged(); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 | 263 |
| 267 private: | 264 private: |
| 268 views::Label* view_; | 265 views::Label* view_; |
| 269 | 266 |
| 270 DISALLOW_COPY_AND_ASSIGN(WebNotificationLabel); | 267 DISALLOW_COPY_AND_ASSIGN(WebNotificationLabel); |
| 271 }; | 268 }; |
| 272 | 269 |
| 273 WebNotificationTray::WebNotificationTray(WmShelf* shelf, | 270 WebNotificationTray::WebNotificationTray(WmShelf* shelf, |
| 274 WmWindow* status_area_window, | 271 WmWindow* status_area_window, |
| 275 SystemTray* system_tray) | 272 SystemTray* system_tray) |
| 276 : TrayBackgroundView(shelf, true), | 273 : TrayBackgroundView(shelf), |
| 277 status_area_window_(status_area_window), | 274 status_area_window_(status_area_window), |
| 278 system_tray_(system_tray), | 275 system_tray_(system_tray), |
| 279 show_message_center_on_unlock_(false), | 276 show_message_center_on_unlock_(false), |
| 280 should_update_tray_content_(false), | 277 should_update_tray_content_(false), |
| 281 should_block_shelf_auto_hide_(false) { | 278 should_block_shelf_auto_hide_(false) { |
| 282 DCHECK(shelf); | 279 DCHECK(shelf); |
| 283 DCHECK(status_area_window_); | 280 DCHECK(status_area_window_); |
| 284 DCHECK(system_tray_); | 281 DCHECK(system_tray_); |
| 285 | 282 |
| 286 SetInkDropMode(InkDropMode::ON); | 283 SetInkDropMode(InkDropMode::ON); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 if (!ShouldShowMessageCenter()) | 323 if (!ShouldShowMessageCenter()) |
| 327 return false; | 324 return false; |
| 328 | 325 |
| 329 should_block_shelf_auto_hide_ = true; | 326 should_block_shelf_auto_hide_ = true; |
| 330 message_center::MessageCenterBubble* message_center_bubble = | 327 message_center::MessageCenterBubble* message_center_bubble = |
| 331 new message_center::MessageCenterBubble(message_center(), | 328 new message_center::MessageCenterBubble(message_center(), |
| 332 message_center_tray_.get()); | 329 message_center_tray_.get()); |
| 333 | 330 |
| 334 // In the horizontal case, message center starts from the top of the shelf. | 331 // In the horizontal case, message center starts from the top of the shelf. |
| 335 // In the vertical case, it starts from the bottom of WebNotificationTray. | 332 // In the vertical case, it starts from the bottom of WebNotificationTray. |
| 336 const int max_height = IsHorizontalAlignment(shelf_alignment()) | 333 const int max_height = shelf()->IsHorizontalAlignment() |
| 337 ? shelf()->GetIdealBounds().y() | 334 ? shelf()->GetIdealBounds().y() |
| 338 : GetBoundsInScreen().bottom(); | 335 : GetBoundsInScreen().bottom(); |
| 339 message_center_bubble->SetMaxHeight(max_height); | 336 message_center_bubble->SetMaxHeight(max_height); |
| 340 | 337 |
| 341 if (show_settings) | 338 if (show_settings) |
| 342 message_center_bubble->SetSettingsVisible(); | 339 message_center_bubble->SetSettingsVisible(); |
| 343 | 340 |
| 344 // For vertical shelf alignments, anchor to the WebNotificationTray, but for | 341 // For vertical shelf alignments, anchor to the WebNotificationTray, but for |
| 345 // horizontal (i.e. bottom) shelves, anchor to the system tray. | 342 // horizontal (i.e. bottom) shelves, anchor to the system tray. |
| 346 TrayBackgroundView* anchor_tray = this; | 343 TrayBackgroundView* anchor_tray = this; |
| 347 if (IsHorizontalAlignment(shelf_alignment())) { | 344 if (shelf()->IsHorizontalAlignment()) { |
| 348 anchor_tray = WmShelf::ForWindow(status_area_window_) | 345 anchor_tray = WmShelf::ForWindow(status_area_window_) |
| 349 ->GetStatusAreaWidget() | 346 ->GetStatusAreaWidget() |
| 350 ->system_tray(); | 347 ->system_tray(); |
| 351 } | 348 } |
| 352 | 349 |
| 353 message_center_bubble_.reset(new WebNotificationBubbleWrapper( | 350 message_center_bubble_.reset(new WebNotificationBubbleWrapper( |
| 354 this, anchor_tray, message_center_bubble)); | 351 this, anchor_tray, message_center_bubble)); |
| 355 | 352 |
| 356 shelf()->UpdateAutoHideState(); | 353 shelf()->UpdateAutoHideState(); |
| 357 SetIsActive(true); | 354 SetIsActive(true); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 if (!IsMessageCenterBubbleVisible()) | 410 if (!IsMessageCenterBubbleVisible()) |
| 414 message_center_tray_->ShowMessageCenterBubble(); | 411 message_center_tray_->ShowMessageCenterBubble(); |
| 415 } | 412 } |
| 416 | 413 |
| 417 void WebNotificationTray::UpdateAfterLoginStatusChange( | 414 void WebNotificationTray::UpdateAfterLoginStatusChange( |
| 418 LoginStatus login_status) { | 415 LoginStatus login_status) { |
| 419 message_center()->SetLockedState(login_status == LoginStatus::LOCKED); | 416 message_center()->SetLockedState(login_status == LoginStatus::LOCKED); |
| 420 OnMessageCenterTrayChanged(); | 417 OnMessageCenterTrayChanged(); |
| 421 } | 418 } |
| 422 | 419 |
| 423 void WebNotificationTray::SetShelfAlignment(ShelfAlignment alignment) { | 420 void WebNotificationTray::UpdateAfterShelfAlignmentChange() { |
| 424 if (alignment == shelf_alignment()) | 421 TrayBackgroundView::UpdateAfterShelfAlignmentChange(); |
| 425 return; | |
| 426 TrayBackgroundView::SetShelfAlignment(alignment); | |
| 427 // Destroy any existing bubble so that it will be rebuilt correctly. | 422 // Destroy any existing bubble so that it will be rebuilt correctly. |
| 428 message_center_tray_->HideMessageCenterBubble(); | 423 message_center_tray_->HideMessageCenterBubble(); |
| 429 message_center_tray_->HidePopupBubble(); | 424 message_center_tray_->HidePopupBubble(); |
| 430 } | 425 } |
| 431 | 426 |
| 432 void WebNotificationTray::AnchorUpdated() { | 427 void WebNotificationTray::AnchorUpdated() { |
| 433 if (message_center_bubble()) { | 428 if (message_center_bubble()) { |
| 434 message_center_bubble()->bubble_view()->UpdateBubble(); | 429 message_center_bubble()->bubble_view()->UpdateBubble(); |
| 435 UpdateBubbleViewArrow(message_center_bubble()->bubble_view()); | 430 UpdateBubbleViewArrow(message_center_bubble()->bubble_view()); |
| 436 } | 431 } |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 621 | 616 |
| 622 message_center::MessageCenterBubble* | 617 message_center::MessageCenterBubble* |
| 623 WebNotificationTray::GetMessageCenterBubbleForTest() { | 618 WebNotificationTray::GetMessageCenterBubbleForTest() { |
| 624 if (!message_center_bubble()) | 619 if (!message_center_bubble()) |
| 625 return nullptr; | 620 return nullptr; |
| 626 return static_cast<message_center::MessageCenterBubble*>( | 621 return static_cast<message_center::MessageCenterBubble*>( |
| 627 message_center_bubble()->bubble()); | 622 message_center_bubble()->bubble()); |
| 628 } | 623 } |
| 629 | 624 |
| 630 } // namespace ash | 625 } // namespace ash |
| OLD | NEW |