| 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/ash_switches.h" | 7 #include "ash/ash_switches.h" |
| 8 #include "ash/root_window_controller.h" | 8 #include "ash/root_window_controller.h" |
| 9 #include "ash/shelf/shelf_layout_manager.h" | 9 #include "ash/shelf/shelf_layout_manager.h" |
| 10 #include "ash/shelf/shelf_layout_manager_observer.h" | 10 #include "ash/shelf/shelf_layout_manager_observer.h" |
| 11 #include "ash/shelf/shelf_util.h" | 11 #include "ash/shelf/shelf_util.h" |
| 12 #include "ash/shelf/shelf_widget.h" | 12 #include "ash/shelf/shelf_widget.h" |
| 13 #include "ash/shell.h" | 13 #include "ash/shell.h" |
| 14 #include "ash/shell_window_ids.h" | 14 #include "ash/shell_window_ids.h" |
| 15 #include "ash/system/status_area_widget.h" | 15 #include "ash/system/status_area_widget.h" |
| 16 #include "ash/system/tray/system_tray.h" | 16 #include "ash/system/tray/system_tray.h" |
| 17 #include "ash/system/tray/tray_background_view.h" | 17 #include "ash/system/tray/tray_background_view.h" |
| 18 #include "ash/system/tray/tray_bubble_wrapper.h" | 18 #include "ash/system/tray/tray_bubble_wrapper.h" |
| 19 #include "ash/system/tray/tray_constants.h" | 19 #include "ash/system/tray/tray_constants.h" |
| 20 #include "ash/system/tray/tray_utils.h" | 20 #include "ash/system/tray/tray_utils.h" |
| 21 #include "ash/system/web_notification/ash_popup_alignment_delegate.h" | 21 #include "ash/system/web_notification/ash_popup_alignment_delegate.h" |
| 22 #include "ash/wm/common/shelf/wm_shelf_util.h" | 22 #include "ash/wm/common/shelf/wm_shelf_util.h" |
| 23 #include "base/auto_reset.h" | 23 #include "base/auto_reset.h" |
| 24 #include "base/i18n/number_formatting.h" | 24 #include "base/i18n/number_formatting.h" |
| 25 #include "base/i18n/rtl.h" | 25 #include "base/i18n/rtl.h" |
| 26 #include "base/strings/utf_string_conversions.h" | 26 #include "base/strings/utf_string_conversions.h" |
| 27 #include "base/thread_task_runner_handle.h" |
| 27 #include "base/threading/thread_task_runner_handle.h" | 28 #include "base/threading/thread_task_runner_handle.h" |
| 29 #include "grit/ash_resources.h" |
| 28 #include "grit/ash_strings.h" | 30 #include "grit/ash_strings.h" |
| 29 #include "ui/aura/window.h" | 31 #include "ui/aura/window.h" |
| 30 #include "ui/aura/window_event_dispatcher.h" | 32 #include "ui/aura/window_event_dispatcher.h" |
| 31 #include "ui/base/l10n/l10n_util.h" | 33 #include "ui/base/l10n/l10n_util.h" |
| 34 #include "ui/base/resource/resource_bundle.h" |
| 32 #include "ui/display/screen.h" | 35 #include "ui/display/screen.h" |
| 33 #include "ui/message_center/message_center_style.h" | 36 #include "ui/message_center/message_center_style.h" |
| 34 #include "ui/message_center/message_center_tray_delegate.h" | 37 #include "ui/message_center/message_center_tray_delegate.h" |
| 35 #include "ui/message_center/views/message_bubble_base.h" | 38 #include "ui/message_center/views/message_bubble_base.h" |
| 36 #include "ui/message_center/views/message_center_bubble.h" | 39 #include "ui/message_center/views/message_center_bubble.h" |
| 37 #include "ui/message_center/views/message_popup_collection.h" | 40 #include "ui/message_center/views/message_popup_collection.h" |
| 38 #include "ui/strings/grit/ui_strings.h" | 41 #include "ui/strings/grit/ui_strings.h" |
| 39 #include "ui/views/bubble/tray_bubble_view.h" | 42 #include "ui/views/bubble/tray_bubble_view.h" |
| 40 #include "ui/views/controls/button/custom_button.h" | 43 #include "ui/views/controls/button/custom_button.h" |
| 41 #include "ui/views/controls/image_view.h" | 44 #include "ui/views/controls/image_view.h" |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 DISALLOW_COPY_AND_ASSIGN(WebNotificationBubbleWrapper); | 114 DISALLOW_COPY_AND_ASSIGN(WebNotificationBubbleWrapper); |
| 112 }; | 115 }; |
| 113 | 116 |
| 114 class WebNotificationButton : public views::CustomButton { | 117 class WebNotificationButton : public views::CustomButton { |
| 115 public: | 118 public: |
| 116 WebNotificationButton(views::ButtonListener* listener) | 119 WebNotificationButton(views::ButtonListener* listener) |
| 117 : views::CustomButton(listener), | 120 : views::CustomButton(listener), |
| 118 is_bubble_visible_(false), | 121 is_bubble_visible_(false), |
| 119 unread_count_(0) { | 122 unread_count_(0) { |
| 120 SetLayoutManager(new views::FillLayout); | 123 SetLayoutManager(new views::FillLayout); |
| 121 unread_label_ = new views::Label(); | 124 |
| 122 SetupLabelForTray(unread_label_); | 125 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 123 AddChildView(unread_label_); | 126 no_unread_icon_.SetImage( |
| 127 rb.GetImageNamed(IDR_ASH_SHELF_NOTIFICATION_TRAY_BELL).ToImageSkia()); |
| 128 no_unread_icon_.SetImageSize(gfx::Size(18, 18)); |
| 129 no_unread_icon_.set_owned_by_client(); |
| 130 |
| 131 unread_label_.set_owned_by_client(); |
| 132 SetupLabelForTray(&unread_label_); |
| 133 |
| 134 AddChildView(&unread_label_); |
| 124 } | 135 } |
| 125 | 136 |
| 126 void SetBubbleVisible(bool visible) { | 137 void SetBubbleVisible(bool visible) { |
| 127 if (visible == is_bubble_visible_) | 138 if (visible == is_bubble_visible_) |
| 128 return; | 139 return; |
| 129 | 140 |
| 130 is_bubble_visible_ = visible; | 141 is_bubble_visible_ = visible; |
| 131 UpdateIconVisibility(); | 142 UpdateIconVisibility(); |
| 132 } | 143 } |
| 133 | 144 |
| 134 void SetUnreadCount(int unread_count) { | 145 void SetUnreadCount(int unread_count) { |
| 135 // base::FormatNumber doesn't convert to arabic numeric characters. | 146 // base::FormatNumber doesn't convert to arabic numeric characters. |
| 136 // TODO(mukai): use ICU to support conversion for such locales. | 147 // TODO(mukai): use ICU to support conversion for such locales. |
| 137 unread_count_ = unread_count; | 148 unread_count_ = unread_count; |
| 138 // TODO(mukai): move NINE_PLUS message to ui_strings, it doesn't need to be | |
| 139 // in ash_strings. | |
| 140 unread_label_->SetText((unread_count > 9) ? | |
| 141 l10n_util::GetStringUTF16(IDS_ASH_NOTIFICATION_UNREAD_COUNT_NINE_PLUS) : | |
| 142 base::FormatNumber(unread_count)); | |
| 143 UpdateIconVisibility(); | 149 UpdateIconVisibility(); |
| 144 } | 150 } |
| 145 | 151 |
| 146 protected: | 152 protected: |
| 147 // Overridden from views::ImageButton: | 153 // Overridden from views::ImageButton: |
| 148 gfx::Size GetPreferredSize() const override { | 154 gfx::Size GetPreferredSize() const override { |
| 149 return gfx::Size(kShelfItemHeight, kShelfItemHeight); | 155 return gfx::Size(kShelfItemHeight, kShelfItemHeight); |
| 150 } | 156 } |
| 151 | 157 |
| 152 int GetHeightForWidth(int width) const override { | 158 int GetHeightForWidth(int width) const override { |
| 153 return GetPreferredSize().height(); | 159 return GetPreferredSize().height(); |
| 154 } | 160 } |
| 155 | 161 |
| 156 private: | 162 private: |
| 157 void UpdateIconVisibility() { | 163 void UpdateIconVisibility() { |
| 158 unread_label_->SetEnabledColor((unread_count_ > 0) | 164 if (unread_count_ == 0) { |
| 159 ? kWebNotificationColorWithUnread | 165 if (!Contains(&no_unread_icon_)) { |
| 160 : kWebNotificationColorNoUnread); | 166 RemoveAllChildViews(false /* delete_children */); |
| 167 AddChildView(&no_unread_icon_); |
| 168 } |
| 169 } else { |
| 170 if (!Contains(&unread_label_)) { |
| 171 RemoveAllChildViews(false /* delete_children */); |
| 172 AddChildView(&unread_label_); |
| 173 } |
| 174 |
| 175 // TODO(mukai): move NINE_PLUS message to ui_strings, it doesn't need to |
| 176 // be in ash_strings. |
| 177 unread_label_.SetText( |
| 178 (unread_count_ > 9) ? l10n_util::GetStringUTF16( |
| 179 IDS_ASH_NOTIFICATION_UNREAD_COUNT_NINE_PLUS) |
| 180 : base::FormatNumber(unread_count_)); |
| 181 unread_label_.SetEnabledColor((unread_count_ > 0) |
| 182 ? kWebNotificationColorWithUnread |
| 183 : kWebNotificationColorNoUnread); |
| 184 } |
| 161 SchedulePaint(); | 185 SchedulePaint(); |
| 162 } | 186 } |
| 163 | 187 |
| 164 bool is_bubble_visible_; | 188 bool is_bubble_visible_; |
| 165 int unread_count_; | 189 int unread_count_; |
| 166 | 190 |
| 167 views::Label* unread_label_; | 191 views::ImageView no_unread_icon_; |
| 192 views::Label unread_label_; |
| 168 | 193 |
| 169 DISALLOW_COPY_AND_ASSIGN(WebNotificationButton); | 194 DISALLOW_COPY_AND_ASSIGN(WebNotificationButton); |
| 170 }; | 195 }; |
| 171 | 196 |
| 172 WebNotificationTray::WebNotificationTray(StatusAreaWidget* status_area_widget) | 197 WebNotificationTray::WebNotificationTray(StatusAreaWidget* status_area_widget) |
| 173 : TrayBackgroundView(status_area_widget), | 198 : TrayBackgroundView(status_area_widget), |
| 174 button_(NULL), | 199 button_(NULL), |
| 175 show_message_center_on_unlock_(false), | 200 show_message_center_on_unlock_(false), |
| 176 should_update_tray_content_(false), | 201 should_update_tray_content_(false), |
| 177 should_block_shelf_auto_hide_(false) { | 202 should_block_shelf_auto_hide_(false) { |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 479 | 504 |
| 480 message_center::MessageCenterBubble* | 505 message_center::MessageCenterBubble* |
| 481 WebNotificationTray::GetMessageCenterBubbleForTest() { | 506 WebNotificationTray::GetMessageCenterBubbleForTest() { |
| 482 if (!message_center_bubble()) | 507 if (!message_center_bubble()) |
| 483 return NULL; | 508 return NULL; |
| 484 return static_cast<message_center::MessageCenterBubble*>( | 509 return static_cast<message_center::MessageCenterBubble*>( |
| 485 message_center_bubble()->bubble()); | 510 message_center_bubble()->bubble()); |
| 486 } | 511 } |
| 487 | 512 |
| 488 } // namespace ash | 513 } // namespace ash |
| OLD | NEW |