| 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/system_tray_delegate.h" | 10 #include "ash/system/tray/system_tray_delegate.h" |
| 11 #include "ash/system/tray/system_tray_item.h" | 11 #include "ash/system/tray/system_tray_item.h" |
| 12 #include "ash/system/user/login_status.h" | 12 #include "ash/system/user/login_status.h" |
| 13 #include "ash/wm/shadow_types.h" | 13 #include "ash/wm/shadow_types.h" |
| 14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
| 16 #include "third_party/skia/include/core/SkCanvas.h" | 16 #include "third_party/skia/include/core/SkCanvas.h" |
| 17 #include "third_party/skia/include/core/SkColor.h" | 17 #include "third_party/skia/include/core/SkColor.h" |
| 18 #include "third_party/skia/include/core/SkPaint.h" | 18 #include "third_party/skia/include/core/SkPaint.h" |
| 19 #include "third_party/skia/include/core/SkPath.h" | 19 #include "third_party/skia/include/core/SkPath.h" |
| 20 #include "ui/gfx/canvas.h" | 20 #include "ui/gfx/canvas.h" |
| 21 #include "ui/gfx/skia_util.h" |
| 21 #include "ui/views/border.h" | 22 #include "ui/views/border.h" |
| 22 #include "ui/views/bubble/bubble_delegate.h" | 23 #include "ui/views/bubble/bubble_delegate.h" |
| 23 #include "ui/views/controls/label.h" | 24 #include "ui/views/controls/label.h" |
| 24 #include "ui/views/layout/box_layout.h" | 25 #include "ui/views/layout/box_layout.h" |
| 25 #include "ui/views/view.h" | 26 #include "ui/views/view.h" |
| 26 | 27 |
| 27 namespace { | 28 namespace { |
| 28 | 29 |
| 29 const int kArrowHeight = 10; | 30 const int kArrowHeight = 10; |
| 30 const int kArrowWidth = 20; | 31 const int kArrowWidth = 20; |
| 31 const int kArrowPaddingFromRight = 20; | 32 const int kArrowPaddingFromRight = 20; |
| 32 | 33 |
| 33 const int kShadowOffset = 3; | 34 const int kShadowOffset = 3; |
| 34 const int kShadowHeight = 3; | 35 const int kShadowHeight = 3; |
| 35 | 36 |
| 36 const SkColor kDarkColor = SkColorSetRGB(120, 120, 120); | 37 const SkColor kDarkColor = SkColorSetRGB(120, 120, 120); |
| 37 const SkColor kLightColor = SkColorSetRGB(240, 240, 240); | 38 const SkColor kLightColor = SkColorSetRGB(240, 240, 240); |
| 38 const SkColor kBackgroundColor = SK_ColorWHITE; | 39 const SkColor kBackgroundColor = SK_ColorWHITE; |
| 39 const SkColor kShadowColor = SkColorSetARGB(25, 0, 0, 0); | 40 const SkColor kShadowColor = SkColorSetARGB(25, 0, 0, 0); |
| 40 | 41 |
| 42 const SkColor kTrayBackgroundColor = SkColorSetARGB(127, 0, 0, 0); |
| 43 |
| 41 class SystemTrayBubbleBackground : public views::Background { | 44 class SystemTrayBubbleBackground : public views::Background { |
| 42 public: | 45 public: |
| 43 explicit SystemTrayBubbleBackground(views::View* owner) | 46 explicit SystemTrayBubbleBackground(views::View* owner) |
| 44 : owner_(owner) { | 47 : owner_(owner) { |
| 45 } | 48 } |
| 46 | 49 |
| 47 virtual ~SystemTrayBubbleBackground() {} | 50 virtual ~SystemTrayBubbleBackground() {} |
| 48 | 51 |
| 49 private: | 52 private: |
| 50 // Overridden from views::Background. | 53 // Overridden from views::Background. |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 } | 190 } |
| 188 } | 191 } |
| 189 | 192 |
| 190 ash::SystemTray* tray_; | 193 ash::SystemTray* tray_; |
| 191 std::vector<ash::SystemTrayItem*> items_; | 194 std::vector<ash::SystemTrayItem*> items_; |
| 192 bool detailed_; | 195 bool detailed_; |
| 193 | 196 |
| 194 DISALLOW_COPY_AND_ASSIGN(SystemTrayBubble); | 197 DISALLOW_COPY_AND_ASSIGN(SystemTrayBubble); |
| 195 }; | 198 }; |
| 196 | 199 |
| 200 class SystemTrayBackground : public views::Background { |
| 201 public: |
| 202 SystemTrayBackground() {} |
| 203 virtual ~SystemTrayBackground() {} |
| 204 |
| 205 private: |
| 206 // Overrridden from views::Background. |
| 207 virtual void Paint(gfx::Canvas* canvas, views::View* view) const OVERRIDE { |
| 208 SkPaint paint; |
| 209 paint.setAntiAlias(true); |
| 210 paint.setStyle(SkPaint::kFill_Style); |
| 211 paint.setColor(kTrayBackgroundColor); |
| 212 SkPath path; |
| 213 gfx::Rect bounds(view->GetContentsBounds()); |
| 214 SkScalar radius = SkIntToScalar(4); |
| 215 path.addRoundRect(gfx::RectToSkRect(bounds), radius, radius); |
| 216 canvas->GetSkCanvas()->drawPath(path, paint); |
| 217 } |
| 218 |
| 219 DISALLOW_COPY_AND_ASSIGN(SystemTrayBackground); |
| 220 }; |
| 221 |
| 197 } // namespace | 222 } // namespace |
| 198 | 223 |
| 199 namespace ash { | 224 namespace ash { |
| 200 | 225 |
| 201 SystemTray::SystemTray() | 226 SystemTray::SystemTray() |
| 202 : items_(), | 227 : items_(), |
| 203 popup_(NULL) { | 228 popup_(NULL) { |
| 204 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, | 229 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, |
| 205 5, 0, 3)); | 230 5, 0, 3)); |
| 206 set_background(views::Background::CreateSolidBackground( | 231 set_background(new SystemTrayBackground); |
| 207 SkColorSetARGB(127, 0, 0, 0))); | |
| 208 } | 232 } |
| 209 | 233 |
| 210 SystemTray::~SystemTray() { | 234 SystemTray::~SystemTray() { |
| 211 if (popup_) | 235 if (popup_) |
| 212 popup_->CloseNow(); | 236 popup_->CloseNow(); |
| 213 for (std::vector<SystemTrayItem*>::iterator it = items_.begin(); | 237 for (std::vector<SystemTrayItem*>::iterator it = items_.begin(); |
| 214 it != items_.end(); | 238 it != items_.end(); |
| 215 ++it) { | 239 ++it) { |
| 216 (*it)->DestroyTrayView(); | 240 (*it)->DestroyTrayView(); |
| 217 } | 241 } |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 ShowItems(items_, false); | 306 ShowItems(items_, false); |
| 283 return true; | 307 return true; |
| 284 } | 308 } |
| 285 | 309 |
| 286 void SystemTray::OnWidgetClosing(views::Widget* widget) { | 310 void SystemTray::OnWidgetClosing(views::Widget* widget) { |
| 287 CHECK_EQ(popup_, widget); | 311 CHECK_EQ(popup_, widget); |
| 288 popup_ = NULL; | 312 popup_ = NULL; |
| 289 } | 313 } |
| 290 | 314 |
| 291 } // namespace ash | 315 } // namespace ash |
| OLD | NEW |