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/thread_task_runner_handle.h" |
28 #include "grit/ash_resources.h" | |
28 #include "grit/ash_strings.h" | 29 #include "grit/ash_strings.h" |
29 #include "ui/aura/window.h" | 30 #include "ui/aura/window.h" |
30 #include "ui/aura/window_event_dispatcher.h" | 31 #include "ui/aura/window_event_dispatcher.h" |
31 #include "ui/base/l10n/l10n_util.h" | 32 #include "ui/base/l10n/l10n_util.h" |
33 #include "ui/base/resource/resource_bundle.h" | |
32 #include "ui/display/screen.h" | 34 #include "ui/display/screen.h" |
33 #include "ui/message_center/message_center_style.h" | 35 #include "ui/message_center/message_center_style.h" |
34 #include "ui/message_center/message_center_tray_delegate.h" | 36 #include "ui/message_center/message_center_tray_delegate.h" |
35 #include "ui/message_center/views/message_bubble_base.h" | 37 #include "ui/message_center/views/message_bubble_base.h" |
36 #include "ui/message_center/views/message_center_bubble.h" | 38 #include "ui/message_center/views/message_center_bubble.h" |
37 #include "ui/message_center/views/message_popup_collection.h" | 39 #include "ui/message_center/views/message_popup_collection.h" |
38 #include "ui/strings/grit/ui_strings.h" | 40 #include "ui/strings/grit/ui_strings.h" |
39 #include "ui/views/bubble/tray_bubble_view.h" | 41 #include "ui/views/bubble/tray_bubble_view.h" |
40 #include "ui/views/controls/button/custom_button.h" | 42 #include "ui/views/controls/button/custom_button.h" |
41 #include "ui/views/controls/image_view.h" | 43 #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); | 113 DISALLOW_COPY_AND_ASSIGN(WebNotificationBubbleWrapper); |
112 }; | 114 }; |
113 | 115 |
114 class WebNotificationButton : public views::CustomButton { | 116 class WebNotificationButton : public views::CustomButton { |
115 public: | 117 public: |
116 WebNotificationButton(views::ButtonListener* listener) | 118 WebNotificationButton(views::ButtonListener* listener) |
117 : views::CustomButton(listener), | 119 : views::CustomButton(listener), |
118 is_bubble_visible_(false), | 120 is_bubble_visible_(false), |
119 unread_count_(0) { | 121 unread_count_(0) { |
120 SetLayoutManager(new views::FillLayout); | 122 SetLayoutManager(new views::FillLayout); |
121 unread_label_ = new views::Label(); | 123 |
122 SetupLabelForTray(unread_label_); | 124 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
123 AddChildView(unread_label_); | 125 no_unread_icon_.reset(new views::ImageView()); |
126 no_unread_icon_->SetImage( | |
127 rb.GetImageNamed(IDR_ASH_SHELF_NOTIFICATION_TRAY_EMPTY).ToImageSkia()); | |
oshima
2016/05/11 02:46:30
do you really need an image view here? Doesn't emp
yoshiki
2016/05/11 05:42:51
Yes, the initial state is unread_count == 0, so we
oshima
2016/05/11 14:35:10
which one is bell icon? Or empty.png is just a pla
| |
128 no_unread_icon_->SetImageSize(gfx::Size(18, 18)); | |
129 no_unread_icon_->set_owned_by_client(); | |
130 | |
131 unread_label_.reset(new views::Label()); | |
oshima
2016/05/11 02:46:30
you can just use view::Label unread_label_;
yoshiki
2016/05/11 05:42:51
Done.
| |
132 unread_label_->set_owned_by_client(); | |
133 SetupLabelForTray(unread_label_.get()); | |
134 | |
135 AddChildView(unread_label_.get()); | |
124 } | 136 } |
125 | 137 |
126 void SetBubbleVisible(bool visible) { | 138 void SetBubbleVisible(bool visible) { |
127 if (visible == is_bubble_visible_) | 139 if (visible == is_bubble_visible_) |
128 return; | 140 return; |
129 | 141 |
130 is_bubble_visible_ = visible; | 142 is_bubble_visible_ = visible; |
131 UpdateIconVisibility(); | 143 UpdateIconVisibility(); |
132 } | 144 } |
133 | 145 |
134 void SetUnreadCount(int unread_count) { | 146 void SetUnreadCount(int unread_count) { |
135 // base::FormatNumber doesn't convert to arabic numeric characters. | 147 // base::FormatNumber doesn't convert to arabic numeric characters. |
136 // TODO(mukai): use ICU to support conversion for such locales. | 148 // TODO(mukai): use ICU to support conversion for such locales. |
137 unread_count_ = unread_count; | 149 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(); | 150 UpdateIconVisibility(); |
144 } | 151 } |
145 | 152 |
146 protected: | 153 protected: |
147 // Overridden from views::ImageButton: | 154 // Overridden from views::ImageButton: |
148 gfx::Size GetPreferredSize() const override { | 155 gfx::Size GetPreferredSize() const override { |
149 return gfx::Size(kShelfItemHeight, kShelfItemHeight); | 156 return gfx::Size(kShelfItemHeight, kShelfItemHeight); |
150 } | 157 } |
151 | 158 |
152 int GetHeightForWidth(int width) const override { | 159 int GetHeightForWidth(int width) const override { |
153 return GetPreferredSize().height(); | 160 return GetPreferredSize().height(); |
154 } | 161 } |
155 | 162 |
156 private: | 163 private: |
157 void UpdateIconVisibility() { | 164 void UpdateIconVisibility() { |
158 unread_label_->SetEnabledColor( | 165 if (unread_count_ == 0) { |
159 (!is_bubble_visible_ && unread_count_ > 0) ? | 166 if (!Contains(no_unread_icon_.get())) { |
160 kWebNotificationColorWithUnread : kWebNotificationColorNoUnread); | 167 RemoveAllChildViews(false /* delete_children */); |
168 AddChildView(no_unread_icon_.get()); | |
169 } | |
170 } else { | |
171 if (!Contains(unread_label_.get())) { | |
172 RemoveAllChildViews(false /* delete_children */); | |
173 AddChildView(unread_label_.get()); | |
174 } | |
175 | |
176 // TODO(mukai): move NINE_PLUS message to ui_strings, it doesn't need to | |
177 // be in ash_strings. | |
178 unread_label_->SetText( | |
179 (unread_count_ > 9) ? l10n_util::GetStringUTF16( | |
180 IDS_ASH_NOTIFICATION_UNREAD_COUNT_NINE_PLUS) | |
181 : base::FormatNumber(unread_count_)); | |
182 unread_label_->SetEnabledColor((!is_bubble_visible_) | |
183 ? kWebNotificationColorWithUnread | |
184 : kWebNotificationColorNoUnread); | |
185 } | |
186 | |
161 SchedulePaint(); | 187 SchedulePaint(); |
162 } | 188 } |
163 | 189 |
164 bool is_bubble_visible_; | 190 bool is_bubble_visible_; |
165 int unread_count_; | 191 int unread_count_; |
166 | 192 |
167 views::Label* unread_label_; | 193 std::unique_ptr<views::ImageView> no_unread_icon_; |
194 std::unique_ptr<views::Label> unread_label_; | |
168 | 195 |
169 DISALLOW_COPY_AND_ASSIGN(WebNotificationButton); | 196 DISALLOW_COPY_AND_ASSIGN(WebNotificationButton); |
170 }; | 197 }; |
171 | 198 |
172 WebNotificationTray::WebNotificationTray(StatusAreaWidget* status_area_widget) | 199 WebNotificationTray::WebNotificationTray(StatusAreaWidget* status_area_widget) |
173 : TrayBackgroundView(status_area_widget), | 200 : TrayBackgroundView(status_area_widget), |
174 button_(NULL), | 201 button_(NULL), |
175 show_message_center_on_unlock_(false), | 202 show_message_center_on_unlock_(false), |
176 should_update_tray_content_(false), | 203 should_update_tray_content_(false), |
177 should_block_shelf_auto_hide_(false) { | 204 should_block_shelf_auto_hide_(false) { |
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
479 | 506 |
480 message_center::MessageCenterBubble* | 507 message_center::MessageCenterBubble* |
481 WebNotificationTray::GetMessageCenterBubbleForTest() { | 508 WebNotificationTray::GetMessageCenterBubbleForTest() { |
482 if (!message_center_bubble()) | 509 if (!message_center_bubble()) |
483 return NULL; | 510 return NULL; |
484 return static_cast<message_center::MessageCenterBubble*>( | 511 return static_cast<message_center::MessageCenterBubble*>( |
485 message_center_bubble()->bubble()); | 512 message_center_bubble()->bubble()); |
486 } | 513 } |
487 | 514 |
488 } // namespace ash | 515 } // namespace ash |
OLD | NEW |