Chromium Code Reviews| Index: ui/message_center/message_center_bubble.cc |
| diff --git a/ui/message_center/message_center_bubble.cc b/ui/message_center/message_center_bubble.cc |
| index 8cf507ad610a2c78e77364a8c2d7264f1363f0ca..f22302c68914be42da942154afd31dc966c9b4fe 100644 |
| --- a/ui/message_center/message_center_bubble.cc |
| +++ b/ui/message_center/message_center_bubble.cc |
| @@ -236,10 +236,13 @@ class WebNotificationButtonView2 : public WebNotificationButtonViewBase, |
| DISALLOW_COPY_AND_ASSIGN(WebNotificationButtonView2); |
| }; |
| -// A custom scroll-view that has a specified size. |
| -class FixedSizedScrollView : public views::ScrollView { |
| +// A custom scroll view whose height has a minimum and maximum value and whose |
| +// scroll bar disappears when not needed. |
| +class BoundedScrollView : public views::ScrollView { |
| public: |
| - FixedSizedScrollView() { |
| + BoundedScrollView(int min_height, int max_height) |
| + : min_height_(min_height), |
| + max_height_(max_height) { |
| set_focusable(true); |
| set_notify_enter_exit_on_child(true); |
| if (IsRichNotificationEnabled()) { |
| @@ -248,53 +251,52 @@ class FixedSizedScrollView : public views::ScrollView { |
| } |
| } |
| - virtual ~FixedSizedScrollView() {} |
| - |
| - void SetFixedSize(const gfx::Size& size) { |
| - if (fixed_size_ == size) |
| - return; |
| - fixed_size_ = size; |
| - PreferredSizeChanged(); |
| - } |
| + virtual ~BoundedScrollView() {} |
| // views::View overrides. |
| virtual gfx::Size GetPreferredSize() OVERRIDE { |
| - gfx::Size size = fixed_size_.IsEmpty() ? |
| - contents()->GetPreferredSize() : fixed_size_; |
| + gfx::Size size = contents()->GetPreferredSize(); |
| + size.ClampToMin(gfx::Size(size.width(), min_height_)); |
| + size.ClampToMax(gfx::Size(size.width(), max_height_)); |
| gfx::Insets insets = GetInsets(); |
| size.Enlarge(insets.width(), insets.height()); |
| return size; |
| } |
| virtual void Layout() OVERRIDE { |
| - gfx::Rect bounds = gfx::Rect(contents()->GetPreferredSize()); |
| - bounds.set_width(std::max(0, width() - GetScrollBarWidth())); |
| - contents()->SetBoundsRect(bounds); |
| - |
| + // Lay out the view as if it will have a scroll bar. |
| + gfx::Rect content_bounds = gfx::Rect(contents()->GetPreferredSize()); |
| + content_bounds.set_width(std::max(0, width() - GetScrollBarWidth())); |
| + contents()->SetBoundsRect(content_bounds); |
| views::ScrollView::Layout(); |
| + |
| + // But use the scroll bar space if no scroll bar is needed. |
| if (!vertical_scroll_bar()->visible()) { |
| - gfx::Rect bounds = contents()->bounds(); |
| - bounds.set_width(bounds.width() + GetScrollBarWidth()); |
| - contents()->SetBoundsRect(bounds); |
| + content_bounds = contents()->bounds(); |
| + content_bounds.set_width(content_bounds.width() + GetScrollBarWidth()); |
| + contents()->SetBoundsRect(content_bounds); |
| } |
| } |
| virtual void OnBoundsChanged(const gfx::Rect& previous_bounds) OVERRIDE { |
| - gfx::Rect bounds = gfx::Rect(contents()->GetPreferredSize()); |
| - bounds.set_width(std::max(0, width() - GetScrollBarWidth())); |
| - contents()->SetBoundsRect(bounds); |
| + // Make sure any content resizing takes into account the scroll bar. |
| + gfx::Rect content_bounds = gfx::Rect(contents()->GetPreferredSize()); |
| + content_bounds.set_width(std::max(0, width() - GetScrollBarWidth())); |
| + contents()->SetBoundsRect(content_bounds); |
| } |
| private: |
| - gfx::Size fixed_size_; |
| + int min_height_; |
| + int max_height_; |
| - DISALLOW_COPY_AND_ASSIGN(FixedSizedScrollView); |
| + DISALLOW_COPY_AND_ASSIGN(BoundedScrollView); |
| }; |
| // Container for the messages. |
| -class ScrollContentView : public views::View { |
| +class MessagesView : public views::View { |
|
Jun Mukai
2013/02/26 02:23:30
I think it's too hard to distinguish this from mes
dharcourt
2013/02/26 03:23:30
Good point. What would you think of MessageListVie
|
| public: |
| - ScrollContentView() { |
| + MessagesView(views::View *message_center_view) |
| + : message_center_view_(message_center_view) { |
| if (IsRichNotificationEnabled()) { |
| // Set the margin to 0 for the layout. BoxLayout assumes the same margin |
| // for top and bottom, but the bottom margin here should be smaller |
| @@ -321,20 +323,22 @@ class ScrollContentView : public views::View { |
| } |
| } |
| - virtual ~ScrollContentView() { |
| + virtual ~MessagesView() { |
| } |
| - virtual gfx::Size GetPreferredSize() OVERRIDE { |
| - if (!preferred_size_.IsEmpty()) |
| - return preferred_size_; |
| - return views::View::GetPreferredSize(); |
| + protected: |
| + // views::View overrides. |
| + virtual void ChildPreferredSizeChanged(views::View* child) OVERRIDE { |
| + // Since the parent of this view is a Viewport and since Viewports ignore |
| + // ChildPreferredSizeChanged() calls, ask the MessageCenterView directly |
| + // to update its layout for the preferred size change. |
| + message_center_view_->Layout(); |
| } |
| - void set_preferred_size(const gfx::Size& size) { preferred_size_ = size; } |
| - |
| private: |
| - gfx::Size preferred_size_; |
| - DISALLOW_COPY_AND_ASSIGN(ScrollContentView); |
| + views::View *message_center_view_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(MessagesView); |
| }; |
| // A border to provide the shadow for each card. |
| @@ -368,21 +372,27 @@ class MessageViewShadowBorder : public views::Border { |
| } // namespace |
| -// Message Center contents. |
| -class MessageCenterContentsView : public views::View { |
| +// View that displays the whole message center. |
| +class MessageCenterView : public views::View { |
| public: |
| - explicit MessageCenterContentsView(MessageCenterBubble* bubble, |
| - NotificationList::Delegate* list_delegate) |
| + explicit MessageCenterView(MessageCenterBubble* bubble, |
| + NotificationList::Delegate* list_delegate) |
| : list_delegate_(list_delegate), |
| bubble_(bubble) { |
| int between_child = IsRichNotificationEnabled() ? 0 : 1; |
| SetLayoutManager( |
| new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, between_child)); |
| - scroll_content_ = new ScrollContentView; |
| - scroller_ = new FixedSizedScrollView; |
| - scroller_->SetContents(scroll_content_); |
| - AddChildView(scroller_); |
| + |
| + if (IsRichNotificationEnabled()) |
| + button_view_ = new WebNotificationButtonView2(list_delegate); |
| + else |
| + button_view_ = new WebNotificationButtonView(list_delegate); |
|
dharcourt
2013/02/23 04:32:00
Button creation had to be moved up in this method
|
| + |
| + const int button_height = button_view_->GetPreferredSize().height(); |
| + const int min_height = kMessageBubbleBaseMinHeight - button_height; |
| + const int max_height = bubble_->max_height() - button_height; |
| + scroller_ = new BoundedScrollView(min_height, max_height); |
| if (get_use_acceleration_when_possible()) { |
| scroller_->SetPaintToLayer(true); |
| @@ -390,10 +400,10 @@ class MessageCenterContentsView : public views::View { |
| scroller_->layer()->SetMasksToBounds(true); |
| } |
| - if (IsRichNotificationEnabled()) |
| - button_view_ = new WebNotificationButtonView2(list_delegate); |
| - else |
| - button_view_ = new WebNotificationButtonView(list_delegate); |
| + messages_view_ = new MessagesView(this); |
| + scroller_->SetContents(messages_view_); |
| + |
| + AddChildView(scroller_); |
| AddChildView(button_view_); |
| } |
| @@ -402,18 +412,16 @@ class MessageCenterContentsView : public views::View { |
| } |
| void Update(const NotificationList::Notifications& notifications) { |
| - scroll_content_->RemoveAllChildViews(true); |
| - scroll_content_->set_preferred_size(gfx::Size()); |
| + messages_view_->RemoveAllChildViews(true); |
| size_t num_children = 0; |
| for (NotificationList::Notifications::const_iterator iter = |
| notifications.begin(); iter != notifications.end(); ++iter) { |
| MessageView* view = |
| NotificationView::ViewForNotification(*iter, list_delegate_); |
| view->set_scroller(scroller_); |
|
dharcourt
2013/02/23 04:32:00
SetUpView() is now avoided as MessageView and all
|
| - view->SetUpView(); |
| if (IsRichNotificationEnabled()) |
| view->set_border(new MessageViewShadowBorder()); |
| - scroll_content_->AddChildView(view); |
| + messages_view_->AddChildView(view); |
| if (++num_children >= |
| NotificationList::kMaxVisibleMessageCenterNotifications) { |
| break; |
| @@ -427,48 +435,38 @@ class MessageCenterContentsView : public views::View { |
| // Set transparent background to ensure that subpixel rendering |
| // is disabled. See crbug.com/169056 |
| label->SetBackgroundColor(kTransparentColor); |
| - scroll_content_->AddChildView(label); |
| + messages_view_->AddChildView(label); |
| button_view_->SetCloseAllVisible(false); |
| scroller_->set_focusable(false); |
| } else { |
| button_view_->SetCloseAllVisible(true); |
| scroller_->set_focusable(true); |
| } |
| - SizeScrollContent(); |
| Layout(); |
| - if (GetWidget()) |
| - GetWidget()->GetRootView()->SchedulePaint(); |
| } |
| size_t NumMessageViews() const { |
| - return scroll_content_->child_count(); |
| + return messages_view_->child_count(); |
| } |
| - private: |
| - void SizeScrollContent() { |
| - gfx::Size scroll_size = scroll_content_->GetPreferredSize(); |
| - const int button_height = button_view_->GetPreferredSize().height(); |
| - const int min_height = kMessageBubbleBaseMinHeight - button_height; |
| - const int max_height = bubble_->max_height() - button_height; |
| - int scroll_height = std::min(std::max( |
| - scroll_size.height(), min_height), max_height); |
| - scroll_size.set_height(scroll_height); |
| - if (scroll_height == min_height) |
| - scroll_content_->set_preferred_size(scroll_size); |
| - else |
| - scroll_content_->set_preferred_size(gfx::Size()); |
| - scroller_->SetFixedSize(scroll_size); |
| + protected: |
| + // views::View overrides. |
| + virtual void Layout() OVERRIDE { |
| scroller_->SizeToPreferredSize(); |
| - scroll_content_->InvalidateLayout(); |
| + views::View::Layout(); |
| + if (GetWidget()) |
| + GetWidget()->GetRootView()->SchedulePaint(); |
| + bubble_->bubble_view()->UpdateBubble(); |
| } |
| + private: |
| NotificationList::Delegate* list_delegate_; |
| - FixedSizedScrollView* scroller_; |
| - ScrollContentView* scroll_content_; |
| + BoundedScrollView* scroller_; |
| + MessagesView* messages_view_; |
| WebNotificationButtonViewBase* button_view_; |
| MessageCenterBubble* bubble_; |
| - DISALLOW_COPY_AND_ASSIGN(MessageCenterContentsView); |
| + DISALLOW_COPY_AND_ASSIGN(MessageCenterView); |
| }; |
| // Message Center Bubble. |
| @@ -495,7 +493,7 @@ views::TrayBubbleView::InitParams MessageCenterBubble::GetInitParams( |
| void MessageCenterBubble::InitializeContents( |
| views::TrayBubbleView* new_bubble_view) { |
| set_bubble_view(new_bubble_view); |
| - contents_view_ = new MessageCenterContentsView(this, list_delegate()); |
| + contents_view_ = new MessageCenterView(this, list_delegate()); |
| bubble_view()->AddChildView(contents_view_); |
| UpdateBubbleView(); |
| contents_view_->FocusContents(); |