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" |
| 12 #include "ash/system/tray/tray_views.h" |
11 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
12 #include "grit/ash_strings.h" | 14 #include "grit/ash_strings.h" |
13 #include "grit/ui_resources.h" | 15 #include "grit/ui_resources.h" |
14 #include "ui/base/resource/resource_bundle.h" | 16 #include "ui/base/resource/resource_bundle.h" |
15 #include "ui/gfx/font.h" | 17 #include "ui/gfx/font.h" |
16 #include "ui/gfx/image/image.h" | 18 #include "ui/gfx/image/image.h" |
17 #include "ui/views/controls/image_view.h" | 19 #include "ui/views/controls/image_view.h" |
18 #include "ui/views/controls/label.h" | 20 #include "ui/views/controls/label.h" |
19 #include "ui/views/controls/scroll_view.h" | 21 #include "ui/views/controls/scroll_view.h" |
20 #include "ui/views/layout/fill_layout.h" | 22 #include "ui/views/layout/fill_layout.h" |
21 #include "ui/views/layout/box_layout.h" | 23 #include "ui/views/layout/box_layout.h" |
22 #include "ui/views/view.h" | 24 #include "ui/views/view.h" |
23 #include "ui/views/widget/widget.h" | 25 #include "ui/views/widget/widget.h" |
24 | 26 |
25 namespace { | 27 namespace { |
26 | 28 |
27 // Width of the icon, and the padding on the right of the icon. These are used | |
28 // to make sure that all icons are of the same size so that they line up | |
29 // properly, including the items that don't have any icons. | |
30 const int kIconWidth = 27; | |
31 const int kIconPaddingLeft = 5; | |
32 | |
33 // Height of the list of networks in the popup. | 29 // Height of the list of networks in the popup. |
34 const int kNetworkListHeight = 160; | 30 const int kNetworkListHeight = 160; |
35 | 31 |
36 // An image view with that always has a fixed width (kIconWidth) so that | |
37 // all the items line up properly. | |
38 class FixedWidthImageView : public views::ImageView { | |
39 public: | |
40 FixedWidthImageView() { | |
41 SetHorizontalAlignment(views::ImageView::CENTER); | |
42 SetVerticalAlignment(views::ImageView::CENTER); | |
43 } | |
44 | |
45 virtual ~FixedWidthImageView() {} | |
46 | |
47 private: | |
48 virtual gfx::Size GetPreferredSize() OVERRIDE { | |
49 gfx::Size size = views::ImageView::GetPreferredSize(); | |
50 return gfx::Size(kIconWidth, size.height()); | |
51 } | |
52 | |
53 DISALLOW_COPY_AND_ASSIGN(FixedWidthImageView); | |
54 }; | |
55 | |
56 class ViewClickListener { | |
57 public: | |
58 virtual ~ViewClickListener() {} | |
59 virtual void ClickedOn(views::View* sender) = 0; | |
60 }; | |
61 | |
62 class HoverHighlightView : public views::View { | |
63 public: | |
64 explicit HoverHighlightView(ViewClickListener* listener) | |
65 : listener_(listener) { | |
66 set_notify_enter_exit_on_child(true); | |
67 } | |
68 | |
69 virtual ~HoverHighlightView() {} | |
70 | |
71 // Convenience function for adding an icon and a label. | |
72 void AddIconAndLabel(const SkBitmap& image, | |
73 const string16& text, | |
74 gfx::Font::FontStyle style) { | |
75 SetLayoutManager(new views::BoxLayout( | |
76 views::BoxLayout::kHorizontal, 0, 3, kIconPaddingLeft)); | |
77 views::ImageView* image_view = new FixedWidthImageView; | |
78 image_view->SetImage(image); | |
79 AddChildView(image_view); | |
80 | |
81 views::Label* label = new views::Label(text); | |
82 label->SetFont(label->font().DeriveFont(0, style)); | |
83 AddChildView(label); | |
84 } | |
85 | |
86 void AddLabel(const string16& text) { | |
87 SetLayoutManager(new views::FillLayout()); | |
88 views::Label* label = new views::Label(text); | |
89 label->set_border(views::Border::CreateEmptyBorder( | |
90 5, kIconWidth + kIconPaddingLeft, 5, 0)); | |
91 label->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | |
92 AddChildView(label); | |
93 } | |
94 | |
95 private: | |
96 // Overridden from views::View. | |
97 virtual bool OnMousePressed(const views::MouseEvent& event) OVERRIDE { | |
98 if (!listener_) | |
99 return false; | |
100 listener_->ClickedOn(this); | |
101 return true; | |
102 } | |
103 | |
104 virtual void OnMouseEntered(const views::MouseEvent& event) OVERRIDE { | |
105 set_background(views::Background::CreateSolidBackground( | |
106 ash::kHoverBackgroundColor)); | |
107 SchedulePaint(); | |
108 } | |
109 | |
110 virtual void OnMouseExited(const views::MouseEvent& event) OVERRIDE { | |
111 set_background(NULL); | |
112 SchedulePaint(); | |
113 } | |
114 | |
115 ViewClickListener* listener_; | |
116 | |
117 DISALLOW_COPY_AND_ASSIGN(HoverHighlightView); | |
118 }; | |
119 | |
120 // A custom scroll-view that has a specified dimension. | 32 // A custom scroll-view that has a specified dimension. |
121 class FixedSizedScrollView : public views::ScrollView { | 33 class FixedSizedScrollView : public views::ScrollView { |
122 public: | 34 public: |
123 FixedSizedScrollView() { | 35 FixedSizedScrollView() { |
124 set_focusable(true); | 36 set_focusable(true); |
125 set_notify_enter_exit_on_child(true); | 37 set_notify_enter_exit_on_child(true); |
126 } | 38 } |
127 | 39 |
128 virtual ~FixedSizedScrollView() {} | 40 virtual ~FixedSizedScrollView() {} |
129 | 41 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 SchedulePaint(); | 103 SchedulePaint(); |
192 } | 104 } |
193 | 105 |
194 private: | 106 private: |
195 views::ImageView* image_view_; | 107 views::ImageView* image_view_; |
196 ResourceSize resource_size_; | 108 ResourceSize resource_size_; |
197 | 109 |
198 DISALLOW_COPY_AND_ASSIGN(NetworkTrayView); | 110 DISALLOW_COPY_AND_ASSIGN(NetworkTrayView); |
199 }; | 111 }; |
200 | 112 |
201 class NetworkDefaultView : public views::View { | 113 class NetworkDefaultView : public TrayItemMore { |
202 public: | 114 public: |
203 explicit NetworkDefaultView(SystemTrayItem* owner) : owner_(owner) { | 115 explicit NetworkDefaultView(SystemTrayItem* owner) |
| 116 : TrayItemMore(owner) { |
204 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, | 117 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, |
205 kTrayPopupPaddingHorizontal, 0, kTrayPopupPaddingBetweenItems)); | 118 kTrayPopupPaddingHorizontal, 0, kTrayPopupPaddingBetweenItems)); |
206 | 119 |
207 icon_ = new NetworkTrayView(LARGE); | 120 icon_ = new NetworkTrayView(LARGE); |
208 AddChildView(icon_); | 121 AddChildView(icon_); |
209 | 122 |
210 label_ = new views::Label(); | 123 label_ = new views::Label(); |
211 AddChildView(label_); | 124 AddChildView(label_); |
212 | 125 |
213 more_ = new views::ImageView; | 126 AddMore(); |
214 more_->SetImage(ui::ResourceBundle::GetSharedInstance().GetImageNamed( | |
215 IDR_AURA_UBER_TRAY_MORE).ToSkBitmap()); | |
216 AddChildView(more_); | |
217 | 127 |
218 Update(Shell::GetInstance()->tray_delegate()-> | 128 Update(Shell::GetInstance()->tray_delegate()-> |
219 GetMostRelevantNetworkIcon(true)); | 129 GetMostRelevantNetworkIcon(true)); |
220 } | 130 } |
221 | 131 |
222 virtual ~NetworkDefaultView() {} | 132 virtual ~NetworkDefaultView() {} |
223 | 133 |
224 void Update(const NetworkIconInfo& info) { | 134 void Update(const NetworkIconInfo& info) { |
225 icon_->Update(info); | 135 icon_->Update(info); |
226 label_->SetText(info.description); | 136 label_->SetText(info.description); |
227 } | 137 } |
228 | 138 |
229 private: | 139 private: |
230 // 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 { | |
242 owner_->PopupDetailedView(0, true); | |
243 return true; | |
244 } | |
245 | |
246 SystemTrayItem* owner_; | |
247 NetworkTrayView* icon_; | 140 NetworkTrayView* icon_; |
248 views::Label* label_; | 141 views::Label* label_; |
249 views::ImageView* more_; | |
250 | 142 |
251 DISALLOW_COPY_AND_ASSIGN(NetworkDefaultView); | 143 DISALLOW_COPY_AND_ASSIGN(NetworkDefaultView); |
252 }; | 144 }; |
253 | 145 |
254 class NetworkDetailedView : public views::View, | 146 class NetworkDetailedView : public views::View, |
255 public ViewClickListener { | 147 public ViewClickListener { |
256 public: | 148 public: |
257 explicit NetworkDetailedView(user::LoginStatus login) | 149 explicit NetworkDetailedView(user::LoginStatus login) |
258 : login_(login), | 150 : login_(login), |
259 header_(NULL), | 151 header_(NULL), |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
461 if (tray_.get()) | 353 if (tray_.get()) |
462 tray_->Update(info); | 354 tray_->Update(info); |
463 if (default_.get()) | 355 if (default_.get()) |
464 default_->Update(info); | 356 default_->Update(info); |
465 if (detailed_.get()) | 357 if (detailed_.get()) |
466 detailed_->Update(); | 358 detailed_->Update(); |
467 } | 359 } |
468 | 360 |
469 } // namespace internal | 361 } // namespace internal |
470 } // namespace ash | 362 } // namespace ash |
OLD | NEW |