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(16, 16); | |
| 72 constexpr gfx::Size kTrayItemInnerBellIconSize(18, 18); | |
| 73 constexpr gfx::Size kTrayItemOuterSize(26, 26); | |
| 74 constexpr gfx::Insets kTrayItemInsets(3, 3); | |
| 75 | |
| 76 constexpr int kTrayItemAnimationDurationMS = 200; | |
| 77 | |
| 78 constexpr size_t kMaximumNotificationNumber = 99; | |
| 79 | |
| 80 // Flag to disable animation. Only for testing. | |
| 81 static bool disable_animations_for_test = false; | |
|
oshima
2016/08/10 06:58:44
nit: you don't need static. anonymous namespace is
yoshiki
2016/08/10 10:18:53
Done.
| |
| 68 } | 82 } |
| 69 | 83 |
| 70 namespace { | 84 namespace { |
| 71 | 85 |
| 72 const SkColor kWebNotificationColorNoUnread = | 86 const SkColor kWebNotificationColorNoUnread = |
| 73 SkColorSetARGB(128, 255, 255, 255); | 87 SkColorSetARGB(128, 255, 255, 255); |
| 74 const SkColor kWebNotificationColorWithUnread = SK_ColorWHITE; | 88 const SkColor kWebNotificationColorWithUnread = SK_ColorWHITE; |
| 75 const int kNoUnreadIconSize = 18; | 89 const int kNoUnreadIconSize = 18; |
| 76 } | 90 } |
| 77 | 91 |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 108 // Convenience accessors. | 122 // Convenience accessors. |
| 109 views::TrayBubbleView* bubble_view() const { return bubble_->bubble_view(); } | 123 views::TrayBubbleView* bubble_view() const { return bubble_->bubble_view(); } |
| 110 | 124 |
| 111 private: | 125 private: |
| 112 std::unique_ptr<message_center::MessageBubbleBase> bubble_; | 126 std::unique_ptr<message_center::MessageBubbleBase> bubble_; |
| 113 std::unique_ptr<TrayBubbleWrapper> bubble_wrapper_; | 127 std::unique_ptr<TrayBubbleWrapper> bubble_wrapper_; |
| 114 | 128 |
| 115 DISALLOW_COPY_AND_ASSIGN(WebNotificationBubbleWrapper); | 129 DISALLOW_COPY_AND_ASSIGN(WebNotificationBubbleWrapper); |
| 116 }; | 130 }; |
| 117 | 131 |
| 118 class WebNotificationButton : public views::CustomButton { | 132 class WebNotificationItem : public views::View, public gfx::AnimationDelegate { |
| 119 public: | 133 public: |
| 120 WebNotificationButton(views::ButtonListener* listener) | 134 WebNotificationItem(gfx::AnimationContainer* container, |
| 121 : views::CustomButton(listener), | 135 WebNotificationTray* tray) |
| 122 is_bubble_visible_(false), | 136 : tray_(tray) { |
| 123 unread_count_(0) { | 137 SetPaintToLayer(true); |
| 138 layer()->SetFillsBoundsOpaquely(false); | |
| 139 views::View::SetVisible(false); | |
| 140 set_owned_by_client(); | |
| 141 | |
| 124 SetLayoutManager(new views::FillLayout); | 142 SetLayoutManager(new views::FillLayout); |
| 125 | 143 |
| 126 gfx::ImageSkia image; | 144 animation_.reset(new gfx::SlideAnimation(this)); |
| 127 if (MaterialDesignController::IsShelfMaterial()) { | 145 animation_->SetContainer(container); |
| 128 image = CreateVectorIcon(gfx::VectorIconId::SHELF_NOTIFICATIONS, | 146 animation_->SetSlideDuration(kTrayItemAnimationDurationMS); |
| 129 kShelfIconColor); | 147 animation_->SetTweenType(gfx::Tween::LINEAR); |
| 130 } else { | 148 } |
| 131 image = | 149 |
| 132 CreateVectorIcon(gfx::VectorIconId::NOTIFICATIONS, kNoUnreadIconSize, | 150 void SetVisible(bool set_visible) override { |
| 133 kWebNotificationColorNoUnread); | 151 if (!GetWidget() || disable_animations_for_test) { |
| 152 views::View::SetVisible(set_visible); | |
| 153 return; | |
| 134 } | 154 } |
| 135 | 155 |
| 136 no_unread_icon_.SetImage(image); | 156 if (!set_visible) { |
| 137 no_unread_icon_.set_owned_by_client(); | 157 animation_->Hide(); |
| 138 | 158 AnimationProgressed(animation_.get()); |
| 139 unread_label_.set_owned_by_client(); | 159 } else { |
| 140 SetupLabelForTray(&unread_label_); | 160 animation_->Show(); |
| 141 | 161 AnimationProgressed(animation_.get()); |
| 142 AddChildView(&no_unread_icon_); | 162 views::View::SetVisible(true); |
| 163 } | |
| 143 } | 164 } |
| 144 | 165 |
| 145 void SetBubbleVisible(bool visible) { | 166 void HideAndDelete() { |
| 146 if (visible == is_bubble_visible_) | 167 SetVisible(false); |
| 147 return; | |
| 148 | 168 |
| 149 is_bubble_visible_ = visible; | 169 if (!visible() && !animation_->is_animating()) { |
| 150 UpdateIconVisibility(); | 170 if (parent()) |
| 151 } | 171 parent()->RemoveChildView(this); |
| 152 | 172 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this); |
| 153 void SetUnreadCount(int unread_count) { | 173 } else { |
| 154 // base::FormatNumber doesn't convert to arabic numeric characters. | 174 delete_after_animation_ = true; |
| 155 // TODO(mukai): use ICU to support conversion for such locales. | 175 } |
| 156 unread_count_ = unread_count; | |
| 157 UpdateIconVisibility(); | |
| 158 } | 176 } |
| 159 | 177 |
| 160 protected: | 178 protected: |
| 161 // Overridden from views::ImageButton: | 179 // Overridden from views::ImageButton: |
| 162 gfx::Size GetPreferredSize() const override { | 180 gfx::Size GetPreferredSize() const override { |
| 163 const int size = GetTrayConstant(TRAY_ITEM_HEIGHT_LEGACY); | 181 if (!animation_.get() || !animation_->is_animating()) |
| 164 return gfx::Size(size, size); | 182 return kTrayItemOuterSize; |
| 183 | |
| 184 // Animate the width (or height) when this item shows (or hides) so that | |
| 185 // the icons on the left are shifted with the animation. | |
| 186 // Note that TrayItemView does the same thing. | |
| 187 gfx::Size size = kTrayItemOuterSize; | |
| 188 if (IsHorizontalLayout()) { | |
| 189 size.set_width(std::max( | |
| 190 1, gfx::ToRoundedInt(size.width() * animation_->GetCurrentValue()))); | |
| 191 } else { | |
| 192 size.set_height(std::max( | |
| 193 1, gfx::ToRoundedInt(size.height() * animation_->GetCurrentValue()))); | |
| 194 } | |
| 195 return size; | |
| 165 } | 196 } |
| 166 | 197 |
| 167 int GetHeightForWidth(int width) const override { | 198 int GetHeightForWidth(int width) const override { |
| 168 return GetPreferredSize().height(); | 199 return GetPreferredSize().height(); |
| 169 } | 200 } |
| 170 | 201 |
| 202 bool IsHorizontalLayout() const { | |
| 203 return IsHorizontalAlignment(tray_->shelf_alignment()); | |
| 204 } | |
| 205 | |
| 171 private: | 206 private: |
| 172 void UpdateIconVisibility() { | 207 // gfx::AnimationDelegate: |
| 173 if (unread_count_ == 0) { | 208 void AnimationProgressed(const gfx::Animation* animation) override { |
| 174 if (!Contains(&no_unread_icon_)) { | 209 gfx::Transform transform; |
| 175 RemoveAllChildViews(false /* delete_children */); | 210 if (IsHorizontalLayout()) { |
| 176 AddChildView(&no_unread_icon_); | 211 transform.Translate(0, animation->CurrentValueBetween( |
| 177 } | 212 static_cast<double>(height()) / 2., 0.)); |
| 178 } else { | 213 } else { |
| 179 if (!Contains(&unread_label_)) { | 214 transform.Translate( |
| 180 RemoveAllChildViews(false /* delete_children */); | 215 animation->CurrentValueBetween(static_cast<double>(width() / 2.), 0.), |
| 181 AddChildView(&unread_label_); | 216 0); |
| 182 } | 217 } |
| 218 transform.Scale(animation->GetCurrentValue(), animation->GetCurrentValue()); | |
| 219 layer()->SetTransform(transform); | |
| 220 PreferredSizeChanged(); | |
| 221 } | |
| 222 void AnimationEnded(const gfx::Animation* animation) override { | |
| 223 if (animation->GetCurrentValue() < 0.1) | |
| 224 views::View::SetVisible(false); | |
| 183 | 225 |
| 184 // TODO(mukai): move NINE_PLUS message to ui_strings, it doesn't need to | 226 if (delete_after_animation_) { |
| 185 // be in ash_strings. | 227 if (parent()) |
| 186 unread_label_.SetText( | 228 parent()->RemoveChildView(this); |
| 187 (unread_count_ > 9) ? l10n_util::GetStringUTF16( | 229 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 } | 230 } |
| 231 } | |
| 232 void AnimationCanceled(const gfx::Animation* animation) override { | |
| 233 AnimationEnded(animation); | |
| 234 } | |
| 235 | |
| 236 std::unique_ptr<gfx::SlideAnimation> animation_; | |
| 237 bool delete_after_animation_ = false; | |
| 238 WebNotificationTray* tray_; | |
| 239 | |
| 240 DISALLOW_COPY_AND_ASSIGN(WebNotificationItem); | |
| 241 }; | |
| 242 | |
| 243 class WebNotificationImage : public WebNotificationItem { | |
| 244 public: | |
| 245 WebNotificationImage(const gfx::ImageSkia& image, | |
| 246 gfx::Size size, | |
| 247 gfx::AnimationContainer* container, | |
| 248 WebNotificationTray* tray) | |
| 249 : WebNotificationItem(container, tray) { | |
| 250 view_ = new views::ImageView(); | |
| 251 view_->SetImage(image); | |
| 252 view_->SetImageSize(size); | |
| 253 AddChildView(view_); | |
| 254 } | |
| 255 | |
| 256 private: | |
| 257 views::ImageView* view_; | |
| 258 | |
| 259 DISALLOW_COPY_AND_ASSIGN(WebNotificationImage); | |
| 260 }; | |
| 261 | |
| 262 class WebNotificationLabel : public WebNotificationItem { | |
| 263 public: | |
| 264 WebNotificationLabel(gfx::AnimationContainer* container, | |
| 265 WebNotificationTray* tray) | |
| 266 : WebNotificationItem(container, tray) { | |
| 267 view_ = new views::Label(); | |
| 268 SetupLabelForTray(view_); | |
| 269 } | |
| 270 | |
| 271 void SetNotificationCount(bool small_icons_exist, size_t notification_count) { | |
| 272 notification_count = std::min(notification_count, | |
| 273 kMaximumNotificationNumber); // cap with 99 | |
| 274 | |
| 275 // TODO(yoshiki): Use a string for "99" and "+99". | |
| 276 | |
| 277 base::string16 str = base::FormatNumber(notification_count); | |
| 278 if (small_icons_exist) { | |
| 279 if (!base::i18n::IsRTL()) | |
| 280 str = base::ASCIIToUTF16("+") + str; | |
| 281 else | |
| 282 str = str + base::ASCIIToUTF16("+"); | |
| 283 } | |
|
xiyuan
2016/08/09 16:50:05
We should add a string template to resource
+<ph
yoshiki
2016/08/10 10:18:53
Got it. I'll do it in a separated patch.
| |
| 284 | |
| 285 view_->SetText(str); | |
| 286 view_->SetEnabledColor(kWebNotificationColorWithUnread); | |
| 287 AddChildView(view_); | |
| 194 SchedulePaint(); | 288 SchedulePaint(); |
| 195 } | 289 } |
| 196 | 290 |
| 197 bool is_bubble_visible_; | 291 private: |
| 198 int unread_count_; | 292 views::Label* view_; |
| 199 | 293 |
| 200 views::ImageView no_unread_icon_; | 294 DISALLOW_COPY_AND_ASSIGN(WebNotificationLabel); |
| 201 views::Label unread_label_; | |
| 202 | |
| 203 DISALLOW_COPY_AND_ASSIGN(WebNotificationButton); | |
| 204 }; | 295 }; |
| 205 | 296 |
| 206 WebNotificationTray::WebNotificationTray(WmShelf* shelf, | 297 WebNotificationTray::WebNotificationTray(WmShelf* shelf, |
| 207 WmWindow* status_area_window, | 298 WmWindow* status_area_window, |
| 208 SystemTray* system_tray) | 299 SystemTray* system_tray) |
| 209 : TrayBackgroundView(shelf), | 300 : TrayBackgroundView(shelf), |
| 210 status_area_window_(status_area_window), | 301 status_area_window_(status_area_window), |
| 211 system_tray_(system_tray), | 302 system_tray_(system_tray), |
| 212 button_(nullptr), | |
| 213 show_message_center_on_unlock_(false), | 303 show_message_center_on_unlock_(false), |
| 214 should_update_tray_content_(false), | 304 should_update_tray_content_(false), |
| 215 should_block_shelf_auto_hide_(false) { | 305 should_block_shelf_auto_hide_(false) { |
| 216 DCHECK(shelf); | 306 DCHECK(shelf); |
| 217 DCHECK(status_area_window_); | 307 DCHECK(status_area_window_); |
| 218 DCHECK(system_tray_); | 308 DCHECK(system_tray_); |
| 219 button_ = new WebNotificationButton(this); | 309 |
| 220 button_->set_triggerable_event_flags(ui::EF_LEFT_MOUSE_BUTTON | | 310 gfx::ImageSkia bell_image; |
| 221 ui::EF_RIGHT_MOUSE_BUTTON); | 311 if (MaterialDesignController::IsShelfMaterial()) { |
| 222 tray_container()->AddChildView(button_); | 312 bell_image = CreateVectorIcon(gfx::VectorIconId::SHELF_NOTIFICATIONS, |
| 223 button_->SetFocusBehavior(FocusBehavior::NEVER); | 313 kShelfIconColor); |
| 314 } else { | |
| 315 bell_image = | |
| 316 CreateVectorIcon(gfx::VectorIconId::NOTIFICATIONS, kNoUnreadIconSize, | |
| 317 kWebNotificationColorNoUnread); | |
| 318 } | |
| 319 bell_icon_.reset(new WebNotificationImage(bell_image, | |
| 320 kTrayItemInnerBellIconSize, | |
| 321 animation_container_.get(), this)); | |
| 322 tray_container()->AddChildView(bell_icon_.get()); | |
| 323 | |
| 324 counter_.reset(new WebNotificationLabel(animation_container_.get(), this)); | |
| 325 tray_container()->AddChildView(counter_.get()); | |
| 326 | |
| 224 SetContentsBackground(); | 327 SetContentsBackground(); |
| 225 tray_container()->SetBorder(views::Border::NullBorder()); | 328 tray_container()->SetBorder(views::Border::NullBorder()); |
| 226 message_center_tray_.reset(new message_center::MessageCenterTray( | 329 message_center_tray_.reset(new message_center::MessageCenterTray( |
| 227 this, message_center::MessageCenter::Get())); | 330 this, message_center::MessageCenter::Get())); |
| 228 popup_alignment_delegate_.reset(new AshPopupAlignmentDelegate(shelf)); | 331 popup_alignment_delegate_.reset(new AshPopupAlignmentDelegate(shelf)); |
| 229 popup_collection_.reset(new message_center::MessagePopupCollection( | 332 popup_collection_.reset(new message_center::MessagePopupCollection( |
| 230 message_center(), message_center_tray_.get(), | 333 message_center(), message_center_tray_.get(), |
| 231 popup_alignment_delegate_.get())); | 334 popup_alignment_delegate_.get())); |
| 232 const display::Display& display = | 335 const display::Display& display = |
| 233 status_area_window_->GetDisplayNearestWindow(); | 336 status_area_window_->GetDisplayNearestWindow(); |
| 234 popup_alignment_delegate_->StartObserving(display::Screen::GetScreen(), | 337 popup_alignment_delegate_->StartObserving(display::Screen::GetScreen(), |
| 235 display); | 338 display); |
| 236 OnMessageCenterTrayChanged(); | 339 OnMessageCenterTrayChanged(); |
| 340 | |
| 341 tray_container()->SetMargin(kTrayItemInsets); | |
| 237 } | 342 } |
| 238 | 343 |
| 239 WebNotificationTray::~WebNotificationTray() { | 344 WebNotificationTray::~WebNotificationTray() { |
| 240 // Release any child views that might have back pointers before ~View(). | 345 // Release any child views that might have back pointers before ~View(). |
| 241 message_center_bubble_.reset(); | 346 message_center_bubble_.reset(); |
| 242 popup_alignment_delegate_.reset(); | 347 popup_alignment_delegate_.reset(); |
| 243 popup_collection_.reset(); | 348 popup_collection_.reset(); |
| 244 } | 349 } |
| 245 | 350 |
| 351 // static | |
| 352 void WebNotificationTray::DisableAnimationsForTest(bool disable) { | |
| 353 disable_animations_for_test = disable; | |
| 354 } | |
| 355 | |
| 246 // Public methods. | 356 // Public methods. |
| 247 | 357 |
| 248 bool WebNotificationTray::ShowMessageCenterInternal(bool show_settings) { | 358 bool WebNotificationTray::ShowMessageCenterInternal(bool show_settings) { |
| 249 if (!ShouldShowMessageCenter()) | 359 if (!ShouldShowMessageCenter()) |
| 250 return false; | 360 return false; |
| 251 | 361 |
| 252 should_block_shelf_auto_hide_ = true; | 362 should_block_shelf_auto_hide_ = true; |
| 253 message_center::MessageCenterBubble* message_center_bubble = | 363 message_center::MessageCenterBubble* message_center_bubble = |
| 254 new message_center::MessageCenterBubble(message_center(), | 364 new message_center::MessageCenterBubble(message_center(), |
| 255 message_center_tray_.get(), true); | 365 message_center_tray_.get(), true); |
| 256 | 366 |
| 257 int max_height; | 367 int max_height; |
| 258 if (IsHorizontalAlignment(shelf()->GetAlignment())) { | 368 if (IsHorizontalAlignment(shelf_alignment())) { |
| 259 max_height = shelf()->GetIdealBounds().y(); | 369 max_height = shelf()->GetIdealBounds().y(); |
| 260 } else { | 370 } else { |
| 261 // Assume the status area and bubble bottoms are aligned when vertical. | 371 // Assume the status area and bubble bottoms are aligned when vertical. |
| 262 gfx::Rect bounds_in_root = | 372 gfx::Rect bounds_in_root = |
| 263 status_area_window_->GetRootWindow()->ConvertRectFromScreen( | 373 status_area_window_->GetRootWindow()->ConvertRectFromScreen( |
| 264 status_area_window_->GetBoundsInScreen()); | 374 status_area_window_->GetBoundsInScreen()); |
| 265 max_height = bounds_in_root.bottom(); | 375 max_height = bounds_in_root.bottom(); |
| 266 } | 376 } |
| 267 message_center_bubble->SetMaxHeight( | 377 message_center_bubble->SetMaxHeight( |
| 268 std::max(0, max_height - GetTrayConstant(TRAY_SPACING))); | 378 std::max(0, max_height - GetTrayConstant(TRAY_SPACING))); |
| 269 if (show_settings) | 379 if (show_settings) |
| 270 message_center_bubble->SetSettingsVisible(); | 380 message_center_bubble->SetSettingsVisible(); |
| 271 message_center_bubble_.reset( | 381 message_center_bubble_.reset( |
| 272 new WebNotificationBubbleWrapper(this, message_center_bubble)); | 382 new WebNotificationBubbleWrapper(this, message_center_bubble)); |
| 273 | 383 |
| 274 system_tray_->SetHideNotifications(true); | 384 system_tray_->SetHideNotifications(true); |
| 275 shelf()->UpdateAutoHideState(); | 385 shelf()->UpdateAutoHideState(); |
| 276 button_->SetBubbleVisible(true); | |
| 277 SetDrawBackgroundAsActive(true); | 386 SetDrawBackgroundAsActive(true); |
| 278 return true; | 387 return true; |
| 279 } | 388 } |
| 280 | 389 |
| 281 bool WebNotificationTray::ShowMessageCenter() { | 390 bool WebNotificationTray::ShowMessageCenter() { |
| 282 return ShowMessageCenterInternal(false /* show_settings */); | 391 return ShowMessageCenterInternal(false /* show_settings */); |
| 283 } | 392 } |
| 284 | 393 |
| 285 void WebNotificationTray::HideMessageCenter() { | 394 void WebNotificationTray::HideMessageCenter() { |
| 286 if (!message_center_bubble()) | 395 if (!message_center_bubble()) |
| 287 return; | 396 return; |
| 288 SetDrawBackgroundAsActive(false); | 397 SetDrawBackgroundAsActive(false); |
| 289 message_center_bubble_.reset(); | 398 message_center_bubble_.reset(); |
| 290 should_block_shelf_auto_hide_ = false; | 399 should_block_shelf_auto_hide_ = false; |
| 291 show_message_center_on_unlock_ = false; | 400 show_message_center_on_unlock_ = false; |
| 292 system_tray_->SetHideNotifications(false); | 401 system_tray_->SetHideNotifications(false); |
| 293 shelf()->UpdateAutoHideState(); | 402 shelf()->UpdateAutoHideState(); |
| 294 button_->SetBubbleVisible(false); | |
| 295 } | 403 } |
| 296 | 404 |
| 297 void WebNotificationTray::SetTrayBubbleHeight(int height) { | 405 void WebNotificationTray::SetTrayBubbleHeight(int height) { |
| 298 popup_alignment_delegate_->SetTrayBubbleHeight(height); | 406 popup_alignment_delegate_->SetTrayBubbleHeight(height); |
| 299 } | 407 } |
| 300 | 408 |
| 301 int WebNotificationTray::tray_bubble_height_for_test() const { | 409 int WebNotificationTray::tray_bubble_height_for_test() const { |
| 302 return popup_alignment_delegate_->tray_bubble_height_for_test(); | 410 return popup_alignment_delegate_->tray_bubble_height_for_test(); |
| 303 } | 411 } |
| 304 | 412 |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 453 bool in_quiet_mode = message_center()->IsQuietMode(); | 561 bool in_quiet_mode = message_center()->IsQuietMode(); |
| 454 message_center()->SetQuietMode(!in_quiet_mode); | 562 message_center()->SetQuietMode(!in_quiet_mode); |
| 455 return; | 563 return; |
| 456 } | 564 } |
| 457 base::TimeDelta expires_in = command_id == kEnableQuietModeDay | 565 base::TimeDelta expires_in = command_id == kEnableQuietModeDay |
| 458 ? base::TimeDelta::FromDays(1) | 566 ? base::TimeDelta::FromDays(1) |
| 459 : base::TimeDelta::FromHours(1); | 567 : base::TimeDelta::FromHours(1); |
| 460 message_center()->EnterQuietModeWithExpire(expires_in); | 568 message_center()->EnterQuietModeWithExpire(expires_in); |
| 461 } | 569 } |
| 462 | 570 |
| 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() { | 571 void WebNotificationTray::OnMessageCenterTrayChanged() { |
| 470 // Do not update the tray contents directly. Multiple change events can happen | 572 // 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 | 573 // consecutively, and calling Update in the middle of those events will show |
| 472 // intermediate unread counts for a moment. | 574 // intermediate unread counts for a moment. |
| 473 should_update_tray_content_ = true; | 575 should_update_tray_content_ = true; |
| 474 base::ThreadTaskRunnerHandle::Get()->PostTask( | 576 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 475 FROM_HERE, | 577 FROM_HERE, |
| 476 base::Bind(&WebNotificationTray::UpdateTrayContent, AsWeakPtr())); | 578 base::Bind(&WebNotificationTray::UpdateTrayContent, AsWeakPtr())); |
| 477 } | 579 } |
| 478 | 580 |
| 479 void WebNotificationTray::UpdateTrayContent() { | 581 void WebNotificationTray::UpdateTrayContent() { |
| 480 if (!should_update_tray_content_) | 582 if (!should_update_tray_content_) |
| 481 return; | 583 return; |
| 482 should_update_tray_content_ = false; | 584 should_update_tray_content_ = false; |
| 483 | 585 |
| 586 std::unordered_set<std::string> notification_ids; | |
| 587 for (auto i : visible_small_icons_) | |
|
oshima
2016/08/10 06:58:44
nit: auto pair
yoshiki
2016/08/10 10:18:53
Done.
| |
| 588 notification_ids.insert(i.first); | |
| 589 | |
| 590 // Add small icons (up to kMaximumSmallIconCount = 3). | |
| 484 message_center::MessageCenter* message_center = | 591 message_center::MessageCenter* message_center = |
| 485 message_center_tray_->message_center(); | 592 message_center_tray_->message_center(); |
| 486 button_->SetUnreadCount(message_center->UnreadNotificationCount()); | 593 size_t visible_small_icon_count = 0; |
| 487 if (IsMessageCenterBubbleVisible()) | 594 for (const auto* notification : message_center->GetVisibleNotifications()) { |
| 488 button_->SetState(views::CustomButton::STATE_PRESSED); | 595 gfx::Image image = notification->small_image(); |
| 489 else | 596 if (image.IsEmpty()) |
| 490 button_->SetState(views::CustomButton::STATE_NORMAL); | 597 continue; |
| 598 | |
| 599 if (visible_small_icon_count >= kMaximumSmallIconCount) | |
| 600 break; | |
| 601 visible_small_icon_count++; | |
| 602 | |
| 603 notification_ids.erase(notification->id()); | |
| 604 if (visible_small_icons_.count(notification->id()) != 0) | |
| 605 continue; | |
| 606 | |
| 607 auto* item = | |
| 608 new WebNotificationImage(image.AsImageSkia(), kTrayItemInnerIconSize, | |
| 609 animation_container_.get(), this); | |
| 610 visible_small_icons_.insert(std::make_pair(notification->id(), item)); | |
| 611 | |
| 612 tray_container()->AddChildViewAt(item, 0); | |
| 613 item->SetVisible(true); | |
| 614 } | |
| 615 | |
| 616 // Remove unnecessary icons. | |
| 617 for (const std::string& id : notification_ids) { | |
| 618 WebNotificationImage* item = visible_small_icons_[id]; | |
| 619 visible_small_icons_.erase(id); | |
| 620 item->HideAndDelete(); | |
| 621 } | |
| 622 | |
| 623 // Show or hide the bell icon. | |
| 624 size_t visible_notification_count = message_center->NotificationCount(); | |
| 625 bell_icon_->SetVisible(visible_notification_count == 0); | |
| 626 | |
| 627 // Show or hide the counter. | |
| 628 size_t hidden_icon_count = | |
| 629 visible_notification_count - visible_small_icon_count; | |
| 630 if (hidden_icon_count != 0) { | |
| 631 counter_->SetVisible(true); | |
| 632 counter_->SetNotificationCount( | |
| 633 (visible_small_icon_count != 0), // small_icons_exist | |
| 634 hidden_icon_count); | |
| 635 } else { | |
| 636 counter_->SetVisible(false); | |
| 637 } | |
| 491 | 638 |
| 492 SetVisible(IsLoggedIn()); | 639 SetVisible(IsLoggedIn()); |
| 640 PreferredSizeChanged(); | |
| 493 Layout(); | 641 Layout(); |
| 494 SchedulePaint(); | 642 SchedulePaint(); |
| 495 if (IsLoggedIn()) | 643 if (IsLoggedIn()) |
| 496 system_tray_->SetNextFocusableView(this); | 644 system_tray_->SetNextFocusableView(this); |
| 497 } | 645 } |
| 498 | 646 |
| 499 void WebNotificationTray::ClickedOutsideBubble() { | 647 void WebNotificationTray::ClickedOutsideBubble() { |
| 500 // Only hide the message center | 648 // Only hide the message center |
| 501 if (!message_center_bubble()) | 649 if (!message_center_bubble()) |
| 502 return; | 650 return; |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 523 | 671 |
| 524 message_center::MessageCenterBubble* | 672 message_center::MessageCenterBubble* |
| 525 WebNotificationTray::GetMessageCenterBubbleForTest() { | 673 WebNotificationTray::GetMessageCenterBubbleForTest() { |
| 526 if (!message_center_bubble()) | 674 if (!message_center_bubble()) |
| 527 return NULL; | 675 return NULL; |
| 528 return static_cast<message_center::MessageCenterBubble*>( | 676 return static_cast<message_center::MessageCenterBubble*>( |
| 529 message_center_bubble()->bubble()); | 677 message_center_bubble()->bubble()); |
| 530 } | 678 } |
| 531 | 679 |
| 532 } // namespace ash | 680 } // namespace ash |
| OLD | NEW |