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" | |
8 #include "chrome/browser/ui/views/new_avatar_button.h" | |
7 #include "ui/gfx/font.h" | 9 #include "ui/gfx/font.h" |
8 #include "ui/views/controls/button/image_button.h" | 10 #include "ui/views/controls/button/image_button.h" |
9 #include "ui/views/controls/label.h" | 11 #include "ui/views/controls/label.h" |
10 | 12 |
11 #if defined(OS_WIN) | 13 #if defined(OS_WIN) |
12 #include "win8/util/win8_util.h" | 14 #include "win8/util/win8_util.h" |
13 #endif // OS_WIN | 15 #endif // OS_WIN |
14 | 16 |
15 namespace { | 17 namespace { |
16 | 18 |
(...skipping 25 matching lines...) Expand all Loading... | |
42 // way the tabstrip draws its bottom edge, will appear like a 1 px gap to the | 44 // way the tabstrip draws its bottom edge, will appear like a 1 px gap to the |
43 // user). | 45 // user). |
44 const int kAvatarBottomSpacing = 2; | 46 const int kAvatarBottomSpacing = 2; |
45 | 47 |
46 // Space between the frame border and the left edge of the avatar. | 48 // Space between the frame border and the left edge of the avatar. |
47 const int kAvatarLeftSpacing = 2; | 49 const int kAvatarLeftSpacing = 2; |
48 | 50 |
49 // Space between the right edge of the avatar and the tabstrip. | 51 // Space between the right edge of the avatar and the tabstrip. |
50 const int kAvatarRightSpacing = -4; | 52 const int kAvatarRightSpacing = -4; |
51 | 53 |
54 // How far the new avatar button is from the left of the minimize button. | |
Elliot Glaysher
2013/10/01 18:12:56
Change comment: how far it is from the closest cap
noms (inactive)
2013/10/03 19:30:14
Done.
| |
55 const int kNewAvatarButtonOffset = 5; | |
56 | |
52 // In restored mode, the New Tab button isn't at the same height as the caption | 57 // 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, | 58 // 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. | 59 // so we stop it when the gap between the two is down to 5 px. |
55 const int kNewTabCaptionRestoredSpacing = 5; | 60 const int kNewTabCaptionRestoredSpacing = 5; |
56 | 61 |
57 // In maximized mode, where the New Tab button and the caption buttons are at | 62 // 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 | 63 // similar vertical coordinates, we need to reserve a larger, 16 px gap to avoid |
59 // looking too cluttered. | 64 // looking too cluttered. |
60 const int kNewTabCaptionMaximizedSpacing = 16; | 65 const int kNewTabCaptionMaximizedSpacing = 16; |
61 | 66 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
94 has_trailing_buttons_(false), | 99 has_trailing_buttons_(false), |
95 extra_caption_y_(kExtraCaption), | 100 extra_caption_y_(kExtraCaption), |
96 window_caption_spacing_(kCaptionButtonSpacing), | 101 window_caption_spacing_(kCaptionButtonSpacing), |
97 minimize_button_(NULL), | 102 minimize_button_(NULL), |
98 maximize_button_(NULL), | 103 maximize_button_(NULL), |
99 restore_button_(NULL), | 104 restore_button_(NULL), |
100 close_button_(NULL), | 105 close_button_(NULL), |
101 window_icon_(NULL), | 106 window_icon_(NULL), |
102 window_title_(NULL), | 107 window_title_(NULL), |
103 avatar_label_(NULL), | 108 avatar_label_(NULL), |
104 avatar_button_(NULL) { | 109 avatar_button_(NULL), |
110 new_avatar_button_(NULL) { | |
105 trailing_buttons_.push_back(views::FRAME_BUTTON_MINIMIZE); | 111 trailing_buttons_.push_back(views::FRAME_BUTTON_MINIMIZE); |
106 trailing_buttons_.push_back(views::FRAME_BUTTON_MAXIMIZE); | 112 trailing_buttons_.push_back(views::FRAME_BUTTON_MAXIMIZE); |
107 trailing_buttons_.push_back(views::FRAME_BUTTON_CLOSE); | 113 trailing_buttons_.push_back(views::FRAME_BUTTON_CLOSE); |
108 } | 114 } |
109 | 115 |
110 OpaqueBrowserFrameViewLayout::~OpaqueBrowserFrameViewLayout() {} | 116 OpaqueBrowserFrameViewLayout::~OpaqueBrowserFrameViewLayout() {} |
111 | 117 |
112 // static | 118 // static |
113 bool OpaqueBrowserFrameViewLayout::ShouldAddDefaultCaptionButtons() { | 119 bool OpaqueBrowserFrameViewLayout::ShouldAddDefaultCaptionButtons() { |
114 #if defined(OS_WIN) | 120 #if defined(OS_WIN) |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
348 window_icon_bounds_ = gfx::Rect(); | 354 window_icon_bounds_ = gfx::Rect(); |
349 } else { | 355 } else { |
350 // We set the icon bounds to a small rectangle in the top leading corner | 356 // We set the icon bounds to a small rectangle in the top leading corner |
351 // if there are no icons on the leading side. | 357 // if there are no icons on the leading side. |
352 window_icon_bounds_ = gfx::Rect( | 358 window_icon_bounds_ = gfx::Rect( |
353 frame_thickness + kIconLeftSpacing, frame_thickness, size, size); | 359 frame_thickness + kIconLeftSpacing, frame_thickness, size, size); |
354 } | 360 } |
355 } | 361 } |
356 } | 362 } |
357 | 363 |
364 void OpaqueBrowserFrameViewLayout::LayoutNewStyleAvatar(views::View* host) { | |
365 if (!has_trailing_buttons_ && !has_leading_buttons_) | |
366 return; | |
367 | |
368 gfx::Size label_size = new_avatar_button_->GetPreferredSize(); | |
369 int button_size_with_offset = kNewAvatarButtonOffset + label_size.width(); | |
370 | |
371 int button_x; | |
372 int button_y = CaptionButtonY(false); | |
373 if (has_trailing_buttons_) { | |
374 button_x = host->width() - trailing_button_start_ - button_size_with_offset; | |
375 trailing_button_start_ += button_size_with_offset; | |
376 minimum_size_for_buttons_ += button_size_with_offset; | |
377 } else { | |
378 button_x = leading_button_start_ + kNewAvatarButtonOffset; | |
379 leading_button_start_ += button_size_with_offset; | |
380 minimum_size_for_buttons_ += button_size_with_offset; | |
381 } | |
382 | |
383 new_avatar_button_->set_avatar_bubble_align_right(has_trailing_buttons_); | |
384 new_avatar_button_->SetBounds( | |
385 button_x, | |
386 button_y, | |
387 label_size.width(), | |
388 button_y + kCaptionButtonHeightWithPadding); | |
389 } | |
390 | |
358 void OpaqueBrowserFrameViewLayout::LayoutAvatar() { | 391 void OpaqueBrowserFrameViewLayout::LayoutAvatar() { |
359 // Even though the avatar is used for both incognito and profiles we always | 392 // 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 | 393 // 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. | 394 // can be customized so we can't depend on its size to perform layout. |
362 gfx::ImageSkia incognito_icon = delegate_->GetOTRAvatarIcon(); | 395 gfx::ImageSkia incognito_icon = delegate_->GetOTRAvatarIcon(); |
363 | 396 |
364 int avatar_bottom = GetTabStripInsetsTop(false) + | 397 int avatar_bottom = GetTabStripInsetsTop(false) + |
365 delegate_->GetTabStripHeight() - kAvatarBottomSpacing; | 398 delegate_->GetTabStripHeight() - kAvatarBottomSpacing; |
366 int avatar_restored_y = avatar_bottom - incognito_icon.height(); | 399 int avatar_restored_y = avatar_bottom - incognito_icon.height(); |
367 int avatar_y = delegate_->IsMaximized() ? | 400 int avatar_y = delegate_->IsMaximized() ? |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
553 view->GetClassName()); | 586 view->GetClassName()); |
554 } | 587 } |
555 window_title_ = static_cast<views::Label*>(view); | 588 window_title_ = static_cast<views::Label*>(view); |
556 break; | 589 break; |
557 case VIEW_ID_AVATAR_LABEL: | 590 case VIEW_ID_AVATAR_LABEL: |
558 avatar_label_ = view; | 591 avatar_label_ = view; |
559 break; | 592 break; |
560 case VIEW_ID_AVATAR_BUTTON: | 593 case VIEW_ID_AVATAR_BUTTON: |
561 avatar_button_ = view; | 594 avatar_button_ = view; |
562 break; | 595 break; |
596 case VIEW_ID_NEW_AVATAR_BUTTON: | |
597 new_avatar_button_ = static_cast<NewAvatarButton*>(view); | |
598 break; | |
563 default: | 599 default: |
564 NOTIMPLEMENTED() << "Unknown view id " << id; | 600 NOTIMPLEMENTED() << "Unknown view id " << id; |
565 break; | 601 break; |
566 } | 602 } |
567 } | 603 } |
568 | 604 |
569 /////////////////////////////////////////////////////////////////////////////// | 605 /////////////////////////////////////////////////////////////////////////////// |
570 // OpaqueBrowserFrameView, views::LayoutManager: | 606 // OpaqueBrowserFrameView, views::LayoutManager: |
571 | 607 |
572 void OpaqueBrowserFrameViewLayout::Layout(views::View* host) { | 608 void OpaqueBrowserFrameViewLayout::Layout(views::View* host) { |
573 // Reset all our data so that everything is invisible. | 609 // Reset all our data so that everything is invisible. |
574 int thickness = FrameBorderThickness(false); | 610 int thickness = FrameBorderThickness(false); |
575 leading_button_start_ = thickness; | 611 leading_button_start_ = thickness; |
576 trailing_button_start_ = thickness; | 612 trailing_button_start_ = thickness; |
577 minimum_size_for_buttons_ = leading_button_start_ + trailing_button_start_; | 613 minimum_size_for_buttons_ = leading_button_start_ + trailing_button_start_; |
578 has_leading_buttons_ = false; | 614 has_leading_buttons_ = false; |
579 has_trailing_buttons_ = false; | 615 has_trailing_buttons_ = false; |
580 | 616 |
581 LayoutWindowControls(host); | 617 LayoutWindowControls(host); |
582 LayoutTitleBar(host); | 618 LayoutTitleBar(host); |
583 | 619 |
584 // We now add a single pixel to the leading spacing. We do this because the | 620 // 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 | 621 // avatar and tab strip start one pixel inward compared to where things start |
586 // on the trailing side. | 622 // on the trailing side. |
587 leading_button_start_++; | 623 leading_button_start_++; |
588 | 624 |
589 LayoutAvatar(); | 625 if (delegate_->IsRegularOrGuestSession() && |
626 profiles::IsNewProfileManagementEnabled()) | |
627 LayoutNewStyleAvatar(host); | |
628 else | |
629 LayoutAvatar(); | |
590 | 630 |
591 client_view_bounds_ = CalculateClientAreaBounds( | 631 client_view_bounds_ = CalculateClientAreaBounds( |
592 host->width(), host->height()); | 632 host->width(), host->height()); |
593 } | 633 } |
594 | 634 |
595 gfx::Size OpaqueBrowserFrameViewLayout::GetPreferredSize(views::View* host) { | 635 gfx::Size OpaqueBrowserFrameViewLayout::GetPreferredSize(views::View* host) { |
596 // This is never used; NonClientView::GetPreferredSize() will be called | 636 // This is never used; NonClientView::GetPreferredSize() will be called |
597 // instead. | 637 // instead. |
598 NOTREACHED(); | 638 NOTREACHED(); |
599 return gfx::Size(); | 639 return gfx::Size(); |
600 } | 640 } |
601 | 641 |
602 void OpaqueBrowserFrameViewLayout::ViewAdded(views::View* host, | 642 void OpaqueBrowserFrameViewLayout::ViewAdded(views::View* host, |
603 views::View* view) { | 643 views::View* view) { |
604 SetView(view->id(), view); | 644 SetView(view->id(), view); |
605 } | 645 } |
606 | 646 |
607 void OpaqueBrowserFrameViewLayout::ViewRemoved(views::View* host, | 647 void OpaqueBrowserFrameViewLayout::ViewRemoved(views::View* host, |
608 views::View* view) { | 648 views::View* view) { |
609 SetView(view->id(), NULL); | 649 SetView(view->id(), NULL); |
610 } | 650 } |
OLD | NEW |