OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "athena/main/debug/debug_window.h" | 5 #include "athena/main/debug/debug_window.h" |
6 | 6 |
7 #include "athena/common/container_priorities.h" | 7 #include "athena/common/container_priorities.h" |
| 8 #include "athena/main/debug/network_selector.h" |
8 #include "athena/resources/athena_resources.h" | 9 #include "athena/resources/athena_resources.h" |
9 #include "athena/screen/public/screen_manager.h" | 10 #include "athena/screen/public/screen_manager.h" |
10 #include "base/bind.h" | 11 #include "base/bind.h" |
11 #include "base/macros.h" | 12 #include "base/macros.h" |
12 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
13 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
14 #include "chromeos/dbus/dbus_thread_manager.h" | 15 #include "chromeos/dbus/dbus_thread_manager.h" |
15 #include "chromeos/dbus/power_manager/power_supply_properties.pb.h" | 16 #include "chromeos/dbus/power_manager/power_supply_properties.pb.h" |
16 #include "chromeos/dbus/power_manager_client.h" | 17 #include "chromeos/dbus/power_manager_client.h" |
17 #include "chromeos/network/network_state.h" | 18 #include "chromeos/network/network_state.h" |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 | 147 |
147 virtual void NetworkPropertiesUpdated( | 148 virtual void NetworkPropertiesUpdated( |
148 const chromeos::NetworkState* network) OVERRIDE { | 149 const chromeos::NetworkState* network) OVERRIDE { |
149 Update(); | 150 Update(); |
150 } | 151 } |
151 | 152 |
152 views::Label* label_; | 153 views::Label* label_; |
153 base::Closure closure_; | 154 base::Closure closure_; |
154 }; | 155 }; |
155 | 156 |
| 157 // Processes user input to show the detailed network-list. |
| 158 class DetailViewHandler : public ui::EventHandler { |
| 159 public: |
| 160 explicit DetailViewHandler(aura::Window* container) : container_(container) {} |
| 161 virtual ~DetailViewHandler() {} |
| 162 |
| 163 private: |
| 164 // ui::EventHandler: |
| 165 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE { |
| 166 if (event->type() == ui::ET_MOUSE_PRESSED) { |
| 167 debug::CreateNetworkSelector(container_); |
| 168 event->SetHandled(); |
| 169 } |
| 170 } |
| 171 |
| 172 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE { |
| 173 if (event->type() == ui::ET_GESTURE_TAP) { |
| 174 debug::CreateNetworkSelector(container_); |
| 175 event->SetHandled(); |
| 176 } |
| 177 } |
| 178 |
| 179 aura::Window* container_; |
| 180 |
| 181 DISALLOW_COPY_AND_ASSIGN(DetailViewHandler); |
| 182 }; |
| 183 |
156 class DebugWidget { | 184 class DebugWidget { |
157 public: | 185 public: |
158 DebugWidget() : container_(NULL), widget_(NULL) { | 186 DebugWidget() : container_(NULL), widget_(NULL) { |
159 CreateContainer(); | 187 CreateContainer(); |
160 CreateWidget(); | 188 CreateWidget(); |
161 | 189 |
162 CreateBatteryView(); | 190 CreateBatteryView(); |
163 CreateNetworkView(); | 191 CreateNetworkView(); |
164 | 192 |
165 UpdateSize(); | 193 UpdateSize(); |
166 } | 194 } |
167 | 195 |
168 virtual ~DebugWidget() {} | 196 virtual ~DebugWidget() {} |
169 | 197 |
170 private: | 198 private: |
171 void CreateContainer() { | 199 void CreateContainer() { |
172 athena::ScreenManager::ContainerParams params("DebugContainer", | 200 athena::ScreenManager::ContainerParams params("DebugContainer", |
173 athena::CP_DEBUG); | 201 athena::CP_DEBUG); |
| 202 params.can_activate_children = true; |
174 container_ = athena::ScreenManager::Get()->CreateContainer(params); | 203 container_ = athena::ScreenManager::Get()->CreateContainer(params); |
175 } | 204 } |
176 | 205 |
177 void CreateWidget() { | 206 void CreateWidget() { |
178 views::Widget::InitParams params; | 207 views::Widget::InitParams params; |
179 params.type = views::Widget::InitParams::TYPE_WINDOW_FRAMELESS; | 208 params.type = views::Widget::InitParams::TYPE_WINDOW_FRAMELESS; |
180 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; | 209 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; |
181 params.activatable = views::Widget::InitParams::ACTIVATABLE_NO; | 210 params.activatable = views::Widget::InitParams::ACTIVATABLE_NO; |
182 params.accept_events = false; | 211 params.accept_events = true; |
183 params.bounds = gfx::Rect(200, 0, 100, 105); | 212 params.bounds = gfx::Rect(200, 0, 100, 105); |
184 params.parent = container_; | 213 params.parent = container_; |
185 widget_ = new views::Widget(); | 214 widget_ = new views::Widget(); |
186 widget_->Init(params); | 215 widget_->Init(params); |
187 | 216 |
| 217 event_handler_.reset(new DetailViewHandler(container_)); |
| 218 |
188 const int kHorizontalSpacing = 10; | 219 const int kHorizontalSpacing = 10; |
189 const int kBorderVerticalSpacing = 3; | 220 const int kBorderVerticalSpacing = 3; |
190 const int kBetweenChildSpacing = 10; | 221 const int kBetweenChildSpacing = 10; |
191 const int kBackgroundColor = SkColorSetARGB(0x7f, 0, 0, 0); | 222 const int kBackgroundColor = SkColorSetARGB(0x7f, 0, 0, 0); |
192 views::View* container = new views::View; | 223 views::View* container = new views::View; |
193 container->SetLayoutManager( | 224 container->SetLayoutManager( |
194 new views::BoxLayout(views::BoxLayout::kHorizontal, | 225 new views::BoxLayout(views::BoxLayout::kHorizontal, |
195 kHorizontalSpacing, | 226 kHorizontalSpacing, |
196 kBorderVerticalSpacing, | 227 kBorderVerticalSpacing, |
197 kBetweenChildSpacing)); | 228 kBetweenChildSpacing)); |
198 container->set_background( | 229 container->set_background( |
199 views::Background::CreateSolidBackground(kBackgroundColor)); | 230 views::Background::CreateSolidBackground(kBackgroundColor)); |
200 container->SetBorder(views::Border::CreateSolidBorder(1, kBackgroundColor)); | 231 container->SetBorder(views::Border::CreateSolidBorder(1, kBackgroundColor)); |
| 232 container->set_target_handler(event_handler_.get()); |
201 widget_->SetContentsView(container); | 233 widget_->SetContentsView(container); |
202 widget_->StackAtTop(); | 234 widget_->StackAtTop(); |
203 widget_->Show(); | 235 widget_->Show(); |
204 | 236 |
205 widget_->SetBounds(gfx::Rect(600, 0, 300, 25)); | 237 widget_->SetBounds(gfx::Rect(600, 0, 300, 25)); |
206 } | 238 } |
207 | 239 |
208 void CreateBatteryView() { | 240 void CreateBatteryView() { |
209 views::View* container = widget_->GetContentsView(); | 241 views::View* container = widget_->GetContentsView(); |
210 views::ImageView* icon = new views::ImageView(); | 242 views::ImageView* icon = new views::ImageView(); |
(...skipping 26 matching lines...) Expand all Loading... |
237 views::View* container = widget_->GetContentsView(); | 269 views::View* container = widget_->GetContentsView(); |
238 container->Layout(); | 270 container->Layout(); |
239 gfx::Size size = container->GetPreferredSize(); | 271 gfx::Size size = container->GetPreferredSize(); |
240 widget_->SetBounds(GetPositionForSize(size)); | 272 widget_->SetBounds(GetPositionForSize(size)); |
241 } | 273 } |
242 | 274 |
243 aura::Window* container_; | 275 aura::Window* container_; |
244 views::Widget* widget_; | 276 views::Widget* widget_; |
245 scoped_ptr<PowerStatus> power_status_; | 277 scoped_ptr<PowerStatus> power_status_; |
246 scoped_ptr<NetworkStatus> network_status_; | 278 scoped_ptr<NetworkStatus> network_status_; |
| 279 scoped_ptr<ui::EventHandler> event_handler_; |
247 | 280 |
248 DISALLOW_COPY_AND_ASSIGN(DebugWidget); | 281 DISALLOW_COPY_AND_ASSIGN(DebugWidget); |
249 }; | 282 }; |
250 | 283 |
251 } // namespace | 284 } // namespace |
252 | 285 |
253 void CreateDebugWindow() { | 286 void CreateDebugWindow() { |
254 new DebugWidget(); | 287 new DebugWidget(); |
255 } | 288 } |
OLD | NEW |