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/common/system/web_notification/web_notification_tray.h" | 5 #include "ash/common/system/web_notification/web_notification_tray.h" |
| 6 | 6 |
| 7 #include "ash/common/ash_switches.h" | 7 #include "ash/common/ash_switches.h" |
| 8 #include "ash/common/material_design/material_design_controller.h" | 8 #include "ash/common/material_design/material_design_controller.h" |
| 9 #include "ash/common/session/session_state_delegate.h" | 9 #include "ash/common/session/session_state_delegate.h" |
| 10 #include "ash/common/shelf/shelf_constants.h" | 10 #include "ash/common/shelf/shelf_constants.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 56 } | 56 } |
| 57 | 57 |
| 58 } // namespace message_center | 58 } // namespace message_center |
| 59 | 59 |
| 60 #endif // defined(OS_CHROMEOS) | 60 #endif // defined(OS_CHROMEOS) |
| 61 | 61 |
| 62 namespace ash { | 62 namespace ash { |
| 63 namespace { | 63 namespace { |
| 64 | 64 |
| 65 // Menu commands | 65 // Menu commands |
| 66 const int kToggleQuietMode = 0; | 66 constexpr int kToggleQuietMode = 0; |
| 67 const int kEnableQuietModeDay = 2; | 67 constexpr int kEnableQuietModeDay = 2; |
| 68 | |
| 69 constexpr int kMaximumSmallIconCount = 3; | |
| 70 | |
| 71 constexpr gfx::Size kTrayItemInnerIconSize = gfx::Size(16, 16); | |
| 72 constexpr gfx::Size kTrayItemInnerBellIconSize = gfx::Size(18, 18); | |
|
oshima
2016/08/04 18:15:21
I think you can do
kTrayItemInnerIconSize(16, 16)
yoshiki
2016/08/05 13:30:47
Done.
| |
| 73 | |
| 74 constexpr int kTrayItemWidth = 26; | |
| 75 constexpr int kTrayItemHeight = 26; | |
|
oshima
2016/08/04 18:15:21
can this also be gfx::Size ?
yoshiki
2016/08/05 13:30:47
Done.
| |
| 76 constexpr int kTrayItemHorizontalInset = 6; | |
| 77 constexpr int kTrayItemVerticalInset = 6; | |
| 78 | |
| 79 constexpr int kTrayItemAnimationDurationMS = 200; | |
| 80 | |
| 81 static int round(double d) { | |
| 82 return std::floor(d + 0.5); | |
| 83 } | |
|
oshima
2016/08/04 18:15:20
gfx::ToRoundedInt
yoshiki
2016/08/05 13:30:48
Done.
| |
| 68 } | 84 } |
| 69 | 85 |
| 70 namespace { | 86 namespace { |
| 71 | 87 |
| 72 const SkColor kWebNotificationColorNoUnread = | 88 const SkColor kWebNotificationColorNoUnread = |
| 73 SkColorSetARGB(128, 255, 255, 255); | 89 SkColorSetARGB(128, 255, 255, 255); |
| 74 const SkColor kWebNotificationColorWithUnread = SK_ColorWHITE; | 90 const SkColor kWebNotificationColorWithUnread = SK_ColorWHITE; |
| 75 const int kNoUnreadIconSize = 18; | 91 const int kNoUnreadIconSize = 18; |
| 76 } | 92 } |
| 77 | 93 |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 108 // Convenience accessors. | 124 // Convenience accessors. |
| 109 views::TrayBubbleView* bubble_view() const { return bubble_->bubble_view(); } | 125 views::TrayBubbleView* bubble_view() const { return bubble_->bubble_view(); } |
| 110 | 126 |
| 111 private: | 127 private: |
| 112 std::unique_ptr<message_center::MessageBubbleBase> bubble_; | 128 std::unique_ptr<message_center::MessageBubbleBase> bubble_; |
| 113 std::unique_ptr<TrayBubbleWrapper> bubble_wrapper_; | 129 std::unique_ptr<TrayBubbleWrapper> bubble_wrapper_; |
| 114 | 130 |
| 115 DISALLOW_COPY_AND_ASSIGN(WebNotificationBubbleWrapper); | 131 DISALLOW_COPY_AND_ASSIGN(WebNotificationBubbleWrapper); |
| 116 }; | 132 }; |
| 117 | 133 |
| 118 class WebNotificationButton : public views::CustomButton { | 134 class WebNotificationItem : public views::View, public gfx::AnimationDelegate { |
| 119 public: | 135 public: |
| 120 WebNotificationButton(views::ButtonListener* listener) | 136 WebNotificationItem(gfx::AnimationContainer* container, |
| 121 : views::CustomButton(listener), | 137 WebNotificationTray* tray) |
| 122 is_bubble_visible_(false), | 138 : tray_(tray) { |
| 123 unread_count_(0) { | 139 SetPaintToLayer(true); |
| 140 layer()->SetFillsBoundsOpaquely(false); | |
| 141 views::View::SetVisible(false); | |
| 142 set_owned_by_client(); | |
| 143 | |
| 124 SetLayoutManager(new views::FillLayout); | 144 SetLayoutManager(new views::FillLayout); |
| 125 | 145 |
| 126 gfx::ImageSkia image; | 146 animation_.reset(new gfx::SlideAnimation(this)); |
| 127 if (MaterialDesignController::IsShelfMaterial()) { | 147 animation_->SetContainer(container); |
| 128 image = CreateVectorIcon(gfx::VectorIconId::SHELF_NOTIFICATIONS, | 148 animation_->SetSlideDuration(kTrayItemAnimationDurationMS); |
| 129 kShelfIconColor); | 149 animation_->SetTweenType(gfx::Tween::LINEAR); |
| 130 } else { | 150 } |
| 131 image = | 151 |
| 132 CreateVectorIcon(gfx::VectorIconId::NOTIFICATIONS, kNoUnreadIconSize, | 152 void SetVisible(bool set_visible) override { |
| 133 kWebNotificationColorNoUnread); | 153 if (!GetWidget()) { |
| 154 views::View::SetVisible(set_visible); | |
| 155 return; | |
| 134 } | 156 } |
| 135 | 157 |
| 136 no_unread_icon_.SetImage(image); | 158 if (!set_visible) { |
| 137 no_unread_icon_.set_owned_by_client(); | 159 animation_->Hide(); |
| 138 | 160 AnimationProgressed(animation_.get()); |
| 139 unread_label_.set_owned_by_client(); | 161 } else { |
| 140 SetupLabelForTray(&unread_label_); | 162 animation_->Show(); |
| 141 | 163 AnimationProgressed(animation_.get()); |
| 142 AddChildView(&no_unread_icon_); | 164 views::View::SetVisible(true); |
| 165 } | |
| 143 } | 166 } |
| 144 | 167 |
| 145 void SetBubbleVisible(bool visible) { | 168 void HideAndDelete() { |
| 146 if (visible == is_bubble_visible_) | 169 SetVisible(false); |
| 147 return; | |
| 148 | 170 |
| 149 is_bubble_visible_ = visible; | 171 if (!visible() && !animation_->is_animating()) { |
| 150 UpdateIconVisibility(); | 172 if (parent()) |
| 151 } | 173 parent()->RemoveChildView(this); |
| 152 | 174 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this); |
| 153 void SetUnreadCount(int unread_count) { | 175 } else { |
| 154 // base::FormatNumber doesn't convert to arabic numeric characters. | 176 delete_after_animation_ = true; |
| 155 // TODO(mukai): use ICU to support conversion for such locales. | 177 } |
| 156 unread_count_ = unread_count; | |
| 157 UpdateIconVisibility(); | |
| 158 } | 178 } |
| 159 | 179 |
| 160 protected: | 180 protected: |
| 161 // Overridden from views::ImageButton: | 181 // Overridden from views::ImageButton: |
| 162 gfx::Size GetPreferredSize() const override { | 182 gfx::Size GetPreferredSize() const override { |
| 163 const int size = GetTrayConstant(TRAY_ITEM_HEIGHT_LEGACY); | 183 gfx::Size size = gfx::Size(kTrayItemWidth, kTrayItemHeight); |
| 164 return gfx::Size(size, size); | 184 if (!animation_.get() || !animation_->is_animating()) |
| 185 return size; | |
| 186 if (IsHorizontalAlignment(tray_->shelf_alignment())) { | |
|
oshima
2016/08/04 18:15:21
since it's used in many places now, it's probably
yoshiki
2016/08/05 13:30:48
Done.
| |
| 187 size.set_width( | |
| 188 std::max(1, round(size.width() * animation_->GetCurrentValue()))); | |
| 189 } else { | |
| 190 size.set_height( | |
| 191 std::max(1, round(size.height() * animation_->GetCurrentValue()))); | |
| 192 } | |
| 193 return size; | |
| 165 } | 194 } |
|
oshima
2016/08/04 18:15:21
I guess we can't just clip it because there are mu
yoshiki
2016/08/05 13:30:48
Done.
| |
| 166 | 195 |
| 167 int GetHeightForWidth(int width) const override { | 196 int GetHeightForWidth(int width) const override { |
| 168 return GetPreferredSize().height(); | 197 return GetPreferredSize().height(); |
| 169 } | 198 } |
| 170 | 199 |
| 171 private: | 200 private: |
| 172 void UpdateIconVisibility() { | 201 // Overridden from gfx::AnimationDelegate. |
|
oshima
2016/08/04 18:15:21
// gfx::AnimationDelegate:
yoshiki
2016/08/05 13:30:47
Done.
| |
| 173 if (unread_count_ == 0) { | 202 void AnimationProgressed(const gfx::Animation* animation) override { |
| 174 if (!Contains(&no_unread_icon_)) { | 203 gfx::Transform transform; |
| 175 RemoveAllChildViews(false /* delete_children */); | 204 if (IsHorizontalAlignment(tray_->shelf_alignment())) { |
| 176 AddChildView(&no_unread_icon_); | 205 transform.Translate(0, animation->CurrentValueBetween( |
| 177 } | 206 static_cast<double>(height()) / 2, 0.)); |
| 178 } else { | 207 } else { |
| 179 if (!Contains(&unread_label_)) { | 208 transform.Translate( |
| 180 RemoveAllChildViews(false /* delete_children */); | 209 animation->CurrentValueBetween(static_cast<double>(width() / 2), 0.), |
| 181 AddChildView(&unread_label_); | 210 0); |
| 182 } | 211 } |
| 212 transform.Scale(animation->GetCurrentValue(), animation->GetCurrentValue()); | |
| 213 layer()->SetTransform(transform); | |
| 214 PreferredSizeChanged(); | |
| 215 } | |
| 216 void AnimationEnded(const gfx::Animation* animation) override { | |
| 217 if (animation->GetCurrentValue() < 0.1) | |
| 218 views::View::SetVisible(false); | |
| 183 | 219 |
| 184 // TODO(mukai): move NINE_PLUS message to ui_strings, it doesn't need to | 220 if (delete_after_animation_) { |
| 185 // be in ash_strings. | 221 if (parent()) |
| 186 unread_label_.SetText( | 222 parent()->RemoveChildView(this); |
| 187 (unread_count_ > 9) ? l10n_util::GetStringUTF16( | 223 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this); |
| 188 IDS_ASH_NOTIFICATION_UNREAD_COUNT_NINE_PLUS) | |
| 189 : base::FormatNumber(unread_count_)); | |
| 190 unread_label_.SetEnabledColor((unread_count_ > 0) | |
| 191 ? kWebNotificationColorWithUnread | |
| 192 : kWebNotificationColorNoUnread); | |
| 193 } | 224 } |
| 225 } | |
| 226 void AnimationCanceled(const gfx::Animation* animation) override { | |
| 227 AnimationEnded(animation); | |
| 228 } | |
| 229 | |
| 230 std::unique_ptr<gfx::SlideAnimation> animation_; | |
| 231 bool delete_after_animation_ = false; | |
| 232 WebNotificationTray* tray_; | |
| 233 | |
| 234 DISALLOW_COPY_AND_ASSIGN(WebNotificationItem); | |
| 235 }; | |
| 236 | |
| 237 class WebNotificationImage : public WebNotificationItem { | |
| 238 public: | |
| 239 WebNotificationImage(const gfx::ImageSkia& image, | |
| 240 gfx::Size size, | |
| 241 gfx::AnimationContainer* container, | |
| 242 WebNotificationTray* tray) | |
| 243 : WebNotificationItem(container, tray) { | |
| 244 view_ = new views::ImageView(); | |
| 245 view_->SetImage(image); | |
| 246 view_->SetImageSize(size); | |
| 247 AddChildView(view_); | |
| 248 } | |
| 249 | |
| 250 private: | |
| 251 views::ImageView* view_; | |
| 252 | |
| 253 DISALLOW_COPY_AND_ASSIGN(WebNotificationImage); | |
| 254 }; | |
| 255 | |
| 256 class WebNotificationLabel : public WebNotificationItem { | |
| 257 public: | |
| 258 WebNotificationLabel(gfx::AnimationContainer* container, | |
| 259 WebNotificationTray* tray) | |
| 260 : WebNotificationItem(container, tray) { | |
| 261 view_ = new views::Label(); | |
| 262 SetupLabelForTray(view_); | |
| 263 } | |
| 264 | |
| 265 void SetUnreadCount(int unread_count) { | |
| 266 // TODO(mukai): move NINE_PLUS message to ui_strings, it doesn't need to | |
| 267 // be in ash_strings. | |
| 268 view_->SetText((unread_count > 9) | |
| 269 ? l10n_util::GetStringUTF16( | |
| 270 IDS_ASH_NOTIFICATION_UNREAD_COUNT_NINE_PLUS) | |
| 271 : base::FormatNumber(unread_count)); | |
| 272 view_->SetEnabledColor(kWebNotificationColorWithUnread); | |
| 273 AddChildView(view_); | |
| 194 SchedulePaint(); | 274 SchedulePaint(); |
| 195 } | 275 } |
| 196 | 276 |
| 197 bool is_bubble_visible_; | 277 private: |
| 198 int unread_count_; | 278 views::Label* view_; |
| 199 | 279 |
| 200 views::ImageView no_unread_icon_; | 280 DISALLOW_COPY_AND_ASSIGN(WebNotificationLabel); |
| 201 views::Label unread_label_; | |
| 202 | |
| 203 DISALLOW_COPY_AND_ASSIGN(WebNotificationButton); | |
| 204 }; | 281 }; |
| 205 | 282 |
| 206 WebNotificationTray::WebNotificationTray(WmShelf* shelf, | 283 WebNotificationTray::WebNotificationTray(WmShelf* shelf, |
| 207 WmWindow* status_area_window, | 284 WmWindow* status_area_window, |
| 208 SystemTray* system_tray) | 285 SystemTray* system_tray) |
| 209 : TrayBackgroundView(shelf), | 286 : TrayBackgroundView(shelf), |
| 210 status_area_window_(status_area_window), | 287 status_area_window_(status_area_window), |
| 211 system_tray_(system_tray), | 288 system_tray_(system_tray), |
| 212 button_(nullptr), | |
| 213 show_message_center_on_unlock_(false), | 289 show_message_center_on_unlock_(false), |
| 214 should_update_tray_content_(false), | 290 should_update_tray_content_(false), |
| 215 should_block_shelf_auto_hide_(false) { | 291 should_block_shelf_auto_hide_(false) { |
| 216 DCHECK(shelf); | 292 DCHECK(shelf); |
| 217 DCHECK(status_area_window_); | 293 DCHECK(status_area_window_); |
| 218 DCHECK(system_tray_); | 294 DCHECK(system_tray_); |
| 219 button_ = new WebNotificationButton(this); | 295 |
| 220 button_->set_triggerable_event_flags(ui::EF_LEFT_MOUSE_BUTTON | | 296 gfx::ImageSkia bell_image; |
| 221 ui::EF_RIGHT_MOUSE_BUTTON); | 297 if (MaterialDesignController::IsShelfMaterial()) { |
| 222 tray_container()->AddChildView(button_); | 298 bell_image = CreateVectorIcon(gfx::VectorIconId::SHELF_NOTIFICATIONS, |
| 223 button_->SetFocusBehavior(FocusBehavior::NEVER); | 299 kShelfIconColor); |
| 300 } else { | |
| 301 bell_image = | |
| 302 CreateVectorIcon(gfx::VectorIconId::NOTIFICATIONS, kNoUnreadIconSize, | |
| 303 kWebNotificationColorNoUnread); | |
| 304 } | |
| 305 bell_icon_.reset(new WebNotificationImage(bell_image, | |
| 306 kTrayItemInnerBellIconSize, | |
| 307 animation_container_.get(), this)); | |
| 308 tray_container()->AddChildView(bell_icon_.get()); | |
| 309 | |
| 310 counter_.reset(new WebNotificationLabel(animation_container_.get(), this)); | |
| 311 tray_container()->AddChildView(counter_.get()); | |
| 312 | |
| 224 SetContentsBackground(); | 313 SetContentsBackground(); |
| 225 tray_container()->SetBorder(views::Border::NullBorder()); | 314 tray_container()->SetBorder(views::Border::NullBorder()); |
| 226 message_center_tray_.reset(new message_center::MessageCenterTray( | 315 message_center_tray_.reset(new message_center::MessageCenterTray( |
| 227 this, message_center::MessageCenter::Get())); | 316 this, message_center::MessageCenter::Get())); |
| 228 popup_alignment_delegate_.reset(new AshPopupAlignmentDelegate(shelf)); | 317 popup_alignment_delegate_.reset(new AshPopupAlignmentDelegate(shelf)); |
| 229 popup_collection_.reset(new message_center::MessagePopupCollection( | 318 popup_collection_.reset(new message_center::MessagePopupCollection( |
| 230 message_center(), message_center_tray_.get(), | 319 message_center(), message_center_tray_.get(), |
| 231 popup_alignment_delegate_.get())); | 320 popup_alignment_delegate_.get())); |
| 232 const display::Display& display = | 321 const display::Display& display = |
| 233 status_area_window_->GetDisplayNearestWindow(); | 322 status_area_window_->GetDisplayNearestWindow(); |
| 234 popup_alignment_delegate_->StartObserving(display::Screen::GetScreen(), | 323 popup_alignment_delegate_->StartObserving(display::Screen::GetScreen(), |
| 235 display); | 324 display); |
| 236 OnMessageCenterTrayChanged(); | 325 OnMessageCenterTrayChanged(); |
| 326 | |
| 327 tray_container()->set_insets( | |
| 328 gfx::Insets(kTrayItemHorizontalInset, kTrayItemVerticalInset)); | |
| 237 } | 329 } |
| 238 | 330 |
| 239 WebNotificationTray::~WebNotificationTray() { | 331 WebNotificationTray::~WebNotificationTray() { |
| 240 // Release any child views that might have back pointers before ~View(). | 332 // Release any child views that might have back pointers before ~View(). |
| 241 message_center_bubble_.reset(); | 333 message_center_bubble_.reset(); |
| 242 popup_alignment_delegate_.reset(); | 334 popup_alignment_delegate_.reset(); |
| 243 popup_collection_.reset(); | 335 popup_collection_.reset(); |
| 244 } | 336 } |
| 245 | 337 |
| 246 // Public methods. | 338 // Public methods. |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 266 } | 358 } |
| 267 message_center_bubble->SetMaxHeight( | 359 message_center_bubble->SetMaxHeight( |
| 268 std::max(0, max_height - GetTrayConstant(TRAY_SPACING))); | 360 std::max(0, max_height - GetTrayConstant(TRAY_SPACING))); |
| 269 if (show_settings) | 361 if (show_settings) |
| 270 message_center_bubble->SetSettingsVisible(); | 362 message_center_bubble->SetSettingsVisible(); |
| 271 message_center_bubble_.reset( | 363 message_center_bubble_.reset( |
| 272 new WebNotificationBubbleWrapper(this, message_center_bubble)); | 364 new WebNotificationBubbleWrapper(this, message_center_bubble)); |
| 273 | 365 |
| 274 system_tray_->SetHideNotifications(true); | 366 system_tray_->SetHideNotifications(true); |
| 275 shelf()->UpdateAutoHideState(); | 367 shelf()->UpdateAutoHideState(); |
| 276 button_->SetBubbleVisible(true); | |
| 277 SetDrawBackgroundAsActive(true); | 368 SetDrawBackgroundAsActive(true); |
| 278 return true; | 369 return true; |
| 279 } | 370 } |
| 280 | 371 |
| 281 bool WebNotificationTray::ShowMessageCenter() { | 372 bool WebNotificationTray::ShowMessageCenter() { |
| 282 return ShowMessageCenterInternal(false /* show_settings */); | 373 return ShowMessageCenterInternal(false /* show_settings */); |
| 283 } | 374 } |
| 284 | 375 |
| 285 void WebNotificationTray::HideMessageCenter() { | 376 void WebNotificationTray::HideMessageCenter() { |
| 286 if (!message_center_bubble()) | 377 if (!message_center_bubble()) |
| 287 return; | 378 return; |
| 288 SetDrawBackgroundAsActive(false); | 379 SetDrawBackgroundAsActive(false); |
| 289 message_center_bubble_.reset(); | 380 message_center_bubble_.reset(); |
| 290 should_block_shelf_auto_hide_ = false; | 381 should_block_shelf_auto_hide_ = false; |
| 291 show_message_center_on_unlock_ = false; | 382 show_message_center_on_unlock_ = false; |
| 292 system_tray_->SetHideNotifications(false); | 383 system_tray_->SetHideNotifications(false); |
| 293 shelf()->UpdateAutoHideState(); | 384 shelf()->UpdateAutoHideState(); |
| 294 button_->SetBubbleVisible(false); | |
| 295 } | 385 } |
| 296 | 386 |
| 297 void WebNotificationTray::SetTrayBubbleHeight(int height) { | 387 void WebNotificationTray::SetTrayBubbleHeight(int height) { |
| 298 popup_alignment_delegate_->SetTrayBubbleHeight(height); | 388 popup_alignment_delegate_->SetTrayBubbleHeight(height); |
| 299 } | 389 } |
| 300 | 390 |
| 301 int WebNotificationTray::tray_bubble_height_for_test() const { | 391 int WebNotificationTray::tray_bubble_height_for_test() const { |
| 302 return popup_alignment_delegate_->tray_bubble_height_for_test(); | 392 return popup_alignment_delegate_->tray_bubble_height_for_test(); |
| 303 } | 393 } |
| 304 | 394 |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 453 bool in_quiet_mode = message_center()->IsQuietMode(); | 543 bool in_quiet_mode = message_center()->IsQuietMode(); |
| 454 message_center()->SetQuietMode(!in_quiet_mode); | 544 message_center()->SetQuietMode(!in_quiet_mode); |
| 455 return; | 545 return; |
| 456 } | 546 } |
| 457 base::TimeDelta expires_in = command_id == kEnableQuietModeDay | 547 base::TimeDelta expires_in = command_id == kEnableQuietModeDay |
| 458 ? base::TimeDelta::FromDays(1) | 548 ? base::TimeDelta::FromDays(1) |
| 459 : base::TimeDelta::FromHours(1); | 549 : base::TimeDelta::FromHours(1); |
| 460 message_center()->EnterQuietModeWithExpire(expires_in); | 550 message_center()->EnterQuietModeWithExpire(expires_in); |
| 461 } | 551 } |
| 462 | 552 |
| 463 void WebNotificationTray::ButtonPressed(views::Button* sender, | |
| 464 const ui::Event& event) { | |
| 465 DCHECK_EQ(button_, sender); | |
| 466 PerformAction(event); | |
| 467 } | |
| 468 | |
| 469 void WebNotificationTray::OnMessageCenterTrayChanged() { | 553 void WebNotificationTray::OnMessageCenterTrayChanged() { |
| 470 // Do not update the tray contents directly. Multiple change events can happen | 554 // Do not update the tray contents directly. Multiple change events can happen |
| 471 // consecutively, and calling Update in the middle of those events will show | 555 // consecutively, and calling Update in the middle of those events will show |
| 472 // intermediate unread counts for a moment. | 556 // intermediate unread counts for a moment. |
| 473 should_update_tray_content_ = true; | 557 should_update_tray_content_ = true; |
| 474 base::ThreadTaskRunnerHandle::Get()->PostTask( | 558 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 475 FROM_HERE, | 559 FROM_HERE, |
| 476 base::Bind(&WebNotificationTray::UpdateTrayContent, AsWeakPtr())); | 560 base::Bind(&WebNotificationTray::UpdateTrayContent, AsWeakPtr())); |
| 477 } | 561 } |
| 478 | 562 |
| 479 void WebNotificationTray::UpdateTrayContent() { | 563 void WebNotificationTray::UpdateTrayContent() { |
| 480 if (!should_update_tray_content_) | 564 if (!should_update_tray_content_) |
| 481 return; | 565 return; |
| 482 should_update_tray_content_ = false; | 566 should_update_tray_content_ = false; |
| 483 | 567 |
| 568 std::set<std::string> notification_ids; | |
|
oshima
2016/08/04 18:15:21
unorderd_set or you can just use vector (which is
yoshiki
2016/08/05 13:30:48
Let me use unordered_map, since I want to show tha
| |
| 569 for (auto i : visible_small_icons_) { | |
| 570 notification_ids.insert(i.first); | |
| 571 } | |
| 572 | |
| 573 // Add small icons (up to kMaximumSmallIconCount = 3). | |
| 484 message_center::MessageCenter* message_center = | 574 message_center::MessageCenter* message_center = |
| 485 message_center_tray_->message_center(); | 575 message_center_tray_->message_center(); |
| 486 button_->SetUnreadCount(message_center->UnreadNotificationCount()); | 576 size_t visible_small_icon_count = 0; |
| 487 if (IsMessageCenterBubbleVisible()) | 577 for (const auto* notification : message_center->GetVisibleNotifications()) { |
| 488 button_->SetState(views::CustomButton::STATE_PRESSED); | 578 gfx::Image image = notification->small_image(); |
| 489 else | 579 if (image.IsEmpty()) |
| 490 button_->SetState(views::CustomButton::STATE_NORMAL); | 580 continue; |
| 581 | |
| 582 if (visible_small_icon_count >= kMaximumSmallIconCount) | |
| 583 break; | |
| 584 visible_small_icon_count++; | |
| 585 | |
| 586 notification_ids.erase(notification->id()); | |
| 587 if (visible_small_icons_.count(notification->id()) != 0) | |
| 588 continue; | |
| 589 | |
| 590 auto* item = | |
| 591 new WebNotificationImage(image.AsImageSkia(), kTrayItemInnerIconSize, | |
| 592 animation_container_.get(), this); | |
| 593 visible_small_icons_.insert(std::make_pair(notification->id(), item)); | |
| 594 | |
| 595 tray_container()->AddChildViewAt(item, 0); | |
| 596 item->SetVisible(true); | |
| 597 } | |
| 598 | |
| 599 // Remove unnecessary icons. | |
| 600 for (const std::string& id : notification_ids) { | |
| 601 WebNotificationImage* item = visible_small_icons_[id]; | |
| 602 visible_small_icons_.erase(id); | |
| 603 item->HideAndDelete(); | |
| 604 } | |
| 605 | |
| 606 // Show or hide the bell icon. | |
| 607 size_t visible_notification_count = message_center->NotificationCount(); | |
| 608 bell_icon_->SetVisible(visible_notification_count == 0); | |
| 609 | |
| 610 // Show or hide the counter. | |
| 611 size_t hidden_icon_count = | |
| 612 visible_notification_count - visible_small_icon_count; | |
| 613 if (hidden_icon_count != 0) { | |
| 614 counter_->SetVisible(true); | |
| 615 counter_->SetUnreadCount(hidden_icon_count); | |
| 616 } else { | |
| 617 counter_->SetVisible(false); | |
| 618 } | |
| 491 | 619 |
| 492 SetVisible(IsLoggedIn()); | 620 SetVisible(IsLoggedIn()); |
| 621 PreferredSizeChanged(); | |
| 493 Layout(); | 622 Layout(); |
| 494 SchedulePaint(); | 623 SchedulePaint(); |
| 495 if (IsLoggedIn()) | 624 if (IsLoggedIn()) |
| 496 system_tray_->SetNextFocusableView(this); | 625 system_tray_->SetNextFocusableView(this); |
| 497 } | 626 } |
| 498 | 627 |
| 499 void WebNotificationTray::ClickedOutsideBubble() { | 628 void WebNotificationTray::ClickedOutsideBubble() { |
| 500 // Only hide the message center | 629 // Only hide the message center |
| 501 if (!message_center_bubble()) | 630 if (!message_center_bubble()) |
| 502 return; | 631 return; |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 523 | 652 |
| 524 message_center::MessageCenterBubble* | 653 message_center::MessageCenterBubble* |
| 525 WebNotificationTray::GetMessageCenterBubbleForTest() { | 654 WebNotificationTray::GetMessageCenterBubbleForTest() { |
| 526 if (!message_center_bubble()) | 655 if (!message_center_bubble()) |
| 527 return NULL; | 656 return NULL; |
| 528 return static_cast<message_center::MessageCenterBubble*>( | 657 return static_cast<message_center::MessageCenterBubble*>( |
| 529 message_center_bubble()->bubble()); | 658 message_center_bubble()->bubble()); |
| 530 } | 659 } |
| 531 | 660 |
| 532 } // namespace ash | 661 } // namespace ash |
| OLD | NEW |