OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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.h" | 5 #include "chrome/browser/ui/views/frame/opaque_browser_frame_view.h" |
6 | 6 |
7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
9 #include "chrome/browser/themes/theme_service.h" | 9 #include "chrome/browser/themes/theme_service.h" |
10 #include "chrome/browser/ui/views/frame/browser_frame.h" | 10 #include "chrome/browser/ui/views/frame/browser_frame.h" |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 | 190 |
191 gfx::Rect OpaqueBrowserFrameView::GetBoundsForReservedArea() const { | 191 gfx::Rect OpaqueBrowserFrameView::GetBoundsForReservedArea() const { |
192 gfx::Rect client_view_bounds = CalculateClientAreaBounds(width(), height()); | 192 gfx::Rect client_view_bounds = CalculateClientAreaBounds(width(), height()); |
193 return gfx::Rect( | 193 return gfx::Rect( |
194 client_view_bounds.x(), | 194 client_view_bounds.x(), |
195 client_view_bounds.y() + client_view_bounds.height(), | 195 client_view_bounds.y() + client_view_bounds.height(), |
196 client_view_bounds.width(), | 196 client_view_bounds.width(), |
197 GetReservedHeight()); | 197 GetReservedHeight()); |
198 } | 198 } |
199 | 199 |
| 200 int OpaqueBrowserFrameView::NonClientTopBorderHeight( |
| 201 bool restored, |
| 202 bool ignore_vertical_tabs) const { |
| 203 views::Window* window = frame_->GetWindow(); |
| 204 views::WindowDelegate* delegate = window->window_delegate(); |
| 205 // |delegate| may be NULL if called from callback of InputMethodChanged while |
| 206 // a window is being destroyed. |
| 207 // See more discussion at http://crosbug.com/8958 |
| 208 if ((delegate && delegate->ShouldShowWindowTitle()) || |
| 209 (browser_view_->IsTabStripVisible() && !ignore_vertical_tabs && |
| 210 browser_view_->UseVerticalTabs())) { |
| 211 return std::max(FrameBorderThickness(restored) + IconSize(), |
| 212 CaptionButtonY(restored) + kCaptionButtonHeightWithPadding) + |
| 213 TitlebarBottomThickness(restored); |
| 214 } |
| 215 |
| 216 return FrameBorderThickness(restored) - |
| 217 ((browser_view_->IsTabStripVisible() && !restored && |
| 218 window->IsMaximized()) ? kTabstripTopShadowThickness : 0); |
| 219 } |
| 220 |
200 /////////////////////////////////////////////////////////////////////////////// | 221 /////////////////////////////////////////////////////////////////////////////// |
201 // OpaqueBrowserFrameView, BrowserNonClientFrameView implementation: | 222 // OpaqueBrowserFrameView, BrowserNonClientFrameView implementation: |
202 | 223 |
203 gfx::Rect OpaqueBrowserFrameView::GetBoundsForTabStrip( | 224 gfx::Rect OpaqueBrowserFrameView::GetBoundsForTabStrip( |
204 views::View* tabstrip) const { | 225 views::View* tabstrip) const { |
205 if (!tabstrip) { | 226 if (!tabstrip) { |
206 return gfx::Rect(); | 227 return gfx::Rect(); |
207 } | 228 } |
208 | 229 |
209 if (browser_view_->UseVerticalTabs()) { | 230 if (browser_view_->UseVerticalTabs()) { |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
467 } | 488 } |
468 | 489 |
469 int OpaqueBrowserFrameView::NonClientBorderThickness() const { | 490 int OpaqueBrowserFrameView::NonClientBorderThickness() const { |
470 // When we fill the screen, we don't show a client edge. | 491 // When we fill the screen, we don't show a client edge. |
471 views::Window* window = frame_->GetWindow(); | 492 views::Window* window = frame_->GetWindow(); |
472 return FrameBorderThickness(false) + | 493 return FrameBorderThickness(false) + |
473 ((window->IsMaximized() || window->IsFullscreen()) ? | 494 ((window->IsMaximized() || window->IsFullscreen()) ? |
474 0 : kClientEdgeThickness); | 495 0 : kClientEdgeThickness); |
475 } | 496 } |
476 | 497 |
477 int OpaqueBrowserFrameView::NonClientTopBorderHeight( | 498 void OpaqueBrowserFrameView::ModifyMaximizedFramePainting( |
478 bool restored, | 499 int* theme_offset, SkBitmap** left_corner, SkBitmap** right_corner) { |
479 bool ignore_vertical_tabs) const { | |
480 views::Window* window = frame_->GetWindow(); | |
481 views::WindowDelegate* delegate = window->window_delegate(); | |
482 // |delegate| may be NULL if called from callback of InputMethodChanged while | |
483 // a window is being destroyed. | |
484 // See more discussion at http://crosbug.com/8958 | |
485 if ((delegate && delegate->ShouldShowWindowTitle()) || | |
486 (browser_view_->IsTabStripVisible() && !ignore_vertical_tabs && | |
487 browser_view_->UseVerticalTabs())) { | |
488 return std::max(FrameBorderThickness(restored) + IconSize(), | |
489 CaptionButtonY(restored) + kCaptionButtonHeightWithPadding) + | |
490 TitlebarBottomThickness(restored); | |
491 } | |
492 | |
493 return FrameBorderThickness(restored) - | |
494 ((browser_view_->IsTabStripVisible() && !restored && | |
495 window->IsMaximized()) ? kTabstripTopShadowThickness : 0); | |
496 } | 500 } |
497 | 501 |
498 int OpaqueBrowserFrameView::CaptionButtonY(bool restored) const { | 502 int OpaqueBrowserFrameView::CaptionButtonY(bool restored) const { |
499 // Maximized buttons start at window top so that even if their images aren't | 503 // Maximized buttons start at window top so that even if their images aren't |
500 // drawn flush with the screen edge, they still obey Fitts' Law. | 504 // drawn flush with the screen edge, they still obey Fitts' Law. |
501 return (!restored && frame_->GetWindow()->IsMaximized()) ? | 505 return (!restored && frame_->GetWindow()->IsMaximized()) ? |
502 FrameBorderThickness(false) : kFrameShadowThickness; | 506 FrameBorderThickness(false) : kFrameShadowThickness; |
503 } | 507 } |
504 | 508 |
505 int OpaqueBrowserFrameView::TitlebarBottomThickness(bool restored) const { | 509 int OpaqueBrowserFrameView::TitlebarBottomThickness(bool restored) const { |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
661 width() - bottom_left_corner->width() - bottom_right_corner->width(), | 665 width() - bottom_left_corner->width() - bottom_right_corner->width(), |
662 bottom_edge->height()); | 666 bottom_edge->height()); |
663 canvas->DrawBitmapInt(*bottom_left_corner, 0, | 667 canvas->DrawBitmapInt(*bottom_left_corner, 0, |
664 height() - bottom_left_corner->height()); | 668 height() - bottom_left_corner->height()); |
665 | 669 |
666 // Left. | 670 // Left. |
667 canvas->TileImageInt(*left_edge, 0, top_left_height, left_edge->width(), | 671 canvas->TileImageInt(*left_edge, 0, top_left_height, left_edge->width(), |
668 height() - top_left_height - bottom_left_corner->height()); | 672 height() - top_left_height - bottom_left_corner->height()); |
669 } | 673 } |
670 | 674 |
671 | |
672 void OpaqueBrowserFrameView::PaintMaximizedFrameBorder(gfx::Canvas* canvas) { | 675 void OpaqueBrowserFrameView::PaintMaximizedFrameBorder(gfx::Canvas* canvas) { |
673 ui::ThemeProvider* tp = GetThemeProvider(); | 676 ui::ThemeProvider* tp = GetThemeProvider(); |
674 views::Window* window = frame_->GetWindow(); | 677 views::Window* window = frame_->GetWindow(); |
675 | 678 |
676 // Window frame mode and color | 679 // Window frame mode and color |
677 SkBitmap* theme_frame; | 680 SkBitmap* theme_frame; |
| 681 |
| 682 // Allow customization of these attributes. |
| 683 SkBitmap* left = NULL; |
| 684 SkBitmap* right = NULL; |
| 685 int top_offset = 0; |
| 686 ModifyMaximizedFramePainting(&top_offset, &left, &right); |
| 687 |
678 // Never theme app and popup windows. | 688 // Never theme app and popup windows. |
679 if (!browser_view_->IsBrowserTypeNormal()) { | 689 if (!browser_view_->IsBrowserTypeNormal()) { |
680 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 690 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
681 theme_frame = rb.GetBitmapNamed(ShouldPaintAsActive() ? | 691 theme_frame = rb.GetBitmapNamed(ShouldPaintAsActive() ? |
682 IDR_FRAME : IDR_FRAME_INACTIVE); | 692 IDR_FRAME : IDR_FRAME_INACTIVE); |
683 } else if (!browser_view_->IsOffTheRecord()) { | 693 } else if (!browser_view_->IsOffTheRecord()) { |
684 theme_frame = tp->GetBitmapNamed(ShouldPaintAsActive() ? | 694 theme_frame = tp->GetBitmapNamed(ShouldPaintAsActive() ? |
685 IDR_THEME_FRAME : IDR_THEME_FRAME_INACTIVE); | 695 IDR_THEME_FRAME : IDR_THEME_FRAME_INACTIVE); |
686 } else { | 696 } else { |
687 theme_frame = tp->GetBitmapNamed(ShouldPaintAsActive() ? | 697 theme_frame = tp->GetBitmapNamed(ShouldPaintAsActive() ? |
688 IDR_THEME_FRAME_INCOGNITO : IDR_THEME_FRAME_INCOGNITO_INACTIVE); | 698 IDR_THEME_FRAME_INCOGNITO : IDR_THEME_FRAME_INCOGNITO_INACTIVE); |
689 } | 699 } |
690 // Draw the theme frame. It must be aligned with the tabstrip as if we were | 700 // Draw the theme frame. It must be aligned with the tabstrip as if we were |
691 // in restored mode. Note that the top of the tabstrip is | 701 // in restored mode. Note that the top of the tabstrip is |
692 // kTabstripTopShadowThickness px off the top of the screen. | 702 // kTabstripTopShadowThickness px off the top of the screen. |
693 int theme_background_y = -(GetHorizontalTabStripVerticalOffset(true) + | 703 int theme_background_y = -(GetHorizontalTabStripVerticalOffset(true) + |
694 kTabstripTopShadowThickness); | 704 kTabstripTopShadowThickness); |
695 canvas->TileImageInt(*theme_frame, 0, theme_background_y, width(), | 705 int left_offset = 0, right_offset = 0; |
| 706 |
| 707 if (left || right) { |
| 708 // If we have either a left or right we should have both. |
| 709 DCHECK(left && right); |
| 710 left_offset = left->width(); |
| 711 right_offset = right->width(); |
| 712 canvas->DrawBitmapInt(*left, 0, 0); |
| 713 canvas->DrawBitmapInt(*right, width() - right_offset, 0); |
| 714 } |
| 715 |
| 716 canvas->TileImageInt(*theme_frame, |
| 717 left_offset, |
| 718 top_offset, |
| 719 width() - (left_offset + right_offset), |
696 theme_frame->height()); | 720 theme_frame->height()); |
697 | |
698 // Draw the theme frame overlay | 721 // Draw the theme frame overlay |
699 if (tp->HasCustomImage(IDR_THEME_FRAME_OVERLAY) && | 722 if (tp->HasCustomImage(IDR_THEME_FRAME_OVERLAY) && |
700 browser_view_->IsBrowserTypeNormal()) { | 723 browser_view_->IsBrowserTypeNormal()) { |
701 SkBitmap* theme_overlay = tp->GetBitmapNamed(ShouldPaintAsActive() ? | 724 SkBitmap* theme_overlay = tp->GetBitmapNamed(ShouldPaintAsActive() ? |
702 IDR_THEME_FRAME_OVERLAY : IDR_THEME_FRAME_OVERLAY_INACTIVE); | 725 IDR_THEME_FRAME_OVERLAY : IDR_THEME_FRAME_OVERLAY_INACTIVE); |
703 canvas->DrawBitmapInt(*theme_overlay, 0, theme_background_y); | 726 canvas->DrawBitmapInt(*theme_overlay, 0, theme_background_y); |
704 } | 727 } |
705 | 728 |
706 if (!browser_view_->IsToolbarVisible()) { | 729 if (!browser_view_->IsToolbarVisible()) { |
707 // There's no toolbar to edge the frame border, so we need to draw a bottom | 730 // There's no toolbar to edge the frame border, so we need to draw a bottom |
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1074 | 1097 |
1075 gfx::Rect OpaqueBrowserFrameView::CalculateClientAreaBounds(int width, | 1098 gfx::Rect OpaqueBrowserFrameView::CalculateClientAreaBounds(int width, |
1076 int height) const { | 1099 int height) const { |
1077 int top_height = NonClientTopBorderHeight(false, false); | 1100 int top_height = NonClientTopBorderHeight(false, false); |
1078 int border_thickness = NonClientBorderThickness(); | 1101 int border_thickness = NonClientBorderThickness(); |
1079 return gfx::Rect(border_thickness, top_height, | 1102 return gfx::Rect(border_thickness, top_height, |
1080 std::max(0, width - (2 * border_thickness)), | 1103 std::max(0, width - (2 * border_thickness)), |
1081 std::max(0, height - GetReservedHeight() - | 1104 std::max(0, height - GetReservedHeight() - |
1082 top_height - border_thickness)); | 1105 top_height - border_thickness)); |
1083 } | 1106 } |
OLD | NEW |