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 #include "ui/views/layout/layout_manager.h"
6 
7 #include "base/auto_reset.h"
8 #include "ui/views/view.h"
9 
10 namespace views {
11 
12 LayoutManager::~LayoutManager() = default;
13 
Installed(View * host)14 void LayoutManager::Installed(View* host) {}
15 
InvalidateLayout()16 void LayoutManager::InvalidateLayout() {}
17 
GetMinimumSize(const View * host) const18 gfx::Size LayoutManager::GetMinimumSize(const View* host) const {
19   // Fall back to using preferred size if no minimum size calculation is
20   // available (e.g. legacy layout managers).
21   //
22   // Ideally we'd just call GetPreferredSize() on ourselves here, but because
23   // some legacy views with layout managers override GetPreferredSize(), we need
24   // to call GetPreferredSize() on the host view instead. The default
25   // views::View behavior will be to call GetPreferredSize() on this layout
26   // manager, so the fallback behavior in all other cases is as expected.
27   return host->GetPreferredSize();
28 }
29 
GetPreferredHeightForWidth(const View * host,int width) const30 int LayoutManager::GetPreferredHeightForWidth(const View* host,
31                                               int width) const {
32   return GetPreferredSize(host).height();
33 }
34 
GetAvailableSize(const View * host,const View * view) const35 SizeBounds LayoutManager::GetAvailableSize(const View* host,
36                                            const View* view) const {
37   return SizeBounds();
38 }
39 
ViewAdded(View * host,View * view)40 void LayoutManager::ViewAdded(View* host, View* view) {}
41 
ViewRemoved(View * host,View * view)42 void LayoutManager::ViewRemoved(View* host, View* view) {}
43 
ViewVisibilitySet(View * host,View * view,bool old_visibility,bool new_visibility)44 void LayoutManager::ViewVisibilitySet(View* host,
45                                       View* view,
46                                       bool old_visibility,
47                                       bool new_visibility) {
48   // Changing the visibility of a child view should force a re-layout. There is
49   // more sophisticated logic in LayoutManagerBase but this should be adequate
50   // for most legacy layouts (none of which override this method).
51   // TODO(dfried): Remove this if/when LayoutManager and LayoutManagerBase can
52   // be merged.
53   if (old_visibility != new_visibility)
54     host->InvalidateLayout();
55 }
56 
SetViewVisibility(View * view,bool visible)57 void LayoutManager::SetViewVisibility(View* view, bool visible) {
58   DCHECK(!view->parent() || view->parent()->GetLayoutManager() == this ||
59          view->parent()->GetLayoutManager() == nullptr);
60   base::AutoReset<View*> setter(&view_setting_visibility_on_, view);
61   view->SetVisible(visible);
62 }
63 
GetChildViewsInPaintOrder(const View * host) const64 std::vector<View*> LayoutManager::GetChildViewsInPaintOrder(
65     const View* host) const {
66   return host->children();
67 }
68 
69 }  // namespace views
70