Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(60)

Side by Side Diff: chrome/browser/ui/views/frame/opaque_browser_frame_view_layout.cc

Issue 1972033002: Simplify some old avatar menu button code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: reinstate ash browser test fix Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
11 #include "chrome/browser/ui/views/profiles/avatar_menu_button.h" 11 #include "chrome/browser/ui/views/profiles/profile_indicator_icon.h"
12 #include "chrome/common/chrome_switches.h" 12 #include "chrome/common/chrome_switches.h"
13 #include "components/signin/core/common/profile_management_switches.h" 13 #include "components/signin/core/common/profile_management_switches.h"
14 #include "ui/base/material_design/material_design_controller.h" 14 #include "ui/base/material_design/material_design_controller.h"
15 #include "ui/gfx/font.h" 15 #include "ui/gfx/font.h"
16 #include "ui/views/controls/button/image_button.h" 16 #include "ui/views/controls/button/image_button.h"
17 #include "ui/views/controls/label.h" 17 #include "ui/views/controls/label.h"
18 18
19 namespace { 19 namespace {
20 20
21 const int kCaptionButtonHeight = 18; 21 const int kCaptionButtonHeight = 18;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 65
66 // The minimum vertical padding between the bottom of the caption buttons and 66 // The minimum vertical padding between the bottom of the caption buttons and
67 // the top of the content shadow. 67 // the top of the content shadow.
68 const int OpaqueBrowserFrameViewLayout::kCaptionButtonBottomPadding = 3; 68 const int OpaqueBrowserFrameViewLayout::kCaptionButtonBottomPadding = 3;
69 69
70 // When the title bar is condensed to one row (as when maximized), the New Tab 70 // When the title bar is condensed to one row (as when maximized), the New Tab
71 // button and the caption buttons are at similar vertical coordinates, so we 71 // button and the caption buttons are at similar vertical coordinates, so we
72 // need to reserve a larger, 16 px gap to avoid looking too cluttered. 72 // need to reserve a larger, 16 px gap to avoid looking too cluttered.
73 const int OpaqueBrowserFrameViewLayout::kNewTabCaptionCondensedSpacing = 16; 73 const int OpaqueBrowserFrameViewLayout::kNewTabCaptionCondensedSpacing = 16;
74 74
75
76 OpaqueBrowserFrameViewLayout::OpaqueBrowserFrameViewLayout( 75 OpaqueBrowserFrameViewLayout::OpaqueBrowserFrameViewLayout(
77 OpaqueBrowserFrameViewLayoutDelegate* delegate) 76 OpaqueBrowserFrameViewLayoutDelegate* delegate)
78 : delegate_(delegate), 77 : delegate_(delegate),
79 leading_button_start_(0), 78 leading_button_start_(0),
80 trailing_button_start_(0), 79 trailing_button_start_(0),
81 minimum_size_for_buttons_(0), 80 minimum_size_for_buttons_(0),
82 has_leading_buttons_(false), 81 has_leading_buttons_(false),
83 has_trailing_buttons_(false), 82 has_trailing_buttons_(false),
84 extra_caption_y_(kExtraCaption), 83 extra_caption_y_(kExtraCaption),
85 window_caption_spacing_(kCaptionButtonSpacing), 84 window_caption_spacing_(kCaptionButtonSpacing),
86 minimize_button_(nullptr), 85 minimize_button_(nullptr),
87 maximize_button_(nullptr), 86 maximize_button_(nullptr),
88 restore_button_(nullptr), 87 restore_button_(nullptr),
89 close_button_(nullptr), 88 close_button_(nullptr),
90 window_icon_(nullptr), 89 window_icon_(nullptr),
91 window_title_(nullptr), 90 window_title_(nullptr),
92 avatar_button_(nullptr), 91 incognito_icon_(nullptr),
93 new_avatar_button_(nullptr) { 92 new_avatar_button_(nullptr) {
94 trailing_buttons_.push_back(views::FRAME_BUTTON_MINIMIZE); 93 trailing_buttons_.push_back(views::FRAME_BUTTON_MINIMIZE);
95 trailing_buttons_.push_back(views::FRAME_BUTTON_MAXIMIZE); 94 trailing_buttons_.push_back(views::FRAME_BUTTON_MAXIMIZE);
96 trailing_buttons_.push_back(views::FRAME_BUTTON_CLOSE); 95 trailing_buttons_.push_back(views::FRAME_BUTTON_CLOSE);
97 } 96 }
98 97
99 OpaqueBrowserFrameViewLayout::~OpaqueBrowserFrameViewLayout() {} 98 OpaqueBrowserFrameViewLayout::~OpaqueBrowserFrameViewLayout() {}
100 99
101 void OpaqueBrowserFrameViewLayout::SetButtonOrdering( 100 void OpaqueBrowserFrameViewLayout::SetButtonOrdering(
102 const std::vector<views::FrameButton>& leading_buttons, 101 const std::vector<views::FrameButton>& leading_buttons,
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 void OpaqueBrowserFrameViewLayout::LayoutIncognitoIcon(views::View* host) { 366 void OpaqueBrowserFrameViewLayout::LayoutIncognitoIcon(views::View* host) {
368 const int old_button_size = leading_button_start_ + trailing_button_start_; 367 const int old_button_size = leading_button_start_ + trailing_button_start_;
369 368
370 // Any buttons/icon/title were laid out based on the frame border thickness, 369 // Any buttons/icon/title were laid out based on the frame border thickness,
371 // but the tabstrip bounds need to be based on the non-client border thickness 370 // but the tabstrip bounds need to be based on the non-client border thickness
372 // on any side where there aren't other buttons forcing a larger inset. 371 // on any side where there aren't other buttons forcing a larger inset.
373 const bool md = ui::MaterialDesignController::IsModeMaterial(); 372 const bool md = ui::MaterialDesignController::IsModeMaterial();
374 int min_button_width = NonClientBorderThickness(); 373 int min_button_width = NonClientBorderThickness();
375 // In non-MD, the toolbar has a rounded corner that we don't want the tabstrip 374 // In non-MD, the toolbar has a rounded corner that we don't want the tabstrip
376 // to overlap. 375 // to overlap.
377 if (!md && !avatar_button_ && delegate_->IsToolbarVisible()) 376 if (!md && !incognito_icon_ && delegate_->IsToolbarVisible())
378 min_button_width += delegate_->GetToolbarLeadingCornerClientWidth(); 377 min_button_width += delegate_->GetToolbarLeadingCornerClientWidth();
379 leading_button_start_ = std::max(leading_button_start_, min_button_width); 378 leading_button_start_ = std::max(leading_button_start_, min_button_width);
380 // The trailing corner is a mirror of the leading one. 379 // The trailing corner is a mirror of the leading one.
381 trailing_button_start_ = std::max(trailing_button_start_, min_button_width); 380 trailing_button_start_ = std::max(trailing_button_start_, min_button_width);
382 381
383 if (avatar_button_) { 382 if (incognito_icon_) {
384 const gfx::Insets insets(GetLayoutInsets(AVATAR_ICON)); 383 const gfx::Insets insets(GetLayoutInsets(AVATAR_ICON));
385 const gfx::Size size(delegate_->GetOTRAvatarIcon().size()); 384 const gfx::Size size(delegate_->GetOTRAvatarIcon().size());
386 const int incognito_width = insets.left() + size.width(); 385 const int incognito_width = insets.left() + size.width();
387 int x; 386 int x;
388 if (ShouldIncognitoIconBeOnRight()) { 387 if (ShouldIncognitoIconBeOnRight()) {
389 trailing_button_start_ += incognito_width; 388 trailing_button_start_ += incognito_width;
390 x = host->width() - trailing_button_start_; 389 x = host->width() - trailing_button_start_;
391 } else { 390 } else {
392 x = leading_button_start_ + insets.left(); 391 x = leading_button_start_ + insets.left();
393 leading_button_start_ += incognito_width; 392 leading_button_start_ += incognito_width;
394 } 393 }
395 const int bottom = GetTabStripInsetsTop(false) + 394 const int bottom = GetTabStripInsetsTop(false) +
396 delegate_->GetTabStripHeight() - insets.bottom(); 395 delegate_->GetTabStripHeight() - insets.bottom();
397 const int y = (md || !IsTitleBarCondensed()) ? 396 const int y = (md || !IsTitleBarCondensed()) ?
398 (bottom - size.height()) : FrameBorderThickness(false); 397 (bottom - size.height()) : FrameBorderThickness(false);
399 avatar_button_->SetBounds(x, y, size.width(), bottom - y); 398 incognito_icon_->SetBounds(x, y, size.width(), bottom - y);
400 } 399 }
401 400
402 minimum_size_for_buttons_ += 401 minimum_size_for_buttons_ +=
403 (leading_button_start_ + trailing_button_start_ - old_button_size); 402 (leading_button_start_ + trailing_button_start_ - old_button_size);
404 } 403 }
405 404
406 void OpaqueBrowserFrameViewLayout::ConfigureButton( 405 void OpaqueBrowserFrameViewLayout::ConfigureButton(
407 views::View* host, 406 views::View* host,
408 views::FrameButton button_id, 407 views::FrameButton button_id,
409 ButtonAlignment alignment, 408 ButtonAlignment alignment,
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 case VIEW_ID_WINDOW_ICON: 561 case VIEW_ID_WINDOW_ICON:
563 window_icon_ = view; 562 window_icon_ = view;
564 break; 563 break;
565 case VIEW_ID_WINDOW_TITLE: 564 case VIEW_ID_WINDOW_TITLE:
566 if (view) { 565 if (view) {
567 DCHECK_EQ(std::string(views::Label::kViewClassName), 566 DCHECK_EQ(std::string(views::Label::kViewClassName),
568 view->GetClassName()); 567 view->GetClassName());
569 } 568 }
570 window_title_ = static_cast<views::Label*>(view); 569 window_title_ = static_cast<views::Label*>(view);
571 break; 570 break;
571 case VIEW_ID_PROFILE_INDICATOR_ICON:
572 incognito_icon_ = view;
573 break;
572 case VIEW_ID_AVATAR_BUTTON: 574 case VIEW_ID_AVATAR_BUTTON:
573 if (view) {
574 DCHECK_EQ(std::string(AvatarMenuButton::kViewClassName),
575 view->GetClassName());
576 }
577 avatar_button_ = static_cast<AvatarMenuButton*>(view);
578 break;
579 case VIEW_ID_NEW_AVATAR_BUTTON:
580 new_avatar_button_ = view; 575 new_avatar_button_ = view;
581 break; 576 break;
582 default: 577 default:
583 NOTIMPLEMENTED() << "Unknown view id " << id; 578 NOTIMPLEMENTED() << "Unknown view id " << id;
584 break; 579 break;
585 } 580 }
586 } 581 }
587 582
588 /////////////////////////////////////////////////////////////////////////////// 583 ///////////////////////////////////////////////////////////////////////////////
589 // OpaqueBrowserFrameView, views::LayoutManager: 584 // OpaqueBrowserFrameView, views::LayoutManager:
(...skipping 28 matching lines...) Expand all
618 613
619 void OpaqueBrowserFrameViewLayout::ViewAdded(views::View* host, 614 void OpaqueBrowserFrameViewLayout::ViewAdded(views::View* host,
620 views::View* view) { 615 views::View* view) {
621 SetView(view->id(), view); 616 SetView(view->id(), view);
622 } 617 }
623 618
624 void OpaqueBrowserFrameViewLayout::ViewRemoved(views::View* host, 619 void OpaqueBrowserFrameViewLayout::ViewRemoved(views::View* host,
625 views::View* view) { 620 views::View* view) {
626 SetView(view->id(), nullptr); 621 SetView(view->id(), nullptr);
627 } 622 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698