| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/panels/panel_browser_frame_view.h" | 5 #include "chrome/browser/ui/panels/panel_browser_frame_view.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/browser/themes/theme_service.h" | 10 #include "chrome/browser/themes/theme_service.h" |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 | 305 |
| 306 const ButtonResources& restore_button_resources = | 306 const ButtonResources& restore_button_resources = |
| 307 GetRestoreButtonResources(); | 307 GetRestoreButtonResources(); |
| 308 restore_button_ = new views::ImageButton(this); | 308 restore_button_ = new views::ImageButton(this); |
| 309 restore_button_->SetImage(views::CustomButton::BS_NORMAL, | 309 restore_button_->SetImage(views::CustomButton::BS_NORMAL, |
| 310 restore_button_resources.normal_image); | 310 restore_button_resources.normal_image); |
| 311 restore_button_->SetImage(views::CustomButton::BS_HOT, | 311 restore_button_->SetImage(views::CustomButton::BS_HOT, |
| 312 restore_button_resources.hover_image); | 312 restore_button_resources.hover_image); |
| 313 restore_button_->SetTooltipText(restore_button_resources.tooltip_text); | 313 restore_button_->SetTooltipText(restore_button_resources.tooltip_text); |
| 314 restore_button_->SetAccessibleName(restore_button_resources.tooltip_text); | 314 restore_button_->SetAccessibleName(restore_button_resources.tooltip_text); |
| 315 restore_button_->SetVisible(false); // only visible when panel is minimized |
| 315 AddChildView(restore_button_); | 316 AddChildView(restore_button_); |
| 316 | 317 |
| 317 title_icon_ = new TabIconView(this); | 318 title_icon_ = new TabIconView(this); |
| 318 title_icon_->set_is_light(true); | 319 title_icon_->set_is_light(true); |
| 319 AddChildView(title_icon_); | 320 AddChildView(title_icon_); |
| 320 title_icon_->Update(); | 321 title_icon_->Update(); |
| 321 | 322 |
| 322 title_label_ = new views::Label(GetTitleText()); | 323 title_label_ = new views::Label(GetTitleText()); |
| 323 title_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | 324 title_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
| 324 title_label_->SetAutoColorReadabilityEnabled(false); | 325 title_label_->SetAutoColorReadabilityEnabled(false); |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 gfx::Size PanelBrowserFrameView::GetMaximumSize() { | 459 gfx::Size PanelBrowserFrameView::GetMaximumSize() { |
| 459 return panel_browser_view_->panel()->max_size(); | 460 return panel_browser_view_->panel()->max_size(); |
| 460 } | 461 } |
| 461 | 462 |
| 462 void PanelBrowserFrameView::Layout() { | 463 void PanelBrowserFrameView::Layout() { |
| 463 Panel* panel = panel_browser_view_->panel(); | 464 Panel* panel = panel_browser_view_->panel(); |
| 464 PanelStrip* panel_strip = panel->panel_strip(); | 465 PanelStrip* panel_strip = panel->panel_strip(); |
| 465 if (!panel_strip) | 466 if (!panel_strip) |
| 466 return; | 467 return; |
| 467 | 468 |
| 468 // Check if the width is only enough to show only the icon, or both icon | |
| 469 // and title. Hide corresponding controls accordingly. | |
| 470 // TODO(aburago) Make sure the close button is always visible even if the | |
| 471 // panel is too narrow. | |
| 472 bool show_close_button = true; | |
| 473 bool show_title_label = true; | |
| 474 bool show_restore_button = panel->CanRestore(); | |
| 475 bool show_minimize_button = panel->CanMinimize(); | |
| 476 | |
| 477 close_button_->SetVisible(show_close_button); | |
| 478 minimize_button_->SetVisible(show_minimize_button); | |
| 479 restore_button_->SetVisible(show_restore_button); | |
| 480 title_label_->SetVisible(show_title_label); | |
| 481 | |
| 482 // Layout the close button. | 469 // Layout the close button. |
| 483 int right = width(); | 470 int right = width(); |
| 484 if (show_close_button) { | 471 gfx::Size close_button_size = close_button_->GetPreferredSize(); |
| 485 gfx::Size close_button_size = close_button_->GetPreferredSize(); | 472 close_button_->SetBounds( |
| 486 close_button_->SetBounds( | 473 width() - NonClientBorderThickness() - kCloseButtonAndBorderSpacing - |
| 487 width() - NonClientBorderThickness() - kCloseButtonAndBorderSpacing - | 474 close_button_size.width(), |
| 488 close_button_size.width(), | 475 (NonClientTopBorderHeight() - close_button_size.height()) / 2, |
| 489 (NonClientTopBorderHeight() - close_button_size.height()) / 2, | 476 close_button_size.width(), |
| 490 close_button_size.width(), | 477 close_button_size.height()); |
| 491 close_button_size.height()); | 478 right = close_button_->x(); |
| 492 right = close_button_->x(); | |
| 493 } | |
| 494 | 479 |
| 495 // Layout the minimize/restore button. | 480 // Layout the minimize and restore button. Both occupy the same space, |
| 496 views::ImageButton* minimize_or_restore_button = NULL; | 481 // but at most one is visible at any time. |
| 497 if (show_minimize_button) | 482 gfx::Size button_size = minimize_button_->GetPreferredSize(); |
| 498 minimize_or_restore_button = minimize_button_; | 483 minimize_button_->SetBounds( |
| 499 else if (show_restore_button) | 484 right - kMinimizeButtonAndCloseButtonSpacing - button_size.width(), |
| 500 minimize_or_restore_button = restore_button_; | 485 (NonClientTopBorderHeight() - button_size.height()) / 2, |
| 501 if (minimize_or_restore_button) { | 486 button_size.width(), |
| 502 gfx::Size button_size = minimize_or_restore_button->GetPreferredSize(); | 487 button_size.height()); |
| 503 minimize_or_restore_button->SetBounds( | 488 restore_button_->SetBoundsRect(minimize_button_->bounds()); |
| 504 right - kMinimizeButtonAndCloseButtonSpacing - button_size.width(), | 489 right = minimize_button_->x(); |
| 505 (NonClientTopBorderHeight() - button_size.height()) / 2, | |
| 506 button_size.width(), | |
| 507 button_size.height()); | |
| 508 right = minimize_or_restore_button->x(); | |
| 509 } | |
| 510 | 490 |
| 511 // Layout the icon. | 491 // Layout the icon. |
| 512 int icon_y = (NonClientTopBorderHeight() - kIconSize) / 2; | 492 int icon_y = (NonClientTopBorderHeight() - kIconSize) / 2; |
| 513 title_icon_->SetBounds( | 493 title_icon_->SetBounds( |
| 514 NonClientBorderThickness() + kIconAndBorderSpacing, | 494 NonClientBorderThickness() + kIconAndBorderSpacing, |
| 515 icon_y, | 495 icon_y, |
| 516 kIconSize, | 496 kIconSize, |
| 517 kIconSize); | 497 kIconSize); |
| 518 | 498 |
| 519 // Layout the title. | 499 // Layout the title. |
| 520 if (show_title_label) { | 500 int title_x = title_icon_->bounds().right() + kTitleSpacing; |
| 521 int title_x = title_icon_->bounds().right() + kTitleSpacing; | 501 int title_height = BrowserFrame::GetTitleFont().GetHeight(); |
| 522 int title_height = BrowserFrame::GetTitleFont().GetHeight(); | 502 title_label_->SetBounds( |
| 523 title_label_->SetBounds( | 503 title_x, |
| 524 title_x, | 504 icon_y + ((kIconSize - title_height - 1) / 2), |
| 525 icon_y + ((kIconSize - title_height - 1) / 2), | 505 std::max(0, right - kTitleSpacing - title_x), |
| 526 std::max(0, right - kTitleSpacing - title_x), | 506 title_height); |
| 527 title_height); | |
| 528 } | |
| 529 | 507 |
| 530 // Calculate the client area bounds. | 508 // Calculate the client area bounds. |
| 531 int top_height = NonClientTopBorderHeight(); | 509 int top_height = NonClientTopBorderHeight(); |
| 532 int border_thickness = NonClientBorderThickness(); | 510 int border_thickness = NonClientBorderThickness(); |
| 533 client_view_bounds_.SetRect( | 511 client_view_bounds_.SetRect( |
| 534 border_thickness, | 512 border_thickness, |
| 535 top_height, | 513 top_height, |
| 536 std::max(0, width() - (2 * border_thickness)), | 514 std::max(0, width() - (2 * border_thickness)), |
| 537 std::max(0, height() - top_height - border_thickness)); | 515 std::max(0, height() - top_height - border_thickness)); |
| 538 } | 516 } |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 804 } | 782 } |
| 805 | 783 |
| 806 string16 PanelBrowserFrameView::GetTitleText() const { | 784 string16 PanelBrowserFrameView::GetTitleText() const { |
| 807 return frame()->widget_delegate()->GetWindowTitle(); | 785 return frame()->widget_delegate()->GetWindowTitle(); |
| 808 } | 786 } |
| 809 | 787 |
| 810 void PanelBrowserFrameView::UpdateTitleBar() { | 788 void PanelBrowserFrameView::UpdateTitleBar() { |
| 811 title_label_->SetText(GetTitleText()); | 789 title_label_->SetText(GetTitleText()); |
| 812 } | 790 } |
| 813 | 791 |
| 792 void PanelBrowserFrameView::UpdateTitleBarMinimizeRestoreButtonVisibility() { |
| 793 Panel* panel = panel_browser_view_->panel(); |
| 794 minimize_button_->SetVisible(panel->CanMinimize()); |
| 795 restore_button_->SetVisible(panel->CanRestore()); |
| 796 } |
| 797 |
| 814 bool PanelBrowserFrameView::CanResize() const { | 798 bool PanelBrowserFrameView::CanResize() const { |
| 815 return panel_browser_view_->panel()->CanResizeByMouse() != | 799 return panel_browser_view_->panel()->CanResizeByMouse() != |
| 816 panel::NOT_RESIZABLE; | 800 panel::NOT_RESIZABLE; |
| 817 } | 801 } |
| 818 | 802 |
| 819 bool PanelBrowserFrameView::IsShowingTitlebarOnly() const { | 803 bool PanelBrowserFrameView::IsShowingTitlebarOnly() const { |
| 820 return height() <= kTitlebarHeight; | 804 return height() <= kTitlebarHeight; |
| 821 } | 805 } |
| OLD | NEW |