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

Side by Side Diff: chrome/browser/views/frame/opaque_non_client_view.cc

Issue 16219: Make Maximized Mode Not Suck, part 1 (checkpoint).... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 12 years 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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/views/frame/opaque_non_client_view.h" 5 #include "chrome/browser/views/frame/opaque_non_client_view.h"
6 6
7 #include "chrome/app/theme/theme_resources.h" 7 #include "chrome/app/theme/theme_resources.h"
8 #include "chrome/browser/tab_contents.h" 8 #include "chrome/browser/tab_contents.h"
9 #include "chrome/browser/views/frame/browser_view.h" 9 #include "chrome/browser/views/frame/browser_view.h"
10 #include "chrome/browser/views/tabs/tab_strip.h" 10 #include "chrome/browser/views/tabs/tab_strip.h"
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 SkBitmap OpaqueNonClientView::app_top_right_; 285 SkBitmap OpaqueNonClientView::app_top_right_;
286 ChromeFont OpaqueNonClientView::title_font_; 286 ChromeFont OpaqueNonClientView::title_font_;
287 287
288 // The distance between the top of the window and the top of the window 288 // The distance between the top of the window and the top of the window
289 // controls when the window is restored. 289 // controls when the window is restored.
290 static const int kWindowControlsTopOffset = 1; 290 static const int kWindowControlsTopOffset = 1;
291 // The distance between the right edge of the window and the right edge of the 291 // The distance between the right edge of the window and the right edge of the
292 // right-most window control when the window is restored. 292 // right-most window control when the window is restored.
293 static const int kWindowControlsRightOffset = 4; 293 static const int kWindowControlsRightOffset = 4;
294 // The distance between the top of the window and the top of the window 294 // The distance between the top of the window and the top of the window
295 // controls when the window is maximized. 295 // controls' images when the window is maximized. We extend the clickable area
296 static const int kWindowControlsTopZoomedOffset = 4; 296 // all the way to the top of the window to obey Fitts' Law.
297 static const int kWindowControlsTopZoomedExtraHeight = 5;
297 // The distance between the right edge of the window and the right edge of the 298 // The distance between the right edge of the window and the right edge of the
298 // right-most window control when the window is maximized. 299 // right-most window control when the window is maximized.
299 static const int kWindowControlsRightZoomedOffset = 5; 300 static const int kWindowControlsRightZoomedOffset = 7;
300 // The distance between the top of the window and the title bar/tab strip when 301 // The distance between the left edge of the window and the left edge of the
301 // the window is maximized. 302 // window icon when a title-bar is showing.
302 static const int kWindowTopMarginZoomed = 1;
303 // The distance between the left edge of the window and the left of the window
304 // icon when a title-bar is showing.
305 static const int kWindowIconLeftOffset = 5; 303 static const int kWindowIconLeftOffset = 5;
306 // The distance between the top of the window and the top of the window icon 304 // The distance between the left edge of the window and the left edge of the
307 // when a title-bar is showing. 305 // window icon when a title-bar is showing and the window is maximized.
308 static const int kWindowIconTopOffset = 5; 306 static const int kWindowIconLeftZoomedOffset = 6;
307 // The distance between the top edge of the window and the top edge of the
308 // window icon when a title-bar is showing.
309 static const int kWindowIconTopOffset = 6;
310 // The distance between the top edge of the window and the top edge of the
311 // window icon when a title-bar is showing and the window is maximized.
312 static const int kWindowIconTopZoomedOffset = 8;
309 // The distance between the window icon and the window title when a title-bar 313 // The distance between the window icon and the window title when a title-bar
310 // is showing. 314 // is showing.
311 static const int kWindowIconTitleSpacing = 4; 315 static const int kWindowIconTitleSpacing = 4;
312 // The distance between the top of the window and the title text when a 316 // The distance between the top of the window and the title text when a
313 // title-bar is showing. 317 // title-bar is showing.
314 static const int kTitleTopOffset = 6; 318 static const int kTitleTopOffset = 6;
319 // The distance between the top of the window and the title text when a
320 // title-bar is showing and the window is maximized.
321 static const int kTitleTopZoomedOffset = 8;
315 // The distance between the right edge of the title text bounding box and the 322 // The distance between the right edge of the title text bounding box and the
316 // left edge of the distributor logo. 323 // left edge of the distributor logo.
317 static const int kTitleLogoSpacing = 5; 324 static const int kTitleLogoSpacing = 5;
318 // The distance between the bottom of the title text and the TabStrip when a 325 // The distance between the bottom of the title text and the TabStrip when a
319 // title-bar is showing. 326 // title-bar is showing.
320 static const int kTitleBottomSpacing = 6; 327 static const int kTitleBottomSpacing = 6;
321 // The distance between the top edge of the window and the TabStrip when there 328 // The distance between the top edge of the window and the TabStrip when there
322 // is no title-bar showing, and the window is restored. 329 // is no title-bar showing, and the window is restored.
323 static const int kNoTitleTopSpacing = 15; 330 static const int kNoTitleTopSpacing = 15;
324 // The distance between the top edge of the window and the TabStrip when there 331 // The distance between the top edge of the window and the TabStrip when there
325 // is no title-bar showing, and the window is maximized. 332 // is no title-bar showing, and the window is maximized.
326 static const int kNoTitleZoomedTopSpacing = 1; 333 static const int kNoTitleZoomedTopSpacing = 4;
334 // The number of pixels to shave off the bottom of the images making up the top
335 // client edge when the window is maximized, so we only draw a shadowed titlebar
336 // and not a grey client area border below it.
337 static const int kClientEdgeZoomedOffset = 1;
327 // The amount of horizontal and vertical distance from a corner of the window 338 // The amount of horizontal and vertical distance from a corner of the window
328 // within which a mouse-drive resize operation will resize the window in two 339 // within which a mouse-drive resize operation will resize the window in two
329 // dimensions. 340 // dimensions.
330 static const int kResizeAreaCornerSize = 16; 341 static const int kResizeAreaCornerSize = 16;
331 // The width of the sizing border on the left and right edge of the window. 342 // The width of the sizing border on the left and right edge of the window.
332 static const int kWindowHorizontalBorderSize = 5; 343 static const int kWindowHorizontalBorderSize = 5;
344 // The width of the sizing border on the left and right edge of the window when
345 // the window is maximized.
346 static const int kWindowHorizontalBorderZoomedSize = 4;
333 // The height of the sizing border at the top edge of the window 347 // The height of the sizing border at the top edge of the window
334 static const int kWindowVerticalBorderTopSize = 3; 348 static const int kWindowVerticalBorderTopSize = 3;
335 // The height of the sizing border on the bottom edge of the window. 349 // The height of the sizing border on the bottom edge of the window.
336 static const int kWindowVerticalBorderBottomSize = 5; 350 static const int kWindowVerticalBorderBottomSize = 5;
351 // The distance between the bottom edge of the window image and the true bottom
352 // edge of the window when the window is maximized.
353 static const int kWindowBottomZoomedSpacing = 4;
337 // The width and height of the window icon that appears at the top left of 354 // The width and height of the window icon that appears at the top left of
338 // pop-up and app windows. 355 // pop-up and app windows.
339 static const int kWindowIconSize = 16; 356 static const int kWindowIconSize = 16;
340 // The horizontal distance of the right edge of the distributor logo from the 357 // The horizontal distance of the right edge of the distributor logo from the
341 // left edge of the left-most window control. 358 // left edge of the left-most window control.
342 static const int kDistributorLogoHorizontalOffset = 7; 359 static const int kDistributorLogoHorizontalOffset = 7;
343 // The vertical distance of the top of the distributor logo from the top edge 360 // The vertical distance of the top of the distributor logo from the top edge
344 // of the window. 361 // of the window.
345 static const int kDistributorLogoVerticalOffset = 3; 362 static const int kDistributorLogoVerticalOffset = 3;
346 // The distance from the left of the window of the OTR avatar icon. 363 // The distance from the left of the window of the OTR avatar icon.
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 if (browser_view_->ShouldShowWindowTitle()) 464 if (browser_view_->ShouldShowWindowTitle())
448 InitAppWindowResources(); 465 InitAppWindowResources();
449 } 466 }
450 467
451 OpaqueNonClientView::~OpaqueNonClientView() { 468 OpaqueNonClientView::~OpaqueNonClientView() {
452 } 469 }
453 470
454 gfx::Rect OpaqueNonClientView::GetWindowBoundsForClientBounds( 471 gfx::Rect OpaqueNonClientView::GetWindowBoundsForClientBounds(
455 const gfx::Rect& client_bounds) { 472 const gfx::Rect& client_bounds) {
456 int top_height = CalculateNonClientTopHeight(); 473 int top_height = CalculateNonClientTopHeight();
457 int window_x = std::max(0, client_bounds.x() - kWindowHorizontalBorderSize); 474 int horizontal_border = frame_->IsMaximized() ?
475 kWindowHorizontalBorderZoomedSize : kWindowHorizontalBorderSize;
476 int window_x = std::max(0, client_bounds.x() - horizontal_border);
458 int window_y = std::max(0, client_bounds.y() - top_height); 477 int window_y = std::max(0, client_bounds.y() - top_height);
459 int window_w = client_bounds.width() + (2 * kWindowHorizontalBorderSize); 478 int window_w = client_bounds.width() + (2 * horizontal_border);
460 int window_h = 479 int window_h =
461 client_bounds.height() + top_height + kWindowVerticalBorderBottomSize; 480 client_bounds.height() + top_height + kWindowVerticalBorderBottomSize;
462 return gfx::Rect(window_x, window_y, window_w, window_h); 481 return gfx::Rect(window_x, window_y, window_w, window_h);
463 } 482 }
464 483
465 gfx::Rect OpaqueNonClientView::GetBoundsForTabStrip(TabStrip* tabstrip) { 484 gfx::Rect OpaqueNonClientView::GetBoundsForTabStrip(TabStrip* tabstrip) {
466 int tabstrip_height = tabstrip->GetPreferredHeight(); 485 int tabstrip_height = tabstrip->GetPreferredHeight();
467 int tabstrip_x = otr_avatar_bounds_.right(); 486 int tabstrip_x = otr_avatar_bounds_.right();
468 int tabstrip_width = minimize_button_->x() - tabstrip_x; 487 int tabstrip_width = minimize_button_->x() - tabstrip_x;
469 if (frame_->IsMaximized()) 488 if (frame_->IsMaximized())
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 frame_->ExecuteSystemMenuCommand(SC_CLOSE); 525 frame_->ExecuteSystemMenuCommand(SC_CLOSE);
507 } 526 }
508 } 527 }
509 528
510 /////////////////////////////////////////////////////////////////////////////// 529 ///////////////////////////////////////////////////////////////////////////////
511 // OpaqueNonClientView, views::NonClientView implementation: 530 // OpaqueNonClientView, views::NonClientView implementation:
512 531
513 gfx::Rect OpaqueNonClientView::CalculateClientAreaBounds(int width, 532 gfx::Rect OpaqueNonClientView::CalculateClientAreaBounds(int width,
514 int height) const { 533 int height) const {
515 int top_margin = CalculateNonClientTopHeight(); 534 int top_margin = CalculateNonClientTopHeight();
516 return gfx::Rect(kWindowHorizontalBorderSize, top_margin, 535 int horizontal_border = frame_->IsMaximized() ?
517 std::max(0, width - (2 * kWindowHorizontalBorderSize)), 536 kWindowHorizontalBorderZoomedSize : kWindowHorizontalBorderSize;
537 return gfx::Rect(horizontal_border, top_margin,
538 std::max(0, width - (2 * horizontal_border)),
518 std::max(0, height - top_margin - kWindowVerticalBorderBottomSize)); 539 std::max(0, height - top_margin - kWindowVerticalBorderBottomSize));
519 } 540 }
520 541
521 gfx::Size OpaqueNonClientView::CalculateWindowSizeForClientSize( 542 gfx::Size OpaqueNonClientView::CalculateWindowSizeForClientSize(
522 int width, 543 int width,
523 int height) const { 544 int height) const {
524 int top_margin = CalculateNonClientTopHeight(); 545 int top_margin = CalculateNonClientTopHeight();
525 return gfx::Size(width + (2 * kWindowHorizontalBorderSize), 546 int horizontal_border = frame_->IsMaximized() ?
547 kWindowHorizontalBorderZoomedSize : kWindowHorizontalBorderSize;
548 return gfx::Size(width + (2 * horizontal_border),
526 height + top_margin + kWindowVerticalBorderBottomSize); 549 height + top_margin + kWindowVerticalBorderBottomSize);
527 } 550 }
528 551
529 CPoint OpaqueNonClientView::GetSystemMenuPoint() const { 552 CPoint OpaqueNonClientView::GetSystemMenuPoint() const {
530 CPoint system_menu_point(icon_bounds_.x(), icon_bounds_.bottom()); 553 CPoint system_menu_point(icon_bounds_.x(), icon_bounds_.bottom());
531 MapWindowPoints(frame_->GetHWND(), HWND_DESKTOP, &system_menu_point, 1); 554 MapWindowPoints(frame_->GetHWND(), HWND_DESKTOP, &system_menu_point, 1);
532 return system_menu_point; 555 return system_menu_point;
533 } 556 }
534 557
535 int OpaqueNonClientView::NonClientHitTest(const gfx::Point& point) { 558 int OpaqueNonClientView::NonClientHitTest(const gfx::Point& point) {
(...skipping 16 matching lines...) Expand all
552 return HTMAXBUTTON; 575 return HTMAXBUTTON;
553 button_bounds = minimize_button_->GetBounds(APPLY_MIRRORING_TRANSFORMATION); 576 button_bounds = minimize_button_->GetBounds(APPLY_MIRRORING_TRANSFORMATION);
554 if (button_bounds.Contains(point)) 577 if (button_bounds.Contains(point))
555 return HTMINBUTTON; 578 return HTMINBUTTON;
556 if (window_icon_) { 579 if (window_icon_) {
557 button_bounds = window_icon_->GetBounds(APPLY_MIRRORING_TRANSFORMATION); 580 button_bounds = window_icon_->GetBounds(APPLY_MIRRORING_TRANSFORMATION);
558 if (button_bounds.Contains(point)) 581 if (button_bounds.Contains(point))
559 return HTSYSMENU; 582 return HTSYSMENU;
560 } 583 }
561 584
585 int horizontal_border = frame_->IsMaximized() ?
586 kWindowHorizontalBorderZoomedSize : kWindowHorizontalBorderSize;
562 component = GetHTComponentForFrame( 587 component = GetHTComponentForFrame(
563 point, 588 point,
564 kWindowHorizontalBorderSize, 589 horizontal_border,
565 kResizeAreaCornerSize, 590 kResizeAreaCornerSize,
566 kWindowVerticalBorderTopSize, 591 kWindowVerticalBorderTopSize,
567 frame_->window_delegate()->CanResize()); 592 frame_->window_delegate()->CanResize());
568 if (component == HTNOWHERE) { 593 if (component == HTNOWHERE) {
569 // Finally fall back to the caption. 594 // Finally fall back to the caption.
570 if (bounds().Contains(point)) 595 if (bounds().Contains(point))
571 component = HTCAPTION; 596 component = HTCAPTION;
572 // Otherwise, the point is outside the window's bounds. 597 // Otherwise, the point is outside the window's bounds.
573 } 598 }
574 return component; 599 return component;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
612 // Clip the content area out of the rendering. 637 // Clip the content area out of the rendering.
613 gfx::Rect contents_bounds = browser_view_->GetClientAreaBounds(); 638 gfx::Rect contents_bounds = browser_view_->GetClientAreaBounds();
614 SkRect clip; 639 SkRect clip;
615 clip.set(SkIntToScalar(contents_bounds.x()), 640 clip.set(SkIntToScalar(contents_bounds.x()),
616 SkIntToScalar(contents_bounds.y()), 641 SkIntToScalar(contents_bounds.y()),
617 SkIntToScalar(contents_bounds.right()), 642 SkIntToScalar(contents_bounds.right()),
618 SkIntToScalar(contents_bounds.bottom())); 643 SkIntToScalar(contents_bounds.bottom()));
619 canvas->clipRect(clip, SkRegion::kDifference_Op); 644 canvas->clipRect(clip, SkRegion::kDifference_Op);
620 645
621 // Render the remaining portions of the non-client area. 646 // Render the remaining portions of the non-client area.
622 if (frame_->IsMaximized()) { 647 if (frame_->IsMaximized())
623 PaintMaximizedFrameBorder(canvas); 648 PaintMaximizedFrameBorder(canvas);
624 } else { 649 else
625 PaintFrameBorder(canvas); 650 PaintFrameBorder(canvas);
626 }
627 PaintOTRAvatar(canvas); 651 PaintOTRAvatar(canvas);
628 PaintDistributorLogo(canvas); 652 PaintDistributorLogo(canvas);
629 PaintTitleBar(canvas); 653 PaintTitleBar(canvas);
630 PaintToolbarBackground(canvas); 654 PaintToolbarBackground(canvas);
631 PaintClientEdge(canvas); 655 PaintClientEdge(canvas);
632 } 656 }
633 657
634 void OpaqueNonClientView::Layout() { 658 void OpaqueNonClientView::Layout() {
635 LayoutWindowControls(); 659 LayoutWindowControls();
636 LayoutOTRAvatar(); 660 LayoutOTRAvatar();
637 LayoutDistributorLogo(); 661 LayoutDistributorLogo();
638 LayoutTitleBar(); 662 LayoutTitleBar();
639 LayoutClientView(); 663 LayoutClientView();
640 } 664 }
641 665
642 gfx::Size OpaqueNonClientView::GetPreferredSize() { 666 gfx::Size OpaqueNonClientView::GetPreferredSize() {
667 int horizontal_border = frame_->IsMaximized() ?
668 kWindowHorizontalBorderZoomedSize : kWindowHorizontalBorderSize;
643 gfx::Size prefsize = frame_->client_view()->GetPreferredSize(); 669 gfx::Size prefsize = frame_->client_view()->GetPreferredSize();
644 prefsize.Enlarge(2 * kWindowHorizontalBorderSize, 670 prefsize.Enlarge(2 * horizontal_border,
645 CalculateNonClientTopHeight() + 671 CalculateNonClientTopHeight() +
646 kWindowVerticalBorderBottomSize); 672 kWindowVerticalBorderBottomSize);
647 return prefsize; 673 return prefsize;
648 } 674 }
649 675
650 views::View* OpaqueNonClientView::GetViewForPoint(const gfx::Point& point, 676 views::View* OpaqueNonClientView::GetViewForPoint(const gfx::Point& point,
651 bool can_create_floating) { 677 bool can_create_floating) {
652 // We override this function because the ClientView can overlap the non - 678 // We override this function because the ClientView can overlap the non -
653 // client view, making it impossible to click on the window controls. We need 679 // client view, making it impossible to click on the window controls. We need
654 // to ensure the window controls are checked _first_. 680 // to ensure the window controls are checked _first_.
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
754 780
755 // Left. 781 // Left.
756 top_stack_height = top_left_corner->height(); 782 top_stack_height = top_left_corner->height();
757 canvas->TileImageInt(*left_edge, 0, top_stack_height, left_edge->width(), 783 canvas->TileImageInt(*left_edge, 0, top_stack_height, left_edge->width(),
758 height() - top_stack_height - 784 height() - top_stack_height -
759 bottom_left_corner->height()); 785 bottom_left_corner->height());
760 } 786 }
761 787
762 void OpaqueNonClientView::PaintMaximizedFrameBorder(ChromeCanvas* canvas) { 788 void OpaqueNonClientView::PaintMaximizedFrameBorder(ChromeCanvas* canvas) {
763 SkBitmap* top_edge = resources()->GetPartBitmap(FRAME_MAXIMIZED_TOP_EDGE); 789 SkBitmap* top_edge = resources()->GetPartBitmap(FRAME_MAXIMIZED_TOP_EDGE);
790 canvas->TileImageInt(*top_edge, 0, kNoTitleZoomedTopSpacing, width(),
791 top_edge->height());
792
764 SkBitmap* bottom_edge = 793 SkBitmap* bottom_edge =
765 resources()->GetPartBitmap(FRAME_MAXIMIZED_BOTTOM_EDGE); 794 resources()->GetPartBitmap(FRAME_MAXIMIZED_BOTTOM_EDGE);
766 canvas->TileImageInt(*top_edge, 0, 0, width(), top_edge->height()); 795 canvas->TileImageInt(*bottom_edge, 0,
767 canvas->TileImageInt(*bottom_edge, 0, height() - bottom_edge->height(), 796 height() - bottom_edge->height() - kWindowBottomZoomedSpacing, width(),
768 width(), bottom_edge->height()); 797 bottom_edge->height());
769 } 798 }
770 799
771 void OpaqueNonClientView::PaintOTRAvatar(ChromeCanvas* canvas) { 800 void OpaqueNonClientView::PaintOTRAvatar(ChromeCanvas* canvas) {
772 if (browser_view_->ShouldShowOffTheRecordAvatar()) { 801 if (browser_view_->ShouldShowOffTheRecordAvatar()) {
773 int icon_x = MirroredLeftPointForRect(otr_avatar_bounds_); 802 int icon_x = MirroredLeftPointForRect(otr_avatar_bounds_);
774 canvas->DrawBitmapInt(browser_view_->GetOTRAvatarIcon(), icon_x, 803 canvas->DrawBitmapInt(browser_view_->GetOTRAvatarIcon(), icon_x,
775 otr_avatar_bounds_.y()); 804 otr_avatar_bounds_.y());
776 } 805 }
777 } 806 }
778 807
779 void OpaqueNonClientView::PaintDistributorLogo(ChromeCanvas* canvas) { 808 void OpaqueNonClientView::PaintDistributorLogo(ChromeCanvas* canvas) {
780 // The distributor logo is only painted when the frame is not maximized and 809 // The distributor logo is only painted when the frame is not maximized and
781 // when we actually have a logo. 810 // when we actually have a logo.
782 if (!frame_->IsMaximized() && !frame_->IsMinimized() && 811 if (!frame_->IsMaximized() && !distributor_logo_.empty()) {
783 !distributor_logo_.empty()) {
784 int logo_x = MirroredLeftPointForRect(logo_bounds_); 812 int logo_x = MirroredLeftPointForRect(logo_bounds_);
785 canvas->DrawBitmapInt(distributor_logo_, logo_x, logo_bounds_.y()); 813 canvas->DrawBitmapInt(distributor_logo_, logo_x, logo_bounds_.y());
786 } 814 }
787 } 815 }
788 816
789 void OpaqueNonClientView::PaintTitleBar(ChromeCanvas* canvas) { 817 void OpaqueNonClientView::PaintTitleBar(ChromeCanvas* canvas) {
790 // The window icon is painted by the TabIconView. 818 // The window icon is painted by the TabIconView.
791 views::WindowDelegate* d = frame_->window_delegate(); 819 views::WindowDelegate* d = frame_->window_delegate();
792 if (d->ShouldShowWindowTitle()) { 820 if (d->ShouldShowWindowTitle()) {
793 int title_x = MirroredLeftPointForRect(title_bounds_); 821 int title_x = MirroredLeftPointForRect(title_bounds_);
(...skipping 24 matching lines...) Expand all
818 toolbar_bounds.y()); 846 toolbar_bounds.y());
819 canvas->TileImageInt(*toolbar_center, 847 canvas->TileImageInt(*toolbar_center,
820 toolbar_bounds.x(), toolbar_bounds.y(), 848 toolbar_bounds.x(), toolbar_bounds.y(),
821 toolbar_bounds.width(), toolbar_center->height()); 849 toolbar_bounds.width(), toolbar_center->height());
822 canvas->DrawBitmapInt(*toolbar_right, toolbar_bounds.right(), 850 canvas->DrawBitmapInt(*toolbar_right, toolbar_bounds.right(),
823 toolbar_bounds.y()); 851 toolbar_bounds.y());
824 } 852 }
825 } 853 }
826 854
827 void OpaqueNonClientView::PaintClientEdge(ChromeCanvas* canvas) { 855 void OpaqueNonClientView::PaintClientEdge(ChromeCanvas* canvas) {
856 // The toolbar draws a client edge along its own bottom edge when it's
857 // visible. However, it only draws this for the width of the actual client
858 // area, leaving a gap at the left and right edges:
859 //
860 // | Toolbar | <-- part of toolbar
861 // ----- (toolbar client edge) ----- <-- gap
862 // | Client area | <-- right client edge
863 //
864 // To address this, we extend the left and right client edges up one pixel to
865 // fill the gap, by pretending the toolbar is one pixel shorter than it really
866 // is.
867 //
868 // Notes:
869 // * This isn't strictly necessary in maximized mode, where the left and right
870 // edges aren't drawn, but it's simpler to not bother checking that.
871 // * We can get away with this hackery because we only draw a top edge when
872 // there is no toolbar. If we tried to draw a top edge over the toolbar's
873 // top edge, we'd need a different solution.
874 gfx::Rect toolbar_bounds = browser_view_->GetToolbarBounds();
875 if (browser_view_->IsToolbarVisible())
876 toolbar_bounds.set_height(std::max(0, toolbar_bounds.height() - 1));
877 int client_area_top = frame_->client_view()->y() + toolbar_bounds.bottom();
878
879 // When we don't have a toolbar to draw a top edge for us, draw a top edge.
880 gfx::Rect client_area_bounds = browser_view_->GetClientAreaBounds();
881 if (!browser_view_->IsToolbarVisible()) {
882 // This hack is necessary because the top center bitmap is shorter than the
883 // top left and right bitmaps. We need their top edges to line up, and we
884 // need the left and right edges to start below the corners' bottoms.
885 // TODO(pkasting): If we just make the bitmaps the same height, a la the
886 // bottom corners/center, we can remove this hack.
887 int top_edge_y = client_area_top - app_top_center_.height() +
888 (frame_->IsMaximized() ? kClientEdgeZoomedOffset : 0);
889 client_area_top = top_edge_y + app_top_left_.height();
890 canvas->DrawBitmapInt(app_top_left_,
891 client_area_bounds.x() - app_top_left_.width(),
892 top_edge_y);
893 canvas->TileImageInt(app_top_center_, client_area_bounds.x(), top_edge_y,
894 client_area_bounds.width(), app_top_center_.height());
895 canvas->DrawBitmapInt(app_top_right_, client_area_bounds.right(),
896 top_edge_y);
897 }
898
899 // In maximized mode, we don't need side or bottom client edges.
900 if (frame_->IsMaximized())
901 return;
902
903 int client_area_bottom =
904 std::max(client_area_top, height() - kWindowVerticalBorderBottomSize);
905 int client_area_height = client_area_bottom - client_area_top;
828 SkBitmap* right = resources()->GetPartBitmap(FRAME_CLIENT_EDGE_RIGHT); 906 SkBitmap* right = resources()->GetPartBitmap(FRAME_CLIENT_EDGE_RIGHT);
829 SkBitmap* bottom_right = 907 canvas->TileImageInt(*right, client_area_bounds.right(), client_area_top,
830 resources()->GetPartBitmap(FRAME_CLIENT_EDGE_BOTTOM_RIGHT); 908 right->width(), client_area_height);
909
910 canvas->DrawBitmapInt(
911 *resources()->GetPartBitmap(FRAME_CLIENT_EDGE_BOTTOM_RIGHT),
912 client_area_bounds.right(), client_area_bottom);
913
831 SkBitmap* bottom = resources()->GetPartBitmap(FRAME_CLIENT_EDGE_BOTTOM); 914 SkBitmap* bottom = resources()->GetPartBitmap(FRAME_CLIENT_EDGE_BOTTOM);
915 canvas->TileImageInt(*bottom, client_area_bounds.x(),
916 client_area_bottom, client_area_bounds.width(),
917 bottom->height());
918
832 SkBitmap* bottom_left = 919 SkBitmap* bottom_left =
833 resources()->GetPartBitmap(FRAME_CLIENT_EDGE_BOTTOM_LEFT); 920 resources()->GetPartBitmap(FRAME_CLIENT_EDGE_BOTTOM_LEFT);
921 canvas->DrawBitmapInt(*bottom_left,
922 client_area_bounds.x() - bottom_left->width(), client_area_bottom);
923
834 SkBitmap* left = resources()->GetPartBitmap(FRAME_CLIENT_EDGE_LEFT); 924 SkBitmap* left = resources()->GetPartBitmap(FRAME_CLIENT_EDGE_LEFT);
835
836 // The toolbar renders its own client edge in PaintToolbarBackground, however
837 // there are other bands that need to have a client edge rendered along their
838 // sides, such as the Bookmark bar, infobars, etc.
839 gfx::Rect toolbar_bounds = browser_view_->GetToolbarBounds();
840 gfx::Rect client_area_bounds = browser_view_->GetClientAreaBounds();
841 // For some reason things don't line up quite right, so we add and subtract
842 // pixels here and there for aesthetic bliss.
843 // Enlarge the client area to include the toolbar, since the top edge of
844 // the client area is the toolbar background and the client edge renders
845 // the left and right sides of the toolbar background.
846 int fudge = frame_->window_delegate()->ShouldShowWindowTitle() ? 0 : 1;
847 client_area_bounds.SetRect(
848 client_area_bounds.x(),
849 frame_->client_view()->y() + toolbar_bounds.bottom() - fudge,
850 client_area_bounds.width(),
851 std::max(0, height() - frame_->client_view()->y() -
852 toolbar_bounds.bottom() + fudge - kWindowVerticalBorderBottomSize));
853
854 // Now the fudge inverts for app vs browser windows.
855 fudge = 1 - fudge;
856 canvas->TileImageInt(*right, client_area_bounds.right(),
857 client_area_bounds.y() + fudge,
858 right->width(), client_area_bounds.height() - fudge);
859 canvas->DrawBitmapInt(*bottom_right, client_area_bounds.right(),
860 client_area_bounds.bottom());
861 canvas->TileImageInt(*bottom, client_area_bounds.x(),
862 client_area_bounds.bottom(),
863 client_area_bounds.width(), bottom_right->height());
864 canvas->DrawBitmapInt(*bottom_left,
865 client_area_bounds.x() - bottom_left->width(),
866 client_area_bounds.bottom());
867 canvas->TileImageInt(*left, client_area_bounds.x() - left->width(), 925 canvas->TileImageInt(*left, client_area_bounds.x() - left->width(),
868 client_area_bounds.y() + fudge, 926 client_area_top, left->width(), client_area_height);
869 left->width(), client_area_bounds.height() - fudge);
870
871 if (frame_->window_delegate()->ShouldShowWindowTitle()) {
872 canvas->DrawBitmapInt(app_top_left_,
873 client_area_bounds.x() - app_top_left_.width(),
874 client_area_bounds.y() - app_top_left_.height() +
875 fudge);
876 canvas->TileImageInt(app_top_center_, client_area_bounds.x(),
877 client_area_bounds.y() - app_top_center_.height(),
878 client_area_bounds.width(), app_top_center_.height());
879 canvas->DrawBitmapInt(app_top_right_, client_area_bounds.right(),
880 client_area_bounds.y() - app_top_right_.height() +
881 fudge);
882 }
883 } 927 }
884 928
885 void OpaqueNonClientView::LayoutWindowControls() { 929 void OpaqueNonClientView::LayoutWindowControls() {
886 gfx::Size ps; 930 // TODO(pkasting): This function is almost identical to
887 if (frame_->IsMaximized() || frame_->IsMinimized()) { 931 // DefaultNonClientView::LayoutWindowControls(), they should be combined.
888 maximize_button_->SetVisible(false); 932 close_button_->SetImageAlignment(views::Button::ALIGN_LEFT,
889 restore_button_->SetVisible(true); 933 views::Button::ALIGN_BOTTOM);
890 } 934 // Maximized buttons start at window top so that even if their images aren't
935 // drawn flush with the screen edge, they still obey Fitts' Law.
936 bool is_maximized = frame_->IsMaximized();
937 int top_offset = is_maximized ? 0 : kWindowControlsTopOffset;
938 int top_extra_height = is_maximized ? kWindowControlsTopZoomedExtraHeight : 0;
939 gfx::Size close_button_size = close_button_->GetPreferredSize();
940 close_button_->SetBounds(
941 (width() - close_button_size.width() - (is_maximized ?
942 kWindowControlsRightZoomedOffset : kWindowControlsRightOffset)),
943 top_offset,
944 (is_maximized ?
945 // We extend the maximized close button to the screen corner to obey
946 // Fitts' Law.
947 (close_button_size.width() + kWindowControlsRightZoomedOffset) :
948 close_button_size.width()),
949 (close_button_size.height() + top_extra_height));
891 950
892 if (frame_->IsMaximized()) { 951 // When the window is restored, we show a maximized button; otherwise, we show
893 ps = close_button_->GetPreferredSize(); 952 // a restore button.
894 close_button_->SetImageAlignment(views::Button::ALIGN_LEFT, 953 bool is_restored = !is_maximized && !frame_->IsMinimized();
895 views::Button::ALIGN_TOP); 954 views::Button* invisible_button = is_restored ?
896 close_button_->SetBounds( 955 restore_button_ : maximize_button_;
897 width() - ps.width() - kWindowControlsRightZoomedOffset, 956 invisible_button->SetVisible(false);
898 0, ps.width() + kWindowControlsRightZoomedOffset,
899 ps.height() + kWindowControlsTopZoomedOffset);
900 957
901 ps = restore_button_->GetPreferredSize(); 958 views::Button* visible_button = is_restored ?
902 restore_button_->SetImageAlignment(views::Button::ALIGN_LEFT, 959 maximize_button_ : restore_button_;
903 views::Button::ALIGN_TOP); 960 visible_button->SetVisible(true);
904 restore_button_->SetBounds(close_button_->x() - ps.width(), 0, ps.width(), 961 visible_button->SetImageAlignment(views::Button::ALIGN_LEFT,
905 ps.height() + kWindowControlsTopZoomedOffset); 962 views::Button::ALIGN_BOTTOM);
963 gfx::Size visible_button_size = visible_button->GetPreferredSize();
964 visible_button->SetBounds(close_button_->x() - visible_button_size.width(),
965 top_offset,
966 visible_button_size.width(),
967 visible_button_size.height() + top_extra_height);
906 968
907 ps = minimize_button_->GetPreferredSize(); 969 minimize_button_->SetVisible(true);
908 minimize_button_->SetImageAlignment(views::Button::ALIGN_LEFT, 970 minimize_button_->SetImageAlignment(views::Button::ALIGN_LEFT,
909 views::Button::ALIGN_TOP); 971 views::Button::ALIGN_BOTTOM);
910 minimize_button_->SetBounds(restore_button_->x() - ps.width(), 0, 972 gfx::Size minimize_button_size = minimize_button_->GetPreferredSize();
911 ps.width(), 973 minimize_button_->SetBounds(
912 ps.height() + kWindowControlsTopZoomedOffset); 974 visible_button->x() - minimize_button_size.width(),
913 } else if (frame_->IsMinimized()) { 975 top_offset,
914 ps = close_button_->GetPreferredSize(); 976 minimize_button_size.width(),
915 close_button_->SetImageAlignment(views::Button::ALIGN_LEFT, 977 minimize_button_size.height() + top_extra_height);
916 views::Button::ALIGN_BOTTOM);
917 close_button_->SetBounds(
918 width() - ps.width() - kWindowControlsRightZoomedOffset,
919 0, ps.width() + kWindowControlsRightZoomedOffset,
920 ps.height() + kWindowControlsTopZoomedOffset);
921
922 ps = restore_button_->GetPreferredSize();
923 restore_button_->SetImageAlignment(views::Button::ALIGN_LEFT,
924 views::Button::ALIGN_BOTTOM);
925 restore_button_->SetBounds(close_button_->x() - ps.width(), 0, ps.width(),
926 ps.height() + kWindowControlsTopZoomedOffset);
927
928 ps = minimize_button_->GetPreferredSize();
929 minimize_button_->SetImageAlignment(views::Button::ALIGN_LEFT,
930 views::Button::ALIGN_BOTTOM);
931 minimize_button_->SetBounds(restore_button_->x() - ps.width(), 0,
932 ps.width(),
933 ps.height() + kWindowControlsTopZoomedOffset);
934 } else {
935 ps = close_button_->GetPreferredSize();
936 close_button_->SetImageAlignment(views::Button::ALIGN_LEFT,
937 views::Button::ALIGN_TOP);
938 close_button_->SetBounds(width() - kWindowControlsRightOffset - ps.width(),
939 kWindowControlsTopOffset, ps.width(),
940 ps.height());
941
942 restore_button_->SetVisible(false);
943
944 maximize_button_->SetVisible(true);
945 ps = maximize_button_->GetPreferredSize();
946 maximize_button_->SetImageAlignment(views::Button::ALIGN_LEFT,
947 views::Button::ALIGN_TOP);
948 maximize_button_->SetBounds(close_button_->x() - ps.width(),
949 kWindowControlsTopOffset, ps.width(),
950 ps.height());
951
952 ps = minimize_button_->GetPreferredSize();
953 minimize_button_->SetImageAlignment(views::Button::ALIGN_LEFT,
954 views::Button::ALIGN_TOP);
955 minimize_button_->SetBounds(maximize_button_->x() - ps.width(),
956 kWindowControlsTopOffset, ps.width(),
957 ps.height());
958 }
959 } 978 }
960 979
961 void OpaqueNonClientView::LayoutOTRAvatar() { 980 void OpaqueNonClientView::LayoutOTRAvatar() {
962 int otr_x = 0; 981 int otr_x = 0;
963 int top_spacing = 982 int top_spacing =
964 frame_->IsMaximized() ? kNoTitleOTRZoomedTopSpacing : kNoTitleTopSpacing; 983 frame_->IsMaximized() ? kNoTitleOTRZoomedTopSpacing : kNoTitleTopSpacing;
965 int otr_y = browser_view_->GetTabStripHeight() + top_spacing; 984 int otr_y = browser_view_->GetTabStripHeight() + top_spacing;
966 int otr_width = 0; 985 int otr_width = 0;
967 int otr_height = 0; 986 int otr_height = 0;
968 if (browser_view_->ShouldShowOffTheRecordAvatar()) { 987 if (browser_view_->ShouldShowOffTheRecordAvatar()) {
969 SkBitmap otr_avatar_icon = browser_view_->GetOTRAvatarIcon(); 988 SkBitmap otr_avatar_icon = browser_view_->GetOTRAvatarIcon();
970 otr_width = otr_avatar_icon.width(); 989 otr_width = otr_avatar_icon.width();
971 otr_height = otr_avatar_icon.height(); 990 otr_height = otr_avatar_icon.height();
972 otr_x = kOTRAvatarIconMargin; 991 otr_x = kOTRAvatarIconMargin;
973 otr_y -= otr_avatar_icon.height() + 2; 992 otr_y -= otr_avatar_icon.height() + 2;
974 } 993 }
975 otr_avatar_bounds_.SetRect(otr_x, otr_y, otr_width, otr_height); 994 otr_avatar_bounds_.SetRect(otr_x, otr_y, otr_width, otr_height);
976 } 995 }
977 996
978 void OpaqueNonClientView::LayoutDistributorLogo() { 997 void OpaqueNonClientView::LayoutDistributorLogo() {
979 int logo_w = distributor_logo_.empty() ? 0 : distributor_logo_.width(); 998 int logo_w = distributor_logo_.empty() ? 0 : distributor_logo_.width();
980 int logo_h = distributor_logo_.empty() ? 0 : distributor_logo_.height(); 999 int logo_h = distributor_logo_.empty() ? 0 : distributor_logo_.height();
981 1000
982 int logo_x = 1001 int logo_x =
983 minimize_button_->x() - logo_w - kDistributorLogoHorizontalOffset; 1002 minimize_button_->x() - logo_w - kDistributorLogoHorizontalOffset;
984 logo_bounds_.SetRect(logo_x, kDistributorLogoVerticalOffset, logo_w, logo_h); 1003 logo_bounds_.SetRect(logo_x, kDistributorLogoVerticalOffset, logo_w, logo_h);
985 } 1004 }
986 1005
987 void OpaqueNonClientView::LayoutTitleBar() { 1006 void OpaqueNonClientView::LayoutTitleBar() {
988 int top_offset = frame_->IsMaximized() ? kWindowTopMarginZoomed : 0;
989 views::WindowDelegate* d = frame_->window_delegate();
990
991 // Size the window icon, even if it is hidden so we can size the title based 1007 // Size the window icon, even if it is hidden so we can size the title based
992 // on its position. 1008 // on its position.
993 bool show_icon = d->ShouldShowWindowIcon(); 1009 int left_offset = frame_->IsMaximized() ?
994 icon_bounds_.SetRect(kWindowIconLeftOffset, kWindowIconLeftOffset, 1010 kWindowIconLeftZoomedOffset : kWindowIconLeftOffset;
995 show_icon ? kWindowIconSize : 0, 1011 int top_offset = frame_->IsMaximized() ?
996 show_icon ? kWindowIconSize : 0); 1012 kWindowIconTopZoomedOffset : kWindowIconTopOffset;
1013 views::WindowDelegate* d = frame_->window_delegate();
1014 int icon_size = d->ShouldShowWindowIcon() ? kWindowIconSize : 0;
1015 icon_bounds_.SetRect(left_offset, top_offset, icon_size, icon_size);
1016 if (window_icon_)
1017 window_icon_->SetBounds(icon_bounds_);
997 1018
998 // Size the title, if visible. 1019 // Size the title, if visible.
999 if (d->ShouldShowWindowTitle()) { 1020 if (d->ShouldShowWindowTitle()) {
1000 int spacing = d->ShouldShowWindowIcon() ? kWindowIconTitleSpacing : 0; 1021 int spacing = d->ShouldShowWindowIcon() ? kWindowIconTitleSpacing : 0;
1001 int title_right = logo_bounds_.x() - kTitleLogoSpacing; 1022 int title_right = logo_bounds_.x() - kTitleLogoSpacing;
1002 int icon_right = icon_bounds_.right(); 1023 int icon_right = icon_bounds_.right();
1003 int title_left = icon_right + spacing; 1024 int title_left = icon_right + spacing;
1004 title_bounds_.SetRect(title_left, kTitleTopOffset + top_offset, 1025 int top_offset = frame_->IsMaximized() ?
1005 std::max(0, static_cast<int>(title_right - icon_right)), 1026 kTitleTopZoomedOffset : kTitleTopOffset;
1006 title_font_.height()); 1027 title_bounds_.SetRect(title_left, top_offset,
1007 1028 std::max(0, title_right - icon_right), title_font_.height());
1008 // Adjust the Y-position of the icon to be vertically centered within
1009 // the bounds of the title text.
1010 int delta_y = title_bounds_.height() - icon_bounds_.height();
1011 if (delta_y > 0)
1012 icon_bounds_.set_y(title_bounds_.y() + static_cast<int>(delta_y / 2));
1013 } 1029 }
1014
1015 // Do this last, after the icon has been moved.
1016 if (window_icon_)
1017 window_icon_->SetBounds(icon_bounds_);
1018 } 1030 }
1019 1031
1020 void OpaqueNonClientView::LayoutClientView() { 1032 void OpaqueNonClientView::LayoutClientView() {
1021 gfx::Rect client_bounds = CalculateClientAreaBounds(width(), height()); 1033 frame_->client_view()->SetBounds(CalculateClientAreaBounds(width(),
1022 frame_->client_view()->SetBounds(client_bounds); 1034 height()));
1023 } 1035 }
1024 1036
1025 // static 1037 // static
1026 void OpaqueNonClientView::InitClass() { 1038 void OpaqueNonClientView::InitClass() {
1027 static bool initialized = false; 1039 static bool initialized = false;
1028 if (!initialized) { 1040 if (!initialized) {
1029 active_resources_ = new ActiveWindowResources; 1041 active_resources_ = new ActiveWindowResources;
1030 inactive_resources_ = new InactiveWindowResources; 1042 inactive_resources_ = new InactiveWindowResources;
1031 1043
1032 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 1044 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
(...skipping 10 matching lines...) Expand all
1043 } 1055 }
1044 1056
1045 // static 1057 // static
1046 void OpaqueNonClientView::InitAppWindowResources() { 1058 void OpaqueNonClientView::InitAppWindowResources() {
1047 static bool initialized = false; 1059 static bool initialized = false;
1048 if (!initialized) { 1060 if (!initialized) {
1049 title_font_ = win_util::GetWindowTitleFont(); 1061 title_font_ = win_util::GetWindowTitleFont();
1050 initialized = true; 1062 initialized = true;
1051 } 1063 }
1052 } 1064 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698