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 "ui/message_center/views/notification_view.h" | 5 #include "ui/message_center/views/notification_view.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "grit/ui_resources.h" | 10 #include "grit/ui_resources.h" |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 | 190 |
191 // NotificationProgressBar ///////////////////////////////////////////////////// | 191 // NotificationProgressBar ///////////////////////////////////////////////////// |
192 | 192 |
193 class NotificationProgressBar : public views::ProgressBar { | 193 class NotificationProgressBar : public views::ProgressBar { |
194 public: | 194 public: |
195 NotificationProgressBar(); | 195 NotificationProgressBar(); |
196 virtual ~NotificationProgressBar(); | 196 virtual ~NotificationProgressBar(); |
197 | 197 |
198 private: | 198 private: |
199 // Overriden from View | 199 // Overriden from View |
200 virtual gfx::Size GetPreferredSize() OVERRIDE; | 200 virtual gfx::Size GetPreferredSize() const OVERRIDE; |
201 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; | 201 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; |
202 | 202 |
203 DISALLOW_COPY_AND_ASSIGN(NotificationProgressBar); | 203 DISALLOW_COPY_AND_ASSIGN(NotificationProgressBar); |
204 }; | 204 }; |
205 | 205 |
206 NotificationProgressBar::NotificationProgressBar() { | 206 NotificationProgressBar::NotificationProgressBar() { |
207 } | 207 } |
208 | 208 |
209 NotificationProgressBar::~NotificationProgressBar() { | 209 NotificationProgressBar::~NotificationProgressBar() { |
210 } | 210 } |
211 | 211 |
212 gfx::Size NotificationProgressBar::GetPreferredSize() { | 212 gfx::Size NotificationProgressBar::GetPreferredSize() const { |
213 gfx::Size pref_size(kProgressBarWidth, message_center::kProgressBarThickness); | 213 gfx::Size pref_size(kProgressBarWidth, message_center::kProgressBarThickness); |
214 gfx::Insets insets = GetInsets(); | 214 gfx::Insets insets = GetInsets(); |
215 pref_size.Enlarge(insets.width(), insets.height()); | 215 pref_size.Enlarge(insets.width(), insets.height()); |
216 return pref_size; | 216 return pref_size; |
217 } | 217 } |
218 | 218 |
219 void NotificationProgressBar::OnPaint(gfx::Canvas* canvas) { | 219 void NotificationProgressBar::OnPaint(gfx::Canvas* canvas) { |
220 gfx::Rect content_bounds = GetContentsBounds(); | 220 gfx::Rect content_bounds = GetContentsBounds(); |
221 | 221 |
222 // Draw background. | 222 // Draw background. |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 // image to overlap the content as needed to provide large enough click and | 355 // image to overlap the content as needed to provide large enough click and |
356 // touch areas (<http://crbug.com/168822> and <http://crbug.com/168856>). | 356 // touch areas (<http://crbug.com/168822> and <http://crbug.com/168856>). |
357 AddChildView(small_image()); | 357 AddChildView(small_image()); |
358 AddChildView(close_button()); | 358 AddChildView(close_button()); |
359 SetAccessibleName(notification); | 359 SetAccessibleName(notification); |
360 } | 360 } |
361 | 361 |
362 NotificationView::~NotificationView() { | 362 NotificationView::~NotificationView() { |
363 } | 363 } |
364 | 364 |
365 gfx::Size NotificationView::GetPreferredSize() { | 365 gfx::Size NotificationView::GetPreferredSize() const { |
366 int top_width = top_view_->GetPreferredSize().width() + | 366 int top_width = top_view_->GetPreferredSize().width() + |
367 icon_view_->GetPreferredSize().width(); | 367 icon_view_->GetPreferredSize().width(); |
368 int bottom_width = bottom_view_->GetPreferredSize().width(); | 368 int bottom_width = bottom_view_->GetPreferredSize().width(); |
369 int preferred_width = std::max(top_width, bottom_width) + GetInsets().width(); | 369 int preferred_width = std::max(top_width, bottom_width) + GetInsets().width(); |
370 return gfx::Size(preferred_width, GetHeightForWidth(preferred_width)); | 370 return gfx::Size(preferred_width, GetHeightForWidth(preferred_width)); |
371 } | 371 } |
372 | 372 |
373 int NotificationView::GetHeightForWidth(int width) { | 373 int NotificationView::GetHeightForWidth(int width) const { |
374 // Get the height assuming no line limit changes. | 374 // Get the height assuming no line limit changes. |
375 int content_width = width - GetInsets().width(); | 375 int content_width = width - GetInsets().width(); |
376 int top_height = top_view_->GetHeightForWidth(content_width); | 376 int top_height = top_view_->GetHeightForWidth(content_width); |
377 int bottom_height = bottom_view_->GetHeightForWidth(content_width); | 377 int bottom_height = bottom_view_->GetHeightForWidth(content_width); |
378 | 378 |
379 // <http://crbug.com/230448> Fix: Adjust the height when the message_view's | 379 // <http://crbug.com/230448> Fix: Adjust the height when the message_view's |
380 // line limit would be different for the specified width than it currently is. | 380 // line limit would be different for the specified width than it currently is. |
381 // TODO(dharcourt): Avoid BoxLayout and directly compute the correct height. | 381 // TODO(dharcourt): Avoid BoxLayout and directly compute the correct height. |
382 if (message_view_) { | 382 if (message_view_) { |
383 int title_lines = 0; | 383 int title_lines = 0; |
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
721 bottom_view_->AddChildView(separator); | 721 bottom_view_->AddChildView(separator); |
722 NotificationButton* button = new NotificationButton(this); | 722 NotificationButton* button = new NotificationButton(this); |
723 ButtonInfo button_info = buttons[i]; | 723 ButtonInfo button_info = buttons[i]; |
724 button->SetTitle(button_info.title); | 724 button->SetTitle(button_info.title); |
725 button->SetIcon(button_info.icon.AsImageSkia()); | 725 button->SetIcon(button_info.icon.AsImageSkia()); |
726 action_buttons_.push_back(button); | 726 action_buttons_.push_back(button); |
727 bottom_view_->AddChildView(button); | 727 bottom_view_->AddChildView(button); |
728 } | 728 } |
729 } | 729 } |
730 | 730 |
731 int NotificationView::GetMessageLineLimit(int title_lines, int width) { | 731 int NotificationView::GetMessageLineLimit(int title_lines, int width) const { |
732 // Image notifications require that the image must be kept flush against | 732 // Image notifications require that the image must be kept flush against |
733 // their icons, but we can allow more text if no image. | 733 // their icons, but we can allow more text if no image. |
734 int effective_title_lines = std::max(0, title_lines - 1); | 734 int effective_title_lines = std::max(0, title_lines - 1); |
735 int line_reduction_from_title = (image_view_ ? 1 : 2) * effective_title_lines; | 735 int line_reduction_from_title = (image_view_ ? 1 : 2) * effective_title_lines; |
736 if (!image_view_) { | 736 if (!image_view_) { |
737 // Title lines are counted as twice as big as message lines for the purpose | 737 // Title lines are counted as twice as big as message lines for the purpose |
738 // of this calculation. | 738 // of this calculation. |
739 // The effect from the title reduction here should be: | 739 // The effect from the title reduction here should be: |
740 // * 0 title lines: 5 max lines message. | 740 // * 0 title lines: 5 max lines message. |
741 // * 1 title line: 5 max lines message. | 741 // * 1 title line: 5 max lines message. |
(...skipping 15 matching lines...) Expand all Loading... |
757 // The effect from the title reduction here should be: | 757 // The effect from the title reduction here should be: |
758 // * 0 title lines: 2 max lines message + context message. | 758 // * 0 title lines: 2 max lines message + context message. |
759 // * 1 title line: 2 max lines message + context message. | 759 // * 1 title line: 2 max lines message + context message. |
760 // * 2 title lines: 1 max lines message + context message. | 760 // * 2 title lines: 1 max lines message + context message. |
761 message_line_limit = | 761 message_line_limit = |
762 std::max(0, message_line_limit - line_reduction_from_title); | 762 std::max(0, message_line_limit - line_reduction_from_title); |
763 | 763 |
764 return message_line_limit; | 764 return message_line_limit; |
765 } | 765 } |
766 | 766 |
767 int NotificationView::GetMessageHeight(int width, int limit) { | 767 int NotificationView::GetMessageHeight(int width, int limit) const { |
768 return message_view_ ? | 768 return message_view_ ? |
769 message_view_->GetSizeForWidthAndLines(width, limit).height() : 0; | 769 message_view_->GetSizeForWidthAndLines(width, limit).height() : 0; |
770 } | 770 } |
771 | 771 |
772 } // namespace message_center | 772 } // namespace message_center |
OLD | NEW |