OLD | NEW |
(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 #ifndef UI_VIEWS_ANCHOR_ATTRIBUTE_H_ |
| 6 #define UI_VIEWS_ANCHOR_ATTRIBUTE_H_ |
| 7 |
| 8 #include "base/macros.h" |
| 9 #include "base/set_template.h" |
| 10 #include "ui/gfx/geometry/point.h" |
| 11 #include "ui/gfx/geometry/rect.h" |
| 12 #include "ui/gfx/geometry/size.h" |
| 13 #include "ui/views/attributes.h" |
| 14 #include "ui/views/fill_attribute.h" |
| 15 #include "ui/views/view.h" |
| 16 |
| 17 namespace views { |
| 18 |
| 19 enum class Anchor { |
| 20 // Anchor view's left side to the parent's left side of its content bounds. |
| 21 Left, |
| 22 // Anchor view's top side to the parent's top side of its content bounds. |
| 23 Top, |
| 24 // Anchor view's right side to the parent's right side of its content |
| 25 // bounds. |
| 26 Right, |
| 27 // Anchor view's bottom side to the parent's bottom side of its content |
| 28 // bounds. |
| 29 Bottom, |
| 30 }; |
| 31 |
| 32 using Anchors = base::SetOf<Anchor, Anchor::Bottom>; |
| 33 |
| 34 struct VIEWS_EXPORT AnchorContent { |
| 35 AnchorContent(); |
| 36 AnchorContent(Anchors anchors); |
| 37 AnchorContent(const AnchorContent& content); |
| 38 static Anchors AnchorFill(Fill fill); |
| 39 gfx::Point& anchorBasis() { return anchor_basis_; } |
| 40 Anchors& anchors() { return anchors_; } |
| 41 gfx::Size& LastParentSize() { return last_parent_size_; } |
| 42 void SetAnchors(Anchors anchors); |
| 43 void SetAttribute(Attribute *attribute) { attribute_ = attribute; } |
| 44 void UpdateAnchorBasis(View *view); |
| 45 private: |
| 46 Attribute *attribute_; |
| 47 Anchors anchors_; |
| 48 gfx::Point anchor_basis_; |
| 49 gfx::Size last_parent_size_; |
| 50 }; |
| 51 |
| 52 class VIEWS_EXPORT AnchorAttribute : public CustomAttribute<AnchorContent> { |
| 53 public: |
| 54 AnchorAttribute(); |
| 55 AnchorAttribute(Anchors anchors); |
| 56 AnchorAttribute(AnchorContent& content); |
| 57 AttributeId Identity() const override; |
| 58 void Notification(Attribute::NotifyType type, Attribute* attribute) override; |
| 59 void ViewNotification(View *view) override; |
| 60 }; |
| 61 |
| 62 REGISTER_ATTRIBUTE_ID(CustomAttribute<AnchorContent>); |
| 63 REGISTER_ATTRIBUTE_ID(AnchorAttribute); |
| 64 |
| 65 } // namespace views |
| 66 |
| 67 #endif // UI_VIEWS_ANCHOR_ATTRIBUTE_H_ |
OLD | NEW |