Chromium Code Reviews| 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" | |
|
James Cook
2017/04/17 16:54:35
Is this needed?
mohsen
2017/04/19 22:59:07
Yes, this file works with TrayBackgroundView::tray
| |
| 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_shell.h" | 24 #include "ash/wm_shell.h" |
| 24 #include "ash/wm_window.h" | 25 #include "ash/wm_window.h" |
| 25 #include "base/auto_reset.h" | 26 #include "base/auto_reset.h" |
| 26 #include "base/i18n/number_formatting.h" | 27 #include "base/i18n/number_formatting.h" |
| 27 #include "base/i18n/rtl.h" | 28 #include "base/i18n/rtl.h" |
| 28 #include "base/strings/utf_string_conversions.h" | 29 #include "base/strings/utf_string_conversions.h" |
| 29 #include "base/threading/thread_task_runner_handle.h" | 30 #include "base/threading/thread_task_runner_handle.h" |
| 30 #include "ui/base/l10n/l10n_util.h" | 31 #include "ui/base/l10n/l10n_util.h" |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 158 protected: | 159 protected: |
| 159 // Overridden from views::View: | 160 // Overridden from views::View: |
| 160 gfx::Size GetPreferredSize() const override { | 161 gfx::Size GetPreferredSize() const override { |
| 161 if (!animation_.get() || !animation_->is_animating()) | 162 if (!animation_.get() || !animation_->is_animating()) |
| 162 return kTrayItemOuterSize; | 163 return kTrayItemOuterSize; |
| 163 | 164 |
| 164 // Animate the width (or height) when this item shows (or hides) so that | 165 // Animate the width (or height) when this item shows (or hides) so that |
| 165 // the icons on the left are shifted with the animation. | 166 // the icons on the left are shifted with the animation. |
| 166 // Note that TrayItemView does the same thing. | 167 // Note that TrayItemView does the same thing. |
| 167 gfx::Size size = kTrayItemOuterSize; | 168 gfx::Size size = kTrayItemOuterSize; |
| 168 if (IsHorizontalLayout()) { | 169 if (tray_->shelf()->IsHorizontalAlignment()) { |
| 169 size.set_width(std::max( | 170 size.set_width(std::max( |
| 170 1, gfx::ToRoundedInt(size.width() * animation_->GetCurrentValue()))); | 171 1, gfx::ToRoundedInt(size.width() * animation_->GetCurrentValue()))); |
| 171 } else { | 172 } else { |
| 172 size.set_height(std::max( | 173 size.set_height(std::max( |
| 173 1, gfx::ToRoundedInt(size.height() * animation_->GetCurrentValue()))); | 174 1, gfx::ToRoundedInt(size.height() * animation_->GetCurrentValue()))); |
| 174 } | 175 } |
| 175 return size; | 176 return size; |
| 176 } | 177 } |
| 177 | 178 |
| 178 int GetHeightForWidth(int width) const override { | 179 int GetHeightForWidth(int width) const override { |
| 179 return GetPreferredSize().height(); | 180 return GetPreferredSize().height(); |
| 180 } | 181 } |
| 181 | 182 |
| 182 bool IsHorizontalLayout() const { | |
| 183 return IsHorizontalAlignment(tray_->shelf_alignment()); | |
| 184 } | |
| 185 | |
| 186 private: | 183 private: |
| 187 // gfx::AnimationDelegate: | 184 // gfx::AnimationDelegate: |
| 188 void AnimationProgressed(const gfx::Animation* animation) override { | 185 void AnimationProgressed(const gfx::Animation* animation) override { |
| 189 gfx::Transform transform; | 186 gfx::Transform transform; |
| 190 if (IsHorizontalLayout()) { | 187 if (tray_->shelf()->IsHorizontalAlignment()) { |
| 191 transform.Translate(0, animation->CurrentValueBetween( | 188 transform.Translate(0, animation->CurrentValueBetween( |
| 192 static_cast<double>(height()) / 2., 0.)); | 189 static_cast<double>(height()) / 2., 0.)); |
| 193 } else { | 190 } else { |
| 194 transform.Translate( | 191 transform.Translate( |
| 195 animation->CurrentValueBetween(static_cast<double>(width() / 2.), 0.), | 192 animation->CurrentValueBetween(static_cast<double>(width() / 2.), 0.), |
| 196 0); | 193 0); |
| 197 } | 194 } |
| 198 transform.Scale(animation->GetCurrentValue(), animation->GetCurrentValue()); | 195 transform.Scale(animation->GetCurrentValue(), animation->GetCurrentValue()); |
| 199 layer()->SetTransform(transform); | 196 layer()->SetTransform(transform); |
| 200 PreferredSizeChanged(); | 197 PreferredSizeChanged(); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 267 | 264 |
| 268 private: | 265 private: |
| 269 views::Label* view_; | 266 views::Label* view_; |
| 270 | 267 |
| 271 DISALLOW_COPY_AND_ASSIGN(WebNotificationLabel); | 268 DISALLOW_COPY_AND_ASSIGN(WebNotificationLabel); |
| 272 }; | 269 }; |
| 273 | 270 |
| 274 WebNotificationTray::WebNotificationTray(WmShelf* shelf, | 271 WebNotificationTray::WebNotificationTray(WmShelf* shelf, |
| 275 WmWindow* status_area_window, | 272 WmWindow* status_area_window, |
| 276 SystemTray* system_tray) | 273 SystemTray* system_tray) |
| 277 : TrayBackgroundView(shelf, true), | 274 : TrayBackgroundView(shelf), |
| 278 status_area_window_(status_area_window), | 275 status_area_window_(status_area_window), |
| 279 system_tray_(system_tray), | 276 system_tray_(system_tray), |
| 280 show_message_center_on_unlock_(false), | 277 show_message_center_on_unlock_(false), |
| 281 should_update_tray_content_(false), | 278 should_update_tray_content_(false), |
| 282 should_block_shelf_auto_hide_(false) { | 279 should_block_shelf_auto_hide_(false) { |
| 283 DCHECK(shelf); | 280 DCHECK(shelf); |
| 284 DCHECK(status_area_window_); | 281 DCHECK(status_area_window_); |
| 285 DCHECK(system_tray_); | 282 DCHECK(system_tray_); |
| 286 | 283 |
| 287 SetInkDropMode(InkDropMode::ON); | 284 SetInkDropMode(InkDropMode::ON); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 327 if (!ShouldShowMessageCenter()) | 324 if (!ShouldShowMessageCenter()) |
| 328 return false; | 325 return false; |
| 329 | 326 |
| 330 should_block_shelf_auto_hide_ = true; | 327 should_block_shelf_auto_hide_ = true; |
| 331 message_center::MessageCenterBubble* message_center_bubble = | 328 message_center::MessageCenterBubble* message_center_bubble = |
| 332 new message_center::MessageCenterBubble(message_center(), | 329 new message_center::MessageCenterBubble(message_center(), |
| 333 message_center_tray_.get()); | 330 message_center_tray_.get()); |
| 334 | 331 |
| 335 // In the horizontal case, message center starts from the top of the shelf. | 332 // In the horizontal case, message center starts from the top of the shelf. |
| 336 // In the vertical case, it starts from the bottom of WebNotificationTray. | 333 // In the vertical case, it starts from the bottom of WebNotificationTray. |
| 337 const int max_height = IsHorizontalAlignment(shelf_alignment()) | 334 const int max_height = shelf()->IsHorizontalAlignment() |
| 338 ? shelf()->GetIdealBounds().y() | 335 ? shelf()->GetIdealBounds().y() |
| 339 : GetBoundsInScreen().bottom(); | 336 : GetBoundsInScreen().bottom(); |
| 340 message_center_bubble->SetMaxHeight(max_height); | 337 message_center_bubble->SetMaxHeight(max_height); |
| 341 | 338 |
| 342 if (show_settings) | 339 if (show_settings) |
| 343 message_center_bubble->SetSettingsVisible(); | 340 message_center_bubble->SetSettingsVisible(); |
| 344 | 341 |
| 345 // For vertical shelf alignments, anchor to the WebNotificationTray, but for | 342 // For vertical shelf alignments, anchor to the WebNotificationTray, but for |
| 346 // horizontal (i.e. bottom) shelves, anchor to the system tray. | 343 // horizontal (i.e. bottom) shelves, anchor to the system tray. |
| 347 TrayBackgroundView* anchor_tray = this; | 344 TrayBackgroundView* anchor_tray = this; |
| 348 if (IsHorizontalAlignment(shelf_alignment())) { | 345 if (shelf()->IsHorizontalAlignment()) { |
| 349 anchor_tray = WmShelf::ForWindow(status_area_window_) | 346 anchor_tray = WmShelf::ForWindow(status_area_window_) |
| 350 ->GetStatusAreaWidget() | 347 ->GetStatusAreaWidget() |
| 351 ->system_tray(); | 348 ->system_tray(); |
| 352 } | 349 } |
| 353 | 350 |
| 354 message_center_bubble_.reset(new WebNotificationBubbleWrapper( | 351 message_center_bubble_.reset(new WebNotificationBubbleWrapper( |
| 355 this, anchor_tray, message_center_bubble)); | 352 this, anchor_tray, message_center_bubble)); |
| 356 | 353 |
| 357 shelf()->UpdateAutoHideState(); | 354 shelf()->UpdateAutoHideState(); |
| 358 SetIsActive(true); | 355 SetIsActive(true); |
| (...skipping 54 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 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 627 | 622 |
| 628 message_center::MessageCenterBubble* | 623 message_center::MessageCenterBubble* |
| 629 WebNotificationTray::GetMessageCenterBubbleForTest() { | 624 WebNotificationTray::GetMessageCenterBubbleForTest() { |
| 630 if (!message_center_bubble()) | 625 if (!message_center_bubble()) |
| 631 return nullptr; | 626 return nullptr; |
| 632 return static_cast<message_center::MessageCenterBubble*>( | 627 return static_cast<message_center::MessageCenterBubble*>( |
| 633 message_center_bubble()->bubble()); | 628 message_center_bubble()->bubble()); |
| 634 } | 629 } |
| 635 | 630 |
| 636 } // namespace ash | 631 } // namespace ash |
| OLD | NEW |