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

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

Issue 2557333003: [ash-md] Stacks child layers properly for sticky header rows (Closed)
Patch Set: [ash-md] Stacks child layers properly for sticky header rows (consider children first) 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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 void PaintChildren(const ui::PaintContext& context) override { 71 void PaintChildren(const ui::PaintContext& context) override {
72 for (int i = 0; i < child_count(); ++i) { 72 for (int i = 0; i < child_count(); ++i) {
73 if (child_at(i)->id() != VIEW_ID_STICKY_HEADER && !child_at(i)->layer()) 73 if (child_at(i)->id() != VIEW_ID_STICKY_HEADER && !child_at(i)->layer())
74 child_at(i)->Paint(context); 74 child_at(i)->Paint(context);
75 } 75 }
76 bool did_draw_shadow = false; 76 bool did_draw_shadow = false;
77 // Paint header rows above other children in Z-order. 77 // Paint header rows above other children in Z-order.
78 for (auto& header : headers_) { 78 for (auto& header : headers_) {
79 if (!header.view->layer()) 79 if (!header.view->layer())
80 header.view->Paint(context); 80 header.view->Paint(context);
81 did_draw_shadow = PaintDelineation(header, context) || did_draw_shadow; 81 did_draw_shadow = PaintDelineation(header, context) || did_draw_shadow;
varkha 2016/12/09 18:59:32 Self review: This is broken now that the headers h
varkha 2016/12/12 18:24:05 Should be fixed now that a separator is painted by
82 } 82 }
83 83
84 // Draw a shadow at the top of the viewport when scrolled, but only if a 84 // Draw a shadow at the top of the viewport when scrolled, but only if a
85 // header didn't already draw one. Overlap the shadow with the separator 85 // header didn't already draw one. Overlap the shadow with the separator
86 // that's below the header view so we don't get both a separator and a full 86 // that's below the header view so we don't get both a separator and a full
87 // shadow. 87 // shadow.
88 if (y() != 0 && !did_draw_shadow) 88 if (y() != 0 && !did_draw_shadow)
89 DrawShadow(context, gfx::Rect(0, 0, width(), -y() - kSeparatorWidth)); 89 DrawShadow(context, gfx::Rect(0, 0, width(), -y() - kSeparatorWidth));
90 } 90 }
91 91
92 void Layout() override { 92 void Layout() override {
93 views::View::Layout(); 93 views::View::Layout();
94 headers_.clear(); 94 headers_.clear();
95 for (int i = 0; i < child_count(); ++i) { 95 for (int i = 0; i < child_count(); ++i) {
96 views::View* view = child_at(i); 96 views::View* view = child_at(i);
97 if (view->id() == VIEW_ID_STICKY_HEADER) 97 if (view->id() == VIEW_ID_STICKY_HEADER)
98 headers_.emplace_back(view); 98 headers_.emplace_back(view);
99 } 99 }
100 PositionHeaderRows(); 100 PositionHeaderRows();
101 } 101 }
102 102
103 void ReorderChildLayers(ui::Layer* parent_layer) override {
104 views::View::ReorderChildLayers(parent_layer);
105 ui::Layer* topmost_layer = TopmostLayer(this, parent_layer);
106 if (!topmost_layer)
107 return;
108
109 // Keep the sticky headers with layers above the rest of the children's
110 // layers. Make sure to avoid changing the stacking order of the layers that
111 // are children of |parent_layer| but do not belong to the same parent view.
112 // Note: this assumes that all views that have id=VIEW_ID_STICKY_HEADER have
113 // a layer.
114 for (int i = child_count() - 1; i >= 0; --i) {
115 View* child = child_at(i);
116 if (child->id() == VIEW_ID_STICKY_HEADER) {
117 if (child->layer() != topmost_layer)
118 parent_layer->StackAbove(child->layer(), topmost_layer);
119 }
120 }
121 }
122
103 void ViewHierarchyChanged( 123 void ViewHierarchyChanged(
104 const ViewHierarchyChangedDetails& details) override { 124 const ViewHierarchyChangedDetails& details) override {
105 if (!details.is_add && details.parent == this) { 125 if (!details.is_add && details.parent == this) {
106 headers_.erase(std::remove_if(headers_.begin(), headers_.end(), 126 headers_.erase(std::remove_if(headers_.begin(), headers_.end(),
107 [details](const Header& header) { 127 [details](const Header& header) {
108 return header.view == details.child; 128 return header.view == details.child;
109 }), 129 }),
110 headers_.end()); 130 headers_.end());
111 } else if (details.is_add && details.parent == this && 131 } else if (details.is_add && details.parent == this &&
112 details.child == child_at(0)) { 132 details.child == child_at(0)) {
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 SkPaint paint; 247 SkPaint paint;
228 gfx::ShadowValues shadow; 248 gfx::ShadowValues shadow;
229 shadow.emplace_back(gfx::Vector2d(0, kShadowOffsetY), kShadowBlur, 249 shadow.emplace_back(gfx::Vector2d(0, kShadowOffsetY), kShadowBlur,
230 kSeparatorColor); 250 kSeparatorColor);
231 paint.setLooper(gfx::CreateShadowDrawLooperCorrectBlur(shadow)); 251 paint.setLooper(gfx::CreateShadowDrawLooperCorrectBlur(shadow));
232 paint.setAntiAlias(true); 252 paint.setAntiAlias(true);
233 canvas->ClipRect(shadowed_area, kDifference_SkClipOp); 253 canvas->ClipRect(shadowed_area, kDifference_SkClipOp);
234 canvas->DrawRect(shadowed_area, paint); 254 canvas->DrawRect(shadowed_area, paint);
235 } 255 }
236 256
257 // Recursively iterates through children to return the child layer that is
258 // stacked at the top. Only considers layers that are direct |parent_layer|'s
259 // children.
260 ui::Layer* TopmostLayer(views::View* view, ui::Layer* parent_layer) {
261 DCHECK(parent_layer);
262 // Iterate backwards through the children to find the topmost layer.
263 for (int i = view->child_count() - 1; i >= 0; --i) {
264 views::View* child = view->child_at(i);
265 ui::Layer* layer = TopmostLayer(child, parent_layer);
266 if (layer)
267 return layer;
268 }
269 if (view->layer() && view->layer() != parent_layer &&
270 view->layer()->parent() == parent_layer) {
271 return view->layer();
272 }
273 return nullptr;
274 }
275
237 views::BoxLayout* box_layout_; 276 views::BoxLayout* box_layout_;
238 277
239 // Header child views that stick to the top of visible viewport when scrolled. 278 // Header child views that stick to the top of visible viewport when scrolled.
240 std::vector<Header> headers_; 279 std::vector<Header> headers_;
241 280
242 DISALLOW_COPY_AND_ASSIGN(ScrollContentsView); 281 DISALLOW_COPY_AND_ASSIGN(ScrollContentsView);
243 }; 282 };
244 283
245 // Constants for the title row in material design. 284 // Constants for the title row in material design.
246 const int kTitleRowVerticalPadding = 4; 285 const int kTitleRowVerticalPadding = 4;
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
566 if (index < child_count() - 1 && child_at(index + 1) != title_row_) 605 if (index < child_count() - 1 && child_at(index + 1) != title_row_)
567 scroll_border_->set_visible(true); 606 scroll_border_->set_visible(true);
568 else 607 else
569 scroll_border_->set_visible(false); 608 scroll_border_->set_visible(false);
570 } 609 }
571 610
572 views::View::OnPaintBorder(canvas); 611 views::View::OnPaintBorder(canvas);
573 } 612 }
574 613
575 } // namespace ash 614 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698