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

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

Issue 18019: Pixel perfection on tabstrip for non-Aero frame. This gets both ends of the ... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 11 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
« no previous file with comments | « chrome/browser/views/frame/opaque_non_client_view.h ('k') | 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 357 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 static const int kOTRZoomedLeftOffset = 6; 368 static const int kOTRZoomedLeftOffset = 6;
369 // The distance between the top edge of the client area and the OTR avatar icon 369 // The distance between the top edge of the client area and the OTR avatar icon
370 // when the window is maximized. 370 // when the window is maximized.
371 static const int kOTRZoomedTopSpacing = 2; 371 static const int kOTRZoomedTopSpacing = 2;
372 // The distance between the bottom of the OTR avatar icon and the bottom of the 372 // The distance between the bottom of the OTR avatar icon and the bottom of the
373 // tabstrip. 373 // tabstrip.
374 static const int kOTRBottomSpacing = 2; 374 static const int kOTRBottomSpacing = 2;
375 // The number of pixels to crop off the top of the OTR image when the window is 375 // The number of pixels to crop off the top of the OTR image when the window is
376 // maximized. 376 // maximized.
377 static const int kOTRZoomedTopCrop = 4; 377 static const int kOTRZoomedTopCrop = 4;
378 // Horizontal distance between the right edge of the OTR avatar icon and the
379 // left edge of the tabstrip.
380 static const int kOTRTabStripSpacing = 2;
381 // Horizontal distance between the right edge of the new tab icon and the left
382 // edge of the window minimize icon when the window is restored.
383 static const int kNewTabIconMinimizeSpacing = 5;
378 // Horizontal distance between the right edge of the new tab icon and the left 384 // Horizontal distance between the right edge of the new tab icon and the left
379 // edge of the window minimize icon when the window is maximized. 385 // edge of the window minimize icon when the window is maximized.
380 static const int kNewTabIconWindowControlsSpacing = 10; 386 static const int kNewTabIconMinimizeZoomedSpacing = 16;
381 387
382 /////////////////////////////////////////////////////////////////////////////// 388 ///////////////////////////////////////////////////////////////////////////////
383 // OpaqueNonClientView, public: 389 // OpaqueNonClientView, public:
384 390
385 OpaqueNonClientView::OpaqueNonClientView(OpaqueFrame* frame, 391 OpaqueNonClientView::OpaqueNonClientView(OpaqueFrame* frame,
386 BrowserView* browser_view) 392 BrowserView* browser_view)
387 : NonClientView(), 393 : NonClientView(),
388 minimize_button_(new views::Button), 394 minimize_button_(new views::Button),
389 maximize_button_(new views::Button), 395 maximize_button_(new views::Button),
390 restore_button_(new views::Button), 396 restore_button_(new views::Button),
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 if (browser_view_->ShouldShowWindowTitle()) 480 if (browser_view_->ShouldShowWindowTitle())
475 InitAppWindowResources(); 481 InitAppWindowResources();
476 } 482 }
477 483
478 OpaqueNonClientView::~OpaqueNonClientView() { 484 OpaqueNonClientView::~OpaqueNonClientView() {
479 } 485 }
480 486
481 gfx::Rect OpaqueNonClientView::GetWindowBoundsForClientBounds( 487 gfx::Rect OpaqueNonClientView::GetWindowBoundsForClientBounds(
482 const gfx::Rect& client_bounds) { 488 const gfx::Rect& client_bounds) {
483 int top_height = CalculateNonClientTopHeight(); 489 int top_height = CalculateNonClientTopHeight();
484 int horizontal_border = frame_->IsMaximized() ? 490 int horizontal_border = HorizontalBorderSize();
485 kWindowHorizontalBorderZoomedSize : kWindowHorizontalBorderSize;
486 int window_x = std::max(0, client_bounds.x() - horizontal_border); 491 int window_x = std::max(0, client_bounds.x() - horizontal_border);
487 int window_y = std::max(0, client_bounds.y() - top_height); 492 int window_y = std::max(0, client_bounds.y() - top_height);
488 int window_w = client_bounds.width() + (2 * horizontal_border); 493 int window_w = client_bounds.width() + (2 * horizontal_border);
489 int window_h = 494 int window_h =
490 client_bounds.height() + top_height + kWindowVerticalBorderBottomSize; 495 client_bounds.height() + top_height + kWindowVerticalBorderBottomSize;
491 return gfx::Rect(window_x, window_y, window_w, window_h); 496 return gfx::Rect(window_x, window_y, window_w, window_h);
492 } 497 }
493 498
494 gfx::Rect OpaqueNonClientView::GetBoundsForTabStrip(TabStrip* tabstrip) { 499 gfx::Rect OpaqueNonClientView::GetBoundsForTabStrip(TabStrip* tabstrip) {
495 int tabstrip_x = otr_avatar_bounds_.right(); 500 int tabstrip_x = browser_view_->ShouldShowOffTheRecordAvatar() ?
496 int tabstrip_width = minimize_button_->x() - tabstrip_x; 501 (otr_avatar_bounds_.right() + kOTRTabStripSpacing) :
497 if (frame_->IsMaximized()) 502 HorizontalBorderSize();
498 tabstrip_width -= kNewTabIconWindowControlsSpacing; 503 int tabstrip_width = minimize_button_->x() - tabstrip_x -
499 return gfx::Rect(tabstrip_x, 0, std::max(0, tabstrip_width), 504 (frame_->IsMaximized() ?
500 tabstrip->GetPreferredHeight()); 505 kNewTabIconMinimizeZoomedSpacing : kNewTabIconMinimizeSpacing);
506 return gfx::Rect(tabstrip_x, CalculateNonClientTopHeight(),
507 std::max(0, tabstrip_width), tabstrip->GetPreferredHeight());
501 } 508 }
502 509
503 void OpaqueNonClientView::UpdateWindowIcon() { 510 void OpaqueNonClientView::UpdateWindowIcon() {
504 if (window_icon_) 511 if (window_icon_)
505 window_icon_->Update(); 512 window_icon_->Update();
506 } 513 }
507 514
508 /////////////////////////////////////////////////////////////////////////////// 515 ///////////////////////////////////////////////////////////////////////////////
509 // OpaqueNonClientView, TabIconView::TabContentsProvider implementation: 516 // OpaqueNonClientView, TabIconView::TabContentsProvider implementation:
510 517
(...skipping 23 matching lines...) Expand all
534 frame_->ExecuteSystemMenuCommand(SC_CLOSE); 541 frame_->ExecuteSystemMenuCommand(SC_CLOSE);
535 } 542 }
536 } 543 }
537 544
538 /////////////////////////////////////////////////////////////////////////////// 545 ///////////////////////////////////////////////////////////////////////////////
539 // OpaqueNonClientView, views::NonClientView implementation: 546 // OpaqueNonClientView, views::NonClientView implementation:
540 547
541 gfx::Rect OpaqueNonClientView::CalculateClientAreaBounds(int width, 548 gfx::Rect OpaqueNonClientView::CalculateClientAreaBounds(int width,
542 int height) const { 549 int height) const {
543 int top_margin = CalculateNonClientTopHeight(); 550 int top_margin = CalculateNonClientTopHeight();
544 int horizontal_border = frame_->IsMaximized() ? 551 int horizontal_border = HorizontalBorderSize();
545 kWindowHorizontalBorderZoomedSize : kWindowHorizontalBorderSize;
546 return gfx::Rect(horizontal_border, top_margin, 552 return gfx::Rect(horizontal_border, top_margin,
547 std::max(0, width - (2 * horizontal_border)), 553 std::max(0, width - (2 * horizontal_border)),
548 std::max(0, height - top_margin - kWindowVerticalBorderBottomSize)); 554 std::max(0, height - top_margin - kWindowVerticalBorderBottomSize));
549 } 555 }
550 556
551 gfx::Size OpaqueNonClientView::CalculateWindowSizeForClientSize( 557 gfx::Size OpaqueNonClientView::CalculateWindowSizeForClientSize(
552 int width, 558 int width,
553 int height) const { 559 int height) const {
554 int horizontal_border = frame_->IsMaximized() ? 560 return gfx::Size(width + (2 * HorizontalBorderSize()),
555 kWindowHorizontalBorderZoomedSize : kWindowHorizontalBorderSize;
556 return gfx::Size(width + (2 * horizontal_border),
557 height + CalculateNonClientTopHeight() + kWindowVerticalBorderBottomSize); 561 height + CalculateNonClientTopHeight() + kWindowVerticalBorderBottomSize);
558 } 562 }
559 563
560 CPoint OpaqueNonClientView::GetSystemMenuPoint() const { 564 CPoint OpaqueNonClientView::GetSystemMenuPoint() const {
561 CPoint system_menu_point(icon_bounds_.x(), icon_bounds_.bottom()); 565 CPoint system_menu_point(icon_bounds_.x(), icon_bounds_.bottom());
562 MapWindowPoints(frame_->GetHWND(), HWND_DESKTOP, &system_menu_point, 1); 566 MapWindowPoints(frame_->GetHWND(), HWND_DESKTOP, &system_menu_point, 1);
563 return system_menu_point; 567 return system_menu_point;
564 } 568 }
565 569
566 int OpaqueNonClientView::NonClientHitTest(const gfx::Point& point) { 570 int OpaqueNonClientView::NonClientHitTest(const gfx::Point& point) {
(...skipping 12 matching lines...) Expand all
579 if (maximize_button_->GetBounds(APPLY_MIRRORING_TRANSFORMATION).Contains( 583 if (maximize_button_->GetBounds(APPLY_MIRRORING_TRANSFORMATION).Contains(
580 point)) 584 point))
581 return HTMAXBUTTON; 585 return HTMAXBUTTON;
582 if (minimize_button_->GetBounds(APPLY_MIRRORING_TRANSFORMATION).Contains( 586 if (minimize_button_->GetBounds(APPLY_MIRRORING_TRANSFORMATION).Contains(
583 point)) 587 point))
584 return HTMINBUTTON; 588 return HTMINBUTTON;
585 if (window_icon_ && 589 if (window_icon_ &&
586 window_icon_->GetBounds(APPLY_MIRRORING_TRANSFORMATION).Contains(point)) 590 window_icon_->GetBounds(APPLY_MIRRORING_TRANSFORMATION).Contains(point))
587 return HTSYSMENU; 591 return HTSYSMENU;
588 592
589 int horizontal_border = frame_->IsMaximized() ? 593 int window_component = GetHTComponentForFrame(point, HorizontalBorderSize(),
590 kWindowHorizontalBorderZoomedSize : kWindowHorizontalBorderSize;
591 int window_component = GetHTComponentForFrame(point, horizontal_border,
592 kResizeAreaCornerSize, kWindowVerticalBorderTopSize, 594 kResizeAreaCornerSize, kWindowVerticalBorderTopSize,
593 frame_->window_delegate()->CanResize()); 595 frame_->window_delegate()->CanResize());
594 // Fall back to the caption if no other component matches. 596 // Fall back to the caption if no other component matches.
595 if ((window_component == HTNOWHERE) && bounds().Contains(point)) 597 if ((window_component == HTNOWHERE) && bounds().Contains(point))
596 window_component = HTCAPTION; 598 window_component = HTCAPTION;
597 return window_component; 599 return window_component;
598 } 600 }
599 601
600 void OpaqueNonClientView::GetWindowMask(const gfx::Size& size, 602 void OpaqueNonClientView::GetWindowMask(const gfx::Size& size,
601 gfx::Path* window_mask) { 603 gfx::Path* window_mask) {
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
658 660
659 void OpaqueNonClientView::Layout() { 661 void OpaqueNonClientView::Layout() {
660 LayoutWindowControls(); 662 LayoutWindowControls();
661 LayoutDistributorLogo(); 663 LayoutDistributorLogo();
662 LayoutTitleBar(); 664 LayoutTitleBar();
663 LayoutOTRAvatar(); 665 LayoutOTRAvatar();
664 LayoutClientView(); 666 LayoutClientView();
665 } 667 }
666 668
667 gfx::Size OpaqueNonClientView::GetPreferredSize() { 669 gfx::Size OpaqueNonClientView::GetPreferredSize() {
668 int horizontal_border = frame_->IsMaximized() ?
669 kWindowHorizontalBorderZoomedSize : kWindowHorizontalBorderSize;
670 gfx::Size prefsize(frame_->client_view()->GetPreferredSize()); 670 gfx::Size prefsize(frame_->client_view()->GetPreferredSize());
671 prefsize.Enlarge(2 * horizontal_border, 671 prefsize.Enlarge(2 * HorizontalBorderSize(),
672 CalculateNonClientTopHeight() + kWindowVerticalBorderBottomSize); 672 CalculateNonClientTopHeight() + kWindowVerticalBorderBottomSize);
673 return prefsize; 673 return prefsize;
674 } 674 }
675 675
676 views::View* OpaqueNonClientView::GetViewForPoint(const gfx::Point& point, 676 views::View* OpaqueNonClientView::GetViewForPoint(const gfx::Point& point,
677 bool can_create_floating) { 677 bool can_create_floating) {
678 // We override this function because the ClientView can overlap the non - 678 // We override this function because the ClientView can overlap the non -
679 // 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
680 // to ensure the window controls are checked _first_. 680 // to ensure the window controls are checked _first_.
681 views::View* views[] = { close_button_, restore_button_, maximize_button_, 681 views::View* views[] = { close_button_, restore_button_, maximize_button_,
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
728 728
729 /////////////////////////////////////////////////////////////////////////////// 729 ///////////////////////////////////////////////////////////////////////////////
730 // OpaqueNonClientView, private: 730 // OpaqueNonClientView, private:
731 731
732 int OpaqueNonClientView::CalculateNonClientTopHeight() const { 732 int OpaqueNonClientView::CalculateNonClientTopHeight() const {
733 if (frame_->window_delegate()->ShouldShowWindowTitle()) 733 if (frame_->window_delegate()->ShouldShowWindowTitle())
734 return kTitleTopOffset + title_font_.height() + kTitleBottomSpacing; 734 return kTitleTopOffset + title_font_.height() + kTitleBottomSpacing;
735 return frame_->IsMaximized() ? kNoTitleZoomedTopSpacing : kNoTitleTopSpacing; 735 return frame_->IsMaximized() ? kNoTitleZoomedTopSpacing : kNoTitleTopSpacing;
736 } 736 }
737 737
738 int OpaqueNonClientView::HorizontalBorderSize() const {
739 return frame_->IsMaximized() ?
740 kWindowHorizontalBorderZoomedSize : kWindowHorizontalBorderSize;
741 }
742
738 void OpaqueNonClientView::PaintFrameBorder(ChromeCanvas* canvas) { 743 void OpaqueNonClientView::PaintFrameBorder(ChromeCanvas* canvas) {
739 SkBitmap* top_left_corner = 744 SkBitmap* top_left_corner =
740 resources()->GetPartBitmap(FRAME_TOP_LEFT_CORNER); 745 resources()->GetPartBitmap(FRAME_TOP_LEFT_CORNER);
741 SkBitmap* top_right_corner = 746 SkBitmap* top_right_corner =
742 resources()->GetPartBitmap(FRAME_TOP_RIGHT_CORNER); 747 resources()->GetPartBitmap(FRAME_TOP_RIGHT_CORNER);
743 SkBitmap* top_edge = resources()->GetPartBitmap(FRAME_TOP_EDGE); 748 SkBitmap* top_edge = resources()->GetPartBitmap(FRAME_TOP_EDGE);
744 SkBitmap* right_edge = resources()->GetPartBitmap(FRAME_RIGHT_EDGE); 749 SkBitmap* right_edge = resources()->GetPartBitmap(FRAME_RIGHT_EDGE);
745 SkBitmap* left_edge = resources()->GetPartBitmap(FRAME_LEFT_EDGE); 750 SkBitmap* left_edge = resources()->GetPartBitmap(FRAME_LEFT_EDGE);
746 SkBitmap* bottom_left_corner = 751 SkBitmap* bottom_left_corner =
747 resources()->GetPartBitmap(FRAME_BOTTOM_LEFT_CORNER); 752 resources()->GetPartBitmap(FRAME_BOTTOM_LEFT_CORNER);
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
832 toolbar_bounds.width(), toolbar_center->height()); 837 toolbar_bounds.width(), toolbar_center->height());
833 838
834 canvas->DrawBitmapInt( 839 canvas->DrawBitmapInt(
835 *resources()->GetPartBitmap(FRAME_CLIENT_EDGE_TOP_RIGHT), 840 *resources()->GetPartBitmap(FRAME_CLIENT_EDGE_TOP_RIGHT),
836 toolbar_bounds.right(), toolbar_bounds.y()); 841 toolbar_bounds.right(), toolbar_bounds.y());
837 } 842 }
838 843
839 void OpaqueNonClientView::PaintOTRAvatar(ChromeCanvas* canvas) { 844 void OpaqueNonClientView::PaintOTRAvatar(ChromeCanvas* canvas) {
840 if (browser_view_->ShouldShowOffTheRecordAvatar()) { 845 if (browser_view_->ShouldShowOffTheRecordAvatar()) {
841 int src_y = frame_->IsMaximized() ? kOTRZoomedTopCrop : 0; 846 int src_y = frame_->IsMaximized() ? kOTRZoomedTopCrop : 0;
842 canvas->DrawBitmapInt(browser_view_->GetOTRAvatarIcon(), 847 canvas->DrawBitmapInt(browser_view_->GetOTRAvatarIcon(), 0, src_y,
843 0, src_y, otr_avatar_bounds_.width(), otr_avatar_bounds_.height(), 848 otr_avatar_bounds_.width(), otr_avatar_bounds_.height(),
844 MirroredLeftPointForRect(otr_avatar_bounds_), otr_avatar_bounds_.y(), 849 MirroredLeftPointForRect(otr_avatar_bounds_), otr_avatar_bounds_.y(),
845 otr_avatar_bounds_.width(), otr_avatar_bounds_.height(), false); 850 otr_avatar_bounds_.width(), otr_avatar_bounds_.height(), false);
846 } 851 }
847 } 852 }
848 853
849 void OpaqueNonClientView::PaintClientEdge(ChromeCanvas* canvas) { 854 void OpaqueNonClientView::PaintClientEdge(ChromeCanvas* canvas) {
850 // The toolbar draws a client edge along its own bottom edge when it's 855 // The toolbar draws a client edge along its own bottom edge when it's
851 // visible. However, it only draws this for the width of the actual client 856 // visible. However, it only draws this for the width of the actual client
852 // area, leaving a gap at the left and right edges: 857 // area, leaving a gap at the left and right edges:
853 // 858 //
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
998 int title_left = 1003 int title_left =
999 icon_right + (d->ShouldShowWindowIcon() ? kWindowIconTitleSpacing : 0); 1004 icon_right + (d->ShouldShowWindowIcon() ? kWindowIconTitleSpacing : 0);
1000 int top_offset = frame_->IsMaximized() ? 1005 int top_offset = frame_->IsMaximized() ?
1001 kTitleZoomedTopOffset : kTitleTopOffset; 1006 kTitleZoomedTopOffset : kTitleTopOffset;
1002 title_bounds_.SetRect(title_left, top_offset, 1007 title_bounds_.SetRect(title_left, top_offset,
1003 std::max(0, title_right - icon_right), title_font_.height()); 1008 std::max(0, title_right - icon_right), title_font_.height());
1004 } 1009 }
1005 } 1010 }
1006 1011
1007 void OpaqueNonClientView::LayoutOTRAvatar() { 1012 void OpaqueNonClientView::LayoutOTRAvatar() {
1008 if (!browser_view_->ShouldShowOffTheRecordAvatar()) {
1009 otr_avatar_bounds_.SetRect(0, 0, 0, 0);
1010 return;
1011 }
1012
1013 SkBitmap otr_avatar_icon = browser_view_->GetOTRAvatarIcon(); 1013 SkBitmap otr_avatar_icon = browser_view_->GetOTRAvatarIcon();
1014 int non_client_height = CalculateNonClientTopHeight(); 1014 int non_client_height = CalculateNonClientTopHeight();
1015 int otr_bottom = non_client_height + browser_view_->GetTabStripHeight() - 1015 int otr_bottom = non_client_height + browser_view_->GetTabStripHeight() -
1016 kOTRBottomSpacing; 1016 kOTRBottomSpacing;
1017 int otr_x, otr_y, otr_height; 1017 int otr_x, otr_y, otr_height;
1018 if (frame_->IsMaximized()) { 1018 if (frame_->IsMaximized()) {
1019 otr_x = kOTRZoomedLeftOffset; 1019 otr_x = kOTRZoomedLeftOffset;
1020 otr_y = non_client_height + kOTRZoomedTopSpacing; 1020 otr_y = non_client_height + kOTRZoomedTopSpacing;
1021 otr_height = otr_bottom - otr_y; 1021 otr_height = otr_bottom - otr_y;
1022 } else { 1022 } else {
(...skipping 30 matching lines...) Expand all
1053 } 1053 }
1054 1054
1055 // static 1055 // static
1056 void OpaqueNonClientView::InitAppWindowResources() { 1056 void OpaqueNonClientView::InitAppWindowResources() {
1057 static bool initialized = false; 1057 static bool initialized = false;
1058 if (!initialized) { 1058 if (!initialized) {
1059 title_font_ = win_util::GetWindowTitleFont(); 1059 title_font_ = win_util::GetWindowTitleFont();
1060 initialized = true; 1060 initialized = true;
1061 } 1061 }
1062 } 1062 }
OLDNEW
« no previous file with comments | « chrome/browser/views/frame/opaque_non_client_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698