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/ash_switches.h" |
9 #include "ash/focus_cycler.h" | 9 #include "ash/focus_cycler.h" |
10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
11 #include "ash/shell_window_ids.h" | 11 #include "ash/shell_window_ids.h" |
12 #include "ash/system/tray/tray_constants.h" | 12 #include "ash/system/tray/tray_constants.h" |
13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
14 #include "ui/aura/window_event_dispatcher.h" | 14 #include "ui/aura/window_event_dispatcher.h" |
15 #include "ui/base/resource/resource_bundle.h" | 15 #include "ui/base/resource/resource_bundle.h" |
16 #include "ui/gfx/canvas.h" | 16 #include "ui/gfx/canvas.h" |
17 #include "ui/gfx/image/image.h" | 17 #include "ui/gfx/image/image.h" |
18 #include "ui/views/accessible_pane_view.h" | 18 #include "ui/views/accessible_pane_view.h" |
19 #include "ui/views/layout/grid_layout.h" | 19 #include "ui/views/layout/grid_layout.h" |
20 #include "ui/views/widget/widget.h" | 20 #include "ui/views/widget/widget.h" |
21 | 21 |
22 namespace ash { | 22 namespace ash { |
23 namespace { | |
24 | |
25 const int kStatusTrayOffsetFromScreenEdge = 4; | |
26 | |
27 } | |
28 | 23 |
29 StatusAreaWidgetDelegate::StatusAreaWidgetDelegate() | 24 StatusAreaWidgetDelegate::StatusAreaWidgetDelegate() |
30 : focus_cycler_for_testing_(NULL), | 25 : focus_cycler_for_testing_(NULL), |
31 alignment_(SHELF_ALIGNMENT_BOTTOM) { | 26 alignment_(SHELF_ALIGNMENT_BOTTOM) { |
32 // Allow the launcher to surrender the focus to another window upon | 27 // Allow the launcher to surrender the focus to another window upon |
33 // navigation completion by the user. | 28 // navigation completion by the user. |
34 set_allow_deactivate_on_esc(true); | 29 set_allow_deactivate_on_esc(true); |
35 } | 30 } |
36 | 31 |
37 StatusAreaWidgetDelegate::~StatusAreaWidgetDelegate() { | 32 StatusAreaWidgetDelegate::~StatusAreaWidgetDelegate() { |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 | 76 |
82 void StatusAreaWidgetDelegate::UpdateLayout() { | 77 void StatusAreaWidgetDelegate::UpdateLayout() { |
83 // Use a grid layout so that the trays can be centered in each cell, and | 78 // Use a grid layout so that the trays can be centered in each cell, and |
84 // so that the widget gets laid out correctly when tray sizes change. | 79 // so that the widget gets laid out correctly when tray sizes change. |
85 views::GridLayout* layout = new views::GridLayout(this); | 80 views::GridLayout* layout = new views::GridLayout(this); |
86 SetLayoutManager(layout); | 81 SetLayoutManager(layout); |
87 | 82 |
88 views::ColumnSet* columns = layout->AddColumnSet(0); | 83 views::ColumnSet* columns = layout->AddColumnSet(0); |
89 if (alignment_ == SHELF_ALIGNMENT_BOTTOM || | 84 if (alignment_ == SHELF_ALIGNMENT_BOTTOM || |
90 alignment_ == SHELF_ALIGNMENT_TOP) { | 85 alignment_ == SHELF_ALIGNMENT_TOP) { |
91 // Alternate shelf layout insets are all handled by tray_background_view. | |
92 if (!ash::switches::UseAlternateShelfLayout()) { | |
93 if (alignment_ == SHELF_ALIGNMENT_TOP) | |
94 layout->SetInsets(kStatusTrayOffsetFromScreenEdge, 0, 0, 0); | |
95 else | |
96 layout->SetInsets(0, 0, kStatusTrayOffsetFromScreenEdge, 0); | |
97 } | |
98 bool is_first_visible_child = true; | 86 bool is_first_visible_child = true; |
99 for (int c = 0; c < child_count(); ++c) { | 87 for (int c = 0; c < child_count(); ++c) { |
100 views::View* child = child_at(c); | 88 views::View* child = child_at(c); |
101 if (!child->visible()) | 89 if (!child->visible()) |
102 continue; | 90 continue; |
103 if (!is_first_visible_child) | 91 if (!is_first_visible_child) |
104 columns->AddPaddingColumn(0, GetTraySpacing()); | 92 columns->AddPaddingColumn(0, kTraySpacing); |
105 is_first_visible_child = false; | 93 is_first_visible_child = false; |
106 columns->AddColumn(views::GridLayout::CENTER, views::GridLayout::FILL, | 94 columns->AddColumn(views::GridLayout::CENTER, views::GridLayout::FILL, |
107 0, /* resize percent */ | 95 0, /* resize percent */ |
108 views::GridLayout::USE_PREF, 0, 0); | 96 views::GridLayout::USE_PREF, 0, 0); |
109 } | 97 } |
110 layout->StartRow(0, 0); | 98 layout->StartRow(0, 0); |
111 for (int c = child_count() - 1; c >= 0; --c) { | 99 for (int c = child_count() - 1; c >= 0; --c) { |
112 views::View* child = child_at(c); | 100 views::View* child = child_at(c); |
113 if (child->visible()) | 101 if (child->visible()) |
114 layout->AddView(child); | 102 layout->AddView(child); |
115 } | 103 } |
116 } else { | 104 } else { |
117 if (!ash::switches::UseAlternateShelfLayout()) { | |
118 if (alignment_ == SHELF_ALIGNMENT_LEFT) | |
119 layout->SetInsets(0, kStatusTrayOffsetFromScreenEdge, 0, 0); | |
120 else | |
121 layout->SetInsets(0, 0, 0, kStatusTrayOffsetFromScreenEdge); | |
122 } | |
123 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER, | 105 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER, |
124 0, /* resize percent */ | 106 0, /* resize percent */ |
125 views::GridLayout::USE_PREF, 0, 0); | 107 views::GridLayout::USE_PREF, 0, 0); |
126 bool is_first_visible_child = true; | 108 bool is_first_visible_child = true; |
127 for (int c = child_count() - 1; c >= 0; --c) { | 109 for (int c = child_count() - 1; c >= 0; --c) { |
128 views::View* child = child_at(c); | 110 views::View* child = child_at(c); |
129 if (!child->visible()) | 111 if (!child->visible()) |
130 continue; | 112 continue; |
131 if (!is_first_visible_child) | 113 if (!is_first_visible_child) |
132 layout->AddPaddingRow(0, GetTraySpacing()); | 114 layout->AddPaddingRow(0, kTraySpacing); |
133 is_first_visible_child = false; | 115 is_first_visible_child = false; |
134 layout->StartRow(0, 0); | 116 layout->StartRow(0, 0); |
135 layout->AddView(child); | 117 layout->AddView(child); |
136 } | 118 } |
137 } | 119 } |
138 Layout(); | 120 Layout(); |
139 UpdateWidgetSize(); | 121 UpdateWidgetSize(); |
140 } | 122 } |
141 | 123 |
142 void StatusAreaWidgetDelegate::ChildPreferredSizeChanged(View* child) { | 124 void StatusAreaWidgetDelegate::ChildPreferredSizeChanged(View* child) { |
143 // Need to resize the window when trays or items are added/removed. | 125 // Need to resize the window when trays or items are added/removed. |
144 UpdateWidgetSize(); | 126 UpdateWidgetSize(); |
145 } | 127 } |
146 | 128 |
147 void StatusAreaWidgetDelegate::ChildVisibilityChanged(View* child) { | 129 void StatusAreaWidgetDelegate::ChildVisibilityChanged(View* child) { |
148 UpdateLayout(); | 130 UpdateLayout(); |
149 } | 131 } |
150 | 132 |
151 void StatusAreaWidgetDelegate::UpdateWidgetSize() { | 133 void StatusAreaWidgetDelegate::UpdateWidgetSize() { |
152 if (GetWidget()) | 134 if (GetWidget()) |
153 GetWidget()->SetSize(GetPreferredSize()); | 135 GetWidget()->SetSize(GetPreferredSize()); |
154 } | 136 } |
155 | 137 |
156 } // namespace ash | 138 } // namespace ash |
OLD | NEW |