Update path of checkdeps to buildtools checkout
[chromium-blink-merge.git] / ui / message_center / views / message_center_bubble.cc
blob7189d2749005db82ec521658dfb9d44254ac0795
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
3 // found in the LICENSE file.
5 #include "ui/message_center/views/message_center_bubble.h"
7 #include "ui/message_center/message_center_style.h"
8 #include "ui/message_center/views/message_center_view.h"
9 #include "ui/views/layout/fill_layout.h"
10 #include "ui/views/widget/widget.h"
12 namespace message_center {
14 // ContentsView ////////////////////////////////////////////////////////////////
16 // Handles changes in MessageCenterView sizes.
17 class ContentsView : public views::View {
18 public:
19 explicit ContentsView(MessageCenterBubble* bubble, views::View* contents);
20 virtual ~ContentsView();
22 // Overridden from views::View:
23 virtual int GetHeightForWidth(int width) const OVERRIDE;
25 protected:
26 // Overridden from views::View:
27 virtual void ChildPreferredSizeChanged(View* child) OVERRIDE;
29 private:
30 base::WeakPtr<MessageCenterBubble> bubble_;
32 DISALLOW_COPY_AND_ASSIGN(ContentsView);
35 ContentsView::ContentsView(MessageCenterBubble* bubble, views::View* contents)
36 : bubble_(bubble->AsWeakPtr()) {
37 SetLayoutManager(new views::FillLayout());
38 AddChildView(contents);
41 ContentsView::~ContentsView() {
44 int ContentsView::GetHeightForWidth(int width) const {
45 DCHECK_EQ(1, child_count());
46 int contents_width = std::max(width - GetInsets().width(), 0);
47 int contents_height = child_at(0)->GetHeightForWidth(contents_width);
48 return contents_height + GetInsets().height();
51 void ContentsView::ChildPreferredSizeChanged(View* child) {
52 // TODO(dharcourt): Reduce the amount of updating this requires.
53 if (bubble_.get())
54 bubble_->bubble_view()->UpdateBubble();
57 // MessageCenterBubble /////////////////////////////////////////////////////////
59 MessageCenterBubble::MessageCenterBubble(MessageCenter* message_center,
60 MessageCenterTray* tray,
61 bool first_item_has_no_margin)
62 : MessageBubbleBase(message_center, tray),
63 message_center_view_(NULL),
64 initially_settings_visible_(false),
65 first_item_has_no_margin_(first_item_has_no_margin) {
68 MessageCenterBubble::~MessageCenterBubble() {
71 void MessageCenterBubble::SetSettingsVisible() {
72 if (message_center_view_)
73 message_center_view_->SetSettingsVisible(true);
74 else
75 initially_settings_visible_ = true;
78 views::TrayBubbleView::InitParams MessageCenterBubble::GetInitParams(
79 views::TrayBubbleView::AnchorAlignment anchor_alignment) {
80 views::TrayBubbleView::InitParams init_params =
81 GetDefaultInitParams(anchor_alignment);
82 init_params.min_width += kMarginBetweenItems * 2;
83 init_params.max_width += kMarginBetweenItems * 2;
84 init_params.max_height = max_height();
85 init_params.can_activate = true;
86 init_params.first_item_has_no_margin = first_item_has_no_margin_;
87 return init_params;
90 void MessageCenterBubble::InitializeContents(
91 views::TrayBubbleView* new_bubble_view) {
92 set_bubble_view(new_bubble_view);
93 bubble_view()->GetWidget()->AddObserver(this);
94 message_center_view_ = new MessageCenterView(
95 message_center(),
96 tray(),
97 max_height(),
98 initially_settings_visible_,
99 false /* MessageCenterBubble should be used only on ChromeOS.
100 Message center is never shown top down in ChromeOS. */);
101 bubble_view()->AddChildView(new ContentsView(this, message_center_view_));
102 // Resize the content of the bubble view to the given bubble size. This is
103 // necessary in case of the bubble border forcing a bigger size then the
104 // |new_bubble_view| actually wants. See crbug.com/169390.
105 bubble_view()->Layout();
106 UpdateBubbleView();
109 void MessageCenterBubble::OnBubbleViewDestroyed() {
110 message_center_view_ = NULL;
113 void MessageCenterBubble::UpdateBubbleView() {
114 if (!bubble_view())
115 return; // Could get called after view is closed
116 const NotificationList::Notifications& notifications =
117 message_center()->GetVisibleNotifications();
118 message_center_view_->SetNotifications(notifications);
119 bubble_view()->GetWidget()->Show();
120 bubble_view()->UpdateBubble();
123 void MessageCenterBubble::OnWidgetClosing(views::Widget* widget) {
124 bubble_view()->GetWidget()->RemoveObserver(this);
125 if (message_center_view_)
126 message_center_view_->SetIsClosing(true);
129 void MessageCenterBubble::OnMouseEnteredView() {
132 void MessageCenterBubble::OnMouseExitedView() {
135 size_t MessageCenterBubble::NumMessageViewsForTest() const {
136 return message_center_view_->NumMessageViewsForTest();
139 } // namespace message_center