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 "build/build_config.h" | 8 #include "build/build_config.h" |
9 #include "chrome/browser/profiles/profiles_state.h" | 9 #include "chrome/browser/profiles/profiles_state.h" |
10 #include "chrome/browser/ui/layout_constants.h" | 10 #include "chrome/browser/ui/layout_constants.h" |
(...skipping 24 matching lines...) Expand all Loading... |
35 | 35 |
36 // The titlebar has a 2 px 3D edge along the top and bottom. | 36 // The titlebar has a 2 px 3D edge along the top and bottom. |
37 const int kTitlebarTopAndBottomEdgeThickness = 2; | 37 const int kTitlebarTopAndBottomEdgeThickness = 2; |
38 | 38 |
39 // The icon is inset 2 px from the left frame border. | 39 // The icon is inset 2 px from the left frame border. |
40 const int kIconLeftSpacing = 2; | 40 const int kIconLeftSpacing = 2; |
41 | 41 |
42 // There is a 4 px gap between the icon and the title text. | 42 // There is a 4 px gap between the icon and the title text. |
43 const int kIconTitleSpacing = 4; | 43 const int kIconTitleSpacing = 4; |
44 | 44 |
45 // The avatar ends 2 px above the bottom of the tabstrip (which, given the | |
46 // way the tabstrip draws its bottom edge, will appear like a 1 px gap to the | |
47 // user). | |
48 const int kAvatarBottomSpacing = 2; | |
49 | |
50 // Space between the frame border and the edge of the avatar. | |
51 const int kAvatarOuterSpacing = 2; | |
52 | |
53 // Space between the edge of the avatar and the tabstrip. | 45 // Space between the edge of the avatar and the tabstrip. |
54 const int kAvatarInnerSpacing = 4; | 46 const int kAvatarInnerSpacing = 4; |
55 | 47 |
56 // How far the new avatar button is from the closest caption button. | 48 // How far the new avatar button is from the closest caption button. |
57 const int kNewAvatarButtonOffset = 5; | 49 const int kNewAvatarButtonOffset = 5; |
58 | 50 |
59 // When the title bar is in its normal two row mode (usually the case for | 51 // When the title bar is in its normal two row mode (usually the case for |
60 // restored windows), the New Tab button isn't at the same height as the caption | 52 // restored windows), the New Tab button isn't at the same height as the caption |
61 // buttons, but the space will look cluttered if it actually slides under them, | 53 // buttons, but the space will look cluttered if it actually slides under them, |
62 // so we stop it when the gap between the two is down to 5 px. | 54 // so we stop it when the gap between the two is down to 5 px. |
63 const int kNewTabCaptionNormalSpacing = 5; | 55 const int kNewTabCaptionNormalSpacing = 5; |
64 | 56 |
65 // When the title bar is condensed to one row (as when maximized), the New Tab | 57 // When the title bar is condensed to one row (as when maximized), the New Tab |
66 // button and the caption buttons are at similar vertical coordinates, so we | 58 // button and the caption buttons are at similar vertical coordinates, so we |
67 // need to reserve a larger, 16 px gap to avoid looking too cluttered. | 59 // need to reserve a larger, 16 px gap to avoid looking too cluttered. |
68 const int kNewTabCaptionCondensedSpacing = 16; | 60 const int kNewTabCaptionCondensedSpacing = 16; |
69 | 61 |
70 // If there are no caption buttons to the right of the New Tab button, we | 62 // If there are no caption buttons to the right of the New Tab button, we |
71 // reserve a small 5px gap, regardless of whether the window is maximized. This | 63 // reserve a small 5px gap, regardless of whether the window is maximized. This |
72 // overrides the two previous constants. | 64 // overrides the two previous constants. |
73 const int kNewTabNoCaptionButtonsSpacing = 5; | 65 const int kNewTabNoCaptionButtonsSpacing = 5; |
74 | 66 |
75 // The top 3 px of the tabstrip is shadow; in maximized mode we push this off | |
76 // the top of the screen so the tabs appear flush against the screen edge. | |
77 const int kTabstripTopShadowThickness = 3; | |
78 | |
79 // How far to indent the tabstrip from the left side of the screen when there | |
80 // is no avatar icon. | |
81 const int kTabStripIndent = -6; | |
82 | |
83 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | 67 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
84 // Default extra space between the top of the frame and the top of the window | 68 // Default extra space between the top of the frame and the top of the window |
85 // caption buttons. | 69 // caption buttons. |
86 const int kExtraCaption = 2; | 70 const int kExtraCaption = 2; |
87 | 71 |
88 // Default extra spacing between individual window caption buttons. | 72 // Default extra spacing between individual window caption buttons. |
89 const int kCaptionButtonSpacing = 2; | 73 const int kCaptionButtonSpacing = 2; |
90 #else | 74 #else |
91 const int kExtraCaption = 0; | 75 const int kExtraCaption = 0; |
92 const int kCaptionButtonSpacing = 0; | 76 const int kCaptionButtonSpacing = 0; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 void OpaqueBrowserFrameViewLayout::SetButtonOrdering( | 109 void OpaqueBrowserFrameViewLayout::SetButtonOrdering( |
126 const std::vector<views::FrameButton>& leading_buttons, | 110 const std::vector<views::FrameButton>& leading_buttons, |
127 const std::vector<views::FrameButton>& trailing_buttons) { | 111 const std::vector<views::FrameButton>& trailing_buttons) { |
128 leading_buttons_ = leading_buttons; | 112 leading_buttons_ = leading_buttons; |
129 trailing_buttons_ = trailing_buttons; | 113 trailing_buttons_ = trailing_buttons; |
130 } | 114 } |
131 | 115 |
132 gfx::Rect OpaqueBrowserFrameViewLayout::GetBoundsForTabStrip( | 116 gfx::Rect OpaqueBrowserFrameViewLayout::GetBoundsForTabStrip( |
133 const gfx::Size& tabstrip_preferred_size, | 117 const gfx::Size& tabstrip_preferred_size, |
134 int available_width) const { | 118 int available_width) const { |
135 available_width -= trailing_button_start_; | 119 int x = leading_button_start_ + GetLayoutInsets(AVATAR_ICON).right(); |
136 available_width -= leading_button_start_; | 120 available_width -= x + NewTabCaptionSpacing() + trailing_button_start_; |
137 | 121 gfx::Rect bounds(x, GetTabStripInsetsTop(false), std::max(0, available_width), |
138 const int caption_spacing = NewTabCaptionSpacing(); | |
139 const int tabstrip_width = available_width - caption_spacing; | |
140 gfx::Rect bounds(leading_button_start_, GetTabStripInsetsTop(false), | |
141 std::max(0, tabstrip_width), | |
142 tabstrip_preferred_size.height()); | 122 tabstrip_preferred_size.height()); |
143 | 123 |
144 int leading_tabstrip_indent = kTabStripIndent; | 124 if (delegate_->ShouldShowAvatar() && !ShouldIncognitoIconBeOnRight()) |
145 if (delegate_->ShouldShowAvatar() && !ShouldAvatarBeOnRight()) | 125 bounds.Inset(kAvatarInnerSpacing, 0, 0, 0); |
146 leading_tabstrip_indent += kAvatarInnerSpacing; | |
147 bounds.Inset(leading_tabstrip_indent, 0, 0, 0); | |
148 return bounds; | 126 return bounds; |
149 } | 127 } |
150 | 128 |
151 gfx::Size OpaqueBrowserFrameViewLayout::GetMinimumSize( | 129 gfx::Size OpaqueBrowserFrameViewLayout::GetMinimumSize( |
152 int available_width) const { | 130 int available_width) const { |
153 gfx::Size min_size = delegate_->GetBrowserViewMinimumSize(); | 131 gfx::Size min_size = delegate_->GetBrowserViewMinimumSize(); |
154 int border_thickness = NonClientBorderThickness(); | 132 int border_thickness = NonClientBorderThickness(); |
155 min_size.Enlarge(2 * border_thickness, | 133 min_size.Enlarge(2 * border_thickness, |
156 NonClientTopBorderHeight(false) + border_thickness); | 134 NonClientTopBorderHeight(false) + border_thickness); |
157 | 135 |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 bool OpaqueBrowserFrameViewLayout::IsTitleBarCondensed() const { | 236 bool OpaqueBrowserFrameViewLayout::IsTitleBarCondensed() const { |
259 // If there are no caption buttons, there is no need to have an uncondensed | 237 // If there are no caption buttons, there is no need to have an uncondensed |
260 // title bar. If the window is maximized, the title bar is condensed | 238 // title bar. If the window is maximized, the title bar is condensed |
261 // regardless of whether there are caption buttons. | 239 // regardless of whether there are caption buttons. |
262 return !delegate_->ShouldShowCaptionButtons() || delegate_->IsMaximized(); | 240 return !delegate_->ShouldShowCaptionButtons() || delegate_->IsMaximized(); |
263 } | 241 } |
264 | 242 |
265 /////////////////////////////////////////////////////////////////////////////// | 243 /////////////////////////////////////////////////////////////////////////////// |
266 // OpaqueBrowserFrameView, private: | 244 // OpaqueBrowserFrameView, private: |
267 | 245 |
268 bool OpaqueBrowserFrameViewLayout::ShouldAvatarBeOnRight() const { | 246 bool OpaqueBrowserFrameViewLayout::ShouldIncognitoIconBeOnRight() const { |
269 // The avatar should be shown either on the end of the left or the beginning | 247 // The incognito should be shown either on the end of the left or the |
270 // of the right depending on which side has fewer buttons. | 248 // beginning of the right, depending on which side has fewer buttons. |
271 return trailing_buttons_.size() < leading_buttons_.size(); | 249 return trailing_buttons_.size() < leading_buttons_.size(); |
272 } | 250 } |
273 | 251 |
274 int OpaqueBrowserFrameViewLayout::NewTabCaptionSpacing() const { | 252 int OpaqueBrowserFrameViewLayout::NewTabCaptionSpacing() const { |
275 if (!has_trailing_buttons_) | 253 if (!has_trailing_buttons_) |
276 return kNewTabNoCaptionButtonsSpacing; | 254 return kNewTabNoCaptionButtonsSpacing; |
277 return IsTitleBarCondensed() ? | 255 return IsTitleBarCondensed() ? |
278 kNewTabCaptionCondensedSpacing : kNewTabCaptionNormalSpacing; | 256 kNewTabCaptionCondensedSpacing : kNewTabCaptionNormalSpacing; |
279 } | 257 } |
280 | 258 |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 // the avatar button. | 376 // the avatar button. |
399 if (!IsTitleBarCondensed()) { | 377 if (!IsTitleBarCondensed()) { |
400 trailing_button_start_ -= | 378 trailing_button_start_ -= |
401 GetLayoutSize(NEW_TAB_BUTTON).width() + kNewTabCaptionNormalSpacing; | 379 GetLayoutSize(NEW_TAB_BUTTON).width() + kNewTabCaptionNormalSpacing; |
402 } | 380 } |
403 | 381 |
404 new_avatar_button_->SetBounds(button_x, button_y, button_width, | 382 new_avatar_button_->SetBounds(button_x, button_y, button_width, |
405 kCaptionButtonHeight); | 383 kCaptionButtonHeight); |
406 } | 384 } |
407 | 385 |
408 void OpaqueBrowserFrameViewLayout::LayoutAvatar(views::View* host) { | 386 void OpaqueBrowserFrameViewLayout::LayoutIncognitoIcon(views::View* host) { |
409 // Even though the avatar is used for both incognito and profiles we always | 387 const int old_button_size = leading_button_start_ + trailing_button_start_; |
410 // use the incognito icon to layout the avatar button. The profile icon | |
411 // can be customized so we can't depend on its size to perform layout. | |
412 gfx::ImageSkia incognito_icon = delegate_->GetOTRAvatarIcon(); | |
413 | 388 |
414 bool avatar_on_right = ShouldAvatarBeOnRight(); | |
415 int avatar_bottom = GetTabStripInsetsTop(false) + | |
416 delegate_->GetTabStripHeight() - kAvatarBottomSpacing; | |
417 int avatar_restored_y = avatar_bottom - incognito_icon.height(); | |
418 int avatar_x = avatar_on_right ? | |
419 host->width() - trailing_button_start_ - kAvatarOuterSpacing - | |
420 incognito_icon.width() : | |
421 leading_button_start_ + kAvatarOuterSpacing; | |
422 int avatar_y = IsTitleBarCondensed() ? | |
423 (NonClientTopBorderHeight(false) + kTabstripTopShadowThickness) : | |
424 avatar_restored_y; | |
425 avatar_bounds_.SetRect( | |
426 avatar_x, | |
427 avatar_y, | |
428 incognito_icon.width(), | |
429 delegate_->ShouldShowAvatar() ? (avatar_bottom - avatar_y) : 0); | |
430 if (avatar_button_) { | 389 if (avatar_button_) { |
431 avatar_button_->SetBoundsRect(avatar_bounds_); | 390 const gfx::Insets insets(GetLayoutInsets(AVATAR_ICON)); |
| 391 const gfx::Size size(delegate_->GetOTRAvatarIcon().size()); |
| 392 const int incognito_width = insets.left() + size.width(); |
| 393 int x; |
| 394 if (ShouldIncognitoIconBeOnRight()) { |
| 395 trailing_button_start_ += incognito_width; |
| 396 x = host->width() - trailing_button_start_; |
| 397 } else { |
| 398 x = leading_button_start_ + insets.left(); |
| 399 leading_button_start_ += incognito_width; |
| 400 } |
| 401 const int bottom = GetTabStripInsetsTop(false) + |
| 402 delegate_->GetTabStripHeight() - insets.bottom(); |
| 403 int y = IsTitleBarCondensed() ? |
| 404 FrameBorderThickness(false) : (bottom - size.height()); |
| 405 avatar_button_->SetBounds(x, y, size.width(), bottom - y); |
| 406 } |
432 | 407 |
433 int edge_offset = kAvatarOuterSpacing + incognito_icon.width(); | 408 minimum_size_for_buttons_ += |
434 if (avatar_on_right) | 409 (leading_button_start_ + trailing_button_start_ - old_button_size); |
435 trailing_button_start_ += edge_offset; | |
436 else | |
437 leading_button_start_ += edge_offset; | |
438 | |
439 // We just add the avatar button size to the minimum size because clicking | |
440 // the avatar label does the same thing as clicking the avatar button. | |
441 minimum_size_for_buttons_ += kAvatarOuterSpacing + incognito_icon.width(); | |
442 } | |
443 } | 410 } |
444 | 411 |
445 void OpaqueBrowserFrameViewLayout::ConfigureButton( | 412 void OpaqueBrowserFrameViewLayout::ConfigureButton( |
446 views::View* host, | 413 views::View* host, |
447 views::FrameButton button_id, | 414 views::FrameButton button_id, |
448 ButtonAlignment alignment, | 415 ButtonAlignment alignment, |
449 int caption_y) { | 416 int caption_y) { |
450 switch (button_id) { | 417 switch (button_id) { |
451 case views::FRAME_BUTTON_MINIMIZE: { | 418 case views::FRAME_BUTTON_MINIMIZE: { |
452 minimize_button_->SetVisible(true); | 419 minimize_button_->SetVisible(true); |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
640 LayoutTitleBar(host); | 607 LayoutTitleBar(host); |
641 | 608 |
642 // We now add a single pixel to the leading spacing. We do this because the | 609 // We now add a single pixel to the leading spacing. We do this because the |
643 // avatar and tab strip start one pixel inward compared to where things start | 610 // avatar and tab strip start one pixel inward compared to where things start |
644 // on the trailing side. | 611 // on the trailing side. |
645 leading_button_start_++; | 612 leading_button_start_++; |
646 | 613 |
647 if (delegate_->IsRegularOrGuestSession()) | 614 if (delegate_->IsRegularOrGuestSession()) |
648 LayoutNewStyleAvatar(host); | 615 LayoutNewStyleAvatar(host); |
649 else | 616 else |
650 LayoutAvatar(host); | 617 LayoutIncognitoIcon(host); |
651 | 618 |
652 client_view_bounds_ = CalculateClientAreaBounds( | 619 client_view_bounds_ = CalculateClientAreaBounds( |
653 host->width(), host->height()); | 620 host->width(), host->height()); |
654 } | 621 } |
655 | 622 |
656 gfx::Size OpaqueBrowserFrameViewLayout::GetPreferredSize( | 623 gfx::Size OpaqueBrowserFrameViewLayout::GetPreferredSize( |
657 const views::View* host) const { | 624 const views::View* host) const { |
658 // This is never used; NonClientView::GetPreferredSize() will be called | 625 // This is never used; NonClientView::GetPreferredSize() will be called |
659 // instead. | 626 // instead. |
660 NOTREACHED(); | 627 NOTREACHED(); |
661 return gfx::Size(); | 628 return gfx::Size(); |
662 } | 629 } |
663 | 630 |
664 void OpaqueBrowserFrameViewLayout::ViewAdded(views::View* host, | 631 void OpaqueBrowserFrameViewLayout::ViewAdded(views::View* host, |
665 views::View* view) { | 632 views::View* view) { |
666 SetView(view->id(), view); | 633 SetView(view->id(), view); |
667 } | 634 } |
668 | 635 |
669 void OpaqueBrowserFrameViewLayout::ViewRemoved(views::View* host, | 636 void OpaqueBrowserFrameViewLayout::ViewRemoved(views::View* host, |
670 views::View* view) { | 637 views::View* view) { |
671 SetView(view->id(), nullptr); | 638 SetView(view->id(), nullptr); |
672 } | 639 } |
OLD | NEW |