Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(319)

Side by Side Diff: ash/system/bluetooth/tray_bluetooth.cc

Issue 10384178: ash: Make sure all the sub-popups retain the same height as the main popup. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ash/ash.gyp ('k') | ash/system/drive/tray_drive.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_details_view.h"
11 #include "ash/system/tray/tray_item_more.h" 12 #include "ash/system/tray/tray_item_more.h"
12 #include "ash/system/tray/tray_views.h" 13 #include "ash/system/tray/tray_views.h"
13 #include "grit/ash_strings.h" 14 #include "grit/ash_strings.h"
14 #include "grit/ui_resources.h" 15 #include "grit/ui_resources.h"
15 #include "ui/base/resource/resource_bundle.h" 16 #include "ui/base/resource/resource_bundle.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/layout/box_layout.h" 20 #include "ui/views/layout/box_layout.h"
20 21
(...skipping 28 matching lines...) Expand all
49 SetVisible(true); 50 SetVisible(true);
50 } else { 51 } else {
51 SetVisible(false); 52 SetVisible(false);
52 } 53 }
53 } 54 }
54 55
55 private: 56 private:
56 DISALLOW_COPY_AND_ASSIGN(BluetoothDefaultView); 57 DISALLOW_COPY_AND_ASSIGN(BluetoothDefaultView);
57 }; 58 };
58 59
59 class BluetoothDetailedView : public views::View, 60 class BluetoothDetailedView : public TrayDetailsView,
60 public ViewClickListener, 61 public ViewClickListener,
61 public views::ButtonListener { 62 public views::ButtonListener {
62 public: 63 public:
63 explicit BluetoothDetailedView(user::LoginStatus login) 64 explicit BluetoothDetailedView(user::LoginStatus login)
64 : login_(login), 65 : login_(login),
65 header_(NULL),
66 add_device_(NULL), 66 add_device_(NULL),
67 toggle_bluetooth_(NULL) { 67 toggle_bluetooth_(NULL) {
68 SetLayoutManager(new views::BoxLayout(
69 views::BoxLayout::kVertical, 0, 0, 0));
70 set_background(views::Background::CreateSolidBackground(kBackgroundColor));
71
72 BluetoothDeviceList list; 68 BluetoothDeviceList list;
73 Shell::GetInstance()->tray_delegate()->GetAvailableBluetoothDevices(&list); 69 Shell::GetInstance()->tray_delegate()->GetAvailableBluetoothDevices(&list);
74 Update(list); 70 Update(list);
75 } 71 }
76 72
77 virtual ~BluetoothDetailedView() {} 73 virtual ~BluetoothDetailedView() {}
78 74
79 void Update(const BluetoothDeviceList& list) { 75 void Update(const BluetoothDeviceList& list) {
80 RemoveAllChildViews(true); 76 Reset();
81 77
82 header_ = NULL;
83 add_device_ = NULL; 78 add_device_ = NULL;
84 toggle_bluetooth_ = NULL; 79 toggle_bluetooth_ = NULL;
85 80
86 AppendDeviceList(list); 81 AppendDeviceList(list);
87 AppendSettingsEntries(); 82 AppendSettingsEntries();
88 AppendHeaderEntry(); 83 AppendHeaderEntry();
89 84
90 Layout(); 85 Layout();
91 } 86 }
92 87
93 private: 88 private:
94 void AppendHeaderEntry() { 89 void AppendHeaderEntry() {
95 header_ = new SpecialPopupRow(); 90 CreateSpecialRow(IDS_ASH_STATUS_TRAY_BLUETOOTH, this);
96 header_->SetTextLabel(IDS_ASH_STATUS_TRAY_BLUETOOTH, this);
97 AddChildView(header_);
98 91
99 if (login_ == user::LOGGED_IN_LOCKED) 92 if (login_ == user::LOGGED_IN_LOCKED)
100 return; 93 return;
101 94
102 // Do not allow toggling bluetooth in the lock screen. 95 // Do not allow toggling bluetooth in the lock screen.
103 ash::SystemTrayDelegate* delegate = 96 ash::SystemTrayDelegate* delegate =
104 ash::Shell::GetInstance()->tray_delegate(); 97 ash::Shell::GetInstance()->tray_delegate();
105 toggle_bluetooth_ = new TrayPopupHeaderButton(this, 98 toggle_bluetooth_ = new TrayPopupHeaderButton(this,
106 IDR_AURA_UBER_TRAY_BLUETOOTH_ENABLED, 99 IDR_AURA_UBER_TRAY_BLUETOOTH_ENABLED,
107 IDR_AURA_UBER_TRAY_BLUETOOTH_DISABLED, 100 IDR_AURA_UBER_TRAY_BLUETOOTH_DISABLED,
108 IDR_AURA_UBER_TRAY_BLUETOOTH_ENABLED_HOVER, 101 IDR_AURA_UBER_TRAY_BLUETOOTH_ENABLED_HOVER,
109 IDR_AURA_UBER_TRAY_BLUETOOTH_DISABLED_HOVER); 102 IDR_AURA_UBER_TRAY_BLUETOOTH_DISABLED_HOVER);
110 toggle_bluetooth_->SetToggled(!delegate->GetBluetoothEnabled()); 103 toggle_bluetooth_->SetToggled(!delegate->GetBluetoothEnabled());
111 header_->AddButton(toggle_bluetooth_); 104 footer()->AddButton(toggle_bluetooth_);
112 } 105 }
113 106
114 void AppendDeviceList(const BluetoothDeviceList& list) { 107 void AppendDeviceList(const BluetoothDeviceList& list) {
115 views::View* devices = new views::View;
116 devices->SetLayoutManager(new views::BoxLayout(
117 views::BoxLayout::kVertical, 0, 0, 1));
118 device_map_.clear(); 108 device_map_.clear();
109 CreateScrollableList();
119 110
120 for (size_t i = 0; i < list.size(); i++) { 111 for (size_t i = 0; i < list.size(); i++) {
121 HoverHighlightView* container = new HoverHighlightView(this); 112 HoverHighlightView* container = new HoverHighlightView(this);
122 container->set_fixed_height(kTrayPopupItemHeight); 113 container->set_fixed_height(kTrayPopupItemHeight);
123 container->AddLabel(list[i].display_name, 114 container->AddLabel(list[i].display_name,
124 list[i].connected ? gfx::Font::BOLD : gfx::Font::NORMAL); 115 list[i].connected ? gfx::Font::BOLD : gfx::Font::NORMAL);
125 devices->AddChildView(container); 116 scroll_content()->AddChildView(container);
126 device_map_[container] = list[i].address; 117 device_map_[container] = list[i].address;
127 } 118 }
128
129 FixedSizedScrollView* scroller = new FixedSizedScrollView;
130 scroller->set_border(views::Border::CreateSolidSidedBorder(1, 0, 1, 0,
131 SkColorSetARGB(25, 0, 0, 0)));
132 scroller->set_fixed_size(
133 gfx::Size(devices->GetPreferredSize().width() +
134 scroller->GetScrollBarWidth(),
135 kDeviceListHeight));
136 scroller->SetContentsView(devices);
137 AddChildView(scroller);
138 } 119 }
139 120
140 // Add settings entries. 121 // Add settings entries.
141 void AppendSettingsEntries() { 122 void AppendSettingsEntries() {
142 // Add bluetooth device requires a browser window, hide it for non logged in 123 // Add bluetooth device requires a browser window, hide it for non logged in
143 // user. 124 // user.
144 if (login_ == user::LOGGED_IN_NONE || 125 if (login_ == user::LOGGED_IN_NONE ||
145 login_ == user::LOGGED_IN_LOCKED) 126 login_ == user::LOGGED_IN_LOCKED)
146 return; 127 return;
147 128
148 ash::SystemTrayDelegate* delegate = 129 ash::SystemTrayDelegate* delegate =
149 ash::Shell::GetInstance()->tray_delegate(); 130 ash::Shell::GetInstance()->tray_delegate();
150 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 131 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
151 HoverHighlightView* container = new HoverHighlightView(this); 132 HoverHighlightView* container = new HoverHighlightView(this);
152 container->set_fixed_height(kTrayPopupItemHeight); 133 container->set_fixed_height(kTrayPopupItemHeight);
153 container->AddLabel(rb.GetLocalizedString( 134 container->AddLabel(rb.GetLocalizedString(
154 IDS_ASH_STATUS_TRAY_BLUETOOTH_ADD_DEVICE), gfx::Font::NORMAL); 135 IDS_ASH_STATUS_TRAY_BLUETOOTH_ADD_DEVICE), gfx::Font::NORMAL);
155 container->SetEnabled(delegate->GetBluetoothEnabled()); 136 container->SetEnabled(delegate->GetBluetoothEnabled());
156 AddChildView(container); 137 AddChildView(container);
157 add_device_ = container; 138 add_device_ = container;
158 } 139 }
159 140
160 // Overridden from ViewClickListener. 141 // Overridden from ViewClickListener.
161 virtual void ClickedOn(views::View* sender) OVERRIDE { 142 virtual void ClickedOn(views::View* sender) OVERRIDE {
162 ash::SystemTrayDelegate* delegate = 143 ash::SystemTrayDelegate* delegate =
163 ash::Shell::GetInstance()->tray_delegate(); 144 ash::Shell::GetInstance()->tray_delegate();
164 if (sender == header_->content()) { 145 if (sender == footer()->content()) {
165 Shell::GetInstance()->tray()->ShowDefaultView(); 146 Shell::GetInstance()->tray()->ShowDefaultView(BUBBLE_USE_EXISTING);
166 } else if (sender == add_device_) { 147 } else if (sender == add_device_) {
167 delegate->AddBluetoothDevice(); 148 delegate->AddBluetoothDevice();
168 } else { 149 } else {
169 std::map<views::View*, std::string>::iterator find; 150 std::map<views::View*, std::string>::iterator find;
170 find = device_map_.find(sender); 151 find = device_map_.find(sender);
171 if (find != device_map_.end()) { 152 if (find != device_map_.end()) {
172 std::string device_id = find->second; 153 std::string device_id = find->second;
173 delegate->ToggleBluetoothConnection(device_id); 154 delegate->ToggleBluetoothConnection(device_id);
174 } 155 }
175 } 156 }
176 } 157 }
177 158
178 // Overridden from ButtonListener. 159 // Overridden from ButtonListener.
179 virtual void ButtonPressed(views::Button* sender, 160 virtual void ButtonPressed(views::Button* sender,
180 const views::Event& event) OVERRIDE { 161 const views::Event& event) OVERRIDE {
181 ash::SystemTrayDelegate* delegate = 162 ash::SystemTrayDelegate* delegate =
182 ash::Shell::GetInstance()->tray_delegate(); 163 ash::Shell::GetInstance()->tray_delegate();
183 if (sender == toggle_bluetooth_) 164 if (sender == toggle_bluetooth_)
184 delegate->ToggleBluetooth(); 165 delegate->ToggleBluetooth();
185 else 166 else
186 NOTREACHED(); 167 NOTREACHED();
187 } 168 }
188 169
189 user::LoginStatus login_; 170 user::LoginStatus login_;
190 171
191 std::map<views::View*, std::string> device_map_; 172 std::map<views::View*, std::string> device_map_;
192 SpecialPopupRow* header_;
193 views::View* add_device_; 173 views::View* add_device_;
194 TrayPopupHeaderButton* toggle_bluetooth_; 174 TrayPopupHeaderButton* toggle_bluetooth_;
195 views::View* settings_; 175 views::View* settings_;
196 176
197 DISALLOW_COPY_AND_ASSIGN(BluetoothDetailedView); 177 DISALLOW_COPY_AND_ASSIGN(BluetoothDetailedView);
198 }; 178 };
199 179
200 } // namespace tray 180 } // namespace tray
201 181
202 TrayBluetooth::TrayBluetooth() 182 TrayBluetooth::TrayBluetooth()
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 BluetoothDeviceList list; 223 BluetoothDeviceList list;
244 Shell::GetInstance()->tray_delegate()->GetAvailableBluetoothDevices(&list); 224 Shell::GetInstance()->tray_delegate()->GetAvailableBluetoothDevices(&list);
245 if (default_) 225 if (default_)
246 default_->UpdateLabel(); 226 default_->UpdateLabel();
247 else if (detailed_) 227 else if (detailed_)
248 detailed_->Update(list); 228 detailed_->Update(list);
249 } 229 }
250 230
251 } // namespace internal 231 } // namespace internal
252 } // namespace ash 232 } // namespace ash
OLDNEW
« no previous file with comments | « ash/ash.gyp ('k') | ash/system/drive/tray_drive.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698