| 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/views/profiles/avatar_menu_button.h" | 10 #include "chrome/browser/ui/views/profiles/avatar_menu_button.h" |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 return IsTabStripVisible() ? Tab::GetMinimumInactiveSize().height() : 0; | 108 return IsTabStripVisible() ? Tab::GetMinimumInactiveSize().height() : 0; |
| 109 } | 109 } |
| 110 | 110 |
| 111 bool IsToolbarVisible() const override { return true; } | 111 bool IsToolbarVisible() const override { return true; } |
| 112 | 112 |
| 113 gfx::Size GetTabstripPreferredSize() const override { | 113 gfx::Size GetTabstripPreferredSize() const override { |
| 114 // Measured from Tabstrip::GetPreferredSize(). | 114 // Measured from Tabstrip::GetPreferredSize(). |
| 115 return IsTabStripVisible() ? gfx::Size(78, 29) : gfx::Size(0, 0); | 115 return IsTabStripVisible() ? gfx::Size(78, 29) : gfx::Size(0, 0); |
| 116 } | 116 } |
| 117 | 117 |
| 118 int GetToolbarLeadingCornerClientWidth() const override { |
| 119 return 0; |
| 120 } |
| 121 |
| 118 private: | 122 private: |
| 119 base::string16 window_title_; | 123 base::string16 window_title_; |
| 120 bool show_avatar_; | 124 bool show_avatar_; |
| 121 bool show_caption_buttons_; | 125 bool show_caption_buttons_; |
| 122 WindowState window_state_; | 126 WindowState window_state_; |
| 123 | 127 |
| 124 DISALLOW_COPY_AND_ASSIGN(TestLayoutDelegate); | 128 DISALLOW_COPY_AND_ASSIGN(TestLayoutDelegate); |
| 125 }; | 129 }; |
| 126 | 130 |
| 127 } // namespace | 131 } // namespace |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 delegate_->SetWindowState(TestLayoutDelegate::STATE_MAXIMIZED); | 258 delegate_->SetWindowState(TestLayoutDelegate::STATE_MAXIMIZED); |
| 255 root_view_->Layout(); | 259 root_view_->Layout(); |
| 256 | 260 |
| 257 // Note how the bounds start at the exact top of the window while maximized | 261 // Note how the bounds start at the exact top of the window while maximized |
| 258 // while they start 1 pixel below when unmaximized. | 262 // while they start 1 pixel below when unmaximized. |
| 259 EXPECT_EQ("0,0 0x0", maximize_button_->bounds().ToString()); | 263 EXPECT_EQ("0,0 0x0", maximize_button_->bounds().ToString()); |
| 260 EXPECT_EQ("403,0 26x18", minimize_button_->bounds().ToString()); | 264 EXPECT_EQ("403,0 26x18", minimize_button_->bounds().ToString()); |
| 261 EXPECT_EQ("429,0 25x18", restore_button_->bounds().ToString()); | 265 EXPECT_EQ("429,0 25x18", restore_button_->bounds().ToString()); |
| 262 EXPECT_EQ("454,0 46x18", close_button_->bounds().ToString()); | 266 EXPECT_EQ("454,0 46x18", close_button_->bounds().ToString()); |
| 263 | 267 |
| 264 EXPECT_EQ("-5,-3 392x29", | 268 EXPECT_EQ("-6,-3 393x29", |
| 265 layout_manager_->GetBoundsForTabStrip( | 269 layout_manager_->GetBoundsForTabStrip( |
| 266 delegate_->GetTabstripPreferredSize(), kWidth).ToString()); | 270 delegate_->GetTabstripPreferredSize(), kWidth).ToString()); |
| 267 EXPECT_EQ("262x61", layout_manager_->GetMinimumSize(kWidth).ToString()); | 271 EXPECT_EQ("262x61", layout_manager_->GetMinimumSize(kWidth).ToString()); |
| 268 | 272 |
| 269 // In the maximized case, OpaqueBrowserFrameView::NonClientHitTest() uses | 273 // In the maximized case, OpaqueBrowserFrameView::NonClientHitTest() uses |
| 270 // this rect, extended to the top left corner of the window. | 274 // this rect, extended to the top left corner of the window. |
| 271 EXPECT_EQ("2,0 17x17", layout_manager_->IconBounds().ToString()); | 275 EXPECT_EQ("2,0 17x17", layout_manager_->IconBounds().ToString()); |
| 272 } | 276 } |
| 273 | 277 |
| 274 TEST_F(OpaqueBrowserFrameViewLayoutTest, MaximizedWithYOffset) { | 278 TEST_F(OpaqueBrowserFrameViewLayoutTest, MaximizedWithYOffset) { |
| 275 // Tests the layout of a basic chrome window with the caption buttons slightly | 279 // Tests the layout of a basic chrome window with the caption buttons slightly |
| 276 // offset from the top of the screen (as they are on Linux). | 280 // offset from the top of the screen (as they are on Linux). |
| 277 layout_manager_->set_extra_caption_y(2); | 281 layout_manager_->set_extra_caption_y(2); |
| 278 delegate_->SetWindowState(TestLayoutDelegate::STATE_MAXIMIZED); | 282 delegate_->SetWindowState(TestLayoutDelegate::STATE_MAXIMIZED); |
| 279 root_view_->Layout(); | 283 root_view_->Layout(); |
| 280 | 284 |
| 281 // Note how the bounds start at the exact top of the window, DESPITE the | 285 // Note how the bounds start at the exact top of the window, DESPITE the |
| 282 // caption Y offset of 2. This ensures that we obey Fitts' Law (the buttons | 286 // caption Y offset of 2. This ensures that we obey Fitts' Law (the buttons |
| 283 // are clickable on the top edge of the screen). However, the buttons are 2 | 287 // are clickable on the top edge of the screen). However, the buttons are 2 |
| 284 // pixels taller, so the images appear to be offset by 2 pixels. | 288 // pixels taller, so the images appear to be offset by 2 pixels. |
| 285 EXPECT_EQ("0,0 0x0", maximize_button_->bounds().ToString()); | 289 EXPECT_EQ("0,0 0x0", maximize_button_->bounds().ToString()); |
| 286 EXPECT_EQ("403,0 26x20", minimize_button_->bounds().ToString()); | 290 EXPECT_EQ("403,0 26x20", minimize_button_->bounds().ToString()); |
| 287 EXPECT_EQ("429,0 25x20", restore_button_->bounds().ToString()); | 291 EXPECT_EQ("429,0 25x20", restore_button_->bounds().ToString()); |
| 288 EXPECT_EQ("454,0 46x20", close_button_->bounds().ToString()); | 292 EXPECT_EQ("454,0 46x20", close_button_->bounds().ToString()); |
| 289 | 293 |
| 290 EXPECT_EQ("-5,-3 392x29", | 294 EXPECT_EQ("-6,-3 393x29", |
| 291 layout_manager_->GetBoundsForTabStrip( | 295 layout_manager_->GetBoundsForTabStrip( |
| 292 delegate_->GetTabstripPreferredSize(), kWidth).ToString()); | 296 delegate_->GetTabstripPreferredSize(), kWidth).ToString()); |
| 293 EXPECT_EQ("262x61", layout_manager_->GetMinimumSize(kWidth).ToString()); | 297 EXPECT_EQ("262x61", layout_manager_->GetMinimumSize(kWidth).ToString()); |
| 294 | 298 |
| 295 // In the maximized case, OpaqueBrowserFrameView::NonClientHitTest() uses | 299 // In the maximized case, OpaqueBrowserFrameView::NonClientHitTest() uses |
| 296 // this rect, extended to the top left corner of the window. | 300 // this rect, extended to the top left corner of the window. |
| 297 EXPECT_EQ("2,0 17x17", layout_manager_->IconBounds().ToString()); | 301 EXPECT_EQ("2,0 17x17", layout_manager_->IconBounds().ToString()); |
| 298 } | 302 } |
| 299 | 303 |
| 300 TEST_F(OpaqueBrowserFrameViewLayoutTest, WindowButtonsOnLeft) { | 304 TEST_F(OpaqueBrowserFrameViewLayoutTest, WindowButtonsOnLeft) { |
| 301 // Tests the layout of a chrome window with caption buttons on the left. | 305 // Tests the layout of a chrome window with caption buttons on the left. |
| 302 std::vector<views::FrameButton> leading_buttons; | 306 std::vector<views::FrameButton> leading_buttons; |
| 303 std::vector<views::FrameButton> trailing_buttons; | 307 std::vector<views::FrameButton> trailing_buttons; |
| 304 leading_buttons.push_back(views::FRAME_BUTTON_CLOSE); | 308 leading_buttons.push_back(views::FRAME_BUTTON_CLOSE); |
| 305 leading_buttons.push_back(views::FRAME_BUTTON_MINIMIZE); | 309 leading_buttons.push_back(views::FRAME_BUTTON_MINIMIZE); |
| 306 leading_buttons.push_back(views::FRAME_BUTTON_MAXIMIZE); | 310 leading_buttons.push_back(views::FRAME_BUTTON_MAXIMIZE); |
| 307 layout_manager_->SetButtonOrdering(leading_buttons, trailing_buttons); | 311 layout_manager_->SetButtonOrdering(leading_buttons, trailing_buttons); |
| 308 root_view_->Layout(); | 312 root_view_->Layout(); |
| 309 | 313 |
| 310 EXPECT_EQ("73,1 25x18", maximize_button_->bounds().ToString()); | 314 EXPECT_EQ("73,1 25x18", maximize_button_->bounds().ToString()); |
| 311 EXPECT_EQ("47,1 26x18", minimize_button_->bounds().ToString()); | 315 EXPECT_EQ("47,1 26x18", minimize_button_->bounds().ToString()); |
| 312 EXPECT_EQ("0,0 0x0", restore_button_->bounds().ToString()); | 316 EXPECT_EQ("0,0 0x0", restore_button_->bounds().ToString()); |
| 313 EXPECT_EQ("4,1 43x18", close_button_->bounds().ToString()); | 317 EXPECT_EQ("4,1 43x18", close_button_->bounds().ToString()); |
| 314 | 318 |
| 315 EXPECT_EQ("93,13 398x29", | 319 EXPECT_EQ("92,13 398x29", |
| 316 layout_manager_->GetBoundsForTabStrip( | 320 layout_manager_->GetBoundsForTabStrip( |
| 317 delegate_->GetTabstripPreferredSize(), kWidth).ToString()); | 321 delegate_->GetTabstripPreferredSize(), kWidth).ToString()); |
| 318 EXPECT_EQ("261x73", layout_manager_->GetMinimumSize(kWidth).ToString()); | 322 EXPECT_EQ("261x73", layout_manager_->GetMinimumSize(kWidth).ToString()); |
| 319 | 323 |
| 320 // If the buttons are on the left, there should be no hidden icon for the user | 324 // If the buttons are on the left, there should be no hidden icon for the user |
| 321 // to double click. | 325 // to double click. |
| 322 EXPECT_EQ("0,0 0x0", layout_manager_->IconBounds().ToString()); | 326 EXPECT_EQ("0,0 0x0", layout_manager_->IconBounds().ToString()); |
| 323 } | 327 } |
| 324 | 328 |
| 325 TEST_F(OpaqueBrowserFrameViewLayoutTest, WithoutCaptionButtons) { | 329 TEST_F(OpaqueBrowserFrameViewLayoutTest, WithoutCaptionButtons) { |
| 326 // Tests the layout of a default chrome window with no caption buttons (which | 330 // Tests the layout of a default chrome window with no caption buttons (which |
| 327 // should force the tab strip to be condensed). | 331 // should force the tab strip to be condensed). |
| 328 delegate_->SetShouldShowCaptionButtons(false); | 332 delegate_->SetShouldShowCaptionButtons(false); |
| 329 root_view_->Layout(); | 333 root_view_->Layout(); |
| 330 | 334 |
| 331 EXPECT_EQ("0,0 0x0", maximize_button_->bounds().ToString()); | 335 EXPECT_EQ("0,0 0x0", maximize_button_->bounds().ToString()); |
| 332 EXPECT_EQ("0,0 0x0", minimize_button_->bounds().ToString()); | 336 EXPECT_EQ("0,0 0x0", minimize_button_->bounds().ToString()); |
| 333 EXPECT_EQ("0,0 0x0", restore_button_->bounds().ToString()); | 337 EXPECT_EQ("0,0 0x0", restore_button_->bounds().ToString()); |
| 334 EXPECT_EQ("0,0 0x0", close_button_->bounds().ToString()); | 338 EXPECT_EQ("0,0 0x0", close_button_->bounds().ToString()); |
| 335 | 339 |
| 336 EXPECT_EQ("-5,-3 500x29", | 340 EXPECT_EQ("-6,-3 501x29", |
| 337 layout_manager_->GetBoundsForTabStrip( | 341 layout_manager_->GetBoundsForTabStrip( |
| 338 delegate_->GetTabstripPreferredSize(), kWidth).ToString()); | 342 delegate_->GetTabstripPreferredSize(), kWidth).ToString()); |
| 339 EXPECT_EQ("251x61", layout_manager_->GetMinimumSize(kWidth).ToString()); | 343 EXPECT_EQ("251x61", layout_manager_->GetMinimumSize(kWidth).ToString()); |
| 340 | 344 |
| 341 // A normal window with no window icon still produces icon bounds for | 345 // A normal window with no window icon still produces icon bounds for |
| 342 // Windows, which has a hidden icon that a user can double click on to close | 346 // Windows, which has a hidden icon that a user can double click on to close |
| 343 // the window. | 347 // the window. |
| 344 EXPECT_EQ("2,0 17x17", layout_manager_->IconBounds().ToString()); | 348 EXPECT_EQ("2,0 17x17", layout_manager_->IconBounds().ToString()); |
| 345 } | 349 } |
| 346 | 350 |
| 347 TEST_F(OpaqueBrowserFrameViewLayoutTest, MaximizedWithoutCaptionButtons) { | 351 TEST_F(OpaqueBrowserFrameViewLayoutTest, MaximizedWithoutCaptionButtons) { |
| 348 // Tests the layout of a maximized chrome window with no caption buttons. | 352 // Tests the layout of a maximized chrome window with no caption buttons. |
| 349 delegate_->SetWindowState(TestLayoutDelegate::STATE_MAXIMIZED); | 353 delegate_->SetWindowState(TestLayoutDelegate::STATE_MAXIMIZED); |
| 350 delegate_->SetShouldShowCaptionButtons(false); | 354 delegate_->SetShouldShowCaptionButtons(false); |
| 351 root_view_->Layout(); | 355 root_view_->Layout(); |
| 352 | 356 |
| 353 EXPECT_EQ("0,0 0x0", maximize_button_->bounds().ToString()); | 357 EXPECT_EQ("0,0 0x0", maximize_button_->bounds().ToString()); |
| 354 EXPECT_EQ("0,0 0x0", minimize_button_->bounds().ToString()); | 358 EXPECT_EQ("0,0 0x0", minimize_button_->bounds().ToString()); |
| 355 EXPECT_EQ("0,0 0x0", restore_button_->bounds().ToString()); | 359 EXPECT_EQ("0,0 0x0", restore_button_->bounds().ToString()); |
| 356 EXPECT_EQ("0,0 0x0", close_button_->bounds().ToString()); | 360 EXPECT_EQ("0,0 0x0", close_button_->bounds().ToString()); |
| 357 | 361 |
| 358 EXPECT_EQ("-5,-3 500x29", | 362 EXPECT_EQ("-6,-3 501x29", |
| 359 layout_manager_->GetBoundsForTabStrip( | 363 layout_manager_->GetBoundsForTabStrip( |
| 360 delegate_->GetTabstripPreferredSize(), kWidth).ToString()); | 364 delegate_->GetTabstripPreferredSize(), kWidth).ToString()); |
| 361 EXPECT_EQ("251x61", layout_manager_->GetMinimumSize(kWidth).ToString()); | 365 EXPECT_EQ("251x61", layout_manager_->GetMinimumSize(kWidth).ToString()); |
| 362 | 366 |
| 363 // In the maximized case, OpaqueBrowserFrameView::NonClientHitTest() uses | 367 // In the maximized case, OpaqueBrowserFrameView::NonClientHitTest() uses |
| 364 // this rect, extended to the top left corner of the window. | 368 // this rect, extended to the top left corner of the window. |
| 365 EXPECT_EQ("2,0 17x17", layout_manager_->IconBounds().ToString()); | 369 EXPECT_EQ("2,0 17x17", layout_manager_->IconBounds().ToString()); |
| 366 } | 370 } |
| 367 | 371 |
| 368 TEST_F(OpaqueBrowserFrameViewLayoutTest, WithWindowTitleAndIcon) { | 372 TEST_F(OpaqueBrowserFrameViewLayoutTest, WithWindowTitleAndIcon) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 388 | 392 |
| 389 // Check the location of the avatar button. | 393 // Check the location of the avatar button. |
| 390 EXPECT_EQ("385,1 12x18", new_avatar_button_->bounds().ToString()); | 394 EXPECT_EQ("385,1 12x18", new_avatar_button_->bounds().ToString()); |
| 391 // The new tab button is 39px wide and slides completely under the new | 395 // The new tab button is 39px wide and slides completely under the new |
| 392 // avatar button, thus increasing the tabstrip by that amount. | 396 // avatar button, thus increasing the tabstrip by that amount. |
| 393 EXPECT_EQ("-1,13 420x29", | 397 EXPECT_EQ("-1,13 420x29", |
| 394 layout_manager_->GetBoundsForTabStrip( | 398 layout_manager_->GetBoundsForTabStrip( |
| 395 delegate_->GetTabstripPreferredSize(), kWidth).ToString()); | 399 delegate_->GetTabstripPreferredSize(), kWidth).ToString()); |
| 396 EXPECT_EQ("261x73", layout_manager_->GetMinimumSize(kWidth).ToString()); | 400 EXPECT_EQ("261x73", layout_manager_->GetMinimumSize(kWidth).ToString()); |
| 397 } | 401 } |
| OLD | NEW |