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. These bounds depend on the avatar label, which |
455 delegate_->GetTabstripPreferredSize(), kWidth).ToString()); | 457 // can have a different width on Linux and Windows depending on the font size |
458 // used. | |
459 int avatar_button_width = menu_button_->bounds().width(); | |
460 int avatar_label_width = avatar_label_->bounds().width(); | |
461 const int kAvatarIconToLabelSpacing = 2; | |
Peter Kasting
2014/01/15 02:06:26
There are a lot of magic numbers in here. It woul
Adrian Kuegel
2014/01/15 16:24:51
I tried to rewrite my changes to do only relative
| |
462 int expected_width = 356 - (avatar_label_width - avatar_button_width) + | |
463 kAvatarIconToLabelSpacing; | |
464 gfx::Rect tab_strip_bounds = layout_manager_->GetBoundsForTabStrip( | |
465 delegate_->GetTabstripPreferredSize(), kWidth); | |
466 EXPECT_EQ(93, tab_strip_bounds.x()); | |
467 EXPECT_EQ(13, tab_strip_bounds.y()); | |
468 EXPECT_EQ(expected_width, tab_strip_bounds.width()); | |
469 EXPECT_EQ(29, tab_strip_bounds.height()); | |
456 EXPECT_EQ("261x73", layout_manager_->GetMinimumSize(kWidth).ToString()); | 470 EXPECT_EQ("261x73", layout_manager_->GetMinimumSize(kWidth).ToString()); |
457 | 471 |
472 // Check the relative location of the avatar label to the avatar. The right | |
473 // end of the avatar label should be slightly to the right of the right end of | |
474 // the avatar icon. | |
475 EXPECT_EQ(menu_button_->bounds().right() + kAvatarIconToLabelSpacing, | |
476 avatar_label_->bounds().right()); | |
477 EXPECT_EQ( | |
478 menu_button_->bounds().bottom() - 3 - avatar_label_->bounds().height(), | |
479 avatar_label_->bounds().y()); | |
480 | |
458 // This means that the menu will pop out facing the left (if it were to face | 481 // 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). | 482 // the right, it would go outside the window frame and be clipped). |
460 EXPECT_TRUE(menu_button_->button_on_right()); | 483 EXPECT_TRUE(menu_button_->button_on_right()); |
461 | 484 |
462 // If the buttons are on the left, there should be no hidden icon for the user | 485 // If the buttons are on the left, there should be no hidden icon for the user |
463 // to double click. | 486 // to double click. |
464 EXPECT_EQ("0,0 0x0", layout_manager_->IconBounds().ToString()); | 487 EXPECT_EQ("0,0 0x0", layout_manager_->IconBounds().ToString()); |
465 } | 488 } |
466 | 489 |
467 TEST_F(OpaqueBrowserFrameViewLayoutTest, | 490 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()); | 534 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 | 535 // 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 | 536 // avatar in the left, and the new avatar button has an offset of 5 to its |
514 // next control. | 537 // next control. |
515 EXPECT_EQ("-1,13 381x29", | 538 EXPECT_EQ("-1,13 381x29", |
516 layout_manager_->GetBoundsForTabStrip( | 539 layout_manager_->GetBoundsForTabStrip( |
517 delegate_->GetTabstripPreferredSize(), kWidth).ToString()); | 540 delegate_->GetTabstripPreferredSize(), kWidth).ToString()); |
518 EXPECT_EQ("261x73", layout_manager_->GetMinimumSize(kWidth).ToString()); | 541 EXPECT_EQ("261x73", layout_manager_->GetMinimumSize(kWidth).ToString()); |
519 } | 542 } |
520 | 543 |
521 TEST_F(OpaqueBrowserFrameViewLayoutTest, WindowWithAvatarLabelAndButton) { | 544 TEST_F(OpaqueBrowserFrameViewLayoutTest, WindowWithAvatarLabelAndButtonOnLeft) { |
522 AddAvatarLabel(); | 545 AddAvatarLabel(); |
523 root_view_->Layout(); | 546 root_view_->Layout(); |
524 | 547 |
525 ExpectBasicWindowBounds(); | 548 ExpectBasicWindowBounds(); |
526 | 549 |
527 // Check the location of the avatar label relative to the avatar button. | 550 // Check the location of the avatar label relative to the avatar button if |
551 // both are displayed on the left side. | |
528 // The label height and width depends on the font size and the text displayed. | 552 // 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. | 553 // This may possibly change, so we don't test it here. |
530 EXPECT_EQ(menu_button_->bounds().x() - 2, avatar_label_->bounds().x()); | 554 EXPECT_EQ(menu_button_->bounds().x() - 2, avatar_label_->bounds().x()); |
531 EXPECT_EQ( | 555 EXPECT_EQ( |
532 menu_button_->bounds().bottom() - 3 - avatar_label_->bounds().height(), | 556 menu_button_->bounds().bottom() - 3 - avatar_label_->bounds().height(), |
533 avatar_label_->bounds().y()); | 557 avatar_label_->bounds().y()); |
534 } | 558 } |
OLD | NEW |