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 | 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/common/material_design/material_design_controller.h" | |
| 10 #include "ash/common/shelf/shelf_constants.h" | |
| 9 #include "ash/common/shelf/wm_shelf_util.h" | 11 #include "ash/common/shelf/wm_shelf_util.h" |
| 10 #include "ash/common/shell_window_ids.h" | 12 #include "ash/common/shell_window_ids.h" |
| 11 #include "ash/common/system/tray/tray_constants.h" | 13 #include "ash/common/system/tray/tray_constants.h" |
| 12 #include "ash/focus_cycler.h" | 14 #include "ash/focus_cycler.h" |
| 13 #include "ash/shelf/shelf_util.h" | 15 #include "ash/shelf/shelf_util.h" |
| 14 #include "ash/shell.h" | 16 #include "ash/shell.h" |
| 17 #include "ash/system/tray/tray_background_view.h" | |
| 15 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
| 16 #include "ui/aura/window_event_dispatcher.h" | 19 #include "ui/aura/window_event_dispatcher.h" |
| 17 #include "ui/compositor/layer.h" | 20 #include "ui/compositor/layer.h" |
| 18 #include "ui/compositor/scoped_layer_animation_settings.h" | 21 #include "ui/compositor/scoped_layer_animation_settings.h" |
| 19 #include "ui/gfx/animation/tween.h" | 22 #include "ui/gfx/animation/tween.h" |
| 20 #include "ui/gfx/canvas.h" | 23 #include "ui/gfx/canvas.h" |
| 21 #include "ui/gfx/image/image.h" | 24 #include "ui/gfx/image/image.h" |
| 22 #include "ui/views/accessible_pane_view.h" | 25 #include "ui/views/accessible_pane_view.h" |
| 23 #include "ui/views/layout/grid_layout.h" | 26 #include "ui/views/layout/grid_layout.h" |
| 24 #include "ui/views/widget/widget.h" | 27 #include "ui/views/widget/widget.h" |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 92 // We don't want mouse clicks to activate us, but we need to allow | 95 // We don't want mouse clicks to activate us, but we need to allow |
| 93 // activation when the user is using the keyboard (FocusCycler). | 96 // activation when the user is using the keyboard (FocusCycler). |
| 94 const FocusCycler* focus_cycler = focus_cycler_for_testing_ ? | 97 const FocusCycler* focus_cycler = focus_cycler_for_testing_ ? |
| 95 focus_cycler_for_testing_ : Shell::GetInstance()->focus_cycler(); | 98 focus_cycler_for_testing_ : Shell::GetInstance()->focus_cycler(); |
| 96 return focus_cycler->widget_activating() == GetWidget(); | 99 return focus_cycler->widget_activating() == GetWidget(); |
| 97 } | 100 } |
| 98 | 101 |
| 99 void StatusAreaWidgetDelegate::DeleteDelegate() { | 102 void StatusAreaWidgetDelegate::DeleteDelegate() { |
| 100 } | 103 } |
| 101 | 104 |
| 102 void StatusAreaWidgetDelegate::AddTray(views::View* tray) { | 105 void StatusAreaWidgetDelegate::AddTray(TrayBackgroundView* tray) { |
| 103 SetLayoutManager(NULL); // Reset layout manager before adding a child. | 106 SetLayoutManager(NULL); // Reset layout manager before adding a child. |
| 104 AddChildView(tray); | 107 AddChildView(tray); |
| 105 // Set the layout manager with the new list of children. | 108 // Set the layout manager with the new list of children. |
| 106 UpdateLayout(); | 109 UpdateLayout(); |
| 107 } | 110 } |
| 108 | 111 |
| 109 void StatusAreaWidgetDelegate::UpdateLayout() { | 112 void StatusAreaWidgetDelegate::UpdateLayout() { |
| 110 // Use a grid layout so that the trays can be centered in each cell, and | 113 // Use a grid layout so that the trays can be centered in each cell, and |
| 111 // so that the widget gets laid out correctly when tray sizes change. | 114 // so that the widget gets laid out correctly when tray sizes change. |
| 112 views::GridLayout* layout = new views::GridLayout(this); | 115 views::GridLayout* layout = new views::GridLayout(this); |
| 113 SetLayoutManager(layout); | 116 SetLayoutManager(layout); |
| 114 | 117 |
| 118 // Update tray border based on layout. | |
| 119 bool is_child_on_edge = true; | |
| 120 for (int c = 0; c < child_count(); ++c) { | |
| 121 views::View* child = child_at(c); | |
| 122 if (!child->visible()) | |
| 123 continue; | |
| 124 if (is_child_on_edge) { | |
| 125 SetBorderOnEdgeTray(child); | |
| 126 } else { | |
| 127 SetBorderOnNonEdgeTray(child); | |
| 128 } | |
| 129 is_child_on_edge = false; | |
| 130 } | |
| 131 | |
| 115 views::ColumnSet* columns = layout->AddColumnSet(0); | 132 views::ColumnSet* columns = layout->AddColumnSet(0); |
| 133 | |
| 116 if (IsHorizontalAlignment(alignment_)) { | 134 if (IsHorizontalAlignment(alignment_)) { |
| 117 bool is_first_visible_child = true; | 135 bool is_first_visible_child = true; |
| 118 for (int c = 0; c < child_count(); ++c) { | 136 for (int c = child_count() - 1; c >= 0; --c) { |
|
tdanderson
2016/06/10 22:54:43
Are you sure you still want to reverse the order o
yiyix
2016/06/13 18:43:55
I think reverse the order makes more sense. With t
yiyix
2016/06/13 18:53:15
Sorry, my explanation is not clear as I read it ag
| |
| 119 views::View* child = child_at(c); | 137 views::View* child = child_at(c); |
| 120 if (!child->visible()) | 138 if (!child->visible()) |
| 121 continue; | 139 continue; |
| 122 if (!is_first_visible_child) | 140 if (!is_first_visible_child) |
| 123 columns->AddPaddingColumn(0, kTraySpacing); | 141 columns->AddPaddingColumn(0, GetTrayConstant(TRAY_SPACING)); |
| 124 is_first_visible_child = false; | 142 is_first_visible_child = false; |
| 125 columns->AddColumn(views::GridLayout::CENTER, views::GridLayout::FILL, | 143 columns->AddColumn(views::GridLayout::CENTER, views::GridLayout::FILL, |
| 126 0, /* resize percent */ | 144 0, /* resize percent */ |
| 127 views::GridLayout::USE_PREF, 0, 0); | 145 views::GridLayout::USE_PREF, 0, 0); |
| 128 } | 146 } |
| 129 layout->StartRow(0, 0); | 147 layout->StartRow(0, 0); |
| 130 for (int c = child_count() - 1; c >= 0; --c) { | 148 for (int c = child_count() - 1; c >= 0; --c) { |
| 131 views::View* child = child_at(c); | 149 views::View* child = child_at(c); |
| 132 if (child->visible()) | 150 if (child->visible()) |
| 133 layout->AddView(child); | 151 layout->AddView(child); |
| 134 } | 152 } |
| 135 } else { | 153 } else { |
| 154 bool is_first_visible_child = true; | |
| 136 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER, | 155 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER, |
| 137 0, /* resize percent */ | 156 0, /* resize percent */ |
| 138 views::GridLayout::USE_PREF, 0, 0); | 157 views::GridLayout::USE_PREF, 0, 0); |
| 139 bool is_first_visible_child = true; | |
| 140 for (int c = child_count() - 1; c >= 0; --c) { | 158 for (int c = child_count() - 1; c >= 0; --c) { |
| 141 views::View* child = child_at(c); | 159 views::View* child = child_at(c); |
| 142 if (!child->visible()) | 160 if (!child->visible()) |
| 143 continue; | 161 continue; |
| 144 if (!is_first_visible_child) | 162 if (!is_first_visible_child) { |
| 145 layout->AddPaddingRow(0, kTraySpacing); | 163 if (!((child_at(kOverviewButtonIndex)->visible()) && |
| 164 c == kOverviewButtonIndex)) { | |
|
tdanderson
2016/06/10 22:54:43
Unless I am missing something, I think you can rem
yiyix
2016/06/13 18:43:55
Done.
| |
| 165 layout->AddPaddingRow(0, GetTrayConstant(TRAY_SPACING)); | |
| 166 } | |
| 167 } | |
| 146 is_first_visible_child = false; | 168 is_first_visible_child = false; |
| 147 layout->StartRow(0, 0); | 169 layout->StartRow(0, 0); |
| 148 layout->AddView(child); | 170 layout->AddView(child); |
| 149 } | 171 } |
| 150 } | 172 } |
| 151 | 173 |
| 152 layer()->GetAnimator()->StopAnimating(); | 174 layer()->GetAnimator()->StopAnimating(); |
| 153 StatusAreaWidgetDelegateAnimationSettings settings(layer()); | 175 StatusAreaWidgetDelegateAnimationSettings settings(layer()); |
| 154 | 176 |
| 155 Layout(); | 177 Layout(); |
| 156 UpdateWidgetSize(); | 178 UpdateWidgetSize(); |
| 157 } | 179 } |
| 158 | 180 |
| 159 void StatusAreaWidgetDelegate::ChildPreferredSizeChanged(View* child) { | 181 void StatusAreaWidgetDelegate::ChildPreferredSizeChanged(View* child) { |
| 160 // Need to resize the window when trays or items are added/removed. | 182 // Need to resize the window when trays or items are added/removed. |
| 161 StatusAreaWidgetDelegateAnimationSettings settings(layer()); | 183 StatusAreaWidgetDelegateAnimationSettings settings(layer()); |
| 162 UpdateWidgetSize(); | 184 UpdateWidgetSize(); |
| 163 } | 185 } |
| 164 | 186 |
| 165 void StatusAreaWidgetDelegate::ChildVisibilityChanged(View* child) { | 187 void StatusAreaWidgetDelegate::ChildVisibilityChanged(View* child) { |
| 166 UpdateLayout(); | 188 UpdateLayout(); |
| 167 } | 189 } |
| 168 | 190 |
| 169 void StatusAreaWidgetDelegate::UpdateWidgetSize() { | 191 void StatusAreaWidgetDelegate::UpdateWidgetSize() { |
| 170 if (GetWidget()) | 192 if (GetWidget()) |
| 171 GetWidget()->SetSize(GetPreferredSize()); | 193 GetWidget()->SetSize(GetPreferredSize()); |
| 172 } | 194 } |
| 173 | 195 |
| 196 void StatusAreaWidgetDelegate::SetBorderOnEdgeTray(views::View* child) { | |
| 197 int top_edge, left_edge, bottom_edge, right_edge; | |
| 198 | |
| 199 if (MaterialDesignController::IsShelfMaterial()) { | |
| 200 if (IsHorizontalAlignment(alignment_)) { | |
| 201 top_edge = (GetShelfConstant(SHELF_SIZE) - kShelfItemHeight) / 2; | |
| 202 left_edge = 0; | |
| 203 bottom_edge = (GetShelfConstant(SHELF_SIZE) - kShelfItemHeight) / 2; | |
| 204 right_edge = GetTrayConstant(PADDING_FROM_EDGE_OF_SHELF); | |
| 205 } else { | |
| 206 top_edge = 0; | |
| 207 left_edge = (GetShelfConstant(SHELF_SIZE) - kShelfItemHeight) / 2; | |
| 208 bottom_edge = GetTrayConstant(PADDING_FROM_EDGE_OF_SHELF); | |
| 209 right_edge = (GetShelfConstant(SHELF_SIZE) - kShelfItemHeight) / 2; | |
| 210 } | |
| 211 } else { | |
| 212 bool on_edge = (child == child_at(0)); | |
|
tdanderson
2016/06/10 22:54:43
Now that you're checking which child is on the edg
yiyix
2016/06/13 18:43:54
The only child with index 0 is overview button. In
| |
| 213 if (IsHorizontalAlignment(alignment_)) { | |
| 214 top_edge = kShelfItemInset; | |
| 215 left_edge = 0; | |
| 216 bottom_edge = | |
| 217 GetShelfConstant(SHELF_SIZE) - kShelfItemInset - kShelfItemHeight; | |
| 218 right_edge = on_edge ? GetTrayConstant(PADDING_FROM_EDGE_OF_SHELF) : 0; | |
| 219 } else if (alignment_ == SHELF_ALIGNMENT_LEFT) { | |
| 220 top_edge = 0; | |
| 221 left_edge = | |
| 222 GetShelfConstant(SHELF_SIZE) - kShelfItemInset - kShelfItemHeight; | |
| 223 bottom_edge = on_edge ? GetTrayConstant(PADDING_FROM_EDGE_OF_SHELF) : 0; | |
| 224 right_edge = kShelfItemInset; | |
| 225 } else { // SHELF_ALIGNMENT_RIGHT | |
| 226 top_edge = 0; | |
| 227 left_edge = kShelfItemInset; | |
| 228 bottom_edge = on_edge ? GetTrayConstant(PADDING_FROM_EDGE_OF_SHELF) : 0; | |
| 229 right_edge = | |
| 230 GetShelfConstant(SHELF_SIZE) - kShelfItemInset - kShelfItemHeight; | |
| 231 } | |
| 232 } | |
| 233 | |
| 234 child->SetBorder(views::Border::CreateEmptyBorder(top_edge, left_edge, | |
| 235 bottom_edge, right_edge)); | |
| 236 } | |
| 237 | |
| 238 void StatusAreaWidgetDelegate::SetBorderOnNonEdgeTray(views::View* child) { | |
| 239 int top_edge, left_edge, bottom_edge, right_edge; | |
| 240 // Tray views are laid out right-to-left or bottom-to-top | |
| 241 if (MaterialDesignController::IsShelfMaterial()) { | |
| 242 if (IsHorizontalAlignment(alignment_)) { | |
| 243 top_edge = (GetShelfConstant(SHELF_SIZE) - kShelfItemHeight) / 2; | |
| 244 left_edge = 0; | |
| 245 bottom_edge = (GetShelfConstant(SHELF_SIZE) - kShelfItemHeight) / 2; | |
| 246 right_edge = 0; | |
| 247 } else { | |
| 248 top_edge = 0; | |
| 249 left_edge = (GetShelfConstant(SHELF_SIZE) - kShelfItemHeight) / 2; | |
| 250 bottom_edge = 0; | |
| 251 right_edge = (GetShelfConstant(SHELF_SIZE) - kShelfItemHeight) / 2; | |
| 252 } | |
| 253 } else { | |
| 254 bool on_edge = (child == child_at(0)); | |
| 255 if (IsHorizontalAlignment(alignment_)) { | |
| 256 top_edge = kShelfItemInset; | |
| 257 left_edge = 0; | |
| 258 bottom_edge = | |
| 259 GetShelfConstant(SHELF_SIZE) - kShelfItemInset - kShelfItemHeight; | |
| 260 right_edge = on_edge ? GetTrayConstant(PADDING_FROM_EDGE_OF_SHELF) : 0; | |
| 261 } else if (alignment_ == SHELF_ALIGNMENT_LEFT) { | |
| 262 top_edge = 0; | |
| 263 left_edge = | |
| 264 GetShelfConstant(SHELF_SIZE) - kShelfItemInset - kShelfItemHeight; | |
| 265 bottom_edge = on_edge ? GetTrayConstant(PADDING_FROM_EDGE_OF_SHELF) : 0; | |
| 266 right_edge = kShelfItemInset; | |
| 267 } else { // SHELF_ALIGNMENT_RIGHT | |
| 268 top_edge = 0; | |
| 269 left_edge = kShelfItemInset; | |
| 270 bottom_edge = on_edge ? GetTrayConstant(PADDING_FROM_EDGE_OF_SHELF) : 0; | |
| 271 right_edge = | |
| 272 GetShelfConstant(SHELF_SIZE) - kShelfItemInset - kShelfItemHeight; | |
| 273 } | |
| 274 } | |
| 275 child->SetBorder(views::Border::CreateEmptyBorder(top_edge, left_edge, | |
| 276 bottom_edge, right_edge)); | |
| 277 } | |
| 278 | |
| 174 } // namespace ash | 279 } // namespace ash |
| OLD | NEW |