OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/feedback_menu_button.h" | 10 #include "chrome/browser/chromeos/status/feedback_menu_button.h" |
11 #include "chrome/browser/chromeos/status/input_method_menu_button.h" | 11 #include "chrome/browser/chromeos/status/input_method_menu_button.h" |
12 #include "chrome/browser/chromeos/status/network_menu_button.h" | 12 #include "chrome/browser/chromeos/status/network_menu_button.h" |
13 #include "chrome/browser/chromeos/status/power_menu_button.h" | 13 #include "chrome/browser/chromeos/status/power_menu_button.h" |
14 #include "chrome/browser/chromeos/status/status_area_host.h" | 14 #include "chrome/browser/chromeos/status/status_area_host.h" |
15 #include "gfx/canvas.h" | 15 #include "gfx/canvas.h" |
16 | 16 |
17 namespace chromeos { | 17 namespace chromeos { |
18 | 18 |
19 // Number of pixels to separate each icon. | 19 // Number of pixels to separate each icon. |
20 const int kSeparation = 6; | 20 const int kSeparation = 3; |
21 | 21 |
22 StatusAreaView::StatusAreaView(StatusAreaHost* host) | 22 StatusAreaView::StatusAreaView(StatusAreaHost* host) |
23 : host_(host), | 23 : host_(host), |
24 clock_view_(NULL), | 24 clock_view_(NULL), |
25 feedback_view_(NULL), | 25 feedback_view_(NULL), |
26 input_method_view_(NULL), | 26 input_method_view_(NULL), |
27 network_view_(NULL), | 27 network_view_(NULL), |
28 power_view_(NULL) { | 28 power_view_(NULL) { |
29 } | 29 } |
30 | 30 |
31 void StatusAreaView::Init() { | 31 void StatusAreaView::Init() { |
| 32 // Clock. |
| 33 clock_view_ = new ClockMenuButton(host_); |
| 34 AddChildView(clock_view_); |
| 35 |
32 // InputMethod. | 36 // InputMethod. |
33 input_method_view_ = new InputMethodMenuButton(host_); | 37 input_method_view_ = new InputMethodMenuButton(host_); |
34 AddChildView(input_method_view_); | 38 AddChildView(input_method_view_); |
35 | 39 |
36 // Feedback. | 40 // Feedback. |
37 feedback_view_ = new FeedbackMenuButton(host_); | 41 feedback_view_ = new FeedbackMenuButton(host_); |
38 AddChildView(feedback_view_); | 42 AddChildView(feedback_view_); |
39 | 43 |
40 // Network. | 44 // Network. |
41 network_view_ = new NetworkMenuButton(host_); | 45 network_view_ = new NetworkMenuButton(host_); |
42 AddChildView(network_view_); | 46 AddChildView(network_view_); |
43 | 47 |
44 // Power. | 48 // Power. |
45 power_view_ = new PowerMenuButton(); | 49 power_view_ = new PowerMenuButton(); |
46 AddChildView(power_view_); | 50 AddChildView(power_view_); |
47 | |
48 // Clock. | |
49 clock_view_ = new ClockMenuButton(host_); | |
50 AddChildView(clock_view_); | |
51 } | 51 } |
52 | 52 |
53 gfx::Size StatusAreaView::GetPreferredSize() { | 53 gfx::Size StatusAreaView::GetPreferredSize() { |
54 int result_w = kSeparation; | 54 int result_w = kSeparation; |
55 int result_h = 0; | 55 int result_h = 0; |
56 for (int i = 0; i < GetChildViewCount(); i++) { | 56 for (int i = 0; i < GetChildViewCount(); i++) { |
57 views::View* cur = GetChildViewAt(i); | 57 views::View* cur = GetChildViewAt(i); |
58 if (cur->IsVisible()) { | 58 if (cur->IsVisible()) { |
59 gfx::Size cur_size = cur->GetPreferredSize(); | 59 gfx::Size cur_size = cur->GetPreferredSize(); |
60 // Add each width. | 60 // Add each width. |
(...skipping 12 matching lines...) Expand all Loading... |
73 if (cur->IsVisible()) { | 73 if (cur->IsVisible()) { |
74 gfx::Size cur_size = cur->GetPreferredSize(); | 74 gfx::Size cur_size = cur->GetPreferredSize(); |
75 int cur_y = (height() - cur_size.height()) / 2; | 75 int cur_y = (height() - cur_size.height()) / 2; |
76 | 76 |
77 // Handle odd number of pixels. | 77 // Handle odd number of pixels. |
78 cur_y += (height() - cur_size.height()) % 2; | 78 cur_y += (height() - cur_size.height()) % 2; |
79 | 79 |
80 // Put next in row horizontally, and center vertically. | 80 // Put next in row horizontally, and center vertically. |
81 cur->SetBounds(cur_x, cur_y, cur_size.width(), cur_size.height()); | 81 cur->SetBounds(cur_x, cur_y, cur_size.width(), cur_size.height()); |
82 | 82 |
83 cur_x += cur_size.width() + kSeparation; | 83 if (cur_size.width() > 0) |
| 84 cur_x += cur_size.width() + kSeparation; |
84 } | 85 } |
85 } | 86 } |
86 } | 87 } |
87 | 88 |
88 void StatusAreaView::ChildPreferredSizeChanged(View* child) { | 89 void StatusAreaView::ChildPreferredSizeChanged(View* child) { |
89 // When something like the clock menu button's size changes, we need to | 90 // When something like the clock menu button's size changes, we need to |
90 // relayout. Also mark that this view's size has changed. This will let | 91 // relayout. Also mark that this view's size has changed. This will let |
91 // BrowserView know to relayout, which will reset the bounds of this view. | 92 // BrowserView know to relayout, which will reset the bounds of this view. |
92 Layout(); | 93 Layout(); |
93 PreferredSizeChanged(); | 94 PreferredSizeChanged(); |
94 } | 95 } |
95 | 96 |
96 } // namespace chromeos | 97 } // namespace chromeos |
OLD | NEW |