| 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/system/public/system_ui.h" | 5 #include "athena/system/public/system_ui.h" |
| 6 | 6 |
| 7 #include "athena/common/container_priorities.h" | 7 #include "athena/common/container_priorities.h" |
| 8 #include "athena/common/fill_layout_manager.h" | 8 #include "athena/common/fill_layout_manager.h" |
| 9 #include "athena/screen/public/screen_manager.h" | 9 #include "athena/screen/public/screen_manager.h" |
| 10 #include "athena/system/background_controller.h" | 10 #include "athena/system/background_controller.h" |
| 11 #include "athena/system/device_socket_listener.h" | 11 #include "athena/system/device_socket_listener.h" |
| 12 #include "athena/system/orientation_controller.h" | 12 #include "athena/system/orientation_controller.h" |
| 13 #include "athena/system/power_button_controller.h" | 13 #include "athena/system/power_button_controller.h" |
| 14 #include "athena/system/status_icon_container_view.h" | 14 #include "athena/system/status_icon_container_view.h" |
| 15 #include "athena/system/time_view.h" | 15 #include "athena/system/time_view.h" |
| 16 #include "base/logging.h" | 16 #include "base/logging.h" |
| 17 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
| 18 #include "base/memory/scoped_ptr.h" | 18 #include "base/memory/scoped_ptr.h" |
| 19 #include "ui/aura/window.h" | 19 #include "ui/aura/window.h" |
| 20 #include "ui/views/view.h" |
| 20 | 21 |
| 21 namespace athena { | 22 namespace athena { |
| 22 namespace { | 23 namespace { |
| 23 | 24 |
| 24 SystemUI* instance = NULL; | 25 SystemUI* instance = NULL; |
| 25 | 26 |
| 27 // View which positions the TimeView on the left and the StatusIconView on the |
| 28 // right. |
| 29 class SystemInfoView : public views::View { |
| 30 public: |
| 31 SystemInfoView(SystemUI::ColorScheme color_scheme, |
| 32 aura::Window* system_modal_container) |
| 33 : time_view_(new TimeView(color_scheme)), |
| 34 status_icon_view_( |
| 35 new StatusIconContainerView(color_scheme, system_modal_container)) { |
| 36 AddChildView(time_view_); |
| 37 AddChildView(status_icon_view_); |
| 38 } |
| 39 |
| 40 virtual ~SystemInfoView() { |
| 41 } |
| 42 |
| 43 // views::View: |
| 44 virtual gfx::Size GetPreferredSize() const OVERRIDE { |
| 45 // The view should be as wide as its parent view. |
| 46 return gfx::Size(0, |
| 47 std::max(time_view_->GetPreferredSize().height(), |
| 48 status_icon_view_->GetPreferredSize().height())); |
| 49 } |
| 50 |
| 51 virtual void Layout() OVERRIDE { |
| 52 time_view_->SetBoundsRect(gfx::Rect(time_view_->GetPreferredSize())); |
| 53 gfx::Size status_icon_preferred_size = |
| 54 status_icon_view_->GetPreferredSize(); |
| 55 status_icon_view_->SetBoundsRect( |
| 56 gfx::Rect(width() - status_icon_preferred_size.width(), |
| 57 0, |
| 58 status_icon_preferred_size.width(), |
| 59 status_icon_preferred_size.height())); |
| 60 } |
| 61 |
| 62 virtual void ChildPreferredSizeChanged(views::View* child) OVERRIDE { |
| 63 // Relayout to take into account changes in |status_icon_view_|'s width. |
| 64 // Assume that |time_view_|'s and |status_icon_view_|'s preferred height |
| 65 // does not change. |
| 66 Layout(); |
| 67 } |
| 68 |
| 69 private: |
| 70 views::View* time_view_; |
| 71 views::View* status_icon_view_; |
| 72 |
| 73 DISALLOW_COPY_AND_ASSIGN(SystemInfoView); |
| 74 }; |
| 75 |
| 26 class SystemUIImpl : public SystemUI { | 76 class SystemUIImpl : public SystemUI { |
| 27 public: | 77 public: |
| 28 SystemUIImpl(scoped_refptr<base::TaskRunner> file_task_runner) | 78 SystemUIImpl(scoped_refptr<base::TaskRunner> file_task_runner) |
| 29 : orientation_controller_(new OrientationController()), | 79 : orientation_controller_(new OrientationController()), |
| 30 power_button_controller_(new PowerButtonController), | 80 power_button_controller_(new PowerButtonController), |
| 31 background_container_(NULL), | 81 background_container_(NULL), |
| 32 system_modal_container_(NULL) { | 82 system_modal_container_(NULL) { |
| 33 orientation_controller_->InitWith(file_task_runner); | 83 orientation_controller_->InitWith(file_task_runner); |
| 34 } | 84 } |
| 35 | 85 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 51 ScreenManager::Get()->CreateContainer(system_modal_params); | 101 ScreenManager::Get()->CreateContainer(system_modal_params); |
| 52 | 102 |
| 53 background_controller_.reset( | 103 background_controller_.reset( |
| 54 new BackgroundController(background_container_)); | 104 new BackgroundController(background_container_)); |
| 55 } | 105 } |
| 56 | 106 |
| 57 virtual void SetBackgroundImage(const gfx::ImageSkia& image) OVERRIDE { | 107 virtual void SetBackgroundImage(const gfx::ImageSkia& image) OVERRIDE { |
| 58 background_controller_->SetImage(image); | 108 background_controller_->SetImage(image); |
| 59 } | 109 } |
| 60 | 110 |
| 61 virtual views::View* CreateTimeView() OVERRIDE { | 111 virtual views::View* CreateSystemInfoView(ColorScheme color_scheme) OVERRIDE { |
| 62 return new TimeView; | 112 return new SystemInfoView(color_scheme, system_modal_container_); |
| 63 } | |
| 64 | |
| 65 virtual views::View* CreateStatusIconView() OVERRIDE { | |
| 66 return new StatusIconContainerView(system_modal_container_); | |
| 67 } | 113 } |
| 68 | 114 |
| 69 private: | 115 private: |
| 70 scoped_refptr<OrientationController> orientation_controller_; | 116 scoped_refptr<OrientationController> orientation_controller_; |
| 71 scoped_ptr<PowerButtonController> power_button_controller_; | 117 scoped_ptr<PowerButtonController> power_button_controller_; |
| 72 scoped_ptr<BackgroundController> background_controller_; | 118 scoped_ptr<BackgroundController> background_controller_; |
| 73 | 119 |
| 74 // The parent container for the background. | 120 // The parent container for the background. |
| 75 aura::Window* background_container_; | 121 aura::Window* background_container_; |
| 76 | 122 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 99 | 145 |
| 100 // static | 146 // static |
| 101 void SystemUI::Shutdown() { | 147 void SystemUI::Shutdown() { |
| 102 CHECK(instance); | 148 CHECK(instance); |
| 103 delete instance; | 149 delete instance; |
| 104 instance = NULL; | 150 instance = NULL; |
| 105 DeviceSocketListener::ShutdownSocketManager(); | 151 DeviceSocketListener::ShutdownSocketManager(); |
| 106 } | 152 } |
| 107 | 153 |
| 108 } // namespace athena | 154 } // namespace athena |
| OLD | NEW |