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

Side by Side Diff: chrome/browser/ui/panels/panel_browser_frame_view.cc

Issue 10260028: Update Panel mininimize/restore button on strip and expansion state change. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: synced Created 8 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 | Annotate | Revision Log
OLDNEW
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
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
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/restore button.
496 views::ImageButton* minimize_or_restore_button = NULL; 481 views::ImageButton* minimize_or_restore_button = NULL;
497 if (show_minimize_button) 482 if (minimize_button_->visible())
498 minimize_or_restore_button = minimize_button_; 483 minimize_or_restore_button = minimize_button_;
499 else if (show_restore_button) 484 else if (restore_button_->visible())
500 minimize_or_restore_button = restore_button_; 485 minimize_or_restore_button = restore_button_;
501 if (minimize_or_restore_button) { 486 if (minimize_or_restore_button) {
502 gfx::Size button_size = minimize_or_restore_button->GetPreferredSize(); 487 gfx::Size button_size = minimize_or_restore_button->GetPreferredSize();
503 minimize_or_restore_button->SetBounds( 488 minimize_or_restore_button->SetBounds(
504 right - kMinimizeButtonAndCloseButtonSpacing - button_size.width(), 489 right - kMinimizeButtonAndCloseButtonSpacing - button_size.width(),
505 (NonClientTopBorderHeight() - button_size.height()) / 2, 490 (NonClientTopBorderHeight() - button_size.height()) / 2,
506 button_size.width(), 491 button_size.width(),
507 button_size.height()); 492 button_size.height());
508 right = minimize_or_restore_button->x(); 493 right = minimize_or_restore_button->x();
509 } 494 }
510 495
511 // Layout the icon. 496 // Layout the icon.
512 int icon_y = (NonClientTopBorderHeight() - kIconSize) / 2; 497 int icon_y = (NonClientTopBorderHeight() - kIconSize) / 2;
513 title_icon_->SetBounds( 498 title_icon_->SetBounds(
514 NonClientBorderThickness() + kIconAndBorderSpacing, 499 NonClientBorderThickness() + kIconAndBorderSpacing,
515 icon_y, 500 icon_y,
516 kIconSize, 501 kIconSize,
517 kIconSize); 502 kIconSize);
518 503
519 // Layout the title. 504 // Layout the title.
520 if (show_title_label) { 505 int title_x = title_icon_->bounds().right() + kTitleSpacing;
521 int title_x = title_icon_->bounds().right() + kTitleSpacing; 506 int title_height = BrowserFrame::GetTitleFont().GetHeight();
522 int title_height = BrowserFrame::GetTitleFont().GetHeight(); 507 title_label_->SetBounds(
523 title_label_->SetBounds( 508 title_x,
524 title_x, 509 icon_y + ((kIconSize - title_height - 1) / 2),
525 icon_y + ((kIconSize - title_height - 1) / 2), 510 std::max(0, right - kTitleSpacing - title_x),
526 std::max(0, right - kTitleSpacing - title_x), 511 title_height);
527 title_height);
528 }
529 512
530 // Calculate the client area bounds. 513 // Calculate the client area bounds.
531 int top_height = NonClientTopBorderHeight(); 514 int top_height = NonClientTopBorderHeight();
532 int border_thickness = NonClientBorderThickness(); 515 int border_thickness = NonClientBorderThickness();
533 client_view_bounds_.SetRect( 516 client_view_bounds_.SetRect(
534 border_thickness, 517 border_thickness,
535 top_height, 518 top_height,
536 std::max(0, width() - (2 * border_thickness)), 519 std::max(0, width() - (2 * border_thickness)),
537 std::max(0, height() - top_height - border_thickness)); 520 std::max(0, height() - top_height - border_thickness));
538 } 521 }
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
804 } 787 }
805 788
806 string16 PanelBrowserFrameView::GetTitleText() const { 789 string16 PanelBrowserFrameView::GetTitleText() const {
807 return frame()->widget_delegate()->GetWindowTitle(); 790 return frame()->widget_delegate()->GetWindowTitle();
808 } 791 }
809 792
810 void PanelBrowserFrameView::UpdateTitleBar() { 793 void PanelBrowserFrameView::UpdateTitleBar() {
811 title_label_->SetText(GetTitleText()); 794 title_label_->SetText(GetTitleText());
812 } 795 }
813 796
797 void PanelBrowserFrameView::UpdateTitleBarMinimizeRestoreButtonVisibility() {
798 Panel* panel = panel_browser_view_->panel();
799 minimize_button_->SetVisible(panel->CanMinimize());
800 restore_button_->SetVisible(panel->CanRestore());
801 Layout();
Dmitry Titov 2012/05/02 03:23:08 Maybe we should layout both buttons in Layout() me
jennb 2012/05/02 19:10:35 Done.
802 }
803
814 bool PanelBrowserFrameView::CanResize() const { 804 bool PanelBrowserFrameView::CanResize() const {
815 return panel_browser_view_->panel()->CanResizeByMouse() != 805 return panel_browser_view_->panel()->CanResizeByMouse() !=
816 panel::NOT_RESIZABLE; 806 panel::NOT_RESIZABLE;
817 } 807 }
818 808
819 bool PanelBrowserFrameView::IsShowingTitlebarOnly() const { 809 bool PanelBrowserFrameView::IsShowingTitlebarOnly() const {
820 return height() <= kTitlebarHeight; 810 return height() <= kTitlebarHeight;
821 } 811 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698