| 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/ash/browser_non_client_frame_view_ash.h" | 5 #include "chrome/browser/ui/views/ash/browser_non_client_frame_view_ash.h" |
| 6 | 6 |
| 7 #include "ash/wm/frame_painter.h" | 7 #include "ash/wm/frame_painter.h" |
| 8 #include "ash/wm/workspace/frame_maximize_button.h" | 8 #include "ash/wm/workspace/frame_maximize_button.h" |
| 9 #include "chrome/browser/themes/theme_service.h" | 9 #include "chrome/browser/themes/theme_service.h" |
| 10 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 ShouldPaintAsActive() ? | 271 ShouldPaintAsActive() ? |
| 272 ash::FramePainter::ACTIVE : ash::FramePainter::INACTIVE, | 272 ash::FramePainter::ACTIVE : ash::FramePainter::INACTIVE, |
| 273 GetThemeFrameImageId(), | 273 GetThemeFrameImageId(), |
| 274 GetThemeFrameOverlayImage()); | 274 GetThemeFrameOverlayImage()); |
| 275 if (browser_view()->ShouldShowWindowTitle()) | 275 if (browser_view()->ShouldShowWindowTitle()) |
| 276 frame_painter_->PaintTitleBar(this, canvas, BrowserFrame::GetTitleFont()); | 276 frame_painter_->PaintTitleBar(this, canvas, BrowserFrame::GetTitleFont()); |
| 277 if (browser_view()->IsToolbarVisible()) { | 277 if (browser_view()->IsToolbarVisible()) { |
| 278 chrome::search::Mode mode = | 278 chrome::search::Mode mode = |
| 279 browser_view()->browser()->search_model()->mode(); | 279 browser_view()->browser()->search_model()->mode(); |
| 280 bool fading_in = false; | 280 bool fading_in = false; |
| 281 // For |MODE_SEARCH|, get current state of background animation to figure | 281 // Get current opacity of gradient background animation to figure out if |
| 282 // out if we're waiting to fade in or in the process of fading in new | 282 // we need to paint both flat and gradient backgrounds or just one: |
| 283 // background for |MODE_SEARCH|. | 283 // - if |gradient_opacity| < 1f, paint flat background at full opacity, and |
| 284 // In the former case, just paint the previous background for |MODE_NTP|. | 284 // only paint gradient background if |gradient_opacity| is not 0f; |
| 285 // In the latter case, paint the previous background for |MODE_NTP| and then | 285 // - if |gradient_opacity| is 1f, paint the background for the current mode |
| 286 // the new background at specified opacity value. | 286 // at full opacity. |
| 287 if (mode.is_search()) { | 287 double gradient_opacity = browser_view()->browser()->search_delegate()-> |
| 288 chrome::search::ToolbarSearchAnimator::BackgroundState background_state = | 288 toolbar_search_animator().GetGradientOpacity(); |
| 289 chrome::search::ToolbarSearchAnimator::BACKGROUND_STATE_DEFAULT; | 289 if (gradient_opacity < 1.0f) { |
| 290 double search_background_opacity = -1.0f; | 290 // Paint flat background of |MODE_NTP|. |
| 291 browser_view()->browser()->search_delegate()->toolbar_search_animator(). | 291 PaintToolbarBackground(canvas, chrome::search::Mode::MODE_NTP); |
| 292 GetCurrentBackgroundState(&background_state, | 292 // We're done if we're not showing gradient background. |
| 293 &search_background_opacity); | 293 if (gradient_opacity == 0.0f) |
| 294 if (background_state & | 294 return; |
| 295 chrome::search::ToolbarSearchAnimator::BACKGROUND_STATE_NTP) { | 295 // Otherwise, we're fading in gradient background at |gradient_opacity|. |
| 296 // Paint background for |MODE_NTP|. | 296 fading_in = true; |
| 297 PaintToolbarBackground(canvas, chrome::search::Mode::MODE_NTP); | 297 canvas->SaveLayerAlpha(static_cast<uint8>(gradient_opacity * 0xFF)); |
| 298 // We're done if we're not showing background for SEARCH mode. | |
| 299 if (!(background_state & chrome::search::ToolbarSearchAnimator:: | |
| 300 BACKGROUND_STATE_SEARCH)) { | |
| 301 return; | |
| 302 } | |
| 303 // Otherwise, we're fading in the new background at | |
| 304 // |search_background_opacity|. | |
| 305 fading_in = true; | |
| 306 canvas->SaveLayerAlpha(static_cast<uint8>( | |
| 307 search_background_opacity * 0xFF)); | |
| 308 } | |
| 309 } | 298 } |
| 310 // Paint the background for the current mode. | 299 // Paint the background for the current mode. |
| 311 PaintToolbarBackground(canvas, mode.mode); | 300 PaintToolbarBackground(canvas, mode.mode); |
| 312 // If we're fading in and have saved canvas, restore it now. | 301 // If we're fading in and have saved canvas, restore it now. |
| 313 if (fading_in) | 302 if (fading_in) |
| 314 canvas->Restore(); | 303 canvas->Restore(); |
| 315 } else { | 304 } else { |
| 316 PaintContentEdge(canvas); | 305 PaintContentEdge(canvas); |
| 317 } | 306 } |
| 318 } | 307 } |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 415 browser_view()->toolbar()->SchedulePaint(); | 404 browser_view()->toolbar()->SchedulePaint(); |
| 416 } | 405 } |
| 417 | 406 |
| 418 void BrowserNonClientFrameViewAsh::OnToolbarBackgroundAnimatorCanceled( | 407 void BrowserNonClientFrameViewAsh::OnToolbarBackgroundAnimatorCanceled( |
| 419 TabContents* tab_contents) { | 408 TabContents* tab_contents) { |
| 420 // Fade in of toolbar background has been canceled, repaint the toolbar | 409 // Fade in of toolbar background has been canceled, repaint the toolbar |
| 421 // background. | 410 // background. |
| 422 browser_view()->toolbar()->SchedulePaint(); | 411 browser_view()->toolbar()->SchedulePaint(); |
| 423 } | 412 } |
| 424 | 413 |
| 414 void BrowserNonClientFrameViewAsh::OnToolbarSeparatorAnimatorProgressed() { |
| 415 // We're fading the toolbar separator, repaint the toolbar separator. |
| 416 browser_view()->toolbar()->SchedulePaint(); |
| 417 } |
| 418 |
| 419 void BrowserNonClientFrameViewAsh::OnToolbarSeparatorAnimatorCanceled() { |
| 420 // Fade in of toolbar background has been canceled, repaint the toolbar |
| 421 // separator. |
| 422 browser_view()->toolbar()->SchedulePaint(); |
| 423 } |
| 424 |
| 425 /////////////////////////////////////////////////////////////////////////////// | 425 /////////////////////////////////////////////////////////////////////////////// |
| 426 // BrowserNonClientFrameViewAsh, private: | 426 // BrowserNonClientFrameViewAsh, private: |
| 427 | 427 |
| 428 | 428 |
| 429 int BrowserNonClientFrameViewAsh::NonClientTopBorderHeight( | 429 int BrowserNonClientFrameViewAsh::NonClientTopBorderHeight( |
| 430 bool force_restored) const { | 430 bool force_restored) const { |
| 431 if (force_restored) | 431 if (force_restored) |
| 432 return tabstrip_top_spacing_tall(); | 432 return tabstrip_top_spacing_tall(); |
| 433 if (frame()->IsFullscreen()) | 433 if (frame()->IsFullscreen()) |
| 434 return 0; | 434 return 0; |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 545 y + kClientEdgeThickness + kContentShadowHeight, | 545 y + kClientEdgeThickness + kContentShadowHeight, |
| 546 toolbar_left->width(), theme_toolbar->height()); | 546 toolbar_left->width(), theme_toolbar->height()); |
| 547 gfx::ImageSkia* toolbar_right = | 547 gfx::ImageSkia* toolbar_right = |
| 548 tp->GetImageSkiaNamed(IDR_TOOLBAR_SHADE_RIGHT); | 548 tp->GetImageSkiaNamed(IDR_TOOLBAR_SHADE_RIGHT); |
| 549 canvas->TileImageInt(*toolbar_right, | 549 canvas->TileImageInt(*toolbar_right, |
| 550 0, 0, | 550 0, 0, |
| 551 w - toolbar_right->width() - 2 * kClientEdgeThickness, | 551 w - toolbar_right->width() - 2 * kClientEdgeThickness, |
| 552 y + kClientEdgeThickness + kContentShadowHeight, | 552 y + kClientEdgeThickness + kContentShadowHeight, |
| 553 toolbar_right->width(), theme_toolbar->height()); | 553 toolbar_right->width(), theme_toolbar->height()); |
| 554 | 554 |
| 555 // Only draw the content/toolbar separator if Instant Extended API is disabled | 555 // If Instant Extended API is disabled, draw the content/toolbar separator as |
| 556 // or mode is DEFAULT. | 556 // is. Otherwise, draw or fade it per ToolbarSearchAnimator. |
| 557 bool extended_instant_enabled = chrome::search::IsInstantExtendedAPIEnabled( | 557 bool extended_instant_enabled = chrome::search::IsInstantExtendedAPIEnabled( |
| 558 browser_view()->browser()->profile()); | 558 browser_view()->browser()->profile()); |
| 559 if (!extended_instant_enabled || mode == chrome::search::Mode::MODE_DEFAULT) { | 559 double separator_opacity = !extended_instant_enabled ? 1.0f : |
| 560 canvas->FillRect( | 560 browser_view()->browser()->search_delegate()->toolbar_search_animator(). |
| 561 gfx::Rect(x + kClientEdgeThickness, | 561 GetSeparatorOpacity(); |
| 562 toolbar_bounds.bottom() - kClientEdgeThickness, | 562 if (separator_opacity == 0.0f) |
| 563 w - (2 * kClientEdgeThickness), kClientEdgeThickness), | 563 return; |
| 564 ThemeService::GetDefaultColor(extended_instant_enabled ? | 564 bool fading = separator_opacity < 1.0f; |
| 565 ThemeService::COLOR_SEARCH_SEPARATOR_LINE : | 565 gfx::Rect separator_rect(x + kClientEdgeThickness, |
| 566 ThemeService::COLOR_TOOLBAR_SEPARATOR)); | 566 toolbar_bounds.bottom() - kClientEdgeThickness, |
| 567 w - (2 * kClientEdgeThickness), |
| 568 kClientEdgeThickness); |
| 569 if (fading) { |
| 570 canvas->SaveLayerAlpha(static_cast<uint8>(separator_opacity * 0xFF), |
| 571 separator_rect); |
| 567 } | 572 } |
| 573 canvas->FillRect(separator_rect, |
| 574 ThemeService::GetDefaultColor(extended_instant_enabled ? |
| 575 ThemeService::COLOR_SEARCH_SEPARATOR_LINE : |
| 576 ThemeService::COLOR_TOOLBAR_SEPARATOR)); |
| 577 if (fading) |
| 578 canvas->Restore(); |
| 568 } | 579 } |
| 569 | 580 |
| 570 void BrowserNonClientFrameViewAsh::PaintContentEdge(gfx::Canvas* canvas) { | 581 void BrowserNonClientFrameViewAsh::PaintContentEdge(gfx::Canvas* canvas) { |
| 571 canvas->FillRect(gfx::Rect(0, close_button_->bounds().bottom(), | 582 canvas->FillRect(gfx::Rect(0, close_button_->bounds().bottom(), |
| 572 width(), kClientEdgeThickness), | 583 width(), kClientEdgeThickness), |
| 573 ThemeService::GetDefaultColor(ThemeService::COLOR_TOOLBAR_SEPARATOR)); | 584 ThemeService::GetDefaultColor(ThemeService::COLOR_TOOLBAR_SEPARATOR)); |
| 574 } | 585 } |
| 575 | 586 |
| 576 int BrowserNonClientFrameViewAsh::GetThemeFrameImageId() const { | 587 int BrowserNonClientFrameViewAsh::GetThemeFrameImageId() const { |
| 577 bool is_incognito = browser_view()->IsOffTheRecord(); | 588 bool is_incognito = browser_view()->IsOffTheRecord(); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 599 BrowserNonClientFrameViewAsh::GetThemeFrameOverlayImage() const { | 610 BrowserNonClientFrameViewAsh::GetThemeFrameOverlayImage() const { |
| 600 ui::ThemeProvider* tp = GetThemeProvider(); | 611 ui::ThemeProvider* tp = GetThemeProvider(); |
| 601 if (tp->HasCustomImage(IDR_THEME_FRAME_OVERLAY) && | 612 if (tp->HasCustomImage(IDR_THEME_FRAME_OVERLAY) && |
| 602 browser_view()->IsBrowserTypeNormal() && | 613 browser_view()->IsBrowserTypeNormal() && |
| 603 !browser_view()->IsOffTheRecord()) { | 614 !browser_view()->IsOffTheRecord()) { |
| 604 return tp->GetImageSkiaNamed(ShouldPaintAsActive() ? | 615 return tp->GetImageSkiaNamed(ShouldPaintAsActive() ? |
| 605 IDR_THEME_FRAME_OVERLAY : IDR_THEME_FRAME_OVERLAY_INACTIVE); | 616 IDR_THEME_FRAME_OVERLAY : IDR_THEME_FRAME_OVERLAY_INACTIVE); |
| 606 } | 617 } |
| 607 return NULL; | 618 return NULL; |
| 608 } | 619 } |
| OLD | NEW |