Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1001)

Side by Side Diff: ui/message_center/views/message_center_view.cc

Issue 273223002: views: Make view::Views::GetPreferredSize() const. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: More compile fix for ToT Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/message_center_view.h" 5 #include "ui/message_center/views/message_center_view.h"
6 6
7 #include <list> 7 #include <list>
8 #include <map> 8 #include <map>
9 9
10 #include "base/memory/weak_ptr.h" 10 #include "base/memory/weak_ptr.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 const int kDefaultAnimationDurationMs = 120; 54 const int kDefaultAnimationDurationMs = 120;
55 const int kDefaultFrameRateHz = 60; 55 const int kDefaultFrameRateHz = 60;
56 } // namespace 56 } // namespace
57 57
58 class NoNotificationMessageView : public views::View { 58 class NoNotificationMessageView : public views::View {
59 public: 59 public:
60 NoNotificationMessageView(); 60 NoNotificationMessageView();
61 virtual ~NoNotificationMessageView(); 61 virtual ~NoNotificationMessageView();
62 62
63 // Overridden from views::View. 63 // Overridden from views::View.
64 virtual gfx::Size GetPreferredSize() OVERRIDE; 64 virtual gfx::Size GetPreferredSize() const OVERRIDE;
65 virtual int GetHeightForWidth(int width) OVERRIDE; 65 virtual int GetHeightForWidth(int width) const OVERRIDE;
66 virtual void Layout() OVERRIDE; 66 virtual void Layout() OVERRIDE;
67 67
68 private: 68 private:
69 views::Label* label_; 69 views::Label* label_;
70 70
71 DISALLOW_COPY_AND_ASSIGN(NoNotificationMessageView); 71 DISALLOW_COPY_AND_ASSIGN(NoNotificationMessageView);
72 }; 72 };
73 73
74 NoNotificationMessageView::NoNotificationMessageView() { 74 NoNotificationMessageView::NoNotificationMessageView() {
75 label_ = new views::Label(l10n_util::GetStringUTF16( 75 label_ = new views::Label(l10n_util::GetStringUTF16(
76 IDS_MESSAGE_CENTER_NO_MESSAGES)); 76 IDS_MESSAGE_CENTER_NO_MESSAGES));
77 label_->SetAutoColorReadabilityEnabled(false); 77 label_->SetAutoColorReadabilityEnabled(false);
78 label_->SetEnabledColor(kNoNotificationsTextColor); 78 label_->SetEnabledColor(kNoNotificationsTextColor);
79 // Set transparent background to ensure that subpixel rendering 79 // Set transparent background to ensure that subpixel rendering
80 // is disabled. See crbug.com/169056 80 // is disabled. See crbug.com/169056
81 #if defined(OS_LINUX) && defined(OS_CHROMEOS) 81 #if defined(OS_LINUX) && defined(OS_CHROMEOS)
82 label_->SetBackgroundColor(kTransparentColor); 82 label_->SetBackgroundColor(kTransparentColor);
83 #endif 83 #endif
84 AddChildView(label_); 84 AddChildView(label_);
85 } 85 }
86 86
87 NoNotificationMessageView::~NoNotificationMessageView() { 87 NoNotificationMessageView::~NoNotificationMessageView() {
88 } 88 }
89 89
90 gfx::Size NoNotificationMessageView::GetPreferredSize() { 90 gfx::Size NoNotificationMessageView::GetPreferredSize() const {
91 return gfx::Size(kMinScrollViewHeight, label_->GetPreferredSize().width()); 91 return gfx::Size(kMinScrollViewHeight, label_->GetPreferredSize().width());
92 } 92 }
93 93
94 int NoNotificationMessageView::GetHeightForWidth(int width) { 94 int NoNotificationMessageView::GetHeightForWidth(int width) const {
95 return kMinScrollViewHeight; 95 return kMinScrollViewHeight;
96 } 96 }
97 97
98 void NoNotificationMessageView::Layout() { 98 void NoNotificationMessageView::Layout() {
99 int text_height = label_->GetHeightForWidth(width()); 99 int text_height = label_->GetHeightForWidth(width());
100 int margin = (height() - text_height) / 2; 100 int margin = (height() - text_height) / 2;
101 label_->SetBounds(0, margin, width(), text_height); 101 label_->SetBounds(0, margin, width(), text_height);
102 } 102 }
103 103
104 // Displays a list of messages for rich notifications. Functions as an array of 104 // Displays a list of messages for rich notifications. Functions as an array of
105 // MessageViews and animates them on transitions. It also supports 105 // MessageViews and animates them on transitions. It also supports
106 // repositioning. 106 // repositioning.
107 class MessageListView : public views::View, 107 class MessageListView : public views::View,
108 public views::BoundsAnimatorObserver { 108 public views::BoundsAnimatorObserver {
109 public: 109 public:
110 explicit MessageListView(MessageCenterView* message_center_view, 110 explicit MessageListView(MessageCenterView* message_center_view,
111 bool top_down); 111 bool top_down);
112 virtual ~MessageListView(); 112 virtual ~MessageListView();
113 113
114 void AddNotificationAt(MessageView* view, int i); 114 void AddNotificationAt(MessageView* view, int i);
115 void RemoveNotification(MessageView* view); 115 void RemoveNotification(MessageView* view);
116 void UpdateNotification(MessageView* view, const Notification& notification); 116 void UpdateNotification(MessageView* view, const Notification& notification);
117 void SetRepositionTarget(const gfx::Rect& target_rect); 117 void SetRepositionTarget(const gfx::Rect& target_rect);
118 void ResetRepositionSession(); 118 void ResetRepositionSession();
119 void ClearAllNotifications(const gfx::Rect& visible_scroll_rect); 119 void ClearAllNotifications(const gfx::Rect& visible_scroll_rect);
120 120
121 protected: 121 protected:
122 // Overridden from views::View. 122 // Overridden from views::View.
123 virtual void Layout() OVERRIDE; 123 virtual void Layout() OVERRIDE;
124 virtual gfx::Size GetPreferredSize() OVERRIDE; 124 virtual gfx::Size GetPreferredSize() const OVERRIDE;
125 virtual int GetHeightForWidth(int width) OVERRIDE; 125 virtual int GetHeightForWidth(int width) const OVERRIDE;
126 virtual void PaintChildren(gfx::Canvas* canvas, 126 virtual void PaintChildren(gfx::Canvas* canvas,
127 const views::CullSet& cull_set) OVERRIDE; 127 const views::CullSet& cull_set) OVERRIDE;
128 virtual void ReorderChildLayers(ui::Layer* parent_layer) OVERRIDE; 128 virtual void ReorderChildLayers(ui::Layer* parent_layer) OVERRIDE;
129 129
130 // Overridden from views::BoundsAnimatorObserver. 130 // Overridden from views::BoundsAnimatorObserver.
131 virtual void OnBoundsAnimatorProgressed( 131 virtual void OnBoundsAnimatorProgressed(
132 views::BoundsAnimator* animator) OVERRIDE; 132 views::BoundsAnimator* animator) OVERRIDE;
133 virtual void OnBoundsAnimatorDone(views::BoundsAnimator* animator) OVERRIDE; 133 virtual void OnBoundsAnimatorDone(views::BoundsAnimator* animator) OVERRIDE;
134 134
135 private: 135 private:
136 bool IsValidChild(views::View* child); 136 bool IsValidChild(const views::View* child) const;
137 void DoUpdateIfPossible(); 137 void DoUpdateIfPossible();
138 138
139 // Animates all notifications below target upwards to align with the top of 139 // Animates all notifications below target upwards to align with the top of
140 // the last closed notification. 140 // the last closed notification.
141 void AnimateNotificationsBelowTarget(); 141 void AnimateNotificationsBelowTarget();
142 // Animates all notifications above target downwards to align with the top of 142 // Animates all notifications above target downwards to align with the top of
143 // the last closed notification. 143 // the last closed notification.
144 void AnimateNotificationsAboveTarget(); 144 void AnimateNotificationsAboveTarget();
145 145
146 // Schedules animation for a child to the specified position. Returns false 146 // Schedules animation for a child to the specified position. Returns false
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 if (animator_.get()) 269 if (animator_.get())
270 animator_->StopAnimatingView(view); 270 animator_->StopAnimatingView(view);
271 if (deleting_views_.find(view) != deleting_views_.end()) 271 if (deleting_views_.find(view) != deleting_views_.end())
272 deleting_views_.erase(view); 272 deleting_views_.erase(view);
273 if (deleted_when_done_.find(view) != deleted_when_done_.end()) 273 if (deleted_when_done_.find(view) != deleted_when_done_.end())
274 deleted_when_done_.erase(view); 274 deleted_when_done_.erase(view);
275 view->UpdateWithNotification(notification); 275 view->UpdateWithNotification(notification);
276 DoUpdateIfPossible(); 276 DoUpdateIfPossible();
277 } 277 }
278 278
279 gfx::Size MessageListView::GetPreferredSize() { 279 gfx::Size MessageListView::GetPreferredSize() const {
280 int width = 0; 280 int width = 0;
281 for (int i = 0; i < child_count(); i++) { 281 for (int i = 0; i < child_count(); i++) {
282 views::View* child = child_at(i); 282 const views::View* child = child_at(i);
283 if (IsValidChild(child)) 283 if (IsValidChild(child))
284 width = std::max(width, child->GetPreferredSize().width()); 284 width = std::max(width, child->GetPreferredSize().width());
285 } 285 }
286 286
287 return gfx::Size(width + GetInsets().width(), 287 return gfx::Size(width + GetInsets().width(),
288 GetHeightForWidth(width + GetInsets().width())); 288 GetHeightForWidth(width + GetInsets().width()));
289 } 289 }
290 290
291 int MessageListView::GetHeightForWidth(int width) { 291 int MessageListView::GetHeightForWidth(int width) const {
292 if (fixed_height_ > 0) 292 if (fixed_height_ > 0)
293 return fixed_height_; 293 return fixed_height_;
294 294
295 width -= GetInsets().width(); 295 width -= GetInsets().width();
296 int height = 0; 296 int height = 0;
297 int padding = 0; 297 int padding = 0;
298 for (int i = 0; i < child_count(); ++i) { 298 for (int i = 0; i < child_count(); ++i) {
299 views::View* child = child_at(i); 299 const views::View* child = child_at(i);
300 if (!IsValidChild(child)) 300 if (!IsValidChild(child))
301 continue; 301 continue;
302 height += child->GetHeightForWidth(width) + padding; 302 height += child->GetHeightForWidth(width) + padding;
303 padding = kMarginBetweenItems - MessageView::GetShadowInsets().bottom(); 303 padding = kMarginBetweenItems - MessageView::GetShadowInsets().bottom();
304 } 304 }
305 305
306 return height + GetInsets().height(); 306 return height + GetInsets().height();
307 } 307 }
308 308
309 void MessageListView::PaintChildren(gfx::Canvas* canvas, 309 void MessageListView::PaintChildren(gfx::Canvas* canvas,
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 384
385 if (has_deferred_task_) { 385 if (has_deferred_task_) {
386 has_deferred_task_ = false; 386 has_deferred_task_ = false;
387 DoUpdateIfPossible(); 387 DoUpdateIfPossible();
388 } 388 }
389 389
390 if (GetWidget()) 390 if (GetWidget())
391 GetWidget()->SynthesizeMouseMoveEvent(); 391 GetWidget()->SynthesizeMouseMoveEvent();
392 } 392 }
393 393
394 bool MessageListView::IsValidChild(views::View* child) { 394 bool MessageListView::IsValidChild(const views::View* child) const {
395 return child->visible() && 395 return child->visible() &&
396 deleting_views_.find(child) == deleting_views_.end() && 396 deleting_views_.find(const_cast<views::View*>(child)) ==
397 deleted_when_done_.find(child) == deleted_when_done_.end(); 397 deleting_views_.end() &&
398 deleted_when_done_.find(const_cast<views::View*>(child)) ==
399 deleted_when_done_.end();
398 } 400 }
399 401
400 void MessageListView::DoUpdateIfPossible() { 402 void MessageListView::DoUpdateIfPossible() {
401 gfx::Rect child_area = GetContentsBounds(); 403 gfx::Rect child_area = GetContentsBounds();
402 if (child_area.IsEmpty()) 404 if (child_area.IsEmpty())
403 return; 405 return;
404 406
405 if (animator_.get() && animator_->IsAnimating()) { 407 if (animator_.get() && animator_->IsAnimating()) {
406 has_deferred_task_ = true; 408 has_deferred_task_ = true;
407 return; 409 return;
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
754 button_bar_->SchedulePaint(); 756 button_bar_->SchedulePaint();
755 } 757 }
756 button_bar_->SetBounds(0, 758 button_bar_->SetBounds(0,
757 top_down_ ? 0 : height() - button_height, 759 top_down_ ? 0 : height() - button_height,
758 width(), 760 width(),
759 button_height); 761 button_height);
760 if (GetWidget()) 762 if (GetWidget())
761 GetWidget()->GetRootView()->SchedulePaint(); 763 GetWidget()->GetRootView()->SchedulePaint();
762 } 764 }
763 765
764 gfx::Size MessageCenterView::GetPreferredSize() { 766 gfx::Size MessageCenterView::GetPreferredSize() const {
765 if (settings_transition_animation_ && 767 if (settings_transition_animation_ &&
766 settings_transition_animation_->is_animating()) { 768 settings_transition_animation_->is_animating()) {
767 int content_width = std::max(source_view_->GetPreferredSize().width(), 769 int content_width = std::max(source_view_->GetPreferredSize().width(),
768 target_view_->GetPreferredSize().width()); 770 target_view_->GetPreferredSize().width());
769 int width = std::max(content_width, 771 int width = std::max(content_width,
770 button_bar_->GetPreferredSize().width()); 772 button_bar_->GetPreferredSize().width());
771 return gfx::Size(width, GetHeightForWidth(width)); 773 return gfx::Size(width, GetHeightForWidth(width));
772 } 774 }
773 775
774 int width = 0; 776 int width = 0;
775 for (int i = 0; i < child_count(); ++i) { 777 for (int i = 0; i < child_count(); ++i) {
776 views::View* child = child_at(0); 778 const views::View* child = child_at(0);
777 if (child->visible()) 779 if (child->visible())
778 width = std::max(width, child->GetPreferredSize().width()); 780 width = std::max(width, child->GetPreferredSize().width());
779 } 781 }
780 return gfx::Size(width, GetHeightForWidth(width)); 782 return gfx::Size(width, GetHeightForWidth(width));
781 } 783 }
782 784
783 int MessageCenterView::GetHeightForWidth(int width) { 785 int MessageCenterView::GetHeightForWidth(int width) const {
784 if (settings_transition_animation_ && 786 if (settings_transition_animation_ &&
785 settings_transition_animation_->is_animating()) { 787 settings_transition_animation_->is_animating()) {
786 int content_height = target_height_; 788 int content_height = target_height_;
787 if (settings_transition_animation_->current_part_index() == 0) { 789 if (settings_transition_animation_->current_part_index() == 0) {
788 content_height = settings_transition_animation_->CurrentValueBetween( 790 content_height = settings_transition_animation_->CurrentValueBetween(
789 source_height_, target_height_); 791 source_height_, target_height_);
790 } 792 }
791 return button_bar_->GetHeightForWidth(width) + content_height; 793 return button_bar_->GetHeightForWidth(width) + content_height;
792 } 794 }
793 795
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
994 scroller_->InvalidateLayout(); 996 scroller_->InvalidateLayout();
995 PreferredSizeChanged(); 997 PreferredSizeChanged();
996 Layout(); 998 Layout();
997 } 999 }
998 1000
999 void MessageCenterView::SetNotificationViewForTest(MessageView* view) { 1001 void MessageCenterView::SetNotificationViewForTest(MessageView* view) {
1000 message_list_view_->AddNotificationAt(view, 0); 1002 message_list_view_->AddNotificationAt(view, 0);
1001 } 1003 }
1002 1004
1003 } // namespace message_center 1005 } // namespace message_center
OLDNEW
« no previous file with comments | « ui/message_center/views/message_center_view.h ('k') | ui/message_center/views/message_center_view_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698