| 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/avatar_label.h" |
| 10 #include "chrome/browser/ui/views/avatar_menu_button.h" | 11 #include "chrome/browser/ui/views/avatar_menu_button.h" |
| 11 #include "chrome/browser/ui/views/tab_icon_view.h" | 12 #include "chrome/browser/ui/views/tab_icon_view.h" |
| 12 #include "chrome/browser/ui/views/tabs/tab.h" | 13 #include "chrome/browser/ui/views/tabs/tab.h" |
| 13 #include "chrome/common/chrome_switches.h" | 14 #include "chrome/common/chrome_switches.h" |
| 14 #include "ui/gfx/image/image_skia.h" | 15 #include "ui/gfx/image/image_skia.h" |
| 15 #include "ui/gfx/image/image_skia_rep.h" | 16 #include "ui/gfx/image/image_skia_rep.h" |
| 16 #include "ui/gfx/text_constants.h" | 17 #include "ui/gfx/text_constants.h" |
| 17 #include "ui/views/controls/button/image_button.h" | 18 #include "ui/views/controls/button/image_button.h" |
| 18 #include "ui/views/controls/button/menu_button.h" | 19 #include "ui/views/controls/button/menu_button.h" |
| 19 #include "ui/views/controls/label.h" | 20 #include "ui/views/controls/label.h" |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 } | 217 } |
| 217 | 218 |
| 218 void AddAvatarButton() { | 219 void AddAvatarButton() { |
| 219 menu_button_ = new AvatarMenuButton(NULL, false); | 220 menu_button_ = new AvatarMenuButton(NULL, false); |
| 220 menu_button_->set_id(VIEW_ID_AVATAR_BUTTON); | 221 menu_button_->set_id(VIEW_ID_AVATAR_BUTTON); |
| 221 delegate_->SetShouldShowAvatar(true); | 222 delegate_->SetShouldShowAvatar(true); |
| 222 root_view_->AddChildView(menu_button_); | 223 root_view_->AddChildView(menu_button_); |
| 223 } | 224 } |
| 224 | 225 |
| 225 void AddAvatarLabel() { | 226 void AddAvatarLabel() { |
| 226 avatar_label_ = new views::MenuButton(NULL, base::string16(), NULL, false); | 227 avatar_label_ = new AvatarLabel(NULL); |
| 227 avatar_label_->set_id(VIEW_ID_AVATAR_LABEL); | 228 avatar_label_->set_id(VIEW_ID_AVATAR_LABEL); |
| 228 root_view_->AddChildView(avatar_label_); | 229 root_view_->AddChildView(avatar_label_); |
| 229 | 230 |
| 230 // The avatar label should only be used together with the avatar button. | 231 // The avatar label should only be used together with the avatar button. |
| 231 AddAvatarButton(); | 232 AddAvatarButton(); |
| 232 } | 233 } |
| 233 | 234 |
| 234 void AddNewAvatarButton() { | 235 void AddNewAvatarButton() { |
| 235 new_avatar_button_ = | 236 new_avatar_button_ = |
| 236 new views::MenuButton(NULL, base::string16(), NULL, false); | 237 new views::MenuButton(NULL, base::string16(), NULL, false); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 252 | 253 |
| 253 // Widgets: | 254 // Widgets: |
| 254 views::ImageButton* minimize_button_; | 255 views::ImageButton* minimize_button_; |
| 255 views::ImageButton* maximize_button_; | 256 views::ImageButton* maximize_button_; |
| 256 views::ImageButton* restore_button_; | 257 views::ImageButton* restore_button_; |
| 257 views::ImageButton* close_button_; | 258 views::ImageButton* close_button_; |
| 258 | 259 |
| 259 TabIconView* tab_icon_view_; | 260 TabIconView* tab_icon_view_; |
| 260 views::Label* window_title_; | 261 views::Label* window_title_; |
| 261 | 262 |
| 263 AvatarLabel* avatar_label_; |
| 262 AvatarMenuButton* menu_button_; | 264 AvatarMenuButton* menu_button_; |
| 263 views::MenuButton* avatar_label_; | |
| 264 views::MenuButton* new_avatar_button_; | 265 views::MenuButton* new_avatar_button_; |
| 265 | 266 |
| 266 DISALLOW_COPY_AND_ASSIGN(OpaqueBrowserFrameViewLayoutTest); | 267 DISALLOW_COPY_AND_ASSIGN(OpaqueBrowserFrameViewLayoutTest); |
| 267 }; | 268 }; |
| 268 | 269 |
| 269 TEST_F(OpaqueBrowserFrameViewLayoutTest, BasicWindow) { | 270 TEST_F(OpaqueBrowserFrameViewLayoutTest, BasicWindow) { |
| 270 // Tests the layout of a default chrome window with no avatars, no window | 271 // Tests the layout of a default chrome window with no avatars, no window |
| 271 // titles, and a tabstrip. | 272 // titles, and a tabstrip. |
| 272 root_view_->Layout(); | 273 root_view_->Layout(); |
| 273 | 274 |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 427 EXPECT_EQ("7,11 40x29", menu_button_->bounds().ToString()); | 428 EXPECT_EQ("7,11 40x29", menu_button_->bounds().ToString()); |
| 428 EXPECT_EQ("45,13 352x29", | 429 EXPECT_EQ("45,13 352x29", |
| 429 layout_manager_->GetBoundsForTabStrip( | 430 layout_manager_->GetBoundsForTabStrip( |
| 430 delegate_->GetTabstripPreferredSize(), kWidth).ToString()); | 431 delegate_->GetTabstripPreferredSize(), kWidth).ToString()); |
| 431 EXPECT_EQ("261x73", layout_manager_->GetMinimumSize(kWidth).ToString()); | 432 EXPECT_EQ("261x73", layout_manager_->GetMinimumSize(kWidth).ToString()); |
| 432 } | 433 } |
| 433 | 434 |
| 434 TEST_F(OpaqueBrowserFrameViewLayoutTest, WindowWithAvatarWithButtonsOnLeft) { | 435 TEST_F(OpaqueBrowserFrameViewLayoutTest, WindowWithAvatarWithButtonsOnLeft) { |
| 435 // Tests the layout of a chrome window with an avatar icon and caption buttons | 436 // Tests the layout of a chrome window with an avatar icon and caption buttons |
| 436 // on the left. The avatar icon should therefore be on the right. | 437 // on the left. The avatar icon should therefore be on the right. |
| 437 AddAvatarButton(); | 438 // AddAvatarLabel() also adds the avatar button. |
| 439 AddAvatarLabel(); |
| 438 std::vector<views::FrameButton> leading_buttons; | 440 std::vector<views::FrameButton> leading_buttons; |
| 439 std::vector<views::FrameButton> trailing_buttons; | 441 std::vector<views::FrameButton> trailing_buttons; |
| 440 leading_buttons.push_back(views::FRAME_BUTTON_CLOSE); | 442 leading_buttons.push_back(views::FRAME_BUTTON_CLOSE); |
| 441 leading_buttons.push_back(views::FRAME_BUTTON_MINIMIZE); | 443 leading_buttons.push_back(views::FRAME_BUTTON_MINIMIZE); |
| 442 leading_buttons.push_back(views::FRAME_BUTTON_MAXIMIZE); | 444 leading_buttons.push_back(views::FRAME_BUTTON_MAXIMIZE); |
| 443 layout_manager_->SetButtonOrdering(leading_buttons, trailing_buttons); | 445 layout_manager_->SetButtonOrdering(leading_buttons, trailing_buttons); |
| 444 root_view_->Layout(); | 446 root_view_->Layout(); |
| 445 | 447 |
| 446 EXPECT_EQ("73,1 25x18", maximize_button_->bounds().ToString()); | 448 EXPECT_EQ("73,1 25x18", maximize_button_->bounds().ToString()); |
| 447 EXPECT_EQ("47,1 26x18", minimize_button_->bounds().ToString()); | 449 EXPECT_EQ("47,1 26x18", minimize_button_->bounds().ToString()); |
| 448 EXPECT_EQ("0,0 0x0", restore_button_->bounds().ToString()); | 450 EXPECT_EQ("0,0 0x0", restore_button_->bounds().ToString()); |
| 449 EXPECT_EQ("4,1 43x18", close_button_->bounds().ToString()); | 451 EXPECT_EQ("4,1 43x18", close_button_->bounds().ToString()); |
| 450 | 452 |
| 451 // Check the location of the avatar | 453 // Check the location of the avatar |
| 452 EXPECT_EQ("454,11 40x29", menu_button_->bounds().ToString()); | 454 EXPECT_EQ("454,11 40x29", menu_button_->bounds().ToString()); |
| 453 EXPECT_EQ("93,13 356x29", | 455 |
| 454 layout_manager_->GetBoundsForTabStrip( | 456 // Check the tab strip bounds. |
| 455 delegate_->GetTabstripPreferredSize(), kWidth).ToString()); | 457 gfx::Rect tab_strip_bounds = layout_manager_->GetBoundsForTabStrip( |
| 458 delegate_->GetTabstripPreferredSize(), kWidth); |
| 459 EXPECT_GT(tab_strip_bounds.x(), maximize_button_->bounds().x()); |
| 460 EXPECT_GT(maximize_button_->bounds().right(), tab_strip_bounds.x()); |
| 461 EXPECT_EQ(13, tab_strip_bounds.y()); |
| 462 EXPECT_EQ(29, tab_strip_bounds.height()); |
| 463 EXPECT_GT(avatar_label_->bounds().x(), tab_strip_bounds.right()); |
| 456 EXPECT_EQ("261x73", layout_manager_->GetMinimumSize(kWidth).ToString()); | 464 EXPECT_EQ("261x73", layout_manager_->GetMinimumSize(kWidth).ToString()); |
| 457 | 465 |
| 466 // Check the relative location of the avatar label to the avatar. The right |
| 467 // end of the avatar label should be slightly to the right of the right end of |
| 468 // the avatar icon. |
| 469 EXPECT_GT(avatar_label_->bounds().right(), menu_button_->bounds().right()); |
| 470 EXPECT_GT(menu_button_->bounds().x(), avatar_label_->bounds().x()); |
| 471 EXPECT_GT(menu_button_->bounds().bottom(), |
| 472 avatar_label_->bounds().bottom()); |
| 473 EXPECT_GT(avatar_label_->bounds().y(), menu_button_->bounds().y()); |
| 474 |
| 458 // This means that the menu will pop out facing the left (if it were to face | 475 // This means that the menu will pop out facing the left (if it were to face |
| 459 // the right, it would go outside the window frame and be clipped). | 476 // the right, it would go outside the window frame and be clipped). |
| 460 EXPECT_TRUE(menu_button_->button_on_right()); | 477 EXPECT_TRUE(menu_button_->button_on_right()); |
| 461 | 478 |
| 462 // If the buttons are on the left, there should be no hidden icon for the user | 479 // If the buttons are on the left, there should be no hidden icon for the user |
| 463 // to double click. | 480 // to double click. |
| 464 EXPECT_EQ("0,0 0x0", layout_manager_->IconBounds().ToString()); | 481 EXPECT_EQ("0,0 0x0", layout_manager_->IconBounds().ToString()); |
| 465 } | 482 } |
| 466 | 483 |
| 467 TEST_F(OpaqueBrowserFrameViewLayoutTest, | 484 TEST_F(OpaqueBrowserFrameViewLayoutTest, |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 511 EXPECT_EQ("385,1 12x20", new_avatar_button_->bounds().ToString()); | 528 EXPECT_EQ("385,1 12x20", new_avatar_button_->bounds().ToString()); |
| 512 // The basic window bounds are (-1, 13 398x29). There should not be an icon | 529 // The basic window bounds are (-1, 13 398x29). There should not be an icon |
| 513 // avatar in the left, and the new avatar button has an offset of 5 to its | 530 // avatar in the left, and the new avatar button has an offset of 5 to its |
| 514 // next control. | 531 // next control. |
| 515 EXPECT_EQ("-1,13 381x29", | 532 EXPECT_EQ("-1,13 381x29", |
| 516 layout_manager_->GetBoundsForTabStrip( | 533 layout_manager_->GetBoundsForTabStrip( |
| 517 delegate_->GetTabstripPreferredSize(), kWidth).ToString()); | 534 delegate_->GetTabstripPreferredSize(), kWidth).ToString()); |
| 518 EXPECT_EQ("261x73", layout_manager_->GetMinimumSize(kWidth).ToString()); | 535 EXPECT_EQ("261x73", layout_manager_->GetMinimumSize(kWidth).ToString()); |
| 519 } | 536 } |
| 520 | 537 |
| 521 TEST_F(OpaqueBrowserFrameViewLayoutTest, WindowWithAvatarLabelAndButton) { | 538 TEST_F(OpaqueBrowserFrameViewLayoutTest, WindowWithAvatarLabelAndButtonOnLeft) { |
| 522 AddAvatarLabel(); | 539 AddAvatarLabel(); |
| 523 root_view_->Layout(); | 540 root_view_->Layout(); |
| 524 | 541 |
| 525 ExpectBasicWindowBounds(); | 542 ExpectBasicWindowBounds(); |
| 526 | 543 |
| 527 // Check the location of the avatar label relative to the avatar button. | 544 // Check the location of the avatar label relative to the avatar button if |
| 545 // both are displayed on the left side. |
| 528 // The label height and width depends on the font size and the text displayed. | 546 // The label height and width depends on the font size and the text displayed. |
| 529 // This may possibly change, so we don't test it here. | 547 // This may possibly change, so we don't test it here. |
| 530 EXPECT_EQ(menu_button_->bounds().x() - 2, avatar_label_->bounds().x()); | 548 EXPECT_EQ(menu_button_->bounds().x() - 2, avatar_label_->bounds().x()); |
| 531 EXPECT_EQ( | 549 EXPECT_EQ( |
| 532 menu_button_->bounds().bottom() - 3 - avatar_label_->bounds().height(), | 550 menu_button_->bounds().bottom() - 3 - avatar_label_->bounds().height(), |
| 533 avatar_label_->bounds().y()); | 551 avatar_label_->bounds().y()); |
| 534 } | 552 } |
| OLD | NEW |