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

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

Issue 10171021: ash: Add a shadow for the uber-tray popups. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: adjustment Created 8 years, 8 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 | « no previous file | 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/audio/tray_volume.h" 10 #include "ash/system/audio/tray_volume.h"
(...skipping 22 matching lines...) Expand all
33 #include "base/i18n/rtl.h" 33 #include "base/i18n/rtl.h"
34 #include "base/logging.h" 34 #include "base/logging.h"
35 #include "base/message_loop.h" 35 #include "base/message_loop.h"
36 #include "base/timer.h" 36 #include "base/timer.h"
37 #include "base/utf_string_conversions.h" 37 #include "base/utf_string_conversions.h"
38 #include "grit/ash_strings.h" 38 #include "grit/ash_strings.h"
39 #include "third_party/skia/include/core/SkCanvas.h" 39 #include "third_party/skia/include/core/SkCanvas.h"
40 #include "third_party/skia/include/core/SkColor.h" 40 #include "third_party/skia/include/core/SkColor.h"
41 #include "third_party/skia/include/core/SkPaint.h" 41 #include "third_party/skia/include/core/SkPaint.h"
42 #include "third_party/skia/include/core/SkPath.h" 42 #include "third_party/skia/include/core/SkPath.h"
43 #include "third_party/skia/include/effects/SkBlurImageFilter.h"
43 #include "ui/aura/root_window.h" 44 #include "ui/aura/root_window.h"
44 #include "ui/base/events.h" 45 #include "ui/base/events.h"
45 #include "ui/base/accessibility/accessible_view_state.h" 46 #include "ui/base/accessibility/accessible_view_state.h"
46 #include "ui/base/l10n/l10n_util.h" 47 #include "ui/base/l10n/l10n_util.h"
47 #include "ui/gfx/canvas.h" 48 #include "ui/gfx/canvas.h"
49 #include "ui/gfx/compositor/layer.h"
48 #include "ui/gfx/screen.h" 50 #include "ui/gfx/screen.h"
49 #include "ui/gfx/skia_util.h" 51 #include "ui/gfx/skia_util.h"
50 #include "ui/views/border.h" 52 #include "ui/views/border.h"
51 #include "ui/views/bubble/bubble_border.h" 53 #include "ui/views/bubble/bubble_border.h"
52 #include "ui/views/bubble/bubble_delegate.h" 54 #include "ui/views/bubble/bubble_delegate.h"
53 #include "ui/views/bubble/bubble_frame_view.h" 55 #include "ui/views/bubble/bubble_frame_view.h"
54 #include "ui/views/controls/label.h" 56 #include "ui/views/controls/label.h"
55 #include "ui/views/layout/fill_layout.h" 57 #include "ui/views/layout/fill_layout.h"
56 #include "ui/views/layout/box_layout.h" 58 #include "ui/views/layout/box_layout.h"
57 #include "ui/views/view.h" 59 #include "ui/views/view.h"
58 #include "ui/views/widget/widget.h" 60 #include "ui/views/widget/widget.h"
59 61
60 namespace ash { 62 namespace ash {
61 63
62 namespace { 64 namespace {
63 65
64 const int kPaddingFromRightEdgeOfScreen = 15; 66 const int kPaddingFromRightEdgeOfScreen = 15;
65 const int kPaddingFromBottomOfScreen = 10; 67 const int kPaddingFromBottomOfScreen = 10;
66 68
67 const int kAnimationDurationForPopupMS = 200; 69 const int kAnimationDurationForPopupMS = 200;
68 70
69 const int kArrowHeight = 10; 71 const int kArrowHeight = 10;
70 const int kArrowWidth = 20; 72 const int kArrowWidth = 20;
71 const int kArrowPaddingFromRight = 20; 73 const int kArrowPaddingFromRight = 20;
72 74
73 const int kShadowOffset = 3; 75 const int kShadowThickness = 4;
74 const int kShadowHeight = 3;
75 76
76 const int kLeftPadding = 4; 77 const int kLeftPadding = 4;
77 const int kBottomLineHeight = 1; 78 const int kBottomLineHeight = 1;
78 79
79 const SkColor kShadowColor = SkColorSetARGB(25, 0, 0, 0); 80 const SkColor kShadowColor = SkColorSetARGB(0xff, 0, 0, 0);
80 81
81 const SkColor kTrayBackgroundAlpha = 100; 82 const SkColor kTrayBackgroundAlpha = 100;
82 const SkColor kTrayBackgroundHoverAlpha = 150; 83 const SkColor kTrayBackgroundHoverAlpha = 150;
83 84
85 void DrawBlurredShadowAroundView(gfx::Canvas* canvas,
86 int top,
87 int bottom,
88 int width,
89 const gfx::Insets& inset) {
90 SkPath path;
91 path.incReserve(4);
92 path.moveTo(SkIntToScalar(inset.left() + kShadowThickness),
93 SkIntToScalar(top + kShadowThickness + 1));
94 path.lineTo(SkIntToScalar(inset.left() + kShadowThickness),
95 SkIntToScalar(bottom));
96 path.lineTo(SkIntToScalar(width),
97 SkIntToScalar(bottom));
98 path.lineTo(SkIntToScalar(width),
99 SkIntToScalar(top + kShadowThickness + 1));
100
101 SkPaint paint;
102 paint.setColor(kShadowColor);
103 paint.setStyle(SkPaint::kStroke_Style);
104 paint.setXfermodeMode(SkXfermode::kSrcOver_Mode);
105 paint.setStrokeWidth(SkIntToScalar(3));
106 paint.setImageFilter(new SkBlurImageFilter(
107 SkIntToScalar(3), SkIntToScalar(3)))->unref();
108 canvas->sk_canvas()->drawPath(path, paint);
109 }
110
84 // A view with some special behaviour for tray items in the popup: 111 // A view with some special behaviour for tray items in the popup:
85 // - changes background color on hover. 112 // - changes background color on hover.
86 class TrayPopupItemContainer : public views::View { 113 class TrayPopupItemContainer : public views::View {
87 public: 114 public:
88 explicit TrayPopupItemContainer(views::View* view) : hover_(false) { 115 explicit TrayPopupItemContainer(views::View* view) : hover_(false) {
89 set_notify_enter_exit_on_child(true); 116 set_notify_enter_exit_on_child(true);
90 set_border(view->border() ? views::Border::CreateEmptyBorder(0, 0, 0, 0) : 117 set_border(view->border() ? views::Border::CreateEmptyBorder(0, 0, 0, 0) :
91 NULL); 118 NULL);
92 SetLayoutManager(new views::FillLayout); 119 SetLayoutManager(new views::FillLayout);
120 SetPaintToLayer(view->layer() != NULL);
121 if (view->layer())
122 SetFillsBoundsOpaquely(view->layer()->fills_bounds_opaquely());
93 AddChildView(view); 123 AddChildView(view);
94 SetVisible(view->visible()); 124 SetVisible(view->visible());
95 } 125 }
96 126
97 virtual ~TrayPopupItemContainer() {} 127 virtual ~TrayPopupItemContainer() {}
98 128
99 private: 129 private:
100 // Overridden from views::View. 130 // Overridden from views::View.
101 virtual void ChildVisibilityChanged(View* child) OVERRIDE { 131 virtual void ChildVisibilityChanged(View* child) OVERRIDE {
102 if (visible() == child->visible()) 132 if (visible() == child->visible())
(...skipping 13 matching lines...) Expand all
116 } 146 }
117 147
118 virtual void OnPaintBackground(gfx::Canvas* canvas) OVERRIDE { 148 virtual void OnPaintBackground(gfx::Canvas* canvas) OVERRIDE {
119 if (child_count() == 0) 149 if (child_count() == 0)
120 return; 150 return;
121 151
122 views::View* view = child_at(0); 152 views::View* view = child_at(0);
123 if (!view->background()) { 153 if (!view->background()) {
124 canvas->FillRect(gfx::Rect(size()), 154 canvas->FillRect(gfx::Rect(size()),
125 hover_ ? kHoverBackgroundColor : kBackgroundColor); 155 hover_ ? kHoverBackgroundColor : kBackgroundColor);
126 } else {
127 canvas->FillRect(gfx::Rect(view->x() + kShadowOffset, view->y(),
128 view->width() - kShadowOffset, kShadowHeight),
129 kShadowColor);
130 } 156 }
131 } 157 }
132 158
133 bool hover_; 159 bool hover_;
134 160
135 DISALLOW_COPY_AND_ASSIGN(TrayPopupItemContainer); 161 DISALLOW_COPY_AND_ASSIGN(TrayPopupItemContainer);
136 }; 162 };
137 163
138 class SystemTrayBubbleBackground : public views::Background { 164 class SystemTrayBubbleBackground : public views::Background {
139 public: 165 public:
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 owner_(owner) { 210 owner_(owner) {
185 set_alignment(views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE); 211 set_alignment(views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE);
186 } 212 }
187 213
188 virtual ~SystemTrayBubbleBorder() {} 214 virtual ~SystemTrayBubbleBorder() {}
189 215
190 private: 216 private:
191 // Overridden from views::Border. 217 // Overridden from views::Border.
192 virtual void Paint(const views::View& view, 218 virtual void Paint(const views::View& view,
193 gfx::Canvas* canvas) const OVERRIDE { 219 gfx::Canvas* canvas) const OVERRIDE {
194 // Draw a line first. 220 views::View* first = NULL, *last = NULL;
221 gfx::Insets inset;
222 GetInsets(&inset);
223 for (int i = 0; i < owner_->child_count(); i++) {
224 views::View* v = owner_->child_at(i);
225 if (v->border()) {
226 if (first) {
227 DrawBlurredShadowAroundView(canvas, first->y(),
228 last->y() + last->height(), owner_->width(), inset);
229 first = NULL;
230 last = NULL;
231 }
232 continue;
233 }
234
235 if (!first)
236 first = v;
237 last = v;
238 }
239 if (first) {
240 DrawBlurredShadowAroundView(canvas, first->y(),
241 last->y() + last->height(), owner_->width(), inset);
242 }
243
244 // Draw the bottom line.
195 int y = owner_->height() + 1; 245 int y = owner_->height() + 1;
196 canvas->FillRect(gfx::Rect(kLeftPadding, y, owner_->width(), 246 canvas->FillRect(gfx::Rect(kLeftPadding, y, owner_->width(),
197 kBottomLineHeight), kBorderDarkColor); 247 kBottomLineHeight), kBorderDarkColor);
198 248
199 // Now, draw a shadow. 249 if (!Shell::GetInstance()->shelf()->IsVisible())
200 canvas->FillRect(gfx::Rect(kLeftPadding + kShadowOffset, y, 250 return;
201 owner_->width() - kShadowOffset, kShadowHeight),
202 kShadowColor);
203 251
204 if (Shell::GetInstance()->shelf()->IsVisible()) { 252 // Draw the arrow.
205 // Draw the arrow. 253 int left_base_x = base::i18n::IsRTL() ? kArrowWidth :
206 int left_base_x = base::i18n::IsRTL() ? kArrowWidth : 254 owner_->width() - kArrowPaddingFromRight - kArrowWidth;
207 owner_->width() - kArrowPaddingFromRight - kArrowWidth; 255 int left_base_y = y;
208 int left_base_y = y; 256 int tip_x = left_base_x + kArrowWidth / 2;
209 int tip_x = left_base_x + kArrowWidth / 2; 257 int tip_y = left_base_y + kArrowHeight;
210 int tip_y = left_base_y + kArrowHeight; 258 SkPath path;
211 SkPath path; 259 path.incReserve(4);
212 path.incReserve(4); 260 path.moveTo(SkIntToScalar(left_base_x), SkIntToScalar(left_base_y));
213 path.moveTo(SkIntToScalar(left_base_x), SkIntToScalar(left_base_y)); 261 path.lineTo(SkIntToScalar(tip_x), SkIntToScalar(tip_y));
214 path.lineTo(SkIntToScalar(tip_x), SkIntToScalar(tip_y)); 262 path.lineTo(SkIntToScalar(left_base_x + kArrowWidth),
215 path.lineTo(SkIntToScalar(left_base_x + kArrowWidth), 263 SkIntToScalar(left_base_y));
216 SkIntToScalar(left_base_y));
217 264
218 SkPaint paint; 265 SkPaint paint;
219 paint.setStyle(SkPaint::kFill_Style); 266 paint.setStyle(SkPaint::kFill_Style);
220 paint.setColor(kBackgroundColor); 267 paint.setColor(kBackgroundColor);
221 canvas->DrawPath(path, paint); 268 canvas->DrawPath(path, paint);
222 269
223 // Now the draw the outline. 270 // Now draw the arrow border.
224 paint.setStyle(SkPaint::kStroke_Style); 271 paint.setStyle(SkPaint::kStroke_Style);
225 paint.setColor(kBorderDarkColor); 272 paint.setColor(kBorderDarkColor);
226 canvas->DrawPath(path, paint); 273 canvas->DrawPath(path, paint);
227 }
228 } 274 }
275
229 views::View* owner_; 276 views::View* owner_;
230 277
231 DISALLOW_COPY_AND_ASSIGN(SystemTrayBubbleBorder); 278 DISALLOW_COPY_AND_ASSIGN(SystemTrayBubbleBorder);
232 }; 279 };
233 280
234 } // namespace 281 } // namespace
235 282
236 namespace internal { 283 namespace internal {
237 284
238 class SystemTrayBackground : public views::Background { 285 class SystemTrayBackground : public views::Background {
(...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after
719 popup_->Hide(); 766 popup_->Hide();
720 } 767 }
721 } 768 }
722 return base::EVENT_CONTINUE; 769 return base::EVENT_CONTINUE;
723 } 770 }
724 771
725 void SystemTray::DidProcessEvent(const base::NativeEvent& event) { 772 void SystemTray::DidProcessEvent(const base::NativeEvent& event) {
726 } 773 }
727 774
728 } // namespace ash 775 } // namespace ash
OLDNEW
« no previous file with comments | « no previous file | ash/system/tray/tray_empty.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698