Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(49)

Side by Side Diff: ash/system/status_area_widget_delegate.cc

Issue 2103113003: Fix shelf layout when switching from left-aligned shelf to right-aligned shelf (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/common/ash_switches.h" 8 #include "ash/common/ash_switches.h"
9 #include "ash/common/focus_cycler.h" 9 #include "ash/common/focus_cycler.h"
10 #include "ash/common/material_design/material_design_controller.h"
11 #include "ash/common/shelf/shelf_constants.h" 10 #include "ash/common/shelf/shelf_constants.h"
12 #include "ash/common/shelf/wm_shelf_util.h" 11 #include "ash/common/shelf/wm_shelf_util.h"
13 #include "ash/common/shell_window_ids.h" 12 #include "ash/common/shell_window_ids.h"
14 #include "ash/common/system/tray/tray_constants.h" 13 #include "ash/common/system/tray/tray_constants.h"
15 #include "ash/common/wm_shell.h" 14 #include "ash/common/wm_shell.h"
16 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
17 #include "ui/compositor/layer.h" 16 #include "ui/compositor/layer.h"
18 #include "ui/compositor/scoped_layer_animation_settings.h" 17 #include "ui/compositor/scoped_layer_animation_settings.h"
19 #include "ui/gfx/animation/tween.h" 18 #include "ui/gfx/animation/tween.h"
20 #include "ui/gfx/canvas.h" 19 #include "ui/gfx/canvas.h"
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 // Set the layout manager with the new list of children. 103 // Set the layout manager with the new list of children.
105 UpdateLayout(); 104 UpdateLayout();
106 } 105 }
107 106
108 void StatusAreaWidgetDelegate::UpdateLayout() { 107 void StatusAreaWidgetDelegate::UpdateLayout() {
109 // Use a grid layout so that the trays can be centered in each cell, and 108 // Use a grid layout so that the trays can be centered in each cell, and
110 // so that the widget gets laid out correctly when tray sizes change. 109 // so that the widget gets laid out correctly when tray sizes change.
111 views::GridLayout* layout = new views::GridLayout(this); 110 views::GridLayout* layout = new views::GridLayout(this);
112 SetLayoutManager(layout); 111 SetLayoutManager(layout);
113 112
114 // Update tray border based on layout.
115 bool is_child_on_edge = true;
116 for (int c = 0; c < child_count(); ++c) {
117 views::View* child = child_at(c);
118 if (!child->visible())
119 continue;
120 SetBorderOnChild(child, is_child_on_edge);
121 is_child_on_edge = false;
122 }
123
124 views::ColumnSet* columns = layout->AddColumnSet(0); 113 views::ColumnSet* columns = layout->AddColumnSet(0);
125 114
126 if (IsHorizontalAlignment(alignment_)) { 115 if (IsHorizontalAlignment(alignment_)) {
127 bool is_first_visible_child = true; 116 bool is_first_visible_child = true;
128 for (int c = child_count() - 1; c >= 0; --c) { 117 for (int c = child_count() - 1; c >= 0; --c) {
129 views::View* child = child_at(c); 118 views::View* child = child_at(c);
130 if (!child->visible()) 119 if (!child->visible())
131 continue; 120 continue;
132 if (!is_first_visible_child) 121 if (!is_first_visible_child)
133 columns->AddPaddingColumn(0, GetTrayConstant(TRAY_SPACING)); 122 columns->AddPaddingColumn(0, GetTrayConstant(TRAY_SPACING));
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 163
175 void StatusAreaWidgetDelegate::ChildVisibilityChanged(View* child) { 164 void StatusAreaWidgetDelegate::ChildVisibilityChanged(View* child) {
176 UpdateLayout(); 165 UpdateLayout();
177 } 166 }
178 167
179 void StatusAreaWidgetDelegate::UpdateWidgetSize() { 168 void StatusAreaWidgetDelegate::UpdateWidgetSize() {
180 if (GetWidget()) 169 if (GetWidget())
181 GetWidget()->SetSize(GetPreferredSize()); 170 GetWidget()->SetSize(GetPreferredSize());
182 } 171 }
183 172
184 void StatusAreaWidgetDelegate::SetBorderOnChild(views::View* child,
185 bool extend_border_to_edge) {
186 const int shelf_size = GetShelfConstant(SHELF_SIZE);
187 const int item_height = GetTrayConstant(TRAY_ITEM_HEIGHT_LEGACY);
188 int top_edge, left_edge, bottom_edge, right_edge;
189
190 // Tray views are laid out right-to-left or bottom-to-top.
191 if (MaterialDesignController::IsShelfMaterial()) {
192 const bool horizontal_alignment = IsHorizontalAlignment(alignment_);
193 const int padding = (shelf_size - item_height) / 2;
194 const int extended_padding =
195 GetTrayConstant(TRAY_PADDING_FROM_EDGE_OF_SHELF);
196
197 top_edge = horizontal_alignment ? padding : 0;
198 left_edge = horizontal_alignment ? 0 : padding;
199 bottom_edge = horizontal_alignment
200 ? padding
201 : (extend_border_to_edge ? extended_padding : 0);
202 right_edge = horizontal_alignment
203 ? (extend_border_to_edge ? extended_padding : 0)
204 : padding;
205 } else {
206 bool on_edge = (child == child_at(0));
207 if (IsHorizontalAlignment(alignment_)) {
208 top_edge = kShelfItemInset;
209 left_edge = 0;
210 bottom_edge = shelf_size - kShelfItemInset - item_height;
211 right_edge =
212 on_edge ? GetTrayConstant(TRAY_PADDING_FROM_EDGE_OF_SHELF) : 0;
213 } else if (alignment_ == SHELF_ALIGNMENT_LEFT) {
214 top_edge = 0;
215 left_edge = shelf_size - kShelfItemInset - item_height;
216 bottom_edge =
217 on_edge ? GetTrayConstant(TRAY_PADDING_FROM_EDGE_OF_SHELF) : 0;
218 right_edge = kShelfItemInset;
219 } else { // SHELF_ALIGNMENT_RIGHT
220 top_edge = 0;
221 left_edge = kShelfItemInset;
222 bottom_edge =
223 on_edge ? GetTrayConstant(TRAY_PADDING_FROM_EDGE_OF_SHELF) : 0;
224 right_edge = shelf_size - kShelfItemInset - item_height;
225 }
226 }
227 child->SetBorder(views::Border::CreateEmptyBorder(top_edge, left_edge,
228 bottom_edge, right_edge));
229 }
230
231 } // namespace ash 173 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698