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

Side by Side Diff: ui/views/anchor_attribute.cc

Issue 2230913003: Experimental alignment layout manager using a property on the views Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Renamed AlignAttribute and associated types to FillAttribute Created 4 years, 2 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
« no previous file with comments | « ui/views/anchor_attribute.h ('k') | ui/views/attributes.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ui/views/anchor_attribute.h"
6
7 namespace views {
8
9 AnchorContent::AnchorContent()
10 : attribute_(nullptr),
11 anchors_({Anchor::Top, Anchor::Left}),
12 anchor_basis_(0, 0),
13 last_parent_size_(0, 0) {}
14
15 AnchorContent::AnchorContent(Anchors anchors)
16 : attribute_(nullptr),
17 anchors_(anchors),
18 anchor_basis_(0, 0),
19 last_parent_size_(0, 0) {}
20
21 AnchorContent::AnchorContent(const AnchorContent& content)
22 : attribute_(content.attribute_),
23 anchors_(content.anchors_),
24 anchor_basis_(content.anchor_basis_),
25 last_parent_size_(content.last_parent_size_) {}
26
27 AnchorAttribute::AnchorAttribute() :
28 CustomAttribute<AnchorContent>(AnchorContent()) {
29 GetContent().SetAttribute(this);
30 }
31
32 AnchorAttribute::AnchorAttribute(Anchors anchors) :
33 CustomAttribute<AnchorContent>(AnchorContent(anchors)) {
34 GetContent().SetAttribute(this);
35 }
36
37 AnchorAttribute::AnchorAttribute(AnchorContent& content) :
38 CustomAttribute<AnchorContent>(content) {
39 GetContent().SetAttribute(this);
40 }
41
42 AttributeId AnchorAttribute::Identity() const {
43 return GetAttributeId<AnchorAttribute>();
44 }
45
46 void AnchorAttribute::Notification(Attribute::NotifyType type,
47 Attribute* attribute) {
48 FillAttribute* fill = attribute->AsAttribute<FillAttribute>();
49 if (fill) {
50 if (type == Attribute::NotifyType::AttributeAdded)
51 GetContent().SetAnchors(AnchorContent::AnchorFill(fill->fill()));
52 else
53 GetContent().SetAnchors(Anchors({Anchor::Left, Anchor::Top}));
54 }
55 }
56
57 void AnchorAttribute::ViewNotification(View* view) {
58 GetContent().UpdateAnchorBasis(view);
59 }
60
61 Anchors AnchorContent::AnchorFill(Fill fill) {
62 static int anchor_fill[] = {
63 // Fill::Left
64 (1 << static_cast<int>(Anchor::Left)) |
65 (1 << static_cast<int>(Anchor::Top)) |
66 (1 << static_cast<int>(Anchor::Bottom)),
67 // Fill::Top
68 (1 << static_cast<int>(Anchor::Left)) |
69 (1 << static_cast<int>(Anchor::Top)) |
70 (1 << static_cast<int>(Anchor::Right)),
71 // Fill::Right
72 (1 << static_cast<int>(Anchor::Top)) |
73 (1 << static_cast<int>(Anchor::Right)) |
74 (1 << static_cast<int>(Anchor::Bottom)),
75 // Fill::Bottom
76 (1 << static_cast<int>(Anchor::Left)) |
77 (1 << static_cast<int>(Anchor::Right)) |
78 (1 << static_cast<int>(Anchor::Bottom)),
79 // Fill::Content
80 (1 << static_cast<int>(Anchor::Left)) |
81 (1 << static_cast<int>(Anchor::Top)) |
82 (1 << static_cast<int>(Anchor::Right)) |
83 (1 << static_cast<int>(Anchor::Bottom)),
84 };
85 return Anchors(anchor_fill[static_cast<int>(fill)]);
86 }
87
88 void AnchorContent::SetAnchors(Anchors anchors) {
89 if (anchors_ != anchors) {
90 anchors_ = anchors;
91 UpdateAnchorBasis(attribute_->view());
92 }
93 }
94
95 void AnchorContent::UpdateAnchorBasis(View* view) {
96 if (anchors_.Equals({Anchor::Left, Anchor::Top})) {
97 last_parent_size_ = gfx::Size(0, 0);
98 return;
99 }
100 gfx::Point center_point = view->bounds().CenterPoint();
101 if (anchors_.Contains(Anchor::Right))
102 if (anchors_.Contains(Anchor::Left))
103 anchor_basis_.set_x(view->width());
104 else
105 anchor_basis_.set_x(view->x());
106 else
107 anchor_basis_.set_x(center_point.x());
108 if (anchors_.Contains(Anchor::Bottom))
109 if (anchors_.Contains(Anchor::Top))
110 anchor_basis_.set_y(view->height());
111 else
112 anchor_basis_.set_y(view->y());
113 else
114 anchor_basis_.set_y(center_point.y());
115 if (view->parent())
116 last_parent_size_ = view->parent()->GetContentsBounds().size();
117 }
118
119 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/anchor_attribute.h ('k') | ui/views/attributes.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698