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