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 "chrome/browser/profiles/profiles_state.h" | |
7 #include "ui/gfx/font.h" | 8 #include "ui/gfx/font.h" |
8 #include "ui/views/controls/button/image_button.h" | 9 #include "ui/views/controls/button/image_button.h" |
9 #include "ui/views/controls/label.h" | 10 #include "ui/views/controls/label.h" |
10 | 11 |
11 #if defined(OS_WIN) | 12 #if defined(OS_WIN) |
12 #include "win8/util/win8_util.h" | 13 #include "win8/util/win8_util.h" |
13 #endif // OS_WIN | 14 #endif // OS_WIN |
14 | 15 |
15 namespace { | 16 namespace { |
16 | 17 |
(...skipping 25 matching lines...) Expand all Loading... | |
42 // way the tabstrip draws its bottom edge, will appear like a 1 px gap to the | 43 // way the tabstrip draws its bottom edge, will appear like a 1 px gap to the |
43 // user). | 44 // user). |
44 const int kAvatarBottomSpacing = 2; | 45 const int kAvatarBottomSpacing = 2; |
45 | 46 |
46 // Space between the frame border and the left edge of the avatar. | 47 // Space between the frame border and the left edge of the avatar. |
47 const int kAvatarLeftSpacing = 2; | 48 const int kAvatarLeftSpacing = 2; |
48 | 49 |
49 // Space between the right edge of the avatar and the tabstrip. | 50 // Space between the right edge of the avatar and the tabstrip. |
50 const int kAvatarRightSpacing = -4; | 51 const int kAvatarRightSpacing = -4; |
51 | 52 |
53 // How far the new avatar button is from the left of the minimize button. | |
54 const int kNewAvatarButtonOffset = 5; | |
55 | |
52 // In restored mode, the New Tab button isn't at the same height as the caption | 56 // In restored mode, the New Tab button isn't at the same height as the caption |
53 // buttons, but the space will look cluttered if it actually slides under them, | 57 // buttons, but the space will look cluttered if it actually slides under them, |
54 // so we stop it when the gap between the two is down to 5 px. | 58 // so we stop it when the gap between the two is down to 5 px. |
55 const int kNewTabCaptionRestoredSpacing = 5; | 59 const int kNewTabCaptionRestoredSpacing = 5; |
56 | 60 |
57 // In maximized mode, where the New Tab button and the caption buttons are at | 61 // In maximized mode, where the New Tab button and the caption buttons are at |
58 // similar vertical coordinates, we need to reserve a larger, 16 px gap to avoid | 62 // similar vertical coordinates, we need to reserve a larger, 16 px gap to avoid |
59 // looking too cluttered. | 63 // looking too cluttered. |
60 const int kNewTabCaptionMaximizedSpacing = 16; | 64 const int kNewTabCaptionMaximizedSpacing = 16; |
61 | 65 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
94 has_trailing_buttons_(false), | 98 has_trailing_buttons_(false), |
95 extra_caption_y_(kExtraCaption), | 99 extra_caption_y_(kExtraCaption), |
96 window_caption_spacing_(kCaptionButtonSpacing), | 100 window_caption_spacing_(kCaptionButtonSpacing), |
97 minimize_button_(NULL), | 101 minimize_button_(NULL), |
98 maximize_button_(NULL), | 102 maximize_button_(NULL), |
99 restore_button_(NULL), | 103 restore_button_(NULL), |
100 close_button_(NULL), | 104 close_button_(NULL), |
101 window_icon_(NULL), | 105 window_icon_(NULL), |
102 window_title_(NULL), | 106 window_title_(NULL), |
103 avatar_label_(NULL), | 107 avatar_label_(NULL), |
104 avatar_button_(NULL) { | 108 avatar_button_(NULL), |
109 new_avatar_button_(NULL) { | |
105 trailing_buttons_.push_back(views::FRAME_BUTTON_MINIMIZE); | 110 trailing_buttons_.push_back(views::FRAME_BUTTON_MINIMIZE); |
106 trailing_buttons_.push_back(views::FRAME_BUTTON_MAXIMIZE); | 111 trailing_buttons_.push_back(views::FRAME_BUTTON_MAXIMIZE); |
107 trailing_buttons_.push_back(views::FRAME_BUTTON_CLOSE); | 112 trailing_buttons_.push_back(views::FRAME_BUTTON_CLOSE); |
108 } | 113 } |
109 | 114 |
110 OpaqueBrowserFrameViewLayout::~OpaqueBrowserFrameViewLayout() {} | 115 OpaqueBrowserFrameViewLayout::~OpaqueBrowserFrameViewLayout() {} |
111 | 116 |
112 // static | 117 // static |
113 bool OpaqueBrowserFrameViewLayout::ShouldAddDefaultCaptionButtons() { | 118 bool OpaqueBrowserFrameViewLayout::ShouldAddDefaultCaptionButtons() { |
114 #if defined(OS_WIN) | 119 #if defined(OS_WIN) |
115 return !win8::IsSingleWindowMetroMode(); | 120 return !win8::IsSingleWindowMetroMode(); |
116 #endif // OS_WIN | 121 #endif // OS_WIN |
117 return true; | 122 return true; |
118 } | 123 } |
119 | 124 |
120 void OpaqueBrowserFrameViewLayout::SetButtonOrdering( | 125 void OpaqueBrowserFrameViewLayout::SetButtonOrdering( |
121 const std::vector<views::FrameButton>& leading_buttons, | 126 const std::vector<views::FrameButton>& leading_buttons, |
122 const std::vector<views::FrameButton>& trailing_buttons) { | 127 const std::vector<views::FrameButton>& trailing_buttons) { |
123 leading_buttons_ = leading_buttons; | 128 leading_buttons_ = leading_buttons; |
124 trailing_buttons_ = trailing_buttons; | 129 trailing_buttons_ = trailing_buttons; |
125 } | 130 } |
126 | 131 |
127 gfx::Rect OpaqueBrowserFrameViewLayout::GetBoundsForTabStrip( | 132 gfx::Rect OpaqueBrowserFrameViewLayout::GetBoundsForTabStrip( |
128 const gfx::Size& tabstrip_preferred_size, | 133 const gfx::Size& tabstrip_preferred_size, |
129 int available_width) const { | 134 int available_width) const { |
130 available_width -= trailing_button_start_; | 135 available_width -= trailing_button_start_; |
131 available_width -= leading_button_start_; | 136 available_width -= leading_button_start_; |
132 | 137 |
138 // The new avatar button is displayed to the left of the caption area buttons. | |
139 if (delegate_->ShouldShowAvatar() && new_avatar_button_) | |
140 available_width -= new_avatar_button_->width(); | |
Elliot Glaysher
2013/09/26 21:05:44
This shouldn't be calculated here; rather, it shou
noms (inactive)
2013/10/01 17:42:21
Done.
| |
141 | |
133 if (delegate_->GetAdditionalReservedSpaceInTabStrip()) | 142 if (delegate_->GetAdditionalReservedSpaceInTabStrip()) |
134 available_width -= delegate_->GetAdditionalReservedSpaceInTabStrip(); | 143 available_width -= delegate_->GetAdditionalReservedSpaceInTabStrip(); |
135 | 144 |
136 const int caption_spacing = delegate_->IsMaximized() ? | 145 const int caption_spacing = delegate_->IsMaximized() ? |
137 kNewTabCaptionMaximizedSpacing : kNewTabCaptionRestoredSpacing; | 146 kNewTabCaptionMaximizedSpacing : kNewTabCaptionRestoredSpacing; |
138 const int tabstrip_width = available_width - caption_spacing; | 147 const int tabstrip_width = available_width - caption_spacing; |
139 gfx::Rect bounds(leading_button_start_, GetTabStripInsetsTop(false), | 148 gfx::Rect bounds(leading_button_start_, GetTabStripInsetsTop(false), |
140 std::max(0, tabstrip_width), | 149 std::max(0, tabstrip_width), |
141 tabstrip_preferred_size.height()); | 150 tabstrip_preferred_size.height()); |
142 | 151 |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
348 window_icon_bounds_ = gfx::Rect(); | 357 window_icon_bounds_ = gfx::Rect(); |
349 } else { | 358 } else { |
350 // We set the icon bounds to a small rectangle in the top leading corner | 359 // We set the icon bounds to a small rectangle in the top leading corner |
351 // if there are no icons on the leading side. | 360 // if there are no icons on the leading side. |
352 window_icon_bounds_ = gfx::Rect( | 361 window_icon_bounds_ = gfx::Rect( |
353 frame_thickness + kIconLeftSpacing, frame_thickness, size, size); | 362 frame_thickness + kIconLeftSpacing, frame_thickness, size, size); |
354 } | 363 } |
355 } | 364 } |
356 } | 365 } |
357 | 366 |
358 void OpaqueBrowserFrameViewLayout::LayoutAvatar() { | 367 void OpaqueBrowserFrameViewLayout::LayoutNewStyleAvatar() { |
Elliot Glaysher
2013/09/26 21:05:44
Since the new avatar menu looks like a caption but
noms (inactive)
2013/10/01 17:42:21
I've used the has_trailing_buttons_ boolean that g
Elliot Glaysher
2013/10/01 18:12:56
Yeap! "close:minimize" is the default button layou
noms (inactive)
2013/10/03 19:30:14
After offline conversation, I've made it so that t
| |
368 gfx::Size label_size = new_avatar_button_->GetPreferredSize(); | |
369 int caption_y = CaptionButtonY(false); | |
370 new_avatar_button_->SetBounds( | |
371 minimize_button_->x() - label_size.width() - kNewAvatarButtonOffset, | |
372 caption_y, | |
373 label_size.width(), | |
374 caption_y + kCaptionButtonHeightWithPadding); | |
Elliot Glaysher
2013/09/26 21:05:44
This position calculation is wrong. You can't posi
noms (inactive)
2013/10/01 17:42:21
Done.
| |
375 } | |
376 | |
377 void OpaqueBrowserFrameViewLayout::LayoutIncognitoAvatar() { | |
359 // Even though the avatar is used for both incognito and profiles we always | 378 // Even though the avatar is used for both incognito and profiles we always |
360 // use the incognito icon to layout the avatar button. The profile icon | 379 // use the incognito icon to layout the avatar button. The profile icon |
361 // can be customized so we can't depend on its size to perform layout. | 380 // can be customized so we can't depend on its size to perform layout. |
362 gfx::ImageSkia incognito_icon = delegate_->GetOTRAvatarIcon(); | 381 gfx::ImageSkia incognito_icon = delegate_->GetOTRAvatarIcon(); |
363 | 382 |
364 int avatar_bottom = GetTabStripInsetsTop(false) + | 383 int avatar_bottom = GetTabStripInsetsTop(false) + |
365 delegate_->GetTabStripHeight() - kAvatarBottomSpacing; | 384 delegate_->GetTabStripHeight() - kAvatarBottomSpacing; |
366 int avatar_restored_y = avatar_bottom - incognito_icon.height(); | 385 int avatar_restored_y = avatar_bottom - incognito_icon.height(); |
367 int avatar_y = delegate_->IsMaximized() ? | 386 int avatar_y = delegate_->IsMaximized() ? |
368 (NonClientTopBorderHeight(false) + kTabstripTopShadowThickness) : | 387 (NonClientTopBorderHeight(false) + kTabstripTopShadowThickness) : |
369 avatar_restored_y; | 388 avatar_restored_y; |
370 avatar_bounds_.SetRect(leading_button_start_ + kAvatarLeftSpacing, | 389 avatar_bounds_.SetRect(leading_button_start_ + kAvatarLeftSpacing, |
371 avatar_y, incognito_icon.width(), | 390 avatar_y, incognito_icon.width(), |
372 delegate_->ShouldShowAvatar() ? (avatar_bottom - avatar_y) : 0); | 391 delegate_->ShouldShowAvatar() ? (avatar_bottom - avatar_y) : 0); |
373 if (avatar_button_) { | 392 if (avatar_button_) { |
374 avatar_button_->SetBoundsRect(avatar_bounds_); | 393 avatar_button_->SetBoundsRect(avatar_bounds_); |
Elliot Glaysher
2013/09/26 21:05:44
If you're pulling out the code block after this (n
noms (inactive)
2013/10/01 17:42:21
I don't actually know what I was thinking when I s
| |
375 | |
376 if (avatar_label_) { | |
377 // Space between the bottom of the avatar and the bottom of the avatar | |
378 // label. | |
379 const int kAvatarLabelBottomSpacing = 3; | |
380 gfx::Size label_size = avatar_label_->GetPreferredSize(); | |
381 // The x-position of the avatar label should be slightly to the left of | |
382 // the avatar menu button. Therefore we use the |leading_button_start_| | |
383 // value directly. | |
384 gfx::Rect label_bounds( | |
385 leading_button_start_, | |
386 avatar_bottom - kAvatarLabelBottomSpacing - label_size.height(), | |
387 label_size.width(), | |
388 delegate_->ShouldShowAvatar() ? label_size.height() : 0); | |
389 avatar_label_->SetBoundsRect(label_bounds); | |
390 leading_button_start_ += label_size.width(); | |
391 } else { | |
392 leading_button_start_ += kAvatarLeftSpacing + incognito_icon.width(); | |
393 } | |
394 | |
395 // We just add the avatar button size to the minimum size because clicking | |
396 // the avatar label does the same thing as clicking the avatar button. | |
397 minimum_size_for_buttons_ += kAvatarLeftSpacing + incognito_icon.width(); | |
398 } | 394 } |
399 } | 395 } |
400 | 396 |
397 void OpaqueBrowserFrameViewLayout::LayoutAvatar() { | |
398 LayoutIncognitoAvatar(); | |
399 gfx::ImageSkia incognito_icon = delegate_->GetOTRAvatarIcon(); | |
400 | |
401 int avatar_bottom = GetTabStripInsetsTop(false) + | |
402 delegate_->GetTabStripHeight() - kAvatarBottomSpacing; | |
403 | |
404 if (avatar_label_) { | |
405 // Space between the bottom of the avatar and the bottom of the avatar | |
406 // label. | |
407 const int kAvatarLabelBottomSpacing = 3; | |
408 gfx::Size label_size = avatar_label_->GetPreferredSize(); | |
409 // The x-position of the avatar label should be slightly to the left of | |
410 // the avatar menu button. Therefore we use the |leading_button_start_| | |
411 // value directly. | |
412 gfx::Rect label_bounds( | |
413 leading_button_start_, | |
414 avatar_bottom - kAvatarLabelBottomSpacing - label_size.height(), | |
415 label_size.width(), | |
416 delegate_->ShouldShowAvatar() ? label_size.height() : 0); | |
417 avatar_label_->SetBoundsRect(label_bounds); | |
418 leading_button_start_ += label_size.width(); | |
419 } else { | |
420 leading_button_start_ += kAvatarLeftSpacing + incognito_icon.width(); | |
421 } | |
422 | |
423 // We just add the avatar button size to the minimum size because clicking | |
424 // the avatar label does the same thing as clicking the avatar button. | |
425 minimum_size_for_buttons_ += kAvatarLeftSpacing + incognito_icon.width(); | |
426 } | |
427 | |
401 void OpaqueBrowserFrameViewLayout::ConfigureButton( | 428 void OpaqueBrowserFrameViewLayout::ConfigureButton( |
402 views::View* host, | 429 views::View* host, |
403 views::FrameButton button_id, | 430 views::FrameButton button_id, |
404 ButtonAlignment alignment, | 431 ButtonAlignment alignment, |
405 int caption_y) { | 432 int caption_y) { |
406 switch (button_id) { | 433 switch (button_id) { |
407 case views::FRAME_BUTTON_MINIMIZE: { | 434 case views::FRAME_BUTTON_MINIMIZE: { |
408 minimize_button_->SetVisible(true); | 435 minimize_button_->SetVisible(true); |
409 SetBoundsForButton(host, minimize_button_, alignment, caption_y); | 436 SetBoundsForButton(host, minimize_button_, alignment, caption_y); |
410 break; | 437 break; |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
553 view->GetClassName()); | 580 view->GetClassName()); |
554 } | 581 } |
555 window_title_ = static_cast<views::Label*>(view); | 582 window_title_ = static_cast<views::Label*>(view); |
556 break; | 583 break; |
557 case VIEW_ID_AVATAR_LABEL: | 584 case VIEW_ID_AVATAR_LABEL: |
558 avatar_label_ = view; | 585 avatar_label_ = view; |
559 break; | 586 break; |
560 case VIEW_ID_AVATAR_BUTTON: | 587 case VIEW_ID_AVATAR_BUTTON: |
561 avatar_button_ = view; | 588 avatar_button_ = view; |
562 break; | 589 break; |
590 case VIEW_ID_NEW_AVATAR_BUTTON: | |
591 new_avatar_button_ = view; | |
592 break; | |
563 default: | 593 default: |
564 NOTIMPLEMENTED() << "Unknown view id " << id; | 594 NOTIMPLEMENTED() << "Unknown view id " << id; |
565 break; | 595 break; |
566 } | 596 } |
567 } | 597 } |
568 | 598 |
569 /////////////////////////////////////////////////////////////////////////////// | 599 /////////////////////////////////////////////////////////////////////////////// |
570 // OpaqueBrowserFrameView, views::LayoutManager: | 600 // OpaqueBrowserFrameView, views::LayoutManager: |
571 | 601 |
572 void OpaqueBrowserFrameViewLayout::Layout(views::View* host) { | 602 void OpaqueBrowserFrameViewLayout::Layout(views::View* host) { |
573 // Reset all our data so that everything is invisible. | 603 // Reset all our data so that everything is invisible. |
574 int thickness = FrameBorderThickness(false); | 604 int thickness = FrameBorderThickness(false); |
575 leading_button_start_ = thickness; | 605 leading_button_start_ = thickness; |
576 trailing_button_start_ = thickness; | 606 trailing_button_start_ = thickness; |
577 minimum_size_for_buttons_ = leading_button_start_ + trailing_button_start_; | 607 minimum_size_for_buttons_ = leading_button_start_ + trailing_button_start_; |
578 has_leading_buttons_ = false; | 608 has_leading_buttons_ = false; |
579 has_trailing_buttons_ = false; | 609 has_trailing_buttons_ = false; |
580 | 610 |
581 LayoutWindowControls(host); | 611 LayoutWindowControls(host); |
582 LayoutTitleBar(host); | 612 LayoutTitleBar(host); |
583 | 613 |
584 // We now add a single pixel to the leading spacing. We do this because the | 614 // We now add a single pixel to the leading spacing. We do this because the |
585 // avatar and tab strip start one pixel inward compared to where things start | 615 // avatar and tab strip start one pixel inward compared to where things start |
586 // on the trailing side. | 616 // on the trailing side. |
587 leading_button_start_++; | 617 leading_button_start_++; |
588 | 618 |
589 LayoutAvatar(); | 619 if (profiles::IsNewProfileManagementEnabled()) { |
620 if (delegate_->IsOffTheRecord() && !delegate_->IsGuestSession()) | |
621 LayoutIncognitoAvatar(); | |
622 else | |
623 LayoutNewStyleAvatar(); | |
624 } else { | |
625 LayoutAvatar(); | |
626 } | |
590 | 627 |
591 client_view_bounds_ = CalculateClientAreaBounds( | 628 client_view_bounds_ = CalculateClientAreaBounds( |
592 host->width(), host->height()); | 629 host->width(), host->height()); |
593 } | 630 } |
594 | 631 |
595 gfx::Size OpaqueBrowserFrameViewLayout::GetPreferredSize(views::View* host) { | 632 gfx::Size OpaqueBrowserFrameViewLayout::GetPreferredSize(views::View* host) { |
596 // This is never used; NonClientView::GetPreferredSize() will be called | 633 // This is never used; NonClientView::GetPreferredSize() will be called |
597 // instead. | 634 // instead. |
598 NOTREACHED(); | 635 NOTREACHED(); |
599 return gfx::Size(); | 636 return gfx::Size(); |
600 } | 637 } |
601 | 638 |
602 void OpaqueBrowserFrameViewLayout::ViewAdded(views::View* host, | 639 void OpaqueBrowserFrameViewLayout::ViewAdded(views::View* host, |
603 views::View* view) { | 640 views::View* view) { |
604 SetView(view->id(), view); | 641 SetView(view->id(), view); |
605 } | 642 } |
606 | 643 |
607 void OpaqueBrowserFrameViewLayout::ViewRemoved(views::View* host, | 644 void OpaqueBrowserFrameViewLayout::ViewRemoved(views::View* host, |
608 views::View* view) { | 645 views::View* view) { |
609 SetView(view->id(), NULL); | 646 SetView(view->id(), NULL); |
610 } | 647 } |
OLD | NEW |