Chromium Code Reviews| 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 | |
| 
 
tdanderson
2016/06/03 19:25:23
nit: replace this blank line
 
yiyix
2016/06/10 19:26:05
Done.
 
 | |
| 5 #include "ash/system/status_area_widget_delegate.h" | 4 #include "ash/system/status_area_widget_delegate.h" | 
| 6 | 5 | 
| 7 #include "ash/ash_export.h" | 6 #include "ash/ash_export.h" | 
| 8 #include "ash/ash_switches.h" | 7 #include "ash/ash_switches.h" | 
| 9 #include "ash/focus_cycler.h" | 8 #include "ash/focus_cycler.h" | 
| 10 #include "ash/shelf/shelf_util.h" | 9 #include "ash/shelf/shelf_util.h" | 
| 11 #include "ash/shell.h" | 10 #include "ash/shell.h" | 
| 12 #include "ash/shell_window_ids.h" | 11 #include "ash/shell_window_ids.h" | 
| 13 #include "ash/system/tray/tray_constants.h" | 12 #include "ash/system/tray/tray_constants.h" | 
| 14 #include "ash/wm/common/shelf/wm_shelf_util.h" | 13 #include "ash/wm/common/shelf/wm_shelf_util.h" | 
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 107 UpdateLayout(); | 106 UpdateLayout(); | 
| 108 } | 107 } | 
| 109 | 108 | 
| 110 void StatusAreaWidgetDelegate::UpdateLayout() { | 109 void StatusAreaWidgetDelegate::UpdateLayout() { | 
| 111 // Use a grid layout so that the trays can be centered in each cell, and | 110 // Use a grid layout so that the trays can be centered in each cell, and | 
| 112 // so that the widget gets laid out correctly when tray sizes change. | 111 // so that the widget gets laid out correctly when tray sizes change. | 
| 113 views::GridLayout* layout = new views::GridLayout(this); | 112 views::GridLayout* layout = new views::GridLayout(this); | 
| 114 SetLayoutManager(layout); | 113 SetLayoutManager(layout); | 
| 115 | 114 | 
| 116 views::ColumnSet* columns = layout->AddColumnSet(0); | 115 views::ColumnSet* columns = layout->AddColumnSet(0); | 
| 116 bool is_first_visible_child = true; | |
| 
 
bruthig
2016/06/03 20:18:17
I think keeping this variable in the tightest scop
 
yiyix
2016/06/10 19:26:04
Done.
 
 | |
| 117 if (wm::IsHorizontalAlignment(alignment_)) { | 117 if (wm::IsHorizontalAlignment(alignment_)) { | 
| 118 bool is_first_visible_child = true; | 118 for (int c = child_count() - 1; c >= 0; --c) { | 
| 119 for (int c = 0; c < child_count(); ++c) { | |
| 120 views::View* child = child_at(c); | 119 views::View* child = child_at(c); | 
| 121 if (!child->visible()) | 120 if (!child->visible()) | 
| 122 continue; | 121 continue; | 
| 123 if (!is_first_visible_child) | 122 if (!is_first_visible_child) { | 
| 124 columns->AddPaddingColumn(0, kTraySpacing); | 123 // If the overview Button is visible, then do not add the additional | 
| 
 
bruthig
2016/06/03 20:18:17
I agree this needs a comment, but the 'why' is mor
 
yiyix
2016/06/10 19:26:05
I will add some explanation for the new approach t
 
 | |
| 124 // empty padding row to the left side to the overview button; otherwise, | |
| 125 // add the empty padding to separate items. | |
| 126 if (!((child_at(kOverviewButtonIndex)->visible()) && | |
| 
 
bruthig
2016/06/03 20:18:17
I think you have an set of extra brackets around '
 
yiyix
2016/06/10 19:26:05
You are right! I didn't notice it!
 
 | |
| 127 c == kOverviewButtonIndex)) | |
| 128 columns->AddPaddingColumn(0, GetTrayConstant(TRAY_SPACING)); | |
| 
 
tdanderson
2016/06/03 19:25:23
nit: use {}
 
yiyix
2016/06/10 19:26:04
Done.
 
 | |
| 129 } | |
| 125 is_first_visible_child = false; | 130 is_first_visible_child = false; | 
| 126 columns->AddColumn(views::GridLayout::CENTER, views::GridLayout::FILL, | 131 columns->AddColumn(views::GridLayout::CENTER, views::GridLayout::FILL, | 
| 127 0, /* resize percent */ | 132 0, /* resize percent */ | 
| 128 views::GridLayout::USE_PREF, 0, 0); | 133 views::GridLayout::USE_PREF, 0, 0); | 
| 129 } | 134 } | 
| 130 layout->StartRow(0, 0); | 135 layout->StartRow(0, 0); | 
| 131 for (int c = child_count() - 1; c >= 0; --c) { | 136 for (int c = child_count() - 1; c >= 0; --c) { | 
| 132 views::View* child = child_at(c); | 137 views::View* child = child_at(c); | 
| 133 if (child->visible()) | 138 if (child->visible()) | 
| 134 layout->AddView(child); | 139 layout->AddView(child); | 
| 135 } | 140 } | 
| 141 | |
| 
 
tdanderson
2016/06/03 19:25:23
nit: remove blank line
 
yiyix
2016/06/10 19:26:04
Done.
 
 | |
| 136 } else { | 142 } else { | 
| 137 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER, | 143 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER, | 
| 138 0, /* resize percent */ | 144 0, /* resize percent */ | 
| 139 views::GridLayout::USE_PREF, 0, 0); | 145 views::GridLayout::USE_PREF, 0, 0); | 
| 140 bool is_first_visible_child = true; | 146 bool is_first_visible_child = true; | 
| 141 for (int c = child_count() - 1; c >= 0; --c) { | 147 for (int c = child_count() - 1; c >= 0; --c) { | 
| 142 views::View* child = child_at(c); | 148 views::View* child = child_at(c); | 
| 143 if (!child->visible()) | 149 if (!child->visible()) | 
| 144 continue; | 150 continue; | 
| 145 if (!is_first_visible_child) | 151 if (!is_first_visible_child) { | 
| 146 layout->AddPaddingRow(0, kTraySpacing); | 152 if (!((child_at(kOverviewButtonIndex)->visible()) && | 
| 153 c == kOverviewButtonIndex)) | |
| 154 layout->AddPaddingRow(0, GetTrayConstant(TRAY_SPACING)); | |
| 
 
tdanderson
2016/06/03 19:25:24
nit: use {} since the if + boolean condition takes
 
 | |
| 155 } | |
| 147 is_first_visible_child = false; | 156 is_first_visible_child = false; | 
| 148 layout->StartRow(0, 0); | 157 layout->StartRow(0, 0); | 
| 149 layout->AddView(child); | 158 layout->AddView(child); | 
| 150 } | 159 } | 
| 151 } | 160 } | 
| 152 | 161 | 
| 153 layer()->GetAnimator()->StopAnimating(); | 162 layer()->GetAnimator()->StopAnimating(); | 
| 154 StatusAreaWidgetDelegateAnimationSettings settings(layer()); | 163 StatusAreaWidgetDelegateAnimationSettings settings(layer()); | 
| 155 | 164 | 
| 156 Layout(); | 165 Layout(); | 
| 157 UpdateWidgetSize(); | 166 UpdateWidgetSize(); | 
| 158 } | 167 } | 
| 159 | 168 | 
| 160 void StatusAreaWidgetDelegate::ChildPreferredSizeChanged(View* child) { | 169 void StatusAreaWidgetDelegate::ChildPreferredSizeChanged(View* child) { | 
| 161 // Need to resize the window when trays or items are added/removed. | 170 // Need to resize the window when trays or items are added/removed. | 
| 162 StatusAreaWidgetDelegateAnimationSettings settings(layer()); | 171 StatusAreaWidgetDelegateAnimationSettings settings(layer()); | 
| 163 UpdateWidgetSize(); | 172 UpdateWidgetSize(); | 
| 164 } | 173 } | 
| 165 | 174 | 
| 166 void StatusAreaWidgetDelegate::ChildVisibilityChanged(View* child) { | 175 void StatusAreaWidgetDelegate::ChildVisibilityChanged(View* child) { | 
| 167 UpdateLayout(); | 176 UpdateLayout(); | 
| 168 } | 177 } | 
| 169 | 178 | 
| 170 void StatusAreaWidgetDelegate::UpdateWidgetSize() { | 179 void StatusAreaWidgetDelegate::UpdateWidgetSize() { | 
| 171 if (GetWidget()) | 180 if (GetWidget()) | 
| 172 GetWidget()->SetSize(GetPreferredSize()); | 181 GetWidget()->SetSize(GetPreferredSize()); | 
| 173 } | 182 } | 
| 174 | 183 | 
| 175 } // namespace ash | 184 } // namespace ash | 
| OLD | NEW |