OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ash/system/status_area_widget_delegate.h" | 5 #include "ash/system/status_area_widget_delegate.h" |
6 | 6 |
7 #include "ash/ash_export.h" | 7 #include "ash/ash_export.h" |
| 8 #include "ash/ash_switches.h" |
8 #include "ash/focus_cycler.h" | 9 #include "ash/focus_cycler.h" |
9 #include "ash/shell.h" | 10 #include "ash/shell.h" |
10 #include "ash/shell_window_ids.h" | 11 #include "ash/shell_window_ids.h" |
11 #include "ash/system/tray/tray_constants.h" | 12 #include "ash/system/tray/tray_constants.h" |
12 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
13 #include "ui/aura/root_window.h" | 14 #include "ui/aura/root_window.h" |
14 #include "ui/base/resource/resource_bundle.h" | 15 #include "ui/base/resource/resource_bundle.h" |
15 #include "ui/gfx/canvas.h" | 16 #include "ui/gfx/canvas.h" |
16 #include "ui/gfx/image/image.h" | 17 #include "ui/gfx/image/image.h" |
17 #include "ui/views/accessible_pane_view.h" | 18 #include "ui/views/accessible_pane_view.h" |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 if (alignment_ == SHELF_ALIGNMENT_TOP) | 92 if (alignment_ == SHELF_ALIGNMENT_TOP) |
92 layout->SetInsets(kStatusTrayOffsetFromScreenEdge, 0, 0, 0); | 93 layout->SetInsets(kStatusTrayOffsetFromScreenEdge, 0, 0, 0); |
93 else | 94 else |
94 layout->SetInsets(0, 0, kStatusTrayOffsetFromScreenEdge, 0); | 95 layout->SetInsets(0, 0, kStatusTrayOffsetFromScreenEdge, 0); |
95 bool is_first_visible_child = true; | 96 bool is_first_visible_child = true; |
96 for (int c = 0; c < child_count(); ++c) { | 97 for (int c = 0; c < child_count(); ++c) { |
97 views::View* child = child_at(c); | 98 views::View* child = child_at(c); |
98 if (!child->visible()) | 99 if (!child->visible()) |
99 continue; | 100 continue; |
100 if (!is_first_visible_child) | 101 if (!is_first_visible_child) |
101 columns->AddPaddingColumn(0, kTraySpacing); | 102 columns->AddPaddingColumn(0, GetTraySpacing()); |
102 is_first_visible_child = false; | 103 is_first_visible_child = false; |
103 columns->AddColumn(views::GridLayout::CENTER, views::GridLayout::FILL, | 104 columns->AddColumn(views::GridLayout::CENTER, views::GridLayout::FILL, |
104 0, /* resize percent */ | 105 0, /* resize percent */ |
105 views::GridLayout::USE_PREF, 0, 0); | 106 views::GridLayout::USE_PREF, 0, 0); |
106 } | 107 } |
107 layout->StartRow(0, 0); | 108 layout->StartRow(0, 0); |
108 for (int c = child_count() - 1; c >= 0; --c) { | 109 for (int c = child_count() - 1; c >= 0; --c) { |
109 views::View* child = child_at(c); | 110 views::View* child = child_at(c); |
110 if (child->visible()) | 111 if (child->visible()) |
111 layout->AddView(child); | 112 layout->AddView(child); |
112 } | 113 } |
113 } else { | 114 } else { |
114 if (alignment_ == SHELF_ALIGNMENT_LEFT) | 115 if (alignment_ == SHELF_ALIGNMENT_LEFT) |
115 layout->SetInsets(0, kStatusTrayOffsetFromScreenEdge, 0, 0); | 116 layout->SetInsets(0, kStatusTrayOffsetFromScreenEdge, 0, 0); |
116 else | 117 else |
117 layout->SetInsets(0, 0, 0, kStatusTrayOffsetFromScreenEdge); | 118 layout->SetInsets(0, 0, 0, kStatusTrayOffsetFromScreenEdge); |
118 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER, | 119 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER, |
119 0, /* resize percent */ | 120 0, /* resize percent */ |
120 views::GridLayout::USE_PREF, 0, 0); | 121 views::GridLayout::USE_PREF, 0, 0); |
121 bool is_first_visible_child = true; | 122 bool is_first_visible_child = true; |
122 for (int c = child_count() - 1; c >= 0; --c) { | 123 for (int c = child_count() - 1; c >= 0; --c) { |
123 views::View* child = child_at(c); | 124 views::View* child = child_at(c); |
124 if (!child->visible()) | 125 if (!child->visible()) |
125 continue; | 126 continue; |
126 if (!is_first_visible_child) | 127 if (!is_first_visible_child) |
127 layout->AddPaddingRow(0, kTraySpacing); | 128 layout->AddPaddingRow(0, GetTraySpacing()); |
128 is_first_visible_child = false; | 129 is_first_visible_child = false; |
129 layout->StartRow(0, 0); | 130 layout->StartRow(0, 0); |
130 layout->AddView(child); | 131 layout->AddView(child); |
131 } | 132 } |
132 } | 133 } |
133 Layout(); | 134 Layout(); |
134 UpdateWidgetSize(); | 135 UpdateWidgetSize(); |
135 } | 136 } |
136 | 137 |
137 void StatusAreaWidgetDelegate::ChildPreferredSizeChanged(View* child) { | 138 void StatusAreaWidgetDelegate::ChildPreferredSizeChanged(View* child) { |
138 // Need to resize the window when trays or items are added/removed. | 139 // Need to resize the window when trays or items are added/removed. |
139 UpdateWidgetSize(); | 140 UpdateWidgetSize(); |
140 } | 141 } |
141 | 142 |
142 void StatusAreaWidgetDelegate::ChildVisibilityChanged(View* child) { | 143 void StatusAreaWidgetDelegate::ChildVisibilityChanged(View* child) { |
143 UpdateLayout(); | 144 UpdateLayout(); |
144 } | 145 } |
145 | 146 |
146 void StatusAreaWidgetDelegate::UpdateWidgetSize() { | 147 void StatusAreaWidgetDelegate::UpdateWidgetSize() { |
147 if (GetWidget()) | 148 if (GetWidget()) |
148 GetWidget()->SetSize(GetPreferredSize()); | 149 GetWidget()->SetSize(GetPreferredSize()); |
149 } | 150 } |
150 | 151 |
151 } // namespace internal | 152 } // namespace internal |
152 } // namespace ash | 153 } // namespace ash |
OLD | NEW |