| 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/views/frame/browser_non_client_frame_view_aura.h" | 5 #include "chrome/browser/ui/views/frame/browser_non_client_frame_view_aura.h" |
| 6 | 6 |
| 7 #include "chrome/browser/themes/theme_service.h" |
| 7 #include "chrome/browser/ui/views/frame/browser_frame.h" | 8 #include "chrome/browser/ui/views/frame/browser_frame.h" |
| 8 #include "chrome/browser/ui/views/frame/browser_view.h" | 9 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 9 #include "content/public/browser/web_contents.h" | 10 #include "content/public/browser/web_contents.h" |
| 10 #include "grit/generated_resources.h" // Accessibility names | 11 #include "grit/generated_resources.h" // Accessibility names |
| 11 #include "grit/theme_resources.h" | 12 #include "grit/theme_resources.h" |
| 12 #include "grit/theme_resources_standard.h" | 13 #include "grit/theme_resources_standard.h" |
| 13 #include "grit/ui_resources.h" | 14 #include "grit/ui_resources.h" |
| 14 #include "third_party/skia/include/core/SkCanvas.h" | 15 #include "third_party/skia/include/core/SkCanvas.h" |
| 15 #include "third_party/skia/include/core/SkPaint.h" | 16 #include "third_party/skia/include/core/SkPaint.h" |
| 16 #include "third_party/skia/include/core/SkPath.h" | 17 #include "third_party/skia/include/core/SkPath.h" |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 } | 261 } |
| 261 | 262 |
| 262 /////////////////////////////////////////////////////////////////////////////// | 263 /////////////////////////////////////////////////////////////////////////////// |
| 263 // views::View overrides: | 264 // views::View overrides: |
| 264 | 265 |
| 265 void BrowserNonClientFrameViewAura::OnPaint(gfx::Canvas* canvas) { | 266 void BrowserNonClientFrameViewAura::OnPaint(gfx::Canvas* canvas) { |
| 266 if (frame()->IsFullscreen()) | 267 if (frame()->IsFullscreen()) |
| 267 return; // Nothing visible, don't paint. | 268 return; // Nothing visible, don't paint. |
| 268 PaintHeader(canvas); | 269 PaintHeader(canvas); |
| 269 PaintTitleBar(canvas); | 270 PaintTitleBar(canvas); |
| 271 PaintToolbarBackground(canvas); |
| 270 // Paint the view hierarchy, which draws the caption buttons. | 272 // Paint the view hierarchy, which draws the caption buttons. |
| 271 BrowserNonClientFrameView::OnPaint(canvas); | 273 BrowserNonClientFrameView::OnPaint(canvas); |
| 272 } | 274 } |
| 273 | 275 |
| 274 void BrowserNonClientFrameViewAura::Layout() { | 276 void BrowserNonClientFrameViewAura::Layout() { |
| 275 // Maximized windows and app/popup windows use shorter buttons. | 277 // Maximized windows and app/popup windows use shorter buttons. |
| 276 if (frame()->IsMaximized() || | 278 if (frame()->IsMaximized() || |
| 277 !browser_view()->IsBrowserTypeNormal()) { | 279 !browser_view()->IsBrowserTypeNormal()) { |
| 278 SetButtonImages(close_button_, | 280 SetButtonImages(close_button_, |
| 279 IDR_AURA_WINDOW_MAXIMIZED_CLOSE, | 281 IDR_AURA_WINDOW_MAXIMIZED_CLOSE, |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 456 // Header right edge. | 458 // Header right edge. |
| 457 int header_right_height = theme_frame->height() - top_right_height; | 459 int header_right_height = theme_frame->height() - top_right_height; |
| 458 canvas->TileImageInt(*header_right_edge_, | 460 canvas->TileImageInt(*header_right_edge_, |
| 459 width() - header_right_edge_->width(), top_right_height, | 461 width() - header_right_edge_->width(), top_right_height, |
| 460 header_right_edge_->width(), header_right_height); | 462 header_right_edge_->width(), header_right_height); |
| 461 | 463 |
| 462 // We don't draw edges around the content area. Web content goes flush | 464 // We don't draw edges around the content area. Web content goes flush |
| 463 // to the edge of the window. | 465 // to the edge of the window. |
| 464 } | 466 } |
| 465 | 467 |
| 468 void BrowserNonClientFrameViewAura::PaintToolbarBackground( |
| 469 gfx::Canvas* canvas) { |
| 470 gfx::Rect toolbar_bounds(browser_view()->GetToolbarBounds()); |
| 471 if (toolbar_bounds.IsEmpty()) |
| 472 return; |
| 473 gfx::Point toolbar_origin(toolbar_bounds.origin()); |
| 474 ConvertPointToView(browser_view(), this, &toolbar_origin); |
| 475 toolbar_bounds.set_origin(toolbar_origin); |
| 476 |
| 477 int x = toolbar_bounds.x(); |
| 478 int w = toolbar_bounds.width(); |
| 479 int y = toolbar_bounds.y(); |
| 480 int h = toolbar_bounds.height(); |
| 481 |
| 482 // Gross hack: We split the toolbar images into two pieces, since sometimes |
| 483 // (popup mode) the toolbar isn't tall enough to show the whole image. The |
| 484 // split happens between the top shadow section and the bottom gradient |
| 485 // section so that we never break the gradient. |
| 486 int split_point = kFrameShadowThickness * 2; |
| 487 int bottom_y = y + split_point; |
| 488 ui::ThemeProvider* tp = GetThemeProvider(); |
| 489 SkBitmap* theme_toolbar = tp->GetBitmapNamed(IDR_THEME_TOOLBAR); |
| 490 int bottom_edge_height = std::min(theme_toolbar->height(), h) - split_point; |
| 491 |
| 492 canvas->FillRect(gfx::Rect(x, bottom_y, w, bottom_edge_height), |
| 493 tp->GetColor(ThemeService::COLOR_TOOLBAR)); |
| 494 |
| 495 // Paint the main toolbar image. Since this image is also used to draw the |
| 496 // tab background, we must use the tab strip offset to compute the image |
| 497 // source y position. If you have to debug this code use an image editor |
| 498 // to paint a diagonal line through the toolbar image and ensure it lines up |
| 499 // across the tab and toolbar. |
| 500 bool restored = !frame()->IsMaximized(); |
| 501 canvas->TileImageInt( |
| 502 *theme_toolbar, |
| 503 x, bottom_y - GetHorizontalTabStripVerticalOffset(restored), |
| 504 x, bottom_y, |
| 505 w, theme_toolbar->height()); |
| 506 |
| 507 SkBitmap* toolbar_center = |
| 508 tp->GetBitmapNamed(IDR_CONTENT_TOP_CENTER); |
| 509 canvas->TileImageInt(*toolbar_center, |
| 510 0, 0, |
| 511 x, y, |
| 512 w, split_point); |
| 513 |
| 514 // Draw the content/toolbar separator. |
| 515 canvas->FillRect(gfx::Rect(x + kClientEdgeThickness, |
| 516 toolbar_bounds.bottom() - kClientEdgeThickness, |
| 517 w - (2 * kClientEdgeThickness), |
| 518 kClientEdgeThickness), |
| 519 ThemeService::GetDefaultColor(ThemeService::COLOR_TOOLBAR_SEPARATOR)); |
| 520 } |
| 521 |
| 466 void BrowserNonClientFrameViewAura::PaintTitleBar(gfx::Canvas* canvas) { | 522 void BrowserNonClientFrameViewAura::PaintTitleBar(gfx::Canvas* canvas) { |
| 467 // The window icon is painted by the TabIconView. | 523 // The window icon is painted by the TabIconView. |
| 468 views::WidgetDelegate* delegate = frame()->widget_delegate(); | 524 views::WidgetDelegate* delegate = frame()->widget_delegate(); |
| 469 if (delegate && delegate->ShouldShowWindowTitle()) { | 525 if (delegate && delegate->ShouldShowWindowTitle()) { |
| 470 int icon_right = window_icon_ ? window_icon_->bounds().right() : 0; | 526 int icon_right = window_icon_ ? window_icon_->bounds().right() : 0; |
| 471 gfx::Rect title_bounds( | 527 gfx::Rect title_bounds( |
| 472 icon_right + kTitleOffsetX, | 528 icon_right + kTitleOffsetX, |
| 473 kTitleOffsetY, | 529 kTitleOffsetY, |
| 474 std::max(0, maximize_button_->x() - kTitleLogoSpacing - icon_right), | 530 std::max(0, maximize_button_->x() - kTitleLogoSpacing - icon_right), |
| 475 BrowserFrame::GetTitleFont().GetHeight()); | 531 BrowserFrame::GetTitleFont().GetHeight()); |
| 476 canvas->DrawStringInt(delegate->GetWindowTitle(), | 532 canvas->DrawStringInt(delegate->GetWindowTitle(), |
| 477 BrowserFrame::GetTitleFont(), | 533 BrowserFrame::GetTitleFont(), |
| 478 SK_ColorWHITE, | 534 SK_ColorBLACK, |
| 479 GetMirroredXForRect(title_bounds), | 535 GetMirroredXForRect(title_bounds), |
| 480 title_bounds.y(), | 536 title_bounds.y(), |
| 481 title_bounds.width(), | 537 title_bounds.width(), |
| 482 title_bounds.height()); | 538 title_bounds.height()); |
| 483 } | 539 } |
| 484 } | 540 } |
| 485 | 541 |
| 486 SkBitmap* BrowserNonClientFrameViewAura::GetThemeFrameBitmap() const { | 542 SkBitmap* BrowserNonClientFrameViewAura::GetThemeFrameBitmap() const { |
| 487 bool is_incognito = browser_view()->IsOffTheRecord(); | 543 bool is_incognito = browser_view()->IsOffTheRecord(); |
| 488 int resource_id; | 544 int resource_id; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 502 return GetCustomBitmap(IDR_THEME_FRAME_INCOGNITO_INACTIVE, | 558 return GetCustomBitmap(IDR_THEME_FRAME_INCOGNITO_INACTIVE, |
| 503 IDR_AURA_WINDOW_HEADER_BASE_INCOGNITO_INACTIVE); | 559 IDR_AURA_WINDOW_HEADER_BASE_INCOGNITO_INACTIVE); |
| 504 } | 560 } |
| 505 return GetCustomBitmap(IDR_THEME_FRAME_INACTIVE, | 561 return GetCustomBitmap(IDR_THEME_FRAME_INACTIVE, |
| 506 IDR_AURA_WINDOW_HEADER_BASE_INACTIVE); | 562 IDR_AURA_WINDOW_HEADER_BASE_INACTIVE); |
| 507 } | 563 } |
| 508 // Never theme app and popup windows. | 564 // Never theme app and popup windows. |
| 509 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 565 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 510 if (ShouldPaintAsActive()) { | 566 if (ShouldPaintAsActive()) { |
| 511 resource_id = is_incognito ? | 567 resource_id = is_incognito ? |
| 512 IDR_THEME_FRAME_INCOGNITO : IDR_FRAME; | 568 IDR_AURA_WINDOW_HEADER_BASE_INCOGNITO_ACTIVE : |
| 569 IDR_AURA_WINDOW_HEADER_BASE_ACTIVE; |
| 513 } else { | 570 } else { |
| 514 resource_id = is_incognito ? | 571 resource_id = is_incognito ? |
| 515 IDR_THEME_FRAME_INCOGNITO_INACTIVE : IDR_THEME_FRAME_INACTIVE; | 572 IDR_AURA_WINDOW_HEADER_BASE_INCOGNITO_INACTIVE : |
| 573 IDR_AURA_WINDOW_HEADER_BASE_INACTIVE; |
| 516 } | 574 } |
| 517 return rb.GetBitmapNamed(resource_id); | 575 return rb.GetBitmapNamed(resource_id); |
| 518 } | 576 } |
| 519 | 577 |
| 520 SkBitmap* BrowserNonClientFrameViewAura::GetThemeFrameOverlayBitmap() const { | 578 SkBitmap* BrowserNonClientFrameViewAura::GetThemeFrameOverlayBitmap() const { |
| 521 ui::ThemeProvider* tp = GetThemeProvider(); | 579 ui::ThemeProvider* tp = GetThemeProvider(); |
| 522 if (tp->HasCustomImage(IDR_THEME_FRAME_OVERLAY) && | 580 if (tp->HasCustomImage(IDR_THEME_FRAME_OVERLAY) && |
| 523 browser_view()->IsBrowserTypeNormal() && | 581 browser_view()->IsBrowserTypeNormal() && |
| 524 !browser_view()->IsOffTheRecord()) { | 582 !browser_view()->IsOffTheRecord()) { |
| 525 return tp->GetBitmapNamed(ShouldPaintAsActive() ? | 583 return tp->GetBitmapNamed(ShouldPaintAsActive() ? |
| 526 IDR_THEME_FRAME_OVERLAY : IDR_THEME_FRAME_OVERLAY_INACTIVE); | 584 IDR_THEME_FRAME_OVERLAY : IDR_THEME_FRAME_OVERLAY_INACTIVE); |
| 527 } | 585 } |
| 528 return NULL; | 586 return NULL; |
| 529 } | 587 } |
| 530 | 588 |
| 531 SkBitmap* BrowserNonClientFrameViewAura::GetCustomBitmap( | 589 SkBitmap* BrowserNonClientFrameViewAura::GetCustomBitmap( |
| 532 int bitmap_id, | 590 int bitmap_id, |
| 533 int fallback_bitmap_id) const { | 591 int fallback_bitmap_id) const { |
| 534 ui::ThemeProvider* tp = GetThemeProvider(); | 592 ui::ThemeProvider* tp = GetThemeProvider(); |
| 535 if (tp->HasCustomImage(bitmap_id)) | 593 if (tp->HasCustomImage(bitmap_id)) |
| 536 return tp->GetBitmapNamed(bitmap_id); | 594 return tp->GetBitmapNamed(bitmap_id); |
| 537 return tp->GetBitmapNamed(fallback_bitmap_id); | 595 return tp->GetBitmapNamed(fallback_bitmap_id); |
| 538 } | 596 } |
| OLD | NEW |