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

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: 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 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_icon())
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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 View::ConvertRectToTarget(this, tabstrip, &rect_in_tabstrip_coords_f); 398 View::ConvertRectToTarget(this, tabstrip, &rect_in_tabstrip_coords_f);
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 = profile_indicator_icon()
409 avatar_button() ? (insets.left() + GetOTRAvatarIcon().width()) : 0; 409 ? (insets.left() + GetOTRAvatarIcon().width())
410 : 0;
410 return avatar_right + insets.right() + frame_values().normal_insets.left(); 411 return avatar_right + insets.right() + frame_values().normal_insets.left();
411 } 412 }
412 413
413 int BrowserNonClientFrameViewMus::GetTabStripRightInset() const { 414 int BrowserNonClientFrameViewMus::GetTabStripRightInset() const {
414 const int frame_right_insets = frame_values().normal_insets.right() + 415 const int frame_right_insets = frame_values().normal_insets.right() +
415 frame_values().max_title_bar_button_width; 416 frame_values().max_title_bar_button_width;
416 int right_inset = kTabstripRightSpacing + frame_right_insets; 417 int right_inset = kTabstripRightSpacing + frame_right_insets;
417 418
418 #if defined(FRAME_AVATAR_BUTTON) 419 #if defined(FRAME_AVATAR_BUTTON)
419 if (profile_switcher_.view()) { 420 if (profile_switcher_.view()) {
420 right_inset += kNewAvatarButtonOffset + 421 right_inset += kAvatarButtonOffset +
421 profile_switcher_.view()->GetPreferredSize().width(); 422 profile_switcher_.view()->GetPreferredSize().width();
422 } 423 }
423 #endif 424 #endif
424 425
425 return right_inset; 426 return right_inset;
426 } 427 }
427 428
428 bool BrowserNonClientFrameViewMus::UseImmersiveLightbarHeaderStyle() const { 429 bool BrowserNonClientFrameViewMus::UseImmersiveLightbarHeaderStyle() const {
429 ImmersiveModeController* immersive_controller = 430 ImmersiveModeController* immersive_controller =
430 browser_view()->immersive_mode_controller(); 431 browser_view()->immersive_mode_controller();
(...skipping 12 matching lines...) Expand all
443 // style. 444 // style.
444 return browser->is_app() && !UseWebAppHeaderStyle(); 445 return browser->is_app() && !UseWebAppHeaderStyle();
445 } 446 }
446 447
447 bool BrowserNonClientFrameViewMus::UseWebAppHeaderStyle() const { 448 bool BrowserNonClientFrameViewMus::UseWebAppHeaderStyle() const {
448 return browser_view()->browser()->SupportsWindowFeature( 449 return browser_view()->browser()->SupportsWindowFeature(
449 Browser::FEATURE_WEBAPPFRAME); 450 Browser::FEATURE_WEBAPPFRAME);
450 } 451 }
451 452
452 void BrowserNonClientFrameViewMus::LayoutIncognitoButton() { 453 void BrowserNonClientFrameViewMus::LayoutIncognitoButton() {
453 DCHECK(avatar_button()); 454 DCHECK(profile_indicator_icon());
454 #if !defined(OS_CHROMEOS) 455 #if !defined(OS_CHROMEOS)
455 // ChromeOS shows avatar on V1 app. 456 // ChromeOS shows avatar on V1 app.
456 DCHECK(browser_view()->IsTabStripVisible()); 457 DCHECK(browser_view()->IsTabStripVisible());
457 #endif 458 #endif
458 gfx::ImageSkia incognito_icon = GetOTRAvatarIcon(); 459 gfx::ImageSkia incognito_icon = GetOTRAvatarIcon();
459 gfx::Insets avatar_insets = GetLayoutInsets(AVATAR_ICON); 460 gfx::Insets avatar_insets = GetLayoutInsets(AVATAR_ICON);
460 int avatar_bottom = GetTopInset(false) + browser_view()->GetTabStripHeight() - 461 int avatar_bottom = GetTopInset(false) + browser_view()->GetTabStripHeight() -
461 avatar_insets.bottom(); 462 avatar_insets.bottom();
462 int avatar_y = avatar_bottom - incognito_icon.height(); 463 int avatar_y = avatar_bottom - incognito_icon.height();
463 if (!ui::MaterialDesignController::IsModeMaterial() && 464 if (!ui::MaterialDesignController::IsModeMaterial() &&
464 browser_view()->IsTabStripVisible() && 465 browser_view()->IsTabStripVisible() &&
465 (frame()->IsMaximized() || frame()->IsFullscreen())) { 466 (frame()->IsMaximized() || frame()->IsFullscreen())) {
466 avatar_y = GetTopInset(false) + kContentShadowHeight; 467 avatar_y = GetTopInset(false) + kContentShadowHeight;
467 } 468 }
468 469
469 // Hide the incognito icon in immersive fullscreen when the tab light bar is 470 // 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 471 // visible because the header is too short for the icognito icon to be
471 // recognizable. 472 // recognizable.
472 bool avatar_visible = !UseImmersiveLightbarHeaderStyle(); 473 bool avatar_visible = !UseImmersiveLightbarHeaderStyle();
473 int avatar_height = avatar_visible ? avatar_bottom - avatar_y : 0; 474 int avatar_height = avatar_visible ? avatar_bottom - avatar_y : 0;
474 475
475 gfx::Rect avatar_bounds(avatar_insets.left(), avatar_y, 476 gfx::Rect avatar_bounds(avatar_insets.left(), avatar_y,
476 incognito_icon.width(), avatar_height); 477 incognito_icon.width(), avatar_height);
477 avatar_button()->SetBoundsRect(avatar_bounds); 478 profile_indicator_icon()->SetBoundsRect(avatar_bounds);
478 avatar_button()->SetVisible(avatar_visible); 479 profile_indicator_icon()->SetVisible(avatar_visible);
479 } 480 }
480 481
481 void BrowserNonClientFrameViewMus::LayoutProfileSwitcher() { 482 void BrowserNonClientFrameViewMus::LayoutProfileSwitcher() {
482 #if defined(FRAME_AVATAR_BUTTON) 483 #if defined(FRAME_AVATAR_BUTTON)
483 gfx::Size button_size = profile_switcher_.view()->GetPreferredSize(); 484 gfx::Size button_size = profile_switcher_.view()->GetPreferredSize();
484 int button_x = width() - GetTabStripRightInset() + kNewAvatarButtonOffset; 485 int button_x = width() - GetTabStripRightInset() + kAvatarButtonOffset;
485 profile_switcher_.view()->SetBounds(button_x, 0, button_size.width(), 486 profile_switcher_.view()->SetBounds(button_x, 0, button_size.width(),
486 button_size.height()); 487 button_size.height());
487 #endif 488 #endif
488 } 489 }
489 490
490 bool BrowserNonClientFrameViewMus::ShouldPaint() const { 491 bool BrowserNonClientFrameViewMus::ShouldPaint() const {
491 if (!frame()->IsFullscreen()) 492 if (!frame()->IsFullscreen())
492 return true; 493 return true;
493 494
494 // We need to paint when in immersive fullscreen and either: 495 // We need to paint when in immersive fullscreen and either:
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 } 617 }
617 618
618 void BrowserNonClientFrameViewMus::PaintContentEdge(gfx::Canvas* canvas) { 619 void BrowserNonClientFrameViewMus::PaintContentEdge(gfx::Canvas* canvas) {
619 DCHECK(!UsePackagedAppHeaderStyle() && !UseWebAppHeaderStyle()); 620 DCHECK(!UsePackagedAppHeaderStyle() && !UseWebAppHeaderStyle());
620 const int bottom = frame_values().normal_insets.bottom(); 621 const int bottom = frame_values().normal_insets.bottom();
621 canvas->FillRect( 622 canvas->FillRect(
622 gfx::Rect(0, bottom, width(), kClientEdgeThickness), 623 gfx::Rect(0, bottom, width(), kClientEdgeThickness),
623 GetThemeProvider()->GetColor( 624 GetThemeProvider()->GetColor(
624 ThemeProperties::COLOR_TOOLBAR_BOTTOM_SEPARATOR)); 625 ThemeProperties::COLOR_TOOLBAR_BOTTOM_SEPARATOR));
625 } 626 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/frame/browser_non_client_frame_view_mus.h ('k') | chrome/browser/ui/views/frame/browser_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698