| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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_ash.h" | 5 #include "chrome/browser/ui/views/frame/browser_non_client_frame_view_ash.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "ash/ash_layout_constants.h" | 9 #include "ash/ash_layout_constants.h" |
| 10 #include "ash/frame/caption_buttons/frame_caption_button_container_view.h" | 10 #include "ash/frame/caption_buttons/frame_caption_button_container_view.h" |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 const bool should_paint_as_active = ShouldPaintAsActive(); | 285 const bool should_paint_as_active = ShouldPaintAsActive(); |
| 286 caption_button_container_->SetPaintAsActive(should_paint_as_active); | 286 caption_button_container_->SetPaintAsActive(should_paint_as_active); |
| 287 if (web_app_left_header_view_) | 287 if (web_app_left_header_view_) |
| 288 web_app_left_header_view_->SetPaintAsActive(should_paint_as_active); | 288 web_app_left_header_view_->SetPaintAsActive(should_paint_as_active); |
| 289 | 289 |
| 290 const ash::HeaderPainter::Mode header_mode = should_paint_as_active ? | 290 const ash::HeaderPainter::Mode header_mode = should_paint_as_active ? |
| 291 ash::HeaderPainter::MODE_ACTIVE : ash::HeaderPainter::MODE_INACTIVE; | 291 ash::HeaderPainter::MODE_ACTIVE : ash::HeaderPainter::MODE_INACTIVE; |
| 292 header_painter_->PaintHeader(canvas, header_mode); | 292 header_painter_->PaintHeader(canvas, header_mode); |
| 293 | 293 |
| 294 if (browser_view()->IsToolbarVisible() && | 294 if (browser_view()->IsToolbarVisible() && |
| 295 !browser_view()->toolbar()->GetPreferredSize().IsEmpty()) { | 295 !browser_view()->toolbar()->GetPreferredSize().IsEmpty() && |
| 296 browser_view()->IsTabStripVisible()) { |
| 296 PaintToolbarBackground(canvas); | 297 PaintToolbarBackground(canvas); |
| 297 } | 298 } |
| 298 if (!browser_view()->IsTabStripVisible()) | |
| 299 PaintContentEdge(canvas); | |
| 300 } | 299 } |
| 301 | 300 |
| 302 void BrowserNonClientFrameViewAsh::Layout() { | 301 void BrowserNonClientFrameViewAsh::Layout() { |
| 303 // The header must be laid out before computing |painted_height| because the | 302 // The header must be laid out before computing |painted_height| because the |
| 304 // computation of |painted_height| for app and popup windows depends on the | 303 // computation of |painted_height| for app and popup windows depends on the |
| 305 // position of the window controls. | 304 // position of the window controls. |
| 306 header_painter_->LayoutHeader(); | 305 header_painter_->LayoutHeader(); |
| 307 | 306 |
| 308 int painted_height = GetTopInset(false); | 307 int painted_height = GetTopInset(false); |
| 309 if (browser_view()->IsTabStripVisible()) | 308 if (browser_view()->IsTabStripVisible()) |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 495 UseImmersiveLightbarHeaderStyle()); | 494 UseImmersiveLightbarHeaderStyle()); |
| 496 } | 495 } |
| 497 | 496 |
| 498 void BrowserNonClientFrameViewAsh::PaintToolbarBackground(gfx::Canvas* canvas) { | 497 void BrowserNonClientFrameViewAsh::PaintToolbarBackground(gfx::Canvas* canvas) { |
| 499 gfx::Rect toolbar_bounds(browser_view()->GetToolbarBounds()); | 498 gfx::Rect toolbar_bounds(browser_view()->GetToolbarBounds()); |
| 500 if (toolbar_bounds.IsEmpty()) | 499 if (toolbar_bounds.IsEmpty()) |
| 501 return; | 500 return; |
| 502 gfx::Point toolbar_origin(toolbar_bounds.origin()); | 501 gfx::Point toolbar_origin(toolbar_bounds.origin()); |
| 503 View::ConvertPointToTarget(browser_view(), this, &toolbar_origin); | 502 View::ConvertPointToTarget(browser_view(), this, &toolbar_origin); |
| 504 toolbar_bounds.set_origin(toolbar_origin); | 503 toolbar_bounds.set_origin(toolbar_origin); |
| 504 |
| 505 const ui::ThemeProvider* tp = GetThemeProvider(); |
| 506 gfx::ImageSkia* bg = tp->GetImageSkiaNamed(IDR_THEME_TOOLBAR); |
| 507 const int x = toolbar_bounds.x(); |
| 508 const int y = toolbar_bounds.y(); |
| 509 const int bg_y = GetTopInset(false) + Tab::GetYInsetForActiveTabBackground(); |
| 510 const int w = toolbar_bounds.width(); |
| 505 const int h = toolbar_bounds.height(); | 511 const int h = toolbar_bounds.height(); |
| 506 const bool md = ui::MaterialDesignController::IsModeMaterial(); | |
| 507 const ui::ThemeProvider* tp = GetThemeProvider(); | |
| 508 const SkColor separator_color = | 512 const SkColor separator_color = |
| 509 tp->GetColor(ThemeProperties::COLOR_TOOLBAR_BOTTOM_SEPARATOR); | 513 tp->GetColor(ThemeProperties::COLOR_TOOLBAR_BOTTOM_SEPARATOR); |
| 514 if (ui::MaterialDesignController::IsModeMaterial()) { |
| 515 // Background. The top stroke is drawn above the toolbar bounds, so |
| 516 // unlike in the non-Material Design code below, we don't need to exclude |
| 517 // any region from having the background image drawn over it. |
| 518 if (tp->HasCustomImage(IDR_THEME_TOOLBAR)) { |
| 519 canvas->TileImageInt(*bg, x + GetThemeBackgroundXInset(), y - bg_y, x, y, |
| 520 w, h); |
| 521 } else { |
| 522 canvas->FillRect(toolbar_bounds, |
| 523 tp->GetColor(ThemeProperties::COLOR_TOOLBAR)); |
| 524 } |
| 510 | 525 |
| 511 if (browser_view()->IsTabStripVisible()) { | 526 // Top stroke. |
| 512 gfx::ImageSkia* bg = tp->GetImageSkiaNamed(IDR_THEME_TOOLBAR); | 527 gfx::Rect separator_rect(x, y, w, 0); |
| 513 int x = toolbar_bounds.x(); | 528 gfx::ScopedCanvas scoped_canvas(canvas); |
| 514 const int y = toolbar_bounds.y(); | 529 gfx::Rect tabstrip_bounds(GetBoundsForTabStrip(browser_view()->tabstrip())); |
| 515 const int bg_y = | 530 tabstrip_bounds.set_x(GetMirroredXForRect(tabstrip_bounds)); |
| 516 GetTopInset(false) + Tab::GetYInsetForActiveTabBackground(); | 531 canvas->sk_canvas()->clipRect(gfx::RectToSkRect(tabstrip_bounds), |
| 517 const int w = toolbar_bounds.width(); | 532 SkRegion::kDifference_Op); |
| 533 separator_rect.set_y(tabstrip_bounds.bottom()); |
| 534 BrowserView::Paint1pxHorizontalLine( |
| 535 canvas, tp->GetColor(ThemeProperties::COLOR_TOOLBAR_TOP_SEPARATOR), |
| 536 separator_rect, true); |
| 518 | 537 |
| 519 if (md) { | 538 // Toolbar/content separator. |
| 520 // Background. The top stroke is drawn above the toolbar bounds, so | 539 toolbar_bounds.Inset(kClientEdgeThickness, 0); |
| 521 // unlike in the non-Material Design code below, we don't need to exclude | 540 BrowserView::Paint1pxHorizontalLine(canvas, separator_color, toolbar_bounds, |
| 522 // any region from having the background image drawn over it. | 541 true); |
| 523 if (tp->HasCustomImage(IDR_THEME_TOOLBAR)) { | 542 } else { |
| 524 canvas->TileImageInt(*bg, x + GetThemeBackgroundXInset(), y - bg_y, x, | 543 // Background. |
| 525 y, w, h); | 544 const int split_point = kContentEdgeShadowThickness; |
| 526 } else { | 545 const int split_y = y + split_point; |
| 527 canvas->FillRect(toolbar_bounds, | 546 canvas->TileImageInt(*bg, x + GetThemeBackgroundXInset(), split_y - bg_y, x, |
| 528 tp->GetColor(ThemeProperties::COLOR_TOOLBAR)); | 547 split_y, w, bg->height()); |
| 529 } | |
| 530 | 548 |
| 531 // Top stroke. | 549 // The pre-material design content area line has a shadow that extends a |
| 532 gfx::Rect separator_rect(x, y, w, 0); | 550 // couple of pixels above the toolbar bounds. |
| 533 gfx::ScopedCanvas scoped_canvas(canvas); | 551 gfx::ImageSkia* toolbar_top = tp->GetImageSkiaNamed(IDR_TOOLBAR_SHADE_TOP); |
| 534 gfx::Rect tabstrip_bounds( | 552 canvas->TileImageInt(*toolbar_top, 0, 0, x, y - kContentEdgeShadowThickness, |
| 535 GetBoundsForTabStrip(browser_view()->tabstrip())); | 553 w, toolbar_top->height()); |
| 536 tabstrip_bounds.set_x(GetMirroredXForRect(tabstrip_bounds)); | |
| 537 canvas->sk_canvas()->clipRect(gfx::RectToSkRect(tabstrip_bounds), | |
| 538 SkRegion::kDifference_Op); | |
| 539 separator_rect.set_y(tabstrip_bounds.bottom()); | |
| 540 BrowserView::Paint1pxHorizontalLine( | |
| 541 canvas, tp->GetColor(ThemeProperties::COLOR_TOOLBAR_TOP_SEPARATOR), | |
| 542 separator_rect, true); | |
| 543 } else { | |
| 544 // Background. | |
| 545 const int split_point = kContentEdgeShadowThickness; | |
| 546 const int split_y = y + split_point; | |
| 547 canvas->TileImageInt(*bg, x + GetThemeBackgroundXInset(), split_y - bg_y, | |
| 548 x, split_y, w, bg->height()); | |
| 549 | 554 |
| 550 // The pre-material design content area line has a shadow that extends a | 555 // Draw the "lightening" shade line around the edges of the toolbar. |
| 551 // couple of pixels above the toolbar bounds. | 556 gfx::ImageSkia* toolbar_left = |
| 552 gfx::ImageSkia* toolbar_top = | 557 tp->GetImageSkiaNamed(IDR_TOOLBAR_SHADE_LEFT); |
| 553 tp->GetImageSkiaNamed(IDR_TOOLBAR_SHADE_TOP); | 558 canvas->TileImageInt( |
| 554 canvas->TileImageInt(*toolbar_top, 0, 0, x, | 559 *toolbar_left, 0, 0, x + kClientEdgeThickness, |
| 555 y - kContentEdgeShadowThickness, w, | 560 y + kClientEdgeThickness + kContentEdgeShadowThickness, |
| 556 toolbar_top->height()); | 561 toolbar_left->width(), bg->height()); |
| 562 gfx::ImageSkia* toolbar_right = |
| 563 tp->GetImageSkiaNamed(IDR_TOOLBAR_SHADE_RIGHT); |
| 564 canvas->TileImageInt( |
| 565 *toolbar_right, 0, 0, |
| 566 w - toolbar_right->width() - 2 * kClientEdgeThickness, |
| 567 y + kClientEdgeThickness + kContentEdgeShadowThickness, |
| 568 toolbar_right->width(), bg->height()); |
| 557 | 569 |
| 558 // Draw the "lightening" shade line around the edges of the toolbar. | 570 // Toolbar/content separator. |
| 559 gfx::ImageSkia* toolbar_left = | 571 toolbar_bounds.Inset(kClientEdgeThickness, h - kClientEdgeThickness, |
| 560 tp->GetImageSkiaNamed(IDR_TOOLBAR_SHADE_LEFT); | 572 kClientEdgeThickness, 0); |
| 561 canvas->TileImageInt( | |
| 562 *toolbar_left, 0, 0, x + kClientEdgeThickness, | |
| 563 y + kClientEdgeThickness + kContentEdgeShadowThickness, | |
| 564 toolbar_left->width(), bg->height()); | |
| 565 gfx::ImageSkia* toolbar_right = | |
| 566 tp->GetImageSkiaNamed(IDR_TOOLBAR_SHADE_RIGHT); | |
| 567 canvas->TileImageInt( | |
| 568 *toolbar_right, 0, 0, | |
| 569 w - toolbar_right->width() - 2 * kClientEdgeThickness, | |
| 570 y + kClientEdgeThickness + kContentEdgeShadowThickness, | |
| 571 toolbar_right->width(), bg->height()); | |
| 572 } | |
| 573 } | |
| 574 | |
| 575 // Draw the toolbar/content separator. | |
| 576 toolbar_bounds.Inset(kClientEdgeThickness, h - kClientEdgeThickness, | |
| 577 kClientEdgeThickness, 0); | |
| 578 if (md) { | |
| 579 BrowserView::Paint1pxHorizontalLine(canvas, separator_color, | |
| 580 toolbar_bounds, true); | |
| 581 } else { | |
| 582 canvas->FillRect(toolbar_bounds, separator_color); | 573 canvas->FillRect(toolbar_bounds, separator_color); |
| 583 } | 574 } |
| 584 } | 575 } |
| 585 | |
| 586 void BrowserNonClientFrameViewAsh::PaintContentEdge(gfx::Canvas* canvas) { | |
| 587 // The content separator is drawn by DefaultHeaderPainter in these cases. | |
| 588 if (UsePackagedAppHeaderStyle() || UseWebAppHeaderStyle()) | |
| 589 return; | |
| 590 | |
| 591 gfx::Rect separator_rect( | |
| 592 0, caption_button_container_->bounds().bottom(), width(), 0); | |
| 593 BrowserView::Paint1pxHorizontalLine( | |
| 594 canvas, | |
| 595 GetThemeProvider()->GetColor( | |
| 596 ThemeProperties::COLOR_TOOLBAR_TOP_SEPARATOR), | |
| 597 separator_rect, true); | |
| 598 } | |
| OLD | NEW |