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

Side by Side Diff: ash/system/tray/system_tray.cc

Issue 9703078: ash: Highlight the items in the uber-tray popup when hovering. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 9 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ash/system/settings/tray_settings.cc ('k') | ash/system/tray/tray_empty.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 virtual ~TrayItemContainer() {}
71
72 private:
73 // Overridden from views::View.
74 virtual void OnMouseEntered(const views::MouseEvent& event) OVERRIDE {
75 hover_ = true;
76 SchedulePaint();
77 }
78
79 virtual void OnMouseExited(const views::MouseEvent& event) OVERRIDE {
80 hover_ = false;
81 SchedulePaint();
82 }
83
84 virtual void OnPaintBackground(gfx::Canvas* canvas) OVERRIDE {
85 views::View* view = child_at(0);
86 if (!view->background()) {
87 canvas->FillRect(gfx::Rect(size()),
88 hover_ ? kHoverBackgroundColor : kBackgroundColor);
89 } else {
90 canvas->FillRect(gfx::Rect(view->x() + kShadowOffset, view->y(),
91 view->width() - kShadowOffset, kShadowHeight),
92 kShadowColor);
93 }
94 }
95
96 bool hover_;
97
98 DISALLOW_COPY_AND_ASSIGN(TrayItemContainer);
99 };
100
55 class SystemTrayBubbleBackground : public views::Background { 101 class SystemTrayBubbleBackground : public views::Background {
56 public: 102 public:
57 explicit SystemTrayBubbleBackground(views::View* owner) 103 explicit SystemTrayBubbleBackground(views::View* owner)
58 : owner_(owner) { 104 : owner_(owner) {
59 } 105 }
60 106
61 virtual ~SystemTrayBubbleBackground() {} 107 virtual ~SystemTrayBubbleBackground() {}
62 108
63 private: 109 private:
64 // Overridden from views::Background. 110 // Overridden from views::Background.
65 virtual void Paint(gfx::Canvas* canvas, views::View* view) const OVERRIDE { 111 virtual void Paint(gfx::Canvas* canvas, views::View* view) const OVERRIDE {
66 views::View* last_view = NULL; 112 views::View* last_view = NULL;
67 for (int i = 0; i < owner_->child_count(); i++) { 113 for (int i = 0; i < owner_->child_count(); i++) {
68 views::View* v = owner_->child_at(i); 114 views::View* v = owner_->child_at(i);
69 115
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()) { 116 if (!v->border()) {
79 canvas->DrawLine(gfx::Point(v->x() - 1, v->y() - 1), 117 canvas->DrawLine(gfx::Point(v->x() - 1, v->y() - 1),
80 gfx::Point(v->x() + v->width() + 1, v->y() - 1), 118 gfx::Point(v->x() + v->width() + 1, v->y() - 1),
81 !last_view || last_view->border() ? kDarkColor : kLightColor); 119 !last_view || last_view->border() ? kDarkColor : kLightColor);
82 canvas->DrawLine(gfx::Point(v->x() - 1, v->y() - 1), 120 canvas->DrawLine(gfx::Point(v->x() - 1, v->y() - 1),
83 gfx::Point(v->x() - 1, v->y() + v->height() + 1), 121 gfx::Point(v->x() - 1, v->y() + v->height() + 1),
84 kDarkColor); 122 kDarkColor);
85 canvas->DrawLine(gfx::Point(v->x() + v->width(), v->y() - 1), 123 canvas->DrawLine(gfx::Point(v->x() + v->width(), v->y() - 1),
86 gfx::Point(v->x() + v->width(), v->y() + v->height() + 1), 124 gfx::Point(v->x() + v->width(), v->y() + v->height() + 1),
87 kDarkColor); 125 kDarkColor);
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 278
241 ash::SystemTrayDelegate* delegate = 279 ash::SystemTrayDelegate* delegate =
242 ash::Shell::GetInstance()->tray_delegate(); 280 ash::Shell::GetInstance()->tray_delegate();
243 ash::user::LoginStatus login_status = delegate->GetUserLoginStatus(); 281 ash::user::LoginStatus login_status = delegate->GetUserLoginStatus();
244 for (std::vector<ash::SystemTrayItem*>::iterator it = items_.begin(); 282 for (std::vector<ash::SystemTrayItem*>::iterator it = items_.begin();
245 it != items_.end(); 283 it != items_.end();
246 ++it) { 284 ++it) {
247 views::View* view = detailed_ ? (*it)->CreateDetailedView(login_status) : 285 views::View* view = detailed_ ? (*it)->CreateDetailedView(login_status) :
248 (*it)->CreateDefaultView(login_status); 286 (*it)->CreateDefaultView(login_status);
249 if (view) 287 if (view)
250 AddChildView(view); 288 AddChildView(new TrayItemContainer(view));
251 } 289 }
252 } 290 }
253 291
254 virtual bool CanActivate() const OVERRIDE { 292 virtual bool CanActivate() const OVERRIDE {
255 return can_activate_; 293 return can_activate_;
256 } 294 }
257 295
258 virtual void OnMouseEntered(const views::MouseEvent& event) OVERRIDE { 296 virtual void OnMouseEntered(const views::MouseEvent& event) OVERRIDE {
259 autoclose_.Stop(); 297 autoclose_.Stop();
260 } 298 }
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 SchedulePaint(); 477 SchedulePaint();
440 } 478 }
441 479
442 void SystemTray::OnWidgetClosing(views::Widget* widget) { 480 void SystemTray::OnWidgetClosing(views::Widget* widget) {
443 CHECK_EQ(popup_, widget); 481 CHECK_EQ(popup_, widget);
444 popup_ = NULL; 482 popup_ = NULL;
445 bubble_ = NULL; 483 bubble_ = NULL;
446 } 484 }
447 485
448 } // namespace ash 486 } // namespace ash
OLDNEW
« no previous file with comments | « ash/system/settings/tray_settings.cc ('k') | ash/system/tray/tray_empty.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698