| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/chromeos/status/status_area_view.h" | 5 #include "chrome/browser/chromeos/status/status_area_view.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "chrome/browser/chromeos/status/clock_menu_button.h" | 9 #include "chrome/browser/chromeos/status/clock_menu_button.h" |
| 10 #include "chrome/browser/chromeos/status/input_method_menu_button.h" | 10 #include "chrome/browser/chromeos/status/input_method_menu_button.h" |
| 11 #include "chrome/browser/chromeos/status/network_menu_button.h" | 11 #include "chrome/browser/chromeos/status/network_menu_button.h" |
| 12 #include "chrome/browser/chromeos/status/power_menu_button.h" | 12 #include "chrome/browser/chromeos/status/power_menu_button.h" |
| 13 #include "chrome/browser/chromeos/status/status_area_host.h" | 13 #include "chrome/browser/chromeos/status/status_area_host.h" |
| 14 #include "chrome/browser/chromeos/status/window_switcher_button.h" | 14 #include "chrome/browser/chromeos/status/window_switcher_button.h" |
| 15 #include "grit/theme_resources.h" |
| 16 #include "ui/base/resource/resource_bundle.h" |
| 15 #include "ui/gfx/canvas.h" | 17 #include "ui/gfx/canvas.h" |
| 18 #include "views/border.h" |
| 19 #include "views/controls/image_view.h" |
| 16 | 20 |
| 17 namespace chromeos { | 21 namespace chromeos { |
| 18 | 22 |
| 19 // Number of pixels to separate each icon. | 23 // Number of pixels to separate each icon. |
| 20 const int kSeparation = 1; | 24 const int kSeparation = 5; |
| 21 | 25 |
| 22 StatusAreaView::StatusAreaView(StatusAreaHost* host) | 26 StatusAreaView::StatusAreaView(StatusAreaHost* host) |
| 23 : host_(host), | 27 : host_(host), |
| 24 clock_view_(NULL), | 28 clock_view_(NULL), |
| 25 input_method_view_(NULL), | 29 input_method_view_(NULL), |
| 26 network_view_(NULL), | 30 network_view_(NULL), |
| 27 power_view_(NULL), | 31 power_view_(NULL), |
| 28 window_switcher_view_(NULL) { | 32 window_switcher_view_(NULL) { |
| 29 } | 33 } |
| 30 | 34 |
| 31 void StatusAreaView::Init() { | 35 void StatusAreaView::Init() { |
| 32 // Clock. | 36 // Clock. |
| 33 clock_view_ = new ClockMenuButton(host_); | 37 clock_view_ = new ClockMenuButton(host_); |
| 38 clock_view_->set_border(views::Border::CreateEmptyBorder(0, 1, 0, 0)); |
| 34 AddChildView(clock_view_); | 39 AddChildView(clock_view_); |
| 35 | 40 |
| 36 // InputMethod. | 41 // InputMethod. |
| 37 input_method_view_ = new InputMethodMenuButton(host_); | 42 input_method_view_ = new InputMethodMenuButton(host_); |
| 38 AddChildView(input_method_view_); | 43 AddChildView(input_method_view_); |
| 39 | 44 |
| 40 // Network. | 45 // Network. |
| 41 network_view_ = new NetworkMenuButton(host_); | 46 network_view_ = new NetworkMenuButton(host_); |
| 42 AddChildView(network_view_); | 47 AddChildView(network_view_); |
| 43 | 48 |
| 44 // Power. | 49 // Power. |
| 45 power_view_ = new PowerMenuButton(); | 50 power_view_ = new PowerMenuButton(host_); |
| 46 AddChildView(power_view_); | 51 AddChildView(power_view_); |
| 47 | 52 |
| 48 // Window Switcher. | 53 // Window Switcher. |
| 49 window_switcher_view_ = new WindowSwitcherButton(host_); | 54 window_switcher_view_ = new WindowSwitcherButton(host_); |
| 50 AddChildView(window_switcher_view_); | 55 AddChildView(window_switcher_view_); |
| 51 } | 56 } |
| 52 | 57 |
| 53 gfx::Size StatusAreaView::GetPreferredSize() { | 58 gfx::Size StatusAreaView::GetPreferredSize() { |
| 54 int result_w = kSeparation; | 59 int result_w = kSeparation; |
| 55 int result_h = 0; | 60 int result_h = 0; |
| 61 int visible_count = 0; |
| 56 for (int i = 0; i < child_count(); i++) { | 62 for (int i = 0; i < child_count(); i++) { |
| 57 views::View* cur = GetChildViewAt(i); | 63 views::View* cur = GetChildViewAt(i); |
| 58 if (cur->IsVisible()) { | 64 if (cur->IsVisible()) { |
| 65 visible_count++; |
| 59 gfx::Size cur_size = cur->GetPreferredSize(); | 66 gfx::Size cur_size = cur->GetPreferredSize(); |
| 60 // Add each width. | 67 // Add each width. |
| 61 result_w += cur_size.width() + kSeparation; | 68 result_w += cur_size.width() + kSeparation; |
| 62 // Use max height. | 69 // Use max height. |
| 63 result_h = std::max(result_h, cur_size.height()); | 70 result_h = std::max(result_h, cur_size.height()); |
| 64 } | 71 } |
| 65 } | 72 } |
| 73 if (visible_count > 0) |
| 74 result_w -= kSeparation; |
| 66 return gfx::Size(result_w, result_h); | 75 return gfx::Size(result_w, result_h); |
| 67 } | 76 } |
| 68 | 77 |
| 69 void StatusAreaView::Layout() { | 78 void StatusAreaView::Layout() { |
| 70 int cur_x = kSeparation; | 79 int cur_x = kSeparation; |
| 71 for (int i = 0; i < child_count(); i++) { | 80 for (int i = 0; i < child_count(); i++) { |
| 72 views::View* cur = GetChildViewAt(i); | 81 views::View* cur = GetChildViewAt(i); |
| 73 if (cur->IsVisible()) { | 82 if (cur->IsVisible()) { |
| 74 gfx::Size cur_size = cur->GetPreferredSize(); | 83 gfx::Size cur_size = cur->GetPreferredSize(); |
| 75 int cur_y = (height() - cur_size.height()) / 2; | 84 int cur_y = (height() - cur_size.height()) / 2; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 95 } | 104 } |
| 96 | 105 |
| 97 void StatusAreaView::MakeButtonsActive(bool active) { | 106 void StatusAreaView::MakeButtonsActive(bool active) { |
| 98 clock_view()->set_active(active); | 107 clock_view()->set_active(active); |
| 99 input_method_view()->set_active(active); | 108 input_method_view()->set_active(active); |
| 100 network_view()->set_active(active); | 109 network_view()->set_active(active); |
| 101 power_view()->set_active(active); | 110 power_view()->set_active(active); |
| 102 } | 111 } |
| 103 | 112 |
| 104 } // namespace chromeos | 113 } // namespace chromeos |
| OLD | NEW |