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

Unified Diff: ash/system/web_notification/message_center_bubble.cc

Issue 11229022: Move ash/system/web_notification message_center to ui/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase again. Created 8 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ash/system/web_notification/message_center_bubble.h ('k') | ash/system/web_notification/popup_bubble.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ash/system/web_notification/message_center_bubble.cc
diff --git a/ash/system/web_notification/message_center_bubble.cc b/ash/system/web_notification/message_center_bubble.cc
deleted file mode 100644
index 316ea6dcffc27c5616f72914fa3fef553992f438..0000000000000000000000000000000000000000
--- a/ash/system/web_notification/message_center_bubble.cc
+++ /dev/null
@@ -1,304 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "ash/system/web_notification/message_center_bubble.h"
-
-#include "ash/system/web_notification/web_notification_view.h"
-#include "grit/ash_strings.h"
-#include "ui/base/l10n/l10n_util.h"
-#include "ui/base/resource/resource_bundle.h"
-#include "ui/gfx/size.h"
-#include "ui/views/controls/button/text_button.h"
-#include "ui/views/controls/label.h"
-#include "ui/views/controls/scroll_view.h"
-#include "ui/views/layout/box_layout.h"
-#include "ui/views/layout/grid_layout.h"
-#include "ui/views/painter.h"
-#include "ui/views/view.h"
-#include "ui/views/widget/widget.h"
-
-namespace message_center {
-
-namespace {
-
-const int kWebNotificationBubbleMinHeight = 80;
-const int kWebNotificationBubbleMaxHeight = 400;
-const SkColor kBorderDarkColor = SkColorSetRGB(0xaa, 0xaa, 0xaa);
-
-// The view for the buttons at the bottom of the web notification tray.
-class WebNotificationButtonView : public views::View,
- public views::ButtonListener {
- public:
- explicit WebNotificationButtonView(
- WebNotificationList::Delegate* list_delegate)
- : list_delegate_(list_delegate),
- close_all_button_(NULL) {
- set_background(views::Background::CreateBackgroundPainter(
- true,
- views::Painter::CreateVerticalGradient(
- WebNotificationBubble::kHeaderBackgroundColorLight,
- WebNotificationBubble::kHeaderBackgroundColorDark)));
- set_border(views::Border::CreateSolidSidedBorder(
- 2, 0, 0, 0, kBorderDarkColor));
-
- views::GridLayout* layout = new views::GridLayout(this);
- SetLayoutManager(layout);
- views::ColumnSet* columns = layout->AddColumnSet(0);
- columns->AddPaddingColumn(100, 0);
- columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER,
- 0, /* resize percent */
- views::GridLayout::USE_PREF, 0, 0);
- columns->AddPaddingColumn(0, 4);
-
- ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
- close_all_button_ = new views::TextButton(
- this, rb.GetLocalizedString(IDS_ASH_WEB_NOTFICATION_TRAY_CLEAR_ALL));
- close_all_button_->set_alignment(views::TextButton::ALIGN_CENTER);
- close_all_button_->set_focusable(true);
- close_all_button_->set_request_focus_on_press(false);
-
- layout->AddPaddingRow(0, 4);
- layout->StartRow(0, 0);
- layout->AddView(close_all_button_);
- }
-
- virtual ~WebNotificationButtonView() {}
-
- void SetCloseAllVisible(bool visible) {
- close_all_button_->SetVisible(visible);
- }
-
- // Overridden from ButtonListener.
- virtual void ButtonPressed(views::Button* sender,
- const ui::Event& event) OVERRIDE {
- if (sender == close_all_button_)
- list_delegate_->SendRemoveAllNotifications();
- }
-
- private:
- WebNotificationList::Delegate* list_delegate_;
- views::TextButton* close_all_button_;
-
- DISALLOW_COPY_AND_ASSIGN(WebNotificationButtonView);
-};
-
-// A custom scroll-view that has a specified size.
-class FixedSizedScrollView : public views::ScrollView {
- public:
- FixedSizedScrollView() {
- set_focusable(true);
- set_notify_enter_exit_on_child(true);
- }
-
- virtual ~FixedSizedScrollView() {}
-
- void SetFixedSize(const gfx::Size& size) {
- if (fixed_size_ == size)
- return;
- fixed_size_ = size;
- PreferredSizeChanged();
- }
-
- // views::View overrides.
- virtual gfx::Size GetPreferredSize() OVERRIDE {
- gfx::Size size = fixed_size_.IsEmpty() ?
- GetContents()->GetPreferredSize() : fixed_size_;
- gfx::Insets insets = GetInsets();
- size.Enlarge(insets.width(), insets.height());
- return size;
- }
-
- virtual void Layout() OVERRIDE {
- views::View* contents = GetContents();
- gfx::Rect bounds = gfx::Rect(contents->GetPreferredSize());
- bounds.set_width(std::max(0, width() - GetScrollBarWidth()));
- contents->SetBoundsRect(bounds);
-
- views::ScrollView::Layout();
- if (!vertical_scroll_bar()->visible()) {
- gfx::Rect bounds = contents->bounds();
- bounds.set_width(bounds.width() + GetScrollBarWidth());
- contents->SetBoundsRect(bounds);
- }
- }
-
- virtual void OnBoundsChanged(const gfx::Rect& previous_bounds) OVERRIDE {
- views::View* contents = GetContents();
- gfx::Rect bounds = gfx::Rect(contents->GetPreferredSize());
- bounds.set_width(std::max(0, width() - GetScrollBarWidth()));
- contents->SetBoundsRect(bounds);
- }
-
- private:
- gfx::Size fixed_size_;
-
- DISALLOW_COPY_AND_ASSIGN(FixedSizedScrollView);
-};
-
-// Container for the messages.
-class ScrollContentView : public views::View {
- public:
- ScrollContentView() {
- views::BoxLayout* layout =
- new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 1);
- layout->set_spread_blank_space(true);
- SetLayoutManager(layout);
- }
-
- virtual ~ScrollContentView() {
- }
-
- virtual gfx::Size GetPreferredSize() OVERRIDE {
- if (!preferred_size_.IsEmpty())
- return preferred_size_;
- return views::View::GetPreferredSize();
- }
-
- void set_preferred_size(const gfx::Size& size) { preferred_size_ = size; }
-
- private:
- gfx::Size preferred_size_;
- DISALLOW_COPY_AND_ASSIGN(ScrollContentView);
-};
-
-} // namespace
-
-// Message Center contents.
-class MessageCenterContentsView : public views::View {
- public:
- explicit MessageCenterContentsView(
- WebNotificationList::Delegate* list_delegate)
- : list_delegate_(list_delegate) {
- SetLayoutManager(
- new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 1));
-
- scroll_content_ = new ScrollContentView;
- scroller_ = new FixedSizedScrollView;
- scroller_->SetContents(scroll_content_);
- AddChildView(scroller_);
-
- scroller_->SetPaintToLayer(true);
- scroller_->SetFillsBoundsOpaquely(false);
- scroller_->layer()->SetMasksToBounds(true);
-
- button_view_ = new WebNotificationButtonView(list_delegate);
- AddChildView(button_view_);
- }
-
- void FocusContents() {
- scroller_->RequestFocus();
- }
-
- void Update(const WebNotificationList::Notifications& notifications) {
- scroll_content_->RemoveAllChildViews(true);
- scroll_content_->set_preferred_size(gfx::Size());
- size_t num_children = 0;
- for (WebNotificationList::Notifications::const_iterator iter =
- notifications.begin(); iter != notifications.end(); ++iter) {
- WebNotificationView* view = new WebNotificationView(
- list_delegate_, *iter, scroller_->GetScrollBarWidth());
- view->set_scroller(scroller_);
- scroll_content_->AddChildView(view);
- if (++num_children >=
- WebNotificationList::kMaxVisibleMessageCenterNotifications) {
- break;
- }
- }
- if (num_children == 0) {
- views::Label* label = new views::Label(l10n_util::GetStringUTF16(
- IDS_ASH_WEB_NOTFICATION_TRAY_NO_MESSAGES));
- label->SetFont(label->font().DeriveFont(1));
- label->SetHorizontalAlignment(views::Label::ALIGN_CENTER);
- label->SetEnabledColor(SK_ColorGRAY);
- scroll_content_->AddChildView(label);
- button_view_->SetCloseAllVisible(false);
- } else {
- button_view_->SetCloseAllVisible(true);
- }
- SizeScrollContent();
- Layout();
- if (GetWidget())
- GetWidget()->GetRootView()->SchedulePaint();
- }
-
- size_t NumMessageViews() const {
- return scroll_content_->child_count();
- }
-
- private:
- void SizeScrollContent() {
- gfx::Size scroll_size = scroll_content_->GetPreferredSize();
- const int button_height = button_view_->GetPreferredSize().height();
- const int min_height = kWebNotificationBubbleMinHeight - button_height;
- const int max_height = kWebNotificationBubbleMaxHeight - 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);
- scroller_->SizeToPreferredSize();
- scroll_content_->InvalidateLayout();
- }
-
- WebNotificationList::Delegate* list_delegate_;
- FixedSizedScrollView* scroller_;
- ScrollContentView* scroll_content_;
- WebNotificationButtonView* button_view_;
-
- DISALLOW_COPY_AND_ASSIGN(MessageCenterContentsView);
-};
-
-// Message Center Bubble.
-MessageCenterBubble::MessageCenterBubble(
- WebNotificationList::Delegate* delegate)
- : WebNotificationBubble(delegate),
- contents_view_(NULL) {
-}
-
-MessageCenterBubble::~MessageCenterBubble() {}
-
-TrayBubbleView::InitParams MessageCenterBubble::GetInitParams(
- TrayBubbleView::AnchorAlignment anchor_alignment) {
- TrayBubbleView::InitParams init_params =
- GetDefaultInitParams(anchor_alignment);
- init_params.max_height = message_center::kWebNotificationBubbleMaxHeight;
- init_params.can_activate = true;
- return init_params;
-}
-
-void MessageCenterBubble::InitializeContents(TrayBubbleView* bubble_view) {
- bubble_view_ = bubble_view;
- contents_view_ = new MessageCenterContentsView(list_delegate_);
- bubble_view_->AddChildView(contents_view_);
- UpdateBubbleView();
- contents_view_->FocusContents();
-}
-
-void MessageCenterBubble::OnBubbleViewDestroyed() {
- contents_view_ = NULL;
-}
-
-void MessageCenterBubble::UpdateBubbleView() {
- if (!bubble_view_)
- return; // Could get called after view is closed
- contents_view_->Update(
- list_delegate_->GetNotificationList()->notifications());
- bubble_view_->Show();
- bubble_view_->UpdateBubble();
-}
-
-void MessageCenterBubble::OnMouseEnteredView() {
-}
-
-void MessageCenterBubble::OnMouseExitedView() {
-}
-
-size_t MessageCenterBubble::NumMessageViewsForTest() const {
- return contents_view_->NumMessageViews();
-}
-
-} // namespace message_center
« no previous file with comments | « ash/system/web_notification/message_center_bubble.h ('k') | ash/system/web_notification/popup_bubble.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698