| 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" |
| 11 #include "chrome/browser/ui/views/profiles/avatar_menu_button.h" | 11 #include "chrome/browser/ui/views/profiles/avatar_menu_button.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/custom_button.h" |
| 16 #include "ui/views/controls/button/image_button.h" | 17 #include "ui/views/controls/button/image_button.h" |
| 17 #include "ui/views/controls/label.h" | 18 #include "ui/views/controls/label.h" |
| 18 | 19 |
| 19 namespace { | 20 namespace { |
| 20 | 21 |
| 21 const int kCaptionButtonHeight = 18; | 22 const int kCaptionButtonHeight = 18; |
| 22 | 23 |
| 23 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | 24 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| 24 // Default extra space between the top of the frame and the top of the window | 25 // Default extra space between the top of the frame and the top of the window |
| 25 // caption buttons. | 26 // caption buttons. |
| (...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 switch (button_id) { | 413 switch (button_id) { |
| 413 case views::FRAME_BUTTON_MINIMIZE: { | 414 case views::FRAME_BUTTON_MINIMIZE: { |
| 414 minimize_button_->SetVisible(true); | 415 minimize_button_->SetVisible(true); |
| 415 SetBoundsForButton(host, minimize_button_, alignment, caption_y); | 416 SetBoundsForButton(host, minimize_button_, alignment, caption_y); |
| 416 break; | 417 break; |
| 417 } | 418 } |
| 418 case views::FRAME_BUTTON_MAXIMIZE: { | 419 case views::FRAME_BUTTON_MAXIMIZE: { |
| 419 // When the window is restored, we show a maximized button; otherwise, we | 420 // When the window is restored, we show a maximized button; otherwise, we |
| 420 // show a restore button. | 421 // show a restore button. |
| 421 bool is_restored = !delegate_->IsMaximized() && !delegate_->IsMinimized(); | 422 bool is_restored = !delegate_->IsMaximized() && !delegate_->IsMinimized(); |
| 422 views::ImageButton* invisible_button = is_restored ? | 423 views::CustomButton* invisible_button = is_restored ? |
| 423 restore_button_ : maximize_button_; | 424 restore_button_ : maximize_button_; |
| 424 invisible_button->SetVisible(false); | 425 invisible_button->SetVisible(false); |
| 425 | 426 |
| 426 views::ImageButton* visible_button = is_restored ? | 427 views::CustomButton* visible_button = is_restored ? |
| 427 maximize_button_ : restore_button_; | 428 maximize_button_ : restore_button_; |
| 428 visible_button->SetVisible(true); | 429 visible_button->SetVisible(true); |
| 429 SetBoundsForButton(host, visible_button, alignment, caption_y); | 430 SetBoundsForButton(host, visible_button, alignment, caption_y); |
| 430 break; | 431 break; |
| 431 } | 432 } |
| 432 case views::FRAME_BUTTON_CLOSE: { | 433 case views::FRAME_BUTTON_CLOSE: { |
| 433 close_button_->SetVisible(true); | 434 close_button_->SetVisible(true); |
| 434 SetBoundsForButton(host, close_button_, alignment, caption_y); | 435 SetBoundsForButton(host, close_button_, alignment, caption_y); |
| 435 break; | 436 break; |
| 436 } | 437 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 447 maximize_button_->SetVisible(false); | 448 maximize_button_->SetVisible(false); |
| 448 break; | 449 break; |
| 449 case views::FRAME_BUTTON_CLOSE: | 450 case views::FRAME_BUTTON_CLOSE: |
| 450 close_button_->SetVisible(false); | 451 close_button_->SetVisible(false); |
| 451 break; | 452 break; |
| 452 } | 453 } |
| 453 } | 454 } |
| 454 | 455 |
| 455 void OpaqueBrowserFrameViewLayout::SetBoundsForButton( | 456 void OpaqueBrowserFrameViewLayout::SetBoundsForButton( |
| 456 views::View* host, | 457 views::View* host, |
| 457 views::ImageButton* button, | 458 views::CustomButton* button, |
| 458 ButtonAlignment alignment, | 459 ButtonAlignment alignment, |
| 459 int caption_y) { | 460 int caption_y) { |
| 460 gfx::Size button_size = button->GetPreferredSize(); | 461 gfx::Size button_size = button->GetPreferredSize(); |
| 461 | 462 |
| 462 button->SetImageAlignment( | 463 // If the custom button is actually an ImageButton, get a pointer so that |
| 463 (alignment == ALIGN_LEADING) ? | 464 // the image can be further configured. |
| 464 views::ImageButton::ALIGN_RIGHT : views::ImageButton::ALIGN_LEFT, | 465 views::ImageButton* image_button = |
| 465 views::ImageButton::ALIGN_BOTTOM); | 466 views::ImageButton::kViewClassName == button->GetClassName() ? |
| 467 static_cast<views::ImageButton*>(button) : nullptr; |
| 468 |
| 469 if (image_button) { |
| 470 image_button->SetImageAlignment( |
| 471 (alignment == ALIGN_LEADING) ? |
| 472 views::ImageButton::ALIGN_RIGHT : views::ImageButton::ALIGN_LEFT, |
| 473 views::ImageButton::ALIGN_BOTTOM); |
| 474 } |
| 466 | 475 |
| 467 // There should always be the same number of non-shadow pixels visible to the | 476 // There should always be the same number of non-shadow pixels visible to the |
| 468 // side of the caption buttons. In maximized mode we extend buttons to the | 477 // side of the caption buttons. In maximized mode we extend buttons to the |
| 469 // screen top and the rightmost button to the screen right (or leftmost button | 478 // screen top and the rightmost button to the screen right (or leftmost button |
| 470 // to the screen left, for left-aligned buttons) to obey Fitts' Law. | 479 // to the screen left, for left-aligned buttons) to obey Fitts' Law. |
| 471 bool title_bar_condensed = IsTitleBarCondensed(); | 480 bool title_bar_condensed = IsTitleBarCondensed(); |
| 472 | 481 |
| 473 // When we are the first button on the leading side and are the close | 482 if (image_button) { |
| 474 // button, we must flip ourselves, because the close button assets have | 483 // When we are the first button on the leading side and are the close |
| 475 // a little notch to fit in the rounded frame. | 484 // button, we must flip ourselves, because the close button assets have |
| 476 button->SetDrawImageMirrored(alignment == ALIGN_LEADING && | 485 // a little notch to fit in the rounded frame. |
| 477 !has_leading_buttons_ && | 486 image_button->SetDrawImageMirrored( |
| 478 button == close_button_); | 487 alignment == ALIGN_LEADING && !has_leading_buttons_ && |
| 488 button == close_button_); |
| 489 } |
| 490 |
| 479 // If the window is maximized, align the buttons to its upper edge. | 491 // If the window is maximized, align the buttons to its upper edge. |
| 480 int extra_height = title_bar_condensed ? extra_caption_y_ : 0; | 492 int extra_height = title_bar_condensed ? extra_caption_y_ : 0; |
| 481 | 493 |
| 482 switch (alignment) { | 494 switch (alignment) { |
| 483 case ALIGN_LEADING: { | 495 case ALIGN_LEADING: { |
| 484 if (has_leading_buttons_) | 496 if (has_leading_buttons_) |
| 485 leading_button_start_ += window_caption_spacing_; | 497 leading_button_start_ += window_caption_spacing_; |
| 486 | 498 |
| 487 // If we're the first button on the left and maximized, add width to the | 499 // If we're the first button on the left and maximized, add width to the |
| 488 // right hand side of the screen. | 500 // right hand side of the screen. |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 527 } | 539 } |
| 528 | 540 |
| 529 void OpaqueBrowserFrameViewLayout::SetView(int id, views::View* view) { | 541 void OpaqueBrowserFrameViewLayout::SetView(int id, views::View* view) { |
| 530 // Why do things this way instead of having an Init() method, where we're | 542 // Why do things this way instead of having an Init() method, where we're |
| 531 // passed the views we'll handle? Because OpaqueBrowserFrameView doesn't own | 543 // passed the views we'll handle? Because OpaqueBrowserFrameView doesn't own |
| 532 // all the views which are part of it. The avatar stuff, for example, will be | 544 // all the views which are part of it. The avatar stuff, for example, will be |
| 533 // added and removed by the base class of OpaqueBrowserFrameView. | 545 // added and removed by the base class of OpaqueBrowserFrameView. |
| 534 switch (id) { | 546 switch (id) { |
| 535 case VIEW_ID_MINIMIZE_BUTTON: | 547 case VIEW_ID_MINIMIZE_BUTTON: |
| 536 if (view) { | 548 if (view) { |
| 537 DCHECK_EQ(std::string(views::ImageButton::kViewClassName), | 549 minimize_button_ = views::CustomButton::AsCustomButton(view); |
| 538 view->GetClassName()); | 550 DCHECK(nullptr != minimize_button_); |
| 551 } else { |
| 552 minimize_button_ = nullptr; |
| 539 } | 553 } |
| 540 minimize_button_ = static_cast<views::ImageButton*>(view); | |
| 541 break; | 554 break; |
| 542 case VIEW_ID_MAXIMIZE_BUTTON: | 555 case VIEW_ID_MAXIMIZE_BUTTON: |
| 543 if (view) { | 556 if (view) { |
| 544 DCHECK_EQ(std::string(views::ImageButton::kViewClassName), | 557 maximize_button_ = views::CustomButton::AsCustomButton(view); |
| 545 view->GetClassName()); | 558 DCHECK(nullptr != maximize_button_); |
| 559 } else { |
| 560 maximize_button_ = nullptr; |
| 546 } | 561 } |
| 547 maximize_button_ = static_cast<views::ImageButton*>(view); | |
| 548 break; | 562 break; |
| 549 case VIEW_ID_RESTORE_BUTTON: | 563 case VIEW_ID_RESTORE_BUTTON: |
| 550 if (view) { | 564 if (view) { |
| 551 DCHECK_EQ(std::string(views::ImageButton::kViewClassName), | 565 restore_button_ = views::CustomButton::AsCustomButton(view); |
| 552 view->GetClassName()); | 566 DCHECK(nullptr != restore_button_); |
| 567 } else { |
| 568 restore_button_ = nullptr; |
| 553 } | 569 } |
| 554 restore_button_ = static_cast<views::ImageButton*>(view); | |
| 555 break; | 570 break; |
| 556 case VIEW_ID_CLOSE_BUTTON: | 571 case VIEW_ID_CLOSE_BUTTON: |
| 557 if (view) { | 572 if (view) { |
| 558 DCHECK_EQ(std::string(views::ImageButton::kViewClassName), | 573 close_button_ = views::CustomButton::AsCustomButton(view); |
| 559 view->GetClassName()); | 574 DCHECK(nullptr != close_button_); |
| 575 } else { |
| 576 close_button_ = nullptr; |
| 560 } | 577 } |
| 561 close_button_ = static_cast<views::ImageButton*>(view); | |
| 562 break; | 578 break; |
| 563 case VIEW_ID_WINDOW_ICON: | 579 case VIEW_ID_WINDOW_ICON: |
| 564 window_icon_ = view; | 580 window_icon_ = view; |
| 565 break; | 581 break; |
| 566 case VIEW_ID_WINDOW_TITLE: | 582 case VIEW_ID_WINDOW_TITLE: |
| 567 if (view) { | 583 if (view) { |
| 568 DCHECK_EQ(std::string(views::Label::kViewClassName), | 584 DCHECK_EQ(std::string(views::Label::kViewClassName), |
| 569 view->GetClassName()); | 585 view->GetClassName()); |
| 570 } | 586 } |
| 571 window_title_ = static_cast<views::Label*>(view); | 587 window_title_ = static_cast<views::Label*>(view); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 619 | 635 |
| 620 void OpaqueBrowserFrameViewLayout::ViewAdded(views::View* host, | 636 void OpaqueBrowserFrameViewLayout::ViewAdded(views::View* host, |
| 621 views::View* view) { | 637 views::View* view) { |
| 622 SetView(view->id(), view); | 638 SetView(view->id(), view); |
| 623 } | 639 } |
| 624 | 640 |
| 625 void OpaqueBrowserFrameViewLayout::ViewRemoved(views::View* host, | 641 void OpaqueBrowserFrameViewLayout::ViewRemoved(views::View* host, |
| 626 views::View* view) { | 642 views::View* view) { |
| 627 SetView(view->id(), nullptr); | 643 SetView(view->id(), nullptr); |
| 628 } | 644 } |
| OLD | NEW |