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