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