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

Side by Side Diff: chrome/browser/ui/views/frame/browser_non_client_frame_view_ash.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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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_ash.h" 5 #include "chrome/browser/ui/views/frame/browser_non_client_frame_view_ash.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "ash/ash_layout_constants.h" 9 #include "ash/ash_layout_constants.h"
10 #include "ash/frame/caption_buttons/frame_caption_button_container_view.h" 10 #include "ash/frame/caption_buttons/frame_caption_button_container_view.h"
11 #include "ash/frame/default_header_painter.h" 11 #include "ash/frame/default_header_painter.h"
12 #include "ash/frame/frame_border_hit_test_controller.h" 12 #include "ash/frame/frame_border_hit_test_controller.h"
13 #include "ash/frame/header_painter_util.h" 13 #include "ash/frame/header_painter_util.h"
14 #include "ash/shell.h" 14 #include "ash/shell.h"
15 #include "build/build_config.h" 15 #include "build/build_config.h"
16 #include "chrome/app/chrome_command_ids.h" 16 #include "chrome/app/chrome_command_ids.h"
17 #include "chrome/browser/extensions/extension_util.h" 17 #include "chrome/browser/extensions/extension_util.h"
18 #include "chrome/browser/profiles/profiles_state.h" 18 #include "chrome/browser/profiles/profiles_state.h"
19 #include "chrome/browser/themes/theme_properties.h" 19 #include "chrome/browser/themes/theme_properties.h"
20 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h"
20 #include "chrome/browser/ui/browser.h" 21 #include "chrome/browser/ui/browser.h"
21 #include "chrome/browser/ui/browser_commands.h" 22 #include "chrome/browser/ui/browser_commands.h"
22 #include "chrome/browser/ui/layout_constants.h" 23 #include "chrome/browser/ui/layout_constants.h"
23 #include "chrome/browser/ui/views/frame/browser_frame.h" 24 #include "chrome/browser/ui/views/frame/browser_frame.h"
24 #include "chrome/browser/ui/views/frame/browser_header_painter_ash.h" 25 #include "chrome/browser/ui/views/frame/browser_header_painter_ash.h"
25 #include "chrome/browser/ui/views/frame/browser_view.h" 26 #include "chrome/browser/ui/views/frame/browser_view.h"
26 #include "chrome/browser/ui/views/frame/immersive_mode_controller.h" 27 #include "chrome/browser/ui/views/frame/immersive_mode_controller.h"
27 #include "chrome/browser/ui/views/frame/web_app_left_header_view_ash.h" 28 #include "chrome/browser/ui/views/frame/web_app_left_header_view_ash.h"
28 #include "chrome/browser/ui/views/profiles/avatar_menu_button.h" 29 #include "chrome/browser/ui/views/profiles/profile_indicator_icon.h"
29 #include "chrome/browser/ui/views/tab_icon_view.h" 30 #include "chrome/browser/ui/views/tab_icon_view.h"
30 #include "chrome/browser/ui/views/tabs/tab_strip.h" 31 #include "chrome/browser/ui/views/tabs/tab_strip.h"
31 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" 32 #include "chrome/browser/ui/views/toolbar/toolbar_view.h"
32 #include "chrome/browser/web_applications/web_app.h" 33 #include "chrome/browser/web_applications/web_app.h"
33 #include "components/signin/core/common/profile_management_switches.h" 34 #include "components/signin/core/common/profile_management_switches.h"
34 #include "content/public/browser/web_contents.h" 35 #include "content/public/browser/web_contents.h"
35 #include "extensions/browser/extension_registry.h" 36 #include "extensions/browser/extension_registry.h"
36 #include "grit/theme_resources.h" 37 #include "grit/theme_resources.h"
37 #include "ui/accessibility/ax_view_state.h" 38 #include "ui/accessibility/ax_view_state.h"
38 #include "ui/aura/client/aura_constants.h" 39 #include "ui/aura/client/aura_constants.h"
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 // computation of |painted_height| for app and popup windows depends on the 299 // computation of |painted_height| for app and popup windows depends on the
299 // position of the window controls. 300 // position of the window controls.
300 header_painter_->LayoutHeader(); 301 header_painter_->LayoutHeader();
301 302
302 int painted_height = GetTopInset(false); 303 int painted_height = GetTopInset(false);
303 if (browser_view()->IsTabStripVisible()) 304 if (browser_view()->IsTabStripVisible())
304 painted_height += browser_view()->tabstrip()->GetPreferredSize().height(); 305 painted_height += browser_view()->tabstrip()->GetPreferredSize().height();
305 306
306 header_painter_->SetHeaderHeightForPainting(painted_height); 307 header_painter_->SetHeaderHeightForPainting(painted_height);
307 308
308 if (avatar_button()) 309 if (profile_indicator())
309 LayoutAvatar(); 310 LayoutProfileIndicator();
310 BrowserNonClientFrameView::Layout(); 311 BrowserNonClientFrameView::Layout();
311 } 312 }
312 313
313 const char* BrowserNonClientFrameViewAsh::GetClassName() const { 314 const char* BrowserNonClientFrameViewAsh::GetClassName() const {
314 return "BrowserNonClientFrameViewAsh"; 315 return "BrowserNonClientFrameViewAsh";
315 } 316 }
316 317
317 void BrowserNonClientFrameViewAsh::GetAccessibleState(ui::AXViewState* state) { 318 void BrowserNonClientFrameViewAsh::GetAccessibleState(ui::AXViewState* state) {
318 state->role = ui::AX_ROLE_TITLE_BAR; 319 state->role = ui::AX_ROLE_TITLE_BAR;
319 } 320 }
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 374
374 gfx::ImageSkia BrowserNonClientFrameViewAsh::GetFaviconForTabIconView() { 375 gfx::ImageSkia BrowserNonClientFrameViewAsh::GetFaviconForTabIconView() {
375 views::WidgetDelegate* delegate = frame()->widget_delegate(); 376 views::WidgetDelegate* delegate = frame()->widget_delegate();
376 return delegate ? delegate->GetWindowIcon() : gfx::ImageSkia(); 377 return delegate ? delegate->GetWindowIcon() : gfx::ImageSkia();
377 } 378 }
378 379
379 /////////////////////////////////////////////////////////////////////////////// 380 ///////////////////////////////////////////////////////////////////////////////
380 // BrowserNonClientFrameViewAsh, protected: 381 // BrowserNonClientFrameViewAsh, protected:
381 382
382 // BrowserNonClientFrameView: 383 // BrowserNonClientFrameView:
383 void BrowserNonClientFrameViewAsh::UpdateAvatar() { 384 void BrowserNonClientFrameViewAsh::UpdateProfileIcons() {
384 UpdateOldAvatarButton(); 385 Browser* browser = browser_view()->browser();
386 if ((browser->is_type_tabbed() || browser->is_app()) &&
387 chrome::MultiUserWindowManager::ShouldShowAvatar(
388 browser_view()->GetNativeWindow())) {
389 UpdateProfileIndicatorIcon();
390 }
385 } 391 }
386 392
387 /////////////////////////////////////////////////////////////////////////////// 393 ///////////////////////////////////////////////////////////////////////////////
388 // BrowserNonClientFrameViewAsh, private: 394 // BrowserNonClientFrameViewAsh, private:
389 395
390 // views::NonClientFrameView: 396 // views::NonClientFrameView:
391 bool BrowserNonClientFrameViewAsh::DoesIntersectRect( 397 bool BrowserNonClientFrameViewAsh::DoesIntersectRect(
392 const views::View* target, 398 const views::View* target,
393 const gfx::Rect& rect) const { 399 const gfx::Rect& rect) const {
394 CHECK_EQ(this, target); 400 CHECK_EQ(this, target);
(...skipping 16 matching lines...) Expand all
411 const gfx::Rect rect_in_tabstrip_coords( 417 const gfx::Rect rect_in_tabstrip_coords(
412 gfx::ToEnclosingRect(rect_in_tabstrip_coords_f)); 418 gfx::ToEnclosingRect(rect_in_tabstrip_coords_f));
413 return (rect_in_tabstrip_coords.y() <= tabstrip->height()) && 419 return (rect_in_tabstrip_coords.y() <= tabstrip->height()) &&
414 (!tabstrip->HitTestRect(rect_in_tabstrip_coords) || 420 (!tabstrip->HitTestRect(rect_in_tabstrip_coords) ||
415 tabstrip->IsRectInWindowCaption(rect_in_tabstrip_coords)); 421 tabstrip->IsRectInWindowCaption(rect_in_tabstrip_coords));
416 } 422 }
417 423
418 int BrowserNonClientFrameViewAsh::GetTabStripLeftInset() const { 424 int BrowserNonClientFrameViewAsh::GetTabStripLeftInset() const {
419 const gfx::Insets insets(GetLayoutInsets(AVATAR_ICON)); 425 const gfx::Insets insets(GetLayoutInsets(AVATAR_ICON));
420 const int avatar_right = 426 const int avatar_right =
421 avatar_button() ? (insets.left() + GetOTRAvatarIcon().width()) : 0; 427 profile_indicator() ? (insets.left() + GetOTRAvatarIcon().width()) : 0;
422 return avatar_right + insets.right(); 428 return avatar_right + insets.right();
423 } 429 }
424 430
425 int BrowserNonClientFrameViewAsh::GetTabStripRightInset() const { 431 int BrowserNonClientFrameViewAsh::GetTabStripRightInset() const {
426 return kTabstripRightSpacing + 432 return kTabstripRightSpacing +
427 caption_button_container_->GetPreferredSize().width(); 433 caption_button_container_->GetPreferredSize().width();
428 } 434 }
429 435
430 bool BrowserNonClientFrameViewAsh::UseImmersiveLightbarHeaderStyle() const { 436 bool BrowserNonClientFrameViewAsh::UseImmersiveLightbarHeaderStyle() const {
431 const ImmersiveModeController* const immersive_controller = 437 const ImmersiveModeController* const immersive_controller =
432 browser_view()->immersive_mode_controller(); 438 browser_view()->immersive_mode_controller();
433 return immersive_controller->IsEnabled() && 439 return immersive_controller->IsEnabled() &&
434 !immersive_controller->IsRevealed() && 440 !immersive_controller->IsRevealed() &&
435 browser_view()->IsTabStripVisible(); 441 browser_view()->IsTabStripVisible();
436 } 442 }
437 443
438 bool BrowserNonClientFrameViewAsh::UsePackagedAppHeaderStyle() const { 444 bool BrowserNonClientFrameViewAsh::UsePackagedAppHeaderStyle() const {
439 // Use for non tabbed trusted source windows, e.g. Settings, as well as apps 445 // Use for non tabbed trusted source windows, e.g. Settings, as well as apps
440 // that aren't using the newer WebApp style. 446 // that aren't using the newer WebApp style.
441 const Browser* const browser = browser_view()->browser(); 447 const Browser* const browser = browser_view()->browser();
442 return (!browser->is_type_tabbed() && browser->is_trusted_source()) || 448 return (!browser->is_type_tabbed() && browser->is_trusted_source()) ||
443 (browser->is_app() && !UseWebAppHeaderStyle()); 449 (browser->is_app() && !UseWebAppHeaderStyle());
444 } 450 }
445 451
446 bool BrowserNonClientFrameViewAsh::UseWebAppHeaderStyle() const { 452 bool BrowserNonClientFrameViewAsh::UseWebAppHeaderStyle() const {
447 return browser_view()->browser()->SupportsWindowFeature( 453 return browser_view()->browser()->SupportsWindowFeature(
448 Browser::FEATURE_WEBAPPFRAME); 454 Browser::FEATURE_WEBAPPFRAME);
449 } 455 }
450 456
451 void BrowserNonClientFrameViewAsh::LayoutAvatar() { 457 void BrowserNonClientFrameViewAsh::LayoutProfileIndicator() {
452 DCHECK(avatar_button()); 458 DCHECK(profile_indicator());
453 #if !defined(OS_CHROMEOS) 459 #if !defined(OS_CHROMEOS)
454 // ChromeOS shows avatar on V1 app. 460 // ChromeOS shows avatar on V1 app.
455 DCHECK(browser_view()->IsTabStripVisible()); 461 DCHECK(browser_view()->IsTabStripVisible());
456 #endif 462 #endif
457 463
458 const gfx::ImageSkia incognito_icon = GetOTRAvatarIcon(); 464 const gfx::ImageSkia incognito_icon = GetOTRAvatarIcon();
459 const gfx::Insets avatar_insets = GetLayoutInsets(AVATAR_ICON); 465 const gfx::Insets avatar_insets = GetLayoutInsets(AVATAR_ICON);
460 const int avatar_bottom = GetTopInset(false) + 466 const int avatar_bottom = GetTopInset(false) +
461 browser_view()->GetTabStripHeight() - avatar_insets.bottom(); 467 browser_view()->GetTabStripHeight() - avatar_insets.bottom();
462 int avatar_y = avatar_bottom - incognito_icon.height(); 468 int avatar_y = avatar_bottom - incognito_icon.height();
463 if (!ui::MaterialDesignController::IsModeMaterial() && 469 if (!ui::MaterialDesignController::IsModeMaterial() &&
464 browser_view()->IsTabStripVisible() && 470 browser_view()->IsTabStripVisible() &&
465 (frame()->IsMaximized() || frame()->IsFullscreen())) { 471 (frame()->IsMaximized() || frame()->IsFullscreen())) {
466 avatar_y = GetTopInset(false) + kContentShadowHeight; 472 avatar_y = GetTopInset(false) + kContentShadowHeight;
467 } 473 }
468 474
469 // Hide the incognito icon in immersive fullscreen when the tab light bar is 475 // 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 476 // visible because the header is too short for the icognito icon to be
471 // recognizable. 477 // recognizable.
472 const bool avatar_visible = !UseImmersiveLightbarHeaderStyle(); 478 const bool avatar_visible = !UseImmersiveLightbarHeaderStyle();
473 const int avatar_height = avatar_visible ? (avatar_bottom - avatar_y) : 0; 479 const int avatar_height = avatar_visible ? (avatar_bottom - avatar_y) : 0;
474 avatar_button()->SetBounds(avatar_insets.left(), avatar_y, 480 profile_indicator()->SetBounds(avatar_insets.left(), avatar_y,
475 incognito_icon.width(), avatar_height); 481 incognito_icon.width(), avatar_height);
476 avatar_button()->SetVisible(avatar_visible); 482 profile_indicator()->SetVisible(avatar_visible);
477 } 483 }
478 484
479 bool BrowserNonClientFrameViewAsh::ShouldPaint() const { 485 bool BrowserNonClientFrameViewAsh::ShouldPaint() const {
480 if (!frame()->IsFullscreen()) 486 if (!frame()->IsFullscreen())
481 return true; 487 return true;
482 488
483 // We need to paint when in immersive fullscreen and either: 489 // We need to paint when in immersive fullscreen and either:
484 // - The top-of-window views are revealed. 490 // - The top-of-window views are revealed.
485 // - The lightbar style tabstrip is visible. 491 // - The lightbar style tabstrip is visible.
486 ImmersiveModeController* immersive_mode_controller = 492 ImmersiveModeController* immersive_mode_controller =
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 // TODO(pkasting): The "2 *" part of this makes no sense to me. 568 // TODO(pkasting): The "2 *" part of this makes no sense to me.
563 canvas->TileImageInt(*right, 0, 0, w - (2 * kClientEdgeThickness) - img_w, 569 canvas->TileImageInt(*right, 0, 0, w - (2 * kClientEdgeThickness) - img_w,
564 img_y, img_w, img_h); 570 img_y, img_w, img_h);
565 571
566 // Toolbar/content separator. 572 // Toolbar/content separator.
567 toolbar_bounds.Inset(kClientEdgeThickness, h - kClientEdgeThickness, 573 toolbar_bounds.Inset(kClientEdgeThickness, h - kClientEdgeThickness,
568 kClientEdgeThickness, 0); 574 kClientEdgeThickness, 0);
569 canvas->FillRect(toolbar_bounds, separator_color); 575 canvas->FillRect(toolbar_bounds, separator_color);
570 } 576 }
571 } 577 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698