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/bluetooth/tray_bluetooth.h" | 5 #include "ash/system/bluetooth/tray_bluetooth.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 "ash/system/tray/tray_item_more.h" |
12 #include "ash/system/tray/tray_views.h" | 12 #include "ash/system/tray/tray_views.h" |
13 #include "grit/ash_strings.h" | 13 #include "grit/ash_strings.h" |
14 #include "grit/ui_resources.h" | 14 #include "grit/ui_resources.h" |
15 #include "ui/base/resource/resource_bundle.h" | 15 #include "ui/base/resource/resource_bundle.h" |
16 #include "ui/gfx/image/image.h" | 16 #include "ui/gfx/image/image.h" |
17 #include "ui/views/controls/image_view.h" | 17 #include "ui/views/controls/image_view.h" |
18 #include "ui/views/controls/label.h" | 18 #include "ui/views/controls/label.h" |
19 #include "ui/views/layout/box_layout.h" | 19 #include "ui/views/layout/box_layout.h" |
20 | 20 |
21 namespace { | 21 namespace { |
22 const int kDeviceListHeight = 190; | 22 const int kDeviceListHeight = 276; |
23 } | 23 } |
24 | 24 |
25 namespace ash { | 25 namespace ash { |
26 namespace internal { | 26 namespace internal { |
27 | 27 |
28 namespace tray { | 28 namespace tray { |
29 | 29 |
30 class BluetoothDefaultView : public TrayItemMore { | 30 class BluetoothDefaultView : public TrayItemMore { |
31 public: | 31 public: |
32 explicit BluetoothDefaultView(SystemTrayItem* owner) | 32 explicit BluetoothDefaultView(SystemTrayItem* owner) |
(...skipping 12 matching lines...) Expand all Loading... |
45 SetLabel(rb.GetLocalizedString(delegate->GetBluetoothEnabled() ? | 45 SetLabel(rb.GetLocalizedString(delegate->GetBluetoothEnabled() ? |
46 IDS_ASH_STATUS_TRAY_BLUETOOTH_CONNECTED : | 46 IDS_ASH_STATUS_TRAY_BLUETOOTH_CONNECTED : |
47 IDS_ASH_STATUS_TRAY_BLUETOOTH_DISABLED)); | 47 IDS_ASH_STATUS_TRAY_BLUETOOTH_DISABLED)); |
48 } | 48 } |
49 | 49 |
50 private: | 50 private: |
51 DISALLOW_COPY_AND_ASSIGN(BluetoothDefaultView); | 51 DISALLOW_COPY_AND_ASSIGN(BluetoothDefaultView); |
52 }; | 52 }; |
53 | 53 |
54 class BluetoothDetailedView : public views::View, | 54 class BluetoothDetailedView : public views::View, |
55 public ViewClickListener { | 55 public ViewClickListener, |
| 56 public views::ButtonListener { |
56 public: | 57 public: |
57 explicit BluetoothDetailedView(user::LoginStatus login) | 58 explicit BluetoothDetailedView(user::LoginStatus login) |
58 : login_(login), | 59 : login_(login), |
59 header_(NULL), | 60 header_(NULL), |
| 61 header_text_(NULL), |
60 add_device_(NULL), | 62 add_device_(NULL), |
61 toggle_bluetooth_(NULL) { | 63 toggle_bluetooth_(NULL) { |
62 SetLayoutManager(new views::BoxLayout( | 64 SetLayoutManager(new views::BoxLayout( |
63 views::BoxLayout::kVertical, 0, 0, 0)); | 65 views::BoxLayout::kVertical, 0, 0, 0)); |
64 set_background(views::Background::CreateSolidBackground(kBackgroundColor)); | 66 set_background(views::Background::CreateSolidBackground(kBackgroundColor)); |
65 | 67 |
66 BluetoothDeviceList list; | 68 BluetoothDeviceList list; |
67 Shell::GetInstance()->tray_delegate()->GetAvailableBluetoothDevices(&list); | 69 Shell::GetInstance()->tray_delegate()->GetAvailableBluetoothDevices(&list); |
68 Update(list); | 70 Update(list); |
69 } | 71 } |
70 | 72 |
71 virtual ~BluetoothDetailedView() {} | 73 virtual ~BluetoothDetailedView() {} |
72 | 74 |
73 void Update(const BluetoothDeviceList& list) { | 75 void Update(const BluetoothDeviceList& list) { |
74 RemoveAllChildViews(true); | 76 RemoveAllChildViews(true); |
75 | 77 |
76 header_ = NULL; | 78 header_ = NULL; |
| 79 header_text_ = NULL; |
77 add_device_ = NULL; | 80 add_device_ = NULL; |
78 toggle_bluetooth_ = NULL; | 81 toggle_bluetooth_ = NULL; |
79 | 82 |
80 AppendHeaderEntry(); | 83 AppendHeaderEntry(); |
81 AppendDeviceList(list); | 84 AppendDeviceList(list); |
82 AppendSettingsEntries(); | 85 AppendSettingsEntries(); |
83 | 86 |
84 Layout(); | 87 Layout(); |
85 } | 88 } |
86 | 89 |
87 private: | 90 private: |
88 void AppendHeaderEntry() { | 91 void AppendHeaderEntry() { |
89 header_ = CreateDetailedHeaderEntry(IDS_ASH_STATUS_TRAY_BLUETOOTH, this); | 92 header_ = new views::View; |
| 93 header_->SetLayoutManager(new |
| 94 views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0)); |
90 AddChildView(header_); | 95 AddChildView(header_); |
| 96 |
| 97 header_text_ = CreateDetailedHeaderEntry(IDS_ASH_STATUS_TRAY_BLUETOOTH, |
| 98 this); |
| 99 header_->AddChildView(header_text_); |
| 100 |
| 101 if (login_ == user::LOGGED_IN_LOCKED) |
| 102 return; |
| 103 |
| 104 // Do not allow toggling bluetooth in the lock screen. |
| 105 ash::SystemTrayDelegate* delegate = |
| 106 ash::Shell::GetInstance()->tray_delegate(); |
| 107 toggle_bluetooth_ = new TrayPopupHeaderButton(this, |
| 108 IDR_AURA_UBER_TRAY_BLUETOOTH_ENABLED, |
| 109 IDR_AURA_UBER_TRAY_BLUETOOTH_DISABLED); |
| 110 toggle_bluetooth_->SetToggled(!delegate->GetBluetoothEnabled()); |
| 111 header_->AddChildView(toggle_bluetooth_); |
91 } | 112 } |
92 | 113 |
93 void AppendDeviceList(const BluetoothDeviceList& list) { | 114 void AppendDeviceList(const BluetoothDeviceList& list) { |
94 views::View* devices = new views::View; | 115 views::View* devices = new views::View; |
95 devices->SetLayoutManager(new views::BoxLayout( | 116 devices->SetLayoutManager(new views::BoxLayout( |
96 views::BoxLayout::kVertical, 0, 0, 1)); | 117 views::BoxLayout::kVertical, 0, 0, 1)); |
97 device_map_.clear(); | 118 device_map_.clear(); |
98 | 119 |
99 for (size_t i = 0; i < list.size(); i++) { | 120 for (size_t i = 0; i < list.size(); i++) { |
100 HoverHighlightView* container = new HoverHighlightView(this); | 121 HoverHighlightView* container = new HoverHighlightView(this); |
| 122 container->set_fixed_height(kTrayPopupItemHeight); |
101 container->AddLabel(list[i].display_name, | 123 container->AddLabel(list[i].display_name, |
102 list[i].connected ? gfx::Font::BOLD : gfx::Font::NORMAL); | 124 list[i].connected ? gfx::Font::BOLD : gfx::Font::NORMAL); |
103 devices->AddChildView(container); | 125 devices->AddChildView(container); |
104 device_map_[container] = list[i].address; | 126 device_map_[container] = list[i].address; |
105 } | 127 } |
106 | 128 |
107 FixedSizedScrollView* scroller = new FixedSizedScrollView; | 129 FixedSizedScrollView* scroller = new FixedSizedScrollView; |
108 scroller->set_border(views::Border::CreateSolidSidedBorder(1, 0, 1, 0, | 130 scroller->set_border(views::Border::CreateSolidSidedBorder(1, 0, 1, 0, |
109 SkColorSetARGB(25, 0, 0, 0))); | 131 SkColorSetARGB(25, 0, 0, 0))); |
110 scroller->set_fixed_size( | 132 scroller->set_fixed_size( |
111 gfx::Size(devices->GetPreferredSize().width() + | 133 gfx::Size(devices->GetPreferredSize().width() + |
112 scroller->GetScrollBarWidth(), | 134 scroller->GetScrollBarWidth(), |
113 kDeviceListHeight)); | 135 kDeviceListHeight)); |
114 scroller->SetContentsView(devices); | 136 scroller->SetContentsView(devices); |
115 AddChildView(scroller); | 137 AddChildView(scroller); |
116 } | 138 } |
117 | 139 |
118 // Add settings entries. | 140 // Add settings entries. |
119 void AppendSettingsEntries() { | 141 void AppendSettingsEntries() { |
120 // If screen is locked, hide all settings entries as user should not be able | 142 // Add bluetooth device requires a browser window, hide it for non logged in |
121 // to modify state. | 143 // user. |
122 if (login_ == user::LOGGED_IN_LOCKED) | 144 if (login_ == user::LOGGED_IN_NONE || |
| 145 login_ == user::LOGGED_IN_LOCKED) |
123 return; | 146 return; |
124 | 147 |
125 ash::SystemTrayDelegate* delegate = | 148 ash::SystemTrayDelegate* delegate = |
126 ash::Shell::GetInstance()->tray_delegate(); | 149 ash::Shell::GetInstance()->tray_delegate(); |
| 150 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
127 HoverHighlightView* container = new HoverHighlightView(this); | 151 HoverHighlightView* container = new HoverHighlightView(this); |
128 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 152 container->set_fixed_height(kTrayPopupItemHeight); |
129 container->AddLabel(rb.GetLocalizedString( | 153 container->AddLabel(rb.GetLocalizedString( |
130 delegate->GetBluetoothEnabled() ? | 154 IDS_ASH_STATUS_TRAY_BLUETOOTH_ADD_DEVICE), gfx::Font::NORMAL); |
131 IDS_ASH_STATUS_TRAY_DISABLE_BLUETOOTH : | 155 container->SetEnabled(delegate->GetBluetoothEnabled()); |
132 IDS_ASH_STATUS_TRAY_ENABLE_BLUETOOTH), gfx::Font::NORMAL); | |
133 AddChildView(container); | 156 AddChildView(container); |
134 toggle_bluetooth_ = container; | 157 add_device_ = container; |
| 158 } |
135 | 159 |
136 // Add bluetooth device requires a browser window, hide it for non logged in | 160 // Overridden from views::View. |
137 // user. | 161 virtual void Layout() OVERRIDE { |
138 if (login_ != user::LOGGED_IN_NONE) { | 162 views::View::Layout(); |
139 container = new HoverHighlightView(this); | 163 if (toggle_bluetooth_) { |
140 container->AddLabel(rb.GetLocalizedString( | 164 // Right-align the toggle-bluetooth button. |
141 IDS_ASH_STATUS_TRAY_BLUETOOTH_ADD_DEVICE), gfx::Font::NORMAL); | 165 gfx::Rect header_bounds = header_->bounds(); |
142 AddChildView(container); | 166 gfx::Size button_size = toggle_bluetooth_->size(); |
143 add_device_ = container; | 167 |
| 168 toggle_bluetooth_->SetBounds(header_->width() - button_size.width(), 0, |
| 169 button_size.width(), header_->height()); |
| 170 header_text_->SetBounds(0, 0, header_->width() - button_size.width(), |
| 171 header_->height()); |
144 } | 172 } |
145 } | 173 } |
146 | 174 |
147 // Overridden from ViewClickListener. | 175 // Overridden from ViewClickListener. |
148 virtual void ClickedOn(views::View* sender) OVERRIDE { | 176 virtual void ClickedOn(views::View* sender) OVERRIDE { |
149 ash::SystemTrayDelegate* delegate = | 177 ash::SystemTrayDelegate* delegate = |
150 ash::Shell::GetInstance()->tray_delegate(); | 178 ash::Shell::GetInstance()->tray_delegate(); |
151 if (sender == header_) { | 179 if (sender == header_text_) { |
152 Shell::GetInstance()->tray()->ShowDefaultView(); | 180 Shell::GetInstance()->tray()->ShowDefaultView(); |
153 } else if (sender == toggle_bluetooth_) { | |
154 delegate->ToggleBluetooth(); | |
155 } else if (sender == add_device_) { | 181 } else if (sender == add_device_) { |
156 delegate->AddBluetoothDevice(); | 182 delegate->AddBluetoothDevice(); |
157 } else { | 183 } else { |
158 std::map<views::View*, std::string>::iterator find; | 184 std::map<views::View*, std::string>::iterator find; |
159 find = device_map_.find(sender); | 185 find = device_map_.find(sender); |
160 if (find != device_map_.end()) { | 186 if (find != device_map_.end()) { |
161 std::string device_id = find->second; | 187 std::string device_id = find->second; |
162 delegate->ToggleBluetoothConnection(device_id); | 188 delegate->ToggleBluetoothConnection(device_id); |
163 } | 189 } |
164 } | 190 } |
165 } | 191 } |
166 | 192 |
| 193 // Overridden from ButtonListener. |
| 194 virtual void ButtonPressed(views::Button* sender, |
| 195 const views::Event& event) OVERRIDE { |
| 196 ash::SystemTrayDelegate* delegate = |
| 197 ash::Shell::GetInstance()->tray_delegate(); |
| 198 if (sender == toggle_bluetooth_) |
| 199 delegate->ToggleBluetooth(); |
| 200 else |
| 201 NOTREACHED(); |
| 202 } |
| 203 |
167 user::LoginStatus login_; | 204 user::LoginStatus login_; |
168 | 205 |
169 std::map<views::View*, std::string> device_map_; | 206 std::map<views::View*, std::string> device_map_; |
170 views::View* header_; | 207 views::View* header_; |
| 208 views::View* header_text_; |
171 views::View* add_device_; | 209 views::View* add_device_; |
172 views::View* toggle_bluetooth_; | 210 TrayPopupHeaderButton* toggle_bluetooth_; |
173 views::View* settings_; | 211 views::View* settings_; |
174 | 212 |
175 DISALLOW_COPY_AND_ASSIGN(BluetoothDetailedView); | 213 DISALLOW_COPY_AND_ASSIGN(BluetoothDetailedView); |
176 }; | 214 }; |
177 | 215 |
178 } // namespace tray | 216 } // namespace tray |
179 | 217 |
180 TrayBluetooth::TrayBluetooth() { | 218 TrayBluetooth::TrayBluetooth() { |
181 } | 219 } |
182 | 220 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 BluetoothDeviceList list; | 254 BluetoothDeviceList list; |
217 Shell::GetInstance()->tray_delegate()->GetAvailableBluetoothDevices(&list); | 255 Shell::GetInstance()->tray_delegate()->GetAvailableBluetoothDevices(&list); |
218 if (default_.get()) | 256 if (default_.get()) |
219 default_->UpdateLabel(); | 257 default_->UpdateLabel(); |
220 if (detailed_.get()) | 258 if (detailed_.get()) |
221 detailed_->Update(list); | 259 detailed_->Update(list); |
222 } | 260 } |
223 | 261 |
224 } // namespace internal | 262 } // namespace internal |
225 } // namespace ash | 263 } // namespace ash |
OLD | NEW |