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/timer.h" | 15 #include "base/timer.h" |
16 #include "base/utf_string_conversions.h" | 16 #include "base/utf_string_conversions.h" |
17 #include "third_party/skia/include/core/SkCanvas.h" | 17 #include "third_party/skia/include/core/SkCanvas.h" |
18 #include "third_party/skia/include/core/SkColor.h" | 18 #include "third_party/skia/include/core/SkColor.h" |
19 #include "third_party/skia/include/core/SkPaint.h" | 19 #include "third_party/skia/include/core/SkPaint.h" |
20 #include "third_party/skia/include/core/SkPath.h" | 20 #include "third_party/skia/include/core/SkPath.h" |
21 #include "ui/gfx/canvas.h" | 21 #include "ui/gfx/canvas.h" |
22 #include "ui/gfx/skia_util.h" | |
22 #include "ui/views/border.h" | 23 #include "ui/views/border.h" |
23 #include "ui/views/bubble/bubble_delegate.h" | 24 #include "ui/views/bubble/bubble_delegate.h" |
24 #include "ui/views/controls/label.h" | 25 #include "ui/views/controls/label.h" |
25 #include "ui/views/layout/box_layout.h" | 26 #include "ui/views/layout/box_layout.h" |
26 #include "ui/views/view.h" | 27 #include "ui/views/view.h" |
27 | 28 |
28 namespace ash { | 29 namespace ash { |
29 | 30 |
30 namespace internal { | 31 namespace internal { |
31 | 32 |
32 const int kArrowHeight = 10; | 33 const int kArrowHeight = 10; |
33 const int kArrowWidth = 20; | 34 const int kArrowWidth = 20; |
34 const int kArrowPaddingFromRight = 20; | 35 const int kArrowPaddingFromRight = 20; |
35 | 36 |
36 const int kShadowOffset = 3; | 37 const int kShadowOffset = 3; |
37 const int kShadowHeight = 3; | 38 const int kShadowHeight = 3; |
38 | 39 |
39 const SkColor kDarkColor = SkColorSetRGB(120, 120, 120); | 40 const SkColor kDarkColor = SkColorSetRGB(120, 120, 120); |
40 const SkColor kLightColor = SkColorSetRGB(240, 240, 240); | 41 const SkColor kLightColor = SkColorSetRGB(240, 240, 240); |
41 const SkColor kBackgroundColor = SK_ColorWHITE; | 42 const SkColor kBackgroundColor = SK_ColorWHITE; |
42 const SkColor kShadowColor = SkColorSetARGB(25, 0, 0, 0); | 43 const SkColor kShadowColor = SkColorSetARGB(25, 0, 0, 0); |
43 | 44 |
45 const SkColor kTrayBackgroundColor = SkColorSetARGB(100, 0, 0, 0); | |
46 const SkColor kTrayBackgroundHover = SkColorSetARGB(150, 0, 0, 0); | |
47 | |
44 class SystemTrayBubbleBackground : public views::Background { | 48 class SystemTrayBubbleBackground : public views::Background { |
45 public: | 49 public: |
46 explicit SystemTrayBubbleBackground(views::View* owner) | 50 explicit SystemTrayBubbleBackground(views::View* owner) |
47 : owner_(owner) { | 51 : owner_(owner) { |
48 } | 52 } |
49 | 53 |
50 virtual ~SystemTrayBubbleBackground() {} | 54 virtual ~SystemTrayBubbleBackground() {} |
51 | 55 |
52 private: | 56 private: |
53 // Overridden from views::Background. | 57 // Overridden from views::Background. |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
222 ash::SystemTray* tray_; | 226 ash::SystemTray* tray_; |
223 std::vector<ash::SystemTrayItem*> items_; | 227 std::vector<ash::SystemTrayItem*> items_; |
224 bool detailed_; | 228 bool detailed_; |
225 | 229 |
226 int autoclose_delay_; | 230 int autoclose_delay_; |
227 base::OneShotTimer<SystemTrayBubble> autoclose_; | 231 base::OneShotTimer<SystemTrayBubble> autoclose_; |
228 | 232 |
229 DISALLOW_COPY_AND_ASSIGN(SystemTrayBubble); | 233 DISALLOW_COPY_AND_ASSIGN(SystemTrayBubble); |
230 }; | 234 }; |
231 | 235 |
236 class SystemTrayBackground : public views::Background { | |
237 public: | |
238 SystemTrayBackground() : hovering_(false) {} | |
239 virtual ~SystemTrayBackground() {} | |
240 | |
241 void set_hovering(bool hover) { hovering_ = hover; } | |
242 | |
243 private: | |
244 // Overrridden from views::Background. | |
Ben Goodger (Google)
2012/03/05 22:54:37
2 rs
sadrul
2012/03/05 22:58:43
Done.
| |
245 virtual void Paint(gfx::Canvas* canvas, views::View* view) const OVERRIDE { | |
246 SkPaint paint; | |
247 paint.setAntiAlias(true); | |
248 paint.setStyle(SkPaint::kFill_Style); | |
249 paint.setColor(hovering_ ? kTrayBackgroundHover : kTrayBackgroundColor); | |
250 SkPath path; | |
251 gfx::Rect bounds(view->GetContentsBounds()); | |
252 SkScalar radius = SkIntToScalar(4); | |
253 path.addRoundRect(gfx::RectToSkRect(bounds), radius, radius); | |
254 canvas->GetSkCanvas()->drawPath(path, paint); | |
255 } | |
256 | |
257 bool hovering_; | |
258 | |
259 DISALLOW_COPY_AND_ASSIGN(SystemTrayBackground); | |
260 }; | |
261 | |
232 } // namespace internal | 262 } // namespace internal |
233 | 263 |
234 SystemTray::SystemTray() | 264 SystemTray::SystemTray() |
235 : items_(), | 265 : items_(), |
236 bubble_(NULL), | 266 bubble_(NULL), |
237 popup_(NULL) { | 267 popup_(NULL) { |
238 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, | 268 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, |
239 5, 0, 3)); | 269 5, 0, 3)); |
240 set_background(views::Background::CreateSolidBackground( | 270 set_background(new SystemTrayBackground); |
241 SkColorSetARGB(127, 0, 0, 0))); | 271 set_notify_enter_exit_on_child(true); |
242 } | 272 } |
243 | 273 |
244 SystemTray::~SystemTray() { | 274 SystemTray::~SystemTray() { |
245 if (popup_) | 275 if (popup_) |
246 popup_->CloseNow(); | 276 popup_->CloseNow(); |
247 for (std::vector<SystemTrayItem*>::iterator it = items_.begin(); | 277 for (std::vector<SystemTrayItem*>::iterator it = items_.begin(); |
248 it != items_.end(); | 278 it != items_.end(); |
249 ++it) { | 279 ++it) { |
250 (*it)->DestroyTrayView(); | 280 (*it)->DestroyTrayView(); |
251 } | 281 } |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
313 } | 343 } |
314 | 344 |
315 bool SystemTray::OnMousePressed(const views::MouseEvent& event) { | 345 bool SystemTray::OnMousePressed(const views::MouseEvent& event) { |
316 if (popup_) | 346 if (popup_) |
317 popup_->Show(); | 347 popup_->Show(); |
318 else | 348 else |
319 ShowItems(items_, false); | 349 ShowItems(items_, false); |
320 return true; | 350 return true; |
321 } | 351 } |
322 | 352 |
353 void SystemTray::OnMouseEntered(const views::MouseEvent& event) { | |
354 static_cast<SystemTrayBackground*>(background())->set_hovering(true); | |
355 SchedulePaint(); | |
356 } | |
357 | |
358 void SystemTray::OnMouseExited(const views::MouseEvent& event) { | |
359 static_cast<SystemTrayBackground*>(background())->set_hovering(false); | |
360 SchedulePaint(); | |
361 } | |
362 | |
323 void SystemTray::OnWidgetClosing(views::Widget* widget) { | 363 void SystemTray::OnWidgetClosing(views::Widget* widget) { |
324 CHECK_EQ(popup_, widget); | 364 CHECK_EQ(popup_, widget); |
325 popup_ = NULL; | 365 popup_ = NULL; |
326 bubble_ = NULL; | 366 bubble_ = NULL; |
327 } | 367 } |
328 | 368 |
329 } // namespace ash | 369 } // namespace ash |
OLD | NEW |