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

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

Issue 1972033002: Simplify some old avatar menu button code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix test 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/browser_non_client_frame_view_mus.h" 5 #include "chrome/browser/ui/views/frame/browser_non_client_frame_view_mus.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "chrome/app/chrome_command_ids.h" 9 #include "chrome/app/chrome_command_ids.h"
10 #include "chrome/browser/extensions/extension_util.h" 10 #include "chrome/browser/extensions/extension_util.h"
11 #include "chrome/browser/profiles/profiles_state.h" 11 #include "chrome/browser/profiles/profiles_state.h"
12 #include "chrome/browser/themes/theme_properties.h" 12 #include "chrome/browser/themes/theme_properties.h"
13 #include "chrome/browser/ui/browser.h" 13 #include "chrome/browser/ui/browser.h"
14 #include "chrome/browser/ui/browser_commands.h" 14 #include "chrome/browser/ui/browser_commands.h"
15 #include "chrome/browser/ui/layout_constants.h" 15 #include "chrome/browser/ui/layout_constants.h"
16 #include "chrome/browser/ui/views/frame/browser_frame.h" 16 #include "chrome/browser/ui/views/frame/browser_frame.h"
17 #include "chrome/browser/ui/views/frame/browser_frame_mus.h" 17 #include "chrome/browser/ui/views/frame/browser_frame_mus.h"
18 #include "chrome/browser/ui/views/frame/browser_header_painter_ash.h" 18 #include "chrome/browser/ui/views/frame/browser_header_painter_ash.h"
19 #include "chrome/browser/ui/views/frame/browser_view.h" 19 #include "chrome/browser/ui/views/frame/browser_view.h"
20 #include "chrome/browser/ui/views/frame/immersive_mode_controller.h" 20 #include "chrome/browser/ui/views/frame/immersive_mode_controller.h"
21 #include "chrome/browser/ui/views/frame/web_app_left_header_view_ash.h" 21 #include "chrome/browser/ui/views/frame/web_app_left_header_view_ash.h"
22 #include "chrome/browser/ui/views/profiles/avatar_menu_button.h" 22 #include "chrome/browser/ui/views/profiles/profile_indicator_icon.h"
23 #include "chrome/browser/ui/views/tab_icon_view.h" 23 #include "chrome/browser/ui/views/tab_icon_view.h"
24 #include "chrome/browser/ui/views/tabs/tab_strip.h" 24 #include "chrome/browser/ui/views/tabs/tab_strip.h"
25 #include "chrome/browser/web_applications/web_app.h" 25 #include "chrome/browser/web_applications/web_app.h"
26 #include "components/mus/public/cpp/window.h" 26 #include "components/mus/public/cpp/window.h"
27 #include "components/signin/core/common/profile_management_switches.h" 27 #include "components/signin/core/common/profile_management_switches.h"
28 #include "content/public/browser/web_contents.h" 28 #include "content/public/browser/web_contents.h"
29 #include "extensions/browser/extension_registry.h" 29 #include "extensions/browser/extension_registry.h"
30 #include "grit/theme_resources.h" 30 #include "grit/theme_resources.h"
31 #include "ui/accessibility/ax_view_state.h" 31 #include "ui/accessibility/ax_view_state.h"
32 #include "ui/aura/client/aura_constants.h" 32 #include "ui/aura/client/aura_constants.h"
(...skipping 15 matching lines...) Expand all
48 #include "ui/views/widget/widget_delegate.h" 48 #include "ui/views/widget/widget_delegate.h"
49 49
50 #if !defined(OS_CHROMEOS) 50 #if !defined(OS_CHROMEOS)
51 #define FRAME_AVATAR_BUTTON 51 #define FRAME_AVATAR_BUTTON
52 #endif 52 #endif
53 53
54 namespace { 54 namespace {
55 55
56 #if defined(FRAME_AVATAR_BUTTON) 56 #if defined(FRAME_AVATAR_BUTTON)
57 // Space between the new avatar button and the minimize button. 57 // Space between the new avatar button and the minimize button.
58 const int kNewAvatarButtonOffset = 5; 58 const int kAvatarButtonOffset = 5;
59 #endif 59 #endif
60 // Space between right edge of tabstrip and maximize button. 60 // Space between right edge of tabstrip and maximize button.
61 const int kTabstripRightSpacing = 10; 61 const int kTabstripRightSpacing = 10;
62 // Height of the shadow of the content area, at the top of the toolbar. 62 // Height of the shadow of the content area, at the top of the toolbar.
63 const int kContentShadowHeight = 1; 63 const int kContentShadowHeight = 1;
64 // Space between top of window and top of tabstrip for tall headers, such as 64 // Space between top of window and top of tabstrip for tall headers, such as
65 // for restored windows, apps, etc. 65 // for restored windows, apps, etc.
66 const int kTabstripTopSpacingTall = 4; 66 const int kTabstripTopSpacingTall = 4;
67 // Space between top of window and top of tabstrip for short headers, such as 67 // Space between top of window and top of tabstrip for short headers, such as
68 // for maximized windows, pop-ups, etc. 68 // for maximized windows, pop-ups, etc.
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 return; 271 return;
272 } 272 }
273 273
274 if (browser_view()->IsToolbarVisible()) 274 if (browser_view()->IsToolbarVisible())
275 PaintToolbarBackground(canvas); 275 PaintToolbarBackground(canvas);
276 else if (!UsePackagedAppHeaderStyle() && !UseWebAppHeaderStyle()) 276 else if (!UsePackagedAppHeaderStyle() && !UseWebAppHeaderStyle())
277 PaintContentEdge(canvas); 277 PaintContentEdge(canvas);
278 } 278 }
279 279
280 void BrowserNonClientFrameViewMus::Layout() { 280 void BrowserNonClientFrameViewMus::Layout() {
281 if (avatar_button()) 281 if (profile_indicator())
282 LayoutIncognitoButton(); 282 LayoutIncognitoButton();
283 283
284 #if defined(FRAME_AVATAR_BUTTON) 284 #if defined(FRAME_AVATAR_BUTTON)
285 if (profile_switcher_.view()) 285 if (profile_switcher_.view())
286 LayoutProfileSwitcher(); 286 LayoutProfileSwitcher();
287 #endif 287 #endif
288 288
289 BrowserNonClientFrameView::Layout(); 289 BrowserNonClientFrameView::Layout();
290 290
291 UpdateClientArea(); 291 UpdateClientArea();
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 gfx::ImageSkia BrowserNonClientFrameViewMus::GetFaviconForTabIconView() { 330 gfx::ImageSkia BrowserNonClientFrameViewMus::GetFaviconForTabIconView() {
331 views::WidgetDelegate* delegate = frame()->widget_delegate(); 331 views::WidgetDelegate* delegate = frame()->widget_delegate();
332 if (!delegate) 332 if (!delegate)
333 return gfx::ImageSkia(); 333 return gfx::ImageSkia();
334 return delegate->GetWindowIcon(); 334 return delegate->GetWindowIcon();
335 } 335 }
336 /////////////////////////////////////////////////////////////////////////////// 336 ///////////////////////////////////////////////////////////////////////////////
337 // BrowserNonClientFrameViewMus, protected: 337 // BrowserNonClientFrameViewMus, protected:
338 338
339 // BrowserNonClientFrameView: 339 // BrowserNonClientFrameView:
340 void BrowserNonClientFrameViewMus::UpdateAvatar() { 340 void BrowserNonClientFrameViewMus::UpdateProfileIcons() {
341 #if defined(FRAME_AVATAR_BUTTON) 341 #if defined(FRAME_AVATAR_BUTTON)
342 if (browser_view()->IsRegularOrGuestSession()) 342 if (browser_view()->IsRegularOrGuestSession())
343 profile_switcher_.Update(AvatarButtonStyle::NATIVE); 343 profile_switcher_.Update(AvatarButtonStyle::NATIVE);
344 else 344 else
345 #endif 345 #endif
346 UpdateOldAvatarButton(); 346 UpdateProfileIndicatorIcon();
347 } 347 }
348 348
349 /////////////////////////////////////////////////////////////////////////////// 349 ///////////////////////////////////////////////////////////////////////////////
350 // BrowserNonClientFrameViewMus, private: 350 // BrowserNonClientFrameViewMus, private:
351 351
352 mus::Window* BrowserNonClientFrameViewMus::mus_window() { 352 mus::Window* BrowserNonClientFrameViewMus::mus_window() {
353 return static_cast<BrowserFrameMus*>(frame()->native_widget())->window(); 353 return static_cast<BrowserFrameMus*>(frame()->native_widget())->window();
354 } 354 }
355 355
356 void BrowserNonClientFrameViewMus::UpdateClientArea() { 356 void BrowserNonClientFrameViewMus::UpdateClientArea() {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 const gfx::Rect rect_in_tabstrip_coords = 399 const gfx::Rect rect_in_tabstrip_coords =
400 gfx::ToEnclosingRect(rect_in_tabstrip_coords_f); 400 gfx::ToEnclosingRect(rect_in_tabstrip_coords_f);
401 return (rect_in_tabstrip_coords.y() <= tabstrip->height()) && 401 return (rect_in_tabstrip_coords.y() <= tabstrip->height()) &&
402 (!tabstrip->HitTestRect(rect_in_tabstrip_coords) || 402 (!tabstrip->HitTestRect(rect_in_tabstrip_coords) ||
403 tabstrip->IsRectInWindowCaption(rect_in_tabstrip_coords)); 403 tabstrip->IsRectInWindowCaption(rect_in_tabstrip_coords));
404 } 404 }
405 405
406 int BrowserNonClientFrameViewMus::GetTabStripLeftInset() const { 406 int BrowserNonClientFrameViewMus::GetTabStripLeftInset() const {
407 const gfx::Insets insets(GetLayoutInsets(AVATAR_ICON)); 407 const gfx::Insets insets(GetLayoutInsets(AVATAR_ICON));
408 const int avatar_right = 408 const int avatar_right =
409 avatar_button() ? (insets.left() + GetOTRAvatarIcon().width()) : 0; 409 profile_indicator() ? (insets.left() + GetOTRAvatarIcon().width()) : 0;
410 return avatar_right + insets.right() + frame_values().normal_insets.left(); 410 return avatar_right + insets.right() + frame_values().normal_insets.left();
411 } 411 }
412 412
413 int BrowserNonClientFrameViewMus::GetTabStripRightInset() const { 413 int BrowserNonClientFrameViewMus::GetTabStripRightInset() const {
414 const int frame_right_insets = frame_values().normal_insets.right() + 414 const int frame_right_insets = frame_values().normal_insets.right() +
415 frame_values().max_title_bar_button_width; 415 frame_values().max_title_bar_button_width;
416 int right_inset = kTabstripRightSpacing + frame_right_insets; 416 int right_inset = kTabstripRightSpacing + frame_right_insets;
417 417
418 #if defined(FRAME_AVATAR_BUTTON) 418 #if defined(FRAME_AVATAR_BUTTON)
419 if (profile_switcher_.view()) { 419 if (profile_switcher_.view()) {
420 right_inset += kNewAvatarButtonOffset + 420 right_inset += kAvatarButtonOffset +
421 profile_switcher_.view()->GetPreferredSize().width(); 421 profile_switcher_.view()->GetPreferredSize().width();
422 } 422 }
423 #endif 423 #endif
424 424
425 return right_inset; 425 return right_inset;
426 } 426 }
427 427
428 bool BrowserNonClientFrameViewMus::UseImmersiveLightbarHeaderStyle() const { 428 bool BrowserNonClientFrameViewMus::UseImmersiveLightbarHeaderStyle() const {
429 ImmersiveModeController* immersive_controller = 429 ImmersiveModeController* immersive_controller =
430 browser_view()->immersive_mode_controller(); 430 browser_view()->immersive_mode_controller();
(...skipping 12 matching lines...) Expand all
443 // style. 443 // style.
444 return browser->is_app() && !UseWebAppHeaderStyle(); 444 return browser->is_app() && !UseWebAppHeaderStyle();
445 } 445 }
446 446
447 bool BrowserNonClientFrameViewMus::UseWebAppHeaderStyle() const { 447 bool BrowserNonClientFrameViewMus::UseWebAppHeaderStyle() const {
448 return browser_view()->browser()->SupportsWindowFeature( 448 return browser_view()->browser()->SupportsWindowFeature(
449 Browser::FEATURE_WEBAPPFRAME); 449 Browser::FEATURE_WEBAPPFRAME);
450 } 450 }
451 451
452 void BrowserNonClientFrameViewMus::LayoutIncognitoButton() { 452 void BrowserNonClientFrameViewMus::LayoutIncognitoButton() {
453 DCHECK(avatar_button()); 453 DCHECK(profile_indicator());
454 #if !defined(OS_CHROMEOS) 454 #if !defined(OS_CHROMEOS)
455 // ChromeOS shows avatar on V1 app. 455 // ChromeOS shows avatar on V1 app.
456 DCHECK(browser_view()->IsTabStripVisible()); 456 DCHECK(browser_view()->IsTabStripVisible());
457 #endif 457 #endif
458 gfx::ImageSkia incognito_icon = GetOTRAvatarIcon(); 458 gfx::ImageSkia incognito_icon = GetOTRAvatarIcon();
459 gfx::Insets avatar_insets = GetLayoutInsets(AVATAR_ICON); 459 gfx::Insets avatar_insets = GetLayoutInsets(AVATAR_ICON);
460 int avatar_bottom = GetTopInset(false) + browser_view()->GetTabStripHeight() - 460 int avatar_bottom = GetTopInset(false) + browser_view()->GetTabStripHeight() -
461 avatar_insets.bottom(); 461 avatar_insets.bottom();
462 int avatar_y = avatar_bottom - incognito_icon.height(); 462 int avatar_y = avatar_bottom - incognito_icon.height();
463 if (!ui::MaterialDesignController::IsModeMaterial() && 463 if (!ui::MaterialDesignController::IsModeMaterial() &&
464 browser_view()->IsTabStripVisible() && 464 browser_view()->IsTabStripVisible() &&
465 (frame()->IsMaximized() || frame()->IsFullscreen())) { 465 (frame()->IsMaximized() || frame()->IsFullscreen())) {
466 avatar_y = GetTopInset(false) + kContentShadowHeight; 466 avatar_y = GetTopInset(false) + kContentShadowHeight;
467 } 467 }
468 468
469 // Hide the incognito icon in immersive fullscreen when the tab light bar is 469 // Hide the incognito icon in immersive fullscreen when the tab light bar is
470 // visible because the header is too short for the icognito icon to be 470 // visible because the header is too short for the icognito icon to be
471 // recognizable. 471 // recognizable.
472 bool avatar_visible = !UseImmersiveLightbarHeaderStyle(); 472 bool avatar_visible = !UseImmersiveLightbarHeaderStyle();
473 int avatar_height = avatar_visible ? avatar_bottom - avatar_y : 0; 473 int avatar_height = avatar_visible ? avatar_bottom - avatar_y : 0;
474 474
475 gfx::Rect avatar_bounds(avatar_insets.left(), avatar_y, 475 gfx::Rect avatar_bounds(avatar_insets.left(), avatar_y,
476 incognito_icon.width(), avatar_height); 476 incognito_icon.width(), avatar_height);
477 avatar_button()->SetBoundsRect(avatar_bounds); 477 profile_indicator()->SetBoundsRect(avatar_bounds);
478 avatar_button()->SetVisible(avatar_visible); 478 profile_indicator()->SetVisible(avatar_visible);
479 } 479 }
480 480
481 void BrowserNonClientFrameViewMus::LayoutProfileSwitcher() { 481 void BrowserNonClientFrameViewMus::LayoutProfileSwitcher() {
482 #if defined(FRAME_AVATAR_BUTTON) 482 #if defined(FRAME_AVATAR_BUTTON)
483 gfx::Size button_size = profile_switcher_.view()->GetPreferredSize(); 483 gfx::Size button_size = profile_switcher_.view()->GetPreferredSize();
484 int button_x = width() - GetTabStripRightInset() + kNewAvatarButtonOffset; 484 int button_x = width() - GetTabStripRightInset() + kAvatarButtonOffset;
485 profile_switcher_.view()->SetBounds(button_x, 0, button_size.width(), 485 profile_switcher_.view()->SetBounds(button_x, 0, button_size.width(),
486 button_size.height()); 486 button_size.height());
487 #endif 487 #endif
488 } 488 }
489 489
490 bool BrowserNonClientFrameViewMus::ShouldPaint() const { 490 bool BrowserNonClientFrameViewMus::ShouldPaint() const {
491 if (!frame()->IsFullscreen()) 491 if (!frame()->IsFullscreen())
492 return true; 492 return true;
493 493
494 // We need to paint when in immersive fullscreen and either: 494 // We need to paint when in immersive fullscreen and either:
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 } 616 }
617 617
618 void BrowserNonClientFrameViewMus::PaintContentEdge(gfx::Canvas* canvas) { 618 void BrowserNonClientFrameViewMus::PaintContentEdge(gfx::Canvas* canvas) {
619 DCHECK(!UsePackagedAppHeaderStyle() && !UseWebAppHeaderStyle()); 619 DCHECK(!UsePackagedAppHeaderStyle() && !UseWebAppHeaderStyle());
620 const int bottom = frame_values().normal_insets.bottom(); 620 const int bottom = frame_values().normal_insets.bottom();
621 canvas->FillRect( 621 canvas->FillRect(
622 gfx::Rect(0, bottom, width(), kClientEdgeThickness), 622 gfx::Rect(0, bottom, width(), kClientEdgeThickness),
623 GetThemeProvider()->GetColor( 623 GetThemeProvider()->GetColor(
624 ThemeProperties::COLOR_TOOLBAR_BOTTOM_SEPARATOR)); 624 ThemeProperties::COLOR_TOOLBAR_BOTTOM_SEPARATOR));
625 } 625 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698