Chromium Code Reviews| Index: ash/system/tray/system_tray.cc |
| diff --git a/ash/system/tray/system_tray.cc b/ash/system/tray/system_tray.cc |
| index 879a00ba12690c2de941c021a1f283269fd67b8c..01793604d7872aaef5f52952f2a5a3f73cf4071b 100644 |
| --- a/ash/system/tray/system_tray.cc |
| +++ b/ash/system/tray/system_tray.cc |
| @@ -25,6 +25,7 @@ |
| #include "ui/views/border.h" |
| #include "ui/views/bubble/bubble_delegate.h" |
| #include "ui/views/controls/label.h" |
| +#include "ui/views/layout/fill_layout.h" |
| #include "ui/views/layout/box_layout.h" |
| #include "ui/views/view.h" |
| @@ -47,11 +48,58 @@ const int kShadowHeight = 3; |
| const SkColor kDarkColor = SkColorSetRGB(120, 120, 120); |
| const SkColor kLightColor = SkColorSetRGB(240, 240, 240); |
| const SkColor kBackgroundColor = SK_ColorWHITE; |
| +const SkColor kHoverBackgroundColor = SkColorSetRGB(0xfb, 0xfc, 0xfb); |
| const SkColor kShadowColor = SkColorSetARGB(25, 0, 0, 0); |
| const SkColor kTrayBackgroundColor = SkColorSetARGB(100, 0, 0, 0); |
| const SkColor kTrayBackgroundHover = SkColorSetARGB(150, 0, 0, 0); |
| +// A view with some special behaviour for tray items: |
| +// - changes background color on hover. |
| +// - TODO: accessibility |
| +class TrayItemContainer : public views::View { |
| + public: |
| + explicit TrayItemContainer(views::View* view) : hover_(false) { |
| + set_notify_enter_exit_on_child(true); |
| + set_border(view->border() ? views::Border::CreateEmptyBorder(0, 0, 0, 0) : |
| + NULL); |
| + SetLayoutManager(new views::FillLayout); |
| + AddChildView(view); |
| + } |
| + |
| + views::View* view() { return child_at(0); } |
| + |
| + virtual ~TrayItemContainer() {} |
|
Ben Goodger (Google)
2012/03/15 19:05:40
put this below the ctor
sadrul
2012/03/15 19:11:08
Done.
|
| + |
| + private: |
| + // Overridden from views::View. |
| + virtual void OnMouseEntered(const views::MouseEvent& event) OVERRIDE { |
| + hover_ = true; |
| + SchedulePaint(); |
| + } |
| + |
| + virtual void OnMouseExited(const views::MouseEvent& event) OVERRIDE { |
| + hover_ = false; |
| + SchedulePaint(); |
| + } |
| + |
| + virtual void OnPaintBackground(gfx::Canvas* canvas) OVERRIDE { |
| + views::View* view = child_at(0); |
| + if (!view->background()) { |
| + canvas->FillRect(gfx::Rect(size()), |
| + hover_ ? kHoverBackgroundColor : kBackgroundColor); |
| + } else { |
| + canvas->FillRect(gfx::Rect(view->x() + kShadowOffset, view->y(), |
| + view->width() - kShadowOffset, kShadowHeight), |
| + kShadowColor); |
| + } |
| + } |
| + |
| + bool hover_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(TrayItemContainer); |
| +}; |
| + |
| class SystemTrayBubbleBackground : public views::Background { |
| public: |
| explicit SystemTrayBubbleBackground(views::View* owner) |
| @@ -67,14 +115,6 @@ class SystemTrayBubbleBackground : public views::Background { |
| for (int i = 0; i < owner_->child_count(); i++) { |
| views::View* v = owner_->child_at(i); |
| - if (!v->background()) { |
| - canvas->FillRect(v->bounds(), kBackgroundColor); |
| - } else if (last_view) { |
| - canvas->FillRect(gfx::Rect(v->x() + kShadowOffset, v->y(), |
| - v->width() - kShadowOffset, kShadowHeight), |
| - kShadowColor); |
| - } |
| - |
| if (!v->border()) { |
| canvas->DrawLine(gfx::Point(v->x() - 1, v->y() - 1), |
| gfx::Point(v->x() + v->width() + 1, v->y() - 1), |
| @@ -247,7 +287,7 @@ class SystemTrayBubble : public views::BubbleDelegateView { |
| views::View* view = detailed_ ? (*it)->CreateDetailedView(login_status) : |
| (*it)->CreateDefaultView(login_status); |
| if (view) |
| - AddChildView(view); |
| + AddChildView(new TrayItemContainer(view)); |
| } |
| } |