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

Side by Side Diff: athena/main/debug/debug_window.cc

Issue 425783003: athena: Add a network-selector widget. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: tot-merge Created 6 years, 4 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
OLDNEW
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
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 class X : public ui::EventHandler {
158 public:
159 explicit X(aura::Window* container) : container_(container) {}
160 virtual ~X() {}
161
162 private:
163 // ui::EventHandler:
164 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE {
165 if (event->type() == ui::ET_MOUSE_PRESSED) {
166 debug::CreateNetworkSelector(container_);
167 event->SetHandled();
168 }
169 }
170
171 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE {
172 if (event->type() == ui::ET_GESTURE_TAP) {
173 debug::CreateNetworkSelector(container_);
174 event->SetHandled();
175 }
176 }
177
178 aura::Window* container_;
179
180 DISALLOW_COPY_AND_ASSIGN(X);
181 };
182
156 class DebugWidget { 183 class DebugWidget {
157 public: 184 public:
158 DebugWidget() : container_(NULL), widget_(NULL) { 185 DebugWidget() : container_(NULL), widget_(NULL) {
159 CreateContainer(); 186 CreateContainer();
160 CreateWidget(); 187 CreateWidget();
161 188
162 CreateBatteryView(); 189 CreateBatteryView();
163 CreateNetworkView(); 190 CreateNetworkView();
164 191
165 UpdateSize(); 192 UpdateSize();
166 } 193 }
167 194
168 virtual ~DebugWidget() {} 195 virtual ~DebugWidget() {}
169 196
170 private: 197 private:
171 void CreateContainer() { 198 void CreateContainer() {
172 athena::ScreenManager::ContainerParams params("DebugContainer", 199 athena::ScreenManager::ContainerParams params("DebugContainer",
173 athena::CP_DEBUG); 200 athena::CP_DEBUG);
201 params.can_activate_children = true;
174 container_ = athena::ScreenManager::Get()->CreateContainer(params); 202 container_ = athena::ScreenManager::Get()->CreateContainer(params);
175 } 203 }
176 204
177 void CreateWidget() { 205 void CreateWidget() {
178 views::Widget::InitParams params; 206 views::Widget::InitParams params;
179 params.type = views::Widget::InitParams::TYPE_WINDOW_FRAMELESS; 207 params.type = views::Widget::InitParams::TYPE_WINDOW_FRAMELESS;
180 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; 208 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
181 params.activatable = views::Widget::InitParams::ACTIVATABLE_NO; 209 params.activatable = views::Widget::InitParams::ACTIVATABLE_NO;
182 params.accept_events = false; 210 params.accept_events = true;
183 params.bounds = gfx::Rect(200, 0, 100, 105); 211 params.bounds = gfx::Rect(200, 0, 100, 105);
184 params.parent = container_; 212 params.parent = container_;
185 widget_ = new views::Widget(); 213 widget_ = new views::Widget();
186 widget_->Init(params); 214 widget_->Init(params);
187 215
216 event_handler_.reset(new X(container_));
217
188 const int kHorizontalSpacing = 10; 218 const int kHorizontalSpacing = 10;
189 const int kBorderVerticalSpacing = 3; 219 const int kBorderVerticalSpacing = 3;
190 const int kBetweenChildSpacing = 10; 220 const int kBetweenChildSpacing = 10;
191 const int kBackgroundColor = SkColorSetARGB(0x7f, 0, 0, 0); 221 const int kBackgroundColor = SkColorSetARGB(0x7f, 0, 0, 0);
192 views::View* container = new views::View; 222 views::View* container = new views::View;
193 container->SetLayoutManager( 223 container->SetLayoutManager(
194 new views::BoxLayout(views::BoxLayout::kHorizontal, 224 new views::BoxLayout(views::BoxLayout::kHorizontal,
195 kHorizontalSpacing, 225 kHorizontalSpacing,
196 kBorderVerticalSpacing, 226 kBorderVerticalSpacing,
197 kBetweenChildSpacing)); 227 kBetweenChildSpacing));
198 container->set_background( 228 container->set_background(
199 views::Background::CreateSolidBackground(kBackgroundColor)); 229 views::Background::CreateSolidBackground(kBackgroundColor));
200 container->SetBorder(views::Border::CreateSolidBorder(1, kBackgroundColor)); 230 container->SetBorder(views::Border::CreateSolidBorder(1, kBackgroundColor));
231 container->set_target_handler(event_handler_.get());
201 widget_->SetContentsView(container); 232 widget_->SetContentsView(container);
202 widget_->StackAtTop(); 233 widget_->StackAtTop();
203 widget_->Show(); 234 widget_->Show();
204 235
205 widget_->SetBounds(gfx::Rect(600, 0, 300, 25)); 236 widget_->SetBounds(gfx::Rect(600, 0, 300, 25));
206 } 237 }
207 238
208 void CreateBatteryView() { 239 void CreateBatteryView() {
209 views::View* container = widget_->GetContentsView(); 240 views::View* container = widget_->GetContentsView();
210 views::ImageView* icon = new views::ImageView(); 241 views::ImageView* icon = new views::ImageView();
(...skipping 26 matching lines...) Expand all
237 views::View* container = widget_->GetContentsView(); 268 views::View* container = widget_->GetContentsView();
238 container->Layout(); 269 container->Layout();
239 gfx::Size size = container->GetPreferredSize(); 270 gfx::Size size = container->GetPreferredSize();
240 widget_->SetBounds(GetPositionForSize(size)); 271 widget_->SetBounds(GetPositionForSize(size));
241 } 272 }
242 273
243 aura::Window* container_; 274 aura::Window* container_;
244 views::Widget* widget_; 275 views::Widget* widget_;
245 scoped_ptr<PowerStatus> power_status_; 276 scoped_ptr<PowerStatus> power_status_;
246 scoped_ptr<NetworkStatus> network_status_; 277 scoped_ptr<NetworkStatus> network_status_;
278 scoped_ptr<ui::EventHandler> event_handler_;
247 279
248 DISALLOW_COPY_AND_ASSIGN(DebugWidget); 280 DISALLOW_COPY_AND_ASSIGN(DebugWidget);
249 }; 281 };
250 282
251 } // namespace 283 } // namespace
252 284
253 void CreateDebugWindow() { 285 void CreateDebugWindow() {
254 new DebugWidget(); 286 new DebugWidget();
255 } 287 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698