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

Side by Side Diff: ash/common/system/tray/tray_details_view.cc

Issue 2530763002: [ash-md] Adjusts layout of lists with sticky header rows to match specs (Closed)
Patch Set: [ash-md] Adjusts layout of lists with sticky header rows to match specs (rebased) Created 4 years 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/common/system/tray/tray_details_view.h" 5 #include "ash/common/system/tray/tray_details_view.h"
6 6
7 #include "ash/common/ash_view_ids.h" 7 #include "ash/common/ash_view_ids.h"
8 #include "ash/common/material_design/material_design_controller.h" 8 #include "ash/common/material_design/material_design_controller.h"
9 #include "ash/common/system/tray/fixed_sized_scroll_view.h" 9 #include "ash/common/system/tray/fixed_sized_scroll_view.h"
10 #include "ash/common/system/tray/system_menu_button.h" 10 #include "ash/common/system/tray/system_menu_button.h"
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 const int kShadowOffsetY = 2; 141 const int kShadowOffsetY = 2;
142 const int kShadowBlur = 2; 142 const int kShadowBlur = 2;
143 // TODO(fukino): Remove this constant once we stop maintaining pre-MD design. 143 // TODO(fukino): Remove this constant once we stop maintaining pre-MD design.
144 // crbug.com/614453. 144 // crbug.com/614453.
145 const int kContentsBetweenChildSpacingNonMd = 1; 145 const int kContentsBetweenChildSpacingNonMd = 1;
146 146
147 // A structure that keeps the original offset of each header between the 147 // A structure that keeps the original offset of each header between the
148 // calls to Layout() to allow keeping track of which view should be sticky. 148 // calls to Layout() to allow keeping track of which view should be sticky.
149 struct Header { 149 struct Header {
150 explicit Header(views::View* view) 150 explicit Header(views::View* view)
151 : view(view), natural_offset(view->y()) {} 151 : view(view), natural_offset(view->y()), separator(false) {}
152 152
153 // A header View that can be decorated as sticky. 153 // A header View that can be decorated as sticky.
154 views::View* view; 154 views::View* view;
155 155
156 // Offset from the top of ScrollContentsView to |view|'s original vertical 156 // Offset from the top of ScrollContentsView to |view|'s original vertical
157 // position. 157 // position.
158 int natural_offset; 158 int natural_offset;
159
160 // True when a separator needs to be painted below the header when another
161 // header is pushing |this| header up.
162 bool separator;
tdanderson 2016/11/24 23:37:54 I suggest renaming to |draw_separator_below| or si
varkha 2016/11/28 17:14:39 Done.
159 }; 163 };
160 164
161 // Adjusts y-position of header rows allowing one or two rows to stick to the 165 // Adjusts y-position of header rows allowing one or two rows to stick to the
162 // top of the visible viewport. 166 // top of the visible viewport.
163 void PositionHeaderRows() { 167 void PositionHeaderRows() {
164 const int scroll_offset = -y(); 168 const int scroll_offset = -y();
165 Header* previous_header = nullptr; 169 Header* previous_header = nullptr;
166 for (auto& header : base::Reversed(headers_)) { 170 for (auto& header : base::Reversed(headers_)) {
167 views::View* header_view = header.view; 171 views::View* header_view = header.view;
168 if (header.natural_offset >= scroll_offset) { 172 if (header.natural_offset >= scroll_offset) {
173 header.separator = false;
tdanderson 2016/11/24 23:37:54 Consider moving this line directly above line 172
varkha 2016/11/28 17:14:39 Done.
174 header_view->SetY(header.natural_offset);
tdanderson 2016/11/24 23:37:54 Is there a reason for moving this line before prev
varkha 2016/11/28 17:14:39 Just seemed nicer with the now moved assignment. M
169 previous_header = &header; 175 previous_header = &header;
170 header_view->SetY(header.natural_offset);
171 continue; 176 continue;
172 } 177 }
173 if (previous_header && 178 if (previous_header &&
174 previous_header->view->y() < scroll_offset + header_view->height()) { 179 previous_header->view->y() <= scroll_offset + header_view->height()) {
tdanderson 2016/11/24 23:37:54 Double checking my understanding: you changed this
varkha 2016/11/28 17:14:39 Yes, exactly. Otherwise I would get a flash of no
175 // Lower header displacing the header above. 180 // Lower header displacing the header above.
181 header.separator = true;
176 header_view->SetY(previous_header->view->y() - header_view->height()); 182 header_view->SetY(previous_header->view->y() - header_view->height());
177 } else { 183 } else {
178 // A header becomes sticky. 184 // A header becomes sticky.
185 header.separator = false;
179 header_view->SetY(scroll_offset); 186 header_view->SetY(scroll_offset);
180 header_view->Layout(); 187 header_view->Layout();
181 header_view->SchedulePaint(); 188 header_view->SchedulePaint();
182 } 189 }
183 break; 190 break;
184 } 191 }
185 } 192 }
186 193
187 // Paints a separator for a header view. The separator can be a horizontal 194 // Paints a separator for a header view. The separator can be a horizontal
188 // rule or a horizontal shadow, depending on whether the header is sticking to 195 // rule or a horizontal shadow, depending on whether the header is sticking to
189 // the top of the scroll viewport. The return value indicates whether a shadow 196 // the top of the scroll viewport. The return value indicates whether a shadow
190 // was drawn. 197 // was drawn.
191 bool PaintDelineation(const Header& header, const ui::PaintContext& context) { 198 bool PaintDelineation(const Header& header, const ui::PaintContext& context) {
192 const View* view = header.view; 199 const View* view = header.view;
193 const bool at_top = view->y() == -y();
194 200
195 // If the header is where it normally belongs, draw a separator above. 201 // If the header is where it normally belongs, draw nothing.
196 if (view->y() == header.natural_offset) { 202 if (view->y() == header.natural_offset)
197 // But if the header is at the very top of the viewport, draw nothing. 203 return false;
198 if (at_top)
199 return false;
200 204
205 // If the header is pushed by a header directly below it, draw a separator.
206 if (header.separator) {
201 // TODO(estade): look better at 1.5x scale. 207 // TODO(estade): look better at 1.5x scale.
202 ui::PaintRecorder recorder(context, size()); 208 ui::PaintRecorder recorder(context, size());
203 gfx::Canvas* canvas = recorder.canvas(); 209 gfx::Canvas* canvas = recorder.canvas();
204 gfx::Rect separator = view->bounds(); 210 gfx::Rect separator = view->bounds();
211 separator.set_y(separator.bottom() - kSeparatorWidth);
205 separator.set_height(kSeparatorWidth); 212 separator.set_height(kSeparatorWidth);
206 canvas->FillRect(separator, kSeparatorColor); 213 canvas->FillRect(separator, kSeparatorColor);
207 return false; 214 return false;
208 } 215 }
209 216
210 // If the header is displaced but is not at the top of the viewport, it's
211 // being pushed out by another header. Draw nothing.
212 if (!at_top)
213 return false;
214
215 // Otherwise, draw a shadow below. 217 // Otherwise, draw a shadow below.
216 DrawShadow(context, 218 DrawShadow(context,
217 gfx::Rect(0, 0, view->width(), view->bounds().bottom())); 219 gfx::Rect(0, 0, view->width(), view->bounds().bottom()));
218 return true; 220 return true;
219 } 221 }
220 222
221 // Draws a drop shadow below |shadowed_area|. 223 // Draws a drop shadow below |shadowed_area|.
222 void DrawShadow(const ui::PaintContext& context, 224 void DrawShadow(const ui::PaintContext& context,
223 const gfx::Rect& shadowed_area) { 225 const gfx::Rect& shadowed_area) {
224 ui::PaintRecorder recorder(context, size()); 226 ui::PaintRecorder recorder(context, size());
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
565 if (index < child_count() - 1 && child_at(index + 1) != title_row_) 567 if (index < child_count() - 1 && child_at(index + 1) != title_row_)
566 scroll_border_->set_visible(true); 568 scroll_border_->set_visible(true);
567 else 569 else
568 scroll_border_->set_visible(false); 570 scroll_border_->set_visible(false);
569 } 571 }
570 572
571 views::View::OnPaintBorder(canvas); 573 views::View::OnPaintBorder(canvas);
572 } 574 }
573 575
574 } // namespace ash 576 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698