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/network/tray_network.h" | 5 #include "ash/system/network/tray_network.h" |
6 | 6 |
7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
8 #include "ash/system/tray/system_tray.h" | 8 #include "ash/system/tray/system_tray.h" |
9 #include "ash/system/tray/system_tray_delegate.h" | 9 #include "ash/system/tray/system_tray_delegate.h" |
10 #include "ash/system/tray/tray_constants.h" | 10 #include "ash/system/tray/tray_constants.h" |
| 11 #include "ash/system/tray/tray_item_more.h" |
11 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
12 #include "grit/ash_strings.h" | 13 #include "grit/ash_strings.h" |
13 #include "grit/ui_resources.h" | 14 #include "grit/ui_resources.h" |
14 #include "ui/base/resource/resource_bundle.h" | 15 #include "ui/base/resource/resource_bundle.h" |
15 #include "ui/gfx/font.h" | 16 #include "ui/gfx/font.h" |
16 #include "ui/gfx/image/image.h" | 17 #include "ui/gfx/image/image.h" |
17 #include "ui/views/controls/image_view.h" | 18 #include "ui/views/controls/image_view.h" |
18 #include "ui/views/controls/label.h" | 19 #include "ui/views/controls/label.h" |
19 #include "ui/views/controls/scroll_view.h" | 20 #include "ui/views/controls/scroll_view.h" |
20 #include "ui/views/layout/fill_layout.h" | 21 #include "ui/views/layout/fill_layout.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 | 53 |
53 DISALLOW_COPY_AND_ASSIGN(FixedWidthImageView); | 54 DISALLOW_COPY_AND_ASSIGN(FixedWidthImageView); |
54 }; | 55 }; |
55 | 56 |
56 class ViewClickListener { | 57 class ViewClickListener { |
57 public: | 58 public: |
58 virtual ~ViewClickListener() {} | 59 virtual ~ViewClickListener() {} |
59 virtual void ClickedOn(views::View* sender) = 0; | 60 virtual void ClickedOn(views::View* sender) = 0; |
60 }; | 61 }; |
61 | 62 |
62 class HoverHighlightView : public views::View { | 63 class HoverHighlightView : public ash::internal::TrayItemMore { |
63 public: | 64 public: |
64 explicit HoverHighlightView(ViewClickListener* listener) | 65 explicit HoverHighlightView(ViewClickListener* listener) |
65 : listener_(listener) { | 66 : listener_(listener) { |
66 set_notify_enter_exit_on_child(true); | 67 set_notify_enter_exit_on_child(true); |
67 } | 68 } |
68 | 69 |
69 virtual ~HoverHighlightView() {} | 70 virtual ~HoverHighlightView() {} |
70 | 71 |
71 // Convenience function for adding an icon and a label. | 72 // Convenience function for adding an icon and a label. |
72 void AddIconAndLabel(const SkBitmap& image, | 73 void AddIconAndLabel(const SkBitmap& image, |
73 const string16& text, | 74 const string16& text, |
74 gfx::Font::FontStyle style) { | 75 gfx::Font::FontStyle style) { |
75 SetLayoutManager(new views::BoxLayout( | 76 SetLayoutManager(new views::BoxLayout( |
76 views::BoxLayout::kHorizontal, 0, 3, kIconPaddingLeft)); | 77 views::BoxLayout::kHorizontal, 0, 3, kIconPaddingLeft)); |
77 views::ImageView* image_view = new FixedWidthImageView; | 78 views::ImageView* image_view = new FixedWidthImageView; |
78 image_view->SetImage(image); | 79 image_view->SetImage(image); |
79 AddChildView(image_view); | 80 AddChildView(image_view); |
80 | 81 |
81 views::Label* label = new views::Label(text); | 82 views::Label* label = new views::Label(text); |
82 label->SetFont(label->font().DeriveFont(0, style)); | 83 label->SetFont(label->font().DeriveFont(0, style)); |
83 AddChildView(label); | 84 AddChildView(label); |
| 85 |
| 86 AddMore(); |
84 } | 87 } |
85 | 88 |
86 void AddLabel(const string16& text) { | 89 void AddLabel(const string16& text) { |
87 SetLayoutManager(new views::FillLayout()); | 90 SetLayoutManager(new views::FillLayout()); |
88 views::Label* label = new views::Label(text); | 91 views::Label* label = new views::Label(text); |
89 label->set_border(views::Border::CreateEmptyBorder( | 92 label->set_border(views::Border::CreateEmptyBorder( |
90 5, kIconWidth + kIconPaddingLeft, 5, 0)); | 93 5, kIconWidth + kIconPaddingLeft, 5, 0)); |
91 label->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | 94 label->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
92 AddChildView(label); | 95 AddChildView(label); |
93 } | 96 } |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 explicit NetworkDefaultView(SystemTrayItem* owner) : owner_(owner) { | 206 explicit NetworkDefaultView(SystemTrayItem* owner) : owner_(owner) { |
204 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, | 207 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, |
205 kTrayPopupPaddingHorizontal, 0, kTrayPopupPaddingBetweenItems)); | 208 kTrayPopupPaddingHorizontal, 0, kTrayPopupPaddingBetweenItems)); |
206 | 209 |
207 icon_ = new NetworkTrayView(LARGE); | 210 icon_ = new NetworkTrayView(LARGE); |
208 AddChildView(icon_); | 211 AddChildView(icon_); |
209 | 212 |
210 label_ = new views::Label(); | 213 label_ = new views::Label(); |
211 AddChildView(label_); | 214 AddChildView(label_); |
212 | 215 |
213 more_ = new views::ImageView; | |
214 more_->SetImage(ui::ResourceBundle::GetSharedInstance().GetImageNamed( | |
215 IDR_AURA_UBER_TRAY_MORE).ToSkBitmap()); | |
216 AddChildView(more_); | |
217 | |
218 Update(Shell::GetInstance()->tray_delegate()-> | 216 Update(Shell::GetInstance()->tray_delegate()-> |
219 GetMostRelevantNetworkIcon(true)); | 217 GetMostRelevantNetworkIcon(true)); |
220 } | 218 } |
221 | 219 |
222 virtual ~NetworkDefaultView() {} | 220 virtual ~NetworkDefaultView() {} |
223 | 221 |
224 void Update(const NetworkIconInfo& info) { | 222 void Update(const NetworkIconInfo& info) { |
225 icon_->Update(info); | 223 icon_->Update(info); |
226 label_->SetText(info.description); | 224 label_->SetText(info.description); |
227 } | 225 } |
228 | 226 |
229 private: | 227 private: |
230 // Overridden from views::View. | 228 // Overridden from views::View. |
231 virtual void Layout() OVERRIDE { | |
232 // Let the box-layout do the layout first. Then move the '>' arrow to right | |
233 // align. | |
234 views::View::Layout(); | |
235 | |
236 gfx::Rect bounds = more_->bounds(); | |
237 bounds.set_x(width() - more_->width() - kTrayPopupPaddingBetweenItems); | |
238 more_->SetBoundsRect(bounds); | |
239 } | |
240 | |
241 virtual bool OnMousePressed(const views::MouseEvent& event) OVERRIDE { | 229 virtual bool OnMousePressed(const views::MouseEvent& event) OVERRIDE { |
242 owner_->PopupDetailedView(0, true); | 230 owner_->PopupDetailedView(0, true); |
243 return true; | 231 return true; |
244 } | 232 } |
245 | 233 |
246 SystemTrayItem* owner_; | 234 SystemTrayItem* owner_; |
247 NetworkTrayView* icon_; | 235 NetworkTrayView* icon_; |
248 views::Label* label_; | 236 views::Label* label_; |
249 views::ImageView* more_; | |
250 | 237 |
251 DISALLOW_COPY_AND_ASSIGN(NetworkDefaultView); | 238 DISALLOW_COPY_AND_ASSIGN(NetworkDefaultView); |
252 }; | 239 }; |
253 | 240 |
254 class NetworkDetailedView : public views::View, | 241 class NetworkDetailedView : public views::View, |
255 public ViewClickListener { | 242 public ViewClickListener { |
256 public: | 243 public: |
257 explicit NetworkDetailedView(user::LoginStatus login) | 244 explicit NetworkDetailedView(user::LoginStatus login) |
258 : login_(login), | 245 : login_(login), |
259 header_(NULL), | 246 header_(NULL), |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
461 if (tray_.get()) | 448 if (tray_.get()) |
462 tray_->Update(info); | 449 tray_->Update(info); |
463 if (default_.get()) | 450 if (default_.get()) |
464 default_->Update(info); | 451 default_->Update(info); |
465 if (detailed_.get()) | 452 if (detailed_.get()) |
466 detailed_->Update(); | 453 detailed_->Update(); |
467 } | 454 } |
468 | 455 |
469 } // namespace internal | 456 } // namespace internal |
470 } // namespace ash | 457 } // namespace ash |
OLD | NEW |