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

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

Issue 2489883005: Fix a couple issues with sticky headers (Closed)
Patch Set: rebase Created 4 years, 1 month 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_tray.h" 10 #include "ash/common/system/tray/system_tray.h"
(...skipping 25 matching lines...) Expand all
36 const int kTitleRowSeparatorIndex = 1; 36 const int kTitleRowSeparatorIndex = 1;
37 37
38 // A view that is used as ScrollView contents. It supports designating some of 38 // A view that is used as ScrollView contents. It supports designating some of
39 // the children as sticky header rows. The sticky header rows are not scrolled 39 // the children as sticky header rows. The sticky header rows are not scrolled
40 // above the top of the visible viewport until the next one "pushes" it up and 40 // above the top of the visible viewport until the next one "pushes" it up and
41 // are painted above other children. To indicate that a child is a sticky header 41 // are painted above other children. To indicate that a child is a sticky header
42 // row use set_id(VIEW_ID_STICKY_HEADER). 42 // row use set_id(VIEW_ID_STICKY_HEADER).
43 class ScrollContentsView : public views::View, 43 class ScrollContentsView : public views::View,
44 public views::ViewTargeterDelegate { 44 public views::ViewTargeterDelegate {
45 public: 45 public:
46 ScrollContentsView() { 46 ScrollContentsView()
47 : box_layout_(new views::BoxLayout(
48 views::BoxLayout::kVertical,
49 0,
50 0,
51 UseMd() ? 0 : kContentsBetweenChildSpacingNonMd)) {
47 SetEventTargeter(base::MakeUnique<views::ViewTargeter>(this)); 52 SetEventTargeter(base::MakeUnique<views::ViewTargeter>(this));
48 SetLayoutManager( 53 SetLayoutManager(box_layout_);
49 new views::BoxLayout(views::BoxLayout::kVertical, 0,
50 UseMd() ? kContentsVerticalSpacingMd : 0,
51 UseMd() ? 0 : kContentsBetweenChildSpacingNonMd));
52 } 54 }
53 ~ScrollContentsView() override {} 55 ~ScrollContentsView() override {}
54 56
55 protected: 57 protected:
56 // views::View: 58 // views::View:
57 void OnBoundsChanged(const gfx::Rect& previous_bounds) override { 59 void OnBoundsChanged(const gfx::Rect& previous_bounds) override {
58 PositionHeaderRows(); 60 PositionHeaderRows();
59 } 61 }
60 62
61 void PaintChildren(const ui::PaintContext& context) override { 63 void PaintChildren(const ui::PaintContext& context) override {
(...skipping 21 matching lines...) Expand all
83 } 85 }
84 86
85 void ViewHierarchyChanged( 87 void ViewHierarchyChanged(
86 const ViewHierarchyChangedDetails& details) override { 88 const ViewHierarchyChangedDetails& details) override {
87 if (!details.is_add && details.parent == this) { 89 if (!details.is_add && details.parent == this) {
88 headers_.erase(std::remove_if(headers_.begin(), headers_.end(), 90 headers_.erase(std::remove_if(headers_.begin(), headers_.end(),
89 [details](const Header& header) { 91 [details](const Header& header) {
90 return header.view == details.child; 92 return header.view == details.child;
91 }), 93 }),
92 headers_.end()); 94 headers_.end());
95 } else if (details.is_add && details.parent == this &&
96 details.child == child_at(0)) {
97 // We always want padding on the bottom of the scroll contents.
98 // We only want padding on the top of the scroll contents if the first
99 // child is not a header (in that case, the padding is built into the
100 // header).
101 DCHECK_EQ(box_layout_, GetLayoutManager());
102 box_layout_->set_inside_border_insets(
103 gfx::Insets(details.child->id() == VIEW_ID_STICKY_HEADER
104 ? 0
105 : kMenuSeparatorVerticalPadding,
106 0, kMenuSeparatorVerticalPadding, 0));
93 } 107 }
94 } 108 }
95 109
96 // views::ViewTargeterDelegate: 110 // views::ViewTargeterDelegate:
97 View* TargetForRect(View* root, const gfx::Rect& rect) override { 111 View* TargetForRect(View* root, const gfx::Rect& rect) override {
98 // Give header rows first dibs on events. 112 // Give header rows first dibs on events.
99 for (auto& header : headers_) { 113 for (auto& header : headers_) {
100 views::View* view = header.view; 114 views::View* view = header.view;
101 gfx::Rect local_to_header = rect; 115 gfx::Rect local_to_header = rect;
102 local_to_header.Offset(-view->x(), -view->y()); 116 local_to_header.Offset(-view->x(), -view->y());
103 if (ViewTargeterDelegate::DoesIntersectRect(view, local_to_header)) 117 if (ViewTargeterDelegate::DoesIntersectRect(view, local_to_header))
104 return ViewTargeterDelegate::TargetForRect(view, local_to_header); 118 return ViewTargeterDelegate::TargetForRect(view, local_to_header);
105 } 119 }
106 return ViewTargeterDelegate::TargetForRect(root, rect); 120 return ViewTargeterDelegate::TargetForRect(root, rect);
107 } 121 }
108 122
109 private: 123 private:
110 const int kSeparatorThickness = 1; 124 const int kSeparatorThickness = 1;
111 const SkColor kSeparatorColor = SkColorSetA(SK_ColorBLACK, 0x1F); 125 const SkColor kSeparatorColor = SkColorSetA(SK_ColorBLACK, 0x1F);
112 const int kShadowOffsetY = 2; 126 const int kShadowOffsetY = 2;
113 const int kShadowBlur = 2; 127 const int kShadowBlur = 2;
114 const int kContentsVerticalSpacingMd = 4;
115 // TODO(fukino): Remove this constant once we stop maintaining pre-MD design. 128 // TODO(fukino): Remove this constant once we stop maintaining pre-MD design.
116 // crbug.com/614453. 129 // crbug.com/614453.
117 const int kContentsBetweenChildSpacingNonMd = 1; 130 const int kContentsBetweenChildSpacingNonMd = 1;
118 131
119 // A structure that keeps the original offset of each header between the 132 // A structure that keeps the original offset of each header between the
120 // calls to Layout() to allow keeping track of which view should be sticky. 133 // calls to Layout() to allow keeping track of which view should be sticky.
121 struct Header { 134 struct Header {
122 explicit Header(views::View* view) 135 explicit Header(views::View* view)
123 : view(view), natural_offset(view->y()) {} 136 : view(view), natural_offset(view->y()) {}
124 137
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 gfx::ShadowValues shadow; 203 gfx::ShadowValues shadow;
191 shadow.emplace_back(gfx::Vector2d(0, kShadowOffsetY), kShadowBlur, 204 shadow.emplace_back(gfx::Vector2d(0, kShadowOffsetY), kShadowBlur,
192 kSeparatorColor); 205 kSeparatorColor);
193 paint.setLooper(gfx::CreateShadowDrawLooperCorrectBlur(shadow)); 206 paint.setLooper(gfx::CreateShadowDrawLooperCorrectBlur(shadow));
194 paint.setAntiAlias(true); 207 paint.setAntiAlias(true);
195 gfx::Rect rect(0, 0, view->width(), view->bounds().bottom()); 208 gfx::Rect rect(0, 0, view->width(), view->bounds().bottom());
196 canvas->ClipRect(rect, SkRegion::kDifference_Op); 209 canvas->ClipRect(rect, SkRegion::kDifference_Op);
197 canvas->DrawRect(rect, paint); 210 canvas->DrawRect(rect, paint);
198 } 211 }
199 212
213 views::BoxLayout* box_layout_;
214
200 // Header child views that stick to the top of visible viewport when scrolled. 215 // Header child views that stick to the top of visible viewport when scrolled.
201 std::vector<Header> headers_; 216 std::vector<Header> headers_;
202 217
203 DISALLOW_COPY_AND_ASSIGN(ScrollContentsView); 218 DISALLOW_COPY_AND_ASSIGN(ScrollContentsView);
204 }; 219 };
205 220
206 // Constants for the title row in material design. 221 // Constants for the title row in material design.
207 const int kTitleRowVerticalPadding = 4; 222 const int kTitleRowVerticalPadding = 4;
208 const int kTitleRowProgressBarHeight = 2; 223 const int kTitleRowProgressBarHeight = 2;
209 const int kTitleRowSeparatorHeight = 1; 224 const int kTitleRowSeparatorHeight = 1;
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 if (index < child_count() - 1 && child_at(index + 1) != title_row_) 466 if (index < child_count() - 1 && child_at(index + 1) != title_row_)
452 scroll_border_->set_visible(true); 467 scroll_border_->set_visible(true);
453 else 468 else
454 scroll_border_->set_visible(false); 469 scroll_border_->set_visible(false);
455 } 470 }
456 471
457 views::View::OnPaintBorder(canvas); 472 views::View::OnPaintBorder(canvas);
458 } 473 }
459 474
460 } // namespace ash 475 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/system/chromeos/network/vpn_list_view.cc ('k') | ash/common/system/tray/tray_popup_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698