Chromium Code Reviews| 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/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "chrome/browser/ui/layout_constants.h" | 10 #include "chrome/browser/ui/layout_constants.h" |
| 11 #include "chrome/browser/ui/views/profiles/avatar_menu_button.h" | 11 #include "chrome/browser/ui/views/profiles/profile_indicator_icon.h" |
| 12 #include "chrome/browser/ui/views/tab_icon_view.h" | 12 #include "chrome/browser/ui/views/tab_icon_view.h" |
| 13 #include "chrome/browser/ui/views/tabs/tab.h" | 13 #include "chrome/browser/ui/views/tabs/tab.h" |
| 14 #include "chrome/common/chrome_switches.h" | 14 #include "chrome/common/chrome_switches.h" |
| 15 #include "components/signin/core/common/profile_management_switches.h" | 15 #include "components/signin/core/common/profile_management_switches.h" |
| 16 #include "ui/gfx/image/image_skia.h" | 16 #include "ui/gfx/image/image_skia.h" |
| 17 #include "ui/gfx/image/image_skia_rep.h" | 17 #include "ui/gfx/image/image_skia_rep.h" |
| 18 #include "ui/gfx/text_constants.h" | 18 #include "ui/gfx/text_constants.h" |
| 19 #include "ui/views/controls/button/image_button.h" | 19 #include "ui/views/controls/button/image_button.h" |
| 20 #include "ui/views/controls/button/menu_button.h" | 20 #include "ui/views/controls/button/menu_button.h" |
| 21 #include "ui/views/controls/label.h" | 21 #include "ui/views/controls/label.h" |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 32 const int kMaximizeButtonWidth = 25; | 32 const int kMaximizeButtonWidth = 25; |
| 33 const int kCloseButtonWidth = 43; | 33 const int kCloseButtonWidth = 43; |
| 34 const int kMaximizedExtraCloseWidth = OBFVL::kFrameBorderThickness - | 34 const int kMaximizedExtraCloseWidth = OBFVL::kFrameBorderThickness - |
| 35 views::NonClientFrameView::kFrameShadowThickness; | 35 views::NonClientFrameView::kFrameShadowThickness; |
| 36 const int kCaptionButtonsWidth = | 36 const int kCaptionButtonsWidth = |
| 37 kMinimizeButtonWidth + kMaximizeButtonWidth + kCloseButtonWidth; | 37 kMinimizeButtonWidth + kMaximizeButtonWidth + kCloseButtonWidth; |
| 38 const int kCaptionButtonHeight = 18; | 38 const int kCaptionButtonHeight = 18; |
| 39 | 39 |
| 40 class TestLayoutDelegate : public OpaqueBrowserFrameViewLayoutDelegate { | 40 class TestLayoutDelegate : public OpaqueBrowserFrameViewLayoutDelegate { |
| 41 public: | 41 public: |
| 42 TestLayoutDelegate() | 42 TestLayoutDelegate() : show_caption_buttons_(true), maximized_(false) {} |
| 43 : show_avatar_(false), | |
| 44 show_caption_buttons_(true), | |
| 45 maximized_(false) { | |
| 46 } | |
| 47 ~TestLayoutDelegate() override {} | 43 ~TestLayoutDelegate() override {} |
| 48 | 44 |
| 49 void set_window_title(const base::string16& title) { window_title_ = title; } | 45 void set_window_title(const base::string16& title) { window_title_ = title; } |
| 50 void set_show_avatar(bool show_avatar) { show_avatar_ = show_avatar; } | |
| 51 void set_show_caption_buttons(bool show_caption_buttons) { | 46 void set_show_caption_buttons(bool show_caption_buttons) { |
| 52 show_caption_buttons_ = show_caption_buttons; | 47 show_caption_buttons_ = show_caption_buttons; |
| 53 } | 48 } |
| 54 void set_maximized(bool maximized) { maximized_ = maximized; } | 49 void set_maximized(bool maximized) { maximized_ = maximized; } |
| 55 | 50 |
| 56 // OpaqueBrowserFrameViewLayoutDelegate: | 51 // OpaqueBrowserFrameViewLayoutDelegate: |
| 57 bool ShouldShowWindowIcon() const override { return !window_title_.empty(); } | 52 bool ShouldShowWindowIcon() const override { return !window_title_.empty(); } |
| 58 bool ShouldShowWindowTitle() const override { return !window_title_.empty(); } | 53 bool ShouldShowWindowTitle() const override { return !window_title_.empty(); } |
| 59 base::string16 GetWindowTitle() const override { return window_title_; } | 54 base::string16 GetWindowTitle() const override { return window_title_; } |
| 60 int GetIconSize() const override { return 17; } | 55 int GetIconSize() const override { return 17; } |
| 61 gfx::Size GetBrowserViewMinimumSize() const override { | 56 gfx::Size GetBrowserViewMinimumSize() const override { |
| 62 return gfx::Size(168, 64); | 57 return gfx::Size(168, 64); |
| 63 } | 58 } |
| 64 bool ShouldShowCaptionButtons() const override { | 59 bool ShouldShowCaptionButtons() const override { |
| 65 return show_caption_buttons_; | 60 return show_caption_buttons_; |
| 66 } | 61 } |
| 67 bool ShouldShowAvatar() const override { return show_avatar_; } | |
| 68 bool IsRegularOrGuestSession() const override { return true; } | 62 bool IsRegularOrGuestSession() const override { return true; } |
| 69 gfx::ImageSkia GetOTRAvatarIcon() const override { | 63 gfx::ImageSkia GetOTRAvatarIcon() const override { |
| 70 return gfx::ImageSkia(gfx::ImageSkiaRep(gfx::Size(40, 29), 1.0f)); | 64 return gfx::ImageSkia(gfx::ImageSkiaRep(gfx::Size(40, 29), 1.0f)); |
| 71 } | 65 } |
| 72 bool IsMaximized() const override { return maximized_; } | 66 bool IsMaximized() const override { return maximized_; } |
| 73 bool IsMinimized() const override { return false; } | 67 bool IsMinimized() const override { return false; } |
| 74 bool IsFullscreen() const override { return false; } | 68 bool IsFullscreen() const override { return false; } |
| 75 bool IsTabStripVisible() const override { return window_title_.empty(); } | 69 bool IsTabStripVisible() const override { return window_title_.empty(); } |
| 76 int GetTabStripHeight() const override { | 70 int GetTabStripHeight() const override { |
| 77 return IsTabStripVisible() ? Tab::GetMinimumInactiveSize().height() : 0; | 71 return IsTabStripVisible() ? Tab::GetMinimumInactiveSize().height() : 0; |
| 78 } | 72 } |
| 79 bool IsToolbarVisible() const override { return true; } | 73 bool IsToolbarVisible() const override { return true; } |
| 80 gfx::Size GetTabstripPreferredSize() const override { | 74 gfx::Size GetTabstripPreferredSize() const override { |
| 81 return IsTabStripVisible() ? gfx::Size(78, 29) : gfx::Size(); | 75 return IsTabStripVisible() ? gfx::Size(78, 29) : gfx::Size(); |
| 82 } | 76 } |
| 83 int GetToolbarLeadingCornerClientWidth() const override { return 0; } | 77 int GetToolbarLeadingCornerClientWidth() const override { return 0; } |
| 84 | 78 |
| 85 private: | 79 private: |
| 86 base::string16 window_title_; | 80 base::string16 window_title_; |
| 87 bool show_avatar_; | |
| 88 bool show_caption_buttons_; | 81 bool show_caption_buttons_; |
| 89 bool maximized_; | 82 bool maximized_; |
| 90 | 83 |
| 91 DISALLOW_COPY_AND_ASSIGN(TestLayoutDelegate); | 84 DISALLOW_COPY_AND_ASSIGN(TestLayoutDelegate); |
| 92 }; | 85 }; |
| 93 | 86 |
| 94 } // namespace | 87 } // namespace |
| 95 | 88 |
| 96 class OpaqueBrowserFrameViewLayoutTest : public views::ViewsTestBase { | 89 class OpaqueBrowserFrameViewLayoutTest : public views::ViewsTestBase { |
| 97 public: | 90 public: |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 163 window_title_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 156 window_title_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 164 window_title_->set_id(VIEW_ID_WINDOW_TITLE); | 157 window_title_->set_id(VIEW_ID_WINDOW_TITLE); |
| 165 root_view_->AddChildView(window_title_); | 158 root_view_->AddChildView(window_title_); |
| 166 } | 159 } |
| 167 | 160 |
| 168 void AddNewAvatarButton() { | 161 void AddNewAvatarButton() { |
| 169 new_avatar_button_ = | 162 new_avatar_button_ = |
| 170 new views::MenuButton(base::string16(), nullptr, false); | 163 new views::MenuButton(base::string16(), nullptr, false); |
| 171 new_avatar_button_->set_id(VIEW_ID_NEW_AVATAR_BUTTON); | 164 new_avatar_button_->set_id(VIEW_ID_NEW_AVATAR_BUTTON); |
| 172 root_view_->AddChildView(new_avatar_button_); | 165 root_view_->AddChildView(new_avatar_button_); |
| 173 delegate_->set_show_avatar(true); | |
| 174 } | 166 } |
| 175 | 167 |
| 176 int CaptionY() const { | 168 int CaptionY() const { |
| 177 return delegate_->IsMaximized() ? | 169 return delegate_->IsMaximized() ? |
| 178 0 : views::NonClientFrameView::kFrameShadowThickness; | 170 0 : views::NonClientFrameView::kFrameShadowThickness; |
| 179 } | 171 } |
| 180 | 172 |
| 181 int CaptionLeft() const { | 173 int CaptionLeft() const { |
| 182 return kWindowWidth - | 174 return kWindowWidth - |
| 183 (delegate_->IsMaximized() ? kMaximizedExtraCloseWidth | 175 (delegate_->IsMaximized() ? kMaximizedExtraCloseWidth |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 233 EXPECT_EQ(kMinimizeButtonWidth, minimize_button_->width()); | 225 EXPECT_EQ(kMinimizeButtonWidth, minimize_button_->width()); |
| 234 EXPECT_EQ(visible_button->height(), minimize_button_->height()); | 226 EXPECT_EQ(visible_button->height(), minimize_button_->height()); |
| 235 EXPECT_TRUE(minimize_button_->visible()); | 227 EXPECT_TRUE(minimize_button_->visible()); |
| 236 EXPECT_FALSE(hidden_button->visible()); | 228 EXPECT_FALSE(hidden_button->visible()); |
| 237 } | 229 } |
| 238 | 230 |
| 239 void ExpectTabStripAndMinimumSize(bool caption_buttons_on_left) { | 231 void ExpectTabStripAndMinimumSize(bool caption_buttons_on_left) { |
| 240 int caption_buttons_width = kCaptionButtonsWidth; | 232 int caption_buttons_width = kCaptionButtonsWidth; |
| 241 bool show_caption_buttons = delegate_->ShouldShowCaptionButtons(); | 233 bool show_caption_buttons = delegate_->ShouldShowCaptionButtons(); |
| 242 bool maximized = delegate_->IsMaximized() || !show_caption_buttons; | 234 bool maximized = delegate_->IsMaximized() || !show_caption_buttons; |
| 243 if (delegate_->ShouldShowAvatar()) { | 235 if (new_avatar_button_) { |
| 244 caption_buttons_width += new_avatar_button_->GetPreferredSize().width() + | 236 caption_buttons_width += |
| 237 new_avatar_button_->GetPreferredSize().width() + | |
| 245 (maximized ? OBFVL::kCaptionSpacing | 238 (maximized ? OBFVL::kCaptionSpacing |
| 246 : -GetLayoutSize(NEW_TAB_BUTTON).width()); | 239 : -GetLayoutSize(NEW_TAB_BUTTON).width()); |
| 247 } | 240 } |
| 248 int tabstrip_x = GetLayoutInsets(AVATAR_ICON).right(); | 241 int tabstrip_x = GetLayoutInsets(AVATAR_ICON).right(); |
| 249 if (show_caption_buttons && caption_buttons_on_left) { | 242 if (show_caption_buttons && caption_buttons_on_left) { |
| 250 int right_of_close = | 243 int right_of_close = |
| 251 maximized ? kMaximizedExtraCloseWidth : OBFVL::kFrameBorderThickness; | 244 maximized ? kMaximizedExtraCloseWidth : OBFVL::kFrameBorderThickness; |
| 252 tabstrip_x += caption_buttons_width + right_of_close; | 245 tabstrip_x += caption_buttons_width + right_of_close; |
| 253 } else if (!maximized) { | 246 } else if (!maximized) { |
| 254 tabstrip_x += kNonClientBorderThickness; | 247 tabstrip_x += kNonClientBorderThickness; |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 342 // Widgets: | 335 // Widgets: |
| 343 views::ImageButton* minimize_button_; | 336 views::ImageButton* minimize_button_; |
| 344 views::ImageButton* maximize_button_; | 337 views::ImageButton* maximize_button_; |
| 345 views::ImageButton* restore_button_; | 338 views::ImageButton* restore_button_; |
| 346 views::ImageButton* close_button_; | 339 views::ImageButton* close_button_; |
| 347 | 340 |
| 348 TabIconView* tab_icon_view_; | 341 TabIconView* tab_icon_view_; |
| 349 views::Label* window_title_; | 342 views::Label* window_title_; |
| 350 | 343 |
| 351 AvatarMenuButton* menu_button_; | 344 AvatarMenuButton* menu_button_; |
| 352 views::MenuButton* new_avatar_button_; | 345 views::MenuButton* new_avatar_button_; |
|
Peter Kasting
2016/05/17 03:51:42
Nit: Again, maybe this should just be |avatar_butt
Evan Stade
2016/05/17 18:13:09
Done.
| |
| 353 | 346 |
| 354 DISALLOW_COPY_AND_ASSIGN(OpaqueBrowserFrameViewLayoutTest); | 347 DISALLOW_COPY_AND_ASSIGN(OpaqueBrowserFrameViewLayoutTest); |
| 355 }; | 348 }; |
| 356 | 349 |
| 357 TEST_F(OpaqueBrowserFrameViewLayoutTest, BasicWindow) { | 350 TEST_F(OpaqueBrowserFrameViewLayoutTest, BasicWindow) { |
| 358 // Tests the layout of a default chrome window with no avatars, no window | 351 // Tests the layout of a default chrome window with no avatars, no window |
| 359 // titles, and a tabstrip. | 352 // titles, and a tabstrip. |
| 360 | 353 |
| 361 for (int i = 0; i < 2; ++i) { | 354 for (int i = 0; i < 2; ++i) { |
| 362 root_view_->Layout(); | 355 root_view_->Layout(); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 435 | 428 |
| 436 for (int i = 0; i < 2; ++i) { | 429 for (int i = 0; i < 2; ++i) { |
| 437 root_view_->Layout(); | 430 root_view_->Layout(); |
| 438 SCOPED_TRACE(i == 0 ? "Window is restored" : "Window is maximized"); | 431 SCOPED_TRACE(i == 0 ? "Window is restored" : "Window is maximized"); |
| 439 ExpectCaptionButtons(false, 0); | 432 ExpectCaptionButtons(false, 0); |
| 440 ExpectTabStripAndMinimumSize(false); | 433 ExpectTabStripAndMinimumSize(false); |
| 441 ExpectAvatar(); | 434 ExpectAvatar(); |
| 442 delegate_->set_maximized(true); | 435 delegate_->set_maximized(true); |
| 443 } | 436 } |
| 444 } | 437 } |
| OLD | NEW |