1 // Copyright 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_TEST_TEST_LAYOUT_MANAGER_H_
6 #define UI_VIEWS_TEST_TEST_LAYOUT_MANAGER_H_
7 
8 #include "base/macros.h"
9 #include "ui/gfx/geometry/size.h"
10 #include "ui/views/layout/layout_manager.h"
11 
12 namespace views {
13 namespace test {
14 
15 // A stub layout manager that returns a specific preferred size and height for
16 // width.
17 class TestLayoutManager : public LayoutManager {
18  public:
19   TestLayoutManager();
20   ~TestLayoutManager() override;
21 
SetPreferredSize(const gfx::Size & size)22   void SetPreferredSize(const gfx::Size& size) { preferred_size_ = size; }
23 
set_preferred_height_for_width(int height)24   void set_preferred_height_for_width(int height) {
25     preferred_height_for_width_ = height;
26   }
27 
invalidate_count()28   int invalidate_count() const { return invalidate_count_; }
29 
30   // LayoutManager:
31   void Layout(View* host) override;
32   gfx::Size GetPreferredSize(const View* host) const override;
33   int GetPreferredHeightForWidth(const View* host, int width) const override;
34   void InvalidateLayout() override;
35 
36  private:
37   // The return value of GetPreferredSize();
38   gfx::Size preferred_size_;
39 
40   // The return value for GetPreferredHeightForWidth().
41   int preferred_height_for_width_ = 0;
42 
43   // The number of calls to InvalidateLayout().
44   int invalidate_count_ = 0;
45 
46   DISALLOW_COPY_AND_ASSIGN(TestLayoutManager);
47 };
48 
49 }  // namespace test
50 }  // namespace views
51 
52 #endif  // UI_VIEWS_TEST_TEST_LAYOUT_MANAGER_H_
53