OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/views/frame/opaque_browser_frame_view_layout.h" | 5 #include "chrome/browser/ui/views/frame/opaque_browser_frame_view_layout.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "chrome/browser/ui/views/profiles/avatar_menu_button.h" | 10 #include "chrome/browser/ui/views/profiles/avatar_menu_button.h" |
(...skipping 27 matching lines...) Expand all Loading... |
38 STATE_MINIMIZED, | 38 STATE_MINIMIZED, |
39 STATE_FULLSCREEN | 39 STATE_FULLSCREEN |
40 }; | 40 }; |
41 | 41 |
42 TestLayoutDelegate() | 42 TestLayoutDelegate() |
43 : show_avatar_(false), | 43 : show_avatar_(false), |
44 show_caption_buttons_(true), | 44 show_caption_buttons_(true), |
45 window_state_(STATE_NORMAL) { | 45 window_state_(STATE_NORMAL) { |
46 } | 46 } |
47 | 47 |
48 virtual ~TestLayoutDelegate() {} | 48 ~TestLayoutDelegate() override {} |
49 | 49 |
50 void SetWindowTitle(const base::string16& title) { | 50 void SetWindowTitle(const base::string16& title) { |
51 window_title_ = title; | 51 window_title_ = title; |
52 } | 52 } |
53 | 53 |
54 void SetShouldShowAvatar(bool show_avatar) { | 54 void SetShouldShowAvatar(bool show_avatar) { |
55 show_avatar_ = show_avatar; | 55 show_avatar_ = show_avatar; |
56 } | 56 } |
57 | 57 |
58 void SetShouldShowCaptionButtons(bool show_caption_buttons) { | 58 void SetShouldShowCaptionButtons(bool show_caption_buttons) { |
59 show_caption_buttons_ = show_caption_buttons; | 59 show_caption_buttons_ = show_caption_buttons; |
60 } | 60 } |
61 | 61 |
62 void SetWindowState(WindowState state) { | 62 void SetWindowState(WindowState state) { |
63 window_state_ = state; | 63 window_state_ = state; |
64 } | 64 } |
65 | 65 |
66 // OpaqueBrowserFrameViewLayoutDelegate overrides: | 66 // OpaqueBrowserFrameViewLayoutDelegate overrides: |
67 | 67 |
68 virtual bool ShouldShowWindowIcon() const override { | 68 bool ShouldShowWindowIcon() const override { return !window_title_.empty(); } |
69 return !window_title_.empty(); | |
70 } | |
71 | 69 |
72 virtual bool ShouldShowWindowTitle() const override { | 70 bool ShouldShowWindowTitle() const override { return !window_title_.empty(); } |
73 return !window_title_.empty(); | |
74 } | |
75 | 71 |
76 virtual base::string16 GetWindowTitle() const override { | 72 base::string16 GetWindowTitle() const override { return window_title_; } |
77 return window_title_; | |
78 } | |
79 | 73 |
80 virtual int GetIconSize() const override { | 74 int GetIconSize() const override { |
81 // The value on linux_aura and non-aura windows. | 75 // The value on linux_aura and non-aura windows. |
82 return 17; | 76 return 17; |
83 } | 77 } |
84 | 78 |
85 virtual bool ShouldLeaveOffsetNearTopBorder() const override { | 79 bool ShouldLeaveOffsetNearTopBorder() const override { |
86 return !IsMaximized(); | 80 return !IsMaximized(); |
87 } | 81 } |
88 | 82 |
89 virtual gfx::Size GetBrowserViewMinimumSize() const override { | 83 gfx::Size GetBrowserViewMinimumSize() const override { |
90 // Taken from a calculation in BrowserViewLayout. | 84 // Taken from a calculation in BrowserViewLayout. |
91 return gfx::Size(168, 64); | 85 return gfx::Size(168, 64); |
92 } | 86 } |
93 | 87 |
94 virtual bool ShouldShowCaptionButtons() const override { | 88 bool ShouldShowCaptionButtons() const override { |
95 return show_caption_buttons_; | 89 return show_caption_buttons_; |
96 } | 90 } |
97 | 91 |
98 virtual bool ShouldShowAvatar() const override { | 92 bool ShouldShowAvatar() const override { return show_avatar_; } |
99 return show_avatar_; | |
100 } | |
101 | 93 |
102 virtual bool IsRegularOrGuestSession() const override { | 94 bool IsRegularOrGuestSession() const override { return true; } |
103 return true; | |
104 } | |
105 | 95 |
106 virtual gfx::ImageSkia GetOTRAvatarIcon() const override { | 96 gfx::ImageSkia GetOTRAvatarIcon() const override { |
107 // The calculations depend on the size of the OTR resource, and chromeos | 97 // The calculations depend on the size of the OTR resource, and chromeos |
108 // uses a different sized image, so hard code the size of the current | 98 // uses a different sized image, so hard code the size of the current |
109 // windows/linux one. | 99 // windows/linux one. |
110 gfx::ImageSkiaRep rep(gfx::Size(40, 29), 1.0f); | 100 gfx::ImageSkiaRep rep(gfx::Size(40, 29), 1.0f); |
111 gfx::ImageSkia image(rep); | 101 gfx::ImageSkia image(rep); |
112 return image; | 102 return image; |
113 } | 103 } |
114 | 104 |
115 virtual bool IsMaximized() const override { | 105 bool IsMaximized() const override { return window_state_ == STATE_MAXIMIZED; } |
116 return window_state_ == STATE_MAXIMIZED; | |
117 } | |
118 | 106 |
119 virtual bool IsMinimized() const override { | 107 bool IsMinimized() const override { return window_state_ == STATE_MINIMIZED; } |
120 return window_state_ == STATE_MINIMIZED; | |
121 } | |
122 | 108 |
123 virtual bool IsFullscreen() const override { | 109 bool IsFullscreen() const override { |
124 return window_state_ == STATE_FULLSCREEN; | 110 return window_state_ == STATE_FULLSCREEN; |
125 } | 111 } |
126 | 112 |
127 virtual bool IsTabStripVisible() const override { | 113 bool IsTabStripVisible() const override { return window_title_.empty(); } |
128 return window_title_.empty(); | |
129 } | |
130 | 114 |
131 virtual int GetTabStripHeight() const override { | 115 int GetTabStripHeight() const override { |
132 return IsTabStripVisible() ? Tab::GetMinimumUnselectedSize().height() : 0; | 116 return IsTabStripVisible() ? Tab::GetMinimumUnselectedSize().height() : 0; |
133 } | 117 } |
134 | 118 |
135 virtual gfx::Size GetTabstripPreferredSize() const override { | 119 gfx::Size GetTabstripPreferredSize() const override { |
136 // Measured from Tabstrip::GetPreferredSize(). | 120 // Measured from Tabstrip::GetPreferredSize(). |
137 return IsTabStripVisible() ? gfx::Size(78, 29) : gfx::Size(0, 0); | 121 return IsTabStripVisible() ? gfx::Size(78, 29) : gfx::Size(0, 0); |
138 } | 122 } |
139 | 123 |
140 private: | 124 private: |
141 base::string16 window_title_; | 125 base::string16 window_title_; |
142 bool show_avatar_; | 126 bool show_avatar_; |
143 bool show_caption_buttons_; | 127 bool show_caption_buttons_; |
144 WindowState window_state_; | 128 WindowState window_state_; |
145 | 129 |
146 DISALLOW_COPY_AND_ASSIGN(TestLayoutDelegate); | 130 DISALLOW_COPY_AND_ASSIGN(TestLayoutDelegate); |
147 }; | 131 }; |
148 | 132 |
149 } // namespace | 133 } // namespace |
150 | 134 |
151 class OpaqueBrowserFrameViewLayoutTest : public views::ViewsTestBase { | 135 class OpaqueBrowserFrameViewLayoutTest : public views::ViewsTestBase { |
152 public: | 136 public: |
153 OpaqueBrowserFrameViewLayoutTest() {} | 137 OpaqueBrowserFrameViewLayoutTest() {} |
154 virtual ~OpaqueBrowserFrameViewLayoutTest() {} | 138 ~OpaqueBrowserFrameViewLayoutTest() override {} |
155 | 139 |
156 virtual void SetUp() override { | 140 void SetUp() override { |
157 views::ViewsTestBase::SetUp(); | 141 views::ViewsTestBase::SetUp(); |
158 | 142 |
159 delegate_.reset(new TestLayoutDelegate); | 143 delegate_.reset(new TestLayoutDelegate); |
160 layout_manager_ = new OpaqueBrowserFrameViewLayout(delegate_.get()); | 144 layout_manager_ = new OpaqueBrowserFrameViewLayout(delegate_.get()); |
161 layout_manager_->set_extra_caption_y(0); | 145 layout_manager_->set_extra_caption_y(0); |
162 layout_manager_->set_window_caption_spacing(0); | 146 layout_manager_->set_window_caption_spacing(0); |
163 widget_ = new Widget; | 147 widget_ = new Widget; |
164 widget_->Init(CreateParams(Widget::InitParams::TYPE_POPUP)); | 148 widget_->Init(CreateParams(Widget::InitParams::TYPE_POPUP)); |
165 root_view_ = widget_->GetRootView(); | 149 root_view_ = widget_->GetRootView(); |
166 root_view_->SetSize(gfx::Size(kWidth, kWidth)); | 150 root_view_->SetSize(gfx::Size(kWidth, kWidth)); |
167 root_view_->SetLayoutManager(layout_manager_); | 151 root_view_->SetLayoutManager(layout_manager_); |
168 | 152 |
169 // Add the caption buttons. We use fake images because we're modeling the | 153 // Add the caption buttons. We use fake images because we're modeling the |
170 // Windows assets here, while the linux version uses differently sized | 154 // Windows assets here, while the linux version uses differently sized |
171 // assets. | 155 // assets. |
172 // | 156 // |
173 // TODO(erg): In a follow up patch, separate these sizes out into virtual | 157 // TODO(erg): In a follow up patch, separate these sizes out into virtual |
174 // accessors so we can test both the windows and linux behaviours once we | 158 // accessors so we can test both the windows and linux behaviours once we |
175 // start modifying the code. | 159 // start modifying the code. |
176 minimize_button_ = InitWindowCaptionButton( | 160 minimize_button_ = InitWindowCaptionButton( |
177 VIEW_ID_MINIMIZE_BUTTON, gfx::Size(26, 18)); | 161 VIEW_ID_MINIMIZE_BUTTON, gfx::Size(26, 18)); |
178 maximize_button_ = InitWindowCaptionButton( | 162 maximize_button_ = InitWindowCaptionButton( |
179 VIEW_ID_MAXIMIZE_BUTTON, gfx::Size(25, 18)); | 163 VIEW_ID_MAXIMIZE_BUTTON, gfx::Size(25, 18)); |
180 restore_button_ = InitWindowCaptionButton( | 164 restore_button_ = InitWindowCaptionButton( |
181 VIEW_ID_RESTORE_BUTTON, gfx::Size(25, 18)); | 165 VIEW_ID_RESTORE_BUTTON, gfx::Size(25, 18)); |
182 close_button_ = InitWindowCaptionButton( | 166 close_button_ = InitWindowCaptionButton( |
183 VIEW_ID_CLOSE_BUTTON, gfx::Size(43, 18)); | 167 VIEW_ID_CLOSE_BUTTON, gfx::Size(43, 18)); |
184 } | 168 } |
185 | 169 |
186 virtual void TearDown() override { | 170 void TearDown() override { |
187 widget_->CloseNow(); | 171 widget_->CloseNow(); |
188 | 172 |
189 views::ViewsTestBase::TearDown(); | 173 views::ViewsTestBase::TearDown(); |
190 } | 174 } |
191 | 175 |
192 protected: | 176 protected: |
193 views::ImageButton* InitWindowCaptionButton(ViewID view_id, | 177 views::ImageButton* InitWindowCaptionButton(ViewID view_id, |
194 const gfx::Size& size) { | 178 const gfx::Size& size) { |
195 views::ImageButton* button = new views::ImageButton(NULL); | 179 views::ImageButton* button = new views::ImageButton(NULL); |
196 gfx::ImageSkiaRep rep(size, 1.0f); | 180 gfx::ImageSkiaRep rep(size, 1.0f); |
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
558 // both are displayed on the left side. | 542 // both are displayed on the left side. |
559 // The label height and width depends on the font size and the text displayed. | 543 // The label height and width depends on the font size and the text displayed. |
560 // This may possibly change, so we don't test it here. | 544 // This may possibly change, so we don't test it here. |
561 EXPECT_EQ(menu_button_->bounds().x() - 2, | 545 EXPECT_EQ(menu_button_->bounds().x() - 2, |
562 supervised_user_avatar_label_->bounds().x()); | 546 supervised_user_avatar_label_->bounds().x()); |
563 EXPECT_EQ(menu_button_->bounds().bottom() - 3 - | 547 EXPECT_EQ(menu_button_->bounds().bottom() - 3 - |
564 supervised_user_avatar_label_->bounds().height(), | 548 supervised_user_avatar_label_->bounds().height(), |
565 supervised_user_avatar_label_->bounds().y()); | 549 supervised_user_avatar_label_->bounds().y()); |
566 } | 550 } |
567 #endif | 551 #endif |
OLD | NEW |