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

Side by Side Diff: ui/views/layout/align_layout_state.h

Issue 2445633003: Experimental alignment layout manager using state retained in the layout manager
Patch Set: 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
« no previous file with comments | « ui/views/BUILD.gn ('k') | ui/views/layout/align_layout_state.cc » ('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) 2011 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_LAYOUT_ALIGN_LAYOUT_STATE_H_
6 #define UI_VIEWS_LAYOUT_ALIGN_LAYOUT_STATE_H_
7
8 #include <stddef.h>
9
10 #include <algorithm>
11 #include <initializer_list>
12 #include <map>
13 #include <vector>
14
15 #include "base/compiler_specific.h"
16 #include "base/macros.h"
17 #include "ui/gfx/geometry/point.h"
18 #include "ui/gfx/geometry/rect.h"
19 #include "ui/views/align_attribute.h"
20 #include "ui/views/anchor_attribute.h"
21 #include "ui/views/layout/layout_manager.h"
22 #include "ui/views/view.h"
23
24 namespace views {
25
26 ///////////////////////////////////////////////////////////////////////////////
27 //
28 // AlignLayout
29 // A LayoutManager that causes the associated view's children to be aligned
30 // and/or anchored within the bounds of their parent based on the value of the
31 // views' align or anchor attributes.
32 //
33 ///////////////////////////////////////////////////////////////////////////////
34 class VIEWS_EXPORT AlignLayoutState : public LayoutManager {
35 public:
36 AlignLayoutState();
37 ~AlignLayoutState() override;
38
39 // Overridden from LayoutManager:
40 void Installed(View* host) override;
41 void Layout(View* host) override;
42 gfx::Size GetPreferredSize(const View* host) const override;
43 int GetPreferredHeightForWidth(const View* host, int width) const override;
44 void ViewAdded(View* host, View* view) override;
45 void ViewRemoved(View* host, View* view) override;
46
47 void AlignView(View* view, Align align);
48 void AnchorView(View* view, Anchors anchors);
49 void AnchorView(View* view, const std::initializer_list<Anchor>& anchors);
50 void NoAlignView(View* view);
51 void NoAnchorView(View* view);
52
53 void SetViewBounds(View* view, int x, int y, int width, int height);
54
55 private:
56 struct AnchorState {
57 AnchorState();
58 AnchorState(Anchors anchors);
59 AnchorState(const AnchorState& state);
60 ~AnchorState();
61 Anchors anchors;
62 gfx::Point anchor_basis;
63 };
64 using AlignMap = std::map<const View*, Align>;
65 using AnchorMap = std::map<const View*, AnchorState>;
66 void AlignViews(View* host, Align align, gfx::Rect& contents);
67 bool FindAlign(View* view, Align* align);
68 bool FindAlign(const View* view, Align* align) const;
69 bool FindAnchorState(View* view, AnchorState** state);
70 void InternalUpdateAnchorBasis(View* view, AnchorMap::iterator pos);
71 void PlaceView(View* view, Align align, gfx::Rect& contents);
72 bool ShouldAlign(View* host);
73 bool ShouldInsert(View* child1, View* child2, Align align);
74 void UpdateAnchorAlign(View *view, Align align);
75 void UpdateAnchorBasis(View* view);
76 AlignMap align_map_;
77 AnchorMap anchor_map_;
78 gfx::Size last_host_size_;
79 DISALLOW_COPY_AND_ASSIGN(AlignLayoutState);
80 };
81
82 } // namespace views
83
84 #endif // UI_VIEWS_LAYOUT_FILL_LAYOUT_STATE_H_
OLDNEW
« no previous file with comments | « ui/views/BUILD.gn ('k') | ui/views/layout/align_layout_state.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698