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

Unified Diff: ui/message_center/views/message_center_view.cc

Issue 18247002: Remove the most obvious dead code from message center. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Pull out more code. Created 7 years, 6 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
Index: ui/message_center/views/message_center_view.cc
diff --git a/ui/message_center/views/message_center_view.cc b/ui/message_center/views/message_center_view.cc
index 92b79715c9479585c67fbacde4010607c13f6668..faaa2ef1044a6329192f24ad1838b5232727c836 100644
--- a/ui/message_center/views/message_center_view.cc
+++ b/ui/message_center/views/message_center_view.cc
@@ -61,63 +61,7 @@ const int kAnimateClearingNextNotificationDelayMS = 40;
static const int kDefaultFrameRateHz = 60;
static const int kDefaultAnimationDurationMs = 120;
-// PoorMessageCenterButtonBar //////////////////////////////////////////////////
-
-// The view for the buttons at the bottom of the message center window used
-// when kEnableRichNotifications is false (hence the "poor" in the name :-).
-class PoorMessageCenterButtonBar : public MessageCenterButtonBar,
- public views::ButtonListener {
- public:
- PoorMessageCenterButtonBar(MessageCenterView* message_center_view,
- MessageCenter* message_center);
-
- // Overridden from views::ButtonListener:
- virtual void ButtonPressed(views::Button* sender,
- const ui::Event& event) OVERRIDE;
-
- private:
- DISALLOW_COPY_AND_ASSIGN(PoorMessageCenterButtonBar);
-};
-
-PoorMessageCenterButtonBar::PoorMessageCenterButtonBar(
- MessageCenterView* message_center_view, MessageCenter* message_center)
- : MessageCenterButtonBar(message_center_view, message_center) {
- set_background(views::Background::CreateBackgroundPainter(
- true,
- views::Painter::CreateVerticalGradient(kBackgroundLightColor,
- kBackgroundDarkColor)));
- 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& resource_bundle = ui::ResourceBundle::GetSharedInstance();
- views::LabelButton* close_all_button = new views::LabelButton(
- this, resource_bundle.GetLocalizedString(IDS_MESSAGE_CENTER_CLEAR_ALL));
- close_all_button->SetHorizontalAlignment(gfx::ALIGN_CENTER);
- close_all_button->set_request_focus_on_press(false);
- close_all_button->SetTextColor(views::Button::STATE_NORMAL, kFooterTextColor);
- close_all_button->SetTextColor(views::Button::STATE_HOVERED,
- kButtonTextHoverColor);
-
- layout->AddPaddingRow(0, 4);
- layout->StartRow(0, 0);
- layout->AddView(close_all_button);
- set_close_all_button(close_all_button);
-}
-
-void PoorMessageCenterButtonBar::ButtonPressed(views::Button* sender,
- const ui::Event& event) {
- if (sender == close_all_button())
- message_center_view()->ClearAllNotifications();
-}
+} // namespace
// NotificationCenterButton ////////////////////////////////////////////////////
@@ -167,36 +111,14 @@ void NotificationCenterButton::OnPaintFocusBorder(gfx::Canvas* canvas) {
}
}
-// RichMessageCenterButtonBar //////////////////////////////////////////////////
-
-// TODO(mukai): Merge this into MessageCenterButtonBar and get rid of
-// PoorMessageCenterButtonBar when the kEnableRichNotifications flag disappears.
-class RichMessageCenterButtonBar : public MessageCenterButtonBar,
- public views::ButtonListener {
- public:
- RichMessageCenterButtonBar(MessageCenterView* message_center_view,
- MessageCenter* message_center);
-
- private:
- // Overridden from MessageCenterButtonBar:
- virtual void SetAllButtonsEnabled(bool enabled) OVERRIDE;
-
- // Overridden from views::View:
- virtual void ChildVisibilityChanged(views::View* child) OVERRIDE;
-
- // Overridden from views::ButtonListener:
- virtual void ButtonPressed(views::Button* sender,
- const ui::Event& event) OVERRIDE;
-
- NotificationCenterButton* settings_button_;
- NotificationCenterButton* quiet_mode_button_;
-
- DISALLOW_COPY_AND_ASSIGN(RichMessageCenterButtonBar);
-};
+// MessageCenterButtonBar //////////////////////////////////////////////////
-RichMessageCenterButtonBar::RichMessageCenterButtonBar(
- MessageCenterView* message_center_view, MessageCenter* message_center)
- : MessageCenterButtonBar(message_center_view, message_center) {
+MessageCenterButtonBar::MessageCenterButtonBar(
+ MessageCenterView* message_center_view,
+ MessageCenter* message_center)
+ : message_center_view_(message_center_view),
+ message_center_(message_center),
+ close_all_button_(NULL) {
if (get_use_acceleration_when_possible())
SetPaintToLayer(true);
set_background(views::Background::CreateSolidBackground(
@@ -265,21 +187,28 @@ RichMessageCenterButtonBar::RichMessageCenterButtonBar(
layout->AddView(button_container);
}
-// Overridden from MessageCenterButtonBar:
-void RichMessageCenterButtonBar::SetAllButtonsEnabled(bool enabled) {
- MessageCenterButtonBar::SetAllButtonsEnabled(enabled);
+MessageCenterButtonBar::~MessageCenterButtonBar() {}
+
+void MessageCenterButtonBar::SetAllButtonsEnabled(bool enabled) {
+ if (close_all_button_)
+ close_all_button_->SetEnabled(enabled);
settings_button_->SetEnabled(enabled);
quiet_mode_button_->SetEnabled(enabled);
}
+void MessageCenterButtonBar::SetCloseAllVisible(bool visible) {
+ if (close_all_button_)
+ close_all_button_->SetVisible(visible);
+}
+
// Overridden from views::View:
-void RichMessageCenterButtonBar::ChildVisibilityChanged(views::View* child) {
+void MessageCenterButtonBar::ChildVisibilityChanged(views::View* child) {
InvalidateLayout();
}
// Overridden from views::ButtonListener:
-void RichMessageCenterButtonBar::ButtonPressed(views::Button* sender,
- const ui::Event& event) {
+void MessageCenterButtonBar::ButtonPressed(views::Button* sender,
+ const ui::Event& event) {
if (sender == close_all_button()) {
message_center_view()->ClearAllNotifications();
} else if (sender == settings_button_) {
@@ -322,11 +251,9 @@ BoundedScrollView::BoundedScrollView(int min_height, int max_height)
set_notify_enter_exit_on_child(true);
// Cancels the default dashed focus border.
set_focus_border(NULL);
- if (IsRichNotificationEnabled()) {
- set_background(views::Background::CreateSolidBackground(
- kMessageCenterBackgroundColor));
- SetVerticalScrollBar(new views::OverlayScrollBar(false));
- }
+ set_background(
+ views::Background::CreateSolidBackground(kMessageCenterBackgroundColor));
+ SetVerticalScrollBar(new views::OverlayScrollBar(false));
}
gfx::Size BoundedScrollView::GetPreferredSize() {
@@ -403,83 +330,28 @@ void NoNotificationMessageView::Layout() {
label_->SetBounds(0, margin, width(), text_height);
}
-} // namespace
-
-// MessageListView /////////////////////////////////////////////////////////////
-
-// Displays a list of messages.
-class MessageListView : public views::View {
+// Displays a list of messages for rich notifications. It also supports
+// repositioning.
+class MessageListView : public views::View,
+ public views::BoundsAnimatorObserver {
public:
explicit MessageListView(MessageCenterView* message_center_view);
+ virtual ~MessageListView();
- // The interface for repositioning.
+ // Overridden from MessageListView.
Jun Mukai 2013/07/01 20:48:58 not overridden. you should remove virtual too
dewittj 2013/07/01 23:58:30 Done.
virtual void AddNotificationAt(views::View* view, int i);
virtual void RemoveNotificationAt(int i);
virtual void UpdateNotificationAt(views::View* view, int i);
- virtual void SetRepositionTarget(const gfx::Rect& target_rect) {}
- virtual void ResetRepositionSession() {}
+ virtual void SetRepositionTarget(const gfx::Rect& target_rect);
+ virtual void ResetRepositionSession();
virtual void ClearAllNotifications(const gfx::Rect& visible_scroll_rect);
protected:
- MessageCenterView* message_center_view() const {
- return message_center_view_;
- }
-
- private:
- MessageCenterView* message_center_view_; // Weak reference.
-
- DISALLOW_COPY_AND_ASSIGN(MessageListView);
-};
-
-MessageListView::MessageListView(MessageCenterView* message_center_view)
- : message_center_view_(message_center_view) {
- views::BoxLayout* layout =
- new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 1);
- layout->set_spread_blank_space(true);
- SetLayoutManager(layout);
-}
-
-void MessageListView::AddNotificationAt(views::View* view, int i) {
- AddChildViewAt(view, i);
-}
-
-void MessageListView::RemoveNotificationAt(int i) {
- delete child_at(i);
-}
-
-void MessageListView::UpdateNotificationAt(views::View* view, int i) {
- delete child_at(i);
- AddChildViewAt(view, i);
-}
-
-void MessageListView::ClearAllNotifications(
- const gfx::Rect& visible_scroll_rect) {
- message_center_view_->OnAllNotificationsCleared();
-}
-
-// Displays a list of messages for rich notifications. It also supports
-// repositioning.
-class RichMessageListView : public MessageListView,
- public views::BoundsAnimatorObserver {
- public:
- explicit RichMessageListView(MessageCenterView* message_center_view);
- virtual ~RichMessageListView();
-
- protected:
// Overridden from views::View.
virtual void Layout() OVERRIDE;
virtual gfx::Size GetPreferredSize() OVERRIDE;
virtual int GetHeightForWidth(int width) OVERRIDE;
- // Overridden from MessageListView.
- virtual void AddNotificationAt(views::View* view, int i) OVERRIDE;
- virtual void RemoveNotificationAt(int i) OVERRIDE;
- virtual void UpdateNotificationAt(views::View* view, int i) OVERRIDE;
- virtual void SetRepositionTarget(const gfx::Rect& target_rect) OVERRIDE;
- virtual void ResetRepositionSession() OVERRIDE;
- virtual void ClearAllNotifications(
- const gfx::Rect& visible_scroll_rect) OVERRIDE;
-
// Overridden from views::BoundsAnimatorObserver.
virtual void OnBoundsAnimatorProgressed(
views::BoundsAnimator* animator) OVERRIDE;
@@ -487,7 +359,7 @@ class RichMessageListView : public MessageListView,
private:
// Returns the actual index for child of |index|.
- // RichMessageListView allows to slide down upper notifications, which means
+ // MessageListView allows to slide down upper notifications, which means
// that the upper ones should come above the lower ones. To achieve this,
// inversed order is adopted. The top most notification is the last child,
// and the bottom most notification is the first child.
@@ -500,12 +372,14 @@ class RichMessageListView : public MessageListView,
// Animate clearing one notification.
void AnimateClearingOneNotification();
+ MessageCenterView* message_center_view() const {
+ return message_center_view_;
+ }
+ MessageCenterView* message_center_view_; // Weak reference.
// The top position of the reposition target rectangle.
int reposition_top_;
-
int fixed_height_;
-
bool has_deferred_task_;
bool clear_all_started_;
std::set<views::View*> adding_views_;
@@ -513,18 +387,23 @@ class RichMessageListView : public MessageListView,
std::set<views::View*> deleted_when_done_;
std::list<views::View*> clearing_all_views_;
scoped_ptr<views::BoundsAnimator> animator_;
- base::WeakPtrFactory<RichMessageListView> weak_ptr_factory_;
+ base::WeakPtrFactory<MessageListView> weak_ptr_factory_;
- DISALLOW_COPY_AND_ASSIGN(RichMessageListView);
+ DISALLOW_COPY_AND_ASSIGN(MessageListView);
};
-RichMessageListView::RichMessageListView(MessageCenterView* message_center_view)
- : MessageListView(message_center_view),
+MessageListView::MessageListView(MessageCenterView* message_center_view)
+ : message_center_view_(message_center_view),
reposition_top_(-1),
fixed_height_(0),
has_deferred_task_(false),
clear_all_started_(false),
weak_ptr_factory_(this) {
+ views::BoxLayout* layout =
+ new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 1);
+ layout->set_spread_blank_space(true);
+ SetLayoutManager(layout);
+
// 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
// because of the shadow of message view. Use an empty border instead
@@ -539,12 +418,12 @@ RichMessageListView::RichMessageListView(MessageCenterView* message_center_view)
kMarginBetweenItems - shadow_insets.right() /* right */ ));
}
-RichMessageListView::~RichMessageListView() {
+MessageListView::~MessageListView() {
if (animator_.get())
animator_->RemoveObserver(this);
}
-void RichMessageListView::Layout() {
+void MessageListView::Layout() {
if (animator_.get())
return;
@@ -563,7 +442,7 @@ void RichMessageListView::Layout() {
}
}
-void RichMessageListView::AddNotificationAt(views::View* view, int i) {
+void MessageListView::AddNotificationAt(views::View* view, int i) {
// Increment by 1 because the default behavior of AddChildViewAt() is to
// insert before the specified index.
AddChildViewAt(view, GetActualIndex(i) + 1);
@@ -574,7 +453,7 @@ void RichMessageListView::AddNotificationAt(views::View* view, int i) {
DoUpdateIfPossible();
}
-void RichMessageListView::RemoveNotificationAt(int i) {
+void MessageListView::RemoveNotificationAt(int i) {
views::View* child = child_at(GetActualIndex(i));
if (GetContentsBounds().IsEmpty()) {
delete child;
@@ -590,7 +469,7 @@ void RichMessageListView::RemoveNotificationAt(int i) {
}
}
-void RichMessageListView::UpdateNotificationAt(views::View* view, int i) {
+void MessageListView::UpdateNotificationAt(views::View* view, int i) {
int actual_index = GetActualIndex(i);
views::View* child = child_at(actual_index);
if (animator_.get())
@@ -607,7 +486,7 @@ void RichMessageListView::UpdateNotificationAt(views::View* view, int i) {
DoUpdateIfPossible();
}
-gfx::Size RichMessageListView::GetPreferredSize() {
+gfx::Size MessageListView::GetPreferredSize() {
int width = 0;
for (int i = 0; i < child_count(); i++) {
views::View* child = child_at(i);
@@ -619,7 +498,7 @@ gfx::Size RichMessageListView::GetPreferredSize() {
GetHeightForWidth(width + GetInsets().width()));
}
-int RichMessageListView::GetHeightForWidth(int width) {
+int MessageListView::GetHeightForWidth(int width) {
if (fixed_height_ > 0)
return fixed_height_;
@@ -637,12 +516,12 @@ int RichMessageListView::GetHeightForWidth(int width) {
return height + GetInsets().height();
}
-void RichMessageListView::SetRepositionTarget(const gfx::Rect& target) {
+void MessageListView::SetRepositionTarget(const gfx::Rect& target) {
reposition_top_ = target.y();
fixed_height_ = GetHeightForWidth(width());
}
-void RichMessageListView::ResetRepositionSession() {
+void MessageListView::ResetRepositionSession() {
// Don't call DoUpdateIfPossible(), but let Layout() do the task without
// animation. Reset will cause the change of the bubble size itself, and
// animation from the old location will look weird.
@@ -660,7 +539,7 @@ void RichMessageListView::ResetRepositionSession() {
fixed_height_ = 0;
}
-void RichMessageListView::ClearAllNotifications(
+void MessageListView::ClearAllNotifications(
const gfx::Rect& visible_scroll_rect) {
for (int i = 0; i < child_count(); ++i) {
views::View* child = child_at(i);
@@ -673,7 +552,7 @@ void RichMessageListView::ClearAllNotifications(
DoUpdateIfPossible();
}
-void RichMessageListView::OnBoundsAnimatorProgressed(
+void MessageListView::OnBoundsAnimatorProgressed(
views::BoundsAnimator* animator) {
DCHECK_EQ(animator_.get(), animator);
for (std::set<views::View*>::iterator iter = deleted_when_done_.begin();
@@ -684,8 +563,7 @@ void RichMessageListView::OnBoundsAnimatorProgressed(
}
}
-void RichMessageListView::OnBoundsAnimatorDone(
- views::BoundsAnimator* animator) {
+void MessageListView::OnBoundsAnimatorDone(views::BoundsAnimator* animator) {
STLDeleteContainerPointers(
deleted_when_done_.begin(), deleted_when_done_.end());
deleted_when_done_.clear();
@@ -704,7 +582,7 @@ void RichMessageListView::OnBoundsAnimatorDone(
GetWidget()->SynthesizeMouseMoveEvent();
}
-int RichMessageListView::GetActualIndex(int index) {
+int MessageListView::GetActualIndex(int index) {
// As is written in the comment in the declaration, this method
// returns actual index for the |index|-th valid child from the end.
int actual_index = child_count() - 1;
@@ -720,13 +598,13 @@ int RichMessageListView::GetActualIndex(int index) {
return actual_index;
}
-bool RichMessageListView::IsValidChild(views::View* child) {
+bool MessageListView::IsValidChild(views::View* child) {
return child->visible() &&
- deleting_views_.find(child) == deleting_views_.end() &&
- deleted_when_done_.find(child) == deleted_when_done_.end();
+ deleting_views_.find(child) == deleting_views_.end() &&
+ deleted_when_done_.find(child) == deleted_when_done_.end();
}
-void RichMessageListView::DoUpdateIfPossible() {
+void MessageListView::DoUpdateIfPossible() {
gfx::Rect child_area = GetContentsBounds();
if (child_area.IsEmpty())
return;
@@ -770,9 +648,7 @@ void RichMessageListView::DoUpdateIfPossible() {
deleting_views_.clear();
}
-void RichMessageListView::AnimateChild(views::View* child,
- int top,
- int height) {
+void MessageListView::AnimateChild(views::View* child, int top, int height) {
gfx::Rect child_area = GetContentsBounds();
if (adding_views_.find(child) != adding_views_.end()) {
child->SetBounds(child_area.right(), top, child_area.width(), height);
@@ -792,7 +668,7 @@ void RichMessageListView::AnimateChild(views::View* child,
}
}
-void RichMessageListView::AnimateClearingOneNotification() {
+void MessageListView::AnimateClearingOneNotification() {
DCHECK(!clearing_all_views_.empty());
clear_all_started_ = true;
@@ -809,35 +685,13 @@ void RichMessageListView::AnimateClearingOneNotification() {
if (!clearing_all_views_.empty()) {
base::MessageLoop::current()->PostDelayedTask(
FROM_HERE,
- base::Bind(&RichMessageListView::AnimateClearingOneNotification,
- weak_ptr_factory_.GetWeakPtr()),
+ base::Bind(&MessageListView::AnimateClearingOneNotification,
+ weak_ptr_factory_.GetWeakPtr()),
base::TimeDelta::FromMilliseconds(
kAnimateClearingNextNotificationDelayMS));
}
}
-// MessageCenterButtonBar //////////////////////////////////////////////////////
-
-MessageCenterButtonBar::MessageCenterButtonBar(
- MessageCenterView* message_center_view, MessageCenter* message_center)
- : message_center_view_(message_center_view),
- message_center_(message_center),
- close_all_button_(NULL) {
-}
-
-MessageCenterButtonBar::~MessageCenterButtonBar() {
-}
-
-void MessageCenterButtonBar::SetAllButtonsEnabled(bool enabled) {
- if (close_all_button_)
- close_all_button_->SetEnabled(enabled);
-}
-
-void MessageCenterButtonBar::SetCloseAllVisible(bool visible) {
- if (close_all_button_)
- close_all_button_->SetVisible(visible);
-}
-
// MessageCenterView ///////////////////////////////////////////////////////////
MessageCenterView::MessageCenterView(MessageCenter* message_center,
@@ -852,10 +706,7 @@ MessageCenterView::MessageCenterView(MessageCenter* message_center,
set_background(views::Background::CreateSolidBackground(
kMessageCenterBackgroundColor));
- if (IsRichNotificationEnabled())
- button_bar_ = new RichMessageCenterButtonBar(this, message_center);
- else
- button_bar_ = new PoorMessageCenterButtonBar(this, message_center);
+ button_bar_ = new MessageCenterButtonBar(this, message_center);
const int button_height = button_bar_->GetPreferredSize().height();
scroller_ = new BoundedScrollView(kMinScrollViewHeight,
@@ -867,8 +718,7 @@ MessageCenterView::MessageCenterView(MessageCenter* message_center,
scroller_->layer()->SetMasksToBounds(true);
}
- message_list_view_ = IsRichNotificationEnabled() ?
- new RichMessageListView(this) : new MessageListView(this);
+ message_list_view_ = new MessageListView(this);
no_notifications_message_view_ = new NoNotificationMessageView();
// Set the default visibility to false, otherwise the notification has slide
// in animation when the center is shown.
@@ -969,7 +819,6 @@ size_t MessageCenterView::NumMessageViewsForTest() const {
}
void MessageCenterView::Layout() {
- int between_child = IsRichNotificationEnabled() ? 0 : 1;
int button_height = button_bar_->GetHeightForWidth(width());
// Skip unnecessary re-layout of contents during the resize animation.
if (settings_transition_animation_ &&
@@ -979,9 +828,8 @@ void MessageCenterView::Layout() {
return;
}
- scroller_->SetBounds(0, 0, width(), height() - button_height - between_child);
- settings_view_->SetBounds(
- 0, 0, width(), height() - button_height - between_child);
+ scroller_->SetBounds(0, 0, width(), height() - button_height);
+ settings_view_->SetBounds(0, 0, width(), height() - button_height);
bool is_scrollable = false;
if (scroller_->visible())

Powered by Google App Engine
This is Rietveld 408576698