| 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 virtual bool ShouldShowWindowIcon() const override { |
| 69 return !window_title_.empty(); | 69 return !window_title_.empty(); |
| 70 } | 70 } |
| 71 | 71 |
| 72 virtual bool ShouldShowWindowTitle() const OVERRIDE { | 72 virtual bool ShouldShowWindowTitle() const override { |
| 73 return !window_title_.empty(); | 73 return !window_title_.empty(); |
| 74 } | 74 } |
| 75 | 75 |
| 76 virtual base::string16 GetWindowTitle() const OVERRIDE { | 76 virtual base::string16 GetWindowTitle() const override { |
| 77 return window_title_; | 77 return window_title_; |
| 78 } | 78 } |
| 79 | 79 |
| 80 virtual int GetIconSize() const OVERRIDE { | 80 virtual int GetIconSize() const override { |
| 81 // The value on linux_aura and non-aura windows. | 81 // The value on linux_aura and non-aura windows. |
| 82 return 17; | 82 return 17; |
| 83 } | 83 } |
| 84 | 84 |
| 85 virtual bool ShouldLeaveOffsetNearTopBorder() const OVERRIDE { | 85 virtual bool ShouldLeaveOffsetNearTopBorder() const override { |
| 86 return !IsMaximized(); | 86 return !IsMaximized(); |
| 87 } | 87 } |
| 88 | 88 |
| 89 virtual gfx::Size GetBrowserViewMinimumSize() const OVERRIDE { | 89 virtual gfx::Size GetBrowserViewMinimumSize() const override { |
| 90 // Taken from a calculation in BrowserViewLayout. | 90 // Taken from a calculation in BrowserViewLayout. |
| 91 return gfx::Size(168, 64); | 91 return gfx::Size(168, 64); |
| 92 } | 92 } |
| 93 | 93 |
| 94 virtual bool ShouldShowCaptionButtons() const OVERRIDE { | 94 virtual bool ShouldShowCaptionButtons() const override { |
| 95 return show_caption_buttons_; | 95 return show_caption_buttons_; |
| 96 } | 96 } |
| 97 | 97 |
| 98 virtual bool ShouldShowAvatar() const OVERRIDE { | 98 virtual bool ShouldShowAvatar() const override { |
| 99 return show_avatar_; | 99 return show_avatar_; |
| 100 } | 100 } |
| 101 | 101 |
| 102 virtual bool IsRegularOrGuestSession() const OVERRIDE { | 102 virtual bool IsRegularOrGuestSession() const override { |
| 103 return true; | 103 return true; |
| 104 } | 104 } |
| 105 | 105 |
| 106 virtual gfx::ImageSkia GetOTRAvatarIcon() const OVERRIDE { | 106 virtual gfx::ImageSkia GetOTRAvatarIcon() const override { |
| 107 // The calculations depend on the size of the OTR resource, and chromeos | 107 // 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 | 108 // uses a different sized image, so hard code the size of the current |
| 109 // windows/linux one. | 109 // windows/linux one. |
| 110 gfx::ImageSkiaRep rep(gfx::Size(40, 29), 1.0f); | 110 gfx::ImageSkiaRep rep(gfx::Size(40, 29), 1.0f); |
| 111 gfx::ImageSkia image(rep); | 111 gfx::ImageSkia image(rep); |
| 112 return image; | 112 return image; |
| 113 } | 113 } |
| 114 | 114 |
| 115 virtual bool IsMaximized() const OVERRIDE { | 115 virtual bool IsMaximized() const override { |
| 116 return window_state_ == STATE_MAXIMIZED; | 116 return window_state_ == STATE_MAXIMIZED; |
| 117 } | 117 } |
| 118 | 118 |
| 119 virtual bool IsMinimized() const OVERRIDE { | 119 virtual bool IsMinimized() const override { |
| 120 return window_state_ == STATE_MINIMIZED; | 120 return window_state_ == STATE_MINIMIZED; |
| 121 } | 121 } |
| 122 | 122 |
| 123 virtual bool IsFullscreen() const OVERRIDE { | 123 virtual bool IsFullscreen() const override { |
| 124 return window_state_ == STATE_FULLSCREEN; | 124 return window_state_ == STATE_FULLSCREEN; |
| 125 } | 125 } |
| 126 | 126 |
| 127 virtual bool IsTabStripVisible() const OVERRIDE { | 127 virtual bool IsTabStripVisible() const override { |
| 128 return window_title_.empty(); | 128 return window_title_.empty(); |
| 129 } | 129 } |
| 130 | 130 |
| 131 virtual int GetTabStripHeight() const OVERRIDE { | 131 virtual int GetTabStripHeight() const override { |
| 132 return IsTabStripVisible() ? Tab::GetMinimumUnselectedSize().height() : 0; | 132 return IsTabStripVisible() ? Tab::GetMinimumUnselectedSize().height() : 0; |
| 133 } | 133 } |
| 134 | 134 |
| 135 virtual gfx::Size GetTabstripPreferredSize() const OVERRIDE { | 135 virtual gfx::Size GetTabstripPreferredSize() const override { |
| 136 // Measured from Tabstrip::GetPreferredSize(). | 136 // Measured from Tabstrip::GetPreferredSize(). |
| 137 return IsTabStripVisible() ? gfx::Size(78, 29) : gfx::Size(0, 0); | 137 return IsTabStripVisible() ? gfx::Size(78, 29) : gfx::Size(0, 0); |
| 138 } | 138 } |
| 139 | 139 |
| 140 private: | 140 private: |
| 141 base::string16 window_title_; | 141 base::string16 window_title_; |
| 142 bool show_avatar_; | 142 bool show_avatar_; |
| 143 bool show_caption_buttons_; | 143 bool show_caption_buttons_; |
| 144 WindowState window_state_; | 144 WindowState window_state_; |
| 145 | 145 |
| 146 DISALLOW_COPY_AND_ASSIGN(TestLayoutDelegate); | 146 DISALLOW_COPY_AND_ASSIGN(TestLayoutDelegate); |
| 147 }; | 147 }; |
| 148 | 148 |
| 149 } // namespace | 149 } // namespace |
| 150 | 150 |
| 151 class OpaqueBrowserFrameViewLayoutTest : public views::ViewsTestBase { | 151 class OpaqueBrowserFrameViewLayoutTest : public views::ViewsTestBase { |
| 152 public: | 152 public: |
| 153 OpaqueBrowserFrameViewLayoutTest() {} | 153 OpaqueBrowserFrameViewLayoutTest() {} |
| 154 virtual ~OpaqueBrowserFrameViewLayoutTest() {} | 154 virtual ~OpaqueBrowserFrameViewLayoutTest() {} |
| 155 | 155 |
| 156 virtual void SetUp() OVERRIDE { | 156 virtual void SetUp() override { |
| 157 views::ViewsTestBase::SetUp(); | 157 views::ViewsTestBase::SetUp(); |
| 158 | 158 |
| 159 delegate_.reset(new TestLayoutDelegate); | 159 delegate_.reset(new TestLayoutDelegate); |
| 160 layout_manager_ = new OpaqueBrowserFrameViewLayout(delegate_.get()); | 160 layout_manager_ = new OpaqueBrowserFrameViewLayout(delegate_.get()); |
| 161 layout_manager_->set_extra_caption_y(0); | 161 layout_manager_->set_extra_caption_y(0); |
| 162 layout_manager_->set_window_caption_spacing(0); | 162 layout_manager_->set_window_caption_spacing(0); |
| 163 widget_ = new Widget; | 163 widget_ = new Widget; |
| 164 widget_->Init(CreateParams(Widget::InitParams::TYPE_POPUP)); | 164 widget_->Init(CreateParams(Widget::InitParams::TYPE_POPUP)); |
| 165 root_view_ = widget_->GetRootView(); | 165 root_view_ = widget_->GetRootView(); |
| 166 root_view_->SetSize(gfx::Size(kWidth, kWidth)); | 166 root_view_->SetSize(gfx::Size(kWidth, kWidth)); |
| 167 root_view_->SetLayoutManager(layout_manager_); | 167 root_view_->SetLayoutManager(layout_manager_); |
| 168 | 168 |
| 169 // Add the caption buttons. We use fake images because we're modeling the | 169 // Add the caption buttons. We use fake images because we're modeling the |
| 170 // Windows assets here, while the linux version uses differently sized | 170 // Windows assets here, while the linux version uses differently sized |
| 171 // assets. | 171 // assets. |
| 172 // | 172 // |
| 173 // TODO(erg): In a follow up patch, separate these sizes out into virtual | 173 // 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 | 174 // accessors so we can test both the windows and linux behaviours once we |
| 175 // start modifying the code. | 175 // start modifying the code. |
| 176 minimize_button_ = InitWindowCaptionButton( | 176 minimize_button_ = InitWindowCaptionButton( |
| 177 VIEW_ID_MINIMIZE_BUTTON, gfx::Size(26, 18)); | 177 VIEW_ID_MINIMIZE_BUTTON, gfx::Size(26, 18)); |
| 178 maximize_button_ = InitWindowCaptionButton( | 178 maximize_button_ = InitWindowCaptionButton( |
| 179 VIEW_ID_MAXIMIZE_BUTTON, gfx::Size(25, 18)); | 179 VIEW_ID_MAXIMIZE_BUTTON, gfx::Size(25, 18)); |
| 180 restore_button_ = InitWindowCaptionButton( | 180 restore_button_ = InitWindowCaptionButton( |
| 181 VIEW_ID_RESTORE_BUTTON, gfx::Size(25, 18)); | 181 VIEW_ID_RESTORE_BUTTON, gfx::Size(25, 18)); |
| 182 close_button_ = InitWindowCaptionButton( | 182 close_button_ = InitWindowCaptionButton( |
| 183 VIEW_ID_CLOSE_BUTTON, gfx::Size(43, 18)); | 183 VIEW_ID_CLOSE_BUTTON, gfx::Size(43, 18)); |
| 184 } | 184 } |
| 185 | 185 |
| 186 virtual void TearDown() OVERRIDE { | 186 virtual void TearDown() override { |
| 187 widget_->CloseNow(); | 187 widget_->CloseNow(); |
| 188 | 188 |
| 189 views::ViewsTestBase::TearDown(); | 189 views::ViewsTestBase::TearDown(); |
| 190 } | 190 } |
| 191 | 191 |
| 192 protected: | 192 protected: |
| 193 views::ImageButton* InitWindowCaptionButton(ViewID view_id, | 193 views::ImageButton* InitWindowCaptionButton(ViewID view_id, |
| 194 const gfx::Size& size) { | 194 const gfx::Size& size) { |
| 195 views::ImageButton* button = new views::ImageButton(NULL); | 195 views::ImageButton* button = new views::ImageButton(NULL); |
| 196 gfx::ImageSkiaRep rep(size, 1.0f); | 196 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. | 558 // both are displayed on the left side. |
| 559 // The label height and width depends on the font size and the text displayed. | 559 // 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. | 560 // This may possibly change, so we don't test it here. |
| 561 EXPECT_EQ(menu_button_->bounds().x() - 2, | 561 EXPECT_EQ(menu_button_->bounds().x() - 2, |
| 562 supervised_user_avatar_label_->bounds().x()); | 562 supervised_user_avatar_label_->bounds().x()); |
| 563 EXPECT_EQ(menu_button_->bounds().bottom() - 3 - | 563 EXPECT_EQ(menu_button_->bounds().bottom() - 3 - |
| 564 supervised_user_avatar_label_->bounds().height(), | 564 supervised_user_avatar_label_->bounds().height(), |
| 565 supervised_user_avatar_label_->bounds().y()); | 565 supervised_user_avatar_label_->bounds().y()); |
| 566 } | 566 } |
| 567 #endif | 567 #endif |
| OLD | NEW |