Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ash/system/tray/system_tray.h" | 5 #include "ash/system/tray/system_tray.h" |
| 6 | 6 |
| 7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
| 8 #include "ash/shell/panel_window.h" | 8 #include "ash/shell/panel_window.h" |
| 9 #include "ash/shell_window_ids.h" | 9 #include "ash/shell_window_ids.h" |
| 10 #include "ash/system/tray/tray_constants.h" | 10 #include "ash/system/tray/tray_constants.h" |
| 11 #include "ash/system/tray/system_tray_delegate.h" | 11 #include "ash/system/tray/system_tray_delegate.h" |
| 12 #include "ash/system/tray/system_tray_item.h" | 12 #include "ash/system/tray/system_tray_item.h" |
| 13 #include "ash/system/user/login_status.h" | 13 #include "ash/system/user/login_status.h" |
| 14 #include "ash/wm/shadow_types.h" | 14 #include "ash/wm/shadow_types.h" |
| 15 #include "ash/wm/window_animations.h" | 15 #include "ash/wm/window_animations.h" |
| 16 #include "base/logging.h" | 16 #include "base/logging.h" |
| 17 #include "base/timer.h" | 17 #include "base/timer.h" |
| 18 #include "base/utf_string_conversions.h" | 18 #include "base/utf_string_conversions.h" |
| 19 #include "third_party/skia/include/core/SkCanvas.h" | 19 #include "third_party/skia/include/core/SkCanvas.h" |
| 20 #include "third_party/skia/include/core/SkColor.h" | 20 #include "third_party/skia/include/core/SkColor.h" |
| 21 #include "third_party/skia/include/core/SkPaint.h" | 21 #include "third_party/skia/include/core/SkPaint.h" |
| 22 #include "third_party/skia/include/core/SkPath.h" | 22 #include "third_party/skia/include/core/SkPath.h" |
| 23 #include "ui/gfx/canvas.h" | 23 #include "ui/gfx/canvas.h" |
| 24 #include "ui/gfx/skia_util.h" | 24 #include "ui/gfx/skia_util.h" |
| 25 #include "ui/views/border.h" | 25 #include "ui/views/border.h" |
| 26 #include "ui/views/bubble/bubble_delegate.h" | 26 #include "ui/views/bubble/bubble_delegate.h" |
| 27 #include "ui/views/controls/label.h" | 27 #include "ui/views/controls/label.h" |
| 28 #include "ui/views/layout/fill_layout.h" | |
| 28 #include "ui/views/layout/box_layout.h" | 29 #include "ui/views/layout/box_layout.h" |
| 29 #include "ui/views/view.h" | 30 #include "ui/views/view.h" |
| 30 | 31 |
| 31 namespace ash { | 32 namespace ash { |
| 32 | 33 |
| 33 namespace { | 34 namespace { |
| 34 | 35 |
| 35 const int kPaddingFromRightEdgeOfScreen = 10; | 36 const int kPaddingFromRightEdgeOfScreen = 10; |
| 36 const int kPaddingFromBottomOfScreen = 10; | 37 const int kPaddingFromBottomOfScreen = 10; |
| 37 | 38 |
| 38 const int kAnimationDurationForPopupMS = 200; | 39 const int kAnimationDurationForPopupMS = 200; |
| 39 | 40 |
| 40 const int kArrowHeight = 10; | 41 const int kArrowHeight = 10; |
| 41 const int kArrowWidth = 20; | 42 const int kArrowWidth = 20; |
| 42 const int kArrowPaddingFromRight = 20; | 43 const int kArrowPaddingFromRight = 20; |
| 43 | 44 |
| 44 const int kShadowOffset = 3; | 45 const int kShadowOffset = 3; |
| 45 const int kShadowHeight = 3; | 46 const int kShadowHeight = 3; |
| 46 | 47 |
| 47 const SkColor kDarkColor = SkColorSetRGB(120, 120, 120); | 48 const SkColor kDarkColor = SkColorSetRGB(120, 120, 120); |
| 48 const SkColor kLightColor = SkColorSetRGB(240, 240, 240); | 49 const SkColor kLightColor = SkColorSetRGB(240, 240, 240); |
| 49 const SkColor kBackgroundColor = SK_ColorWHITE; | 50 const SkColor kBackgroundColor = SK_ColorWHITE; |
| 51 const SkColor kHoverBackgroundColor = SkColorSetRGB(0xfb, 0xfc, 0xfb); | |
| 50 const SkColor kShadowColor = SkColorSetARGB(25, 0, 0, 0); | 52 const SkColor kShadowColor = SkColorSetARGB(25, 0, 0, 0); |
| 51 | 53 |
| 52 const SkColor kTrayBackgroundColor = SkColorSetARGB(100, 0, 0, 0); | 54 const SkColor kTrayBackgroundColor = SkColorSetARGB(100, 0, 0, 0); |
| 53 const SkColor kTrayBackgroundHover = SkColorSetARGB(150, 0, 0, 0); | 55 const SkColor kTrayBackgroundHover = SkColorSetARGB(150, 0, 0, 0); |
| 54 | 56 |
| 57 // A view with some special behaviour for tray items: | |
| 58 // - changes background color on hover. | |
| 59 // - TODO: accessibility | |
| 60 class TrayItemContainer : public views::View { | |
| 61 public: | |
| 62 explicit TrayItemContainer(views::View* view) : hover_(false) { | |
| 63 set_notify_enter_exit_on_child(true); | |
| 64 set_border(view->border() ? views::Border::CreateEmptyBorder(0, 0, 0, 0) : | |
| 65 NULL); | |
| 66 SetLayoutManager(new views::FillLayout); | |
| 67 AddChildView(view); | |
| 68 } | |
| 69 | |
| 70 views::View* view() { return child_at(0); } | |
| 71 | |
| 72 virtual ~TrayItemContainer() {} | |
|
Ben Goodger (Google)
2012/03/15 19:05:40
put this below the ctor
sadrul
2012/03/15 19:11:08
Done.
| |
| 73 | |
| 74 private: | |
| 75 // Overridden from views::View. | |
| 76 virtual void OnMouseEntered(const views::MouseEvent& event) OVERRIDE { | |
| 77 hover_ = true; | |
| 78 SchedulePaint(); | |
| 79 } | |
| 80 | |
| 81 virtual void OnMouseExited(const views::MouseEvent& event) OVERRIDE { | |
| 82 hover_ = false; | |
| 83 SchedulePaint(); | |
| 84 } | |
| 85 | |
| 86 virtual void OnPaintBackground(gfx::Canvas* canvas) OVERRIDE { | |
| 87 views::View* view = child_at(0); | |
| 88 if (!view->background()) { | |
| 89 canvas->FillRect(gfx::Rect(size()), | |
| 90 hover_ ? kHoverBackgroundColor : kBackgroundColor); | |
| 91 } else { | |
| 92 canvas->FillRect(gfx::Rect(view->x() + kShadowOffset, view->y(), | |
| 93 view->width() - kShadowOffset, kShadowHeight), | |
| 94 kShadowColor); | |
| 95 } | |
| 96 } | |
| 97 | |
| 98 bool hover_; | |
| 99 | |
| 100 DISALLOW_COPY_AND_ASSIGN(TrayItemContainer); | |
| 101 }; | |
| 102 | |
| 55 class SystemTrayBubbleBackground : public views::Background { | 103 class SystemTrayBubbleBackground : public views::Background { |
| 56 public: | 104 public: |
| 57 explicit SystemTrayBubbleBackground(views::View* owner) | 105 explicit SystemTrayBubbleBackground(views::View* owner) |
| 58 : owner_(owner) { | 106 : owner_(owner) { |
| 59 } | 107 } |
| 60 | 108 |
| 61 virtual ~SystemTrayBubbleBackground() {} | 109 virtual ~SystemTrayBubbleBackground() {} |
| 62 | 110 |
| 63 private: | 111 private: |
| 64 // Overridden from views::Background. | 112 // Overridden from views::Background. |
| 65 virtual void Paint(gfx::Canvas* canvas, views::View* view) const OVERRIDE { | 113 virtual void Paint(gfx::Canvas* canvas, views::View* view) const OVERRIDE { |
| 66 views::View* last_view = NULL; | 114 views::View* last_view = NULL; |
| 67 for (int i = 0; i < owner_->child_count(); i++) { | 115 for (int i = 0; i < owner_->child_count(); i++) { |
| 68 views::View* v = owner_->child_at(i); | 116 views::View* v = owner_->child_at(i); |
| 69 | 117 |
| 70 if (!v->background()) { | |
| 71 canvas->FillRect(v->bounds(), kBackgroundColor); | |
| 72 } else if (last_view) { | |
| 73 canvas->FillRect(gfx::Rect(v->x() + kShadowOffset, v->y(), | |
| 74 v->width() - kShadowOffset, kShadowHeight), | |
| 75 kShadowColor); | |
| 76 } | |
| 77 | |
| 78 if (!v->border()) { | 118 if (!v->border()) { |
| 79 canvas->DrawLine(gfx::Point(v->x() - 1, v->y() - 1), | 119 canvas->DrawLine(gfx::Point(v->x() - 1, v->y() - 1), |
| 80 gfx::Point(v->x() + v->width() + 1, v->y() - 1), | 120 gfx::Point(v->x() + v->width() + 1, v->y() - 1), |
| 81 !last_view || last_view->border() ? kDarkColor : kLightColor); | 121 !last_view || last_view->border() ? kDarkColor : kLightColor); |
| 82 canvas->DrawLine(gfx::Point(v->x() - 1, v->y() - 1), | 122 canvas->DrawLine(gfx::Point(v->x() - 1, v->y() - 1), |
| 83 gfx::Point(v->x() - 1, v->y() + v->height() + 1), | 123 gfx::Point(v->x() - 1, v->y() + v->height() + 1), |
| 84 kDarkColor); | 124 kDarkColor); |
| 85 canvas->DrawLine(gfx::Point(v->x() + v->width(), v->y() - 1), | 125 canvas->DrawLine(gfx::Point(v->x() + v->width(), v->y() - 1), |
| 86 gfx::Point(v->x() + v->width(), v->y() + v->height() + 1), | 126 gfx::Point(v->x() + v->width(), v->y() + v->height() + 1), |
| 87 kDarkColor); | 127 kDarkColor); |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 240 | 280 |
| 241 ash::SystemTrayDelegate* delegate = | 281 ash::SystemTrayDelegate* delegate = |
| 242 ash::Shell::GetInstance()->tray_delegate(); | 282 ash::Shell::GetInstance()->tray_delegate(); |
| 243 ash::user::LoginStatus login_status = delegate->GetUserLoginStatus(); | 283 ash::user::LoginStatus login_status = delegate->GetUserLoginStatus(); |
| 244 for (std::vector<ash::SystemTrayItem*>::iterator it = items_.begin(); | 284 for (std::vector<ash::SystemTrayItem*>::iterator it = items_.begin(); |
| 245 it != items_.end(); | 285 it != items_.end(); |
| 246 ++it) { | 286 ++it) { |
| 247 views::View* view = detailed_ ? (*it)->CreateDetailedView(login_status) : | 287 views::View* view = detailed_ ? (*it)->CreateDetailedView(login_status) : |
| 248 (*it)->CreateDefaultView(login_status); | 288 (*it)->CreateDefaultView(login_status); |
| 249 if (view) | 289 if (view) |
| 250 AddChildView(view); | 290 AddChildView(new TrayItemContainer(view)); |
| 251 } | 291 } |
| 252 } | 292 } |
| 253 | 293 |
| 254 virtual bool CanActivate() const OVERRIDE { | 294 virtual bool CanActivate() const OVERRIDE { |
| 255 return can_activate_; | 295 return can_activate_; |
| 256 } | 296 } |
| 257 | 297 |
| 258 virtual void OnMouseEntered(const views::MouseEvent& event) OVERRIDE { | 298 virtual void OnMouseEntered(const views::MouseEvent& event) OVERRIDE { |
| 259 autoclose_.Stop(); | 299 autoclose_.Stop(); |
| 260 } | 300 } |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 439 SchedulePaint(); | 479 SchedulePaint(); |
| 440 } | 480 } |
| 441 | 481 |
| 442 void SystemTray::OnWidgetClosing(views::Widget* widget) { | 482 void SystemTray::OnWidgetClosing(views::Widget* widget) { |
| 443 CHECK_EQ(popup_, widget); | 483 CHECK_EQ(popup_, widget); |
| 444 popup_ = NULL; | 484 popup_ = NULL; |
| 445 bubble_ = NULL; | 485 bubble_ = NULL; |
| 446 } | 486 } |
| 447 | 487 |
| 448 } // namespace ash | 488 } // namespace ash |
| OLD | NEW |